Merge pull request #170 from kylemanna/travis-ci
[apps/agl-service-can-low-level.git] / tests / alltypes / decode_alltypes.c
index 55d025c..458e511 100644 (file)
@@ -8,6 +8,7 @@
 #include <stdlib.h>
 #include <pb_decode.h>
 #include "alltypes.pb.h"
+#include "test_helpers.h"
 
 #define TEST(x) if (!(x)) { \
     printf("Test " #x " failed.\n"); \
    the decoding and checks the fields. */
 bool check_alltypes(pb_istream_t *stream, int mode)
 {
-    AllTypes alltypes;
+    /* Uses _init_default to just make sure that it works. */
+    AllTypes alltypes = AllTypes_init_default;
     
     /* Fill with garbage to better detect initialization errors */
     memset(&alltypes, 0xAA, sizeof(alltypes));
+    alltypes.extensions = 0;
     
     if (!pb_decode(stream, AllTypes_fields, &alltypes))
         return false;
@@ -122,6 +125,8 @@ bool check_alltypes(pb_istream_t *stream, int mode)
         TEST(alltypes.has_opt_enum     == false);
         TEST(alltypes.opt_enum == MyEnum_Second);
         TEST(alltypes.has_opt_emptymsg == false);
+
+        TEST(alltypes.which_oneof == 0);
     }
     else
     {
@@ -167,8 +172,23 @@ bool check_alltypes(pb_istream_t *stream, int mode)
         TEST(alltypes.has_opt_enum      == true);
         TEST(alltypes.opt_enum == MyEnum_Truth);
         TEST(alltypes.has_opt_emptymsg  == true);
+
+        TEST(alltypes.which_oneof == AllTypes_oneof_msg1_tag);
+        TEST(strcmp(alltypes.oneof.oneof_msg1.substuff1, "4059") == 0);
+        TEST(alltypes.oneof.oneof_msg1.substuff2 == 4059);
     }
     
+    TEST(alltypes.req_limits.int32_min  == INT32_MIN);
+    TEST(alltypes.req_limits.int32_max  == INT32_MAX);
+    TEST(alltypes.req_limits.uint32_min == 0);
+    TEST(alltypes.req_limits.uint32_max == UINT32_MAX);
+    TEST(alltypes.req_limits.int64_min  == INT64_MIN);
+    TEST(alltypes.req_limits.int64_max  == INT64_MAX);
+    TEST(alltypes.req_limits.uint64_min == 0);
+    TEST(alltypes.req_limits.uint64_max == UINT64_MAX);
+    TEST(alltypes.req_limits.enum_min   == HugeEnum_Negative);
+    TEST(alltypes.req_limits.enum_max   == HugeEnum_Positive);
+    
     TEST(alltypes.end == 1099);
     
     return true;
@@ -176,15 +196,19 @@ bool check_alltypes(pb_istream_t *stream, int mode)
 
 int main(int argc, char **argv)
 {
+    uint8_t buffer[1024];
+    size_t count;
+    pb_istream_t stream;
+
     /* Whether to expect the optional values or the default values. */
     int mode = (argc > 1) ? atoi(argv[1]) : 0;
     
     /* Read the data into buffer */
-    uint8_t buffer[1024];
-    size_t count = fread(buffer, 1, sizeof(buffer), stdin);
+    SET_BINARY_MODE(stdin);
+    count = fread(buffer, 1, sizeof(buffer), stdin);
     
     /* Construct a pb_istream_t for reading from the buffer */
-    pb_istream_t stream = pb_istream_from_buffer(buffer, count);
+    stream = pb_istream_from_buffer(buffer, count);
     
     /* Decode and print out the stuff */
     if (!check_alltypes(&stream, mode))