Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nanopb/nanopb.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorPetteri Aimonen <jpa@git.mail.kapsi.fi>2013-12-21 14:41:20 +0400
committerPetteri Aimonen <jpa@git.mail.kapsi.fi>2013-12-21 14:41:20 +0400
commitcd9004089fd4ae42cc68fd15f085f42c48494cb4 (patch)
treef0b690d8866e2f4ae84a0f5cdf9a0a02d3755ec7 /tests
parentee5b12c537115b113ce01708d4a86a4062cdb182 (diff)
Add test for extreme integer values (INT32_MAX etc.) in AllTypes.
Diffstat (limited to 'tests')
-rw-r--r--tests/alltypes/alltypes.proto21
-rw-r--r--tests/alltypes/decode_alltypes.c11
-rw-r--r--tests/alltypes/encode_alltypes.c11
-rw-r--r--tests/cxx_main_program/SConscript4
-rw-r--r--tests/extra_fields/SConscript4
-rw-r--r--tests/field_size_16/alltypes.proto21
-rw-r--r--tests/field_size_32/alltypes.proto21
7 files changed, 92 insertions, 1 deletions
diff --git a/tests/alltypes/alltypes.proto b/tests/alltypes/alltypes.proto
index 2bc8efc..234b723 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 ee2e115..db72bb9 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 9a2c6f6..fa8eec9 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 */
diff --git a/tests/cxx_main_program/SConscript b/tests/cxx_main_program/SConscript
index 4bca1b1..e78c6b3 100644
--- a/tests/cxx_main_program/SConscript
+++ b/tests/cxx_main_program/SConscript
@@ -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)
diff --git a/tests/extra_fields/SConscript b/tests/extra_fields/SConscript
index 797c4e6..75ac5c5 100644
--- a/tests/extra_fields/SConscript
+++ b/tests/extra_fields/SConscript
@@ -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'])
diff --git a/tests/field_size_16/alltypes.proto b/tests/field_size_16/alltypes.proto
index b981760..7494853 100644
--- a/tests/field_size_16/alltypes.proto
+++ b/tests/field_size_16/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 = 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;
diff --git a/tests/field_size_32/alltypes.proto b/tests/field_size_32/alltypes.proto
index 3d1d856..17f17ee 100644
--- a/tests/field_size_32/alltypes.proto
+++ b/tests/field_size_32/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 = 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;