Merge pull request #435 from redboltz/fix_433

Fix 433
This commit is contained in:
Takatoshi Kondo 2016-02-27 08:06:06 +09:00
commit 07e635f158
5 changed files with 440 additions and 21 deletions

View File

@ -70,6 +70,7 @@ struct convert<type::assoc_vector<K, V, Compare, Alloc> > {
msgpack::object const& operator()(msgpack::object const& o, type::assoc_vector<K, V, Compare, Alloc>& v) const { msgpack::object const& operator()(msgpack::object const& o, type::assoc_vector<K, V, Compare, Alloc>& v) const {
if (o.type != msgpack::type::MAP) { throw msgpack::type_error(); } if (o.type != msgpack::type::MAP) { throw msgpack::type_error(); }
v.resize(o.via.map.size); v.resize(o.via.map.size);
if (o.via.map.size != 0) {
msgpack::object_kv* p = o.via.map.ptr; msgpack::object_kv* p = o.via.map.ptr;
msgpack::object_kv* const pend = o.via.map.ptr + o.via.map.size; msgpack::object_kv* const pend = o.via.map.ptr + o.via.map.size;
std::pair<K, V>* it(&v.front()); std::pair<K, V>* it(&v.front());
@ -78,6 +79,7 @@ struct convert<type::assoc_vector<K, V, Compare, Alloc> > {
p->val.convert(it->second); p->val.convert(it->second);
} }
std::sort(v.begin(), v.end(), type::detail::pair_first_less<K, V, Compare, Alloc>()); std::sort(v.begin(), v.end(), type::detail::pair_first_less<K, V, Compare, Alloc>());
}
return o; return o;
} }
}; };
@ -192,14 +194,22 @@ struct object_with_zone<std::map<K, V, Compare, Alloc> > {
} }
else { else {
uint32_t size = checked_get_container_size(v.size()); uint32_t size = checked_get_container_size(v.size());
msgpack::object_kv* p = static_cast<msgpack::object_kv*>(o.zone.allocate_align(sizeof(msgpack::object_kv)*size)); msgpack::object_kv* p = static_cast<msgpack::object_kv*>(o.zone.allocate_align(sizeof(msgpack::object_kv)*size));
msgpack::object_kv* const pend = p + size; msgpack::object_kv* const pend = p + size;
o.via.map.ptr = p; o.via.map.ptr = p;
o.via.map.size = size; o.via.map.size = size;
typename std::map<K, V, Compare, Alloc>::const_iterator it(v.begin()); typename std::map<K, V, Compare, Alloc>::const_iterator it(v.begin());
do { do {
#if (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) && !defined(__clang__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
#endif // (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) && !defined(__clang__)
p->key = msgpack::object(it->first, o.zone); p->key = msgpack::object(it->first, o.zone);
p->val = msgpack::object(it->second, o.zone); p->val = msgpack::object(it->second, o.zone);
#if (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) && !defined(__clang__)
#pragma GCC diagnostic pop
#endif // (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) && !defined(__clang__)
++p; ++p;
++it; ++it;
} while(p < pend); } while(p < pend);

View File

@ -31,11 +31,29 @@ struct convert<std::vector<char, Alloc> > {
switch (o.type) { switch (o.type) {
case msgpack::type::BIN: case msgpack::type::BIN:
v.resize(o.via.bin.size); v.resize(o.via.bin.size);
if (o.via.bin.size != 0) {
#if (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) && !defined(__clang__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
#endif // (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) && !defined(__clang__)
std::memcpy(&v.front(), o.via.bin.ptr, o.via.bin.size); std::memcpy(&v.front(), o.via.bin.ptr, o.via.bin.size);
#if (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) && !defined(__clang__)
#pragma GCC diagnostic pop
#endif // (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) && !defined(__clang__)
}
break; break;
case msgpack::type::STR: case msgpack::type::STR:
v.resize(o.via.str.size); v.resize(o.via.str.size);
if (o.via.str.size != 0) {
#if (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) && !defined(__clang__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
#endif // (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) && !defined(__clang__)
std::memcpy(&v.front(), o.via.str.ptr, o.via.str.size); std::memcpy(&v.front(), o.via.str.ptr, o.via.str.size);
#if (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) && !defined(__clang__)
#pragma GCC diagnostic pop
#endif // (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) && !defined(__clang__)
}
break; break;
default: default:
throw msgpack::type_error(); throw msgpack::type_error();
@ -51,7 +69,9 @@ struct pack<std::vector<char, Alloc> > {
msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, const std::vector<char, Alloc>& v) const { msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, const std::vector<char, Alloc>& v) const {
uint32_t size = checked_get_container_size(v.size()); uint32_t size = checked_get_container_size(v.size());
o.pack_bin(size); o.pack_bin(size);
if (size != 0) {
o.pack_bin_body(&v.front(), size); o.pack_bin_body(&v.front(), size);
}
return o; return o;
} }
@ -62,7 +82,9 @@ struct object<std::vector<char, Alloc> > {
void operator()(msgpack::object& o, const std::vector<char, Alloc>& v) const { void operator()(msgpack::object& o, const std::vector<char, Alloc>& v) const {
uint32_t size = checked_get_container_size(v.size()); uint32_t size = checked_get_container_size(v.size());
o.type = msgpack::type::BIN; o.type = msgpack::type::BIN;
if (size != 0) {
o.via.bin.ptr = &v.front(); o.via.bin.ptr = &v.front();
}
o.via.bin.size = size; o.via.bin.size = size;
} }
}; };
@ -72,11 +94,13 @@ struct object_with_zone<std::vector<char, Alloc> > {
void operator()(msgpack::object::with_zone& o, const std::vector<char, Alloc>& v) const { void operator()(msgpack::object::with_zone& o, const std::vector<char, Alloc>& v) const {
uint32_t size = checked_get_container_size(v.size()); uint32_t size = checked_get_container_size(v.size());
o.type = msgpack::type::BIN; o.type = msgpack::type::BIN;
o.via.bin.size = size;
if (size != 0) {
char* ptr = static_cast<char*>(o.zone.allocate_align(size)); char* ptr = static_cast<char*>(o.zone.allocate_align(size));
o.via.bin.ptr = ptr; o.via.bin.ptr = ptr;
o.via.bin.size = size;
std::memcpy(ptr, &v.front(), size); std::memcpy(ptr, &v.front(), size);
} }
}
}; };
} // namespace adaptor } // namespace adaptor

View File

@ -31,11 +31,29 @@ struct convert<std::vector<unsigned char, Alloc> > {
switch (o.type) { switch (o.type) {
case msgpack::type::BIN: case msgpack::type::BIN:
v.resize(o.via.bin.size); v.resize(o.via.bin.size);
if (o.via.bin.size != 0) {
#if (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) && !defined(__clang__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
#endif // (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) && !defined(__clang__)
std::memcpy(&v.front(), o.via.bin.ptr, o.via.bin.size); std::memcpy(&v.front(), o.via.bin.ptr, o.via.bin.size);
#if (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) && !defined(__clang__)
#pragma GCC diagnostic pop
#endif // (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) && !defined(__clang__)
}
break; break;
case msgpack::type::STR: case msgpack::type::STR:
v.resize(o.via.str.size); v.resize(o.via.str.size);
if (o.via.str.size != 0) {
#if (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) && !defined(__clang__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
#endif // (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) && !defined(__clang__)
std::memcpy(&v.front(), o.via.str.ptr, o.via.str.size); std::memcpy(&v.front(), o.via.str.ptr, o.via.str.size);
#if (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) && !defined(__clang__)
#pragma GCC diagnostic pop
#endif // (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) && !defined(__clang__)
}
break; break;
default: default:
throw msgpack::type_error(); throw msgpack::type_error();
@ -51,7 +69,9 @@ struct pack<std::vector<unsigned char, Alloc> > {
msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, const std::vector<unsigned char, Alloc>& v) const { msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, const std::vector<unsigned char, Alloc>& v) const {
uint32_t size = checked_get_container_size(v.size()); uint32_t size = checked_get_container_size(v.size());
o.pack_bin(size); o.pack_bin(size);
if (size != 0) {
o.pack_bin_body(reinterpret_cast<char const*>(&v.front()), size); o.pack_bin_body(reinterpret_cast<char const*>(&v.front()), size);
}
return o; return o;
} }
@ -62,7 +82,9 @@ struct object<std::vector<unsigned char, Alloc> > {
void operator()(msgpack::object& o, const std::vector<unsigned char, Alloc>& v) const { void operator()(msgpack::object& o, const std::vector<unsigned char, Alloc>& v) const {
uint32_t size = checked_get_container_size(v.size()); uint32_t size = checked_get_container_size(v.size());
o.type = msgpack::type::BIN; o.type = msgpack::type::BIN;
if (size != 0) {
o.via.bin.ptr = reinterpret_cast<char const*>(&v.front()); o.via.bin.ptr = reinterpret_cast<char const*>(&v.front());
}
o.via.bin.size = size; o.via.bin.size = size;
} }
}; };
@ -72,11 +94,13 @@ struct object_with_zone<std::vector<unsigned char, Alloc> > {
void operator()(msgpack::object::with_zone& o, const std::vector<unsigned char, Alloc>& v) const { void operator()(msgpack::object::with_zone& o, const std::vector<unsigned char, Alloc>& v) const {
uint32_t size = checked_get_container_size(v.size()); uint32_t size = checked_get_container_size(v.size());
o.type = msgpack::type::BIN; o.type = msgpack::type::BIN;
o.via.bin.size = size;
if (size != 0) {
char* ptr = static_cast<char*>(o.zone.allocate_align(size)); char* ptr = static_cast<char*>(o.zone.allocate_align(size));
o.via.bin.ptr = ptr; o.via.bin.ptr = ptr;
o.via.bin.size = size;
std::memcpy(ptr, &v.front(), size); std::memcpy(ptr, &v.front(), size);
} }
}
}; };
} // namespace adaptor } // namespace adaptor

