Move the rest of the tests to scons
This commit is contained in:
11
tests/backwards_compatibility/SConscript
Normal file
11
tests/backwards_compatibility/SConscript
Normal file
@@ -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"])
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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"); \
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
12
tests/basic_stream/SConscript
Normal file
12
tests/basic_stream/SConscript
Normal file
@@ -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"])
|
||||
|
||||
14
tests/callbacks/SConscript
Normal file
14
tests/callbacks/SConscript
Normal file
@@ -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"])
|
||||
|
||||
16
tests/extensions/SConscript
Normal file
16
tests/extensions/SConscript
Normal file
@@ -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"])
|
||||
|
||||
10
tests/extra_fields/SConscript
Normal file
10
tests/extra_fields/SConscript
Normal file
@@ -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'])
|
||||
14
tests/extra_fields/person_with_extra_field.expected
Normal file
14
tests/extra_fields/person_with_extra_field.expected
Normal file
@@ -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
|
||||
}
|
||||
8
tests/missing_fields/SConscript
Normal file
8
tests/missing_fields/SConscript
Normal file
@@ -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)
|
||||
|
||||
13
tests/multiple_files/SConscript
Normal file
13
tests/multiple_files/SConscript
Normal file
@@ -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)
|
||||
|
||||
@@ -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>
|
||||
|
||||
7
tests/no_messages/SConscript
Normal file
7
tests/no_messages/SConscript
Normal file
@@ -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')
|
||||
|
||||
9
tests/options/SConscript
Normal file
9
tests/options/SConscript
Normal file
@@ -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'])
|
||||
|
||||
@@ -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})
|
||||
|
||||
|
||||
|
||||
7
tests/special_characters/SConscript
Normal file
7
tests/special_characters/SConscript
Normal file
@@ -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")
|
||||
Reference in New Issue
Block a user