Move the rest of the tests to scons
authorPetteri Aimonen <jpa@git.mail.kapsi.fi>
Tue, 10 Sep 2013 19:34:54 +0000 (22:34 +0300)
committerPetteri Aimonen <jpa@git.mail.kapsi.fi>
Tue, 10 Sep 2013 19:34:54 +0000 (22:34 +0300)
17 files changed:
tests/backwards_compatibility/SConscript [new file with mode: 0644]
tests/backwards_compatibility/alltypes_legacy.c
tests/backwards_compatibility/decode_legacy.c
tests/backwards_compatibility/encode_legacy.c
tests/basic_stream/SConscript [new file with mode: 0644]
tests/callbacks/SConscript [new file with mode: 0644]
tests/extensions/SConscript [new file with mode: 0644]
tests/extra_fields/SConscript [new file with mode: 0644]
tests/extra_fields/person_with_extra_field.expected [new file with mode: 0644]
tests/missing_fields/SConscript [new file with mode: 0644]
tests/multiple_files/SConscript [new file with mode: 0644]
tests/multiple_files/test_multiple_files.c
tests/no_messages/SConscript [new file with mode: 0644]
tests/options/SConscript [new file with mode: 0644]
tests/site_scons/site_init.py
tests/special_characters/SConscript [new file with mode: 0644]
tests/special_characters/funny-proto+name.proto [deleted file]

diff --git a/tests/backwards_compatibility/SConscript b/tests/backwards_compatibility/SConscript
new file mode 100644 (file)
index 0000000..5fb978f
--- /dev/null
@@ -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"])
+
index b144b1e..9134d5e 100644 (file)
@@ -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;
index b74172f..315b16e 100644 (file)
@@ -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"); \
index e84f090..0e31309 100644 (file)
@@ -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 (file)
index 0000000..17382a9
--- /dev/null
@@ -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 (file)
index 0000000..729fd65
--- /dev/null
@@ -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 (file)
index 0000000..b48d6a6
--- /dev/null
@@ -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 (file)
index 0000000..a6f0e75
--- /dev/null
@@ -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 (file)
index 0000000..da9c32d
--- /dev/null
@@ -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 (file)
index 0000000..361b550
--- /dev/null
@@ -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 (file)
index 0000000..6b4f6b6
--- /dev/null
@@ -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)
+
index cb4e16d..05722dc 100644 (file)
@@ -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 (file)
index 0000000..6492e2c
--- /dev/null
@@ -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 (file)
index 0000000..89a00fa
--- /dev/null
@@ -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'])
+
index b69db64..86e5033 100644 (file)
@@ -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 (file)
index 0000000..05dccae
--- /dev/null
@@ -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 (file)
index e69de29..0000000