Skip to content

Commit

Permalink
Update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
MikePopoloski committed May 12, 2024
1 parent bd2ecf9 commit 74ee084
Show file tree
Hide file tree
Showing 66 changed files with 2,225 additions and 697 deletions.
2 changes: 1 addition & 1 deletion test/exception/containers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ typedef boost::unordered_multiset<test::exception::object,
test::exception::hash, test::exception::equal_to,
test::exception::allocator2<test::exception::object> >
test_multiset;
typedef boost::unordered_map<test::exception::object, test::exception::object,
typedef boost::unordered_flat_map<test::exception::object, test::exception::object,
test::exception::hash, test::exception::equal_to,
test::exception::allocator2<test::exception::object> >
test_map;
Expand Down
11 changes: 7 additions & 4 deletions test/exception/insert_exception_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
#include "../helpers/random_values.hpp"
#include "../helpers/strong.hpp"
#include "../helpers/tracker.hpp"

#include <boost/tuple/tuple.hpp>

#include <cmath>
#include <string>

Expand Down Expand Up @@ -84,7 +87,7 @@ void insert_exception_test(T*, Inserter insert, test::random_generator gen)
test::random_values<T> v(10, gen);
T x;

EXCEPTION_LOOP(insert_exception_test_impl(x, generate(insert, x), v));
EXCEPTION_LOOP(insert_exception_test_impl(x, generate(insert, x), v))
}
}

Expand All @@ -100,7 +103,7 @@ void insert_rehash_exception_test(
rehash_prep(x);

test::random_values<T> v2(5, gen);
EXCEPTION_LOOP(insert_exception_test_impl(x, generate(insert, x), v2));
EXCEPTION_LOOP(insert_exception_test_impl(x, generate(insert, x), v2))
}
}

Expand Down Expand Up @@ -458,7 +461,7 @@ void insert_range_exception_test(T*, test::random_generator gen)
test::random_values<T> v(10, gen);
T x;

EXCEPTION_LOOP(insert_range_exception_test_impl(x, v));
EXCEPTION_LOOP(insert_range_exception_test_impl(x, v))
}
}

Expand All @@ -470,7 +473,7 @@ void insert_range_rehash_exception_test(T*, test::random_generator gen)
rehash_prep(x);

test::random_values<T> v2(5, gen);
EXCEPTION_LOOP(insert_range_exception_test_impl(x, v2));
EXCEPTION_LOOP(insert_range_exception_test_impl(x, v2))
}
}

Expand Down
2 changes: 1 addition & 1 deletion test/exception/merge_exception_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ boost::unordered_set<test::exception::object, test::exception::hash,
boost::unordered_multiset<test::exception::object, test::exception::hash,
test::exception::equal_to,
test::exception::allocator<test::exception::object> >* test_multiset_;
boost::unordered_map<test::exception::object, test::exception::object,
boost::unordered_flat_map<test::exception::object, test::exception::object,
test::exception::hash, test::exception::equal_to,
test::exception::allocator2<test::exception::object> >* test_map_;
boost::unordered_multimap<test::exception::object, test::exception::object,
Expand Down
2 changes: 1 addition & 1 deletion test/exception/swap_exception_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ using unordered_node_map = boost::unordered_node_map<int, int, boost::hash<int>,
typedef boost::unordered_set<int, boost::hash<int>, std::equal_to<int>,
test::allocator1<int> >
unordered_set;
typedef boost::unordered_map<int, int, boost::hash<int>, std::equal_to<int>,
typedef boost::unordered_flat_map<int, int, boost::hash<int>, std::equal_to<int>,
test::allocator1<std::pair<int const, int> > >
unordered_map;
typedef boost::unordered_multiset<int, boost::hash<int>, std::equal_to<int>,
Expand Down
112 changes: 111 additions & 1 deletion test/helpers/count.hpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@

// Copyright 2008-2009 Daniel James.
// Copyright 2024 Braden Ganetsky.
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or move at http://www.boost.org/LICENSE_1_0.txt)

#if !defined(BOOST_UNORDERED_TEST_HELPERS_COUNT_HEAD)
#define BOOST_UNORDERED_TEST_HELPERS_COUNT_HEAD

#include <boost/core/lightweight_test.hpp>
#include <boost/container_hash/hash.hpp>

namespace test {
struct object_count
Expand Down Expand Up @@ -84,6 +86,114 @@ namespace test {
return global_object_count.constructions - constructions_;
}
};
}

