diff options
author | Petteri Aimonen <jpa@npb.mail.kapsi.fi> | 2011-08-17 19:03:06 +0000 |
---|---|---|
committer | Petteri Aimonen <jpa@npb.mail.kapsi.fi> | 2011-08-17 19:03:06 +0000 |
commit | 7f53c3f7484679c1e38607f59542d43be1387650 (patch) | |
tree | 396198a24a1661eb7af87d0364a936d8df98a5ae /tests/test_decode1.c | |
parent | 2cefaeaf61f38f1566293e53b4708e9ceff2d945 (diff) |
Example
git-svn-id: https://svn.kapsi.fi/jpa/nanopb@957 e3a754e5-d11d-0410-8d38-ebb782a927b9
Diffstat (limited to 'tests/test_decode1.c')
-rw-r--r-- | tests/test_decode1.c | 28 |
1 files changed, 23 insertions, 5 deletions
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; |