• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #include <stdio.h>
2 #include <string.h>
3 #include <pb_encode.h>
4 #include "unittests.h"
5 #include "enums.pb.h"
6 
main()7 int 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 
44