struct smf_count
{
int default_constructions = 0;
int copy_constructions = 0;
int move_constructions = 0;
int copy_assignments = 0;
int move_assignments = 0;
int destructions = 0;

#if (BOOST_CXX_VERSION < 201402L) || (defined(_MSC_VER) && _MSC_VER < 1910)
smf_count() = default;

smf_count(int default_constructions_, int copy_constructions_,
int move_constructions_, int copy_assignments_, int move_assignments_,
int destructions_)
: default_constructions(default_constructions_),
copy_constructions(copy_constructions_),
move_constructions(move_constructions_),
copy_assignments(copy_assignments_),
move_assignments(move_assignments_), destructions(destructions_)
{
}
#endif

void reset() { *this = smf_count(); }

void default_construct() { ++default_constructions; }
void copy_construct() { ++copy_constructions; }
void move_construct() { ++move_constructions; }
void copy_assign() { ++copy_assignments; }
void move_assign() { ++move_assignments; }
void destruct() { ++destructions; }

friend bool operator==(smf_count const& lhs, smf_count const& rhs)
{
return lhs.default_constructions == rhs.default_constructions &&
lhs.copy_constructions == rhs.copy_constructions &&
lhs.move_constructions == rhs.move_constructions &&
lhs.copy_assignments == rhs.copy_assignments &&
lhs.move_assignments == rhs.move_assignments &&
lhs.destructions == rhs.destructions;
}

friend std::ostream& operator<<(std::ostream& out, smf_count const& c)
{
out << "[default_constructions: " << c.default_constructions
<< ", copy_constructions: " << c.copy_constructions
<< ", move_constructions: " << c.move_constructions
<< ", copy_assignments: " << c.copy_assignments
<< ", move_assignments: " << c.move_assignments
<< ", destructions: " << c.destructions << "]";
return out;
}
};

template <class Tag> class smf_counted_object
{
public:
static smf_count count;
static void reset_count() { count.reset(); }

smf_counted_object(int index) : smf_counted_object() { index_ = index; }

smf_counted_object() : index_(++running_index)
{
count.default_construct();
}
smf_counted_object(smf_counted_object const& rhs) : index_(rhs.index_)
{
count.copy_construct();
}
smf_counted_object(smf_counted_object&& rhs) noexcept : index_(rhs.index_)
{
count.move_construct();
}
smf_counted_object& operator=(smf_counted_object const& rhs)
{
count.copy_assign();
index_ = rhs.index_;
return *this;
}
smf_counted_object& operator=(smf_counted_object&& rhs) noexcept
{
count.move_assign();
index_ = rhs.index_;
return *this;
}
~smf_counted_object() { count.destruct(); }

friend bool operator==(
smf_counted_object const& lhs, smf_counted_object const& rhs)
{
return lhs.index_ == rhs.index_;
}

friend std::size_t hash_value(smf_counted_object const& x)
{
return boost::hash<int>()(x.index_);
}

int index_;

private:
static int running_index;
};
template <class Tag> smf_count smf_counted_object<Tag>::count = {};
template <class Tag> int smf_counted_object<Tag>::running_index = 0;
} // namespace test

#endif
1 change: 1 addition & 0 deletions test/helpers/equivalent.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "./metafunctions.hpp"
#include <algorithm>
#include <boost/core/lightweight_test.hpp>
#include <boost/container_hash/hash.hpp>

namespace test {
template <class T1, class T2>
Expand Down
2 changes: 1 addition & 1 deletion test/helpers/invariants.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ namespace test {
}
}
#endif
};
}

// Check that size matches up.

Expand Down
1 change: 1 addition & 0 deletions test/helpers/memory.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#include "../helpers/test.hpp"
#include <boost/assert.hpp>
#include <boost/unordered/detail/implementation.hpp>
#include <map>
#include <memory>

Expand Down
8 changes: 7 additions & 1 deletion test/helpers/test.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,15 @@
#define BOOST_UNORDERED_TEST_TEST_HEADER

#include <boost/core/lightweight_test.hpp>
#include <boost/core/lightweight_test_trait.hpp>
#include <boost/preprocessor/cat.hpp>
#include <boost/preprocessor/stringize.hpp>

#include <boost/type_traits/is_nothrow_move_assignable.hpp>
#include <boost/type_traits/is_nothrow_move_constructible.hpp>
#include <boost/type_traits/is_nothrow_swappable.hpp>
#include <boost/type_traits/make_void.hpp>

