Skip to content

Commit

Permalink
Add testcase for issue nanopb#229
Browse files Browse the repository at this point in the history
  • Loading branch information
PetteriAimonen committed Dec 31, 2016
1 parent 16f08f9 commit 90a19bf
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 0 deletions.
13 changes: 13 additions & 0 deletions tests/regression/issue_229/SConscript
Original file line number Diff line number Diff line change
@@ -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)

35 changes: 35 additions & 0 deletions tests/regression/issue_229/multiple_oneof.c
Original file line number Diff line number Diff line change
@@ -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;
}

11 changes: 11 additions & 0 deletions tests/regression/issue_229/multiple_oneof.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
syntax = "proto2";

message MainMessage {
oneof oneof1 {
uint32 oneof1_uint32 = 1;
}
oneof oneof2 {
uint32 oneof2_uint32 = 2;
}
}

0 comments on commit 90a19bf

Please sign in to comment.