aboutsummaryrefslogtreecommitdiffstats
path: root/tests/basic_buffer
diff options
context:
space:
mode:
authorPetteri Aimonen <jpa@git.mail.kapsi.fi>2013-09-10 17:44:32 +0300
committerPetteri Aimonen <jpa@git.mail.kapsi.fi>2013-09-10 17:53:07 +0300
commitf04ab838abd90fb70f7d6ef77fdacdf07f09ba4d (patch)
tree00d3d7834953f6ca2b7a804fe02bfd95f795c6e6 /tests/basic_buffer
parente681dd0d75a4b6a7974cc898477f3a138f7872c2 (diff)
Build fixes for Windows/Visual C++
Diffstat (limited to 'tests/basic_buffer')
-rw-r--r--tests/basic_buffer/SConscript8
-rw-r--r--tests/basic_buffer/decode_buffer.c11
-rw-r--r--tests/basic_buffer/encode_buffer.c11
3 files changed, 20 insertions, 10 deletions
diff --git a/tests/basic_buffer/SConscript b/tests/basic_buffer/SConscript
index 5b85e13..349fb14 100644
--- a/tests/basic_buffer/SConscript
+++ b/tests/basic_buffer/SConscript
@@ -2,11 +2,11 @@
Import("env")
-env.Program(["encode_buffer.c", "#common/person.pb.c", "#common/pb_encode.o"])
-env.Program(["decode_buffer.c", "#common/person.pb.c", "#common/pb_decode.o"])
+enc = env.Program(["encode_buffer.c", "#common/person.pb.c", "#common/pb_encode.o"])
+dec = env.Program(["decode_buffer.c", "#common/person.pb.c", "#common/pb_decode.o"])
-env.RunTest("encode_buffer")
-env.RunTest(["decode_buffer", "encode_buffer.output"])
+env.RunTest(enc)
+env.RunTest([dec, "encode_buffer.output"])
env.Decode(["encode_buffer.output", "#common/person.proto"], MESSAGE = "Person")
env.Compare(["decode_buffer.output", "encode_buffer.decoded"])
diff --git a/tests/basic_buffer/decode_buffer.c b/tests/basic_buffer/decode_buffer.c
index 56bbd8f..d231c91 100644
--- a/tests/basic_buffer/decode_buffer.c
+++ b/tests/basic_buffer/decode_buffer.c
@@ -9,6 +9,7 @@
#include <stdio.h>
#include <pb_decode.h>
#include "person.pb.h"
+#include "test_helpers.h"
/* This function is called once from main(), it handles
the decoding and printing. */
@@ -59,9 +60,13 @@ bool print_person(pb_istream_t *stream)
int main()
{
- /* Read the data into buffer */
uint8_t buffer[512];
- size_t count = fread(buffer, 1, sizeof(buffer), stdin);
+ pb_istream_t stream;
+ size_t count;
+
+ /* Read the data into buffer */
+ SET_BINARY_MODE(stdin);
+ count = fread(buffer, 1, sizeof(buffer), stdin);
if (!feof(stdin))
{
@@ -70,7 +75,7 @@ int main()
}
/* 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 (!print_person(&stream))
diff --git a/tests/basic_buffer/encode_buffer.c b/tests/basic_buffer/encode_buffer.c
index 742c99f..d3e4f6e 100644
--- a/tests/basic_buffer/encode_buffer.c
+++ b/tests/basic_buffer/encode_buffer.c
@@ -6,9 +6,13 @@
#include <stdio.h>
#include <pb_encode.h>
#include "person.pb.h"
+#include "test_helpers.h"
int main()
{
+ uint8_t buffer[512];
+ pb_ostream_t stream;
+
/* Initialize the structure with constants */
Person person = {"Test Person 99", 99, true, "test@person.com",
3, {{"555-12345678", true, Person_PhoneType_MOBILE},
@@ -16,12 +20,13 @@ int main()
{"1234-5678", true, Person_PhoneType_WORK},
}};
- uint8_t buffer[512];
- pb_ostream_t stream = pb_ostream_from_buffer(buffer, sizeof(buffer));
+ stream = pb_ostream_from_buffer(buffer, sizeof(buffer));
/* Now encode it and check if we succeeded. */
if (pb_encode(&stream, Person_fields, &person))
- {
+ {
+ /* Write the result data to stdout */
+ SET_BINARY_MODE(stdout);
fwrite(buffer, 1, stream.bytes_written, stdout);
return 0; /* Success */
}