Eric Fiselier | 83c9dc1 | 2016-04-15 23:27:27 +0000 | [diff] [blame] | 1 | //===----------------------------------------------------------------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is dual licensed under the MIT and the University of Illinois Open |
| 6 | // Source Licenses. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | #ifndef SET_ALLOCATOR_REQUIREMENT_TEST_TEMPLATES_H |
| 10 | #define SET_ALLOCATOR_REQUIREMENT_TEST_TEMPLATES_H |
| 11 | |
| 12 | // <set> |
| 13 | // <unordered_set> |
| 14 | |
| 15 | // class set |
| 16 | // class unordered_set |
| 17 | |
| 18 | // insert(...); |
| 19 | // emplace(...); |
| 20 | // emplace_hint(...); |
| 21 | |
| 22 | |
| 23 | #include <cassert> |
| 24 | |
| 25 | #include "test_macros.h" |
| 26 | #include "count_new.hpp" |
| 27 | #include "container_test_types.h" |
| 28 | #include "assert_checkpoint.h" |
| 29 | |
| 30 | |
| 31 | template <class Container> |
| 32 | void testSetInsert() |
| 33 | { |
| 34 | typedef typename Container::value_type ValueTp; |
| 35 | typedef Container C; |
| 36 | typedef std::pair<typename C::iterator, bool> R; |
| 37 | ConstructController* cc = getConstructController(); |
| 38 | cc->reset(); |
| 39 | { |
| 40 | CHECKPOINT("Testing C::insert(const value_type&)"); |
| 41 | Container c; |
| 42 | const ValueTp v(42); |
| 43 | cc->expect<const ValueTp&>(); |
| 44 | assert(c.insert(v).second); |
| 45 | assert(!cc->unchecked()); |
| 46 | { |
| 47 | DisableAllocationGuard g; |
| 48 | const ValueTp v2(42); |
| 49 | assert(c.insert(v2).second == false); |
| 50 | } |
| 51 | } |
| 52 | { |
| 53 | CHECKPOINT("Testing C::insert(value_type&)"); |
| 54 | Container c; |
| 55 | ValueTp v(42); |
| 56 | cc->expect<const ValueTp&>(); |
| 57 | assert(c.insert(v).second); |
| 58 | assert(!cc->unchecked()); |
| 59 | { |
| 60 | DisableAllocationGuard g; |
| 61 | ValueTp v2(42); |
| 62 | assert(c.insert(v2).second == false); |
| 63 | } |
| 64 | } |
| 65 | { |
| 66 | CHECKPOINT("Testing C::insert(value_type&&)"); |
| 67 | Container c; |
| 68 | ValueTp v(42); |
| 69 | cc->expect<ValueTp&&>(); |
| 70 | assert(c.insert(std::move(v)).second); |
| 71 | assert(!cc->unchecked()); |
| 72 | { |
| 73 | DisableAllocationGuard g; |
| 74 | ValueTp v2(42); |
| 75 | assert(c.insert(std::move(v2)).second == false); |
| 76 | } |
| 77 | } |
| 78 | { |
| 79 | CHECKPOINT("Testing C::insert(const value_type&&)"); |
| 80 | Container c; |
| 81 | const ValueTp v(42); |
| 82 | cc->expect<const ValueTp&>(); |
| 83 | assert(c.insert(std::move(v)).second); |
| 84 | assert(!cc->unchecked()); |
| 85 | { |
| 86 | DisableAllocationGuard g; |
| 87 | const ValueTp v2(42); |
| 88 | assert(c.insert(std::move(v2)).second == false); |
| 89 | } |
| 90 | } |
| 91 | { |
| 92 | CHECKPOINT("Testing C::insert(std::initializer_list<ValueTp>)"); |
| 93 | Container c; |
| 94 | std::initializer_list<ValueTp> il = { ValueTp(1), ValueTp(2) }; |
| 95 | cc->expect<ValueTp const&>(2); |
| 96 | c.insert(il); |
| 97 | assert(!cc->unchecked()); |
| 98 | { |
| 99 | DisableAllocationGuard g; |
| 100 | c.insert(il); |
| 101 | } |
| 102 | } |
| 103 | { |
| 104 | CHECKPOINT("Testing C::insert(Iter, Iter) for *Iter = value_type const&"); |
| 105 | Container c; |
| 106 | const ValueTp ValueList[] = { ValueTp(1), ValueTp(2), ValueTp(3) }; |
| 107 | cc->expect<ValueTp const&>(3); |
| 108 | c.insert(std::begin(ValueList), std::end(ValueList)); |
| 109 | assert(!cc->unchecked()); |
| 110 | { |
| 111 | DisableAllocationGuard g; |
| 112 | c.insert(std::begin(ValueList), std::end(ValueList)); |
| 113 | } |
| 114 | } |
| 115 | { |
| 116 | CHECKPOINT("Testing C::insert(Iter, Iter) for *Iter = value_type&&"); |
| 117 | Container c; |
| 118 | ValueTp ValueList[] = { ValueTp(1), ValueTp(2) , ValueTp(3) }; |
| 119 | cc->expect<ValueTp&&>(3); |
| 120 | c.insert(std::move_iterator<ValueTp*>(std::begin(ValueList)), |
| 121 | std::move_iterator<ValueTp*>(std::end(ValueList))); |
| 122 | assert(!cc->unchecked()); |
| 123 | { |
| 124 | DisableAllocationGuard g; |
| 125 | ValueTp ValueList2[] = { ValueTp(1), ValueTp(2) , ValueTp(3) }; |
| 126 | c.insert(std::move_iterator<ValueTp*>(std::begin(ValueList2)), |
| 127 | std::move_iterator<ValueTp*>(std::end(ValueList2))); |
| 128 | } |
| 129 | } |
| 130 | { |
| 131 | CHECKPOINT("Testing C::insert(Iter, Iter) for *Iter = value_type&"); |
| 132 | Container c; |
| 133 | ValueTp ValueList[] = { ValueTp(1), ValueTp(2) , ValueTp(3) }; |
| 134 | cc->expect<ValueTp const&>(3); |
| 135 | c.insert(std::begin(ValueList), std::end(ValueList)); |
| 136 | assert(!cc->unchecked()); |
| 137 | { |
| 138 | DisableAllocationGuard g; |
| 139 | c.insert(std::begin(ValueList), std::end(ValueList)); |
| 140 | } |
| 141 | } |
| 142 | } |
| 143 | |
| 144 | |
| 145 | template <class Container> |
| 146 | void testSetEmplace() |
| 147 | { |
| 148 | typedef typename Container::value_type ValueTp; |
| 149 | typedef Container C; |
| 150 | typedef std::pair<typename C::iterator, bool> R; |
| 151 | ConstructController* cc = getConstructController(); |
| 152 | cc->reset(); |
| 153 | { |
| 154 | CHECKPOINT("Testing C::emplace(const value_type&)"); |
| 155 | Container c; |
| 156 | const ValueTp v(42); |
| 157 | cc->expect<const ValueTp&>(); |
| 158 | assert(c.emplace(v).second); |
| 159 | assert(!cc->unchecked()); |
| 160 | { |
| 161 | DisableAllocationGuard g; |
| 162 | const ValueTp v2(42); |
| 163 | assert(c.emplace(v2).second == false); |
| 164 | } |
| 165 | } |
| 166 | { |
| 167 | CHECKPOINT("Testing C::emplace(value_type&)"); |
| 168 | Container c; |
| 169 | ValueTp v(42); |
| 170 | cc->expect<ValueTp&>(); |
| 171 | assert(c.emplace(v).second); |
| 172 | assert(!cc->unchecked()); |
| 173 | { |
| 174 | DisableAllocationGuard g; |
| 175 | ValueTp v2(42); |
| 176 | assert(c.emplace(v2).second == false); |
| 177 | } |
| 178 | } |
| 179 | { |
| 180 | CHECKPOINT("Testing C::emplace(value_type&&)"); |
| 181 | Container c; |
| 182 | ValueTp v(42); |
| 183 | cc->expect<ValueTp&&>(); |
| 184 | assert(c.emplace(std::move(v)).second); |
| 185 | assert(!cc->unchecked()); |
| 186 | { |
| 187 | DisableAllocationGuard g; |
| 188 | ValueTp v2(42); |
| 189 | assert(c.emplace(std::move(v2)).second == false); |
| 190 | } |
| 191 | } |
| 192 | { |
| 193 | CHECKPOINT("Testing C::emplace(const value_type&&)"); |
| 194 | Container c; |
| 195 | const ValueTp v(42); |
| 196 | cc->expect<const ValueTp&&>(); |
| 197 | assert(c.emplace(std::move(v)).second); |
| 198 | assert(!cc->unchecked()); |
| 199 | { |
| 200 | DisableAllocationGuard g; |
| 201 | const ValueTp v2(42); |
| 202 | assert(c.emplace(std::move(v2)).second == false); |
| 203 | } |
| 204 | } |
| 205 | } |
| 206 | |
| 207 | |
| 208 | template <class Container> |
| 209 | void testSetEmplaceHint() |
| 210 | { |
| 211 | typedef typename Container::value_type ValueTp; |
| 212 | |
| 213 | typedef Container C; |
| 214 | typedef typename C::iterator It; |
| 215 | ConstructController* cc = getConstructController(); |
| 216 | cc->reset(); |
| 217 | { |
| 218 | CHECKPOINT("Testing C::emplace_hint(p, const value_type&)"); |
| 219 | Container c; |
| 220 | const ValueTp v(42); |
| 221 | cc->expect<const ValueTp&>(); |
| 222 | It ret = c.emplace_hint(c.end(), v); |
| 223 | assert(ret != c.end()); |
| 224 | assert(c.size() == 1); |
| 225 | assert(!cc->unchecked()); |
| 226 | { |
| 227 | DisableAllocationGuard g; |
| 228 | const ValueTp v2(42); |
| 229 | It ret2 = c.emplace_hint(c.begin(), v2); |
| 230 | assert(&(*ret2) == &(*ret)); |
| 231 | assert(c.size() == 1); |
| 232 | } |
| 233 | } |
| 234 | { |
| 235 | CHECKPOINT("Testing C::emplace_hint(p, value_type&)"); |
| 236 | Container c; |
| 237 | ValueTp v(42); |
| 238 | cc->expect<ValueTp&>(); |
| 239 | It ret = c.emplace_hint(c.end(), v); |
| 240 | assert(ret != c.end()); |
| 241 | assert(c.size() == 1); |
| 242 | assert(!cc->unchecked()); |
| 243 | { |
| 244 | DisableAllocationGuard g; |
| 245 | ValueTp v2(42); |
| 246 | It ret2 = c.emplace_hint(c.begin(), v2); |
| 247 | assert(&(*ret2) == &(*ret)); |
| 248 | assert(c.size() == 1); |
| 249 | } |
| 250 | } |
| 251 | { |
| 252 | CHECKPOINT("Testing C::emplace_hint(p, value_type&&)"); |
| 253 | Container c; |
| 254 | ValueTp v(42); |
| 255 | cc->expect<ValueTp&&>(); |
| 256 | It ret = c.emplace_hint(c.end(), std::move(v)); |
| 257 | assert(ret != c.end()); |
| 258 | assert(c.size() == 1); |
| 259 | assert(!cc->unchecked()); |
| 260 | { |
| 261 | DisableAllocationGuard g; |
| 262 | ValueTp v2(42); |
| 263 | It ret2 = c.emplace_hint(c.begin(), std::move(v2)); |
| 264 | assert(&(*ret2) == &(*ret)); |
| 265 | assert(c.size() == 1); |
| 266 | } |
| 267 | } |
| 268 | { |
| 269 | CHECKPOINT("Testing C::emplace_hint(p, const value_type&&)"); |
| 270 | Container c; |
| 271 | const ValueTp v(42); |
| 272 | cc->expect<const ValueTp&&>(); |
| 273 | It ret = c.emplace_hint(c.end(), std::move(v)); |
| 274 | assert(ret != c.end()); |
| 275 | assert(c.size() == 1); |
| 276 | assert(!cc->unchecked()); |
| 277 | { |
| 278 | DisableAllocationGuard g; |
| 279 | const ValueTp v2(42); |
| 280 | It ret2 = c.emplace_hint(c.begin(), std::move(v2)); |
| 281 | assert(&(*ret2) == &(*ret)); |
| 282 | assert(c.size() == 1); |
| 283 | } |
| 284 | } |
| 285 | } |
| 286 | |
| 287 | |
| 288 | template <class Container> |
| 289 | void testMultisetInsert() |
| 290 | { |
| 291 | typedef typename Container::value_type ValueTp; |
| 292 | typedef Container C; |
| 293 | ConstructController* cc = getConstructController(); |
| 294 | cc->reset(); |
| 295 | { |
| 296 | CHECKPOINT("Testing C::insert(const value_type&)"); |
| 297 | Container c; |
| 298 | const ValueTp v(42); |
| 299 | cc->expect<const ValueTp&>(); |
| 300 | c.insert(v); |
| 301 | assert(!cc->unchecked()); |
| 302 | } |
| 303 | { |
| 304 | CHECKPOINT("Testing C::insert(value_type&)"); |
| 305 | Container c; |
| 306 | ValueTp v(42); |
| 307 | cc->expect<const ValueTp&>(); |
| 308 | c.insert(v); |
| 309 | assert(!cc->unchecked()); |
| 310 | } |
| 311 | { |
| 312 | CHECKPOINT("Testing C::insert(value_type&&)"); |
| 313 | Container c; |
| 314 | ValueTp v(42); |
| 315 | cc->expect<ValueTp&&>(); |
| 316 | c.insert(std::move(v)); |
| 317 | assert(!cc->unchecked()); |
| 318 | } |
| 319 | { |
| 320 | CHECKPOINT("Testing C::insert(std::initializer_list<ValueTp>)"); |
| 321 | Container c; |
| 322 | std::initializer_list<ValueTp> il = { ValueTp(1), ValueTp(2) }; |
| 323 | cc->expect<ValueTp const&>(2); |
| 324 | c.insert(il); |
| 325 | assert(!cc->unchecked()); |
| 326 | } |
| 327 | { |
| 328 | CHECKPOINT("Testing C::insert(Iter, Iter) for *Iter = value_type const&"); |
| 329 | Container c; |
| 330 | const ValueTp ValueList[] = { ValueTp(1), ValueTp(2), ValueTp(3) }; |
| 331 | cc->expect<ValueTp const&>(3); |
| 332 | c.insert(std::begin(ValueList), std::end(ValueList)); |
| 333 | assert(!cc->unchecked()); |
| 334 | } |
| 335 | { |
| 336 | CHECKPOINT("Testing C::insert(Iter, Iter) for *Iter = value_type&&"); |
| 337 | Container c; |
| 338 | ValueTp ValueList[] = { ValueTp(1), ValueTp(2) , ValueTp(3) }; |
| 339 | cc->expect<ValueTp&&>(3); |
| 340 | c.insert(std::move_iterator<ValueTp*>(std::begin(ValueList)), |
| 341 | std::move_iterator<ValueTp*>(std::end(ValueList))); |
| 342 | assert(!cc->unchecked()); |
| 343 | } |
| 344 | { |
| 345 | CHECKPOINT("Testing C::insert(Iter, Iter) for *Iter = value_type&"); |
| 346 | Container c; |
| 347 | ValueTp ValueList[] = { ValueTp(1), ValueTp(2) , ValueTp(3) }; |
| 348 | cc->expect<ValueTp&>(3); |
| 349 | c.insert(std::begin(ValueList), std::end(ValueList)); |
| 350 | assert(!cc->unchecked()); |
| 351 | } |
| 352 | } |
| 353 | |
Eric Fiselier | dc414cd | 2016-04-16 00:23:12 +0000 | [diff] [blame] | 354 | #endif |