~ubuntu-branches/debian/sid/boost1.49/sid

« back to all changes in this revision

Viewing changes to libs/unordered/test/helpers/test.hpp

  • Committer: Package Import Robot
  • Author(s): Steve M. Robbins
  • Date: 2012-02-26 00:31:44 UTC
  • Revision ID: package-import@ubuntu.com-20120226003144-eaytp12cbf6ubpms
Tags: upstream-1.49.0
ImportĀ upstreamĀ versionĀ 1.49.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
#if !defined(BOOST_UNORDERED_TEST_TEST_HEADER)
 
7
#define BOOST_UNORDERED_TEST_TEST_HEADER
 
8
 
 
9
#include <boost/detail/lightweight_test.hpp>
 
10
#include <boost/preprocessor/cat.hpp>
 
11
#include <boost/preprocessor/stringize.hpp>
 
12
#include <iostream>
 
13
 
 
14
#define UNORDERED_AUTO_TEST(x)                                              \
 
15
    struct BOOST_PP_CAT(x, _type) : public ::test::registered_test_base {   \
 
16
        BOOST_PP_CAT(x, _type)()                                            \
 
17
            : ::test::registered_test_base(BOOST_PP_STRINGIZE(x))           \
 
18
        {                                                                   \
 
19
            ::test::test_list::add_test(this);                              \
 
20
        }                                                                   \
 
21
        void run();                                                         \
 
22
    };                                                                      \
 
23
    BOOST_PP_CAT(x, _type) x;                                               \
 
24
    void BOOST_PP_CAT(x, _type)::run()                                      \
 
25
 
 
26
#define RUN_TESTS() int main(int, char**)                                   \
 
27
    { ::test::test_list::run_tests(); return boost::report_errors(); }      \
 
28
 
 
29
namespace test {
 
30
    struct registered_test_base {
 
31
        registered_test_base* next;
 
32
        char const* name;
 
33
        explicit registered_test_base(char const* n) : name(n) {}
 
34
        virtual void run() = 0;
 
35
        virtual ~registered_test_base() {}
 
36
    };
 
37
 
 
38
    namespace test_list {
 
39
        static inline registered_test_base*& first() {
 
40
            static registered_test_base* ptr = 0;
 
41
            return ptr;
 
42
        }
 
43
 
 
44
        static inline registered_test_base*& last() {
 
45
            static registered_test_base* ptr = 0;
 
46
            return ptr;
 
47
        }
 
48
 
 
49
        static inline void add_test(registered_test_base* test) {
 
50
            if(last()) {
 
51
                last()->next = test;
 
52
            }
 
53
            else {
 
54
                first() = test;
 
55
            }
 
56
 
 
57
            last() = test;
 
58
        }
 
59
 
 
60
        static inline void run_tests() {
 
61
            for(registered_test_base* i = first(); i; i = i->next) {
 
62
                std::cout<<"Running "<<i->name<<"\n"<<std::flush;
 
63
                i->run();
 
64
                std::cerr<<std::flush;
 
65
                std::cout<<std::flush;
 
66
            }
 
67
        }
 
68
    }
 
69
}
 
70
 
 
71
#include <boost/preprocessor/seq/for_each_product.hpp>
 
72
#include <boost/preprocessor/seq/fold_left.hpp>
 
73
#include <boost/preprocessor/seq/to_tuple.hpp>
 
74
#include <boost/preprocessor/seq/seq.hpp>
 
75
#include <boost/preprocessor/cat.hpp>
 
76
 
 
77
// Run test with every combination of the parameters (a sequence of sequences)
 
78
#define UNORDERED_TEST(name, parameters)                                    \
 
79
    BOOST_PP_SEQ_FOR_EACH_PRODUCT(UNORDERED_TEST_OP, ((name)) parameters)   \
 
80
 
 
81
#define UNORDERED_TEST_OP(r, product)                                       \
 
82
    UNORDERED_TEST_OP2(                                                     \
 
83
        BOOST_PP_SEQ_HEAD(product),                                         \
 
84
        BOOST_PP_SEQ_TAIL(product))                                         \
 
85
 
 
86
#define UNORDERED_TEST_OP2(name, params)                                    \
 
87
    UNORDERED_AUTO_TEST(                                                    \
 
88
        BOOST_PP_SEQ_FOLD_LEFT(UNORDERED_TEST_OP_JOIN, name, params))       \
 
89
    {                                                                       \
 
90
        name BOOST_PP_SEQ_TO_TUPLE(params);                                 \
 
91
    }                                                                       \
 
92
 
 
93
#define UNORDERED_TEST_OP_JOIN(s, state, elem)                              \
 
94
    BOOST_PP_CAT(state, BOOST_PP_CAT(_, elem))                              \
 
95
 
 
96
#endif