summaryrefslogtreecommitdiffstats
path: root/tests/package_name
diff options
context:
space:
mode:
authorPetteri Aimonen <jpa@git.mail.kapsi.fi>2014-02-12 19:22:01 +0200
committerPetteri Aimonen <jpa@git.mail.kapsi.fi>2014-02-12 19:22:01 +0200
commitfe0bf121eb606d9accbc0fc8be6b1ff6fd5f6f27 (patch)
treeed4af3551e389b8d2a0055421b3dc640fcd42fae /tests/package_name
parentbd22cf27776f8981f1bf2fff4fcccf171a0ed2c8 (diff)
Add test case for package names defined in .proto file.
Diffstat (limited to 'tests/package_name')
-rw-r--r--tests/package_name/SConscript36
1 files changed, 36 insertions, 0 deletions
diff --git a/tests/package_name/SConscript b/tests/package_name/SConscript
new file mode 100644
index 00000000..8f1b9021
--- /dev/null
+++ b/tests/package_name/SConscript
@@ -0,0 +1,36 @@
+# Check that alltypes test case works also when the .proto file defines
+# a package name.
+
+Import("env")
+
+# Build a modified alltypes.proto
+def modify_proto(target, source, env):
+ '''Add a "package test.package;" directive to the beginning of the .proto file.'''
+ data = open(str(source[0]), 'r').read()
+ open(str(target[0]), 'w').write("package test.package;\n\n" + data)
+ return 0
+
+env.Command("alltypes.proto", "#alltypes/alltypes.proto", modify_proto)
+env.Command("alltypes.options", "#alltypes/alltypes.options", Copy("$TARGET", "$SOURCE"))
+env.NanopbProto(["alltypes", "alltypes.options"])
+
+# Build a modified encode_alltypes.c
+def modify_c(target, source, env):
+ '''Add package name to type names in .c file.'''
+
+ data = open(str(source[0]), 'r').read()
+
+ type_names = ['AllTypes', 'MyEnum', 'HugeEnum']
+ for name in type_names:
+ data = data.replace(name, 'test_package_' + name)
+
+ open(str(target[0]), 'w').write(data)
+ return 0
+env.Command("encode_alltypes.c", "#alltypes/encode_alltypes.c", modify_c)
+
+# Encode and compare results to original alltypes testcase
+enc = env.Program(["encode_alltypes.c", "alltypes.pb.c", "$COMMON/pb_encode.o"])
+refdec = "$BUILD/alltypes/decode_alltypes$PROGSUFFIX"
+env.RunTest(enc)
+env.Compare(["encode_alltypes.output", "$BUILD/alltypes/encode_alltypes.output"])
+