summaryrefslogtreecommitdiff
path: root/cpp/test
diff options
context:
space:
mode:
authorfrsyuki <frsyuki@users.sourceforge.jp>2010-06-01 05:15:36 +0900
committerfrsyuki <frsyuki@users.sourceforge.jp>2010-06-01 05:15:36 +0900
commit6056f939103624d21092a5e4a4d8ffaf9204c191 (patch)
tree9a793525a82593106303cf9f073c5f6b8c345d27 /cpp/test
parent18fa2d1af4fc557a6269678e84c404c8612bf1af (diff)
downloadmsgpack-python-6056f939103624d21092a5e4a4d8ffaf9204c191.tar.gz
cpp: add cases.mpac test
Diffstat (limited to 'cpp/test')
-rw-r--r--cpp/test/Makefile.am5
-rw-r--r--cpp/test/cases.cc36
2 files changed, 41 insertions, 0 deletions
diff --git a/cpp/test/Makefile.am b/cpp/test/Makefile.am
index 3670d7f..f9c5f22 100644
--- a/cpp/test/Makefile.am
+++ b/cpp/test/Makefile.am
@@ -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
+
diff --git a/cpp/test/cases.cc b/cpp/test/cases.cc
new file mode 100644
index 0000000..b408876
--- /dev/null
+++ b/cpp/test/cases.cc
@@ -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());
+ }
+}
+