aboutsummaryrefslogtreecommitdiffstats
path: root/tests/alltypes
diff options
context:
space:
mode:
authorPetteri Aimonen <jpa@git.mail.kapsi.fi>2013-12-21 12:41:20 +0200
committerPetteri Aimonen <jpa@git.mail.kapsi.fi>2013-12-21 12:41:20 +0200
commitcd9004089fd4ae42cc68fd15f085f42c48494cb4 (patch)
treef0b690d8866e2f4ae84a0f5cdf9a0a02d3755ec7 /tests/alltypes
parentee5b12c537115b113ce01708d4a86a4062cdb182 (diff)
Add test for extreme integer values (INT32_MAX etc.) in AllTypes.
Diffstat (limited to 'tests/alltypes')
-rw-r--r--tests/alltypes/alltypes.proto21
-rw-r--r--tests/alltypes/decode_alltypes.c11
-rw-r--r--tests/alltypes/encode_alltypes.c11
3 files changed, 43 insertions, 0 deletions
diff --git a/tests/alltypes/alltypes.proto b/tests/alltypes/alltypes.proto
index 2bc8efcd..234b7236 100644
--- a/tests/alltypes/alltypes.proto
+++ b/tests/alltypes/alltypes.proto
@@ -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;
diff --git a/tests/alltypes/decode_alltypes.c b/tests/alltypes/decode_alltypes.c
index ee2e115c..db72bb9f 100644
--- a/tests/alltypes/decode_alltypes.c
+++ b/tests/alltypes/decode_alltypes.c
@@ -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;
diff --git a/tests/alltypes/encode_alltypes.c b/tests/alltypes/encode_alltypes.c
index 9a2c6f60..fa8eec94 100644
--- a/tests/alltypes/encode_alltypes.c
+++ b/tests/alltypes/encode_alltypes.c
@@ -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 */