Add oneofs to AllTypes test case

This commit is contained in:
Petteri Aimonen
2015-01-11 19:47:27 +02:00
parent d2e023e3e5
commit f4b3a1c202
12 changed files with 53 additions and 2 deletions

View File

@@ -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;

View File

@@ -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);

View File

@@ -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;

View File

@@ -1,3 +1,4 @@
# Generate all fields as callbacks.
AllTypes.* type:FT_CALLBACK
SubMessage.substuff1 max_size:16
AllTypes.oneof no_unions:true

View File

@@ -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);

View File

@@ -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;

View File

@@ -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)

View File

@@ -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);

View File

@@ -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;

View File

@@ -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;

View File

@@ -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;

View File

@@ -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)