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,24 @@
# Test proto3 "optional" field types.
# This is supported in protoc 3.12 and newer.
Import('env')
import re
version = None
if 'PROTOC_VERSION' in env:
match = re.search('([0-9]+).([0-9]+).([0-9]+)', env['PROTOC_VERSION'])
version = (int(match.group(1)), int(match.group(2)), int(match.group(3)))
# Oneof is supported by protoc >= 3.12.0
if env.GetOption('clean') or (version and (version[0] > 3 or (version[0] == 3 and version[1] >= 12))):
env2 = env.Clone()
env2.Append(PROTOCFLAGS = "--experimental_allow_proto3_optional")
env2.NanopbProto("optional.proto")
opt = env2.Program(["optional.c", "optional.pb.c",
"$COMMON/pb_decode.o", "$COMMON/pb_encode.o",
"$COMMON/pb_common.o"])
env2.RunTest(opt)

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

View file

@ -0,0 +1,9 @@
syntax = "proto3";
message TestMessage {
optional int32 opt_int = 1;
int32 normal_int = 2;
optional int32 opt_int2 = 3;
int32 normal_int2 = 4;
}