Added an encode/decode test for 'required' fields of all types.

This commit is contained in:
Petteri Aimonen
2012-01-12 19:06:33 +02:00
parent a1adf39805
commit 0f6b615ae3
4 changed files with 168 additions and 3 deletions

50
tests/test_encode3.c Normal file
View File

@@ -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 */
}
}