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,17 @@
# Regression test for #494:
# Using sizeof on anonymous union not allowed in C++, in message_size oneof sizing fallback
Import('env')
import os, sys
# The build rules here are a bit tricky to make the normal dependency
# resolution intentionally fail. This causes the generator to use the fallback
# define which had the problem with C++.
env.Command("oneof.pb", "oneof.proto", "$PROTOC $PROTOCFLAGS -I$BUILDDIR/regression/issue_494 -o$TARGETS $SOURCES")
env.Command(["oneof.pb.c", "oneof.pb.h"], "oneof.pb", env['NANOPB_GENERATOR'] + " -D$BUILDDIR/regression/issue_494 $SOURCES")
env.NanopbProto("submessage.proto")
env.Depends("oneof.pb", "submessage.proto")
test = env.Program(["oneof_size.cc"])
env.Depends(test, "oneof.pb.h")
env.RunTest(test)

View file

@ -0,0 +1,13 @@
syntax = "proto3";
import "submessage.proto";
message MyMessage
{
oneof foo
{
SubMessage1 msg1 = 1;
SubMessage2 msg2 = 2;
SubMessage3 msg3 = 3;
}
}

View file

@ -0,0 +1,19 @@
#include "oneof.pb.h"
#include "unittests.h"
extern "C" int main()
{
int status = 0;
// Expected maximum encoded size:
// 1 byte for MyMessage.foo tag
// 1-5 bytes for MyMessage.foo submsg length
// 1 byte for SubMessage3.foo tag
// 5 bytes for SubMessage3.foo value
// 1 byte for SubMessage3.bar tag
// 5 bytes for SubMessage3.bar value
printf("Size: %d\n", (int)MyMessage_size);
TEST(MyMessage_size == 18);
return status;
}

View file

@ -0,0 +1,17 @@
syntax = "proto3";
message SubMessage1
{
uint32 foo = 1;
}
message SubMessage2
{
uint32 foo = 1;
}
message SubMessage3
{
uint32 foo = 1;
uint32 bar = 2;
}