aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorPetteri Aimonen <jpa@npb.mail.kapsi.fi>2011-08-04 16:49:32 +0000
committerPetteri Aimonen <jpa@npb.mail.kapsi.fi>2011-08-04 16:49:32 +0000
commita8d0172507d59b73b95f766aa7644147fd060f20 (patch)
tree56115021e9bed640e273851f0a99631163041bba /tests
parent3959290bc77ae26772bc107128b0a4edd3930361 (diff)
Encoder
git-svn-id: https://svn.kapsi.fi/jpa/nanopb@951 e3a754e5-d11d-0410-8d38-ebb782a927b9
Diffstat (limited to 'tests')
-rw-r--r--tests/Makefile8
-rw-r--r--tests/person.proto2
-rw-r--r--tests/test_decode1.c5
-rw-r--r--tests/test_encode1.c23
4 files changed, 31 insertions, 7 deletions
diff --git a/tests/Makefile b/tests/Makefile
index 35c6f97..7450e1e 100644
--- a/tests/Makefile
+++ b/tests/Makefile
@@ -1,14 +1,14 @@
CFLAGS=-ansi -Wall -Werror -I .. -g -O0
-DEPS=../pb_decode.c ../pb_decode.h ../pb.h person.h
-TESTS=test_decode1 decode_unittests
+DEPS=../pb_decode.c ../pb_decode.h ../pb_encode.c ../pb_encode.h ../pb.h person.h
+TESTS=test_decode1 test_encode1 decode_unittests
all: $(TESTS)
clean:
- rm -f test_decode1
+ rm -f $(TESTS)
%: %.c $(DEPS)
- $(CC) $(CFLAGS) -o $@ $< ../pb_decode.c
+ $(CC) $(CFLAGS) -o $@ $< ../pb_decode.c ../pb_encode.c
run_unittests: decode_unittests
./decode_unittests
diff --git a/tests/person.proto b/tests/person.proto
index 01b2d4e..5befb07 100644
--- a/tests/person.proto
+++ b/tests/person.proto
@@ -4,7 +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 = "abc\x00\x01\x02"];
+ optional bytes test = 5 [default="\x00\x01\x02", (nanopb).max_size = 20];
enum PhoneType {
MOBILE = 0;
diff --git a/tests/test_decode1.c b/tests/test_decode1.c
index 362c404..cc4688d 100644
--- a/tests/test_decode1.c
+++ b/tests/test_decode1.c
@@ -1,9 +1,10 @@
#include <stdio.h>
-#include <string.h>
-#include <stddef.h>
#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;
diff --git a/tests/test_encode1.c b/tests/test_encode1.c
new file mode 100644
index 0000000..b4998f4
--- /dev/null
+++ b/tests/test_encode1.c
@@ -0,0 +1,23 @@
+#include <stdio.h>
+#include <pb_encode.h>
+#include "person.h"
+
+/* This test has only one source file anyway.. */
+#include "person.c"
+
+bool callback(pb_ostream_t *stream, const uint8_t *buf, size_t count)
+{
+ return fwrite(buf, 1, count, stdout) == count;
+}
+
+int main()
+{
+ Person person = {"Test Person 99", 99, true, "test@person.com",
+ 1, {{"555-12345678", true, Person_PhoneType_MOBILE}}};
+
+ pb_ostream_t stream = {&callback, 0, SIZE_MAX, 0};
+
+ pb_encode(&stream, Person_fields, &person);
+
+ return 0;
+}