MOS Source Code
Loading...
Searching...
No Matches
test_fixarray.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 "fixed_array.pb.h"
7#include "unittests.h"
8
9int main(int argc, char **argv)
10{
11 int status = 0;
12 uint8_t buffer[64];
13 pb_size_t msglen = 0;
14
15 {
16 pb_ostream_t stream = pb_ostream_from_buffer(buffer, sizeof(buffer));
17 MainMessage msg = MainMessage_init_zero;
18
19 msg.submsg.data[0] = 0;
20 msg.submsg.data[4] = 5;
21
22 TEST(pb_encode(&stream, MainMessage_fields, &msg));
23
24 msglen = stream.bytes_written;
25 TEST(msglen > 5);
26 }
27
28 {
29 pb_istream_t stream = pb_istream_from_buffer(buffer, msglen);
30 MainMessage msg = MainMessage_init_zero;
31
32 TEST(pb_decode(&stream, MainMessage_fields, &msg));
33
34 TEST(msg.submsg.data[0] == 0);
35 TEST(msg.submsg.data[4] == 5);
36 }
37
38 return status;
39}
40
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
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