123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870 |
- #include <iostream>
- #include <msgpack.hpp>
- #include <cmath>
- #include <string>
- #include <vector>
- #include <map>
- #include <deque>
- #include <set>
- #include <list>
- #include <limits>
- #include "test_allocator.hpp"
- #include <gtest/gtest.h>
- #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 <class Key>
- struct equal_to : std::equal_to<Key> {
- };
- template <class Key>
- struct less : std::less<Key> {
- };
- } // namespace test
- TEST(MSGPACK_STL, simple_buffer_vector)
- {
- typedef vector<int, test::allocator<int> > 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<type>();
- EXPECT_EQ(val1.size(), val2.size());
- EXPECT_TRUE(equal(val1.begin(), val1.end(), val2.begin()));
- }
- }
- TEST(MSGPACK_STL, simple_buffer_vector_empty)
- {
- typedef vector<int, test::allocator<int> > 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<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;
- 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::BIN);
- type const& val2 = oh.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_empty)
- {
- typedef vector<char, test::allocator<char> > 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<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;
- 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::BIN);
- type const& val2 = oh.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_empty)
- {
- typedef vector<unsigned char, test::allocator<unsigned char> > 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<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;
- typedef vector<uint8_t, test::allocator<uint8_t> > 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::BIN);
- type const& val2 = oh.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_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::object_handle oh =
- msgpack::unpack(sbuf.data(), sbuf.size());
- EXPECT_EQ(oh.get().type, msgpack::type::BIN);
- type const& val2 = oh.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;
- 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<type>();
- 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<bool, test::allocator<bool> > 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<type>();
- 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<int, int, test::less<int>, test::allocator<std::pair<int, int> > >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<type>();
- 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<int, int, test::less<int>, test::allocator<std::pair<int, int> > >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<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;
- 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<type>();
- EXPECT_EQ(val1.size(), val2.size());
- EXPECT_TRUE(equal(val1.begin(), val1.end(), val2.begin()));
- }
- }
- 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::object_handle oh =
- msgpack::unpack(sbuf.data(), sbuf.size());
- type const& val2 = oh.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;
- 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<type>();
- EXPECT_EQ(val1.size(), val2.size());
- EXPECT_TRUE(equal(val1.begin(), val1.end(), val2.begin()));
- }
- }
- TEST(MSGPACK_STL, simple_buffer_deque_empty)
- {
- typedef deque<int, test::allocator<int> > 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<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;
- 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<type>();
- EXPECT_EQ(val1.size(), val2.size());
- EXPECT_TRUE(equal(val1.begin(), val1.end(), val2.begin()));
- }
- }
- TEST(MSGPACK_STL, simple_buffer_list_empty)
- {
- typedef list<int, test::allocator<int> > 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<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;
- 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<type>();
- EXPECT_EQ(val1.size(), val2.size());
- EXPECT_TRUE(equal(val1.begin(), val1.end(), val2.begin()));
- }
- }
- 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::object_handle oh =
- msgpack::unpack(sbuf.data(), sbuf.size());
- type val2 = oh.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++) {
- pair<int, int> val1 = make_pair(rand(), rand());
- msgpack::sbuffer sbuf;
- msgpack::pack(sbuf, val1);
- msgpack::object_handle oh =
- msgpack::unpack(sbuf.data(), sbuf.size());
- pair<int, int> val2 = oh.get().as<pair<int, int> >();
- EXPECT_EQ(val1.first, val2.first);
- EXPECT_EQ(val1.second, val2.second);
- }
- }
- TEST(MSGPACK_STL, simple_buffer_multimap)
- {
- typedef multimap<int, int, test::less<int>, test::allocator<std::pair<const int, int> > > 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<type>();
- vector<pair<int, int> > 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<int, int, test::less<int>, test::allocator<std::pair<const int, int> > > 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<type>();
- EXPECT_EQ(val1.size(), val2.size());
- }
- TEST(MSGPACK_STL, simple_buffer_multiset)
- {
- typedef multiset<int, test::less<int>, test::allocator<int> > 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<type>();
- vector<int> 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<int, test::less<int>, test::allocator<int> > 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<type>();
- EXPECT_EQ(val1.size(), val2.size());
- }
- TEST(MSGPACK_TUPLE, simple_tuple)
- {
- msgpack::sbuffer sbuf;
- msgpack::type::tuple<bool, std::string, double> val1(true, "kzk", 12.3);
- msgpack::pack(sbuf, val1);
- msgpack::object_handle oh =
- msgpack::unpack(sbuf.data(), sbuf.size());
- msgpack::type::tuple<bool, std::string, double> val2
- = oh.get().as<msgpack::type::tuple<bool, std::string, double> >();
- 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<msgpack::type::tuple<> >();
- EXPECT_EQ(oh.get().via.array.size, 0u);
- }
- TEST(MSGPACK_TUPLE, simple_tuple_grater_than_as)
- {
- msgpack::sbuffer sbuf;
- msgpack::type::tuple<bool, std::string, int> val1(true, "kzk", 42);
- msgpack::pack(sbuf, val1);
- msgpack::object_handle oh =
- msgpack::unpack(sbuf.data(), sbuf.size());
- msgpack::type::tuple<bool, std::string, int, int> val2
- = oh.get().as<msgpack::type::tuple<bool, std::string, int, int> >();
- 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<bool, std::string, int> val1(true, "kzk", 42);
- msgpack::pack(sbuf, val1);
- msgpack::object_handle oh =
- msgpack::unpack(sbuf.data(), sbuf.size());
- msgpack::type::tuple<bool, std::string, int, int> 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<bool, std::string, int> val1(true, "kzk", 42);
- msgpack::pack(sbuf, val1);
- msgpack::object_handle oh =
- msgpack::unpack(sbuf.data(), sbuf.size());
- msgpack::type::tuple<bool, std::string> val2
- = oh.get().as<msgpack::type::tuple<bool, std::string> >();
- 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<bool, std::string, int> val1(true, "kzk", 42);
- msgpack::pack(sbuf, val1);
- msgpack::object_handle oh =
- msgpack::unpack(sbuf.data(), sbuf.size());
- msgpack::type::tuple<bool, std::string> 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>());
- }
- // TR1
- #if defined(MSGPACK_HAS_STD_TR1_UNORDERED_MAP) || defined(MSGPACK_HAS_STD_TR1_UNORDERED_SET)
- #include <tr1/functional>
- namespace test {
- template <class Key>
- struct tr1_hash : std::tr1::hash<Key> {
- };
- } // 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 <tr1/unordered_map>
- #include "msgpack/adaptor/tr1/unordered_map.hpp"
- TEST(MSGPACK_TR1, simple_buffer_tr1_unordered_map)
- {
- typedef tr1::unordered_map<int, int, test::tr1_hash<int>, test::equal_to<int>, test::allocator<std::pair<const int, int> > > 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<type>();
- 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<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::object_handle oh =
- msgpack::unpack(sbuf.data(), sbuf.size());
- type val2 = oh.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;
- 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<type>();
- vector<pair<int, int> > 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<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::object_handle oh =
- msgpack::unpack(sbuf.data(), sbuf.size());
- type val2 = oh.get().as<type>();
- EXPECT_EQ(val1.size(), val2.size());
- }
- #endif
- #ifdef MSGPACK_HAS_STD_TR1_UNORDERED_SET
- #include <tr1/unordered_set>
- #include "msgpack/adaptor/tr1/unordered_set.hpp"
- TEST(MSGPACK_TR1, simple_buffer_tr1_unordered_set)
- {
- typedef tr1::unordered_set<int, test::tr1_hash<int>, test::equal_to<int>, test::allocator<int> > 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<type>();
- 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<int, test::tr1_hash<int>, test::equal_to<int>, test::allocator<int> > 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<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;
- 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<type>();
- vector<int> 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<int, test::tr1_hash<int>, test::equal_to<int>, test::allocator<int> > 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<type>();
- EXPECT_EQ(val1.size(), val2.size());
- }
- #endif
- #if defined (MSGPACK_HAS_STD_UNORDERED_MAP) || defined (MSGPACK_HAS_STD_UNORDERED_SET)
- #include <functional>
- namespace test {
- template <class Key>
- struct hash : std::hash<Key> {
- };
- } // namespace test
- #endif // defined (MSGPACK_HAS_STD_UNORDERED_MAP) || defined (MSGPACK_HAS_STD_UNORDERED_SET)
- #ifdef MSGPACK_HAS_STD_UNORDERED_MAP
- #include <unordered_map>
- #include "msgpack/adaptor/tr1/unordered_map.hpp"
- TEST(MSGPACK_TR1, simple_buffer_unordered_map)
- {
- typedef unordered_map<int, int, test::hash<int>, test::equal_to<int>, test::allocator<std::pair<const int, int> > > 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<type>();
- 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<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::object_handle oh =
- msgpack::unpack(sbuf.data(), sbuf.size());
- type val2 = oh.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;
- 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<type>();
- vector<pair<int, int> > 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<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::object_handle oh =
- msgpack::unpack(sbuf.data(), sbuf.size());
- type val2 = oh.get().as<type>();
- EXPECT_EQ(val1.size(), val2.size());
- }
- #endif
- #ifdef MSGPACK_HAS_STD_UNORDERED_SET
- #include <unordered_set>
- #include "msgpack/adaptor/tr1/unordered_set.hpp"
- TEST(MSGPACK_TR1, simple_buffer_unordered_set)
- {
- typedef unordered_set<int, test::hash<int>, test::equal_to<int>, test::allocator<int> > 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<type>();
- 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<int, test::hash<int>, test::equal_to<int>, test::allocator<int> > 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<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;
- 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<type>();
- vector<int> 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<int, test::hash<int>, test::equal_to<int>, test::allocator<int> > 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<type>();
- EXPECT_EQ(val1.size(), val2.size());
- }
- #endif
|