Merge branch 'daemon-ext'
[libi2ncommon] / test / test_tribool.cpp
CommitLineData
4693e3a7
GE
1/*
2The software in this package is distributed under the GNU General
3Public License version 2 (with a special exception described below).
4
5A copy of GNU General Public License (GPL) is included in this distribution,
6in the file COPYING.GPL.
7
8As a special exception, if other files instantiate templates or use macros
9or inline functions from this file, or you compile this file and link it
10with other works to produce a work based on this file, this file
11does not by itself cause the resulting work to be covered
12by the GNU General Public License.
13
14However the source code for this file must still be made available
15in accordance with section (3) of the GNU General Public License.
16
17This exception does not invalidate any other reasons why a work based
18on this file might be covered by the GNU General Public License.
19*/
20/** @file
21 * test cases for Tribool
22 *
23 * (c) Copyright 2012 by Intra2net AG
24 */
25
26//#define NOISEDEBUG
27
28#include <string>
29#include <iostream>
30#include <sstream>
31#include <exception>
32
33#define BOOST_TEST_DYN_LINK
34#include <boost/test/unit_test.hpp>
35
36#include <tribool.hpp>
37
38#ifdef NOISEDEBUG
39#define DOUT(msg) std::cout << msg << std::endl
40#else
41#define DOUT(msg) do {} while (0)
42#endif
43
44using namespace I2n;
45using namespace std;
46
47class TestTriboolFixture
48{
49public:
50 TestTriboolFixture()
51 {
52 }
53
54 ~TestTriboolFixture()
55 {
56 }
57};
58
59BOOST_FIXTURE_TEST_SUITE(TestTriool, TestTriboolFixture)
60
61BOOST_AUTO_TEST_CASE(CompareTribool1)
62{
63 Tribool a, b;
64
65 a=Tribool::True;
66 b=Tribool::True;
67
68 BOOST_CHECK_EQUAL(a, b);
69}
70
71BOOST_AUTO_TEST_CASE(CompareTribool2)
72{
73 Tribool a, b;
74
75 a=Tribool::False;
76 b=Tribool::False;
77
78 BOOST_CHECK_EQUAL(a, b);
79}
80
81BOOST_AUTO_TEST_CASE(CompareTribool3)
82{
83 Tribool a, b;
84
85 a=Tribool::Undef;
86 b=Tribool::Undef;
87
88 BOOST_CHECK_EQUAL(a, b);
89}
90
91BOOST_AUTO_TEST_CASE(CompareTribool4)
92{
93 Tribool a, b;
94
95 a=Tribool::True;
96 b=Tribool::Undef;
97
98 BOOST_CHECK(a != b);
99}
100
101BOOST_AUTO_TEST_CASE(CompareTribool5)
102{
103 Tribool a, b;
104
105 a=Tribool::False;
106 b=Tribool::Undef;
107
108 BOOST_CHECK(a != b);
109}
110
111BOOST_AUTO_TEST_CASE(IsExact1)
112{
113 Tribool a=Tribool::False;
114
115 BOOST_CHECK_EQUAL(a.is_exact(false),true);
116}
117
118BOOST_AUTO_TEST_CASE(IsExact2)
119{
120 Tribool a=Tribool::True;
121
122 BOOST_CHECK_EQUAL(a.is_exact(true),true);
123}
124
125BOOST_AUTO_TEST_CASE(IsExact3)
126{
127 Tribool a=Tribool::True;
128
129 BOOST_CHECK_EQUAL(a.is_exact(false),false);
130}
131
132BOOST_AUTO_TEST_CASE(IsExact4)
133{
134 Tribool a=Tribool::Undef;
135
136 BOOST_CHECK_EQUAL(a.is_exact(false),false);
137}
138
139BOOST_AUTO_TEST_CASE(IsExact5)
140{
141 Tribool a=Tribool::Undef;
142
143 BOOST_CHECK_EQUAL(a.is_exact(true),false);
144}
145
146BOOST_AUTO_TEST_CASE(OStream)
147{
148 Tribool a=Tribool::True;
149 Tribool b=Tribool::False;
150 Tribool c=Tribool::Undef;
151
152 stringstream os;
153
154 os << a << b << c;
155
156 BOOST_CHECK_EQUAL(os.str(), "10?");
157}
158
159BOOST_AUTO_TEST_SUITE_END()