#include #include #include #include #include #include #include #include #include #include #include "test_allocator.hpp" #if defined(__GNUC__) #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wconversion" #endif //defined(__GNUC__) #include #if defined(__GNUC__) #pragma GCC diagnostic pop #endif //defined(__GNUC__) #ifdef HAVE_CONFIG_H #include "config.h" #endif using namespace std; const unsigned int kLoop = 1000; const unsigned int kElements = 100; // strong typedefs namespace test { template struct equal_to : std::equal_to { }; template struct less : std::less { }; } // namespace test TEST(MSGPACK_STL, simple_buffer_vector) { typedef vector > type; for (unsigned int k = 0; k < kLoop; k++) { type val1; for (unsigned int i = 0; i < kElements; i++) val1.push_back(rand()); msgpack::sbuffer sbuf; msgpack::pack(sbuf, val1); msgpack::object_handle oh = msgpack::unpack(sbuf.data(), sbuf.size()); EXPECT_EQ(oh.get().type, msgpack::type::ARRAY); type const& val2 = oh.get().as(); EXPECT_EQ(val1.size(), val2.size()); EXPECT_TRUE(equal(val1.begin(), val1.end(), val2.begin())); } } TEST(MSGPACK_STL, simple_buffer_vector_empty) { typedef vector > type; type val1; msgpack::sbuffer sbuf; msgpack::pack(sbuf, val1); msgpack::object_handle oh = msgpack::unpack(sbuf.data(), sbuf.size()); EXPECT_EQ(oh.get().type, msgpack::type::ARRAY); type const& val2 = oh.get().as(); EXPECT_EQ(val1.size(), val2.size()); EXPECT_TRUE(equal(val1.begin(), val1.end(), val2.begin())); } TEST(MSGPACK_STL, simple_buffer_vector_char) { typedef vector > type; for (unsigned int k = 0; k < kLoop; k++) { type val1; for (unsigned int i = 0; i < kElements; i++) val1.push_back(static_cast(rand())); msgpack::sbuffer sbuf; msgpack::pack(sbuf, val1); msgpack::object_handle oh = msgpack::unpack(sbuf.data(), sbuf.size()); EXPECT_EQ(oh.get().type, msgpack::type::BIN); type const& val2 = oh.get().as(); EXPECT_EQ(val1.size(), val2.size()); EXPECT_TRUE(equal(val1.begin(), val1.end(), val2.begin())); } } TEST(MSGPACK_STL, simple_buffer_vector_char_empty) { typedef vector > type; type val1; msgpack::sbuffer sbuf; msgpack::pack(sbuf, val1); msgpack::object_handle oh = msgpack::unpack(sbuf.data(), sbuf.size()); EXPECT_EQ(oh.get().type, msgpack::type::BIN); type const& val2 = oh.get().as(); 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 > type; for (unsigned int k = 0; k < kLoop; k++) { type val1; for (unsigned int i = 0; i < kElements; i++) val1.push_back(static_cast(rand())); msgpack::sbuffer sbuf; msgpack::pack(sbuf, val1); msgpack::object_handle oh = msgpack::unpack(sbuf.data(), sbuf.size()); EXPECT_EQ(oh.get().type, msgpack::type::BIN); type const& val2 = oh.get().as(); EXPECT_EQ(val1.size(), val2.size()); EXPECT_TRUE(equal(val1.begin(), val1.end(), val2.begin())); } } TEST(MSGPACK_STL, simple_buffer_vector_unsigned_char_empty) { typedef vector > type; type val1; msgpack::sbuffer sbuf; msgpack::pack(sbuf, val1); msgpack::object_handle oh = msgpack::unpack(sbuf.data(), sbuf.size()); EXPECT_EQ(oh.get().type, msgpack::type::BIN); type const& val2 = oh.get().as(); 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::value) return; typedef vector > type; for (unsigned int k = 0; k < kLoop; k++) { type val1; for (unsigned int i = 0; i < kElements; i++) val1.push_back(static_cast(rand())); msgpack::sbuffer sbuf; msgpack::pack(sbuf, val1); msgpack::object_handle oh = msgpack::unpack(sbuf.data(), sbuf.size()); EXPECT_EQ(oh.get().type, msgpack::type::BIN); type const& val2 = oh.get().as(); EXPECT_EQ(val1.size(), val2.size()); EXPECT_TRUE(equal(val1.begin(), val1.end(), val2.begin())); } } TEST(MSGPACK_STL, simple_buffer_vector_uint8_t_empty) { if (!msgpack::is_same::value) return; typedef vector > type; type val1; msgpack::sbuffer sbuf; msgpack::pack(sbuf, val1); msgpack::object_handle oh = msgpack::unpack(sbuf.data(), sbuf.size()); EXPECT_EQ(oh.get().type, msgpack::type::BIN); type const& val2 = oh.get().as(); EXPECT_EQ(val1.size(), val2.size()); EXPECT_TRUE(equal(val1.begin(), val1.end(), val2.begin())); } TEST(MSGPACK_STL, simple_buffer_vector_bool) { typedef vector > type; type val1; for (unsigned int i = 0; i < kElements; i++) val1.push_back(i % 2 ? false : true); msgpack::sbuffer sbuf; msgpack::pack(sbuf, val1); msgpack::object_handle oh = msgpack::unpack(sbuf.data(), sbuf.size()); EXPECT_EQ(oh.get().type, msgpack::type::ARRAY); type const& val2 = oh.get().as(); EXPECT_EQ(val1.size(), val2.size()); EXPECT_TRUE(equal(val1.begin(), val1.end(), val2.begin())); } TEST(MSGPACK_STL, simple_buffer_vector_bool_empty) { typedef vector > type; type val1; msgpack::sbuffer sbuf; msgpack::pack(sbuf, val1); msgpack::object_handle oh = msgpack::unpack(sbuf.data(), sbuf.size()); EXPECT_EQ(oh.get().type, msgpack::type::ARRAY); type const& val2 = oh.get().as(); EXPECT_EQ(val1.size(), val2.size()); EXPECT_TRUE(equal(val1.begin(), val1.end(), val2.begin())); } TEST(MSGPACK_STL, simple_buffer_assoc_vector) { typedef msgpack::type::assoc_vector, test::allocator > >type; for (unsigned int k = 0; k < kLoop; k++) { type val1; val1.push_back(std::make_pair(1, 2)); val1.push_back(std::make_pair(3, 4)); val1.push_back(std::make_pair(5, 6)); msgpack::sbuffer sbuf; msgpack::pack(sbuf, val1); msgpack::object_handle oh = msgpack::unpack(sbuf.data(), sbuf.size()); type const& val2 = oh.get().as(); EXPECT_EQ(val1.size(), val2.size()); EXPECT_TRUE(equal(val1.begin(), val1.end(), val2.begin())); } } TEST(MSGPACK_STL, simple_buffer_assoc_vector_empty) { typedef msgpack::type::assoc_vector, test::allocator > >type; type val1; msgpack::sbuffer sbuf; msgpack::pack(sbuf, val1); msgpack::object_handle oh = msgpack::unpack(sbuf.data(), sbuf.size()); type const& val2 = oh.get().as(); EXPECT_EQ(val1.size(), val2.size()); EXPECT_TRUE(equal(val1.begin(), val1.end(), val2.begin())); } TEST(MSGPACK_STL, simple_buffer_map) { typedef map, test::allocator > > type; for (unsigned int k = 0; k < kLoop; k++) { type val1; for (unsigned int i = 0; i < kElements; i++) val1[rand()] = rand(); msgpack::sbuffer sbuf; msgpack::pack(sbuf, val1); msgpack::object_handle oh = msgpack::unpack(sbuf.data(), sbuf.size()); type const& val2 = oh.get().as(); EXPECT_EQ(val1.size(), val2.size()); EXPECT_TRUE(equal(val1.begin(), val1.end(), val2.begin())); } } TEST(MSGPACK_STL, simple_buffer_map_empty) { typedef map, test::allocator > > type; type val1; msgpack::sbuffer sbuf; msgpack::pack(sbuf, val1); msgpack::object_handle oh = msgpack::unpack(sbuf.data(), sbuf.size()); type const& val2 = oh.get().as(); EXPECT_EQ(val1.size(), val2.size()); EXPECT_TRUE(equal(val1.begin(), val1.end(), val2.begin())); } TEST(MSGPACK_STL, simple_buffer_deque) { typedef deque > type; for (unsigned int k = 0; k < kLoop; k++) { type val1; for (unsigned int i = 0; i < kElements; i++) val1.push_back(rand()); msgpack::sbuffer sbuf; msgpack::pack(sbuf, val1); msgpack::object_handle oh = msgpack::unpack(sbuf.data(), sbuf.size()); type const& val2 = oh.get().as(); EXPECT_EQ(val1.size(), val2.size()); EXPECT_TRUE(equal(val1.begin(), val1.end(), val2.begin())); } } TEST(MSGPACK_STL, simple_buffer_deque_empty) { typedef deque > type; type val1; msgpack::sbuffer sbuf; msgpack::pack(sbuf, val1); msgpack::object_handle oh = msgpack::unpack(sbuf.data(), sbuf.size()); type const& val2 = oh.get().as(); EXPECT_EQ(val1.size(), val2.size()); EXPECT_TRUE(equal(val1.begin(), val1.end(), val2.begin())); } TEST(MSGPACK_STL, simple_buffer_list) { typedef list > type; for (unsigned int k = 0; k < kLoop; k++) { type val1; for (unsigned int i = 0; i < kElements; i++) val1.push_back(rand()); msgpack::sbuffer sbuf; msgpack::pack(sbuf, val1); msgpack::object_handle oh = msgpack::unpack(sbuf.data(), sbuf.size()); type const& val2 = oh.get().as(); EXPECT_EQ(val1.size(), val2.size()); EXPECT_TRUE(equal(val1.begin(), val1.end(), val2.begin())); } } TEST(MSGPACK_STL, simple_buffer_list_empty) { typedef list > type; type val1; msgpack::sbuffer sbuf; msgpack::pack(sbuf, val1); msgpack::object_handle oh = msgpack::unpack(sbuf.data(), sbuf.size()); type const& val2 = oh.get().as(); EXPECT_EQ(val1.size(), val2.size()); EXPECT_TRUE(equal(val1.begin(), val1.end(), val2.begin())); } TEST(MSGPACK_STL, simple_buffer_set) { typedef set, test::allocator > type; for (unsigned int k = 0; k < kLoop; k++) { type val1; for (unsigned int i = 0; i < kElements; i++) val1.insert(rand()); msgpack::sbuffer sbuf; msgpack::pack(sbuf, val1); msgpack::object_handle oh = msgpack::unpack(sbuf.data(), sbuf.size()); type val2 = oh.get().as(); EXPECT_EQ(val1.size(), val2.size()); EXPECT_TRUE(equal(val1.begin(), val1.end(), val2.begin())); } } TEST(MSGPACK_STL, simple_buffer_set_empty) { typedef set, test::allocator > type; type val1; msgpack::sbuffer sbuf; msgpack::pack(sbuf, val1); msgpack::object_handle oh = msgpack::unpack(sbuf.data(), sbuf.size()); type val2 = oh.get().as(); 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++) { pair val1 = make_pair(rand(), rand()); msgpack::sbuffer sbuf; msgpack::pack(sbuf, val1); msgpack::object_handle oh = msgpack::unpack(sbuf.data(), sbuf.size()); pair val2 = oh.get().as >(); EXPECT_EQ(val1.first, val2.first); EXPECT_EQ(val1.second, val2.second); } } TEST(MSGPACK_STL, simple_buffer_multimap) { typedef multimap, test::allocator > > type; for (unsigned int k = 0; k < kLoop; k++) { type val1; for (unsigned int i = 0; i < kElements; i++) { int i1 = rand(); val1.insert(make_pair(i1, rand())); val1.insert(make_pair(i1, rand())); } msgpack::sbuffer sbuf; msgpack::pack(sbuf, val1); msgpack::object_handle oh = msgpack::unpack(sbuf.data(), sbuf.size()); type val2 = oh.get().as(); vector > v1, v2; type::const_iterator it; for (it = val1.begin(); it != val1.end(); ++it) v1.push_back(make_pair(it->first, it->second)); for (it = val2.begin(); it != val2.end(); ++it) v2.push_back(make_pair(it->first, it->second)); EXPECT_EQ(val1.size(), val2.size()); EXPECT_EQ(v1.size(), v2.size()); sort(v1.begin(), v1.end()); sort(v2.begin(), v2.end()); EXPECT_TRUE(v1 == v2); } } TEST(MSGPACK_STL, simple_buffer_multimap_empty) { typedef multimap, test::allocator > > type; type val1; msgpack::sbuffer sbuf; msgpack::pack(sbuf, val1); msgpack::object_handle oh = msgpack::unpack(sbuf.data(), sbuf.size()); type val2 = oh.get().as(); EXPECT_EQ(val1.size(), val2.size()); } TEST(MSGPACK_STL, simple_buffer_multiset) { typedef multiset, test::allocator > type; for (unsigned int k = 0; k < kLoop; k++) { type val1; for (unsigned int i = 0; i < kElements; i++) val1.insert(rand()); msgpack::sbuffer sbuf; msgpack::pack(sbuf, val1); msgpack::object_handle oh = msgpack::unpack(sbuf.data(), sbuf.size()); type val2 = oh.get().as(); vector v1, v2; type::const_iterator it; for (it = val1.begin(); it != val1.end(); ++it) v1.push_back(*it); for (it = val2.begin(); it != val2.end(); ++it) v2.push_back(*it); EXPECT_EQ(val1.size(), val2.size()); EXPECT_EQ(v1.size(), v2.size()); sort(v1.begin(), v1.end()); sort(v2.begin(), v2.end()); EXPECT_TRUE(v1 == v2); } } TEST(MSGPACK_STL, simple_buffer_multiset_empty) { typedef multiset, test::allocator > type; type val1; msgpack::sbuffer sbuf; msgpack::pack(sbuf, val1); msgpack::object_handle oh = msgpack::unpack(sbuf.data(), sbuf.size()); type val2 = oh.get().as(); EXPECT_EQ(val1.size(), val2.size()); } TEST(MSGPACK_TUPLE, simple_tuple) { msgpack::sbuffer sbuf; msgpack::type::tuple val1(true, "kzk", 12.3); msgpack::pack(sbuf, val1); msgpack::object_handle oh = msgpack::unpack(sbuf.data(), sbuf.size()); msgpack::type::tuple val2 = oh.get().as >(); EXPECT_EQ(oh.get().via.array.size, 3u); EXPECT_EQ(val1.get<0>(), val2.get<0>()); EXPECT_EQ(val1.get<1>(), val2.get<1>()); EXPECT_EQ(val1.get<2>(), val2.get<2>()); } TEST(MSGPACK_TUPLE, simple_tuple_empty) { msgpack::sbuffer sbuf; msgpack::type::tuple<> val1; msgpack::pack(sbuf, val1); msgpack::object_handle oh = msgpack::unpack(sbuf.data(), sbuf.size()); oh.get().as >(); EXPECT_EQ(oh.get().via.array.size, 0u); } TEST(MSGPACK_TUPLE, simple_tuple_grater_than_as) { msgpack::sbuffer sbuf; msgpack::type::tuple val1(true, "kzk", 42); msgpack::pack(sbuf, val1); msgpack::object_handle oh = msgpack::unpack(sbuf.data(), sbuf.size()); msgpack::type::tuple val2 = oh.get().as >(); EXPECT_EQ(oh.get().via.array.size, 3u); EXPECT_EQ(val1.get<0>(), val2.get<0>()); EXPECT_EQ(val1.get<1>(), val2.get<1>()); EXPECT_EQ(val1.get<2>(), val2.get<2>()); } TEST(MSGPACK_TUPLE, simple_tuple_grater_than_convert) { msgpack::sbuffer sbuf; msgpack::type::tuple val1(true, "kzk", 42); msgpack::pack(sbuf, val1); msgpack::object_handle oh = msgpack::unpack(sbuf.data(), sbuf.size()); msgpack::type::tuple val2; oh.get().convert(val2); EXPECT_EQ(oh.get().via.array.size, 3u); EXPECT_EQ(val1.get<0>(), val2.get<0>()); EXPECT_EQ(val1.get<1>(), val2.get<1>()); EXPECT_EQ(val1.get<2>(), val2.get<2>()); } TEST(MSGPACK_TUPLE, simple_tuple_less_than_as) { msgpack::sbuffer sbuf; msgpack::type::tuple val1(true, "kzk", 42); msgpack::pack(sbuf, val1); msgpack::object_handle oh = msgpack::unpack(sbuf.data(), sbuf.size()); msgpack::type::tuple val2 = oh.get().as >(); EXPECT_EQ(oh.get().via.array.size, 3u); EXPECT_EQ(val1.get<0>(), val2.get<0>()); EXPECT_EQ(val1.get<1>(), val2.get<1>()); } TEST(MSGPACK_TUPLE, simple_tuple_less_than_convert) { msgpack::sbuffer sbuf; msgpack::type::tuple val1(true, "kzk", 42); msgpack::pack(sbuf, val1); msgpack::object_handle oh = msgpack::unpack(sbuf.data(), sbuf.size()); msgpack::type::tuple val2; oh.get().convert(val2); EXPECT_EQ(oh.get().via.array.size, 3u); EXPECT_EQ(val1.get<0>(), val2.get<0>()); EXPECT_EQ(val1.get<1>(), val2.get<1>()); } TEST(MSGPACK_TUPLE, simple_tuple_nest) { msgpack::sbuffer sbuf; msgpack::type::tuple > val1; msgpack::pack(sbuf, val1); msgpack::object_handle oh = msgpack::unpack(sbuf.data(), sbuf.size()); msgpack::type::tuple > val2; oh.get().convert(val2); EXPECT_EQ(oh.get().via.array.size, 1u); } // TR1 #if defined(MSGPACK_HAS_STD_TR1_UNORDERED_MAP) || defined(MSGPACK_HAS_STD_TR1_UNORDERED_SET) #include namespace test { template struct tr1_hash : std::tr1::hash { }; } // namespace test #endif // defined(MSGPACK_HAS_STD_TR1_UNORDERED_MAP) || defined(MSGPACK_HAS_STD_TR1_UNORDERED_SET) #ifdef MSGPACK_HAS_STD_TR1_UNORDERED_MAP #include #include "msgpack/adaptor/tr1/unordered_map.hpp" TEST(MSGPACK_TR1, simple_buffer_tr1_unordered_map) { typedef tr1::unordered_map, test::equal_to, test::allocator > > type; for (unsigned int k = 0; k < kLoop; k++) { type val1; for (unsigned int i = 0; i < kElements; i++) val1[rand()] = rand(); msgpack::sbuffer sbuf; msgpack::pack(sbuf, val1); msgpack::object_handle oh = msgpack::unpack(sbuf.data(), sbuf.size()); type val2 = oh.get().as(); EXPECT_EQ(val1.size(), val2.size()); type::const_iterator it; for (it = val1.begin(); it != val1.end(); ++it) { EXPECT_TRUE(val2.find(it->first) != val2.end()); EXPECT_EQ(it->second, val2.find(it->first)->second); } } } TEST(MSGPACK_TR1, simple_buffer_tr1_unordered_map_empty) { typedef tr1::unordered_map, test::equal_to, test::allocator > > type; type val1; msgpack::sbuffer sbuf; msgpack::pack(sbuf, val1); msgpack::object_handle oh = msgpack::unpack(sbuf.data(), sbuf.size()); type val2 = oh.get().as(); EXPECT_EQ(val1.size(), val2.size()); } TEST(MSGPACK_TR1, simple_buffer_tr1_unordered_multimap) { typedef tr1::unordered_multimap, test::equal_to, test::allocator > > type; for (unsigned int k = 0; k < kLoop; k++) { type val1; for (unsigned int i = 0; i < kElements; i++) { int i1 = rand(); val1.insert(make_pair(i1, rand())); val1.insert(make_pair(i1, rand())); } msgpack::sbuffer sbuf; msgpack::pack(sbuf, val1); msgpack::object_handle oh = msgpack::unpack(sbuf.data(), sbuf.size()); type val2 = oh.get().as(); vector > v1, v2; type::const_iterator it; for (it = val1.begin(); it != val1.end(); ++it) v1.push_back(make_pair(it->first, it->second)); for (it = val2.begin(); it != val2.end(); ++it) v2.push_back(make_pair(it->first, it->second)); EXPECT_EQ(val1.size(), val2.size()); EXPECT_EQ(v1.size(), v2.size()); sort(v1.begin(), v1.end()); sort(v2.begin(), v2.end()); EXPECT_TRUE(v1 == v2); } } TEST(MSGPACK_TR1, simple_buffer_tr1_unordered_multimap_empty) { typedef tr1::unordered_multimap, test::equal_to, test::allocator > > type; type val1; msgpack::sbuffer sbuf; msgpack::pack(sbuf, val1); msgpack::object_handle oh = msgpack::unpack(sbuf.data(), sbuf.size()); type val2 = oh.get().as(); EXPECT_EQ(val1.size(), val2.size()); } #endif #ifdef MSGPACK_HAS_STD_TR1_UNORDERED_SET #include #include "msgpack/adaptor/tr1/unordered_set.hpp" TEST(MSGPACK_TR1, simple_buffer_tr1_unordered_set) { typedef tr1::unordered_set, test::equal_to, test::allocator > type; for (unsigned int k = 0; k < kLoop; k++) { type val1; for (unsigned int i = 0; i < kElements; i++) val1.insert(rand()); msgpack::sbuffer sbuf; msgpack::pack(sbuf, val1); msgpack::object_handle oh = msgpack::unpack(sbuf.data(), sbuf.size()); type val2 = oh.get().as(); EXPECT_EQ(val1.size(), val2.size()); type::const_iterator it; for (it = val1.begin(); it != val1.end(); ++it) EXPECT_TRUE(val2.find(*it) != val2.end()); } } TEST(MSGPACK_TR1, simple_buffer_tr1_unordered_set_empty) { typedef tr1::unordered_set, test::equal_to, test::allocator > type; type val1; msgpack::sbuffer sbuf; msgpack::pack(sbuf, val1); msgpack::object_handle oh = msgpack::unpack(sbuf.data(), sbuf.size()); type val2 = oh.get().as(); EXPECT_EQ(val1.size(), val2.size()); } TEST(MSGPACK_TR1, simple_buffer_tr1_unordered_multiset) { typedef tr1::unordered_multiset, test::equal_to, test::allocator > type; for (unsigned int k = 0; k < kLoop; k++) { type val1; for (unsigned int i = 0; i < kElements; i++) val1.insert(rand()); msgpack::sbuffer sbuf; msgpack::pack(sbuf, val1); msgpack::object_handle oh = msgpack::unpack(sbuf.data(), sbuf.size()); type val2 = oh.get().as(); vector v1, v2; type::const_iterator it; for (it = val1.begin(); it != val1.end(); ++it) v1.push_back(*it); for (it = val2.begin(); it != val2.end(); ++it) v2.push_back(*it); EXPECT_EQ(val1.size(), val2.size()); EXPECT_EQ(v1.size(), v2.size()); sort(v1.begin(), v1.end()); sort(v2.begin(), v2.end()); EXPECT_TRUE(v1 == v2); } } TEST(MSGPACK_TR1, simple_buffer_tr1_unordered_multiset_empty) { typedef tr1::unordered_multiset, test::equal_to, test::allocator > type; type val1; msgpack::sbuffer sbuf; msgpack::pack(sbuf, val1); msgpack::object_handle oh = msgpack::unpack(sbuf.data(), sbuf.size()); type val2 = oh.get().as(); EXPECT_EQ(val1.size(), val2.size()); } #endif #if defined (MSGPACK_HAS_STD_UNORDERED_MAP) || defined (MSGPACK_HAS_STD_UNORDERED_SET) #include namespace test { template struct hash : std::hash { }; } // namespace test #endif // defined (MSGPACK_HAS_STD_UNORDERED_MAP) || defined (MSGPACK_HAS_STD_UNORDERED_SET) #ifdef MSGPACK_HAS_STD_UNORDERED_MAP #include #include "msgpack/adaptor/tr1/unordered_map.hpp" TEST(MSGPACK_TR1, simple_buffer_unordered_map) { typedef unordered_map, test::equal_to, test::allocator > > type; for (unsigned int k = 0; k < kLoop; k++) { type val1; for (unsigned int i = 0; i < kElements; i++) val1[rand()] = rand(); msgpack::sbuffer sbuf; msgpack::pack(sbuf, val1); msgpack::object_handle oh = msgpack::unpack(sbuf.data(), sbuf.size()); type val2 = oh.get().as(); EXPECT_EQ(val1.size(), val2.size()); type::const_iterator it; for (it = val1.begin(); it != val1.end(); ++it) { EXPECT_TRUE(val2.find(it->first) != val2.end()); EXPECT_EQ(it->second, val2.find(it->first)->second); } } } TEST(MSGPACK_TR1, simple_buffer_unordered_map_empty) { typedef unordered_map, test::equal_to, test::allocator > > type; type val1; msgpack::sbuffer sbuf; msgpack::pack(sbuf, val1); msgpack::object_handle oh = msgpack::unpack(sbuf.data(), sbuf.size()); type val2 = oh.get().as(); EXPECT_EQ(val1.size(), val2.size()); } TEST(MSGPACK_TR1, simple_buffer_unordered_multimap) { typedef unordered_multimap, test::equal_to, test::allocator > > type; for (unsigned int k = 0; k < kLoop; k++) { type val1; for (unsigned int i = 0; i < kElements; i++) { int i1 = rand(); val1.insert(make_pair(i1, rand())); val1.insert(make_pair(i1, rand())); } msgpack::sbuffer sbuf; msgpack::pack(sbuf, val1); msgpack::object_handle oh = msgpack::unpack(sbuf.data(), sbuf.size()); type val2 = oh.get().as(); vector > v1, v2; type::const_iterator it; for (it = val1.begin(); it != val1.end(); ++it) v1.push_back(make_pair(it->first, it->second)); for (it = val2.begin(); it != val2.end(); ++it) v2.push_back(make_pair(it->first, it->second)); EXPECT_EQ(val1.size(), val2.size()); EXPECT_EQ(v1.size(), v2.size()); sort(v1.begin(), v1.end()); sort(v2.begin(), v2.end()); EXPECT_TRUE(v1 == v2); } } TEST(MSGPACK_TR1, simple_buffer_unordered_multimap_empty) { typedef unordered_multimap, test::equal_to, test::allocator > > type; type val1; msgpack::sbuffer sbuf; msgpack::pack(sbuf, val1); msgpack::object_handle oh = msgpack::unpack(sbuf.data(), sbuf.size()); type val2 = oh.get().as(); EXPECT_EQ(val1.size(), val2.size()); } #endif #ifdef MSGPACK_HAS_STD_UNORDERED_SET #include #include "msgpack/adaptor/tr1/unordered_set.hpp" TEST(MSGPACK_TR1, simple_buffer_unordered_set) { typedef unordered_set, test::equal_to, test::allocator > type; for (unsigned int k = 0; k < kLoop; k++) { type val1; for (unsigned int i = 0; i < kElements; i++) val1.insert(rand()); msgpack::sbuffer sbuf; msgpack::pack(sbuf, val1); msgpack::object_handle oh = msgpack::unpack(sbuf.data(), sbuf.size()); type val2 = oh.get().as(); EXPECT_EQ(val1.size(), val2.size()); type::const_iterator it; for (it = val1.begin(); it != val1.end(); ++it) EXPECT_TRUE(val2.find(*it) != val2.end()); } } TEST(MSGPACK_TR1, simple_buffer_unordered_set_empty) { typedef unordered_set, test::equal_to, test::allocator > type; type val1; msgpack::sbuffer sbuf; msgpack::pack(sbuf, val1); msgpack::object_handle oh = msgpack::unpack(sbuf.data(), sbuf.size()); type val2 = oh.get().as(); EXPECT_EQ(val1.size(), val2.size()); } TEST(MSGPACK_TR1, simple_buffer_unordered_multiset) { typedef unordered_multiset, test::equal_to, test::allocator > type; for (unsigned int k = 0; k < kLoop; k++) { type val1; for (unsigned int i = 0; i < kElements; i++) val1.insert(rand()); msgpack::sbuffer sbuf; msgpack::pack(sbuf, val1); msgpack::object_handle oh = msgpack::unpack(sbuf.data(), sbuf.size()); type val2 = oh.get().as(); vector v1, v2; type::const_iterator it; for (it = val1.begin(); it != val1.end(); ++it) v1.push_back(*it); for (it = val2.begin(); it != val2.end(); ++it) v2.push_back(*it); EXPECT_EQ(val1.size(), val2.size()); EXPECT_EQ(v1.size(), v2.size()); sort(v1.begin(), v1.end()); sort(v2.begin(), v2.end()); EXPECT_TRUE(v1 == v2); } } TEST(MSGPACK_TR1, simple_buffer_unordered_multiset_empty) { typedef unordered_multiset, test::equal_to, test::allocator > type; type val1; msgpack::sbuffer sbuf; msgpack::pack(sbuf, val1); msgpack::object_handle oh = msgpack::unpack(sbuf.data(), sbuf.size()); type val2 = oh.get().as(); EXPECT_EQ(val1.size(), val2.size()); } #endif