Publishing nanopb-0.3.6
[apps/agl-service-can-low-level.git] / tests / encode_unittests / encode_unittests.c
index edbc10a..583af5c 100644 (file)
@@ -1,4 +1,5 @@
 /* This includes the whole .c file to get access to static functions. */
+#include "pb_common.c"
 #include "pb_encode.c"
 
 #include <stdio.h>
@@ -169,7 +170,7 @@ int main()
     {
         uint8_t buffer[30];
         pb_ostream_t s;
-        struct { size_t size; uint8_t bytes[5]; } value = {5, {'x', 'y', 'z', 'z', 'y'}};
+        struct { pb_size_t size; uint8_t bytes[5]; } value = {5, {'x', 'y', 'z', 'z', 'y'}};
     
         COMMENT("Test pb_enc_bytes")
         TEST(WRITES(pb_enc_bytes(&s, &BytesMessage_fields[0], &value), "\x05xyzzy"))
@@ -281,6 +282,15 @@ int main()
         TEST(WRITES(pb_encode_delimited(&s, IntegerContainer_fields, &msg),
                     "\x09\x0A\x07\x0A\x05\x01\x02\x03\x04\x05"))
     }
+
+    {
+        IntegerContainer msg = {{5, {1,2,3,4,5}}};
+        size_t size;
+        
+        COMMENT("Test pb_get_encoded_size.")
+        TEST(pb_get_encoded_size(&size, IntegerContainer_fields, &msg) &&
+             size == 9);
+    }
     
     {
         uint8_t buffer[10];
@@ -321,6 +331,23 @@ int main()
         TEST(s.bytes_written == StringMessage_size);
     }
     
+    {
+        uint8_t buffer[128];
+        pb_ostream_t s;
+        StringPointerContainer msg = StringPointerContainer_init_zero;
+        char *strs[1] = {NULL};
+        char zstr[] = "Z";
+        
+        COMMENT("Test string pointer encoding.");
+        
+        msg.rep_str = strs;
+        msg.rep_str_count = 1;
+        TEST(WRITES(pb_encode(&s, StringPointerContainer_fields, &msg), "\x0a\x00"))
+        
+        strs[0] = zstr;
+        TEST(WRITES(pb_encode(&s, StringPointerContainer_fields, &msg), "\x0a\x01Z"))
+    }
+    
     if (status != 0)
         fprintf(stdout, "\n\nSome tests FAILED!\n");