bool boost_fusion_vector_test(std::ostream &log, const char *archive_type, const char *test_name) { boost::fusion::vector<int, double> v1(33, 3.14), v2; typename archive_traits::oarchive oa; archive_traits::ocreate(oa, archive_type); oa & YAS_OBJECT_NVP("obj", ("vector", v1)); typename archive_traits::iarchive ia; archive_traits::icreate(ia, oa, archive_type); ia & YAS_OBJECT_NVP("obj", ("vector", v2)); if ( v1 != v2 ) { YAS_TEST_REPORT(log, archive_type, test_name); return false; } std::set<std::string> set; set.insert("2"); set.insert("3"); set.insert("4"); boost::fusion::vector< std::string, std::set<std::string> > v3("1", std::move(set)), v4; typename archive_traits::oarchive oa2; archive_traits::ocreate(oa2, archive_type); oa2 & YAS_OBJECT_NVP("obj", ("vector", v3)); typename archive_traits::iarchive ia2; archive_traits::icreate(ia2, oa2, archive_type); ia2 & YAS_OBJECT_NVP("obj", ("vector", v4)); if ( v3 != v4 ) { YAS_TEST_REPORT(log, archive_type, test_name); return false; } boost::fusion::vector<int, int> vv; typename archive_traits::oarchive oa3; archive_traits::ocreate(oa3, archive_type); oa3 & YAS_OBJECT_NVP("obj", ("vector", boost::fusion::make_vector(33,44))); typename archive_traits::iarchive ia3; archive_traits::icreate(ia3, oa3, archive_type); ia3 & YAS_OBJECT_NVP("obj", ("vector", vv)); if ( vv != boost::fusion::make_vector(33,44) ) { YAS_TEST_REPORT(log, archive_type, test_name); return false; } static const char str[] = "str"; boost::fusion::vector<boost::uint64_t, std::string> v5(33, str), v6, v7; typename archive_traits::oarchive oa4; archive_traits::ocreate(oa4, archive_type); oa4 & YAS_OBJECT_NVP("obj", ("vector", v5)); static const std::size_t binary_expected_size = archive_traits::oarchive_type::header_size() // archive header +sizeof(std::uint8_t) // fusion::vector size marker +sizeof(std::uint64_t) // first type +sizeof(std::uint64_t) // string size marker +std::strlen(str) // string ; static const std::size_t binary_compacted_expected_size = archive_traits::oarchive_type::header_size() // archive header +sizeof(std::uint8_t) // fusion::vector size marker +1/*len of next field*/ +1/*string length*/+std::strlen(str) // string ; static const std::size_t text_expected_size = archive_traits::oarchive_type::header_size() +1/*len of next field*/+1/*size marker*/ +1/*len of next field*/+2/*value*/ +1/*len of next field*/+1/*string len*/+3/*string*/ ; if ( yas::is_binary_archive<typename archive_traits::oarchive_type>::value ) { if ( archive_traits::oarchive_type::compacted() ) { const size_t current_size = oa4.size(); if (current_size != binary_compacted_expected_size) { YAS_TEST_REPORT(log, archive_type, test_name); return false; } } else { const size_t current_size = oa4.size(); if (current_size != binary_expected_size) { YAS_TEST_REPORT(log, archive_type, test_name); return false; } } } if ( yas::is_text_archive<typename archive_traits::oarchive_type>::value ) { const size_t current_size = oa4.size(); if ( current_size != text_expected_size ) { YAS_TEST_REPORT(log, archive_type, test_name); return false; } } typename archive_traits::iarchive ia4; archive_traits::icreate(ia4, oa4, archive_type); ia4 & YAS_OBJECT_NVP("obj", ("vector", v6)); if ( v5 != v6 ) { YAS_TEST_REPORT(log, archive_type, test_name); return false; } typename archive_traits::oarchive oa5; archive_traits::ocreate(oa5, archive_type); auto v = boost::fusion::make_vector<boost::uint64_t, std::string>(33, "str"); oa5 & YAS_OBJECT_NVP("obj", ("vector", std::move(v))); if ( yas::is_binary_archive<typename archive_traits::oarchive_type>::value ) { if ( archive_traits::oarchive_type::compacted() ) { const size_t current_size2 = oa5.size(); if (current_size2 != binary_compacted_expected_size) { YAS_TEST_REPORT(log, archive_type, test_name); return false; } } else { const size_t current_size2 = oa5.size(); if (current_size2 != binary_expected_size) { YAS_TEST_REPORT(log, archive_type, test_name); return false; } } } if ( yas::is_text_archive<typename archive_traits::oarchive_type>::value ) { const size_t current_size = oa5.size(); if ( current_size != text_expected_size ) { YAS_TEST_REPORT(log, archive_type, test_name); return false; } } typename archive_traits::iarchive ia5; archive_traits::icreate(ia5, oa5, archive_type); ia5 & YAS_OBJECT_NVP("obj", ("vector", v7)); if ( v5 != v7 ) { YAS_TEST_REPORT(log, archive_type, test_name); return false; } boost::fusion::vector<> vv0, vv1; typename archive_traits::oarchive oa6; archive_traits::ocreate(oa6, archive_type); oa6 & YAS_OBJECT_NVP("obj", ("vector", vv0)); if ( yas::is_binary_archive<typename archive_traits::oarchive_type>::value ) { if ( oa6.size() != (archive_traits::oarchive_type::header_size()+1) ) { YAS_TEST_REPORT(log, archive_type, test_name); return false; } } if ( yas::is_text_archive<typename archive_traits::oarchive_type>::value ) { if ( oa6.size() != (archive_traits::oarchive_type::header_size()+1/*len of next field*/+1/*size marker*/) ) { YAS_TEST_REPORT(log, archive_type, test_name); return false; } } typename archive_traits::iarchive ia6; archive_traits::icreate(ia6, oa6, archive_type); ia6 & YAS_OBJECT_NVP("obj", ("vector", vv1)); boost::fusion::vector0<> ve0, ve1; typename archive_traits::oarchive oa7; archive_traits::ocreate(oa7, archive_type); oa7 & YAS_OBJECT_NVP("obj", ("vector", ve0)); if ( yas::is_binary_archive<typename archive_traits::oarchive_type>::value ) { if ( oa7.size() != (archive_traits::oarchive_type::header_size()+1) ) { YAS_TEST_REPORT(log, archive_type, test_name); return false; } } if ( yas::is_text_archive<typename archive_traits::oarchive_type>::value ) { if ( oa7.size() != (archive_traits::oarchive_type::header_size()+1/*len of next field*/+1/*size marker*/) ) { YAS_TEST_REPORT(log, archive_type, test_name); return false; } } typename archive_traits::iarchive ia7; archive_traits::icreate(ia7, oa7, archive_type); ia7 & YAS_OBJECT_NVP("obj", ("vector", ve1)); return true; }
bool buffer_test(const char* archive_type, const char* io_type) { // binary: 4(header) + 4(string length) +21(string)= 29 // text : 5(header) +1(space) + 2(string length) + 1(space) +21(string) = 30 static const char str1[] = "intrusive buffer test"; yas::intrusive_buffer buf1(str1, sizeof(str1)-1); typename archive_traits::oarchive oa1; archive_traits::ocreate(oa1, archive_type, io_type); oa1 & buf1; // binary if ( yas::is_binary_archive<typename archive_traits::oarchive_type>::value ) { static const unsigned char _res64_le[] = { _HEADER_BYTES(),0x43,0x15,0x00,0x00,0x00,0x69,0x6e,0x74,0x72,0x75,0x73 ,0x69,0x76,0x65,0x20,0x62,0x75,0x66,0x66,0x65,0x72,0x20,0x74,0x65,0x73,0x74 }; static const unsigned char _res32_le[] = { _HEADER_BYTES(),0x03,0x15,0x00,0x00,0x00,0x69,0x6e,0x74,0x72,0x75,0x73 ,0x69,0x76,0x65,0x20,0x62,0x75,0x66,0x66,0x65,0x72,0x20,0x74,0x65,0x73,0x74 }; static const unsigned char _res64_be[] = { _HEADER_BYTES(),0x44,0x00,0x00,0x00,0x15,0x69,0x6e,0x74,0x72,0x75,0x73 ,0x69,0x76,0x65,0x20,0x62,0x75,0x66,0x66,0x65,0x72,0x20,0x74,0x65,0x73,0x74 }; static const unsigned char _res32_be[] = { _HEADER_BYTES(),0x03,0x00,0x00,0x00,0x15,0x69,0x6e,0x74,0x72,0x75,0x73 ,0x69,0x76,0x65,0x20,0x62,0x75,0x66,0x66,0x65,0x72,0x20,0x74,0x65,0x73,0x74 }; const unsigned char *res_ptr = ( YAS_PLATFORM_BITS_IS_64() ? oa1.is_little_endian() ? _res64_le : _res64_be : oa1.is_little_endian() ? _res32_le : _res32_be ); const unsigned int res_size= ( YAS_PLATFORM_BITS_IS_64() ? oa1.is_little_endian() ? sizeof(_res64_le) : sizeof(_res64_be) : oa1.is_little_endian() ? sizeof(_res32_le) : sizeof(_res32_be) ); if ( oa1.size() != res_size ) { std::cout << "BUFFER intrusive serialization error! [1]" << std::endl; return false; } if ( !oa1.compare(res_ptr, res_size) ) { std::cout << "BUFFER intrusive serialization error! [2]" << std::endl; return false; } // text } else if ( yas::is_text_archive<typename archive_traits::oarchive_type>::value ) { static const unsigned char res64[] = { // "yas49 0221intrusive buffer test" _HEADER_BYTES(),0x34,0x39,0x20,0x30,0x32,0x32,0x31,0x69,0x6e,0x74,0x72,0x75,0x73 ,0x69,0x76,0x65,0x20,0x62,0x75,0x66,0x66,0x65,0x72,0x20,0x74,0x65,0x73,0x74 }; static const unsigned char res32[] = { // "yas09 0221intrusive buffer test" _HEADER_BYTES(),0x30,0x39,0x20,0x30,0x32,0x32,0x31,0x69,0x6e,0x74,0x72,0x75,0x73 ,0x69,0x76,0x65,0x20,0x62,0x75,0x66,0x66,0x65,0x72,0x20,0x74,0x65,0x73,0x74 }; const unsigned char *res_ptr = (YAS_PLATFORM_BITS_IS_64()) ? res64 : res32; const unsigned int res_size = (YAS_PLATFORM_BITS_IS_64()) ? sizeof(res64) : sizeof(res32); if ( oa1.size() != res_size ) { std::cout << "BUFFER intrusive serialization error! [3]" << std::endl; return false; } if ( !oa1.compare(res_ptr, res_size) ) { std::cout << "BUFFER intrusive serialization error! [4]" << std::endl; return false; } // json } else if ( yas::is_json_archive<typename archive_traits::oarchive_type>::value ) { std::cout << "BUFFER intrusive serialization error! json is not implemented!" << std::endl; return false; } static const char str2[] = "shared buffer test"; // 18 + 4(header) + 4(size of array) = 26 yas::shared_buffer buf2(str2, sizeof(str2)-1); typename archive_traits::oarchive oa2; archive_traits::ocreate(oa2, archive_type, io_type); oa2 & buf2; if ( yas::is_binary_archive<typename archive_traits::oarchive_type>::value ) { static const unsigned char _res64_le[] = { _HEADER_BYTES(),0x43,0x12,0x00,0x00,0x00,0x73,0x68,0x61 ,0x72,0x65,0x64,0x20,0x62,0x75,0x66,0x66,0x65,0x72,0x20,0x74,0x65,0x73,0x74 }; static const unsigned char _res32_le[] = { _HEADER_BYTES(),0x03,0x12,0x00,0x00,0x00,0x73,0x68,0x61 ,0x72,0x65,0x64,0x20,0x62,0x75,0x66,0x66,0x65,0x72,0x20,0x74,0x65,0x73,0x74 }; static const unsigned char _res64_be[] = { _HEADER_BYTES(),0x44,0x00,0x00,0x00,0x12,0x73,0x68,0x61 ,0x72,0x65,0x64,0x20,0x62,0x75,0x66,0x66,0x65,0x72,0x20,0x74,0x65,0x73,0x74 }; static const unsigned char _res32_be[] = { _HEADER_BYTES(),0x03,0x00,0x00,0x00,0x12,0x73,0x68,0x61 ,0x72,0x65,0x64,0x20,0x62,0x75,0x66,0x66,0x65,0x72,0x20,0x74,0x65,0x73,0x74 }; const unsigned char *res_ptr = ( YAS_PLATFORM_BITS_IS_64() ? oa2.is_little_endian() ? _res64_le : _res64_be : oa2.is_little_endian() ? _res32_le : _res32_be ); const unsigned int res_size= ( YAS_PLATFORM_BITS_IS_64() ? oa2.is_little_endian() ? sizeof(_res64_le) : sizeof(_res64_be) : oa2.is_little_endian() ? sizeof(_res32_le) : sizeof(_res32_be) ); if ( oa2.size() != res_size ) { std::cout << "BUFFER shared serialization error! [5]" << std::endl; return false; } if ( !oa2.compare(res_ptr, res_size) ) { std::cout << "BUFFER shared serialization error! [6]" << std::endl; return false; } } else if ( yas::is_text_archive<typename archive_traits::oarchive_type>::value ) { static const unsigned char res64[] = { // "yas4A 0218shared buffer test" _HEADER_BYTES(),0x34,0x39,0x20,0x30,0x32,0x31,0x38,0x73,0x68 ,0x61,0x72,0x65,0x64,0x20,0x62,0x75,0x66,0x66,0x65,0x72,0x20,0x74,0x65,0x73,0x74 }; static const unsigned char res32[] = { // "yas09 0218shared buffer test" _HEADER_BYTES(),0x30,0x39,0x20,0x30,0x32,0x31,0x38,0x73,0x68 ,0x61,0x72,0x65,0x64,0x20,0x62,0x75,0x66,0x66,0x65,0x72,0x20,0x74,0x65,0x73,0x74 }; const unsigned char* res_ptr = (YAS_PLATFORM_BITS_IS_64() ? res64 : res32); const unsigned int res_size= (YAS_PLATFORM_BITS_IS_64() ? sizeof(res64) : sizeof(res32)); if ( oa2.size() != res_size ) { std::cout << "BUFFER shared serialization error! [7]" << std::endl; return false; } if ( !oa2.compare(res_ptr, res_size) ) { std::cout << "BUFFER shared serialization error! [8]" << std::endl; return false; } typename archive_traits::iarchive ia1; archive_traits::icreate(ia1, oa2, archive_type, io_type); yas::shared_buffer buf4; ia1 & buf4; if ( buf4.size != sizeof(str2)-1 || memcmp(str2, buf4.data.get(), buf4.size) ) { std::cout << "BUFFER shared deserialization error! [9]" << std::endl; return false; } } return true; }
bool fusion_vector_test(const char* archive_type, const char* io_type) { boost::fusion::vector<int, double> v1(33, 3.14), v2; typename archive_traits::oarchive oa; archive_traits::ocreate(oa, archive_type, io_type); oa & v1; typename archive_traits::iarchive ia; archive_traits::icreate(ia, oa, archive_type, io_type); ia & v2; if ( v1 != v2 ) { std::cout << "FUSION_VECTOR deserialization error! [1]" << std::endl; return false; } std::set<std::string> set; set.insert("2"); set.insert("3"); set.insert("4"); boost::fusion::vector< std::string, std::set<std::string> > v3("1", set), v4; typename archive_traits::oarchive oa2; archive_traits::ocreate(oa2, archive_type, io_type); oa2 & v3; typename archive_traits::iarchive ia2; archive_traits::icreate(ia2, oa2, archive_type, io_type); ia2 & v4; if ( v3 != v4 ) { std::cout << "FUSION_VECTOR deserialization error! [2]" << std::endl; return false; } boost::fusion::vector<int, int> vv; typename archive_traits::oarchive oa3; archive_traits::ocreate(oa3, archive_type, io_type); oa3 & boost::fusion::make_vector(33,44); typename archive_traits::iarchive ia3; archive_traits::icreate(ia3, oa3, archive_type, io_type); ia3 & vv; if ( vv != boost::fusion::make_vector(33,44) ) { std::cout << "FUSION_VECTOR deserialization error! [3]" << std::endl; return false; } static const char str[] = "str"; boost::fusion::vector<boost::uint64_t, std::string> v5(33, str), v6; typename archive_traits::oarchive oa4; archive_traits::ocreate(oa4, archive_type, io_type); oa4 & v5; const size_t expected_size = 4+ // archive information sizeof(std::uint8_t)+ // fusion::vector size marker sizeof(std::uint64_t)+ // first type sizeof(std::uint32_t)+ // string size marker strlen(str); // string length if ( yas::is_binary_archive<typename archive_traits::oarchive_type>::value ) { const size_t current_size = oa4.size(); if ( current_size != expected_size ) { std::cout << "FUSION_VECTOR deserialization error! [4]" << std::endl; return false; } } typename archive_traits::iarchive ia4; archive_traits::icreate(ia4, oa4, archive_type, io_type); ia4 & v6; if ( v5 != v6 ) { std::cout << "FUSION_VECTOR deserialization error! [5]" << std::endl; return false; } typename archive_traits::oarchive oa5; archive_traits::ocreate(oa5, archive_type, io_type); oa5 & boost::fusion::make_vector<boost::uint64_t, std::string>(33, "str"); if ( yas::is_binary_archive<typename archive_traits::oarchive_type>::value ) { const size_t current_size2 = oa5.size(); if ( current_size2 != expected_size ) { std::cout << "FUSION_VECTOR deserialization error! [6]" << std::endl; return false; } } typename archive_traits::iarchive ia5; archive_traits::icreate(ia5, oa5, archive_type, io_type); ia5 & v6; if ( v5 != v6 ) { std::cout << "FUSION_VECTOR deserialization error! [7]" << std::endl; return false; } return true; }
bool pod_test(const char* archive_type, const char* io_type) { typename archive_traits::oarchive oa; archive_traits::ocreate(oa, archive_type, io_type); char c = '1', cc; signed char sc = '2', sc2; unsigned char uc = '3', uc2; short s = 4, ss; int i = 5, ii; long l = 6, ll; float f = 3.14f, ff; double d = 3.14, dd; enum { binary_expected_size = sizeof(char) +sizeof(signed char) +sizeof(unsigned char) +sizeof(short) +sizeof(int) +sizeof(long) +sizeof(float) +sizeof(double) ,text_expected_size = 22 ,json_expected_size = 0 }; oa & c & sc & uc & s & i & l & f & d; switch ( archive_traits::oarchive_type::_type ) { case yas::archive_type::binary: if ( oa.size() != archive_traits::oarchive_type::_header_size+binary_expected_size ) { std::cout << "POD serialization error! [1]" << std::endl; return false; } break; case yas::archive_type::text: if ( oa.size() != archive_traits::oarchive_type::_header_size+text_expected_size ) { std::cout << "POD serialization error! [2]" << std::endl; return false; } break; case yas::archive_type::json: std::cout << "unimplemented" << std::endl; return false; break; default: std::cout << "bad archive type!" << std::endl; return false; } typename archive_traits::iarchive ia; archive_traits::icreate(ia, oa, archive_type, io_type); ia & cc & sc2 & uc2 & ss & ii & ll & ff & dd; if ( c != cc || sc != sc2 || sc != sc2 || s != ss || i != ii || l != ll || f != ff || d != dd ) { std::cout << "POD deserialization error! [4]" << std::endl; return false; } return true; }