Move the rest of the tests to scons

This commit is contained in:
Petteri Aimonen
2013-09-10 22:34:54 +03:00
parent 0bbcb7b367
commit e2e9980627
17 changed files with 151 additions and 14 deletions

View 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"])

View 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;

View 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"); \

View 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)
{

View 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"])

View 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"])

View 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"])

View 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'])

View 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
}

View 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)

View 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)

View 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>

View 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
View 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'])

View 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})

View 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")