diff options
author | Petteri Aimonen <jpa@git.mail.kapsi.fi> | 2015-01-11 19:47:27 +0200 |
---|---|---|
committer | Petteri Aimonen <jpa@git.mail.kapsi.fi> | 2015-01-11 19:47:27 +0200 |
commit | f4b3a1c2027e330c52e661252acba6f69742fca6 (patch) | |
tree | fcb18a08ca5cad3d79ce9cc68f24e801780ed80f /tests | |
parent | d2e023e3e5ef888e176292f149d1ba93ba270c94 (diff) |
Add oneofs to AllTypes test case
Diffstat (limited to 'tests')
-rw-r--r-- | tests/alltypes/alltypes.proto | 6 | ||||
-rw-r--r-- | tests/alltypes/decode_alltypes.c | 6 | ||||
-rw-r--r-- | tests/alltypes/encode_alltypes.c | 4 | ||||
-rw-r--r-- | tests/alltypes_callback/alltypes.options | 1 | ||||
-rw-r--r-- | tests/alltypes_callback/decode_alltypes_callback.c | 5 | ||||
-rw-r--r-- | tests/alltypes_callback/encode_alltypes_callback.c | 5 | ||||
-rw-r--r-- | tests/alltypes_pointer/SConscript | 2 | ||||
-rw-r--r-- | tests/alltypes_pointer/decode_alltypes_pointer.c | 6 | ||||
-rw-r--r-- | tests/alltypes_pointer/encode_alltypes_pointer.c | 6 | ||||
-rw-r--r-- | tests/field_size_16/alltypes.proto | 6 | ||||
-rw-r--r-- | tests/field_size_32/alltypes.proto | 6 | ||||
-rw-r--r-- | tests/io_errors_pointers/SConscript | 2 |
12 files changed, 53 insertions, 2 deletions
diff --git a/tests/alltypes/alltypes.proto b/tests/alltypes/alltypes.proto index db83c9a6..28eaf0be 100644 --- a/tests/alltypes/alltypes.proto +++ b/tests/alltypes/alltypes.proto @@ -101,6 +101,12 @@ message AllTypes { optional MyEnum opt_enum = 57 [default = Second]; optional EmptyMessage opt_emptymsg = 58; + oneof oneof + { + SubMessage oneof_msg1 = 59; + EmptyMessage oneof_msg2 = 60; + } + // Check that extreme integer values are handled correctly required Limits req_limits = 98; diff --git a/tests/alltypes/decode_alltypes.c b/tests/alltypes/decode_alltypes.c index 67cb72c4..458e5112 100644 --- a/tests/alltypes/decode_alltypes.c +++ b/tests/alltypes/decode_alltypes.c @@ -125,6 +125,8 @@ bool check_alltypes(pb_istream_t *stream, int mode) TEST(alltypes.has_opt_enum == false); TEST(alltypes.opt_enum == MyEnum_Second); TEST(alltypes.has_opt_emptymsg == false); + + TEST(alltypes.which_oneof == 0); } else { @@ -170,6 +172,10 @@ bool check_alltypes(pb_istream_t *stream, int mode) TEST(alltypes.has_opt_enum == true); TEST(alltypes.opt_enum == MyEnum_Truth); TEST(alltypes.has_opt_emptymsg == true); + + TEST(alltypes.which_oneof == AllTypes_oneof_msg1_tag); + TEST(strcmp(alltypes.oneof.oneof_msg1.substuff1, "4059") == 0); + TEST(alltypes.oneof.oneof_msg1.substuff2 == 4059); } TEST(alltypes.req_limits.int32_min == INT32_MIN); diff --git a/tests/alltypes/encode_alltypes.c b/tests/alltypes/encode_alltypes.c index deec7903..16f4b298 100644 --- a/tests/alltypes/encode_alltypes.c +++ b/tests/alltypes/encode_alltypes.c @@ -121,6 +121,10 @@ int main(int argc, char **argv) alltypes.has_opt_enum = true; alltypes.opt_enum = MyEnum_Truth; alltypes.has_opt_emptymsg = true; + + alltypes.which_oneof = AllTypes_oneof_msg1_tag; + strcpy(alltypes.oneof.oneof_msg1.substuff1, "4059"); + alltypes.oneof.oneof_msg1.substuff2 = 4059; } alltypes.end = 1099; diff --git a/tests/alltypes_callback/alltypes.options b/tests/alltypes_callback/alltypes.options index a9c55ece..daee5224 100644 --- a/tests/alltypes_callback/alltypes.options +++ b/tests/alltypes_callback/alltypes.options @@ -1,3 +1,4 @@ # Generate all fields as callbacks. AllTypes.* type:FT_CALLBACK SubMessage.substuff1 max_size:16 +AllTypes.oneof no_unions:true diff --git a/tests/alltypes_callback/decode_alltypes_callback.c b/tests/alltypes_callback/decode_alltypes_callback.c index b6017fe6..c53ab6ed 100644 --- a/tests/alltypes_callback/decode_alltypes_callback.c +++ b/tests/alltypes_callback/decode_alltypes_callback.c @@ -214,6 +214,8 @@ bool check_alltypes(pb_istream_t *stream, int mode) int64_t opt_sfixed64 = 3052; double opt_double = 3053.0f; SubMessage opt_submsg = {"3056", 3056}; + + SubMessage oneof_msg1 = {"4059", 4059}; /* Bind callbacks for required fields */ AllTypes alltypes; @@ -392,6 +394,9 @@ bool check_alltypes(pb_istream_t *stream, int mode) alltypes.opt_enum.arg = (void*)MyEnum_Truth; alltypes.opt_emptymsg.funcs.decode = &read_emptymsg; + + alltypes.oneof_msg1.funcs.decode = &read_submsg; + alltypes.oneof_msg1.arg = &oneof_msg1; } return pb_decode(stream, AllTypes_fields, &alltypes); diff --git a/tests/alltypes_callback/encode_alltypes_callback.c b/tests/alltypes_callback/encode_alltypes_callback.c index 10560b19..abc43f58 100644 --- a/tests/alltypes_callback/encode_alltypes_callback.c +++ b/tests/alltypes_callback/encode_alltypes_callback.c @@ -202,6 +202,8 @@ int main(int argc, char **argv) double opt_double = 3053.0f; SubMessage opt_submsg = {"3056", 3056}; + SubMessage oneof_msg1 = {"4059", 4059}; + /* Bind callbacks for required fields */ AllTypes alltypes = {{{0}}}; @@ -372,6 +374,9 @@ int main(int argc, char **argv) alltypes.opt_enum.arg = (void*)MyEnum_Truth; alltypes.opt_emptymsg.funcs.encode = &write_emptymsg; + + alltypes.oneof_msg1.funcs.encode = &write_submsg; + alltypes.oneof_msg1.arg = &oneof_msg1; } alltypes.end.funcs.encode = &write_varint; diff --git a/tests/alltypes_pointer/SConscript b/tests/alltypes_pointer/SConscript index 52856f6e..b095ae03 100644 --- a/tests/alltypes_pointer/SConscript +++ b/tests/alltypes_pointer/SConscript @@ -27,7 +27,7 @@ valgrind = env.WhereIs('valgrind') kwargs = {} if valgrind: kwargs['COMMAND'] = valgrind - kwargs['ARGS'] = ["-q", dec[0].abspath] + kwargs['ARGS'] = ["-q", "--error-exitcode=99", dec[0].abspath] env.RunTest("decode_alltypes.output", [dec, "encode_alltypes_pointer.output"], **kwargs) diff --git a/tests/alltypes_pointer/decode_alltypes_pointer.c b/tests/alltypes_pointer/decode_alltypes_pointer.c index 1e719019..1dbb6c55 100644 --- a/tests/alltypes_pointer/decode_alltypes_pointer.c +++ b/tests/alltypes_pointer/decode_alltypes_pointer.c @@ -99,6 +99,8 @@ bool check_alltypes(pb_istream_t *stream, int mode) TEST(alltypes.opt_bytes == NULL); TEST(alltypes.opt_submsg == NULL); TEST(alltypes.opt_enum == NULL); + + TEST(alltypes.which_oneof == 0); } else { @@ -125,6 +127,10 @@ bool check_alltypes(pb_istream_t *stream, int mode) TEST(alltypes.opt_submsg && *alltypes.opt_submsg->substuff2 == 3056); TEST(alltypes.opt_enum && *alltypes.opt_enum == MyEnum_Truth); TEST(alltypes.opt_emptymsg); + + TEST(alltypes.which_oneof == AllTypes_oneof_msg1_tag); + TEST(alltypes.oneof.oneof_msg1 && strcmp(alltypes.oneof.oneof_msg1->substuff1, "4059") == 0); + TEST(alltypes.oneof.oneof_msg1->substuff2 && *alltypes.oneof.oneof_msg1->substuff2 == 4059); } TEST(alltypes.req_limits->int32_min && *alltypes.req_limits->int32_min == INT32_MIN); diff --git a/tests/alltypes_pointer/encode_alltypes_pointer.c b/tests/alltypes_pointer/encode_alltypes_pointer.c index c128569b..7b52662f 100644 --- a/tests/alltypes_pointer/encode_alltypes_pointer.c +++ b/tests/alltypes_pointer/encode_alltypes_pointer.c @@ -84,6 +84,9 @@ int main(int argc, char **argv) MyEnum opt_enum = MyEnum_Truth; EmptyMessage opt_emptymsg = {0}; + static int32_t oneof_substuff = 4059; + SubMessage oneof_msg1 = {"4059", &oneof_substuff}; + /* Values for the Limits message. */ static int32_t int32_min = INT32_MIN; static int32_t int32_max = INT32_MAX; @@ -164,6 +167,9 @@ int main(int argc, char **argv) alltypes.opt_submsg = &opt_submsg; alltypes.opt_enum = &opt_enum; alltypes.opt_emptymsg = &opt_emptymsg; + + alltypes.which_oneof = AllTypes_oneof_msg1_tag; + alltypes.oneof.oneof_msg1 = &oneof_msg1; } alltypes.end = &end; diff --git a/tests/field_size_16/alltypes.proto b/tests/field_size_16/alltypes.proto index 81693c00..039391fc 100644 --- a/tests/field_size_16/alltypes.proto +++ b/tests/field_size_16/alltypes.proto @@ -101,6 +101,12 @@ message AllTypes { optional MyEnum opt_enum = 10057 [default = Second]; optional EmptyMessage opt_emptymsg = 10058; + oneof oneof + { + SubMessage oneof_msg1 = 10059; + EmptyMessage oneof_msg2 = 10060; + } + // Check that extreme integer values are handled correctly required Limits req_limits = 98; diff --git a/tests/field_size_32/alltypes.proto b/tests/field_size_32/alltypes.proto index 81717bbc..5749e0d4 100644 --- a/tests/field_size_32/alltypes.proto +++ b/tests/field_size_32/alltypes.proto @@ -101,6 +101,12 @@ message AllTypes { optional MyEnum opt_enum = 10057 [default = Second]; optional EmptyMessage opt_emptymsg = 10058; + oneof oneof + { + SubMessage oneof_msg1 = 10059; + EmptyMessage oneof_msg2 = 10060; + } + // Check that extreme integer values are handled correctly required Limits req_limits = 98; diff --git a/tests/io_errors_pointers/SConscript b/tests/io_errors_pointers/SConscript index 8d23f603..03727df9 100644 --- a/tests/io_errors_pointers/SConscript +++ b/tests/io_errors_pointers/SConscript @@ -19,7 +19,7 @@ valgrind = env.WhereIs('valgrind') kwargs = {} if valgrind: kwargs['COMMAND'] = valgrind - kwargs['ARGS'] = ["-q", ioerr[0].abspath] + kwargs['ARGS'] = ["-q", "--error-exitcode=99", ioerr[0].abspath] env.RunTest("io_errors.output", [ioerr, "$BUILD/alltypes/encode_alltypes.output"], **kwargs) |