MOS Source Code
Loading...
Searching...
No Matches
enum_encoded_size.c
Go to the documentation of this file.
1#include <stdio.h>
2#include <string.h>
3#include <pb_encode.h>
4#include "unittests.h"
5#include "enums.pb.h"
6
7int main()
8{
9 int status = 0;
10
11 uint8_t buf[256];
12 SignedMsg msg1;
13 UnsignedMsg msg2;
14 pb_ostream_t s;
15
16 {
17 COMMENT("Test negative value of signed enum");
18 /* Negative value should take up the maximum size */
19 msg1.value = SignedEnum_SE_MIN;
20 s = pb_ostream_from_buffer(buf, sizeof(buf));
21 TEST(pb_encode(&s, SignedMsg_fields, &msg1));
22 TEST(s.bytes_written == SignedMsg_size);
23
24 COMMENT("Test positive value of signed enum");
25 /* Positive value should be smaller */
26 msg1.value = SignedEnum_SE_MAX;
27 s = pb_ostream_from_buffer(buf, sizeof(buf));
28 TEST(pb_encode(&s, SignedMsg_fields, &msg1));
29 TEST(s.bytes_written < SignedMsg_size);
30 }
31
32 {
33 COMMENT("Test positive value of unsigned enum");
34 /* This should take up the maximum size */
35 msg2.value = UnsignedEnum_UE_MAX;
36 s = pb_ostream_from_buffer(buf, sizeof(buf));
37 TEST(pb_encode(&s, UnsignedMsg_fields, &msg2));
38 TEST(s.bytes_written == UnsignedMsg_size);
39 }
40
41 return status;
42}
43
int main()
pb_ostream_t pb_ostream_from_buffer(pb_byte_t *buf, size_t bufsize)
Definition pb_encode.c:63
bool pb_encode(pb_ostream_t *stream, const pb_msgdesc_t *fields, const void *src_struct)
Definition pb_encode.c:512
unsigned char uint8_t
Definition pb_syshdr.h:20
#define TEST(x)
Definition test.h:3
#define COMMENT(x)
Definition unittests.h:17