Add test for extreme integer values (INT32_MAX etc.) in AllTypes.

This commit is contained in:
Petteri Aimonen
2013-12-21 12:41:20 +02:00
parent ee5b12c537
commit cd9004089f
7 changed files with 92 additions and 1 deletions

View File

@@ -8,6 +8,24 @@ message EmptyMessage {
}
enum HugeEnum {
Negative = -2147483647; /* protoc doesn't accept -2147483648 here */
Positive = 2147483647;
}
message Limits {
required int32 int32_min = 1;
required int32 int32_max = 2;
required uint32 uint32_min = 3;
required uint32 uint32_max = 4;
required int64 int64_min = 5;
required int64 int64_max = 6;
required uint64 uint64_min = 7;
required uint64 uint64_max = 8;
required HugeEnum enum_min = 9;
required HugeEnum enum_max = 10;
}
enum MyEnum {
Zero = 0;
First = 1;
@@ -83,6 +101,9 @@ message AllTypes {
optional MyEnum opt_enum = 57 [default = Second];
optional EmptyMessage opt_emptymsg = 58;
// Check that extreme integer values are handled correctly
required Limits req_limits = 98;
// Just to make sure that the size of the fields has been calculated
// properly, i.e. otherwise a bug in last field might not be detected.
required int32 end = 99;

View File

@@ -170,6 +170,17 @@ bool check_alltypes(pb_istream_t *stream, int mode)
TEST(alltypes.has_opt_emptymsg == true);
}
TEST(alltypes.req_limits.int32_min == INT32_MIN);
TEST(alltypes.req_limits.int32_max == INT32_MAX);
TEST(alltypes.req_limits.uint32_min == 0);
TEST(alltypes.req_limits.uint32_max == UINT32_MAX);
TEST(alltypes.req_limits.int64_min == INT64_MIN);
TEST(alltypes.req_limits.int64_max == INT64_MAX);
TEST(alltypes.req_limits.uint64_min == 0);
TEST(alltypes.req_limits.uint64_max == UINT64_MAX);
TEST(alltypes.req_limits.enum_min == HugeEnum_Negative);
TEST(alltypes.req_limits.enum_max == HugeEnum_Positive);
TEST(alltypes.end == 1099);
return true;

View File

@@ -67,6 +67,17 @@ int main(int argc, char **argv)
alltypes.rep_enum_count = 5; alltypes.rep_enum[4] = MyEnum_Truth;
alltypes.rep_emptymsg_count = 5;
alltypes.req_limits.int32_min = INT32_MIN;
alltypes.req_limits.int32_max = INT32_MAX;
alltypes.req_limits.uint32_min = 0;
alltypes.req_limits.uint32_max = UINT32_MAX;
alltypes.req_limits.int64_min = INT64_MIN;
alltypes.req_limits.int64_max = INT64_MAX;
alltypes.req_limits.uint64_min = 0;
alltypes.req_limits.uint64_max = UINT64_MAX;
alltypes.req_limits.enum_min = HugeEnum_Negative;
alltypes.req_limits.enum_max = HugeEnum_Positive;
if (mode != 0)
{
/* Fill in values for optional fields */

View File

@@ -3,6 +3,10 @@
Import("env")
# This is needed to get INT32_MIN etc. macros defined
env = env.Clone()
env.Append(CPPDEFINES = ['__STDC_LIMIT_MACROS'])
# Copy the files to .cxx extension in order to force C++ build.
c = Copy("$TARGET", "$SOURCE")
env.Command("pb_encode.cxx", "#../pb_encode.c", c)

View File

@@ -10,5 +10,7 @@ dec = env.GetBuildPath('$BUILD/basic_stream/${PROGPREFIX}decode_stream${PROGSUFF
env.RunTest('person_with_extra_field_stream.output', [dec, "person_with_extra_field.pb"])
env.Compare(["person_with_extra_field_stream.output", "person_with_extra_field.expected"])
dec2 = env.GetBuildPath('$BUILD/alltypes/${PROGPREFIX}decode_alltypes${PROGSUFFIX}')
# This uses the backwards compatibility alltypes test, so that
# alltypes_with_extra_fields.pb doesn't have to be remade so often.
dec2 = env.GetBuildPath('$BUILD/backwards_compatibility/${PROGPREFIX}decode_legacy${PROGSUFFIX}')
env.RunTest('alltypes_with_extra_fields.output', [dec2, 'alltypes_with_extra_fields.pb'])

View File

@@ -8,6 +8,24 @@ message EmptyMessage {
}
enum HugeEnum {
Negative = -2147483647; /* protoc doesn't accept -2147483648 here */
Positive = 2147483647;
}
message Limits {
required int32 int32_min = 1;
required int32 int32_max = 2;
required uint32 uint32_min = 3;
required uint32 uint32_max = 4;
required int64 int64_min = 5;
required int64 int64_max = 6;
required uint64 uint64_min = 7;
required uint64 uint64_max = 8;
required HugeEnum enum_min = 9;
required HugeEnum enum_max = 10;
}
enum MyEnum {
Zero = 0;
First = 1;
@@ -83,6 +101,9 @@ message AllTypes {
optional MyEnum opt_enum = 10057 [default = Second];
optional EmptyMessage opt_emptymsg = 10058;
// Check that extreme integer values are handled correctly
required Limits req_limits = 98;
// Just to make sure that the size of the fields has been calculated
// properly, i.e. otherwise a bug in last field might not be detected.
required int32 end = 10099;

View File

@@ -8,6 +8,24 @@ message EmptyMessage {
}
enum HugeEnum {
Negative = -2147483647; /* protoc doesn't accept -2147483648 here */
Positive = 2147483647;
}
message Limits {
required int32 int32_min = 1;
required int32 int32_max = 2;
required uint32 uint32_min = 3;
required uint32 uint32_max = 4;
required int64 int64_min = 5;
required int64 int64_max = 6;
required uint64 uint64_min = 7;
required uint64 uint64_max = 8;
required HugeEnum enum_min = 9;
required HugeEnum enum_max = 10;
}
enum MyEnum {
Zero = 0;
First = 1;
@@ -83,6 +101,9 @@ message AllTypes {
optional MyEnum opt_enum = 10057 [default = Second];
optional EmptyMessage opt_emptymsg = 10058;
// Check that extreme integer values are handled correctly
required Limits req_limits = 98;
// Just to make sure that the size of the fields has been calculated
// properly, i.e. otherwise a bug in last field might not be detected.
required int32 end = 13432099;