unordered/test/exception/rehash_exception_tests.cpp
Daniel James be93c29493 Merge the latest unordered changes. These are concerned with getting the tests
working on more compilers. The biggest change is that the exception tests have
been changed to use a very simple exception testing mechanism on top of
lightweight_test. This was because Boost.Test exception testing isn't working
on several platforms. I'm trying to set this up so that I can use Boost.Test on
compilers which it completely supports, and lightweight test on others.
Boost.Test tests more than my simple exception testing code ever will so it's
worth using where I can.


[SVN r42698]
2008-01-12 14:43:40 +00:00

82 lines
2.0 KiB
C++

// Copyright 2006-2007 Daniel James.
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
#include "./containers.hpp"
#include <string>
#include "../helpers/random_values.hpp"
#include "../helpers/invariants.hpp"
#include "../helpers/strong.hpp"
#include <iostream>
test::seed_t seed(3298597);
template <class T>
struct rehash_test_base : public test::exception_base
{
test::random_values<T> values;
unsigned int n;
rehash_test_base(unsigned int count = 100, unsigned int n = 0) : values(count), n(n) {}
typedef T data_type;
typedef test::strong<T> strong_type;
data_type init() const {
T x(values.begin(), values.end(), n);
return x;
}
void check(T const& x, strong_type const& strong) const {
std::string scope(test::scope);
if(scope.find("hash::operator()") == std::string::npos &&
scope.find("equal_to::operator()") == std::string::npos &&
scope != "operator==(object, object)")
strong.test(x);
test::check_equivalent_keys(x);
}
};
template <class T>
struct rehash_test0 : rehash_test_base<T>
{
rehash_test0() : rehash_test_base<T>(0) {}
void run(T& x) const { x.rehash(0); }
};
template <class T>
struct rehash_test1 : rehash_test_base<T>
{
rehash_test1() : rehash_test_base<T>(0) {}
void run(T& x) const { x.rehash(200); }
};
template <class T>
struct rehash_test2 : rehash_test_base<T>
{
rehash_test2() : rehash_test_base<T>(0, 200) {}
void run(T& x) const { x.rehash(0); }
};
template <class T>
struct rehash_test3 : rehash_test_base<T>
{
rehash_test3() : rehash_test_base<T>(10, 0) {}
void run(T& x) const { x.rehash(200); }
};
template <class T>
struct rehash_test4 : rehash_test_base<T>
{
rehash_test4() : rehash_test_base<T>(10, 200) {}
void run(T& x) const { x.rehash(0); }
};
RUN_EXCEPTION_TESTS(
(rehash_test0)(rehash_test1)(rehash_test2)(rehash_test3)(rehash_test4),
CONTAINER_SEQ)