1 /////////////////////////////////////////////////////////////////////////////
2 // Copyright (c) Electronic Arts Inc. All rights reserved.
3 /////////////////////////////////////////////////////////////////////////////
4
5
6
7 #include "TestSet.h"
8 #include "EASTLTest.h"
9 #include <EASTL/vector_set.h>
10 #include <EASTL/vector_multiset.h>
11 #include <EASTL/vector.h>
12 #include <EASTL/deque.h>
13 #include <EABase/eabase.h>
14
15 EA_DISABLE_ALL_VC_WARNINGS()
16 #ifndef EA_COMPILER_NO_STANDARD_CPP_LIBRARY
17 #include <set>
18 #endif
19 EA_RESTORE_ALL_VC_WARNINGS()
20
21 using namespace eastl;
22
23
24 // Template instantations.
25 // These tell the compiler to compile all the functions for the given class.
26 template class eastl::vector_set<int>;
27 template class eastl::vector_multiset<float>;
28 template class eastl::vector_set<TestObject>;
29 template class eastl::vector_multiset<TestObject>;
30
31
32 ///////////////////////////////////////////////////////////////////////////////
33 // typedefs
34 //
35 typedef eastl::vector_set<int> VS1;
36 typedef eastl::vector_set<int, eastl::less<int>, EASTLAllocatorType, eastl::deque<int> > VS2;
37 typedef eastl::vector_set<TestObject> VS4;
38 typedef eastl::vector_set<TestObject, eastl::less<TestObject>, EASTLAllocatorType, eastl::deque<TestObject> > VS5;
39 typedef eastl::vector_multiset<int> VMS1;
40 typedef eastl::vector_multiset<int, eastl::less<int>, EASTLAllocatorType, eastl::deque<int> > VMS2;
41 typedef eastl::vector_multiset<TestObject> VMS4;
42 typedef eastl::vector_multiset<TestObject, eastl::less<TestObject>, EASTLAllocatorType, eastl::deque<TestObject> > VMS5;
43
44 #ifndef EA_COMPILER_NO_STANDARD_CPP_LIBRARY
45 typedef std::set<int> VS3;
46 typedef std::set<TestObject> VS6;
47 typedef std::multiset<int> VMS3;
48 typedef std::multiset<TestObject> VMS6;
49 #endif
50 ///////////////////////////////////////////////////////////////////////////////
51
52
TestVectorSet()53 int TestVectorSet()
54 {
55 int nErrorCount = 0;
56
57 #ifndef EA_COMPILER_NO_STANDARD_CPP_LIBRARY
58 { // Test construction
59 nErrorCount += TestSetConstruction<VS1, VS3, false>();
60 nErrorCount += TestSetConstruction<VS2, VS3, false>();
61 nErrorCount += TestSetConstruction<VS4, VS6, false>();
62 nErrorCount += TestSetConstruction<VS5, VS6, false>();
63
64 nErrorCount += TestSetConstruction<VMS1, VMS3, true>();
65 nErrorCount += TestSetConstruction<VMS2, VMS3, true>();
66 nErrorCount += TestSetConstruction<VMS4, VMS6, true>();
67 nErrorCount += TestSetConstruction<VMS5, VMS6, true>();
68 }
69
70
71 { // Test mutating functionality.
72 nErrorCount += TestSetMutation<VS1, VS3, false>();
73 nErrorCount += TestSetMutation<VS2, VS3, false>();
74 nErrorCount += TestSetMutation<VS4, VS6, false>();
75 nErrorCount += TestSetMutation<VS5, VS6, false>();
76
77 nErrorCount += TestSetMutation<VMS1, VMS3, true>();
78 nErrorCount += TestSetMutation<VMS2, VMS3, true>();
79 nErrorCount += TestSetMutation<VMS4, VMS6, true>();
80 nErrorCount += TestSetMutation<VMS5, VMS6, true>();
81 }
82 #endif // EA_COMPILER_NO_STANDARD_CPP_LIBRARY
83
84
85 { // Test search functionality.
86 nErrorCount += TestSetSearch<VS1, false>();
87 nErrorCount += TestSetSearch<VS2, false>();
88 nErrorCount += TestSetSearch<VS4, false>();
89 nErrorCount += TestSetSearch<VS5, false>();
90
91 nErrorCount += TestSetSearch<VMS1, true>();
92 nErrorCount += TestSetSearch<VMS2, true>();
93 nErrorCount += TestSetSearch<VMS4, true>();
94 nErrorCount += TestSetSearch<VMS5, true>();
95 }
96
97
98 {
99 // C++11 emplace and related functionality
100 nErrorCount += TestSetCpp11<VS4>();
101 nErrorCount += TestSetCpp11<VS5>();
102
103 nErrorCount += TestMultisetCpp11<VMS4>();
104 nErrorCount += TestMultisetCpp11<VMS5>();
105 }
106
107
108 { // Misc tests
109 {
110 // const key_compare& key_comp() const;
111 // key_compare& key_comp();
112 VS2 vs;
113 const VS2 vsc;
114
115 // ensure count can be called from a const object
116 const VS2::key_compare& kc = vsc.key_comp();
117 vs.key_comp() = kc;
118 vsc.count(0);
119 }
120
121 {
122 // ensure count can be called from a const object
123 const VMS1 vms;
124 vms.count(0);
125 }
126 }
127
128 { // find_as predicate
129 { // vector_set
130 eastl::vector_set<string> vss = {"abc", "def", "ghi", "jklmnop", "qrstu", "vw", "x", "yz"};
131 VERIFY(vss.find_as("GHI", TestStrCmpI_2()) != vss.end());
132 }
133
134 { // const vector_set
135 const eastl::vector_set<string> vss = {"abc", "def", "ghi", "jklmnop", "qrstu", "vw", "x", "yz"};
136 VERIFY(vss.find_as("GHI", TestStrCmpI_2()) != vss.end());
137 }
138
139 { // vector_multiset
140 eastl::vector_multiset<string> vss = {"abc", "def", "ghi", "jklmnop", "qrstu", "vw", "x", "yz"};
141 VERIFY(vss.find_as("GHI", TestStrCmpI_2()) != vss.end());
142 }
143
144 { // const vector_multiset
145 const eastl::vector_multiset<string> vss = {"abc", "def", "ghi", "jklmnop", "qrstu", "vw", "x", "yz"};
146 VERIFY(vss.find_as("GHI", TestStrCmpI_2()) != vss.end());
147 }
148 }
149
150 return nErrorCount;
151 }
152
153
154
155
156
157
158
159
160
161
162
163
164