///////////////////////////////////////////////////////////////////////////// // Copyright (c) Electronic Arts Inc. All rights reserved. ///////////////////////////////////////////////////////////////////////////// #include "TestMap.h" #include "EASTLTest.h" #include #include #include #include #include #include #include #include EA_DISABLE_ALL_VC_WARNINGS() #ifndef EA_COMPILER_NO_STANDARD_CPP_LIBRARY #include #endif EA_RESTORE_ALL_VC_WARNINGS() using namespace eastl; // Template instantations. // These tell the compiler to compile all the functions for the given class. template class eastl::vector_map; template class eastl::vector_multimap; template class eastl::vector_map; template class eastl::vector_multimap; /////////////////////////////////////////////////////////////////////////////// // typedefs // typedef eastl::vector_map VM1; typedef eastl::vector_map, EASTLAllocatorType, eastl::deque > > VM2; typedef eastl::vector_map VM4; typedef eastl::vector_map, EASTLAllocatorType, eastl::deque > > VM5; typedef eastl::vector_multimap VMM1; typedef eastl::vector_multimap, EASTLAllocatorType, eastl::deque > > VMM2; typedef eastl::vector_multimap VMM4; typedef eastl::vector_multimap, EASTLAllocatorType, eastl::deque > > VMM5; #ifndef EA_COMPILER_NO_STANDARD_CPP_LIBRARY typedef std::map VM3; typedef std::map VM6; typedef std::multimap VMM3; typedef std::multimap VMM6; #endif /////////////////////////////////////////////////////////////////////////////// int TestVectorMap() { int nErrorCount = 0; #ifndef EA_COMPILER_NO_STANDARD_CPP_LIBRARY { // Test construction nErrorCount += TestMapConstruction(); nErrorCount += TestMapConstruction(); nErrorCount += TestMapConstruction(); nErrorCount += TestMapConstruction(); nErrorCount += TestMapConstruction(); nErrorCount += TestMapConstruction(); nErrorCount += TestMapConstruction(); nErrorCount += TestMapConstruction(); } { // Test mutating functionality. nErrorCount += TestMapMutation(); nErrorCount += TestMapMutation(); nErrorCount += TestMapMutation(); nErrorCount += TestMapMutation(); nErrorCount += TestMapMutation(); nErrorCount += TestMapMutation(); nErrorCount += TestMapMutation(); nErrorCount += TestMapMutation(); } #endif // EA_COMPILER_NO_STANDARD_CPP_LIBRARY { // Test search functionality. nErrorCount += TestMapSearch(); nErrorCount += TestMapSearch(); nErrorCount += TestMapSearch(); nErrorCount += TestMapSearch(); nErrorCount += TestMapSearch(); nErrorCount += TestMapSearch(); nErrorCount += TestMapSearch(); nErrorCount += TestMapSearch(); } { // C++11 emplace and related functionality nErrorCount += TestMapCpp11 >(); nErrorCount += TestMapCpp11, EASTLAllocatorType, eastl::deque > > >(); nErrorCount += TestMultimapCpp11 >(); nErrorCount += TestMultimapCpp11, EASTLAllocatorType, eastl::deque > > >(); } { // insert at the upper bound of a range VMM1 vmm = {{0, 0}}; VERIFY(vmm.emplace(0, 0) != vmm.begin()); } { // Misc tests // const key_compare& key_comp() const; // key_compare& key_comp(); VM2 vm; const VM2 vmc; const VM2::key_compare& kc = vmc.key_comp(); vm.key_comp() = kc; // ensure count can be called from a const object vmc.count(0); } { const VMM1 vmm; // ensure count can be called from a const object vmm.count(0); } { // Misc testing typedef eastl::fixed_vector, 8> FV; typedef eastl::vector_map, FV::allocator_type, FV> FixedVectorMap; FixedVectorMap fvm; for(int i = FV::kMaxSize - 1; i >= 0; i--) fvm.insert(eastl::pair(i, (float)i)); FixedVectorMap::iterator it = fvm.find(3); EATEST_VERIFY(it != fvm.end()); } { // Misc testing typedef eastl::fixed_string KeyStringType; typedef eastl::fixed_string ValueStringType; typedef eastl::pair StringMapValueType; typedef eastl::vector_map StringMapType; StringMapType stringMap; stringMap.reserve(20); EATEST_VERIFY(stringMap.capacity() == 20); StringMapValueType& v1 = stringMap["abc"]; EATEST_VERIFY(strlen(v1.first.c_str()) == 0); v1.first.clear(); EATEST_VERIFY(strlen(v1.first.c_str()) == 0); StringMapValueType& v2 = stringMap["def"]; EATEST_VERIFY(strlen(v2.first.c_str()) == 0); v2.first = "def"; EATEST_VERIFY(strlen(v2.first.c_str()) == 3); } { // Regression for problem observed in EAWebKit typedef eastl::vector_map TestVectorMap; TestVectorMap tvm; tvm["Parameters"] = NULL; tvm["ThemeParameters"] = NULL; tvm["CookieInfo"] = NULL; tvm["DiskCacheInfo"] = NULL; tvm["RamCacheInfo"] = NULL; tvm["SSLCert"] = NULL; tvm["AllowedDomain"] = NULL; } { // find_as predicate { // vector_map eastl::vector_map vss = {{"abc", 11}, {"def", 22}, {"ghi", 33}, {"jklmnop", 44}, {"qrstu", 55}, {"vw", 66}, {"x", 77}, {"yz", 88}}; VERIFY(vss.find_as("GHI", TestStrCmpI_2()) != vss.end()); } { // const vector_map const eastl::vector_map vss = {{"abc", 11}, {"def", 22}, {"ghi", 33}, {"jklmnop", 44}, {"qrstu", 55}, {"vw", 66}, {"x", 77}, {"yz", 88}}; VERIFY(vss.find_as("GHI", TestStrCmpI_2()) != vss.end()); } // vector_multimap { eastl::vector_multimap vss = {{"abc", 11}, {"def", 22}, {"ghi", 33}, {"jklmnop", 44}, {"qrstu", 55}, {"vw", 66}, {"x", 77}, {"yz", 88}}; VERIFY(vss.find_as("GHI", TestStrCmpI_2()) != vss.end()); } // const vector_multimap { const eastl::vector_multimap vss = {{"abc", 11}, {"def", 22}, {"ghi", 33}, {"jklmnop", 44}, {"qrstu", 55}, {"vw", 66}, {"x", 77}, {"yz", 88}}; VERIFY(vss.find_as("GHI", TestStrCmpI_2()) != vss.end()); } } return nErrorCount; }