1#include <msgpack.hpp> 2 3#include <gtest/gtest.h> 4 5#ifdef HAVE_CONFIG_H 6#include "config.h" 7#endif 8 9#if !defined(MSGPACK_USE_CPP03) 10 11class TestEnumClassMemberClass 12{ 13public: 14 TestEnumClassMemberClass() 15 : t1(TestEnumClassType::STATE_A), t2(TestEnumClassType::STATE_B), t3(TestEnumClassType::STATE_C) {} 16 17 enum class TestEnumClassType:long { 18 STATE_INVALID = 0, 19 STATE_A = 1, 20 STATE_B = 2, 21 STATE_C = 3 22 }; 23 TestEnumClassType t1; 24 TestEnumClassType t2; 25 TestEnumClassType t3; 26 27 MSGPACK_DEFINE(t1, t2, t3); 28}; 29 30MSGPACK_ADD_ENUM(TestEnumClassMemberClass::TestEnumClassType); 31 32using namespace std; 33 34const unsigned int kLoop = 10000; 35const unsigned int kElements = 100; 36 37 38// C++11 39 40TEST(MSGPACK_CPP11, simple_tuple) 41{ 42 msgpack::sbuffer sbuf; 43 std::tuple<bool, std::string, double> val1(true, "kzk", 12.3); 44 msgpack::pack(sbuf, val1); 45 msgpack::unpacked ret; 46 msgpack::unpack(ret, sbuf.data(), sbuf.size()); 47 std::tuple<bool, std::string, double> val2 = ret.get().as<std::tuple<bool, std::string, double> >(); 48 EXPECT_EQ(val1, val2); 49} 50 51TEST(MSGPACK_CPP11, simple_tuple_empty) 52{ 53 msgpack::sbuffer sbuf; 54 std::tuple<> val1; 55 msgpack::pack(sbuf, val1); 56 msgpack::unpacked ret; 57 msgpack::unpack(ret, sbuf.data(), sbuf.size()); 58 std::tuple<> val2 = ret.get().as<std::tuple<> >(); 59 EXPECT_EQ(val1, val2); 60} 61 62TEST(MSGPACK_CPP11, simple_array) 63{ 64 for (unsigned int k = 0; k < kLoop; k++) { 65 array<int, kElements> val1; 66 for (unsigned int i = 0; i < kElements; i++) 67 val1[i] = rand(); 68 msgpack::sbuffer sbuf; 69 msgpack::pack(sbuf, val1); 70 msgpack::unpacked ret; 71 msgpack::unpack(ret, sbuf.data(), sbuf.size()); 72 EXPECT_EQ(ret.get().type, msgpack::type::ARRAY); 73 array<int, kElements> val2 = ret.get().as<array<int, kElements> >(); 74 EXPECT_EQ(val1.size(), val2.size()); 75 EXPECT_TRUE(equal(val1.begin(), val1.end(), val2.begin())); 76 } 77} 78 79TEST(MSGPACK_CPP11, simple_array_empty) 80{ 81 array<int, 0> val1; 82 msgpack::sbuffer sbuf; 83 msgpack::pack(sbuf, val1); 84 msgpack::unpacked ret; 85 msgpack::unpack(ret, sbuf.data(), sbuf.size()); 86 EXPECT_EQ(ret.get().type, msgpack::type::ARRAY); 87 array<int, 0> val2 = ret.get().as<array<int, 0> >(); 88 EXPECT_EQ(val1.size(), val2.size()); 89 EXPECT_TRUE(equal(val1.begin(), val1.end(), val2.begin())); 90} 91 92TEST(MSGPACK_CPP11, simple_buffer_array_char) 93{ 94 for (unsigned int k = 0; k < kLoop; k++) { 95 array<char, kElements> val1; 96 for (unsigned int i = 0; i < kElements; i++) 97 val1[i] = rand(); 98 msgpack::sbuffer sbuf; 99 msgpack::pack(sbuf, val1); 100 msgpack::unpacked ret; 101 msgpack::unpack(ret, sbuf.data(), sbuf.size()); 102 EXPECT_EQ(ret.get().type, msgpack::type::BIN); 103 array<char, kElements> val2 = ret.get().as<array<char, kElements> >(); 104 EXPECT_EQ(val1.size(), val2.size()); 105 EXPECT_TRUE(equal(val1.begin(), val1.end(), val2.begin())); 106 } 107} 108 109TEST(MSGPACK_CPP11, simple_buffer_array_char_empty) 110{ 111 array<char, 0> val1; 112 msgpack::sbuffer sbuf; 113 msgpack::pack(sbuf, val1); 114 msgpack::unpacked ret; 115 msgpack::unpack(ret, sbuf.data(), sbuf.size()); 116 EXPECT_EQ(ret.get().type, msgpack::type::BIN); 117 array<char, 0> val2 = ret.get().as<array<char, 0> >(); 118 EXPECT_EQ(val1.size(), val2.size()); 119 EXPECT_TRUE(equal(val1.begin(), val1.end(), val2.begin())); 120} 121 122TEST(MSGPACK_CPP11, simple_buffer_array_unsigned_char) 123{ 124 if (!msgpack::is_same<uint8_t, unsigned char>::value) return; 125 for (unsigned int k = 0; k < kLoop; k++) { 126 array<unsigned char, kElements> val1; 127 for (unsigned int i = 0; i < kElements; i++) 128 val1[i] = rand(); 129 msgpack::sbuffer sbuf; 130 msgpack::pack(sbuf, val1); 131 msgpack::unpacked ret; 132 msgpack::unpack(ret, sbuf.data(), sbuf.size()); 133 EXPECT_EQ(ret.get().type, msgpack::type::BIN); 134 array<unsigned char, kElements> val2 = ret.get().as<array<unsigned char, kElements> >(); 135 EXPECT_EQ(val1.size(), val2.size()); 136 EXPECT_TRUE(equal(val1.begin(), val1.end(), val2.begin())); 137 } 138} 139 140TEST(MSGPACK_CPP11, simple_buffer_array_unsigned_char_empty) 141{ 142 if (!msgpack::is_same<uint8_t, unsigned char>::value) return; 143 array<unsigned char, 0> val1; 144 msgpack::sbuffer sbuf; 145 msgpack::pack(sbuf, val1); 146 msgpack::unpacked ret; 147 msgpack::unpack(ret, sbuf.data(), sbuf.size()); 148 EXPECT_EQ(ret.get().type, msgpack::type::BIN); 149 array<unsigned char, 0> val2 = ret.get().as<array<unsigned char, 0> >(); 150 EXPECT_EQ(val1.size(), val2.size()); 151 EXPECT_TRUE(equal(val1.begin(), val1.end(), val2.begin())); 152} 153 154// strong typedefs 155namespace test { 156 157template <class Key> 158struct hash : std::hash<Key> { 159 using std::hash<Key>::hash; 160}; 161 162template <class Key> 163struct equal_to : std::equal_to<Key> { 164 using std::equal_to<Key>::equal_to; 165}; 166 167template <class Key> 168struct set_allocator : std::allocator<Key> { 169 using std::allocator<Key>::allocator; 170}; 171 172template <class Key, class T> 173struct map_allocator : std::allocator<std::pair<const Key, T>> { 174 using std::allocator<std::pair<const Key, T>>::allocator; 175}; 176 177template <class T> 178struct allocator : std::allocator<T> { 179 using std::allocator<T>::allocator; 180}; 181 182} // namespace test 183 184 185TEST(MSGPACK_STL, simple_buffer_forward_list) 186{ 187 using type = forward_list<int, test::allocator<int>>; 188 for (unsigned int k = 0; k < kLoop; k++) { 189 type val1; 190 for (unsigned int i = 0; i < kElements; i++) 191 val1.push_front(rand()); 192 msgpack::sbuffer sbuf; 193 msgpack::pack(sbuf, val1); 194 msgpack::unpacked ret; 195 msgpack::unpack(ret, sbuf.data(), sbuf.size()); 196 type val2 = ret.get().as<type >(); 197 EXPECT_EQ(val1, val2); 198 } 199} 200 201TEST(MSGPACK_STL, simple_buffer_forward_list_empty) 202{ 203 using type = forward_list<int, test::allocator<int>>; 204 type val1; 205 msgpack::sbuffer sbuf; 206 msgpack::pack(sbuf, val1); 207 msgpack::unpacked ret; 208 msgpack::unpack(ret, sbuf.data(), sbuf.size()); 209 type val2 = ret.get().as<type >(); 210 EXPECT_EQ(val1, val2); 211} 212 213TEST(MSGPACK_STL, simple_buffer_unordered_map) 214{ 215 using type = unordered_map<int, int, test::hash<int>, test::equal_to<int>, test::map_allocator<int, int>>; 216 for (unsigned int k = 0; k < kLoop; k++) { 217 type val1; 218 for (unsigned int i = 0; i < kElements; i++) 219 val1[rand()] = rand(); 220 msgpack::sbuffer sbuf; 221 msgpack::pack(sbuf, val1); 222 msgpack::unpacked ret; 223 msgpack::unpack(ret, sbuf.data(), sbuf.size()); 224 type val2 = ret.get().as<type >(); 225 EXPECT_EQ(val1, val2); 226 } 227} 228 229TEST(MSGPACK_STL, simple_buffer_unordered_map_empty) 230{ 231 using type = unordered_map<int, int, test::hash<int>, test::equal_to<int>, test::map_allocator<int, int>>; 232 type val1; 233 msgpack::sbuffer sbuf; 234 msgpack::pack(sbuf, val1); 235 msgpack::unpacked ret; 236 msgpack::unpack(ret, sbuf.data(), sbuf.size()); 237 type val2 = ret.get().as<type >(); 238 EXPECT_EQ(val1, val2); 239} 240 241TEST(MSGPACK_STL, simple_buffer_unordered_multimap) 242{ 243 using type = unordered_multimap<int, int, test::hash<int>, test::equal_to<int>, test::map_allocator<int, int>>; 244 for (unsigned int k = 0; k < kLoop; k++) { 245 type val1; 246 for (unsigned int i = 0; i < kElements; i++) { 247 int i1 = rand(); 248 val1.insert(make_pair(i1, rand())); 249 val1.insert(make_pair(i1, rand())); 250 } 251 msgpack::sbuffer sbuf; 252 msgpack::pack(sbuf, val1); 253 msgpack::unpacked ret; 254 msgpack::unpack(ret, sbuf.data(), sbuf.size()); 255 type val2 = ret.get().as<type >(); 256 257 EXPECT_EQ(val1, val2); 258 } 259} 260 261TEST(MSGPACK_STL, simple_buffer_unordered_multimap_empty) 262{ 263 using type = unordered_multimap<int, int, test::hash<int>, test::equal_to<int>, test::map_allocator<int, int>>; 264 type val1; 265 msgpack::sbuffer sbuf; 266 msgpack::pack(sbuf, val1); 267 msgpack::unpacked ret; 268 msgpack::unpack(ret, sbuf.data(), sbuf.size()); 269 type val2 = ret.get().as<type >(); 270 271 EXPECT_EQ(val1, val2); 272} 273 274TEST(MSGPACK_STL, simple_buffer_unordered_set) 275{ 276 using type = unordered_set<int, test::hash<int>, test::equal_to<int>, test::set_allocator<int>>; 277 for (unsigned int k = 0; k < kLoop; k++) { 278 type val1; 279 for (unsigned int i = 0; i < kElements; i++) 280 val1.insert(rand()); 281 msgpack::sbuffer sbuf; 282 msgpack::pack(sbuf, val1); 283 msgpack::unpacked ret; 284 msgpack::unpack(ret, sbuf.data(), sbuf.size()); 285 type val2 = ret.get().as<type>(); 286 EXPECT_EQ(val1, val2); 287 } 288} 289 290TEST(MSGPACK_STL, simple_buffer_unordered_set_empty) 291{ 292 using type = unordered_set<int, test::hash<int>, test::equal_to<int>, test::set_allocator<int>>; 293 type val1; 294 msgpack::sbuffer sbuf; 295 msgpack::pack(sbuf, val1); 296 msgpack::unpacked ret; 297 msgpack::unpack(ret, sbuf.data(), sbuf.size()); 298 type val2 = ret.get().as<type>(); 299 EXPECT_EQ(val1, val2); 300} 301 302TEST(MSGPACK_STL, simple_buffer_unordered_multiset) 303{ 304 using type = unordered_multiset<int, test::hash<int>, test::equal_to<int>, test::set_allocator<int>>; 305 for (unsigned int k = 0; k < kLoop; k++) { 306 type val1; 307 for (unsigned int i = 0; i < kElements; i++) 308 val1.insert(rand()); 309 msgpack::sbuffer sbuf; 310 msgpack::pack(sbuf, val1); 311 msgpack::unpacked ret; 312 msgpack::unpack(ret, sbuf.data(), sbuf.size()); 313 type val2 = ret.get().as<type >(); 314 EXPECT_EQ(val1, val2); 315 } 316} 317 318TEST(MSGPACK_STL, simple_buffer_unordered_multiset_empty) 319{ 320 using type = unordered_multiset<int, test::hash<int>, test::equal_to<int>, test::set_allocator<int>>; 321 type val1; 322 msgpack::sbuffer sbuf; 323 msgpack::pack(sbuf, val1); 324 msgpack::unpacked ret; 325 msgpack::unpack(ret, sbuf.data(), sbuf.size()); 326 type val2 = ret.get().as<type >(); 327 EXPECT_EQ(val1, val2); 328} 329 330TEST(MSGPACK_USER_DEFINED, simple_buffer_enum_class_member) 331{ 332 TestEnumClassMemberClass val1; 333 msgpack::sbuffer sbuf; 334 msgpack::pack(sbuf, val1); 335 msgpack::unpacked ret; 336 msgpack::unpack(ret, sbuf.data(), sbuf.size()); 337 TestEnumClassMemberClass val2 = ret.get().as<TestEnumClassMemberClass>(); 338 EXPECT_EQ(val1.t1, val2.t1); 339 EXPECT_EQ(val1.t2, val2.t2); 340 EXPECT_EQ(val1.t3, val2.t3); 341} 342 343struct no_def_con { 344 no_def_con() = delete; 345 no_def_con(int i):i(i) {} 346 int i; 347 MSGPACK_DEFINE(i); 348}; 349 350inline bool operator==(no_def_con const& lhs, no_def_con const& rhs) { 351 return lhs.i == rhs.i; 352} 353 354inline bool operator!=(no_def_con const& lhs, no_def_con const& rhs) { 355 return !(lhs == rhs); 356} 357 358inline bool operator<(no_def_con const& lhs, no_def_con const& rhs) { 359 return lhs.i < rhs.i; 360} 361 362namespace msgpack { 363MSGPACK_API_VERSION_NAMESPACE(MSGPACK_DEFAULT_API_NS) { 364 namespace adaptor { 365 template <> 366 struct as<no_def_con> { 367 no_def_con operator()(msgpack::object const& o) const { 368 if (o.type != msgpack::type::ARRAY) throw msgpack::type_error(); 369 if (o.via.array.size != 1) throw msgpack::type_error(); 370 return no_def_con(o.via.array.ptr[0].as<int>()); 371 } 372 }; 373 } // adaptor 374} // MSGPACK_API_VERSION_NAMESPACE(MSGPACK_DEFAULT_API_NS) 375} // msgpack 376 377namespace std { 378template <> struct hash<no_def_con> { 379 size_t operator()(const no_def_con & x) const { 380 return hash<int>()(x.i); 381 } 382}; 383} // std 384 385TEST(MSGPACK_NO_DEF_CON, simple_buffer) 386{ 387 no_def_con val1(42); 388 msgpack::sbuffer sbuf; 389 msgpack::pack(sbuf, val1); 390 msgpack::unpacked ret; 391 msgpack::unpack(ret, sbuf.data(), sbuf.size()); 392 393 no_def_con val2 = ret.get().as<no_def_con>(); 394 EXPECT_EQ(val1, val2); 395} 396 397struct no_def_con_composite { 398 no_def_con_composite() = delete; 399 no_def_con_composite(int i):ndc(i) {} 400 no_def_con_composite(no_def_con const& a):ndc(a) {} 401 no_def_con ndc; 402 MSGPACK_DEFINE(ndc); 403}; 404 405inline bool operator==(no_def_con_composite const& lhs, no_def_con_composite const& rhs) { 406 return lhs.ndc == rhs.ndc; 407} 408 409inline bool operator!=(no_def_con_composite const& lhs, no_def_con_composite const& rhs) { 410 return !(lhs == rhs); 411} 412 413inline bool operator<(no_def_con_composite const& lhs, no_def_con_composite const& rhs) { 414 return lhs.ndc < rhs.ndc; 415} 416 417namespace msgpack { 418MSGPACK_API_VERSION_NAMESPACE(MSGPACK_DEFAULT_API_NS) { 419 namespace adaptor { 420 template <> 421 struct as<no_def_con_composite> { 422 no_def_con_composite operator()(msgpack::object const& o) const { 423 if (o.type != msgpack::type::ARRAY) throw msgpack::type_error(); 424 if (o.via.array.size != 1) throw msgpack::type_error(); 425 return no_def_con_composite(o.via.array.ptr[0].as<no_def_con>()); 426 } 427 }; 428 } // adaptor 429} // MSGPACK_API_VERSION_NAMESPACE(MSGPACK_DEFAULT_API_NS) 430} // msgpack 431 432TEST(MSGPACK_NO_DEF_CON_COMPOSITE, simple_buffer) 433{ 434 no_def_con_composite val1(42); 435 msgpack::sbuffer sbuf; 436 msgpack::pack(sbuf, val1); 437 msgpack::unpacked ret; 438 msgpack::unpack(ret, sbuf.data(), sbuf.size()); 439 no_def_con_composite val2 = ret.get().as<no_def_con_composite>(); 440 EXPECT_EQ(val1, val2); 441} 442 443struct no_def_con_inherit : no_def_con { 444 no_def_con_inherit() = delete; 445 no_def_con_inherit(no_def_con const& a):no_def_con(a) {} 446 MSGPACK_DEFINE(MSGPACK_BASE(no_def_con)); 447}; 448 449namespace msgpack { 450MSGPACK_API_VERSION_NAMESPACE(MSGPACK_DEFAULT_API_NS) { 451 namespace adaptor { 452 template <> 453 struct as<no_def_con_inherit> { 454 no_def_con_inherit operator()(msgpack::object const& o) const { 455 if (o.type != msgpack::type::ARRAY) throw msgpack::type_error(); 456 if (o.via.array.size != 1) throw msgpack::type_error(); 457 return no_def_con_inherit(o.via.array.ptr[0].as<no_def_con>()); 458 } 459 }; 460 } // adaptor 461} // MSGPACK_API_VERSION_NAMESPACE(MSGPACK_DEFAULT_API_NS) 462} // msgpack 463 464TEST(MSGPACK_NO_DEF_CON_INHERIT, simple_buffer) 465{ 466 no_def_con_inherit val1(42); 467 msgpack::sbuffer sbuf; 468 msgpack::pack(sbuf, val1); 469 msgpack::unpacked ret; 470 msgpack::unpack(ret, sbuf.data(), sbuf.size()); 471 no_def_con_inherit val2 = ret.get().as<no_def_con_inherit>(); 472 EXPECT_EQ(val1, val2); 473} 474 475TEST(MSGPACK_NO_DEF_CON_VECTOR, simple_buffer) 476{ 477 std::vector<no_def_con> val1 { 1, 2, 3 }; 478 msgpack::sbuffer sbuf; 479 msgpack::pack(sbuf, val1); 480 msgpack::unpacked ret; 481 msgpack::unpack(ret, sbuf.data(), sbuf.size()); 482 std::vector<no_def_con> val2 = ret.get().as<std::vector<no_def_con>>(); 483 EXPECT_EQ(val1, val2); 484} 485 486TEST(MSGPACK_NO_DEF_CON_LIST, simple_buffer) 487{ 488 std::list<no_def_con> val1 { 1, 2, 3 }; 489 msgpack::sbuffer sbuf; 490 msgpack::pack(sbuf, val1); 491 msgpack::unpacked ret; 492 msgpack::unpack(ret, sbuf.data(), sbuf.size()); 493 std::list<no_def_con> val2 = ret.get().as<std::list<no_def_con>>(); 494 EXPECT_EQ(val1, val2); 495} 496 497TEST(MSGPACK_NO_DEF_CON_SET, simple_buffer) 498{ 499 std::set<no_def_con> val1 { 1, 2, 3 }; 500 msgpack::sbuffer sbuf; 501 msgpack::pack(sbuf, val1); 502 msgpack::unpacked ret; 503 msgpack::unpack(ret, sbuf.data(), sbuf.size()); 504 std::set<no_def_con> val2 = ret.get().as<std::set<no_def_con>>(); 505 EXPECT_EQ(val1, val2); 506} 507 508TEST(MSGPACK_NO_DEF_CON_MULTISET, simple_buffer) 509{ 510 std::multiset<no_def_con> val1 { 1, 2, 3 }; 511 msgpack::sbuffer sbuf; 512 msgpack::pack(sbuf, val1); 513 msgpack::unpacked ret; 514 msgpack::unpack(ret, sbuf.data(), sbuf.size()); 515 std::multiset<no_def_con> val2 = ret.get().as<std::multiset<no_def_con>>(); 516 EXPECT_EQ(val1, val2); 517} 518 519TEST(MSGPACK_NO_DEF_CON_ASSOC_VECTOR, simple_buffer) 520{ 521 msgpack::type::assoc_vector<no_def_con, no_def_con_composite> val1 { {1, 2}, {3, 4}, {5, 6}}; 522 msgpack::sbuffer sbuf; 523 msgpack::pack(sbuf, val1); 524 msgpack::unpacked ret; 525 msgpack::unpack(ret, sbuf.data(), sbuf.size()); 526 msgpack::type::assoc_vector<no_def_con, no_def_con_composite> val2 527 = ret.get().as<msgpack::type::assoc_vector<no_def_con, no_def_con_composite>>(); 528 EXPECT_EQ(val1, val2); 529} 530 531TEST(MSGPACK_NO_DEF_CON_MAP, simple_buffer) 532{ 533 std::map<no_def_con, no_def_con_composite> val1 { {1, 2}, {3, 4}, {5, 6}}; 534 msgpack::sbuffer sbuf; 535 msgpack::pack(sbuf, val1); 536 msgpack::unpacked ret; 537 msgpack::unpack(ret, sbuf.data(), sbuf.size()); 538 std::map<no_def_con, no_def_con_composite> val2 539 = ret.get().as<std::map<no_def_con, no_def_con_composite>>(); 540 EXPECT_EQ(val1, val2); 541} 542 543TEST(MSGPACK_NO_DEF_CON_MULTIMAP, simple_buffer) 544{ 545 std::multimap<no_def_con, no_def_con_composite> val1 { {1, 2}, {3, 4}, {5, 6}}; 546 msgpack::sbuffer sbuf; 547 msgpack::pack(sbuf, val1); 548 msgpack::unpacked ret; 549 msgpack::unpack(ret, sbuf.data(), sbuf.size()); 550 std::multimap<no_def_con, no_def_con_composite> val2 551 = ret.get().as<std::multimap<no_def_con, no_def_con_composite>>(); 552 EXPECT_EQ(val1, val2); 553} 554 555TEST(MSGPACK_NO_DEF_CON_DEQUE, simple_buffer) 556{ 557 std::deque<no_def_con> val1 { 1, 2, 3 }; 558 msgpack::sbuffer sbuf; 559 msgpack::pack(sbuf, val1); 560 msgpack::unpacked ret; 561 msgpack::unpack(ret, sbuf.data(), sbuf.size()); 562 std::deque<no_def_con> val2 = ret.get().as<std::deque<no_def_con>>(); 563 EXPECT_EQ(val1, val2); 564} 565 566TEST(MSGPACK_NO_DEF_CON_PAIR, simple_buffer) 567{ 568 std::pair<no_def_con, no_def_con_composite> val1 {1, 2}; 569 msgpack::sbuffer sbuf; 570 msgpack::pack(sbuf, val1); 571 msgpack::unpacked ret; 572 msgpack::unpack(ret, sbuf.data(), sbuf.size()); 573 std::pair<no_def_con, no_def_con_composite> val2 574 = ret.get().as<std::pair<no_def_con, no_def_con_composite>>(); 575 EXPECT_EQ(val1, val2); 576} 577 578 579 580// MSVC2015's std::tuple requires default constructor during 'as' process. 581// It doesn't support Expression SFINAE yet, then 'as' is fallbacked to 'convert'. 582// After MSVC would support Expression SFINAE, remove this guard. 583#if !defined(_MSC_VER) 584 585TEST(MSGPACK_NO_DEF_CON_TUPLE, simple_buffer) 586{ 587 std::tuple<no_def_con, no_def_con, no_def_con_composite> val1 {1, 2, 3}; 588 msgpack::sbuffer sbuf; 589 msgpack::pack(sbuf, val1); 590 msgpack::unpacked ret; 591 msgpack::unpack(ret, sbuf.data(), sbuf.size()); 592 std::tuple<no_def_con, no_def_con, no_def_con_composite> val2 593 = ret.get().as<std::tuple<no_def_con, no_def_con, no_def_con_composite>>(); 594 EXPECT_EQ(val1, val2); 595} 596 597TEST(MSGPACK_NO_DEF_CON_MSGPACK_TUPLE, simple_buffer) 598{ 599 msgpack::type::tuple<no_def_con, no_def_con, no_def_con_composite> val1 {1, 2, 3}; 600 msgpack::sbuffer sbuf; 601 msgpack::pack(sbuf, val1); 602 msgpack::unpacked ret; 603 msgpack::unpack(ret, sbuf.data(), sbuf.size()); 604 msgpack::type::tuple<no_def_con, no_def_con, no_def_con_composite> val2 605 = ret.get().as<msgpack::type::tuple<no_def_con, no_def_con, no_def_con_composite>>(); 606 EXPECT_EQ(val1, val2); 607} 608 609#endif // !define(_MSC_VER) 610 611TEST(MSGPACK_NO_DEF_FORWARD_LIST, simple_buffer) 612{ 613 std::forward_list<no_def_con> val1 { 1, 2, 3 }; 614 msgpack::sbuffer sbuf; 615 msgpack::pack(sbuf, val1); 616 msgpack::unpacked ret; 617 msgpack::unpack(ret, sbuf.data(), sbuf.size()); 618 std::forward_list<no_def_con> val2 = ret.get().as<std::forward_list<no_def_con>>(); 619 EXPECT_TRUE(val1 == val2); 620} 621 622TEST(MSGPACK_NO_DEF_CON_UNORDERED_SET, simple_buffer) 623{ 624 std::unordered_set<no_def_con> val1 { 1, 2, 3 }; 625 msgpack::sbuffer sbuf; 626 msgpack::pack(sbuf, val1); 627 msgpack::unpacked ret; 628 msgpack::unpack(ret, sbuf.data(), sbuf.size()); 629 std::unordered_set<no_def_con> val2 = ret.get().as<std::unordered_set<no_def_con>>(); 630 EXPECT_EQ(val1, val2); 631} 632 633TEST(MSGPACK_NO_DEF_CON_UNORDERED_MULTISET, simple_buffer) 634{ 635 std::unordered_multiset<no_def_con> val1 { 1, 2, 3 }; 636 msgpack::sbuffer sbuf; 637 msgpack::pack(sbuf, val1); 638 msgpack::unpacked ret; 639 msgpack::unpack(ret, sbuf.data(), sbuf.size()); 640 std::unordered_multiset<no_def_con> val2 = ret.get().as<std::unordered_multiset<no_def_con>>(); 641 EXPECT_EQ(val1, val2); 642} 643 644TEST(MSGPACK_NO_DEF_CON_UNORDERED_MAP, simple_buffer) 645{ 646 std::unordered_map<no_def_con, no_def_con_composite> val1 { {1, 2}, {3, 4}, {5, 6}}; 647 msgpack::sbuffer sbuf; 648 msgpack::pack(sbuf, val1); 649 msgpack::unpacked ret; 650 msgpack::unpack(ret, sbuf.data(), sbuf.size()); 651 std::unordered_map<no_def_con, no_def_con_composite> val2 652 = ret.get().as<std::unordered_map<no_def_con, no_def_con_composite>>(); 653 EXPECT_EQ(val1, val2); 654} 655 656TEST(MSGPACK_NO_DEF_CON_UNORDERED_MULTIMAP, simple_buffer) 657{ 658 std::unordered_multimap<no_def_con, no_def_con_composite> val1 { {1, 2}, {3, 4}, {5, 6}}; 659 msgpack::sbuffer sbuf; 660 msgpack::pack(sbuf, val1); 661 msgpack::unpacked ret; 662 msgpack::unpack(ret, sbuf.data(), sbuf.size()); 663 std::unordered_multimap<no_def_con, no_def_con_composite> val2 664 = ret.get().as<std::unordered_multimap<no_def_con, no_def_con_composite>>(); 665 EXPECT_EQ(val1, val2); 666} 667 668TEST(MSGPACK_NO_DEF_CON_ARRAY, simple_buffer) 669{ 670 std::array<no_def_con, 3> val1 { { 1, 2, 3 } }; 671 msgpack::sbuffer sbuf; 672 msgpack::pack(sbuf, val1); 673 msgpack::unpacked ret; 674 msgpack::unpack(ret, sbuf.data(), sbuf.size()); 675 std::array<no_def_con, 3> val2 = ret.get().as<std::array<no_def_con, 3>>(); 676 EXPECT_EQ(val1, val2); 677} 678 679#endif // !defined(MSGPACK_USE_CPP03) 680