switch to new MPL based Fraunhofer FOKUS Public License
[senf.git] / senf / Utils / RestrictedInt.test.cc
1 // $Id$
2 //
3 // Copyright (C) 2010
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 RestrictedInt.test unit tests */
30
31 //#include "RestrictedInt.test.hh"
32 //#include "RestrictedInt.test.ih"
33
34 // Custom includes
35 #include "RestrictedInt.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     struct TestIntTag {};
45     typedef senf::RestrictedInt<int,TestIntTag> TestInt;
46 }
47
48 SENF_AUTO_UNIT_TEST(restrictedInt)
49 {
50     TestInt i1;
51     TestInt i2(10);
52
53     BOOST_CHECK_EQUAL( i1, TestInt(0) );
54     BOOST_CHECK_EQUAL( i2, TestInt(10) );
55
56     BOOST_CHECK_EQUAL( i1+i2, TestInt(10) );
57
58     i1 = TestInt(6);
59
60     BOOST_CHECK_EQUAL( i2-i1, TestInt(4) );
61
62     i2 = TestInt(0);
63
64     BOOST_CHECK_EQUAL( -i1, TestInt(-6) );
65     BOOST_CHECK( static_cast<bool>(i1) );
66     BOOST_CHECK( static_cast<bool>(!i2) );
67
68     BOOST_CHECK_EQUAL( i1 ++, TestInt(6) );
69     BOOST_CHECK_EQUAL( ++ i1, TestInt(8) );
70
71     BOOST_CHECK_EQUAL( i1 * TestInt(2), TestInt(16) );
72     BOOST_CHECK_EQUAL( i1, TestInt(8) );
73     BOOST_CHECK_EQUAL( i1 / TestInt(2), TestInt(4) );
74     BOOST_CHECK_EQUAL( i1, TestInt(8) );
75     BOOST_CHECK_EQUAL( i1 >> TestInt(1), TestInt(4) );
76     BOOST_CHECK_EQUAL( i1, TestInt(8) );
77     BOOST_CHECK_EQUAL( i1 << TestInt(1), TestInt(16) );
78     BOOST_CHECK_EQUAL( i1, TestInt(8) );
79     BOOST_CHECK_EQUAL( i1 & TestInt(2), TestInt(0) );
80     BOOST_CHECK_EQUAL( i1, TestInt(8) );
81     BOOST_CHECK_EQUAL( i1 | TestInt(2), TestInt(10) );
82     BOOST_CHECK_EQUAL( i1, TestInt(8) );
83     BOOST_CHECK_EQUAL( i1 ^ TestInt(2), TestInt(10) );
84     BOOST_CHECK_EQUAL( i1, TestInt(8) );
85
86     BOOST_CHECK_EQUAL( ~~i1, i1 );
87     SENF_CHECK_NOT_EQUAL( ~i1, i1 );
88
89     BOOST_CHECK( i1 > i2 );
90     BOOST_CHECK( i2 < i1 );
91     BOOST_CHECK( i1 >= i2 );
92     BOOST_CHECK( i2 <= i1 );
93     BOOST_CHECK( i1 == TestInt(8) );
94     BOOST_CHECK( i1 != i2 );
95
96     BOOST_CHECK_EQUAL( i1.value(), 8 );
97
98     std::stringstream ss;
99     ss << i1;
100     BOOST_CHECK_EQUAL( ss.str(), "8" );
101     ss >> i2;
102     BOOST_CHECK_EQUAL( i2, TestInt(8) );
103 }
104
105 //-/////////////////////////////////////////////////////////////////////////////////////////////////
106 #undef prefix_
107
108 \f
109 // Local Variables:
110 // mode: c++
111 // fill-column: 100
112 // comment-column: 40
113 // c-file-style: "senf"
114 // indent-tabs-mode: nil
115 // ispell-local-dictionary: "american"
116 // compile-command: "scons -u test"
117 // End: