msgpack/test/zone.cc
Takatoshi Kondo c2ca709d68 Added header files that use c++11 variadic templates instead of ruby code generation.
When the compiler configured to support C++11 (e.g. CXXFLAG contains -std=c++11 is given),
those files are used.
Decoupled unpacker and msgpack_unpacker.
This modification introduced C++11 dependency such as nullptr and unique_ptr.
I will support C++11 and C++03, finally.

Decoupled msgpack.hpp and msgpack.h.

Decoupled sbuffer from msgpack_sbuffer.

Decoupled vrefbuffer from msgpack_vrefbuffer.

Decoupled zbuffer from msgpack_zbuffer.

Added some z_stream initialization.

Removed unpack macros.

Removed CTX_CAST and CTX_REFERENCED.

Embed ctx_ as a member variable (not a pointer).

Modified zone free using C++ way.
2014-07-07 16:16:29 +09:00

79 lines
1.2 KiB
C++

#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_unique_ptr)
{
msgpack::zone z;
std::unique_ptr<myclass> am(new myclass());
z.push_finalizer(std::move(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);
}