PageRenderTime 20ms CodeModel.GetById 1ms app.highlight 14ms RepoModel.GetById 3ms app.codeStats 0ms

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

http://hadesmem.googlecode.com/
C++ | 93 lines | 72 code | 18 blank | 3 comment | 0 complexity | 4463a6d35f5d399d81c557de10a6f889 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 "../helpers/random_values.hpp"
10#include "../helpers/invariants.hpp"
11
12#if defined(BOOST_MSVC)
13#pragma warning(disable:4512) // assignment operator could not be generated
14#endif
15
16test::seed_t seed(12847);
17
18template <class T>
19struct self_assign_base : public test::exception_base
20{
21    test::random_values<T> values;
22    self_assign_base(int count = 0) : values(count) {}
23
24    typedef T data_type;
25    T init() const { return T(values.begin(), values.end()); }
26    void run(T& x) const { x = x; }
27    void check BOOST_PREVENT_MACRO_SUBSTITUTION(T const& x) const
28        { test::check_equivalent_keys(x); }
29};
30
31template <class T>
32struct self_assign_test1 : self_assign_base<T> {};
33
34template <class T>
35struct self_assign_test2 : self_assign_base<T>
36{
37    self_assign_test2() : self_assign_base<T>(100) {}
38};
39
40template <class T>
41struct assign_base : public test::exception_base
42{
43    const test::random_values<T> x_values, y_values;
44    const T x,y;
45
46    typedef BOOST_DEDUCED_TYPENAME T::hasher hasher;
47    typedef BOOST_DEDUCED_TYPENAME T::key_equal key_equal;
48    typedef BOOST_DEDUCED_TYPENAME T::allocator_type allocator_type;
49
50    assign_base(unsigned int count1, unsigned int count2, int tag1, int tag2) :
51        x_values(count1),
52        y_values(count2),
53        x(x_values.begin(), x_values.end(), 0, hasher(tag1), key_equal(tag1),
54            allocator_type(tag1)),
55        y(y_values.begin(), y_values.end(), 0, hasher(tag2), key_equal(tag2),
56            allocator_type(tag2))
57    {}
58
59    typedef T data_type;
60    T init() const { return T(x); }
61    void run(T& x1) const { x1 = y; }
62    void check BOOST_PREVENT_MACRO_SUBSTITUTION(T const& x1) const
63        { test::check_equivalent_keys(x1); }
64};
65
66template <class T>
67struct assign_test1 : assign_base<T>
68{
69    assign_test1() : assign_base<T>(0, 0, 0, 0) {}
70};
71
72template <class T>
73struct assign_test2 : assign_base<T>
74{
75    assign_test2() : assign_base<T>(60, 0, 0, 0) {}    
76};
77
78template <class T>
79struct assign_test3 : assign_base<T>
80{
81    assign_test3() : assign_base<T>(0, 60, 0, 0) {}    
82};
83
84template <class T>
85struct assign_test4 : assign_base<T>
86{
87    assign_test4() : assign_base<T>(10, 10, 1, 2) {}
88};
89
90RUN_EXCEPTION_TESTS(
91    (self_assign_test1)(self_assign_test2)
92    (assign_test1)(assign_test2)(assign_test3)(assign_test4),
93    CONTAINER_SEQ)