Import of the watch repository from Pebble

This commit is contained in:
Matthieu Jeanson 2024-12-12 16:43:03 -08:00 committed by Katharine Berry
commit 3b92768480
10334 changed files with 2564465 additions and 0 deletions

View 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;
}