MOS Source Code
Loading...
Searching...
No Matches
test_oneofmsg.c
Go to the documentation of this file.
1#include <stdio.h>
2#include <stdlib.h>
3#include <string.h>
4#include <pb_encode.h>
5#include <pb_decode.h>
6#include "oneofmsg.pb.h"
7#include "unittests.h"
8
9int main(int argc, char **argv)
10{
11 int status = 0;
12 uint8_t buffer[512];
13 pb_size_t msglen = 0;
14
15 {
16 pb_ostream_t stream = pb_ostream_from_buffer(buffer, sizeof(buffer));
17 BodyMessage msg = BodyMessage_init_zero;
18
19 msg.which_body_type = BodyMessage_device_data_crypted_tag;
20 msg.body_type.device_data_crypted.size = 252;
21 memset(msg.body_type.device_data_crypted.bytes, 0xAA, 252);
22
23 TEST(pb_encode(&stream, BodyMessage_fields, &msg));
24
25 msglen = stream.bytes_written;
26 TEST(msglen > 252);
27 }
28
29 {
30 pb_istream_t stream = pb_istream_from_buffer(buffer, msglen);
31 BodyMessage msg = BodyMessage_init_zero;
32
33 TEST(pb_decode(&stream, BodyMessage_fields, &msg));
34
35 TEST(msg.which_body_type == BodyMessage_device_data_crypted_tag);
36 TEST(msg.body_type.device_data_crypted.size == 252);
37 TEST(msg.body_type.device_data_crypted.bytes[251] == 0xAA);
38 }
39
40 return status;
41}
42
const char ** argv
Definition kmain.c:44
size_t argc
Definition kmain.c:43
uint_least16_t pb_size_t
Definition pb.h:310
bool pb_decode(pb_istream_t *stream, const pb_msgdesc_t *fields, void *dest_struct)
Definition pb_decode.c:1182
pb_istream_t pb_istream_from_buffer(const pb_byte_t *buf, size_t msglen)
Definition pb_decode.c:143
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
static void * memset(void *s, int c, size_t n)
Definition pb_syshdr.h:101
unsigned char uint8_t
Definition pb_syshdr.h:20
int main()
Definition simple.cpp:6
#define TEST(x)
Definition test.h:3
static char buffer[2048]
Definition test_printf.c:7