summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorPetteri Aimonen <jpa@npb.mail.kapsi.fi>2011-08-17 19:03:06 +0000
committerPetteri Aimonen <jpa@npb.mail.kapsi.fi>2011-08-17 19:03:06 +0000
commit7f53c3f7484679c1e38607f59542d43be1387650 (patch)
tree396198a24a1661eb7af87d0364a936d8df98a5ae /tests
parent2cefaeaf61f38f1566293e53b4708e9ceff2d945 (diff)
Example
git-svn-id: https://svn.kapsi.fi/jpa/nanopb@957 e3a754e5-d11d-0410-8d38-ebb782a927b9
Diffstat (limited to 'tests')
-rw-r--r--tests/Makefile18
-rw-r--r--tests/person.proto3
-rw-r--r--tests/test_decode1.c28
-rw-r--r--tests/test_encode1.c3
4 files changed, 36 insertions, 16 deletions
diff --git a/tests/Makefile b/tests/Makefile
index 4993297e..243dbd17 100644
--- a/tests/Makefile
+++ b/tests/Makefile
@@ -2,21 +2,27 @@ CFLAGS=-ansi -Wall -Werror -I .. -g -O0
DEPS=../pb_decode.c ../pb_decode.h ../pb_encode.c ../pb_encode.h ../pb.h person.h unittests.h
TESTS=test_decode1 test_encode1 decode_unittests encode_unittests
-all: $(TESTS) run_unittests
+all: $(TESTS) run_unittests breakpoints
clean:
rm -f $(TESTS)
%: %.c $(DEPS)
- $(CC) $(CFLAGS) -o $@ $< ../pb_decode.c ../pb_encode.c
+ $(CC) $(CFLAGS) -o $@ $< ../pb_decode.c ../pb_encode.c person.c
-%.h: %.proto
+person.h: person.proto
protoc -I. -I../generator -I/usr/include -operson.pb $<
python ../generator/nanopb_generator.py person.pb
-run_unittests: decode_unittests encode_unittests
- ./decode_unittests
- ./encode_unittests
+breakpoints: ../*.c *.c
+ grep -n 'return false;' $^ | cut -d: -f-2 | xargs -n 1 echo b > $@
+
+run_unittests: decode_unittests encode_unittests test_encode1 test_decode1
+ ./decode_unittests > /dev/null
+ ./encode_unittests > /dev/null
+
+ [ "`./test_encode1 | ./test_decode1`" = \
+ "`./test_encode1 | protoc --decode=Person -I. -I../generator -I/usr/include person.proto`" ]
run_fuzztest: test_decode1
bash -c 'I=1; while cat /dev/urandom | ./test_decode1 > /dev/null; do I=$$(($$I+1)); echo -en "\r$$I"; done' \ No newline at end of file
diff --git a/tests/person.proto b/tests/person.proto
index 5befb076..dafcf934 100644
--- a/tests/person.proto
+++ b/tests/person.proto
@@ -4,8 +4,7 @@ message Person {
required string name = 1 [(nanopb).max_size = 40];
required int32 id = 2;
optional string email = 3 [(nanopb).max_size = 40];
- optional bytes test = 5 [default="\x00\x01\x02", (nanopb).max_size = 20];
-
+
enum PhoneType {
MOBILE = 0;
HOME = 1;
diff --git a/tests/test_decode1.c b/tests/test_decode1.c
index a2c7f428..b7698efc 100644
--- a/tests/test_decode1.c
+++ b/tests/test_decode1.c
@@ -2,9 +2,6 @@
#include <pb_decode.h>
#include "person.h"
-/* This test has only one source file anyway.. */
-#include "person.c"
-
bool print_person(pb_istream_t *stream)
{
int i;
@@ -13,12 +10,33 @@ bool print_person(pb_istream_t *stream)
if (!pb_decode(stream, Person_fields, &person))
return false;
- printf("Person: name '%s' id '%d' email '%s'\n", person.name, person.id, person.email);
+ printf("name: \"%s\"\n", person.name);
+ printf("id: %d\n", person.id);
+
+ if (person.has_email)
+ printf("email: \"%s\"\n", person.email);
for (i = 0; i < person.phone_count; i++)
{
Person_PhoneNumber *phone = &person.phone[i];
- printf("PhoneNumber: number '%s' type '%d'\n", phone->number, phone->type);
+ printf("phone {\n");
+ printf(" number: \"%s\"\n", phone->number);
+
+ switch (phone->type)
+ {
+ case Person_PhoneType_WORK:
+ printf(" type: WORK\n");
+ break;
+
+ case Person_PhoneType_HOME:
+ printf(" type: HOME\n");
+ break;
+
+ case Person_PhoneType_MOBILE:
+ printf(" type: MOBILE\n");
+ break;
+ }
+ printf("}\n");
}
return true;
diff --git a/tests/test_encode1.c b/tests/test_encode1.c
index 99be7cb5..ac13df35 100644
--- a/tests/test_encode1.c
+++ b/tests/test_encode1.c
@@ -2,9 +2,6 @@
#include <pb_encode.h>
#include "person.h"
-/* This test has only one source file anyway.. */
-#include "person.c"
-
bool streamcallback(pb_ostream_t *stream, const uint8_t *buf, size_t count)
{
FILE *file = (FILE*) stream->state;