git-svn-id: https://svn.kapsi.fi/jpa/nanopb@951 e3a754e5-d11d-0410-8d38-ebb782a927b9
This commit is contained in:
Petteri Aimonen
2011-08-04 16:49:32 +00:00
parent 3959290bc7
commit a8d0172507
10 changed files with 583 additions and 104 deletions

View File

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

View File

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

View File

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

23
tests/test_encode1.c Normal file
View File

@@ -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;
}