aboutsummaryrefslogtreecommitdiffstats
path: root/tests/decode_unittests.c
diff options
context:
space:
mode:
authorPetteri Aimonen <jpa@npb.mail.kapsi.fi>2011-08-23 16:16:33 +0000
committerPetteri Aimonen <jpa@npb.mail.kapsi.fi>2011-08-23 16:16:33 +0000
commit64ac18c8848d3071a16065c84fca3b5e7210ce95 (patch)
treeaf3f7a5d759e51ac6ada8d95ea6e946709fb6bab /tests/decode_unittests.c
parent9966a8c9b680ada47b6bd5fe96405c0abaf773e4 (diff)
Changed autogenerated file naming from foo.c to foo.pb.c
git-svn-id: https://svn.kapsi.fi/jpa/nanopb@965 e3a754e5-d11d-0410-8d38-ebb782a927b9
Diffstat (limited to 'tests/decode_unittests.c')
-rw-r--r--tests/decode_unittests.c21
1 files changed, 3 insertions, 18 deletions
diff --git a/tests/decode_unittests.c b/tests/decode_unittests.c
index 6f2b77e..006ad90 100644
--- a/tests/decode_unittests.c
+++ b/tests/decode_unittests.c
@@ -2,6 +2,7 @@
#include <string.h>
#include "pb_decode.h"
#include "unittests.h"
+#include "unittestproto.pb.h"
#define S(x) pb_istream_from_buffer((uint8_t*)x, sizeof(x) - 1)
@@ -15,24 +16,6 @@ bool stream_callback(pb_istream_t *stream, uint8_t *buf, size_t count)
return true;
}
-typedef struct { size_t data_count; int32_t data[10]; } IntegerArray;
-const pb_field_t IntegerArray_fields[] = {
- {1, PB_HTYPE_ARRAY | PB_LTYPE_VARINT, offsetof(IntegerArray, data),
- pb_delta(IntegerArray, data_count, data),
- pb_membersize(IntegerArray, data[0]),
- pb_membersize(IntegerArray, data) / pb_membersize(IntegerArray, data[0])},
-
- PB_LAST_FIELD
-};
-
-typedef struct { pb_callback_t data; } CallbackArray;
-const pb_field_t CallbackArray_fields[] = {
- {1, PB_HTYPE_CALLBACK | PB_LTYPE_VARINT, offsetof(CallbackArray, data),
- 0, pb_membersize(CallbackArray, data), 0},
-
- PB_LAST_FIELD
-};
-
/* Verifies that the stream passed to callback matches the byte array pointed to by arg. */
bool callback_check(pb_istream_t *stream, const pb_field_t *field, void *arg)
{
@@ -224,6 +207,8 @@ int main()
IntegerArray dest;
COMMENT("Testing pb_decode with packed int32 field")
+ TEST((s = S("\x0A\x00"), pb_decode(&s, IntegerArray_fields, &dest)
+ && dest.data_count == 0))
TEST((s = S("\x0A\x01\x01"), pb_decode(&s, IntegerArray_fields, &dest)
&& dest.data_count == 1 && dest.data[0] == 1))
TEST((s = S("\x0A\x0A\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0A"), pb_decode(&s, IntegerArray_fields, &dest)