///////////////////////////////////////////////////////////////////////////// // Copyright (c) Electronic Arts Inc. All rights reserved. ///////////////////////////////////////////////////////////////////////////// #include "EASTLTest.h" #include "TestMap.h" #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::fixed_map ; template class eastl::fixed_multimap; template class eastl::fixed_map ; template class eastl::fixed_multimap; template class eastl::fixed_map , MallocAllocator>; template class eastl::fixed_multimap, MallocAllocator>; template class eastl::fixed_map , MallocAllocator>; template class eastl::fixed_multimap, MallocAllocator>; /////////////////////////////////////////////////////////////////////////////// // typedefs // const eastl_size_t kContainerSize = 1000; typedef eastl::fixed_map VM1; typedef eastl::fixed_map VM4; typedef eastl::fixed_multimap VMM1; typedef eastl::fixed_multimap VMM4; #ifndef EA_COMPILER_NO_STANDARD_CPP_LIBRARY typedef std::map VM3; typedef std::map VM6; typedef std::multimap VMM3; typedef std::multimap VMM6; #endif /////////////////////////////////////////////////////////////////////////////// EA_DISABLE_VC_WARNING(6262) int TestFixedMap() { int nErrorCount = 0; #ifndef EA_COMPILER_NO_STANDARD_CPP_LIBRARY { // Test construction nErrorCount += TestMapConstruction(); nErrorCount += TestMapConstruction(); nErrorCount += TestMapConstruction(); nErrorCount += TestMapConstruction(); } { // Test mutating functionality. nErrorCount += TestMapMutation(); nErrorCount += TestMapMutation(); nErrorCount += TestMapMutation(); nErrorCount += TestMapMutation(); } #endif // EA_COMPILER_NO_STANDARD_CPP_LIBRARY { // Test searching functionality. nErrorCount += TestMapSearch(); nErrorCount += TestMapSearch(); nErrorCount += TestMapSearch(); nErrorCount += TestMapSearch(); } { // C++11 emplace and related functionality nErrorCount += TestMapCpp11 >(); nErrorCount += TestMultimapCpp11 >(); nErrorCount += TestMapCpp11NonCopyable>(); } { // C++17 try_emplace and related functionality nErrorCount += TestMapCpp17>(); } { // Test functionality specific to fixed size containers. VM1 vm1; VMM1 vmm1; VERIFY(vm1.max_size() == kContainerSize); VERIFY(vmm1.max_size() == kContainerSize); } { // Regression of bug report by Eric Turmel, May 20, 2008 typedef eastl::fixed_map FixedMap; VERIFY(FixedMap::kMaxSize == 37); FixedMap fixedMap; FixedMap::fixed_allocator_type& a = fixedMap.get_allocator(); for(int i = 0; i < FixedMap::kMaxSize; i++) { VERIFY(a.can_allocate()); fixedMap.insert(FixedMap::value_type(i, TestObject(i))); #if EASTL_FIXED_SIZE_TRACKING_ENABLED // Disabled because mPool is (mistakenly) inaccessible. // VERIFY((a.mPool.mnCurrentSize == a.mPool.mnPeakSize) && (a.mPool.mnCurrentSize == i)); #endif } VERIFY(!a.can_allocate()); } { // Test fixed set with overflow and alignment requirements. typedef fixed_map FixedMapWithAlignment; typedef fixed_multimap FixedMultiMapWithAlignment; FixedMapWithAlignment fm; FixedMultiMapWithAlignment fmm; Align64 a; a.mX = 1; Align64 b; b.mX = 2; Align64 c; c.mX = 3; Align64 d; d.mX = 4; Align64 e; e.mX = 5; fm.insert(a); fm.insert(b); fm.insert(c); fm.insert(d); fm.insert(e); for (FixedMapWithAlignment::const_iterator it = fm.begin(); it != fm.end(); ++it) { const Align64* ptr = &((*it).first); EATEST_VERIFY((uint64_t)ptr % EASTL_ALIGN_OF(Align64) == 0); } fmm.insert(a); fmm.insert(b); fmm.insert(c); fmm.insert(d); fmm.insert(e); for (FixedMultiMapWithAlignment::const_iterator it = fmm.begin(); it != fmm.end(); ++it) { const Align64* ptr = &((*it).first); EATEST_VERIFY((uint64_t)ptr % EASTL_ALIGN_OF(Align64) == 0); } } return nErrorCount; } EA_RESTORE_VC_WARNING()