#define UNORDERED_AUTO_TEST(x) \
struct BOOST_PP_CAT(x, _type) : public ::test::registered_test_base \
{ \
Expand Down Expand Up @@ -119,7 +125,7 @@ namespace test {
static state instance;
return instance;
}
}
} // namespace test

#if defined(__cplusplus)
#define BOOST_UNORDERED_CPLUSPLUS __cplusplus
Expand Down
7 changes: 7 additions & 0 deletions test/helpers/unordered.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,16 @@
#include <boost/unordered/unordered_flat_map.hpp>
#include <boost/unordered/unordered_node_map.hpp>
#include <boost/unordered/unordered_node_set.hpp>
#include <boost/unordered/detail/implementation.hpp>
#else
#endif
#include "postfix.hpp"
// clang-format on

#if defined(BOOST_LIBSTDCXX_VERSION)
#if BOOST_LIBSTDCXX_VERSION < 60000
#define BOOST_UNORDERED_NO_INIT_TYPE_TESTS
#endif
#endif

#endif
31 changes: 14 additions & 17 deletions test/objects/cxx11_allocator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,9 +182,7 @@ namespace test

~cxx11_allocator_base() { detail::tracker.allocator_unref(); }

#if !defined(BOOST_NO_CXX11_DEFAULTED_FUNCTIONS)
cxx11_allocator_base& operator=(cxx11_allocator_base const& x) = default;
#endif

pointer address(reference r) { return pointer(&r); }

Expand Down Expand Up @@ -214,21 +212,12 @@ namespace test
::operator delete((void*)p);
}

#if defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
template <class U, class V>
void construct(U* p, V const& v)
{
detail::tracker.track_construct((void*)p, sizeof(U), tag_);
new (p) U(v);
}
#else
template <class U, typename... Args>
void construct(U* p, Args&&... args)
{
detail::tracker.track_construct((void*)p, sizeof(U), tag_);
new (p) U(std::forward<Args>(args)...);
}
#endif

template <class U>
void destroy(U* p)
Expand All @@ -248,13 +237,19 @@ namespace test

template <typename T, typename Flags>
struct cxx11_allocator<T, Flags,
typename std::enable_if<!Flags::is_select_on_copy>::type>
typename boost::disable_if_c<Flags::is_select_on_copy>::type>
: public cxx11_allocator_base<T>,
public swap_allocator_base<Flags>,
public assign_allocator_base<Flags>,
public move_allocator_base<Flags>,
Flags
{
#if BOOST_WORKAROUND(BOOST_GCC_VERSION, < 402000)
template <typename U> struct rebind
{
typedef cxx11_allocator<U, Flags> other;
};
#endif

explicit cxx11_allocator(int t = 0) : cxx11_allocator_base<T>(t) {}

Expand All @@ -266,9 +261,7 @@ namespace test

cxx11_allocator(cxx11_allocator const& x) : cxx11_allocator_base<T>(x) {}

#if !defined(BOOST_NO_CXX11_DEFAULTED_FUNCTIONS)
cxx11_allocator& operator=(cxx11_allocator const& x) = default;
#endif

// When not propagating swap, allocators are always equal
// to avoid undefined behaviour.
Expand All @@ -282,7 +275,7 @@ namespace test

template <typename T, typename Flags>
struct cxx11_allocator<T, Flags,
typename std::enable_if<Flags::is_select_on_copy>::type>
typename boost::enable_if_c<Flags::is_select_on_copy>::type>
: public cxx11_allocator_base<T>,
public swap_allocator_base<Flags>,
public assign_allocator_base<Flags>,
Expand All @@ -296,6 +289,12 @@ namespace test
return tmp;
}

#if BOOST_WORKAROUND(BOOST_GCC_VERSION, < 402000)
template <typename U> struct rebind
{
typedef cxx11_allocator<U, Flags> other;
};
#endif

explicit cxx11_allocator(int t = 0) : cxx11_allocator_base<T>(t) {}

Expand All @@ -307,9 +306,7 @@ namespace test

cxx11_allocator(cxx11_allocator const& x) : cxx11_allocator_base<T>(x) {}

#if !defined(BOOST_NO_CXX11_DEFAULTED_FUNCTIONS)
cxx11_allocator& operator=(cxx11_allocator const& x) = default;
#endif

// When not propagating swap, allocators are always equal
// to avoid undefined behaviour.
Expand Down
Loading

0 comments on commit 74ee084

Please sign in to comment.