MOS Source Code
Loading...
Searching...
No Matches
test.c
Go to the documentation of this file.
1#include <string.h>
2#include <pb_encode.h>
3#include <unittests.h>
4#include "test.pb.h"
5
6int main()
7{
8 pb_byte_t buf[512];
9 MyMessage msg = MyMessage_init_zero;
10 pb_ostream_t stream = pb_ostream_from_buffer(buf, sizeof(buf));
11
12 msg.mybytes.size = 0xFFFFFFFF;
13
14 if (pb_encode(&stream, MyMessage_fields, &msg))
15 {
16 fprintf(stderr, "Failure: expected pb_encode() to fail.\n");
17 return 1;
18 }
19 else if (strcmp(PB_GET_ERROR(&stream), "bytes size exceeded") != 0)
20 {
21 fprintf(stderr, "Unexpected encoding error: %s\n", PB_GET_ERROR(&stream));
22 return 2;
23 }
24 else
25 {
26 return 0;
27 }
28}
int main()
Definition test.c:24
MOSAPI s32 strcmp(const char *str1, const char *str2)
Definition mos_string.c:24
#define stderr
Definition mos_stdio.h:32
uint_least8_t pb_byte_t
Definition pb.h:227
#define PB_GET_ERROR(stream)
Definition pb.h:891
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