123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388 |
- //===----------------------------------------------------------------------===//
- //
- // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
- // See https://llvm.org/LICENSE.txt for license information.
- // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
- //
- //===----------------------------------------------------------------------===//
- #ifndef SET_ALLOCATOR_REQUIREMENT_TEST_TEMPLATES_H
- #define SET_ALLOCATOR_REQUIREMENT_TEST_TEMPLATES_H
- // <set>
- // <unordered_set>
- // class set
- // class unordered_set
- // insert(...);
- // emplace(...);
- // emplace_hint(...);
- #include <cassert>
- #include "test_macros.h"
- #include "count_new.h"
- #include "container_test_types.h"
- #include "assert_checkpoint.h"
- template <class Container>
- void testSetInsert()
- {
- typedef typename Container::value_type ValueTp;
- ConstructController* cc = getConstructController();
- cc->reset();
- {
- CHECKPOINT("Testing C::insert(const value_type&)");
- Container c;
- const ValueTp v(42);
- cc->expect<const ValueTp&>();
- assert(c.insert(v).second);
- assert(!cc->unchecked());
- {
- DisableAllocationGuard g;
- const ValueTp v2(42);
- assert(c.insert(v2).second == false);
- }
- }
- {
- CHECKPOINT("Testing C::insert(value_type&)");
- Container c;
- ValueTp v(42);
- cc->expect<const ValueTp&>();
- assert(c.insert(v).second);
- assert(!cc->unchecked());
- {
- DisableAllocationGuard g;
- ValueTp v2(42);
- assert(c.insert(v2).second == false);
- }
- }
- {
- CHECKPOINT("Testing C::insert(value_type&&)");
- Container c;
- ValueTp v(42);
- cc->expect<ValueTp&&>();
- assert(c.insert(std::move(v)).second);
- assert(!cc->unchecked());
- {
- DisableAllocationGuard g;
- ValueTp v2(42);
- assert(c.insert(std::move(v2)).second == false);
- }
- }
- {
- CHECKPOINT("Testing C::insert(const value_type&&)");
- Container c;
- const ValueTp v(42);
- cc->expect<const ValueTp&>();
- assert(c.insert(std::move(v)).second);
- assert(!cc->unchecked());
- {
- DisableAllocationGuard g;
- const ValueTp v2(42);
- assert(c.insert(std::move(v2)).second == false);
- }
- }
- {
- CHECKPOINT("Testing C::insert(std::initializer_list<ValueTp>)");
- Container c;
- std::initializer_list<ValueTp> il = { ValueTp(1), ValueTp(2) };
- cc->expect<ValueTp const&>(2);
- c.insert(il);
- assert(!cc->unchecked());
- {
- DisableAllocationGuard g;
- c.insert(il);
- }
- }
- {
- CHECKPOINT("Testing C::insert(Iter, Iter) for *Iter = value_type const&");
- Container c;
- const ValueTp ValueList[] = { ValueTp(1), ValueTp(2), ValueTp(3) };
- cc->expect<ValueTp const&>(3);
- c.insert(std::begin(ValueList), std::end(ValueList));
- assert(!cc->unchecked());
- {
- DisableAllocationGuard g;
- c.insert(std::begin(ValueList), std::end(ValueList));
- }
- }
- {
- CHECKPOINT("Testing C::insert(Iter, Iter) for *Iter = value_type&&");
- Container c;
- ValueTp ValueList[] = { ValueTp(1), ValueTp(2) , ValueTp(3) };
- cc->expect<ValueTp&&>(3);
- c.insert(std::move_iterator<ValueTp*>(std::begin(ValueList)),
- std::move_iterator<ValueTp*>(std::end(ValueList)));
- assert(!cc->unchecked());
- {
- DisableAllocationGuard g;
- ValueTp ValueList2[] = { ValueTp(1), ValueTp(2) , ValueTp(3) };
- c.insert(std::move_iterator<ValueTp*>(std::begin(ValueList2)),
- std::move_iterator<ValueTp*>(std::end(ValueList2)));
- }
- }
- {
- CHECKPOINT("Testing C::insert(Iter, Iter) for *Iter = value_type&");
- Container c;
- ValueTp ValueList[] = { ValueTp(1), ValueTp(2) , ValueTp(3) };
- cc->expect<ValueTp const&>(3);
- c.insert(std::begin(ValueList), std::end(ValueList));
- assert(!cc->unchecked());
- {
- DisableAllocationGuard g;
- c.insert(std::begin(ValueList), std::end(ValueList));
- }
- }
- }
- template <class Container>
- void testSetEmplace()
- {
- typedef typename Container::value_type ValueTp;
- ConstructController* cc = getConstructController();
- cc->reset();
- {
- CHECKPOINT("Testing C::emplace(const value_type&)");
- Container c;
- const ValueTp v(42);
- cc->expect<const ValueTp&>();
- assert(c.emplace(v).second);
- assert(!cc->unchecked());
- {
- DisableAllocationGuard g;
- const ValueTp v2(42);
- assert(c.emplace(v2).second == false);
- }
- }
- {
- CHECKPOINT("Testing C::emplace(value_type&)");
- Container c;
- ValueTp v(42);
- cc->expect<ValueTp&>();
- assert(c.emplace(v).second);
- assert(!cc->unchecked());
- {
- DisableAllocationGuard g;
- ValueTp v2(42);
- assert(c.emplace(v2).second == false);
- }
- }
- {
- CHECKPOINT("Testing C::emplace(value_type&&)");
- Container c;
- ValueTp v(42);
- cc->expect<ValueTp&&>();
- assert(c.emplace(std::move(v)).second);
- assert(!cc->unchecked());
- {
- DisableAllocationGuard g;
- ValueTp v2(42);
- assert(c.emplace(std::move(v2)).second == false);
- }
- }
- {
- CHECKPOINT("Testing C::emplace(const value_type&&)");
- Container c;
- const ValueTp v(42);
- cc->expect<const ValueTp&&>();
- assert(c.emplace(std::move(v)).second);
- assert(!cc->unchecked());
- {
- DisableAllocationGuard g;
- const ValueTp v2(42);
- assert(c.emplace(std::move(v2)).second == false);
- }
- }
- }
- template <class Container>
- void testSetEmplaceHint()
- {
- typedef typename Container::value_type ValueTp;
- typedef Container C;
- typedef typename C::iterator It;
- ConstructController* cc = getConstructController();
- cc->reset();
- {
- CHECKPOINT("Testing C::emplace_hint(p, const value_type&)");
- Container c;
- const ValueTp v(42);
- cc->expect<const ValueTp&>();
- It ret = c.emplace_hint(c.end(), v);
- assert(ret != c.end());
- assert(c.size() == 1);
- assert(!cc->unchecked());
- {
- DisableAllocationGuard g;
- const ValueTp v2(42);
- It ret2 = c.emplace_hint(c.begin(), v2);
- assert(&(*ret2) == &(*ret));
- assert(c.size() == 1);
- }
- }
- {
- CHECKPOINT("Testing C::emplace_hint(p, value_type&)");
- Container c;
- ValueTp v(42);
- cc->expect<ValueTp&>();
- It ret = c.emplace_hint(c.end(), v);
- assert(ret != c.end());
- assert(c.size() == 1);
- assert(!cc->unchecked());
- {
- DisableAllocationGuard g;
- ValueTp v2(42);
- It ret2 = c.emplace_hint(c.begin(), v2);
- assert(&(*ret2) == &(*ret));
- assert(c.size() == 1);
- }
- }
- {
- CHECKPOINT("Testing C::emplace_hint(p, value_type&&)");
- Container c;
- ValueTp v(42);
- cc->expect<ValueTp&&>();
- It ret = c.emplace_hint(c.end(), std::move(v));
- assert(ret != c.end());
- assert(c.size() == 1);
- assert(!cc->unchecked());
- {
- DisableAllocationGuard g;
- ValueTp v2(42);
- It ret2 = c.emplace_hint(c.begin(), std::move(v2));
- assert(&(*ret2) == &(*ret));
- assert(c.size() == 1);
- }
- }
- {
- CHECKPOINT("Testing C::emplace_hint(p, const value_type&&)");
- Container c;
- const ValueTp v(42);
- cc->expect<const ValueTp&&>();
- It ret = c.emplace_hint(c.end(), std::move(v));
- assert(ret != c.end());
- assert(c.size() == 1);
- assert(!cc->unchecked());
- {
- DisableAllocationGuard g;
- const ValueTp v2(42);
- It ret2 = c.emplace_hint(c.begin(), std::move(v2));
- assert(&(*ret2) == &(*ret));
- assert(c.size() == 1);
- }
- }
- }
- template <class Container>
- void testMultisetInsert()
- {
- typedef typename Container::value_type ValueTp;
- ConstructController* cc = getConstructController();
- cc->reset();
- {
- CHECKPOINT("Testing C::insert(const value_type&)");
- Container c;
- const ValueTp v(42);
- cc->expect<const ValueTp&>();
- c.insert(v);
- assert(!cc->unchecked());
- }
- {
- CHECKPOINT("Testing C::insert(value_type&)");
- Container c;
- ValueTp v(42);
- cc->expect<const ValueTp&>();
- c.insert(v);
- assert(!cc->unchecked());
- }
- {
- CHECKPOINT("Testing C::insert(value_type&&)");
- Container c;
- ValueTp v(42);
- cc->expect<ValueTp&&>();
- c.insert(std::move(v));
- assert(!cc->unchecked());
- }
- {
- CHECKPOINT("Testing C::insert(std::initializer_list<ValueTp>)");
- Container c;
- std::initializer_list<ValueTp> il = { ValueTp(1), ValueTp(2) };
- cc->expect<ValueTp const&>(2);
- c.insert(il);
- assert(!cc->unchecked());
- }
- {
- CHECKPOINT("Testing C::insert(Iter, Iter) for *Iter = value_type const&");
- Container c;
- const ValueTp ValueList[] = { ValueTp(1), ValueTp(2), ValueTp(3) };
- cc->expect<ValueTp const&>(3);
- c.insert(std::begin(ValueList), std::end(ValueList));
- assert(!cc->unchecked());
- }
- {
- CHECKPOINT("Testing C::insert(Iter, Iter) for *Iter = value_type&&");
- Container c;
- ValueTp ValueList[] = { ValueTp(1), ValueTp(2) , ValueTp(3) };
- cc->expect<ValueTp&&>(3);
- c.insert(std::move_iterator<ValueTp*>(std::begin(ValueList)),
- std::move_iterator<ValueTp*>(std::end(ValueList)));
- assert(!cc->unchecked());
- }
- {
- CHECKPOINT("Testing C::insert(Iter, Iter) for *Iter = value_type&");
- Container c;
- ValueTp ValueList[] = { ValueTp(1), ValueTp(2) , ValueTp(1) };
- cc->expect<ValueTp&>(3);
- c.insert(std::begin(ValueList), std::end(ValueList));
- assert(!cc->unchecked());
- }
- }
- template <class Container>
- void testMultisetEmplace()
- {
- typedef typename Container::value_type ValueTp;
- ConstructController* cc = getConstructController();
- cc->reset();
- {
- CHECKPOINT("Testing C::emplace(const value_type&)");
- Container c;
- const ValueTp v(42);
- cc->expect<const ValueTp&>();
- c.emplace(v);
- assert(!cc->unchecked());
- }
- {
- CHECKPOINT("Testing C::emplace(value_type&)");
- Container c;
- ValueTp v(42);
- cc->expect<ValueTp&>();
- c.emplace(v);
- assert(!cc->unchecked());
- }
- {
- CHECKPOINT("Testing C::emplace(value_type&&)");
- Container c;
- ValueTp v(42);
- cc->expect<ValueTp&&>();
- c.emplace(std::move(v));
- assert(!cc->unchecked());
- }
- {
- CHECKPOINT("Testing C::emplace(const value_type&&)");
- Container c;
- const ValueTp v(42);
- cc->expect<const ValueTp&&>();
- c.emplace(std::move(v));
- assert(!cc->unchecked());
- }
- }
- #endif
|