cpp: add cases.mpac test

This commit is contained in:
frsyuki
2010-06-01 05:15:36 +09:00
parent 18fa2d1af4
commit 6056f93910
4 changed files with 58 additions and 0 deletions

View File

@@ -25,4 +25,6 @@ cp -f ../msgpack/pack_define.h src/msgpack/
cp -f ../msgpack/pack_template.h src/msgpack/
cp -f ../msgpack/unpack_define.h src/msgpack/
cp -f ../msgpack/unpack_template.h src/msgpack/
cp -f ../test/cases.mpac test/
cp -f ../test/cases_compact.mpac test/

View File

@@ -10,6 +10,7 @@ check_PROGRAMS = \
object \
convert \
buffer \
cases \
msgpackc_test \
msgpack_test
@@ -28,7 +29,11 @@ convert_SOURCES = convert.cc
buffer_SOURCES = buffer.cc
buffer_LDADD = -lz
cases_SOURCES = cases.cc
msgpackc_test_SOURCES = msgpackc_test.cpp
msgpack_test_SOURCES = msgpack_test.cpp
EXTRA_DIST = cases.mpac cases_compact.mpac

36
cpp/test/cases.cc Normal file
View File

@@ -0,0 +1,36 @@
#include <msgpack.hpp>
#include <fstream>
#include <gtest/gtest.h>
static void feed_file(msgpack::unpacker& pac, const char* path)
{
std::ifstream fin(path);
while(true) {
pac.reserve_buffer(32*1024);
fin.read(pac.buffer(), pac.buffer_capacity());
if(fin.bad()) {
throw std::runtime_error("read failed");
}
pac.buffer_consumed(fin.gcount());
if(fin.fail()) {
break;
}
}
}
TEST(cases, format)
{
msgpack::unpacker pac;
msgpack::unpacker pac_compact;
feed_file(pac, "cases.mpac");
feed_file(pac_compact, "cases_compact.mpac");
msgpack::unpacked result;
while(pac.next(&result)) {
msgpack::unpacked result_compact;
EXPECT_TRUE( pac_compact.next(&result_compact) );
EXPECT_EQ(result_compact.get(), result.get());
}
}