PageRenderTime 12ms CodeModel.GetById 1ms app.highlight 8ms RepoModel.GetById 1ms app.codeStats 1ms

/Src/Dependencies/Boost/libs/unordered/test/exception/rehash_exception_tests.cpp

http://hadesmem.googlecode.com/
C++ | 87 lines | 66 code | 18 blank | 3 comment | 4 complexity | 05943dd7d0f994ac314cead36b3e088a MD5 | raw file
 1
 2// Copyright 2006-2009 Daniel James.
 3// Distributed under the Boost Software License, Version 1.0. (See accompanying
 4// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
 5
 6#include "../helpers/prefix.hpp"
 7
 8#include "./containers.hpp"
 9#include <string>
10#include "../helpers/random_values.hpp"
11#include "../helpers/invariants.hpp"
12#include "../helpers/strong.hpp"
13
14#include <iostream>
15
16test::seed_t seed(3298597);
17
18template <class T>
19struct rehash_test_base : public test::exception_base
20{
21    test::random_values<T> values;
22    unsigned int n;
23    rehash_test_base(unsigned int count = 100, unsigned int n = 0)
24        : values(count), n(n)
25    {}
26
27    typedef T data_type;
28    typedef test::strong<T> strong_type;
29
30    data_type init() const {
31        T x(values.begin(), values.end(), n);
32        return x;
33    }
34
35    void check BOOST_PREVENT_MACRO_SUBSTITUTION(T const& x,
36        strong_type const& strong) const
37    {
38        std::string scope(test::scope);
39
40        if(scope.find("hash::operator()") == std::string::npos &&
41                scope.find("equal_to::operator()") == std::string::npos &&
42                scope != "operator==(object, object)")
43            strong.test(x);
44
45        test::check_equivalent_keys(x);
46    }
47};
48
49template <class T>
50struct rehash_test0 : rehash_test_base<T>
51{
52    rehash_test0() : rehash_test_base<T>(0) {}
53    void run(T& x) const { x.rehash(0); }
54};
55
56template <class T>
57struct rehash_test1 : rehash_test_base<T>
58{
59    rehash_test1() : rehash_test_base<T>(0) {}
60    void run(T& x) const { x.rehash(200); }
61};
62
63template <class T>
64struct rehash_test2 : rehash_test_base<T>
65{
66    rehash_test2() : rehash_test_base<T>(0, 200) {}
67    void run(T& x) const { x.rehash(0); }
68};
69
70template <class T>
71struct rehash_test3 : rehash_test_base<T>
72{
73    rehash_test3() : rehash_test_base<T>(10, 0) {}
74    void run(T& x) const { x.rehash(200); }
75};
76
77template <class T>
78struct rehash_test4 : rehash_test_base<T>
79{
80    rehash_test4() : rehash_test_base<T>(10, 200) {}
81    void run(T& x) const { x.rehash(0); }
82};
83
84RUN_EXCEPTION_TESTS(
85    (rehash_test0)(rehash_test1)(rehash_test2)(rehash_test3)(rehash_test4),
86    CONTAINER_SEQ)
87