From eabcf15790a774ce718ae1738c6ddb407e1cd279 Mon Sep 17 00:00:00 2001 From: frsyuki Date: Tue, 1 Jun 2010 07:16:25 +0900 Subject: cpp: update tests --- cpp/test/streaming_c.cc | 57 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 cpp/test/streaming_c.cc (limited to 'cpp/test/streaming_c.cc') diff --git a/cpp/test/streaming_c.cc b/cpp/test/streaming_c.cc new file mode 100644 index 0000000..6c87ac6 --- /dev/null +++ b/cpp/test/streaming_c.cc @@ -0,0 +1,57 @@ +#include +#include +#include + +TEST(streaming, basic) +{ + msgpack_sbuffer* buffer = msgpack_sbuffer_new(); + + msgpack_packer* pk = msgpack_packer_new(buffer, msgpack_sbuffer_write); + EXPECT_EQ(0, msgpack_pack_int(pk, 1)); + EXPECT_EQ(0, msgpack_pack_int(pk, 2)); + EXPECT_EQ(0, msgpack_pack_int(pk, 3)); + msgpack_packer_free(pk); + + const char* input = buffer->data; + const char* const eof = input + buffer->size; + + msgpack_unpacker pac; + msgpack_unpacker_init(&pac, MSGPACK_UNPACKER_INIT_BUFFER_SIZE); + + msgpack_unpacked result; + msgpack_unpacked_init(&result); + + int count = 0; + while(count < 3) { + msgpack_unpacker_reserve_buffer(&pac, 32*1024); + + /* read buffer into msgpack_unapcker_buffer(&pac) upto + * msgpack_unpacker_buffer_capacity(&pac) bytes. */ + size_t len = 1; + memcpy(msgpack_unpacker_buffer(&pac), input, len); + input += len; + + msgpack_unpacker_buffer_consumed(&pac, len); + + while(msgpack_unpacker_next(&pac, &result)) { + msgpack_object obj = result.data; + switch(count++) { + case 0: + EXPECT_EQ(MSGPACK_OBJECT_POSITIVE_INTEGER, result.data.type); + EXPECT_EQ(1, result.data.via.u64); + break; + case 1: + EXPECT_EQ(MSGPACK_OBJECT_POSITIVE_INTEGER, result.data.type); + EXPECT_EQ(2, result.data.via.u64); + break; + case 2: + EXPECT_EQ(MSGPACK_OBJECT_POSITIVE_INTEGER, result.data.type); + EXPECT_EQ(3, result.data.via.u64); + return; + } + } + + EXPECT_TRUE(input < eof); + } +} + -- cgit v1.2.1