diff options
author | Romain Forlot <romain.forlot@iot.bzh> | 2017-05-02 17:51:53 +0200 |
---|---|---|
committer | Romain Forlot <romain.forlot@iot.bzh> | 2017-05-02 17:51:53 +0200 |
commit | 3102ec9ce009d0f28355c5b7df9c5bd5013e6e75 (patch) | |
tree | 80a1ea19ff06cc9308b236a0d8d6358d21dd0381 /CAN-binder/libs/nanopb/tests/regression | |
parent | 12e680a3c97a2750c657a8c561a79706f3689149 (diff) | |
parent | 278ffb890e3d8722e4c7d824baaf221a1e375fc4 (diff) |
Add 'CAN-binder/libs/nanopb/' from commit '278ffb890e3d8722e4c7d824baaf221a1e375fc4'
git-subtree-dir: CAN-binder/libs/nanopb
git-subtree-mainline: 12e680a3c97a2750c657a8c561a79706f3689149
git-subtree-split: 278ffb890e3d8722e4c7d824baaf221a1e375fc4
Diffstat (limited to 'CAN-binder/libs/nanopb/tests/regression')
54 files changed, 807 insertions, 0 deletions
diff --git a/CAN-binder/libs/nanopb/tests/regression/issue_118/SConscript b/CAN-binder/libs/nanopb/tests/regression/issue_118/SConscript new file mode 100644 index 0000000..833d9de --- /dev/null +++ b/CAN-binder/libs/nanopb/tests/regression/issue_118/SConscript @@ -0,0 +1,12 @@ +# Regression test for Issue 118: Short enum names in imported proto files are not honoured + +Import("env") +env = env.Clone() +env.Append(PROTOCPATH = "#regression/issue_118") + +env.NanopbProto("enumdef") +env.Object('enumdef.pb.c') + +env.NanopbProto(["enumuse", "enumdef.proto"]) +env.Object('enumuse.pb.c') + diff --git a/CAN-binder/libs/nanopb/tests/regression/issue_118/enumdef.proto b/CAN-binder/libs/nanopb/tests/regression/issue_118/enumdef.proto new file mode 100644 index 0000000..46845bc --- /dev/null +++ b/CAN-binder/libs/nanopb/tests/regression/issue_118/enumdef.proto @@ -0,0 +1,8 @@ +syntax = "proto2"; + +import 'nanopb.proto'; + +enum MyEnum { + option (nanopb_enumopt).long_names = false; + FOOBAR = 1; +} diff --git a/CAN-binder/libs/nanopb/tests/regression/issue_118/enumuse.proto b/CAN-binder/libs/nanopb/tests/regression/issue_118/enumuse.proto new file mode 100644 index 0000000..4afc452 --- /dev/null +++ b/CAN-binder/libs/nanopb/tests/regression/issue_118/enumuse.proto @@ -0,0 +1,7 @@ +syntax = "proto2"; + +import 'enumdef.proto'; + +message MyMessage { + required MyEnum myenum = 1 [default = FOOBAR]; +} diff --git a/CAN-binder/libs/nanopb/tests/regression/issue_125/SConscript b/CAN-binder/libs/nanopb/tests/regression/issue_125/SConscript new file mode 100644 index 0000000..f2155e6 --- /dev/null +++ b/CAN-binder/libs/nanopb/tests/regression/issue_125/SConscript @@ -0,0 +1,9 @@ +# Regression test for Issue 125: Wrong identifier name for extension fields + +Import("env") + +env.NanopbProto(["extensionbug", "extensionbug.options"]) +env.Object('extensionbug.pb.c') + +env.Match(['extensionbug.pb.h', 'extensionbug.expected']) + diff --git a/CAN-binder/libs/nanopb/tests/regression/issue_125/extensionbug.expected b/CAN-binder/libs/nanopb/tests/regression/issue_125/extensionbug.expected new file mode 100644 index 0000000..fc21335 --- /dev/null +++ b/CAN-binder/libs/nanopb/tests/regression/issue_125/extensionbug.expected @@ -0,0 +1,3 @@ +pb_extension_type_t Message2_extras +uint32_t field2 + diff --git a/CAN-binder/libs/nanopb/tests/regression/issue_125/extensionbug.options b/CAN-binder/libs/nanopb/tests/regression/issue_125/extensionbug.options new file mode 100644 index 0000000..30b464a --- /dev/null +++ b/CAN-binder/libs/nanopb/tests/regression/issue_125/extensionbug.options @@ -0,0 +1,4 @@ +* type:FT_IGNORE + +Message2.extras type:FT_STATIC +Message2.field2 type:FT_STATIC diff --git a/CAN-binder/libs/nanopb/tests/regression/issue_125/extensionbug.proto b/CAN-binder/libs/nanopb/tests/regression/issue_125/extensionbug.proto new file mode 100644 index 0000000..fd1e74f --- /dev/null +++ b/CAN-binder/libs/nanopb/tests/regression/issue_125/extensionbug.proto @@ -0,0 +1,18 @@ +syntax = "proto2"; + +message Message1 +{ + optional uint32 fieldA = 1; + extensions 30 to max; +} + +message Message2 +{ + extend Message1 + { + optional Message2 extras = 30; + } + + optional uint32 field1 = 1; + optional uint32 field2 = 2; +} diff --git a/CAN-binder/libs/nanopb/tests/regression/issue_141/SConscript b/CAN-binder/libs/nanopb/tests/regression/issue_141/SConscript new file mode 100644 index 0000000..b6526be --- /dev/null +++ b/CAN-binder/libs/nanopb/tests/regression/issue_141/SConscript @@ -0,0 +1,8 @@ +# Regression test for issue 141: wrong encoded size #define for oneof messages + +Import("env") + +env.NanopbProto("testproto") +env.Object('testproto.pb.c') +env.Match(['testproto.pb.h', 'testproto.expected']) + diff --git a/CAN-binder/libs/nanopb/tests/regression/issue_141/testproto.expected b/CAN-binder/libs/nanopb/tests/regression/issue_141/testproto.expected new file mode 100644 index 0000000..75bc195 --- /dev/null +++ b/CAN-binder/libs/nanopb/tests/regression/issue_141/testproto.expected @@ -0,0 +1,7 @@ +define SubMessage_size \s* 88 +define OneOfMessage_size \s* 113 +define topMessage_size \s* 70 +define MyMessage1_size \s* 46 +define MyMessage2_size \s* 8 +define MyMessage3_size \s* 5 +define MyMessage4_size \s* 18 diff --git a/CAN-binder/libs/nanopb/tests/regression/issue_141/testproto.proto b/CAN-binder/libs/nanopb/tests/regression/issue_141/testproto.proto new file mode 100644 index 0000000..a445c68 --- /dev/null +++ b/CAN-binder/libs/nanopb/tests/regression/issue_141/testproto.proto @@ -0,0 +1,52 @@ +syntax = "proto2"; + +import 'nanopb.proto'; + +message SubMessage +{ + repeated int32 array = 1 [(nanopb).max_count = 8]; +} + +message OneOfMessage +{ + required int32 prefix = 1; + oneof values + { + int32 first = 5; + string second = 6 [(nanopb).max_size = 8]; + SubMessage third = 7; + } + required int32 suffix = 99; +} + +message topMessage { + required int32 start = 1; + oneof msg { + MyMessage1 msg1 = 2; + MyMessage2 msg2 = 3; + } + required int32 end = 4; +} + +message MyMessage1 { + required uint32 n1 = 1; + required uint32 n2 = 2; + required string s = 3 [(nanopb).max_size = 32]; +} + +message MyMessage2 { + required uint32 num = 1; + required bool b = 2; +} + +message MyMessage3 { + required bool bbb = 1; + required string ss = 2 [(nanopb).max_size = 1]; +} + +message MyMessage4 { + required bool bbbb = 1; + required string sss = 2 [(nanopb).max_size = 2]; + required uint32 num = 3; + required uint32 num2 = 4; +} diff --git a/CAN-binder/libs/nanopb/tests/regression/issue_145/SConscript b/CAN-binder/libs/nanopb/tests/regression/issue_145/SConscript new file mode 100644 index 0000000..0b793a7 --- /dev/null +++ b/CAN-binder/libs/nanopb/tests/regression/issue_145/SConscript @@ -0,0 +1,9 @@ +# Regression test for Issue 145: Allow /* */ and // comments in .options files + +Import("env") + +env.NanopbProto(["comments", "comments.options"]) +env.Object('comments.pb.c') + +env.Match(['comments.pb.h', 'comments.expected']) + diff --git a/CAN-binder/libs/nanopb/tests/regression/issue_145/comments.expected b/CAN-binder/libs/nanopb/tests/regression/issue_145/comments.expected new file mode 100644 index 0000000..7f87458 --- /dev/null +++ b/CAN-binder/libs/nanopb/tests/regression/issue_145/comments.expected @@ -0,0 +1,3 @@ +char foo\[5\]; +char bar\[16\]; + diff --git a/CAN-binder/libs/nanopb/tests/regression/issue_145/comments.options b/CAN-binder/libs/nanopb/tests/regression/issue_145/comments.options new file mode 100644 index 0000000..89959ba --- /dev/null +++ b/CAN-binder/libs/nanopb/tests/regression/issue_145/comments.options @@ -0,0 +1,6 @@ +/* Block comment */ +# Line comment +// Line comment +DummyMessage.foo /* Block comment */ max_size:5 +DummyMessage.bar max_size:16 # Line comment ### + diff --git a/CAN-binder/libs/nanopb/tests/regression/issue_145/comments.proto b/CAN-binder/libs/nanopb/tests/regression/issue_145/comments.proto new file mode 100644 index 0000000..621779f --- /dev/null +++ b/CAN-binder/libs/nanopb/tests/regression/issue_145/comments.proto @@ -0,0 +1,7 @@ +syntax = "proto2"; + +message DummyMessage { + required string foo = 1; + required string bar = 2; +} + diff --git a/CAN-binder/libs/nanopb/tests/regression/issue_166/SConscript b/CAN-binder/libs/nanopb/tests/regression/issue_166/SConscript new file mode 100644 index 0000000..c50b919 --- /dev/null +++ b/CAN-binder/libs/nanopb/tests/regression/issue_166/SConscript @@ -0,0 +1,13 @@ +# Verify that the maximum encoded size is calculated properly +# for enums. + +Import('env') + +env.NanopbProto('enums') + +p = env.Program(["enum_encoded_size.c", + "enums.pb.c", + "$COMMON/pb_encode.o", + "$COMMON/pb_common.o"]) +env.RunTest(p) + diff --git a/CAN-binder/libs/nanopb/tests/regression/issue_166/enum_encoded_size.c b/CAN-binder/libs/nanopb/tests/regression/issue_166/enum_encoded_size.c new file mode 100644 index 0000000..84e1c7d --- /dev/null +++ b/CAN-binder/libs/nanopb/tests/regression/issue_166/enum_encoded_size.c @@ -0,0 +1,43 @@ +#include <stdio.h> +#include <string.h> +#include <pb_encode.h> +#include "unittests.h" +#include "enums.pb.h" + +int main() +{ + int status = 0; + + uint8_t buf[256]; + SignedMsg msg1; + UnsignedMsg msg2; + pb_ostream_t s; + + { + COMMENT("Test negative value of signed enum"); + /* Negative value should take up the maximum size */ + msg1.value = SignedEnum_SE_MIN; + s = pb_ostream_from_buffer(buf, sizeof(buf)); + TEST(pb_encode(&s, SignedMsg_fields, &msg1)); + TEST(s.bytes_written == SignedMsg_size); + + COMMENT("Test positive value of signed enum"); + /* Positive value should be smaller */ + msg1.value = SignedEnum_SE_MAX; + s = pb_ostream_from_buffer(buf, sizeof(buf)); + TEST(pb_encode(&s, SignedMsg_fields, &msg1)); + TEST(s.bytes_written < SignedMsg_size); + } + + { + COMMENT("Test positive value of unsigned enum"); + /* This should take up the maximum size */ + msg2.value = UnsignedEnum_UE_MAX; + s = pb_ostream_from_buffer(buf, sizeof(buf)); + TEST(pb_encode(&s, UnsignedMsg_fields, &msg2)); + TEST(s.bytes_written == UnsignedMsg_size); + } + + return status; +} + diff --git a/CAN-binder/libs/nanopb/tests/regression/issue_166/enums.proto b/CAN-binder/libs/nanopb/tests/regression/issue_166/enums.proto new file mode 100644 index 0000000..3694804 --- /dev/null +++ b/CAN-binder/libs/nanopb/tests/regression/issue_166/enums.proto @@ -0,0 +1,18 @@ +syntax = "proto2"; + +enum SignedEnum { + SE_MIN = -1; + SE_MAX = 255; +} + +enum UnsignedEnum { + UE_MAX = 65536; +} + +message SignedMsg { + required SignedEnum value = 1; +} + +message UnsignedMsg { + required UnsignedEnum value = 1; +} diff --git a/CAN-binder/libs/nanopb/tests/regression/issue_172/SConscript b/CAN-binder/libs/nanopb/tests/regression/issue_172/SConscript new file mode 100644 index 0000000..49c919e --- /dev/null +++ b/CAN-binder/libs/nanopb/tests/regression/issue_172/SConscript @@ -0,0 +1,16 @@ +# Verify that _size define is generated for messages that have +# includes from another directory. + +Import('env') + +incpath = env.Clone() +incpath.Append(PROTOCPATH="#regression/issue_172/submessage") +incpath.Append(CPPPATH="$BUILD/regression/issue_172/submessage") +incpath.NanopbProto('test') +incpath.NanopbProto(['submessage/submessage', 'submessage/submessage.options']) + +p = incpath.Program(["msg_size.c", + "test.pb.c", + "submessage/submessage.pb.c"]) + + diff --git a/CAN-binder/libs/nanopb/tests/regression/issue_172/msg_size.c b/CAN-binder/libs/nanopb/tests/regression/issue_172/msg_size.c new file mode 100644 index 0000000..be45acb --- /dev/null +++ b/CAN-binder/libs/nanopb/tests/regression/issue_172/msg_size.c @@ -0,0 +1,9 @@ +#include "test.pb.h" + +PB_STATIC_ASSERT(testmessage_size >= 1+1+1+1+16, TESTMESSAGE_SIZE_IS_WRONG) + +int main() +{ + return 0; +} + diff --git a/CAN-binder/libs/nanopb/tests/regression/issue_172/submessage/submessage.options b/CAN-binder/libs/nanopb/tests/regression/issue_172/submessage/submessage.options new file mode 100644 index 0000000..12fb198 --- /dev/null +++ b/CAN-binder/libs/nanopb/tests/regression/issue_172/submessage/submessage.options @@ -0,0 +1 @@ +submessage.data max_size: 16 diff --git a/CAN-binder/libs/nanopb/tests/regression/issue_172/submessage/submessage.proto b/CAN-binder/libs/nanopb/tests/regression/issue_172/submessage/submessage.proto new file mode 100644 index 0000000..ce6804a --- /dev/null +++ b/CAN-binder/libs/nanopb/tests/regression/issue_172/submessage/submessage.proto @@ -0,0 +1,4 @@ +syntax = "proto2"; +message submessage { + required bytes data = 1; +} diff --git a/CAN-binder/libs/nanopb/tests/regression/issue_172/test.proto b/CAN-binder/libs/nanopb/tests/regression/issue_172/test.proto new file mode 100644 index 0000000..fbd97be --- /dev/null +++ b/CAN-binder/libs/nanopb/tests/regression/issue_172/test.proto @@ -0,0 +1,6 @@ +syntax = "proto2"; +import "submessage.proto"; + +message testmessage { + optional submessage sub = 1; +} diff --git a/CAN-binder/libs/nanopb/tests/regression/issue_188/SConscript b/CAN-binder/libs/nanopb/tests/regression/issue_188/SConscript new file mode 100644 index 0000000..6bc3271 --- /dev/null +++ b/CAN-binder/libs/nanopb/tests/regression/issue_188/SConscript @@ -0,0 +1,6 @@ +# Regression test for issue with Enums inside OneOf. + +Import('env') + +env.NanopbProto('oneof') + diff --git a/CAN-binder/libs/nanopb/tests/regression/issue_188/oneof.proto b/CAN-binder/libs/nanopb/tests/regression/issue_188/oneof.proto new file mode 100644 index 0000000..e37f5c0 --- /dev/null +++ b/CAN-binder/libs/nanopb/tests/regression/issue_188/oneof.proto @@ -0,0 +1,29 @@ +syntax = "proto2"; + +message MessageOne +{ + required uint32 one = 1; + required uint32 two = 2; + required uint32 three = 3; + required int32 four = 4; +} + +enum EnumTwo +{ + SOME_ENUM_1 = 1; + SOME_ENUM_2 = 5; + SOME_ENUM_3 = 6; + SOME_ENUM_4 = 9; + SOME_ENUM_5 = 10; + SOME_ENUM_6 = 12; + SOME_ENUM_7 = 39; + SOME_ENUM_8 = 401; +} + +message OneofMessage +{ + oneof payload { + MessageOne message = 1; + EnumTwo enum = 2; + } +} diff --git a/CAN-binder/libs/nanopb/tests/regression/issue_195/SConscript b/CAN-binder/libs/nanopb/tests/regression/issue_195/SConscript new file mode 100644 index 0000000..78326d3 --- /dev/null +++ b/CAN-binder/libs/nanopb/tests/regression/issue_195/SConscript @@ -0,0 +1,10 @@ +# Regression test for Issue 195: Message size not calculated if a submessage includes +# bytes. Basically a non-working #define being generated. + +Import("env") + +env.NanopbProto(["test"]) +env.Object('test.pb.c') + +env.Match(['test.pb.h', 'test.expected']) + diff --git a/CAN-binder/libs/nanopb/tests/regression/issue_195/test.expected b/CAN-binder/libs/nanopb/tests/regression/issue_195/test.expected new file mode 100644 index 0000000..83ea7ab --- /dev/null +++ b/CAN-binder/libs/nanopb/tests/regression/issue_195/test.expected @@ -0,0 +1 @@ +/\* TestMessage_size depends diff --git a/CAN-binder/libs/nanopb/tests/regression/issue_195/test.proto b/CAN-binder/libs/nanopb/tests/regression/issue_195/test.proto new file mode 100644 index 0000000..7a77d69 --- /dev/null +++ b/CAN-binder/libs/nanopb/tests/regression/issue_195/test.proto @@ -0,0 +1,8 @@ +message TestMessage { + required uint32 id = 1; + required bytes payload = 2; +} +message EncapsulatedMessage { + required uint32 id = 1; + required TestMessage test = 2; +} diff --git a/CAN-binder/libs/nanopb/tests/regression/issue_203/SConscript b/CAN-binder/libs/nanopb/tests/regression/issue_203/SConscript new file mode 100644 index 0000000..8b4d6cc --- /dev/null +++ b/CAN-binder/libs/nanopb/tests/regression/issue_203/SConscript @@ -0,0 +1,9 @@ +# Regression test for issue with multiple files generated at once + +Import('env') + +env.Command(['file1.pb.c', 'file1.pb.h', 'file2.pb.c', 'file2.pb.h'], ['file1.proto', 'file2.proto'], + env['NANOPB_PROTO_CMD']) + +env.Object('file1.pb.c') +env.Object('file2.pb.c') diff --git a/CAN-binder/libs/nanopb/tests/regression/issue_203/file1.proto b/CAN-binder/libs/nanopb/tests/regression/issue_203/file1.proto new file mode 100644 index 0000000..dae250b --- /dev/null +++ b/CAN-binder/libs/nanopb/tests/regression/issue_203/file1.proto @@ -0,0 +1,10 @@ +syntax = "proto2"; + +message SubMessage1 { + required int32 foo = 1; +} + +message Message1 { + required SubMessage1 bar = 1; +} + diff --git a/CAN-binder/libs/nanopb/tests/regression/issue_203/file2.proto b/CAN-binder/libs/nanopb/tests/regression/issue_203/file2.proto new file mode 100644 index 0000000..513b0f0 --- /dev/null +++ b/CAN-binder/libs/nanopb/tests/regression/issue_203/file2.proto @@ -0,0 +1,10 @@ +syntax = "proto2"; + +message SubMessage2 { + required int32 foo = 1; +} + +message Message2 { + required SubMessage2 bar = 1; +} + diff --git a/CAN-binder/libs/nanopb/tests/regression/issue_205/SConscript b/CAN-binder/libs/nanopb/tests/regression/issue_205/SConscript new file mode 100644 index 0000000..ed8899d --- /dev/null +++ b/CAN-binder/libs/nanopb/tests/regression/issue_205/SConscript @@ -0,0 +1,14 @@ +# Check that pb_release() correctly handles corrupted size fields of +# static arrays. + +Import('env', 'malloc_env') + +env.NanopbProto('size_corruption') + +p = malloc_env.Program(["size_corruption.c", + "size_corruption.pb.c", + "$COMMON/pb_decode_with_malloc.o", + "$COMMON/pb_common_with_malloc.o", + "$COMMON/malloc_wrappers.o"]) +env.RunTest(p) + diff --git a/CAN-binder/libs/nanopb/tests/regression/issue_205/size_corruption.c b/CAN-binder/libs/nanopb/tests/regression/issue_205/size_corruption.c new file mode 100644 index 0000000..08cef45 --- /dev/null +++ b/CAN-binder/libs/nanopb/tests/regression/issue_205/size_corruption.c @@ -0,0 +1,12 @@ +#include "size_corruption.pb.h" +#include <pb_decode.h> + +int main() +{ + MainMessage msg = MainMessage_init_zero; + msg.bar_count = (pb_size_t)-1; + pb_release(MainMessage_fields, &msg); + + return 0; +} + diff --git a/CAN-binder/libs/nanopb/tests/regression/issue_205/size_corruption.proto b/CAN-binder/libs/nanopb/tests/regression/issue_205/size_corruption.proto new file mode 100644 index 0000000..6c9c245 --- /dev/null +++ b/CAN-binder/libs/nanopb/tests/regression/issue_205/size_corruption.proto @@ -0,0 +1,11 @@ +syntax = "proto2"; +import 'nanopb.proto'; + +message SubMessage { + repeated int32 foo = 1 [(nanopb).type = FT_POINTER]; +} + +message MainMessage { + repeated SubMessage bar = 1 [(nanopb).max_count = 5]; +} + diff --git a/CAN-binder/libs/nanopb/tests/regression/issue_227/SConscript b/CAN-binder/libs/nanopb/tests/regression/issue_227/SConscript new file mode 100644 index 0000000..1074124 --- /dev/null +++ b/CAN-binder/libs/nanopb/tests/regression/issue_227/SConscript @@ -0,0 +1,14 @@ +# Regression test for Issue 227:Using proto3 type fields can cause unaligned access +# NOTE: This test will only detect problems when run with clang sanitizer (which +# is done regularly by a jenkins run). + +Import('env') + +env.NanopbProto('unaligned_uint64') + +p = env.Program(["unaligned_uint64.c", + "unaligned_uint64.pb.c", + "$COMMON/pb_encode.o", + "$COMMON/pb_common.o"]) +env.RunTest(p) + diff --git a/CAN-binder/libs/nanopb/tests/regression/issue_227/unaligned_uint64.c b/CAN-binder/libs/nanopb/tests/regression/issue_227/unaligned_uint64.c new file mode 100644 index 0000000..17c1d77 --- /dev/null +++ b/CAN-binder/libs/nanopb/tests/regression/issue_227/unaligned_uint64.c @@ -0,0 +1,14 @@ +#include "unaligned_uint64.pb.h" +#include <pb_encode.h> + +int main() +{ + uint8_t buf[128]; + pb_ostream_t stream = pb_ostream_from_buffer(buf, sizeof(buf)); + MainMessage msg = MainMessage_init_zero; + msg.bar[0] = 'A'; + pb_encode(&stream, MainMessage_fields, &msg); + + return 0; +} + diff --git a/CAN-binder/libs/nanopb/tests/regression/issue_227/unaligned_uint64.proto b/CAN-binder/libs/nanopb/tests/regression/issue_227/unaligned_uint64.proto new file mode 100644 index 0000000..f0269f6 --- /dev/null +++ b/CAN-binder/libs/nanopb/tests/regression/issue_227/unaligned_uint64.proto @@ -0,0 +1,8 @@ +syntax = "proto3"; +import 'nanopb.proto'; + +message MainMessage { + string foo = 1 [(nanopb).max_size = 3]; + string bar = 2 [(nanopb).max_size = 8]; +} + diff --git a/CAN-binder/libs/nanopb/tests/regression/issue_229/SConscript b/CAN-binder/libs/nanopb/tests/regression/issue_229/SConscript new file mode 100644 index 0000000..b0f8376 --- /dev/null +++ b/CAN-binder/libs/nanopb/tests/regression/issue_229/SConscript @@ -0,0 +1,13 @@ +# Regression test for Issue 229: problem encoding message that has +# multiple oneof fields +Import('env') + +env.NanopbProto('multiple_oneof') + +p = env.Program(["multiple_oneof.c", + "multiple_oneof.pb.c", + "$COMMON/pb_decode.o", + "$COMMON/pb_encode.o", + "$COMMON/pb_common.o"]) +env.RunTest(p) + diff --git a/CAN-binder/libs/nanopb/tests/regression/issue_229/multiple_oneof.c b/CAN-binder/libs/nanopb/tests/regression/issue_229/multiple_oneof.c new file mode 100644 index 0000000..902248d --- /dev/null +++ b/CAN-binder/libs/nanopb/tests/regression/issue_229/multiple_oneof.c @@ -0,0 +1,35 @@ +#include "multiple_oneof.pb.h" +#include <unittests.h> +#include <pb_encode.h> +#include <pb_decode.h> + +int main() +{ + int status = 0; + uint8_t buf[128]; + size_t msglen; + + { + pb_ostream_t stream = pb_ostream_from_buffer(buf, sizeof(buf)); + MainMessage msg = MainMessage_init_zero; + msg.which_oneof1 = MainMessage_oneof1_uint32_tag; + msg.oneof1.oneof1_uint32 = 1234; + msg.which_oneof2 = MainMessage_oneof2_uint32_tag; + msg.oneof2.oneof2_uint32 = 5678; + TEST(pb_encode(&stream, MainMessage_fields, &msg)); + msglen = stream.bytes_written; + } + + { + pb_istream_t stream = pb_istream_from_buffer(buf, msglen); + MainMessage msg = MainMessage_init_zero; + TEST(pb_decode(&stream, MainMessage_fields, &msg)); + TEST(msg.which_oneof1 == MainMessage_oneof1_uint32_tag); + TEST(msg.oneof1.oneof1_uint32 == 1234); + TEST(msg.which_oneof2 == MainMessage_oneof2_uint32_tag); + TEST(msg.oneof2.oneof2_uint32 == 5678); + } + + return status; +} + diff --git a/CAN-binder/libs/nanopb/tests/regression/issue_229/multiple_oneof.proto b/CAN-binder/libs/nanopb/tests/regression/issue_229/multiple_oneof.proto new file mode 100644 index 0000000..22373e1 --- /dev/null +++ b/CAN-binder/libs/nanopb/tests/regression/issue_229/multiple_oneof.proto @@ -0,0 +1,11 @@ +syntax = "proto2"; + +message MainMessage { + oneof oneof1 { + uint32 oneof1_uint32 = 1; + } + oneof oneof2 { + uint32 oneof2_uint32 = 2; + } +} + diff --git a/CAN-binder/libs/nanopb/tests/regression/issue_242/SConscript b/CAN-binder/libs/nanopb/tests/regression/issue_242/SConscript new file mode 100644 index 0000000..000063e --- /dev/null +++ b/CAN-binder/libs/nanopb/tests/regression/issue_242/SConscript @@ -0,0 +1,13 @@ +# Regression test for Issue 242: pb_encode does not encode tag for +# extension fields that is all zeros +Import('env') + +env.NanopbProto('zero_value') + +p = env.Program(["zero_value.c", + "zero_value.pb.c", + "$COMMON/pb_decode.o", + "$COMMON/pb_encode.o", + "$COMMON/pb_common.o"]) +env.RunTest(p) + diff --git a/CAN-binder/libs/nanopb/tests/regression/issue_242/zero_value.c b/CAN-binder/libs/nanopb/tests/regression/issue_242/zero_value.c new file mode 100644 index 0000000..b3d96b7 --- /dev/null +++ b/CAN-binder/libs/nanopb/tests/regression/issue_242/zero_value.c @@ -0,0 +1,51 @@ +#include <unittests.h> +#include <pb_encode.h> +#include <pb_decode.h> +#include <string.h> +#include "zero_value.pb.h" + +int main() +{ + int status = 0; + + COMMENT("Test extension fields with zero values"); + { + uint8_t buffer[256] = {0}; + pb_ostream_t ostream; + int32_t value = 0; + Extendable source = {0}; + + pb_extension_t source_ext = {0}; + source_ext.type = &opt_int32; + source_ext.dest = &value; + source.extensions = &source_ext; + + ostream = pb_ostream_from_buffer(buffer, sizeof(buffer)); + TEST(pb_encode(&ostream, Extendable_fields, &source)); + + TEST(ostream.bytes_written == 2); + TEST(memcmp(buffer, "\x58\x00", 2) == 0); + } + + /* Note: There never was a bug here, but this check is included + * in the regression test because the logic is closely related. + */ + COMMENT("Test pointer fields with zero values"); + { + uint8_t buffer[256] = {0}; + pb_ostream_t ostream; + int32_t value = 0; + PointerMessage source = {0}; + + source.opt_int32 = &value; + + ostream = pb_ostream_from_buffer(buffer, sizeof(buffer)); + TEST(pb_encode(&ostream, PointerMessage_fields, &source)); + + TEST(ostream.bytes_written == 2); + TEST(memcmp(buffer, "\x58\x00", 2) == 0); + } + + return status; +} + diff --git a/CAN-binder/libs/nanopb/tests/regression/issue_242/zero_value.proto b/CAN-binder/libs/nanopb/tests/regression/issue_242/zero_value.proto new file mode 100644 index 0000000..020a39a --- /dev/null +++ b/CAN-binder/libs/nanopb/tests/regression/issue_242/zero_value.proto @@ -0,0 +1,15 @@ +syntax = "proto2"; +import "nanopb.proto"; + +message Extendable { + extensions 10 to 100; +} + +extend Extendable { + optional int32 opt_int32 = 11; +} + +message PointerMessage { + optional int32 opt_int32 = 11 [(nanopb).type = FT_POINTER]; +} + diff --git a/CAN-binder/libs/nanopb/tests/regression/issue_247/SConscript b/CAN-binder/libs/nanopb/tests/regression/issue_247/SConscript new file mode 100644 index 0000000..b41e9f2 --- /dev/null +++ b/CAN-binder/libs/nanopb/tests/regression/issue_247/SConscript @@ -0,0 +1,14 @@ +# Test that pb_check_proto3_default_value() correctly skips padding +# bytes in submessage structures. + +Import("env") + +env.NanopbProto("padding") + +p = env.Program(["padding.c", + "padding.pb.c", + "$COMMON/pb_encode.o", + "$COMMON/pb_common.o"]) + +env.RunTest(p) + diff --git a/CAN-binder/libs/nanopb/tests/regression/issue_247/padding.c b/CAN-binder/libs/nanopb/tests/regression/issue_247/padding.c new file mode 100644 index 0000000..8860179 --- /dev/null +++ b/CAN-binder/libs/nanopb/tests/regression/issue_247/padding.c @@ -0,0 +1,32 @@ +#include <pb_encode.h> +#include <unittests.h> +#include <string.h> +#include "padding.pb.h" + +int main() +{ + int status = 0; + + TestMessage msg; + + /* Set padding bytes to garbage */ + memset(&msg, 0xAA, sizeof(msg)); + + /* Set all meaningful fields to 0 */ + msg.submsg.boolfield = false; + msg.submsg.intfield = 0; + + /* Test encoding */ + { + pb_byte_t buf[128] = {0}; + pb_ostream_t stream = pb_ostream_from_buffer(buf, sizeof(buf)); + TEST(pb_encode(&stream, TestMessage_fields, &msg)); + + /* Because all fields have zero values, proto3 encoder + * shouldn't write out anything. */ + TEST(stream.bytes_written == 0); + } + + return status; +} + diff --git a/CAN-binder/libs/nanopb/tests/regression/issue_247/padding.proto b/CAN-binder/libs/nanopb/tests/regression/issue_247/padding.proto new file mode 100644 index 0000000..20bddac --- /dev/null +++ b/CAN-binder/libs/nanopb/tests/regression/issue_247/padding.proto @@ -0,0 +1,12 @@ +syntax = "proto3"; +import "nanopb.proto"; + +message SubMessage { + bool boolfield = 1; + int64 intfield = 2; +} + +message TestMessage { + SubMessage submsg = 1; +} + diff --git a/CAN-binder/libs/nanopb/tests/regression/issue_249/SConscript b/CAN-binder/libs/nanopb/tests/regression/issue_249/SConscript new file mode 100644 index 0000000..ba66712 --- /dev/null +++ b/CAN-binder/libs/nanopb/tests/regression/issue_249/SConscript @@ -0,0 +1,12 @@ +# Regression test for Issue 249: proto3 mode pb_decode() corrupts callback fields +Import('env') + +env.NanopbProto('test') + +p = env.Program(["test.c", + "test.pb.c", + "$COMMON/pb_decode.o", + "$COMMON/pb_encode.o", + "$COMMON/pb_common.o"]) +env.RunTest(p) + diff --git a/CAN-binder/libs/nanopb/tests/regression/issue_249/test.c b/CAN-binder/libs/nanopb/tests/regression/issue_249/test.c new file mode 100644 index 0000000..a37180f --- /dev/null +++ b/CAN-binder/libs/nanopb/tests/regression/issue_249/test.c @@ -0,0 +1,59 @@ +#include "test.pb.h" +#include <unittests.h> +#include <pb_encode.h> +#include <pb_decode.h> + +static bool write_array(pb_ostream_t *stream, const pb_field_t *field, void * const *arg) +{ + int i; + for (i = 0; i < 5; i++) + { + if (!pb_encode_tag_for_field(stream, field)) + return false; + if (!pb_encode_varint(stream, 1000 + i)) + return false; + } + + return true; +} + +static bool read_array(pb_istream_t *stream, const pb_field_t *field, void **arg) +{ + uint32_t i; + int *sum = *arg; + + if (!pb_decode_varint32(stream, &i)) + return false; + + *sum += i; + + return true; +} + +int main() +{ + int status = 0; + pb_byte_t buf[128] = {0}; + pb_size_t msglen; + + { + MainMessage msg = MainMessage_init_zero; + pb_ostream_t stream = pb_ostream_from_buffer(buf, sizeof(buf)); + msg.submsg.foo.funcs.encode = &write_array; + TEST(pb_encode(&stream, MainMessage_fields, &msg)); + msglen = stream.bytes_written; + } + + { + MainMessage msg = MainMessage_init_zero; + pb_istream_t stream = pb_istream_from_buffer(buf, msglen); + int sum = 0; + msg.submsg.foo.funcs.decode = &read_array; + msg.submsg.foo.arg = ∑ + TEST(pb_decode(&stream, MainMessage_fields, &msg)); + TEST(sum == 1000 + 1001 + 1002 + 1003 + 1004); + } + + return status; +} + diff --git a/CAN-binder/libs/nanopb/tests/regression/issue_249/test.proto b/CAN-binder/libs/nanopb/tests/regression/issue_249/test.proto new file mode 100644 index 0000000..eaa2abd --- /dev/null +++ b/CAN-binder/libs/nanopb/tests/regression/issue_249/test.proto @@ -0,0 +1,10 @@ +syntax = "proto3"; + +message SubMessage { + repeated int32 foo = 1; +} + +message MainMessage { + SubMessage submsg = 1; +} + diff --git a/CAN-binder/libs/nanopb/tests/regression/issue_253/SConscript b/CAN-binder/libs/nanopb/tests/regression/issue_253/SConscript new file mode 100644 index 0000000..5a16948 --- /dev/null +++ b/CAN-binder/libs/nanopb/tests/regression/issue_253/SConscript @@ -0,0 +1,15 @@ +# Regression test for Issue 253: Wrong calculated message maximum size + +Import('env') + +env.NanopbProto('short_array') + +p = env.Program(['short_array.c', + 'short_array.pb.c', + "$COMMON/pb_decode.o", + "$COMMON/pb_encode.o", + "$COMMON/pb_common.o"]) + +env.RunTest(p) + + diff --git a/CAN-binder/libs/nanopb/tests/regression/issue_253/short_array.c b/CAN-binder/libs/nanopb/tests/regression/issue_253/short_array.c new file mode 100644 index 0000000..5ed6c3f --- /dev/null +++ b/CAN-binder/libs/nanopb/tests/regression/issue_253/short_array.c @@ -0,0 +1,24 @@ +#include <unittests.h> +#include <pb_encode.h> +#include "short_array.pb.h" + +int main() +{ + int status = 0; + + COMMENT("Test message length calculation for short arrays"); + { + uint8_t buffer[TestMessage_size] = {0}; + pb_ostream_t ostream = pb_ostream_from_buffer(buffer, TestMessage_size); + TestMessage msg = TestMessage_init_zero; + + msg.rep_uint32_count = 1; + msg.rep_uint32[0] = (1 << 31); + + TEST(pb_encode(&ostream, TestMessage_fields, &msg)); + TEST(ostream.bytes_written == TestMessage_size); + } + + return status; +} + diff --git a/CAN-binder/libs/nanopb/tests/regression/issue_253/short_array.proto b/CAN-binder/libs/nanopb/tests/regression/issue_253/short_array.proto new file mode 100644 index 0000000..5a5d8a3 --- /dev/null +++ b/CAN-binder/libs/nanopb/tests/regression/issue_253/short_array.proto @@ -0,0 +1,7 @@ +syntax = "proto2"; +import "nanopb.proto"; + +message TestMessage { + repeated uint32 rep_uint32 = 1 [(nanopb).max_count = 1]; +} + diff --git a/CAN-binder/libs/nanopb/tests/regression/issue_256/SConscript b/CAN-binder/libs/nanopb/tests/regression/issue_256/SConscript new file mode 100644 index 0000000..b2c3e86 --- /dev/null +++ b/CAN-binder/libs/nanopb/tests/regression/issue_256/SConscript @@ -0,0 +1,16 @@ +# Regression test for Issue 256: Proto3 mode skips submessages even when +# later array fields have non-zero value + +Import('env') + +env.NanopbProto('submsg_array') + +p = env.Program(['submsg_array.c', + 'submsg_array.pb.c', + "$COMMON/pb_decode.o", + "$COMMON/pb_encode.o", + "$COMMON/pb_common.o"]) + +env.RunTest(p) + + diff --git a/CAN-binder/libs/nanopb/tests/regression/issue_256/submsg_array.c b/CAN-binder/libs/nanopb/tests/regression/issue_256/submsg_array.c new file mode 100644 index 0000000..c63bd30 --- /dev/null +++ b/CAN-binder/libs/nanopb/tests/regression/issue_256/submsg_array.c @@ -0,0 +1,38 @@ +#include <unittests.h> +#include <pb_encode.h> +#include <pb_decode.h> +#include "submsg_array.pb.h" + +int main() +{ + int status = 0; + + COMMENT("Test encoding for submessage with array"); + { + uint8_t buffer[TestMessage_size] = {0}; + pb_ostream_t ostream = pb_ostream_from_buffer(buffer, TestMessage_size); + TestMessage msg = TestMessage_init_zero; + + msg.submsg.rep_uint32_count = 3; + msg.submsg.rep_uint32[0] = 0; + msg.submsg.rep_uint32[1] = 1; + msg.submsg.rep_uint32[2] = 2; + + TEST(pb_encode(&ostream, TestMessage_fields, &msg)); + TEST(ostream.bytes_written > 0); + + { + pb_istream_t istream = pb_istream_from_buffer(buffer, ostream.bytes_written); + TestMessage msg2 = TestMessage_init_zero; + + TEST(pb_decode(&istream, TestMessage_fields, &msg2)); + TEST(msg2.submsg.rep_uint32_count == 3); + TEST(msg2.submsg.rep_uint32[0] == 0); + TEST(msg2.submsg.rep_uint32[1] == 1); + TEST(msg2.submsg.rep_uint32[2] == 2); + } + } + + return status; +} + diff --git a/CAN-binder/libs/nanopb/tests/regression/issue_256/submsg_array.proto b/CAN-binder/libs/nanopb/tests/regression/issue_256/submsg_array.proto new file mode 100644 index 0000000..4964a05 --- /dev/null +++ b/CAN-binder/libs/nanopb/tests/regression/issue_256/submsg_array.proto @@ -0,0 +1,11 @@ +syntax = "proto3"; +import "nanopb.proto"; + +message SubMessage { + repeated uint32 rep_uint32 = 1 [(nanopb).max_count = 3]; +} + +message TestMessage { + SubMessage submsg = 1; +} + |