mirror of
https://github.com/google/pebble.git
synced 2025-06-24 01:56:16 +00:00
Import of the watch repository from Pebble
This commit is contained in:
commit
3b92768480
10334 changed files with 2564465 additions and 0 deletions
47
third_party/nanopb/tests/proto3_optional/optional.c
vendored
Normal file
47
third_party/nanopb/tests/proto3_optional/optional.c
vendored
Normal file
|
@ -0,0 +1,47 @@
|
|||
#include <pb_encode.h>
|
||||
#include <pb_decode.h>
|
||||
#include <unittests.h>
|
||||
#include "optional.pb.h"
|
||||
|
||||
int main()
|
||||
{
|
||||
int status = 0;
|
||||
uint8_t buf[256];
|
||||
size_t msglen;
|
||||
|
||||
COMMENT("Test encoding message with optional field")
|
||||
{
|
||||
pb_ostream_t stream = pb_ostream_from_buffer(buf, sizeof(buf));
|
||||
TestMessage msg = TestMessage_init_zero;
|
||||
|
||||
msg.has_opt_int = true;
|
||||
msg.opt_int = 99;
|
||||
msg.normal_int = 100;
|
||||
msg.opt_int2 = 101;
|
||||
|
||||
TEST(pb_encode(&stream, TestMessage_fields, &msg));
|
||||
msglen = stream.bytes_written;
|
||||
}
|
||||
|
||||
COMMENT("Test decoding message with optional field")
|
||||
{
|
||||
pb_istream_t stream = pb_istream_from_buffer(buf, msglen);
|
||||
TestMessage msg = TestMessage_init_zero;
|
||||
|
||||
/* These fields should be missing from the message
|
||||
* so the values wouldn't be overwritten. */
|
||||
msg.opt_int2 = 5;
|
||||
msg.normal_int2 = 6;
|
||||
|
||||
TEST(pb_decode_noinit(&stream, TestMessage_fields, &msg));
|
||||
TEST(msg.has_opt_int);
|
||||
TEST(msg.opt_int == 99);
|
||||
TEST(msg.normal_int == 100);
|
||||
TEST(!msg.has_opt_int2);
|
||||
TEST(msg.opt_int2 == 5);
|
||||
TEST(msg.normal_int2 == 6);
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue