Compare commits

...

10 Commits

Author SHA1 Message Date
Takatoshi Kondo
7df967142d Merge pull request #439 from redboltz/ver1.4.1
Updated the version to 1.4.1.
2016-03-06 20:30:15 +09:00
Takatoshi Kondo
437400c6fe Updated the version to 1.4.1. 2016-03-06 19:54:33 +09:00
Takatoshi Kondo
ae8de13ab6 Merge pull request #438 from redboltz/bp_436
Backported #436 to version 1.4.0.
2016-03-06 18:49:20 +09:00
Takatoshi Kondo
39433e8588 Merge pull request #437 from redboltz/bp_435
Backported #435 to version 1.4.0.
2016-03-06 18:48:52 +09:00
Takatoshi Kondo
94c9bc2ddc Backported #436 to version 1.4.0. 2016-03-06 14:19:10 +09:00
Takatoshi Kondo
1088aa55af Backported #435 to version 1.4.0. 2016-03-06 13:40:40 +09:00
Takatoshi Kondo
66a5fcf8f1 Merge pull request #428 from redboltz/bp_426_1.4
Backported #426 to version 1.4.0.
2016-02-21 00:04:51 +09:00
Takatoshi Kondo
bb0617bd47 Merge pull request #427 from redboltz/bp_423_to_1.4
Backported #423 to version 1.4.0.
2016-02-21 00:03:54 +09:00
Takatoshi Kondo
f642b70e6a Backported #426 to version 1.4.0. 2016-02-20 19:09:18 +09:00
Takatoshi Kondo
3f4ffb9386 Backported #423 to version 1.4.0. 2016-02-20 18:50:13 +09:00
11 changed files with 457 additions and 26 deletions

View File

@@ -1,3 +1,10 @@
# 2016-03-06 version 1.4.1
* Fix TARGET_OS_IPHONE checking (#436, #438)
* Fix invalid front() call for empty container (#435. #437)
* Fix compile error on g++6 (C++11 only) (#426, #428)
* Fix zone size expansion logic (#423, #427)
# 2016-01-22 version 1.4.0 # 2016-01-22 version 1.4.0
## << recommended changes >> ## << recommended changes >>

View File

@@ -1,7 +1,7 @@
`msgpack` for C/C++ `msgpack` for C/C++
=================== ===================
Version 1.4.0 [![Build Status](https://travis-ci.org/msgpack/msgpack-c.svg?branch=master)](https://travis-ci.org/msgpack/msgpack-c) [![Build status](https://ci.appveyor.com/api/projects/status/8kstcgt79qj123mw/branch/master?svg=true)](https://ci.appveyor.com/project/redboltz/msgpack-c/branch/master) Version 1.4.1 [![Build Status](https://travis-ci.org/msgpack/msgpack-c.svg?branch=master)](https://travis-ci.org/msgpack/msgpack-c) [![Build status](https://ci.appveyor.com/api/projects/status/8kstcgt79qj123mw/branch/master?svg=true)](https://ci.appveyor.com/project/redboltz/msgpack-c/branch/master)
It's like JSON but small and fast. It's like JSON but small and fast.

View File

@@ -36,12 +36,13 @@ namespace type {
public: public:
using base = std::tuple<Types...>; using base = std::tuple<Types...>;
using base::base;
tuple() = default;
tuple(tuple const&) = default; tuple(tuple const&) = default;
tuple(tuple&&) = default; tuple(tuple&&) = default;
template<typename... OtherTypes>
tuple(OtherTypes&&... other):base(std::forward<OtherTypes>(other)...) {}
template<typename... OtherTypes> template<typename... OtherTypes>
tuple(tuple<OtherTypes...> const& other):base(static_cast<std::tuple<OtherTypes...> const&>(other)) {} tuple(tuple<OtherTypes...> const& other):base(static_cast<std::tuple<OtherTypes...> const&>(other)) {}
template<typename... OtherTypes> template<typename... OtherTypes>

View File

@@ -72,14 +72,16 @@ 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);
msgpack::object_kv* p = o.via.map.ptr; if (o.via.map.size != 0) {
msgpack::object_kv* const pend = o.via.map.ptr + o.via.map.size; msgpack::object_kv* p = o.via.map.ptr;
std::pair<K, V>* it(&v.front()); msgpack::object_kv* const pend = o.via.map.ptr + o.via.map.size;
for (; p < pend; ++p, ++it) { std::pair<K, V>* it(&v.front());
p->key.convert(it->first); for (; p < pend; ++p, ++it) {
p->val.convert(it->second); p->key.convert(it->first);
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;
} }
}; };
@@ -194,14 +196,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

@@ -30,11 +30,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);
std::memcpy(&v.front(), o.via.bin.ptr, 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);
#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);
std::memcpy(&v.front(), o.via.str.ptr, 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);
#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();
@@ -50,7 +68,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);
o.pack_bin_body(&v.front(), size); if (size != 0) {
o.pack_bin_body(&v.front(), size);
}
return o; return o;
} }
@@ -61,7 +81,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;
o.via.bin.ptr = &v.front(); if (size != 0) {
o.via.bin.ptr = &v.front();
}
o.via.bin.size = size; o.via.bin.size = size;
} }
}; };
@@ -71,10 +93,12 @@ 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;
char* ptr = static_cast<char*>(o.zone.allocate_align(size));
o.via.bin.ptr = ptr;
o.via.bin.size = size; o.via.bin.size = size;
std::memcpy(ptr, &v.front(), size); if (size != 0) {
char* ptr = static_cast<char*>(o.zone.allocate_align(size));
o.via.bin.ptr = ptr;
std::memcpy(ptr, &v.front(), size);
}
} }
}; };

View File

@@ -30,11 +30,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);
std::memcpy(&v.front(), o.via.bin.ptr, 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);
#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);
std::memcpy(&v.front(), o.via.str.ptr, 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);
#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();
@@ -50,7 +68,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);
o.pack_bin_body(reinterpret_cast<char const*>(&v.front()), size); if (size != 0) {
o.pack_bin_body(reinterpret_cast<char const*>(&v.front()), size);
}
return o; return o;
} }
@@ -61,7 +81,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;
o.via.bin.ptr = reinterpret_cast<char const*>(&v.front()); if (size != 0) {
o.via.bin.ptr = reinterpret_cast<char const*>(&v.front());
}
o.via.bin.size = size; o.via.bin.size = size;
} }
}; };
@@ -71,10 +93,12 @@ 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;
char* ptr = static_cast<char*>(o.zone.allocate_align(size));
o.via.bin.ptr = ptr;
o.via.bin.size = size; o.via.bin.size = size;
std::memcpy(ptr, &v.front(), size); if (size != 0) {
char* ptr = static_cast<char*>(o.zone.allocate_align(size));
o.via.bin.ptr = ptr;
std::memcpy(ptr, &v.front(), size);
}
} }
}; };

View File

@@ -186,4 +186,8 @@
# define inline __inline # define inline __inline
#endif #endif
#ifdef __APPLE__
# include <TargetConditionals.h>
#endif
#endif /* msgpack/sysdep.h */ #endif /* msgpack/sysdep.h */

View File

@@ -1,3 +1,3 @@
#define MSGPACK_VERSION_MAJOR 1 #define MSGPACK_VERSION_MAJOR 1
#define MSGPACK_VERSION_MINOR 4 #define MSGPACK_VERSION_MINOR 4
#define MSGPACK_VERSION_REVISION 0 #define MSGPACK_VERSION_REVISION 1

View File

@@ -74,7 +74,7 @@ void* msgpack_zone_malloc_expand(msgpack_zone* zone, size_t size)
while(sz < size) { while(sz < size) {
size_t tmp_sz = sz * 2; size_t tmp_sz = sz * 2;
if (tmp_sz <= sz) { if (tmp_sz <= sz) {
tmp_sz = size; sz = size;
break; break;
} }
sz = tmp_sz; sz = tmp_sz;

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;