summaryrefslogtreecommitdiffstats
path: root/tests/test_encode3.c
diff options
context:
space:
mode:
authorPetteri Aimonen <jpa@git.mail.kapsi.fi>2012-01-12 19:06:33 +0200
committerPetteri Aimonen <jpa@git.mail.kapsi.fi>2012-01-12 19:06:33 +0200
commit0f6b615ae3395734ee9a1b35185540acad18c452 (patch)
tree9c2765813a5d187dd94a51f701b3242fadc6bd04 /tests/test_encode3.c
parenta1adf398052bf2c78a457c484efbc5ec0258374e (diff)
Added an encode/decode test for 'required' fields of all types.
Diffstat (limited to 'tests/test_encode3.c')
-rw-r--r--tests/test_encode3.c50
1 files changed, 50 insertions, 0 deletions
diff --git a/tests/test_encode3.c b/tests/test_encode3.c
new file mode 100644
index 00000000..5e94be51
--- /dev/null
+++ b/tests/test_encode3.c
@@ -0,0 +1,50 @@
+/* Attempts to test all the datatypes supported by ProtoBuf.
+ * Currently only tests the 'required' variety.
+ */
+
+#include <stdio.h>
+#include <pb_encode.h>
+#include "alltypes.pb.h"
+
+int main()
+{
+ /* Initialize the structure with constants */
+ AllTypes alltypes = {
+ 1001,
+ 1002,
+ 1003,
+ 1004,
+ 1005,
+ 1006,
+ true,
+
+ 1008,
+ 1009,
+ 1010.0f,
+
+ 1011,
+ 1012,
+ 1013.0,
+
+ "1014",
+ {4, "1015"},
+ {"1016", 1016},
+ MyEnum_Truth,
+
+ 1099
+ };
+
+ uint8_t buffer[512];
+ pb_ostream_t stream = pb_ostream_from_buffer(buffer, sizeof(buffer));
+
+ /* Now encode it and check if we succeeded. */
+ if (pb_encode(&stream, AllTypes_fields, &alltypes))
+ {
+ fwrite(buffer, 1, stream.bytes_written, stdout);
+ return 0; /* Success */
+ }
+ else
+ {
+ return 1; /* Failure */
+ }
+}