45 {
46 T cont;
47 const T& ccont(cont);
48 CheckEmptyContainerAllocatorE(cont, 1, 0);
49
50 ASSERT(ccont.empty(),
"Concurrent container is not empty after construction");
51
52
53 ASSERT(ccont.size() == 0,
"Concurrent container is not empty after construction");
54
55
56 ASSERT(ccont.max_size() > 0,
"Concurrent container max size is invalid");
57
58
59
60 ASSERT(cont.begin() == cont.end(),
"Concurrent container iterators are invalid after construction");
61 ASSERT(ccont.begin() == ccont.end(),
"Concurrent container iterators are invalid after construction");
62 ASSERT(cont.cbegin() == cont.cend(),
"Concurrent container iterators are invalid after construction");
63
64
65 std::pair<typename T::iterator, bool> ins = cont.insert(Value<T>::make(1));
66 ASSERT(ins.second ==
true && Value<T>::get(*(ins.first)) == 1,
"Element 1 has not been inserted properly");
67
68#if __TBB_CPP11_RVALUE_REF_PRESENT
69 test_rvalue_insert<T, do_check_element_state>(1, 2);
70#if __TBB_CPP11_VARIADIC_TEMPLATES_PRESENT
71 test_emplace_insert<T, do_check_element_state>(1, 2);
72#endif
73#endif
74
75
76 ASSERT(!ccont.empty(),
"Concurrent container is empty after adding an element");
77
78
79 ASSERT(ccont.size() == 1,
"Concurrent container size is incorrect");
80
81 std::pair<typename T::iterator, bool> ins2 = cont.insert(Value<T>::make(1));
82
83 if (T::allow_multimapping)
84 {
85
86 ASSERT(ins2.second ==
true && Value<T>::get(*(ins2.first)) == 1,
"Element 1 has not been inserted properly");
87
88
89 ASSERT(ccont.size() == 2,
"Concurrent container size is incorrect");
90
91
92 ASSERT(ccont.count(1) == 2,
"Concurrent container count(1) is incorrect");
93
94 std::pair<typename T::iterator, typename T::iterator> range = cont.equal_range(1);
95 typename T::iterator it = range.first;
96 ASSERT(it != cont.end() && Value<T>::get(*it) == 1,
"Element 1 has not been found properly");
97 unsigned int count = 0;
98 for (; it != range.second; it++)
99 {
100 count++;
101 ASSERT(Value<T>::get(*it) == 1,
"Element 1 has not been found properly");
102 }
103
104 ASSERT(count == 2,
"Range doesn't have the right number of elements");
105 }
106 else
107 {
108
109 ASSERT(ins2.second ==
false && ins2.first == ins.first,
"Element 1 should not be re-inserted");
110
111
112 ASSERT(ccont.size() == 1,
"Concurrent container size is incorrect");
113
114
115 ASSERT(ccont.count(1) == 1,
"Concurrent container count(1) is incorrect");
116
117
118
119 std::pair<typename T::iterator, typename T::iterator> range = cont.equal_range(1);
120 typename T::iterator it = range.first;
121 ASSERT(it != cont.end() && Value<T>::get(*it) == 1,
"Element 1 has not been found properly");
122 ASSERT(++it == range.second,
"Range doesn't have the right number of elements");
123 }
124
125
126
127 typename T::iterator it = cont.find(1);
128 ASSERT(it != cont.end() && Value<T>::get(*(it)) == 1,
"Element 1 has not been found properly");
129 ASSERT(ccont.find(1) == it,
"Element 1 has not been found properly");
130
131
132#if !__TBB_UNORDERED_TEST
133
134 ASSERT(cont.contains(1),
"contains() cannot detect existing element");
135 ASSERT(!cont.contains(0),
"contains() detect not existing element");
136#endif
137
138
139 typename T::iterator it2 = cont.insert(ins.first, Value<T>::make(2));
140 ASSERT(Value<T>::get(*it2) == 2,
"Element 2 has not been inserted properly");
141
142
143 T newcont = ccont;
144 ASSERT(T::allow_multimapping ? (newcont.size() == 3) : (newcont.size() == 2),
"Copy construction has not copied the elements properly");
145
146
147
148 typename T::size_type size = cont.unsafe_erase(1);
149 ASSERT(T::allow_multimapping ? (size == 2) : (size == 1),
"Erase has not removed the right number of elements");
150
151
152 typename T::iterator it4 = cont.unsafe_erase(cont.find(2));
153 ASSERT(it4 == cont.end() && cont.size() == 0,
"Erase has not removed the last element properly");
154
155
156 cont.insert(Value<T>::make(3));
157 typename T::iterator it5 = cont.unsafe_erase(cont.cbegin());
158 ASSERT(it5 == cont.end() && cont.size() == 0,
"Erase has not removed the last element properly");
159
160
161 cont.insert(newcont.begin(), newcont.end());
162 ASSERT(T::allow_multimapping ? (cont.size() == 3) : (cont.size() == 2),
"Range insert has not copied the elements properly");
163
164
165
166 std::pair<typename T::iterator, typename T::iterator> range2 = newcont.equal_range(1);
167 newcont.unsafe_erase(range2.first, range2.second);
168 ASSERT(newcont.size() == 1,
"Range erase has not erased the elements properly");
169
170
171 newcont.clear();
172 ASSERT(newcont.begin() == newcont.end() && newcont.size() == 0,
"Clear has not cleared the container");
173
174#if __TBB_INITIALIZER_LISTS_PRESENT
175#if __TBB_CPP11_INIT_LIST_TEMP_OBJS_LIFETIME_BROKEN
176 REPORT(
"Known issue: the test for insert with initializer_list is skipped.\n");
177#else
178
179 newcont.insert({ Value<T>::make(1), Value<T>::make(2), Value<T>::make(1) });
180 if (T::allow_multimapping) {
181 ASSERT(newcont.size() == 3,
"Concurrent container size is incorrect");
182 ASSERT(newcont.count(1) == 2,
"Concurrent container count(1) is incorrect");
183 ASSERT(newcont.count(2) == 1,
"Concurrent container count(2) is incorrect");
184 std::pair<typename T::iterator, typename T::iterator> range = cont.equal_range(1);
185 it = range.first;
186 ASSERT(it != newcont.end() && Value<T>::get(*it) == 1,
"Element 1 has not been found properly");
187 unsigned int count = 0;
188 for (; it != range.second; it++) {
189 count++;
190 ASSERT(Value<T>::get(*it) == 1,
"Element 1 has not been found properly");
191 }
192 ASSERT(count == 2,
"Range doesn't have the right number of elements");
193 range = newcont.equal_range(2); it = range.first;
194 ASSERT(it != newcont.end() && Value<T>::get(*it) == 2,
"Element 2 has not been found properly");
195 count = 0;
196 for (; it != range.second; it++) {
197 count++;
198 ASSERT(Value<T>::get(*it) == 2,
"Element 2 has not been found properly");
199 }
200 ASSERT(count == 1,
"Range doesn't have the right number of elements");
201 }
202 else {
203 ASSERT(newcont.size() == 2,
"Concurrent container size is incorrect");
204 ASSERT(newcont.count(1) == 1,
"Concurrent container count(1) is incorrect");
205 ASSERT(newcont.count(2) == 1,
"Concurrent container count(2) is incorrect");
206 std::pair<typename T::iterator, typename T::iterator> range = newcont.equal_range(1);
207 it = range.first;
208 ASSERT(it != newcont.end() && Value<T>::get(*it) == 1,
"Element 1 has not been found properly");
209 ASSERT(++it == range.second,
"Range doesn't have the right number of elements");
210 range = newcont.equal_range(2); it = range.first;
211 ASSERT(it != newcont.end() && Value<T>::get(*it) == 2,
"Element 2 has not been found properly");
212 ASSERT(++it == range.second,
"Range doesn't have the right number of elements");
213 }
214#endif
215#endif
216
217
218 newcont = ccont;
219 ASSERT(T::allow_multimapping ? (newcont.size() == 3) : (newcont.size() == 2),
"Assignment operator has not copied the elements properly");
220
221 REMARK(
"passed -- basic %s tests\n", str);
222
223#if defined (VERBOSE)
224 REMARK(
"container dump debug:\n");
225 cont._Dump();
226 REMARK(
"container dump release:\n");
227 cont.dump();
229#endif
230
231 cont.clear();
232 CheckEmptyContainerAllocatorA(cont, 1, 0);
233 for (int i = 0; i < 256; i++)
234 {
235 std::pair<typename T::iterator, bool> ins3 = cont.insert(Value<T>::make(i));
236 ASSERT(ins3.second ==
true && Value<T>::get(*(ins3.first)) == i,
"Element 1 has not been inserted properly");
237 }
238 ASSERT(cont.size() == 256,
"Wrong number of elements have been inserted");
239 ASSERT((256 == CheckRecursiveRange<T, typename T::iterator>(cont.range()).first), NULL);
240 ASSERT((256 == CheckRecursiveRange<T, typename T::const_iterator>(ccont.range()).first), NULL);
241
242
243 cont.swap(newcont);
244 ASSERT(newcont.size() == 256,
"Wrong number of elements after swap");
245 ASSERT(newcont.count(200) == 1,
"Element with key 200 is not present after swap");
246 ASSERT(newcont.count(16) == 1,
"Element with key 16 is not present after swap");
247 ASSERT(newcont.count(99) == 1,
"Element with key 99 is not present after swap");
248 ASSERT(T::allow_multimapping ? (cont.size() == 3) : (cont.size() == 2),
"Assignment operator has not copied the elements properly");
249
250
251 SpecialTests<T>::Test(str);
252 }
#define ASSERT(p, message)
#define REPORT
printf style reporting macro
#define REMARK
printf style remark macro