aboutsummaryrefslogtreecommitdiffhomepage
path: root/third_party/nanopb/tests/regression
diff options
context:
space:
mode:
Diffstat (limited to 'third_party/nanopb/tests/regression')
-rw-r--r--third_party/nanopb/tests/regression/issue_118/SConscript12
-rw-r--r--third_party/nanopb/tests/regression/issue_118/enumdef.proto8
-rw-r--r--third_party/nanopb/tests/regression/issue_118/enumuse.proto7
-rw-r--r--third_party/nanopb/tests/regression/issue_125/SConscript9
-rw-r--r--third_party/nanopb/tests/regression/issue_125/extensionbug.expected3
-rw-r--r--third_party/nanopb/tests/regression/issue_125/extensionbug.options4
-rw-r--r--third_party/nanopb/tests/regression/issue_125/extensionbug.proto18
-rw-r--r--third_party/nanopb/tests/regression/issue_141/SConscript8
-rw-r--r--third_party/nanopb/tests/regression/issue_141/testproto.expected7
-rw-r--r--third_party/nanopb/tests/regression/issue_141/testproto.proto52
-rw-r--r--third_party/nanopb/tests/regression/issue_145/SConscript9
-rw-r--r--third_party/nanopb/tests/regression/issue_145/comments.expected3
-rw-r--r--third_party/nanopb/tests/regression/issue_145/comments.options6
-rw-r--r--third_party/nanopb/tests/regression/issue_145/comments.proto7
-rw-r--r--third_party/nanopb/tests/regression/issue_166/SConscript13
-rw-r--r--third_party/nanopb/tests/regression/issue_166/enum_encoded_size.c43
-rw-r--r--third_party/nanopb/tests/regression/issue_166/enums.proto18
-rw-r--r--third_party/nanopb/tests/regression/issue_172/SConscript16
-rw-r--r--third_party/nanopb/tests/regression/issue_172/msg_size.c9
-rw-r--r--third_party/nanopb/tests/regression/issue_172/submessage/submessage.options1
-rw-r--r--third_party/nanopb/tests/regression/issue_172/submessage/submessage.proto4
-rw-r--r--third_party/nanopb/tests/regression/issue_172/test.proto6
22 files changed, 263 insertions, 0 deletions
diff --git a/third_party/nanopb/tests/regression/issue_118/SConscript b/third_party/nanopb/tests/regression/issue_118/SConscript
new file mode 100644
index 0000000000..833d9dec72
--- /dev/null
+++ b/third_party/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/third_party/nanopb/tests/regression/issue_118/enumdef.proto b/third_party/nanopb/tests/regression/issue_118/enumdef.proto
new file mode 100644
index 0000000000..46845bc9e2
--- /dev/null
+++ b/third_party/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/third_party/nanopb/tests/regression/issue_118/enumuse.proto b/third_party/nanopb/tests/regression/issue_118/enumuse.proto
new file mode 100644
index 0000000000..4afc45211c
--- /dev/null
+++ b/third_party/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/third_party/nanopb/tests/regression/issue_125/SConscript b/third_party/nanopb/tests/regression/issue_125/SConscript
new file mode 100644
index 0000000000..f2155e634d
--- /dev/null
+++ b/third_party/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/third_party/nanopb/tests/regression/issue_125/extensionbug.expected b/third_party/nanopb/tests/regression/issue_125/extensionbug.expected
new file mode 100644
index 0000000000..fc21335405
--- /dev/null
+++ b/third_party/nanopb/tests/regression/issue_125/extensionbug.expected
@@ -0,0 +1,3 @@
+pb_extension_type_t Message2_extras
+uint32_t field2
+
diff --git a/third_party/nanopb/tests/regression/issue_125/extensionbug.options b/third_party/nanopb/tests/regression/issue_125/extensionbug.options
new file mode 100644
index 0000000000..30b464a415
--- /dev/null
+++ b/third_party/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/third_party/nanopb/tests/regression/issue_125/extensionbug.proto b/third_party/nanopb/tests/regression/issue_125/extensionbug.proto
new file mode 100644
index 0000000000..fd1e74f105
--- /dev/null
+++ b/third_party/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/third_party/nanopb/tests/regression/issue_141/SConscript b/third_party/nanopb/tests/regression/issue_141/SConscript
new file mode 100644
index 0000000000..b6526beda5
--- /dev/null
+++ b/third_party/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/third_party/nanopb/tests/regression/issue_141/testproto.expected b/third_party/nanopb/tests/regression/issue_141/testproto.expected
new file mode 100644
index 0000000000..75bc195c8d
--- /dev/null
+++ b/third_party/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/third_party/nanopb/tests/regression/issue_141/testproto.proto b/third_party/nanopb/tests/regression/issue_141/testproto.proto
new file mode 100644
index 0000000000..a445c68a2a
--- /dev/null
+++ b/third_party/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/third_party/nanopb/tests/regression/issue_145/SConscript b/third_party/nanopb/tests/regression/issue_145/SConscript
new file mode 100644
index 0000000000..0b793a7ac4
--- /dev/null
+++ b/third_party/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/third_party/nanopb/tests/regression/issue_145/comments.expected b/third_party/nanopb/tests/regression/issue_145/comments.expected
new file mode 100644
index 0000000000..7f874587b7
--- /dev/null
+++ b/third_party/nanopb/tests/regression/issue_145/comments.expected
@@ -0,0 +1,3 @@
+char foo\[5\];
+char bar\[16\];
+
diff --git a/third_party/nanopb/tests/regression/issue_145/comments.options b/third_party/nanopb/tests/regression/issue_145/comments.options
new file mode 100644
index 0000000000..89959ba235
--- /dev/null
+++ b/third_party/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/third_party/nanopb/tests/regression/issue_145/comments.proto b/third_party/nanopb/tests/regression/issue_145/comments.proto
new file mode 100644
index 0000000000..621779f54c
--- /dev/null
+++ b/third_party/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/third_party/nanopb/tests/regression/issue_166/SConscript b/third_party/nanopb/tests/regression/issue_166/SConscript
new file mode 100644
index 0000000000..c50b91939d
--- /dev/null
+++ b/third_party/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/third_party/nanopb/tests/regression/issue_166/enum_encoded_size.c b/third_party/nanopb/tests/regression/issue_166/enum_encoded_size.c
new file mode 100644
index 0000000000..84e1c7de71
--- /dev/null
+++ b/third_party/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/third_party/nanopb/tests/regression/issue_166/enums.proto b/third_party/nanopb/tests/regression/issue_166/enums.proto
new file mode 100644
index 0000000000..36948044bf
--- /dev/null
+++ b/third_party/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/third_party/nanopb/tests/regression/issue_172/SConscript b/third_party/nanopb/tests/regression/issue_172/SConscript
new file mode 100644
index 0000000000..49c919e805
--- /dev/null
+++ b/third_party/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/third_party/nanopb/tests/regression/issue_172/msg_size.c b/third_party/nanopb/tests/regression/issue_172/msg_size.c
new file mode 100644
index 0000000000..be45acb4fb
--- /dev/null
+++ b/third_party/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/third_party/nanopb/tests/regression/issue_172/submessage/submessage.options b/third_party/nanopb/tests/regression/issue_172/submessage/submessage.options
new file mode 100644
index 0000000000..12fb1984e9
--- /dev/null
+++ b/third_party/nanopb/tests/regression/issue_172/submessage/submessage.options
@@ -0,0 +1 @@
+submessage.data max_size: 16
diff --git a/third_party/nanopb/tests/regression/issue_172/submessage/submessage.proto b/third_party/nanopb/tests/regression/issue_172/submessage/submessage.proto
new file mode 100644
index 0000000000..ce6804afa8
--- /dev/null
+++ b/third_party/nanopb/tests/regression/issue_172/submessage/submessage.proto
@@ -0,0 +1,4 @@
+syntax = "proto2";
+message submessage {
+ required bytes data = 1;
+}
diff --git a/third_party/nanopb/tests/regression/issue_172/test.proto b/third_party/nanopb/tests/regression/issue_172/test.proto
new file mode 100644
index 0000000000..fbd97be5b0
--- /dev/null
+++ b/third_party/nanopb/tests/regression/issue_172/test.proto
@@ -0,0 +1,6 @@
+syntax = "proto2";
+import "submessage.proto";
+
+message testmessage {
+ optional submessage sub = 1;
+}