View File

@ -54,6 +54,20 @@ TEST(MSGPACK_STL, simple_buffer_vector)
} }
} }
TEST(MSGPACK_STL, simple_buffer_vector_empty)
{
typedef vector<int, test::allocator<int> > type;
type val1;
msgpack::sbuffer sbuf;
msgpack::pack(sbuf, val1);
msgpack::unpacked ret;
msgpack::unpack(ret, sbuf.data(), sbuf.size());
EXPECT_EQ(ret.get().type, msgpack::type::ARRAY);
type const& val2 = ret.get().as<type>();
EXPECT_EQ(val1.size(), val2.size());
EXPECT_TRUE(equal(val1.begin(), val1.end(), val2.begin()));
}
TEST(MSGPACK_STL, simple_buffer_vector_char) TEST(MSGPACK_STL, simple_buffer_vector_char)
{ {
typedef vector<char, test::allocator<char> > type; typedef vector<char, test::allocator<char> > type;
@ -72,6 +86,20 @@ TEST(MSGPACK_STL, simple_buffer_vector_char)
} }
} }
TEST(MSGPACK_STL, simple_buffer_vector_char_empty)
{
typedef vector<char, test::allocator<char> > type;
type val1;
msgpack::sbuffer sbuf;
msgpack::pack(sbuf, val1);
msgpack::unpacked ret;
msgpack::unpack(ret, sbuf.data(), sbuf.size());
EXPECT_EQ(ret.get().type, msgpack::type::BIN);
type const& val2 = ret.get().as<type>();
EXPECT_EQ(val1.size(), val2.size());
EXPECT_TRUE(equal(val1.begin(), val1.end(), val2.begin()));
}
TEST(MSGPACK_STL, simple_buffer_vector_unsigned_char) TEST(MSGPACK_STL, simple_buffer_vector_unsigned_char)
{ {
typedef vector<unsigned char, test::allocator<unsigned char> > type; typedef vector<unsigned char, test::allocator<unsigned char> > type;
@ -90,6 +118,20 @@ TEST(MSGPACK_STL, simple_buffer_vector_unsigned_char)
} }
} }
TEST(MSGPACK_STL, simple_buffer_vector_unsigned_char_empty)
{
typedef vector<unsigned char, test::allocator<unsigned char> > type;
type val1;
msgpack::sbuffer sbuf;
msgpack::pack(sbuf, val1);
msgpack::unpacked ret;
msgpack::unpack(ret, sbuf.data(), sbuf.size());
EXPECT_EQ(ret.get().type, msgpack::type::BIN);
type const& val2 = ret.get().as<type>();
EXPECT_EQ(val1.size(), val2.size());
EXPECT_TRUE(equal(val1.begin(), val1.end(), val2.begin()));
}
TEST(MSGPACK_STL, simple_buffer_vector_uint8_t) TEST(MSGPACK_STL, simple_buffer_vector_uint8_t)
{ {
if (!msgpack::is_same<uint8_t, unsigned char>::value) return; if (!msgpack::is_same<uint8_t, unsigned char>::value) return;
@ -109,6 +151,21 @@ TEST(MSGPACK_STL, simple_buffer_vector_uint8_t)
} }
} }
TEST(MSGPACK_STL, simple_buffer_vector_uint8_t_empty)
{
if (!msgpack::is_same<uint8_t, unsigned char>::value) return;
typedef vector<uint8_t, test::allocator<uint8_t> > type;
type val1;
msgpack::sbuffer sbuf;
msgpack::pack(sbuf, val1);
msgpack::unpacked ret;
msgpack::unpack(ret, sbuf.data(), sbuf.size());
EXPECT_EQ(ret.get().type, msgpack::type::BIN);
type const& val2 = ret.get().as<type>();
EXPECT_EQ(val1.size(), val2.size());
EXPECT_TRUE(equal(val1.begin(), val1.end(), val2.begin()));
}
TEST(MSGPACK_STL, simple_buffer_vector_bool) TEST(MSGPACK_STL, simple_buffer_vector_bool)
{ {
typedef vector<bool, test::allocator<bool> > type; typedef vector<bool, test::allocator<bool> > type;
@ -125,6 +182,20 @@ TEST(MSGPACK_STL, simple_buffer_vector_bool)
EXPECT_TRUE(equal(val1.begin(), val1.end(), val2.begin())); EXPECT_TRUE(equal(val1.begin(), val1.end(), val2.begin()));
} }
TEST(MSGPACK_STL, simple_buffer_vector_bool_empty)
{
typedef vector<bool, test::allocator<bool> > type;
type val1;
msgpack::sbuffer sbuf;
msgpack::pack(sbuf, val1);
msgpack::unpacked ret;
msgpack::unpack(ret, sbuf.data(), sbuf.size());
EXPECT_EQ(ret.get().type, msgpack::type::ARRAY);
type const& val2 = ret.get().as<type>();
EXPECT_EQ(val1.size(), val2.size());
EXPECT_TRUE(equal(val1.begin(), val1.end(), val2.begin()));
}
TEST(MSGPACK_STL, simple_buffer_assoc_vector) TEST(MSGPACK_STL, simple_buffer_assoc_vector)
{ {
@ -144,6 +215,19 @@ TEST(MSGPACK_STL, simple_buffer_assoc_vector)
} }
} }
TEST(MSGPACK_STL, simple_buffer_assoc_vector_empty)
{
typedef msgpack::type::assoc_vector<int, int, test::less<int>, test::allocator<std::pair<int, int> > >type;
type val1;
msgpack::sbuffer sbuf;
msgpack::pack(sbuf, val1);
msgpack::unpacked ret;
msgpack::unpack(ret, sbuf.data(), sbuf.size());
type const& val2 = ret.get().as<type>();
EXPECT_EQ(val1.size(), val2.size());
EXPECT_TRUE(equal(val1.begin(), val1.end(), val2.begin()));
}
TEST(MSGPACK_STL, simple_buffer_map) TEST(MSGPACK_STL, simple_buffer_map)
{ {
typedef map<int, int, test::less<int>, test::allocator<std::pair<const int, int> > > type; typedef map<int, int, test::less<int>, test::allocator<std::pair<const int, int> > > type;
@ -161,6 +245,19 @@ TEST(MSGPACK_STL, simple_buffer_map)
} }
} }
TEST(MSGPACK_STL, simple_buffer_map_empty)
{
typedef map<int, int, test::less<int>, test::allocator<std::pair<const int, int> > > type;
type val1;
msgpack::sbuffer sbuf;
msgpack::pack(sbuf, val1);
msgpack::unpacked ret;
msgpack::unpack(ret, sbuf.data(), sbuf.size());
type const& val2 = ret.get().as<type>();
EXPECT_EQ(val1.size(), val2.size());
EXPECT_TRUE(equal(val1.begin(), val1.end(), val2.begin()));
}
TEST(MSGPACK_STL, simple_buffer_deque) TEST(MSGPACK_STL, simple_buffer_deque)
{ {
typedef deque<int, test::allocator<int> > type; typedef deque<int, test::allocator<int> > type;
@ -178,6 +275,19 @@ TEST(MSGPACK_STL, simple_buffer_deque)
} }
} }
TEST(MSGPACK_STL, simple_buffer_deque_empty)
{
typedef deque<int, test::allocator<int> > type;
type val1;
msgpack::sbuffer sbuf;
msgpack::pack(sbuf, val1);
msgpack::unpacked ret;
msgpack::unpack(ret, sbuf.data(), sbuf.size());
type const& val2 = ret.get().as<type>();
EXPECT_EQ(val1.size(), val2.size());
EXPECT_TRUE(equal(val1.begin(), val1.end(), val2.begin()));
}
TEST(MSGPACK_STL, simple_buffer_list) TEST(MSGPACK_STL, simple_buffer_list)
{ {
typedef list<int, test::allocator<int> > type; typedef list<int, test::allocator<int> > type;
@ -195,6 +305,19 @@ TEST(MSGPACK_STL, simple_buffer_list)
} }
} }
TEST(MSGPACK_STL, simple_buffer_list_empty)
{
typedef list<int, test::allocator<int> > type;
type val1;
msgpack::sbuffer sbuf;
msgpack::pack(sbuf, val1);
msgpack::unpacked ret;
msgpack::unpack(ret, sbuf.data(), sbuf.size());
type const& val2 = ret.get().as<type>();
EXPECT_EQ(val1.size(), val2.size());
EXPECT_TRUE(equal(val1.begin(), val1.end(), val2.begin()));
}
TEST(MSGPACK_STL, simple_buffer_set) TEST(MSGPACK_STL, simple_buffer_set)
{ {
typedef set<int, test::less<int>, test::allocator<int> > type; typedef set<int, test::less<int>, test::allocator<int> > type;
@ -212,6 +335,19 @@ TEST(MSGPACK_STL, simple_buffer_set)
} }
} }
TEST(MSGPACK_STL, simple_buffer_set_empty)
{
typedef set<int, test::less<int>, test::allocator<int> > type;
type val1;
msgpack::sbuffer sbuf;
msgpack::pack(sbuf, val1);
msgpack::unpacked ret;
msgpack::unpack(ret, sbuf.data(), sbuf.size());
type val2 = ret.get().as<type>();
EXPECT_EQ(val1.size(), val2.size());
EXPECT_TRUE(equal(val1.begin(), val1.end(), val2.begin()));
}
TEST(MSGPACK_STL, simple_buffer_pair) TEST(MSGPACK_STL, simple_buffer_pair)
{ {
for (unsigned int k = 0; k < kLoop; k++) { for (unsigned int k = 0; k < kLoop; k++) {
@ -256,6 +392,18 @@ TEST(MSGPACK_STL, simple_buffer_multimap)
} }
} }
TEST(MSGPACK_STL, simple_buffer_multimap_empty)
{
typedef multimap<int, int, test::less<int>, test::allocator<std::pair<const int, int> > > type;
type val1;
msgpack::sbuffer sbuf;
msgpack::pack(sbuf, val1);
msgpack::unpacked ret;
msgpack::unpack(ret, sbuf.data(), sbuf.size());
type val2 = ret.get().as<type>();
EXPECT_EQ(val1.size(), val2.size());
}
TEST(MSGPACK_STL, simple_buffer_multiset) TEST(MSGPACK_STL, simple_buffer_multiset)
{ {
typedef multiset<int, test::less<int>, test::allocator<int> > type; typedef multiset<int, test::less<int>, test::allocator<int> > type;
@ -283,6 +431,18 @@ TEST(MSGPACK_STL, simple_buffer_multiset)
} }
} }
TEST(MSGPACK_STL, simple_buffer_multiset_empty)
{
typedef multiset<int, test::less<int>, test::allocator<int> > type;
type val1;
msgpack::sbuffer sbuf;
msgpack::pack(sbuf, val1);
msgpack::unpacked ret;
msgpack::unpack(ret, sbuf.data(), sbuf.size());
type val2 = ret.get().as<type>();
EXPECT_EQ(val1.size(), val2.size());
}
TEST(MSGPACK_TUPLE, simple_tuple) TEST(MSGPACK_TUPLE, simple_tuple)
{ {
msgpack::sbuffer sbuf; msgpack::sbuffer sbuf;
@ -350,6 +510,18 @@ TEST(MSGPACK_TR1, simple_buffer_tr1_unordered_map)
} }
} }
TEST(MSGPACK_TR1, simple_buffer_tr1_unordered_map_empty)
{
typedef tr1::unordered_map<int, int, test::tr1_hash<int>, test::equal_to<int>, test::allocator<std::pair<const int, int> > > type;
type val1;
msgpack::sbuffer sbuf;
msgpack::pack(sbuf, val1);
msgpack::unpacked ret;
msgpack::unpack(ret, sbuf.data(), sbuf.size());
type val2 = ret.get().as<type>();
EXPECT_EQ(val1.size(), val2.size());
}
TEST(MSGPACK_TR1, simple_buffer_tr1_unordered_multimap) TEST(MSGPACK_TR1, simple_buffer_tr1_unordered_multimap)
{ {
typedef tr1::unordered_multimap<int, int, test::tr1_hash<int>, test::equal_to<int>, test::allocator<std::pair<const int, int> > > type; typedef tr1::unordered_multimap<int, int, test::tr1_hash<int>, test::equal_to<int>, test::allocator<std::pair<const int, int> > > type;
@ -379,6 +551,19 @@ TEST(MSGPACK_TR1, simple_buffer_tr1_unordered_multimap)
EXPECT_TRUE(v1 == v2); EXPECT_TRUE(v1 == v2);
} }
} }
TEST(MSGPACK_TR1, simple_buffer_tr1_unordered_multimap_empty)
{
typedef tr1::unordered_multimap<int, int, test::tr1_hash<int>, test::equal_to<int>, test::allocator<std::pair<const int, int> > > type;
type val1;
msgpack::sbuffer sbuf;
msgpack::pack(sbuf, val1);
msgpack::unpacked ret;
msgpack::unpack(ret, sbuf.data(), sbuf.size());
type val2 = ret.get().as<type>();
EXPECT_EQ(val1.size(), val2.size());
}
#endif #endif
#ifdef MSGPACK_HAS_STD_TR1_UNORDERED_SET #ifdef MSGPACK_HAS_STD_TR1_UNORDERED_SET
@ -403,6 +588,18 @@ TEST(MSGPACK_TR1, simple_buffer_tr1_unordered_set)
} }
} }
TEST(MSGPACK_TR1, simple_buffer_tr1_unordered_set_empty)
{
typedef tr1::unordered_set<int, test::tr1_hash<int>, test::equal_to<int>, test::allocator<int> > type;
type val1;
msgpack::sbuffer sbuf;
msgpack::pack(sbuf, val1);
msgpack::unpacked ret;
msgpack::unpack(ret, sbuf.data(), sbuf.size());
type val2 = ret.get().as<type>();
EXPECT_EQ(val1.size(), val2.size());
}
TEST(MSGPACK_TR1, simple_buffer_tr1_unordered_multiset) TEST(MSGPACK_TR1, simple_buffer_tr1_unordered_multiset)
{ {
typedef tr1::unordered_multiset<int, test::tr1_hash<int>, test::equal_to<int>, test::allocator<int> > type; typedef tr1::unordered_multiset<int, test::tr1_hash<int>, test::equal_to<int>, test::allocator<int> > type;
@ -429,6 +626,19 @@ TEST(MSGPACK_TR1, simple_buffer_tr1_unordered_multiset)
EXPECT_TRUE(v1 == v2); EXPECT_TRUE(v1 == v2);
} }
} }
TEST(MSGPACK_TR1, simple_buffer_tr1_unordered_multiset_empty)
{
typedef tr1::unordered_multiset<int, test::tr1_hash<int>, test::equal_to<int>, test::allocator<int> > type;
type val1;
msgpack::sbuffer sbuf;
msgpack::pack(sbuf, val1);
msgpack::unpacked ret;
msgpack::unpack(ret, sbuf.data(), sbuf.size());
type val2 = ret.get().as<type>();
EXPECT_EQ(val1.size(), val2.size());
}
#endif #endif
#if defined (MSGPACK_HAS_STD_UNORDERED_MAP) || defined (MSGPACK_HAS_STD_UNORDERED_SET) #if defined (MSGPACK_HAS_STD_UNORDERED_MAP) || defined (MSGPACK_HAS_STD_UNORDERED_SET)
@ -469,6 +679,18 @@ TEST(MSGPACK_TR1, simple_buffer_unordered_map)
} }
} }
TEST(MSGPACK_TR1, simple_buffer_unordered_map_empty)
{
typedef unordered_map<int, int, test::hash<int>, test::equal_to<int>, test::allocator<std::pair<const int, int> > > type;
type val1;
msgpack::sbuffer sbuf;
msgpack::pack(sbuf, val1);
msgpack::unpacked ret;
msgpack::unpack(ret, sbuf.data(), sbuf.size());
type val2 = ret.get().as<type>();
EXPECT_EQ(val1.size(), val2.size());
}
TEST(MSGPACK_TR1, simple_buffer_unordered_multimap) TEST(MSGPACK_TR1, simple_buffer_unordered_multimap)
{ {
typedef unordered_multimap<int, int, test::hash<int>, test::equal_to<int>, test::allocator<std::pair<const int, int> > > type; typedef unordered_multimap<int, int, test::hash<int>, test::equal_to<int>, test::allocator<std::pair<const int, int> > > type;
@ -498,6 +720,19 @@ TEST(MSGPACK_TR1, simple_buffer_unordered_multimap)
EXPECT_TRUE(v1 == v2); EXPECT_TRUE(v1 == v2);
} }
} }
TEST(MSGPACK_TR1, simple_buffer_unordered_multimap_empty)
{
typedef unordered_multimap<int, int, test::hash<int>, test::equal_to<int>, test::allocator<std::pair<const int, int> > > type;
type val1;
msgpack::sbuffer sbuf;
msgpack::pack(sbuf, val1);
msgpack::unpacked ret;
msgpack::unpack(ret, sbuf.data(), sbuf.size());
type val2 = ret.get().as<type>();
EXPECT_EQ(val1.size(), val2.size());
}
#endif #endif
#ifdef MSGPACK_HAS_STD_UNORDERED_SET #ifdef MSGPACK_HAS_STD_UNORDERED_SET
@ -523,6 +758,18 @@ TEST(MSGPACK_TR1, simple_buffer_unordered_set)
} }
} }
TEST(MSGPACK_TR1, simple_buffer_unordered_set_empty)
{
typedef unordered_set<int, test::hash<int>, test::equal_to<int>, test::allocator<int> > type;
type val1;
msgpack::sbuffer sbuf;
msgpack::pack(sbuf, val1);
msgpack::unpacked ret;
msgpack::unpack(ret, sbuf.data(), sbuf.size());
type val2 = ret.get().as<type>();
EXPECT_EQ(val1.size(), val2.size());
}
TEST(MSGPACK_TR1, simple_buffer_unordered_multiset) TEST(MSGPACK_TR1, simple_buffer_unordered_multiset)
{ {
typedef unordered_multiset<int, test::hash<int>, test::equal_to<int>, test::allocator<int> > type; typedef unordered_multiset<int, test::hash<int>, test::equal_to<int>, test::allocator<int> > type;
@ -549,4 +796,17 @@ TEST(MSGPACK_TR1, simple_buffer_unordered_multiset)
EXPECT_TRUE(v1 == v2); EXPECT_TRUE(v1 == v2);
} }
} }
TEST(MSGPACK_TR1, simple_buffer_unordered_multiset_empty)
{
typedef unordered_multiset<int, test::hash<int>, test::equal_to<int>, test::allocator<int> > type;
type val1;
msgpack::sbuffer sbuf;
msgpack::pack(sbuf, val1);
msgpack::unpacked ret;
msgpack::unpack(ret, sbuf.data(), sbuf.size());
type val2 = ret.get().as<type>();
EXPECT_EQ(val1.size(), val2.size());
}
#endif #endif

