MOS Source Code
Loading...
Searching...
No Matches
test.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 "test.pb.h"
7#include "unittests.h"
8
9int main(int argc, char **argv)
10{
11 int status = 0;
12 uint8_t buffer[512] = {0};
13 int i;
14 pb_ostream_t ostream;
15
16 Reply reply = Reply_init_zero;
17 Reply_Result request_result = Reply_Result_OK;
18
19 ostream = pb_ostream_from_buffer(buffer, sizeof(buffer));
20 reply.result = request_result;
21 if (!pb_encode(&ostream, Reply_fields, &reply)) {
22 fprintf(stderr, "Encode failed: %s\n", PB_GET_ERROR(&ostream));
23 return 1;
24 }
25
26 printf("response payload (%d):", (int)ostream.bytes_written);
27 for (i = 0; i < ostream.bytes_written; i++) {
28 printf("%02X", buffer[i]);
29 }
30 printf("\n");
31
32 TEST(ostream.bytes_written == 2);
33 TEST(buffer[0] == 0x08);
34 TEST(buffer[1] == 0x01);
35
36 return status;
37}
38
int main()
Definition test.c:24
#define stderr
Definition mos_stdio.h:32
const char ** argv
Definition kmain.c:44
size_t argc
Definition kmain.c:43
#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
unsigned char uint8_t
Definition pb_syshdr.h:20
#define TEST(x)
Definition test.h:3
static char buffer[2048]
Definition test_printf.c:7