diff options
| author | frsyuki <frsyuki@users.sourceforge.jp> | 2010-06-01 07:16:25 +0900 |
|---|---|---|
| committer | frsyuki <frsyuki@users.sourceforge.jp> | 2010-06-01 07:16:25 +0900 |
| commit | eabcf15790a774ce718ae1738c6ddb407e1cd279 (patch) | |
| tree | a69c899bd8d136a8fbb6934ea8b5d87a521e4e23 /cpp/test/streaming_c.cc | |
| parent | 684bca203ad862f30558429081d1a27681fe4559 (diff) | |
| download | msgpack-python-eabcf15790a774ce718ae1738c6ddb407e1cd279.tar.gz | |
cpp: update tests
Diffstat (limited to 'cpp/test/streaming_c.cc')
| -rw-r--r-- | cpp/test/streaming_c.cc | 57 |
1 files changed, 57 insertions, 0 deletions
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 <msgpack.h> +#include <gtest/gtest.h> +#include <stdio.h> + +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); + } +} + |
