summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorPetteri Aimonen <jpa@git.mail.kapsi.fi>2017-04-14 11:45:57 +0300
committerPetteri Aimonen <jpa@git.mail.kapsi.fi>2017-04-14 11:45:57 +0300
commite75d20b659aced782a0017244836e415164e2d0e (patch)
tree13962119046a17c7592b993bfc49399e0e8772a6 /tests
parent651bdc45f2180b17c132470ff1a3a515dbffaa78 (diff)
Add testcase for issue #256
Diffstat (limited to 'tests')
-rw-r--r--tests/regression/issue_256/SConscript16
-rw-r--r--tests/regression/issue_256/submsg_array.c38
-rw-r--r--tests/regression/issue_256/submsg_array.proto11
3 files changed, 65 insertions, 0 deletions
diff --git a/tests/regression/issue_256/SConscript b/tests/regression/issue_256/SConscript
new file mode 100644
index 00000000..b2c3e864
--- /dev/null
+++ b/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/tests/regression/issue_256/submsg_array.c b/tests/regression/issue_256/submsg_array.c
new file mode 100644
index 00000000..c63bd30a
--- /dev/null
+++ b/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/tests/regression/issue_256/submsg_array.proto b/tests/regression/issue_256/submsg_array.proto
new file mode 100644
index 00000000..4964a05f
--- /dev/null
+++ b/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;
+}
+