summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/backwards_compatibility/SConscript11
-rw-r--r--tests/backwards_compatibility/alltypes_legacy.c2
-rw-r--r--tests/backwards_compatibility/decode_legacy.c10
-rw-r--r--tests/backwards_compatibility/encode_legacy.c8
-rw-r--r--tests/basic_stream/SConscript12
-rw-r--r--tests/callbacks/SConscript14
-rw-r--r--tests/extensions/SConscript16
-rw-r--r--tests/extra_fields/SConscript10
-rw-r--r--tests/extra_fields/person_with_extra_field.expected14
-rw-r--r--tests/missing_fields/SConscript8
-rw-r--r--tests/multiple_files/SConscript13
-rw-r--r--tests/multiple_files/test_multiple_files.c3
-rw-r--r--tests/no_messages/SConscript7
-rw-r--r--tests/options/SConscript9
-rw-r--r--tests/site_scons/site_init.py21
-rw-r--r--tests/special_characters/SConscript7
-rw-r--r--tests/special_characters/funny-proto+name.proto0
17 files changed, 151 insertions, 14 deletions
diff --git a/tests/backwards_compatibility/SConscript b/tests/backwards_compatibility/SConscript
new file mode 100644
index 00000000..5fb978f3
--- /dev/null
+++ b/tests/backwards_compatibility/SConscript
@@ -0,0 +1,11 @@
+# Check that the old generated .pb.c/.pb.h files are still compatible with the
+# current version of nanopb.
+
+Import("env")
+
+enc = env.Program(["encode_legacy.c", "alltypes_legacy.c", "#common/pb_encode.o"])
+dec = env.Program(["decode_legacy.c", "alltypes_legacy.c", "#common/pb_decode.o"])
+
+env.RunTest(enc)
+env.RunTest([dec, "encode_legacy.output"])
+
diff --git a/tests/backwards_compatibility/alltypes_legacy.c b/tests/backwards_compatibility/alltypes_legacy.c
index b144b1e3..9134d5e6 100644
--- a/tests/backwards_compatibility/alltypes_legacy.c
+++ b/tests/backwards_compatibility/alltypes_legacy.c
@@ -5,7 +5,7 @@
* incompatible changes made to the generator in future versions.
*/
-#include "bc_alltypes.pb.h"
+#include "alltypes_legacy.h"
const char SubMessage_substuff1_default[16] = "1";
const int32_t SubMessage_substuff2_default = 2;
diff --git a/tests/backwards_compatibility/decode_legacy.c b/tests/backwards_compatibility/decode_legacy.c
index b74172fd..315b16ef 100644
--- a/tests/backwards_compatibility/decode_legacy.c
+++ b/tests/backwards_compatibility/decode_legacy.c
@@ -1,16 +1,16 @@
/* Tests the decoding of all types.
- * This is a backwards-compatibility test, using bc_alltypes.pb.h.
- * It is similar to test_decode3, but duplicated in order to allow
- * test_decode3 to test any new features introduced later.
+ * This is a backwards-compatibility test, using alltypes_legacy.h.
+ * It is similar to decode_alltypes, but duplicated in order to allow
+ * decode_alltypes to test any new features introduced later.
*
- * Run e.g. ./bc_encode | ./bc_decode
+ * Run e.g. ./encode_legacy | ./decode_legacy
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <pb_decode.h>
-#include "bc_alltypes.pb.h"
+#include "alltypes_legacy.h"
#define TEST(x) if (!(x)) { \
printf("Test " #x " failed.\n"); \
diff --git a/tests/backwards_compatibility/encode_legacy.c b/tests/backwards_compatibility/encode_legacy.c
index e84f0908..0e313093 100644
--- a/tests/backwards_compatibility/encode_legacy.c
+++ b/tests/backwards_compatibility/encode_legacy.c
@@ -1,14 +1,14 @@
/* Attempts to test all the datatypes supported by ProtoBuf.
- * This is a backwards-compatibility test, using bc_alltypes.pb.h.
- * It is similar to test_encode3, but duplicated in order to allow
- * test_encode3 to test any new features introduced later.
+ * This is a backwards-compatibility test, using alltypes_legacy.h.
+ * It is similar to encode_alltypes, but duplicated in order to allow
+ * encode_alltypes to test any new features introduced later.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <pb_encode.h>
-#include "bc_alltypes.pb.h"
+#include "alltypes_legacy.h"
int main(int argc, char **argv)
{
diff --git a/tests/basic_stream/SConscript b/tests/basic_stream/SConscript
new file mode 100644
index 00000000..17382a98
--- /dev/null
+++ b/tests/basic_stream/SConscript
@@ -0,0 +1,12 @@
+# Build and run a basic round-trip test using direct stream encoding.
+
+Import("env")
+
+enc = env.Program(["encode_stream.c", "#common/person.pb.c", "#common/pb_encode.o"])
+dec = env.Program(["decode_stream.c", "#common/person.pb.c", "#common/pb_decode.o"])
+
+env.RunTest(enc)
+env.RunTest([dec, "encode_stream.output"])
+env.Decode(["encode_stream.output", "#common/person.proto"], MESSAGE = "Person")
+env.Compare(["decode_stream.output", "encode_stream.decoded"])
+
diff --git a/tests/callbacks/SConscript b/tests/callbacks/SConscript
new file mode 100644
index 00000000..729fd65f
--- /dev/null
+++ b/tests/callbacks/SConscript
@@ -0,0 +1,14 @@
+# Test the functionality of the callback fields.
+
+Import("env")
+
+env.NanopbProto("callbacks")
+enc = env.Program(["encode_callbacks.c", "callbacks.pb.c", "#common/pb_encode.o"])
+dec = env.Program(["decode_callbacks.c", "callbacks.pb.c", "#common/pb_decode.o"])
+
+env.RunTest(enc)
+env.RunTest([dec, "encode_callbacks.output"])
+
+env.Decode(["encode_callbacks.output", "callbacks.proto"], MESSAGE = "TestMessage")
+env.Compare(["decode_callbacks.output", "encode_callbacks.decoded"])
+
diff --git a/tests/extensions/SConscript b/tests/extensions/SConscript
new file mode 100644
index 00000000..b48d6a66
--- /dev/null
+++ b/tests/extensions/SConscript
@@ -0,0 +1,16 @@
+# Test the support for extension fields.
+
+Import("env")
+
+# We use the files from the alltypes test case
+incpath = env.Clone()
+incpath.Append(PROTOCPATH = '#alltypes')
+incpath.Append(CPPPATH = '#alltypes')
+
+incpath.NanopbProto("extensions")
+enc = incpath.Program(["encode_extensions.c", "extensions.pb.c", "#alltypes/alltypes.pb.o", "#common/pb_encode.o"])
+dec = incpath.Program(["decode_extensions.c", "extensions.pb.c", "#alltypes/alltypes.pb.o", "#common/pb_decode.o"])
+
+env.RunTest(enc)
+env.RunTest([dec, "encode_extensions.output"])
+
diff --git a/tests/extra_fields/SConscript b/tests/extra_fields/SConscript
new file mode 100644
index 00000000..a6f0e751
--- /dev/null
+++ b/tests/extra_fields/SConscript
@@ -0,0 +1,10 @@
+# Test that the decoder properly handles unknown fields in the input.
+
+Import("env")
+
+dec = env.GetBuildPath('#basic_buffer/${PROGPREFIX}decode_buffer${PROGSUFFIX}')
+env.RunTest('person_with_extra_field.output', [dec, "person_with_extra_field.pb"])
+env.Compare(["person_with_extra_field.output", "person_with_extra_field.expected"])
+
+dec2 = env.GetBuildPath('#alltypes/${PROGPREFIX}decode_alltypes${PROGSUFFIX}')
+env.RunTest('alltypes_with_extra_fields.output', [dec2, 'alltypes_with_extra_fields.pb'])
diff --git a/tests/extra_fields/person_with_extra_field.expected b/tests/extra_fields/person_with_extra_field.expected
new file mode 100644
index 00000000..da9c32df
--- /dev/null
+++ b/tests/extra_fields/person_with_extra_field.expected
@@ -0,0 +1,14 @@
+name: "Test Person 99"
+id: 99
+email: "test@person.com"
+phone {
+ number: "555-12345678"
+ type: MOBILE
+}
+phone {
+ number: "99-2342"
+}
+phone {
+ number: "1234-5678"
+ type: WORK
+}
diff --git a/tests/missing_fields/SConscript b/tests/missing_fields/SConscript
new file mode 100644
index 00000000..361b5502
--- /dev/null
+++ b/tests/missing_fields/SConscript
@@ -0,0 +1,8 @@
+# Check that the decoder properly detects when required fields are missing.
+
+Import("env")
+
+env.NanopbProto("missing_fields")
+test = env.Program(["missing_fields.c", "missing_fields.pb.c", "#common/pb_encode.o", "#common/pb_decode.o"])
+env.RunTest(test)
+
diff --git a/tests/multiple_files/SConscript b/tests/multiple_files/SConscript
new file mode 100644
index 00000000..6b4f6b69
--- /dev/null
+++ b/tests/multiple_files/SConscript
@@ -0,0 +1,13 @@
+# Test that multiple .proto files don't cause name collisions.
+
+Import("env")
+
+incpath = env.Clone()
+incpath.Append(PROTOCPATH = '#multiple_files')
+
+incpath.NanopbProto("callbacks")
+incpath.NanopbProto("callbacks2")
+test = incpath.Program(["test_multiple_files.c", "callbacks.pb.c", "callbacks2.pb.c"])
+
+env.RunTest(test)
+
diff --git a/tests/multiple_files/test_multiple_files.c b/tests/multiple_files/test_multiple_files.c
index cb4e16d3..05722dc5 100644
--- a/tests/multiple_files/test_multiple_files.c
+++ b/tests/multiple_files/test_multiple_files.c
@@ -1,6 +1,5 @@
/*
- * Tests if still compile if typedefs are redfefined in STATIC_ASSERTS when
- * proto file includes another poto file
+ * Tests if this still compiles when multiple .proto files are involved.
*/
#include <stdio.h>
diff --git a/tests/no_messages/SConscript b/tests/no_messages/SConscript
new file mode 100644
index 00000000..6492e2cf
--- /dev/null
+++ b/tests/no_messages/SConscript
@@ -0,0 +1,7 @@
+# Test that a .proto file without any messages compiles fine.
+
+Import("env")
+
+env.NanopbProto("no_messages")
+env.Object('no_messages.pb.c')
+
diff --git a/tests/options/SConscript b/tests/options/SConscript
new file mode 100644
index 00000000..89a00fa5
--- /dev/null
+++ b/tests/options/SConscript
@@ -0,0 +1,9 @@
+# Test that the generator options work as expected.
+
+Import("env")
+
+env.NanopbProto("options")
+env.Object('options.pb.c')
+
+env.Match(['options.pb.h', 'options.expected'])
+
diff --git a/tests/site_scons/site_init.py b/tests/site_scons/site_init.py
index b69db646..86e50335 100644
--- a/tests/site_scons/site_init.py
+++ b/tests/site_scons/site_init.py
@@ -1,5 +1,6 @@
import subprocess
import sys
+import re
try:
# Make terminal colors work on windows
@@ -13,8 +14,9 @@ def add_nanopb_builders(env):
# Build command for building .pb from .proto using protoc
def proto_actions(source, target, env, for_signature):
- dirs = ' '.join(['-I' + env.GetBuildPath(d) for d in env['PROTOCPATH']])
- return '$PROTOC $PROTOCFLAGS %s -o%s %s' % (dirs, target[0], source[0])
+ esc = env['ESCAPE']
+ dirs = ' '.join(['-I' + esc(env.GetBuildPath(d)) for d in env['PROTOCPATH']])
+ return '$PROTOC $PROTOCFLAGS %s -o%s %s' % (dirs, esc(str(target[0])), esc(str(source[0])))
proto_file_builder = Builder(generator = proto_actions,
suffix = '.pb',
@@ -91,4 +93,19 @@ def add_nanopb_builders(env):
suffix = '.equal')
env.Append(BUILDERS = {'Compare': compare_builder})
+ # Build command that checks that each pattern in source2 is found in source1.
+ def match_files(target, source, env):
+ data = open(str(source[0]), 'rU').read()
+ patterns = open(str(source[1]))
+ for pattern in patterns:
+ if pattern.strip() and not re.search(pattern.strip(), data, re.MULTILINE):
+ print '\033[31m[FAIL]\033[0m Pattern not found in ' + str(source[0]) + ': ' + pattern
+ return 1
+ else:
+ print '\033[32m[ OK ]\033[0m All patterns found in ' + str(source[0])
+ return 0
+
+ match_builder = Builder(action = match_files, suffix = '.matched')
+ env.Append(BUILDERS = {'Match': match_builder})
+
diff --git a/tests/special_characters/SConscript b/tests/special_characters/SConscript
new file mode 100644
index 00000000..05dccaee
--- /dev/null
+++ b/tests/special_characters/SConscript
@@ -0,0 +1,7 @@
+# Test that special characters in .proto filenames work.
+
+Import('env')
+
+env.Proto("funny-proto+name has.characters.proto")
+env.Nanopb("funny-proto+name has.characters.pb.c", "funny-proto+name has.characters.pb")
+env.Object("funny-proto+name has.characters.pb.c")
diff --git a/tests/special_characters/funny-proto+name.proto b/tests/special_characters/funny-proto+name.proto
deleted file mode 100644
index e69de29b..00000000
--- a/tests/special_characters/funny-proto+name.proto
+++ /dev/null