summaryrefslogtreecommitdiff
path: root/cpp/test.cpp
diff options
context:
space:
mode:
authorfrsyuki <frsyuki@5a5092ae-2292-43ba-b2d5-dcab9c1a2731>2009-02-15 09:09:56 +0000
committerfrsyuki <frsyuki@5a5092ae-2292-43ba-b2d5-dcab9c1a2731>2009-02-15 09:09:56 +0000
commit529a50633dffc91dd5ce58ae5a905a0ac4a5fdf9 (patch)
treedd81e58a7ef270790969f3179b655136757bc303 /cpp/test.cpp
parent9f460f17d73e749d58c2f58beb621e1f7292cfa6 (diff)
downloadmsgpack-python-529a50633dffc91dd5ce58ae5a905a0ac4a5fdf9.tar.gz
lang/c/msgpack: added C++ binding
git-svn-id: file:///Users/frsyuki/project/msgpack-git/svn/x@50 5a5092ae-2292-43ba-b2d5-dcab9c1a2731
Diffstat (limited to 'cpp/test.cpp')
-rw-r--r--cpp/test.cpp110
1 files changed, 110 insertions, 0 deletions
diff --git a/cpp/test.cpp b/cpp/test.cpp
new file mode 100644
index 0000000..423a6bd
--- /dev/null
+++ b/cpp/test.cpp
@@ -0,0 +1,110 @@
+#include <iostream>
+#include <msgpack/unpack.hpp>
+
+class checker {
+public:
+ void check(const char* d, size_t len, msgpack::object should) {
+ try {
+ std::cout << "----" << std::endl;
+ msgpack::object o;
+ try {
+ o = msgpack::unpack(d, len, m_zone);
+ } catch (std::runtime_error& e) {
+ std::cout << should << std::endl;
+ std::cout << "**" << e.what() << "**" << std::endl;
+ return;
+ }
+ std::cout << o << std::endl;
+ if(o != should) {
+ std::cout << "** TEST FAILED **" << std::endl;
+ }
+ } catch (...) { m_zone.clear(); throw; }
+ m_zone.clear();
+ }
+private:
+ msgpack::zone m_zone;
+};
+
+int main(void)
+{
+
+checker c;
+
+{ // SimpleValue
+ msgpack::zone z;
+ const char d[] = {
+ 0x93, 0xc0, 0xc2, 0xc3,
+ };
+ c.check(d, sizeof(d),
+ z.narray(
+ z.nnil(), z.nfalse(), z.ntrue()
+ )
+ );
+}
+
+{ // Fixnum
+ msgpack::zone z;
+ const char d[] = {
+ 0x92,
+ 0x93, 0x00, 0x40, 0x7f,
+ 0x93, 0xe0, 0xf0, 0xff,
+ };
+ c.check(d, sizeof(d),
+ z.narray(
+ z.narray(
+ z.nu8(0),
+ z.nu8(64),
+ z.nu8(127)
+ ),
+ z.narray(
+ z.ni8(-32),
+ z.ni8(-16),
+ z.ni8(-1)
+ )
+ )
+ );
+}
+
+{ // FixArray
+ msgpack::zone z;
+ const char d[] = {
+ 0x92,
+ 0x90,
+ 0x91,
+ 0x91, 0xc0,
+ };
+ c.check(d, sizeof(d),
+ z.narray(
+ z.narray(),
+ z.narray(
+ z.narray(
+ z.nnil()
+ )
+ )
+ )
+ );
+}
+
+{ // FixRaw
+ msgpack::zone z;
+ const char d[] = {
+ 0x94,
+ 0xa0,
+ 0xa1, 'a',
+ 0xa2, 'b', 'c',
+ 0xa3, 'd', 'e', 'f',
+ };
+ c.check(d, sizeof(d),
+ z.narray(
+ z.nraw("", 0),
+ z.nraw("a", 1),
+ z.nraw("bc", 2),
+ z.nraw("def", 3)
+ )
+ );
+}
+
+
+return 0;
+}
+