mirror of
				https://github.com/msgpack/msgpack-c.git
				synced 2025-10-22 08:02:08 +02:00 
			
		
		
		
	Compare commits
	
		
			10 Commits
		
	
	
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
|   | 7df967142d | ||
|   | 437400c6fe | ||
|   | ae8de13ab6 | ||
|   | 39433e8588 | ||
|   | 94c9bc2ddc | ||
|   | 1088aa55af | ||
|   | 66a5fcf8f1 | ||
|   | bb0617bd47 | ||
|   | f642b70e6a | ||
|   | 3f4ffb9386 | 
| @@ -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 | ||||
|  | ||||
| ## << recommended changes >> | ||||
|   | ||||
| @@ -1,7 +1,7 @@ | ||||
| `msgpack` for C/C++ | ||||
| =================== | ||||
|  | ||||
| Version 1.4.0 [](https://travis-ci.org/msgpack/msgpack-c) [](https://ci.appveyor.com/project/redboltz/msgpack-c/branch/master) | ||||
| Version 1.4.1 [](https://travis-ci.org/msgpack/msgpack-c) [](https://ci.appveyor.com/project/redboltz/msgpack-c/branch/master) | ||||
|  | ||||
| It's like JSON but small and fast. | ||||
|  | ||||
|   | ||||
| @@ -36,12 +36,13 @@ namespace type { | ||||
|     public: | ||||
|         using base = std::tuple<Types...>; | ||||
|  | ||||
|         using base::base; | ||||
|  | ||||
|         tuple() = default; | ||||
|         tuple(tuple const&) = default; | ||||
|         tuple(tuple&&) = default; | ||||
|  | ||||
|         template<typename... OtherTypes> | ||||
|         tuple(OtherTypes&&... other):base(std::forward<OtherTypes>(other)...) {} | ||||
|  | ||||
|         template<typename... OtherTypes> | ||||
|         tuple(tuple<OtherTypes...> const& other):base(static_cast<std::tuple<OtherTypes...> const&>(other)) {} | ||||
|         template<typename... OtherTypes> | ||||
|   | ||||
| @@ -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 { | ||||
|         if (o.type != msgpack::type::MAP) { throw msgpack::type_error(); } | ||||
|         v.resize(o.via.map.size); | ||||
|         msgpack::object_kv* p = o.via.map.ptr; | ||||
|         msgpack::object_kv* const pend = o.via.map.ptr + o.via.map.size; | ||||
|         std::pair<K, V>* it(&v.front()); | ||||
|         for (; p < pend; ++p, ++it) { | ||||
|             p->key.convert(it->first); | ||||
|             p->val.convert(it->second); | ||||
|         if (o.via.map.size != 0) { | ||||
|             msgpack::object_kv* p = o.via.map.ptr; | ||||
|             msgpack::object_kv* const pend = o.via.map.ptr + o.via.map.size; | ||||
|             std::pair<K, V>* it(&v.front()); | ||||
|             for (; p < pend; ++p, ++it) { | ||||
|                 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; | ||||
|     } | ||||
| }; | ||||
| @@ -194,14 +196,22 @@ struct object_with_zone<std::map<K, V, Compare, Alloc> > { | ||||
|         } | ||||
|         else { | ||||
|             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* const pend = p + size; | ||||
|             o.via.map.ptr  = p; | ||||
|             o.via.map.size = size; | ||||
|             typename std::map<K, V, Compare, Alloc>::const_iterator it(v.begin()); | ||||
|             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->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; | ||||
|                 ++it; | ||||
|             } while(p < pend); | ||||
|   | ||||
| @@ -30,11 +30,29 @@ struct convert<std::vector<char, Alloc> > { | ||||
|         switch (o.type) { | ||||
|         case msgpack::type::BIN: | ||||
|             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; | ||||
|         case msgpack::type::STR: | ||||
|             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; | ||||
|         default: | ||||
|             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 { | ||||
|         uint32_t size = checked_get_container_size(v.size()); | ||||
|         o.pack_bin(size); | ||||
|         o.pack_bin_body(&v.front(), size); | ||||
|         if (size != 0) { | ||||
|             o.pack_bin_body(&v.front(), size); | ||||
|         } | ||||
|  | ||||
|         return o; | ||||
|     } | ||||
| @@ -61,7 +81,9 @@ struct object<std::vector<char, Alloc> > { | ||||
|     void operator()(msgpack::object& o, const std::vector<char, Alloc>& v) const { | ||||
|         uint32_t size = checked_get_container_size(v.size()); | ||||
|         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; | ||||
|     } | ||||
| }; | ||||
| @@ -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 { | ||||
|         uint32_t size = checked_get_container_size(v.size()); | ||||
|         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; | ||||
|         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); | ||||
|         } | ||||
|     } | ||||
| }; | ||||
|  | ||||
|   | ||||
| @@ -30,11 +30,29 @@ struct convert<std::vector<unsigned char, Alloc> > { | ||||
|         switch (o.type) { | ||||
|         case msgpack::type::BIN: | ||||
|             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; | ||||
|         case msgpack::type::STR: | ||||
|             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; | ||||
|         default: | ||||
|             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 { | ||||
|         uint32_t size = checked_get_container_size(v.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; | ||||
|     } | ||||
| @@ -61,7 +81,9 @@ struct object<std::vector<unsigned char, Alloc> > { | ||||
|     void operator()(msgpack::object& o, const std::vector<unsigned char, Alloc>& v) const { | ||||
|         uint32_t size = checked_get_container_size(v.size()); | ||||
|         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; | ||||
|     } | ||||
| }; | ||||
| @@ -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 { | ||||
|         uint32_t size = checked_get_container_size(v.size()); | ||||
|         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; | ||||
|         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); | ||||
|         } | ||||
|     } | ||||
| }; | ||||
|  | ||||
|   | ||||
| @@ -186,4 +186,8 @@ | ||||
| #  define inline __inline | ||||
| #endif | ||||
|  | ||||
| #ifdef __APPLE__ | ||||
| #  include <TargetConditionals.h> | ||||
| #endif | ||||
|  | ||||
| #endif /* msgpack/sysdep.h */ | ||||
|   | ||||
| @@ -1,3 +1,3 @@ | ||||
| #define MSGPACK_VERSION_MAJOR    1 | ||||
| #define MSGPACK_VERSION_MINOR    4 | ||||
| #define MSGPACK_VERSION_REVISION 0 | ||||
| #define MSGPACK_VERSION_REVISION 1 | ||||
|   | ||||
| @@ -74,7 +74,7 @@ void* msgpack_zone_malloc_expand(msgpack_zone* zone, size_t size) | ||||
|     while(sz < size) { | ||||
|         size_t tmp_sz = sz * 2; | ||||
|         if (tmp_sz <= sz) { | ||||
|             tmp_sz = size; | ||||
|             sz = size; | ||||
|             break; | ||||
|         } | ||||
|         sz = tmp_sz; | ||||
|   | ||||
| @@ -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) | ||||
| { | ||||
|     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) | ||||
| { | ||||
|     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) | ||||
| { | ||||
|     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) | ||||
| { | ||||
|     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())); | ||||
| } | ||||
|  | ||||
| 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) | ||||
| { | ||||
| @@ -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) | ||||
| { | ||||
|     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) | ||||
| { | ||||
|     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) | ||||
| { | ||||
|     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) | ||||
| { | ||||
|     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) | ||||
| { | ||||
|     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) | ||||
| { | ||||
|     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) | ||||
| { | ||||
|     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) | ||||
| { | ||||
|     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); | ||||
|     } | ||||
| } | ||||
|  | ||||
| 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 | ||||
|  | ||||
| #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) | ||||
| { | ||||
|     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); | ||||
|     } | ||||
| } | ||||
|  | ||||
| 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 | ||||
|  | ||||
| #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) | ||||
| { | ||||
|     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); | ||||
|     } | ||||
| } | ||||
|  | ||||
| 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 | ||||
|  | ||||
| #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) | ||||
| { | ||||
|     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); | ||||
|     } | ||||
| } | ||||
|  | ||||
| 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 | ||||
|   | ||||
| @@ -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) | ||||
| { | ||||
|     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) | ||||
| { | ||||
|     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 | ||||
| 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) | ||||
| { | ||||
|     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) | ||||
| { | ||||
|     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) | ||||
| { | ||||
|     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) | ||||
| { | ||||
|     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) | ||||
| { | ||||
|     TestEnumClassMemberClass val1; | ||||
|   | ||||
		Reference in New Issue
	
	Block a user