switch to new MPL based Fraunhofer FOKUS Public License
[senf.git] / senf / Utils / mpl.test.cc
1 // $Id$
2 //
3 // Copyright (C) 2007
4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 //
6 // The contents of this file are subject to the Fraunhofer FOKUS Public License
7 // Version 1.0 (the "License"); you may not use this file except in compliance
8 // with the License. You may obtain a copy of the License at 
9 // http://senf.berlios.de/license.html
10 //
11 // The Fraunhofer FOKUS Public License Version 1.0 is based on, 
12 // but modifies the Mozilla Public License Version 1.1.
13 // See the full license text for the amendments.
14 //
15 // Software distributed under the License is distributed on an "AS IS" basis, 
16 // WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 
17 // for the specific language governing rights and limitations under the License.
18 //
19 // The Original Code is Fraunhofer FOKUS code.
20 //
21 // The Initial Developer of the Original Code is Fraunhofer-Gesellschaft e.V. 
22 // (registered association), Hansastraße 27 c, 80686 Munich, Germany.
23 // All Rights Reserved.
24 //
25 // Contributor(s):
26 //   Stefan Bund <g0dil@berlios.de>
27
28 /** \file
29     \brief mpl unit tests */
30
31 //#include "mpl.test.hh"
32 //#include "mpl.test.ih"
33
34 // Custom includes
35 #include "mpl.hh"
36
37 #include <senf/Utils/auto_unit_test.hh>
38 #include <boost/test/test_tools.hpp>
39
40 #define prefix_
41 //-/////////////////////////////////////////////////////////////////////////////////////////////////
42
43 namespace {
44
45     template <unsigned _>
46     struct select {
47         static bool const has_int_value = false;
48         static bool const has_class_value = false;
49     };
50     template <class T>
51     senf::mpl::rv<0> select_(...);
52
53
54     template <>
55     struct select<1> {
56         static bool const has_int_value = true;
57         static bool const has_class_value = false;
58     };
59     template <class T>
60     senf::mpl::rv<1> select_(int, senf::mpl::take_int<T::value> * = 0);
61
62     template <>
63     struct select<2> {
64         static bool const has_int_value = false;
65         static bool const has_class_value = true;
66     };
67     template <class T>
68     senf::mpl::rv<2> select_(int, senf::mpl::take_class<typename T::value> * = 0);
69
70     template <class T>
71     struct choice : public select<SENF_MPL_RV( select_<T>(0) )> {};
72
73     struct A { static const int value = 0; };
74     struct B { struct value {}; };
75     struct C {};
76 }
77
78 SENF_AUTO_UNIT_TEST(senfmpl)
79 {
80     BOOST_CHECK( choice<A>::has_int_value );
81     BOOST_CHECK( ! choice<A>::has_class_value );
82
83     BOOST_CHECK( ! choice<B>::has_int_value );
84     BOOST_CHECK( choice<B>::has_class_value );
85
86     BOOST_CHECK( ! choice<C>::has_int_value );
87     BOOST_CHECK( ! choice<C>::has_class_value );
88 }
89
90 namespace {
91
92 #   define Begin() SENF_MPL_SLOT_DEF(accum, 0)
93 #   define Add(n) SENF_MPL_SLOT_SET(accum, SENF_MPL_SLOT_GET(accum)+n)
94 #   define End() BOOST_STATIC_CONSTANT(unsigned, total = SENF_MPL_SLOT_GET(accum))
95
96     struct Test
97     {
98         Begin();
99
100         Add(2);
101         Add(2);
102
103         // Here some comment ...
104
105         Add(4);
106
107         End();
108     };
109
110 }
111
112 SENF_AUTO_UNIT_TEST(mplSlot)
113 {
114     BOOST_CHECK_EQUAL( unsigned(Test::total), 8u );
115 }
116
117 //-/////////////////////////////////////////////////////////////////////////////////////////////////
118 #undef prefix_
119
120 \f
121 // Local Variables:
122 // mode: c++
123 // fill-column: 100
124 // comment-column: 40
125 // c-file-style: "senf"
126 // indent-tabs-mode: nil
127 // ispell-local-dictionary: "american"
128 // compile-command: "scons -u test"
129 // End: