• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /////////////////////////////////////////////////////////////////////////////
2 //
3 // (C) Copyright Ion Gaztanaga  2006-2013
4 //
5 // Distributed under the Boost Software License, Version 1.0.
6 //    (See accompanying file LICENSE_1_0.txt or copy at
7 //          http://www.boost.org/LICENSE_1_0.txt)
8 //
9 // See http://www.boost.org/libs/intrusive for documentation.
10 //
11 /////////////////////////////////////////////////////////////////////////////
12 
13 #ifndef BOOST_INTRUSIVE_TEST_TEST_MACROS_HPP
14 #define BOOST_INTRUSIVE_TEST_TEST_MACROS_HPP
15 
16 #include <boost/intrusive/intrusive_fwd.hpp>
17 #include <algorithm> //std::unique
18 
19 namespace boost{
20 namespace intrusive{
21 namespace test{
22 
23 template <class T>
24 struct is_multikey_true
25 {
26    typedef char yes_type;
27    template<bool IsMultikey>
28    struct two { yes_type _[1+IsMultikey]; };
29    template <class U> static yes_type           test(...);
30    template <class U> static two<U::is_multikey>test(int);
31    static const bool value = sizeof(test<T>(0)) != sizeof(yes_type);
32 };
33 
34 }  //namespace test{
35 
36 template<class It1, class It2>
test_equal(It1 f1,It1 l1,It2 f2)37 bool test_equal(It1 f1, It1 l1, It2 f2)
38 {
39    while(f1 != l1){
40       if(*f1 != *f2){
41          return false;
42       }
43       ++f1;
44       ++f2;
45    }
46    return true;
47 }
48 
49 #define TEST_INTRUSIVE_SEQUENCE( INTVALUES, ITERATOR )\
50 {  \
51    BOOST_TEST (boost::intrusive::test_equal(&INTVALUES[0], &INTVALUES[0] + sizeof(INTVALUES)/sizeof(INTVALUES[0]), ITERATOR) ); \
52 }
53 
54 #define TEST_INTRUSIVE_SEQUENCE_EXPECTED( EXPECTEDVECTOR, ITERATOR )\
55 {  \
56    BOOST_TEST (boost::intrusive::test_equal(EXPECTEDVECTOR.begin(), EXPECTEDVECTOR.end(), ITERATOR) ); \
57 }
58 
59 namespace test{
60 
61 template<class Container, class Vector>
test_intrusive_maybe_unique(const Container & c,Vector & v)62 void test_intrusive_maybe_unique(const Container &c, Vector &v)
63 {
64    if(!is_multikey_true<Container>::value)
65       v.erase(std::unique(v.begin(), v.end()), v.end());
66    BOOST_TEST (boost::intrusive::test_equal(v.begin(), v.end(), c.begin()) );
67 }
68 
69 }  //namespace test{
70 
71 #define TEST_INTRUSIVE_SEQUENCE_MAYBEUNIQUE(INTVALUES, CONTAINER)\
72 {\
73    boost::container::vector<int>v(&INTVALUES[0], &INTVALUES[0] + sizeof(INTVALUES)/sizeof(INTVALUES[0]));\
74    boost::intrusive::test::test_intrusive_maybe_unique(CONTAINER, v);\
75 }\
76 //
77 
78 }  //namespace boost{
79 }  //namespace intrusive{
80 
81 #endif
82