MOS Source Code
Loading...
Searching...
No Matches
defaults.c
Go to the documentation of this file.
1#include "defaults.pb.h"
2#include <unittests.h>
3#include <pb_decode.h>
4
5int check_defaults(const DefaultsMsg *msg)
6{
7 int status = 0;
8
9 TEST(msg->b1[0] == 0xDE && msg->b1[1] == 0xAD && msg->b1[2] == 0x00 &&
10 msg->b1[3] == 0xBE && msg->b1[4] == 0xEF);
11 TEST(msg->b2.bytes[0] == 0xDE && msg->b2.bytes[1] == 0xAD &&
12 msg->b2.bytes[2] == 0x00 && msg->b2.bytes[3] == 0xBE &&
13 msg->b2.bytes[4] == 0xEF && msg->b2.size == 5);
14 TEST(msg->b3.bytes[0] == 0xDE && msg->b3.bytes[1] == 0xAD &&
15 msg->b3.bytes[2] == 0x00 && msg->b3.bytes[3] == 0xBE &&
16 msg->b3.bytes[4] == 0xEF && msg->b2.size == 5);
17 TEST(msg->s1[0] == (char)0xC3 && msg->s1[1] == (char)0xA4 &&
18 msg->s1[2] == (char)0xC3 && msg->s1[3] == (char)0xB6 &&
19 msg->s1[4] == '\0');
20
21 return status;
22}
23
24int main()
25{
26 int status = 0;
27
28 {
29 DefaultsMsg msg = DefaultsMsg_init_default;
30 COMMENT("Checking defaults from static initializer");
31 status += check_defaults(&msg);
32 }
33
34 {
35 DefaultsMsg msg = DefaultsMsg_init_zero;
36 pb_istream_t empty = {0,0,0};
37 pb_decode(&empty, DefaultsMsg_fields, &msg);
38 COMMENT("Checking defaults set at runtime");
39 status += check_defaults(&msg);
40 }
41
42 return status;
43}
44
int check_defaults(const DefaultsMsg *msg)
Definition defaults.c:5
int main()
Definition defaults.c:24
bool pb_decode(pb_istream_t *stream, const pb_msgdesc_t *fields, void *dest_struct)
Definition pb_decode.c:1182
#define TEST(x)
Definition test.h:3
#define COMMENT(x)
Definition unittests.h:17