X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;f=tests%2Ftest_encode1.c;h=f46e60a6a005961f1fe85ff335e5bc1f474205a0;hb=e66675a25d39bb5dfebea3041c8f2360bcac290c;hp=df1ec4fcccbf67dacb78999cc338dfd529baa9a9;hpb=d4abb63c052dc9d4c23ce72e498b4c7483f3b7cb;p=apps%2Fagl-service-can-low-level.git diff --git a/tests/test_encode1.c b/tests/test_encode1.c index df1ec4fc..f46e60a6 100644 --- a/tests/test_encode1.c +++ b/tests/test_encode1.c @@ -1,11 +1,13 @@ /* A very simple encoding test case using person.proto. - * Just puts constant data in the fields. + * Just puts constant data in the fields and writes the + * data to stdout. */ #include #include #include "person.pb.h" +/* This binds the pb_ostream_t into the stdout stream */ bool streamcallback(pb_ostream_t *stream, const uint8_t *buf, size_t count) { FILE *file = (FILE*) stream->state; @@ -14,12 +16,16 @@ bool streamcallback(pb_ostream_t *stream, const uint8_t *buf, size_t count) int main() { + /* Initialize the structure with constants */ Person person = {"Test Person 99", 99, true, "test@person.com", 1, {{"555-12345678", true, Person_PhoneType_MOBILE}}}; + /* Prepare the stream, output goes directly to stdout */ pb_ostream_t stream = {&streamcallback, stdout, SIZE_MAX, 0}; - pb_encode(&stream, Person_fields, &person); - - return 0; + /* Now encode it and check if we succeeded. */ + if (pb_encode(&stream, Person_fields, &person)) + return 0; /* Success */ + else + return 1; /* Failure */ }