diff options
| author | frsyuki <frsyuki@users.sourceforge.jp> | 2010-04-25 18:08:14 +0900 |
|---|---|---|
| committer | frsyuki <frsyuki@users.sourceforge.jp> | 2010-04-25 18:08:14 +0900 |
| commit | 9fbca83ac0ba0017d22cd84b696cff3baa1cde23 (patch) | |
| tree | 154feafc1ade3636b1394348ff9df82f1281f280 /cpp/test/zone.cc | |
| parent | d19bfaa2cb16eaabee79922f7d8b59ef9bccb592 (diff) | |
| download | msgpack-python-9fbca83ac0ba0017d22cd84b696cff3baa1cde23.tar.gz | |
cpp: add test/{zone,pack_unpack,streaming,object,convert,buffer}.cc
Diffstat (limited to 'cpp/test/zone.cc')
| -rw-r--r-- | cpp/test/zone.cc | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/cpp/test/zone.cc b/cpp/test/zone.cc new file mode 100644 index 0000000..5274e9f --- /dev/null +++ b/cpp/test/zone.cc @@ -0,0 +1,78 @@ +#include <msgpack.hpp> +#include <gtest/gtest.h> + +TEST(zone, malloc) +{ + msgpack::zone z; + char* buf1 = (char*)z.malloc(4); + memcpy(buf1, "test", 4); + char* buf2 = (char*)z.malloc(4); + memcpy(buf2, "test", 4); +} + + +class myclass { +public: + myclass() : num(0), str("default") { } + + myclass(int num, const std::string& str) : + num(num), str(str) { } + + ~myclass() { } + + int num; + std::string str; + +private: + myclass(const myclass&); +}; + + +TEST(zone, allocate) +{ + msgpack::zone z; + myclass* m = z.allocate<myclass>(); + EXPECT_EQ(m->num, 0); + EXPECT_EQ(m->str, "default"); +} + + +TEST(zone, allocate_constructor) +{ + msgpack::zone z; + myclass* m = z.allocate<myclass>(7, "msgpack"); + EXPECT_EQ(m->num, 7); + EXPECT_EQ(m->str, "msgpack"); +} + + +static void custom_finalizer_func(void* user) +{ + myclass* m = (myclass*)user; + delete m; +} + +TEST(zone, push_finalizer) +{ + msgpack::zone z; + myclass* m = new myclass(); + z.push_finalizer(custom_finalizer_func, (void*)m); +} + + +TEST(zone, push_finalizer_auto_ptr) +{ + msgpack::zone z; + std::auto_ptr<myclass> am(new myclass()); + z.push_finalizer(am); +} + + +TEST(zone, malloc_no_align) +{ + msgpack::zone z; + char* buf1 = (char*)z.malloc_no_align(4); + char* buf2 = (char*)z.malloc_no_align(4); + EXPECT_EQ(buf1+4, buf2); +} + |
