summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPetteri Aimonen <jpa@git.mail.kapsi.fi>2016-12-31 10:33:19 +0200
committerPetteri Aimonen <jpa@git.mail.kapsi.fi>2016-12-31 10:33:19 +0200
commit90a19bf0368035147a74b9b8edd65d672a03cd00 (patch)
tree023f86c1bef24cbb8c3938e0cf3562b7b9e2b299
parent16f08f9fc8ff73e775cbf54b1024629ca7db0e58 (diff)
Add testcase for issue #229
-rw-r--r--tests/regression/issue_229/SConscript13
-rw-r--r--tests/regression/issue_229/multiple_oneof.c35
-rw-r--r--tests/regression/issue_229/multiple_oneof.proto11
3 files changed, 59 insertions, 0 deletions
diff --git a/tests/regression/issue_229/SConscript b/tests/regression/issue_229/SConscript
new file mode 100644
index 00000000..b0f8376d
--- /dev/null
+++ b/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/tests/regression/issue_229/multiple_oneof.c b/tests/regression/issue_229/multiple_oneof.c
new file mode 100644
index 00000000..902248d0
--- /dev/null
+++ b/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/tests/regression/issue_229/multiple_oneof.proto b/tests/regression/issue_229/multiple_oneof.proto
new file mode 100644
index 00000000..22373e1d
--- /dev/null
+++ b/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;
+ }
+}
+