View File

@ -76,6 +76,19 @@ TEST(MSGPACK_CPP11, simple_array)
} }
} }
TEST(MSGPACK_CPP11, simple_array_empty)
{
array<int, 0> val1;
msgpack::sbuffer sbuf;
msgpack::pack(sbuf, val1);
msgpack::unpacked ret;
msgpack::unpack(ret, sbuf.data(), sbuf.size());
EXPECT_EQ(ret.get().type, msgpack::type::ARRAY);
array<int, 0> val2 = ret.get().as<array<int, 0> >();
EXPECT_EQ(val1.size(), val2.size());
EXPECT_TRUE(equal(val1.begin(), val1.end(), val2.begin()));
}
TEST(MSGPACK_CPP11, simple_buffer_array_char) TEST(MSGPACK_CPP11, simple_buffer_array_char)
{ {
for (unsigned int k = 0; k < kLoop; k++) { for (unsigned int k = 0; k < kLoop; k++) {
@ -93,6 +106,19 @@ TEST(MSGPACK_CPP11, simple_buffer_array_char)
} }
} }
TEST(MSGPACK_CPP11, simple_buffer_array_char_empty)
{
array<char, 0> val1;
msgpack::sbuffer sbuf;
msgpack::pack(sbuf, val1);
msgpack::unpacked ret;
msgpack::unpack(ret, sbuf.data(), sbuf.size());
EXPECT_EQ(ret.get().type, msgpack::type::BIN);
array<char, 0> val2 = ret.get().as<array<char, 0> >();
EXPECT_EQ(val1.size(), val2.size());
EXPECT_TRUE(equal(val1.begin(), val1.end(), val2.begin()));
}
TEST(MSGPACK_CPP11, simple_buffer_array_unsigned_char) TEST(MSGPACK_CPP11, simple_buffer_array_unsigned_char)
{ {
if (!msgpack::is_same<uint8_t, unsigned char>::value) return; if (!msgpack::is_same<uint8_t, unsigned char>::value) return;
@ -111,6 +137,20 @@ TEST(MSGPACK_CPP11, simple_buffer_array_unsigned_char)
} }
} }
TEST(MSGPACK_CPP11, simple_buffer_array_unsigned_char_empty)
{
if (!msgpack::is_same<uint8_t, unsigned char>::value) return;
array<unsigned char, 0> val1;
msgpack::sbuffer sbuf;
msgpack::pack(sbuf, val1);
msgpack::unpacked ret;
msgpack::unpack(ret, sbuf.data(), sbuf.size());
EXPECT_EQ(ret.get().type, msgpack::type::BIN);
array<unsigned char, 0> val2 = ret.get().as<array<unsigned char, 0> >();
EXPECT_EQ(val1.size(), val2.size());
EXPECT_TRUE(equal(val1.begin(), val1.end(), val2.begin()));
}
// strong typedefs // strong typedefs
namespace test { namespace test {
@ -158,6 +198,18 @@ TEST(MSGPACK_STL, simple_buffer_forward_list)
} }
} }
TEST(MSGPACK_STL, simple_buffer_forward_list_empty)
{
using type = forward_list<int, test::allocator<int>>;
type val1;
msgpack::sbuffer sbuf;
msgpack::pack(sbuf, val1);
msgpack::unpacked ret;
msgpack::unpack(ret, sbuf.data(), sbuf.size());
type val2 = ret.get().as<type >();
EXPECT_EQ(val1, val2);
}
TEST(MSGPACK_STL, simple_buffer_unordered_map) TEST(MSGPACK_STL, simple_buffer_unordered_map)
{ {
using type = unordered_map<int, int, test::hash<int>, test::equal_to<int>, test::map_allocator<int, int>>; using type = unordered_map<int, int, test::hash<int>, test::equal_to<int>, test::map_allocator<int, int>>;
@ -174,6 +226,18 @@ TEST(MSGPACK_STL, simple_buffer_unordered_map)
} }
} }
TEST(MSGPACK_STL, simple_buffer_unordered_map_empty)
{
using type = unordered_map<int, int, test::hash<int>, test::equal_to<int>, test::map_allocator<int, int>>;
type val1;
msgpack::sbuffer sbuf;
msgpack::pack(sbuf, val1);
msgpack::unpacked ret;
msgpack::unpack(ret, sbuf.data(), sbuf.size());
type val2 = ret.get().as<type >();
EXPECT_EQ(val1, val2);
}
TEST(MSGPACK_STL, simple_buffer_unordered_multimap) TEST(MSGPACK_STL, simple_buffer_unordered_multimap)
{ {
using type = unordered_multimap<int, int, test::hash<int>, test::equal_to<int>, test::map_allocator<int, int>>; using type = unordered_multimap<int, int, test::hash<int>, test::equal_to<int>, test::map_allocator<int, int>>;
@ -194,6 +258,19 @@ TEST(MSGPACK_STL, simple_buffer_unordered_multimap)
} }
} }
TEST(MSGPACK_STL, simple_buffer_unordered_multimap_empty)
{
using type = unordered_multimap<int, int, test::hash<int>, test::equal_to<int>, test::map_allocator<int, int>>;
type val1;
msgpack::sbuffer sbuf;
msgpack::pack(sbuf, val1);
msgpack::unpacked ret;
msgpack::unpack(ret, sbuf.data(), sbuf.size());
type val2 = ret.get().as<type >();
EXPECT_EQ(val1, val2);
}
TEST(MSGPACK_STL, simple_buffer_unordered_set) TEST(MSGPACK_STL, simple_buffer_unordered_set)
{ {
using type = unordered_set<int, test::hash<int>, test::equal_to<int>, test::set_allocator<int>>; using type = unordered_set<int, test::hash<int>, test::equal_to<int>, test::set_allocator<int>>;
@ -210,6 +287,18 @@ TEST(MSGPACK_STL, simple_buffer_unordered_set)
} }
} }
TEST(MSGPACK_STL, simple_buffer_unordered_set_empty)
{
using type = unordered_set<int, test::hash<int>, test::equal_to<int>, test::set_allocator<int>>;
type val1;
msgpack::sbuffer sbuf;
msgpack::pack(sbuf, val1);
msgpack::unpacked ret;
msgpack::unpack(ret, sbuf.data(), sbuf.size());
type val2 = ret.get().as<type>();
EXPECT_EQ(val1, val2);
}
TEST(MSGPACK_STL, simple_buffer_unordered_multiset) TEST(MSGPACK_STL, simple_buffer_unordered_multiset)
{ {
using type = unordered_multiset<int, test::hash<int>, test::equal_to<int>, test::set_allocator<int>>; using type = unordered_multiset<int, test::hash<int>, test::equal_to<int>, test::set_allocator<int>>;
@ -226,6 +315,18 @@ TEST(MSGPACK_STL, simple_buffer_unordered_multiset)
} }
} }
TEST(MSGPACK_STL, simple_buffer_unordered_multiset_empty)
{
using type = unordered_multiset<int, test::hash<int>, test::equal_to<int>, test::set_allocator<int>>;
type val1;
msgpack::sbuffer sbuf;
msgpack::pack(sbuf, val1);
msgpack::unpacked ret;
msgpack::unpack(ret, sbuf.data(), sbuf.size());
type val2 = ret.get().as<type >();
EXPECT_EQ(val1, val2);
}
TEST(MSGPACK_USER_DEFINED, simple_buffer_enum_class_member) TEST(MSGPACK_USER_DEFINED, simple_buffer_enum_class_member)
{ {
TestEnumClassMemberClass val1; TestEnumClassMemberClass val1;