| 1 | /* |
| 2 | The software in this package is distributed under the GNU General |
| 3 | Public License version 2 (with a special exception described below). |
| 4 | |
| 5 | A copy of GNU General Public License (GPL) is included in this distribution, |
| 6 | in the file COPYING.GPL. |
| 7 | |
| 8 | As a special exception, if other files instantiate templates or use macros |
| 9 | or inline functions from this file, or you compile this file and link it |
| 10 | with other works to produce a work based on this file, this file |
| 11 | does not by itself cause the resulting work to be covered |
| 12 | by the GNU General Public License. |
| 13 | |
| 14 | However the source code for this file must still be made available |
| 15 | in accordance with section (3) of the GNU General Public License. |
| 16 | |
| 17 | This exception does not invalidate any other reasons why a work based |
| 18 | on 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 | |
| 44 | using namespace I2n; |
| 45 | using namespace std; |
| 46 | |
| 47 | class TestTriboolFixture |
| 48 | { |
| 49 | public: |
| 50 | TestTriboolFixture() |
| 51 | { |
| 52 | } |
| 53 | |
| 54 | ~TestTriboolFixture() |
| 55 | { |
| 56 | } |
| 57 | }; |
| 58 | |
| 59 | BOOST_FIXTURE_TEST_SUITE(TestTriool, TestTriboolFixture) |
| 60 | |
| 61 | BOOST_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 | |
| 71 | BOOST_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 | |
| 81 | BOOST_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 | |
| 91 | BOOST_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 | |
| 101 | BOOST_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 | |
| 111 | BOOST_AUTO_TEST_CASE(IsExact1) |
| 112 | { |
| 113 | Tribool a=Tribool::False; |
| 114 | |
| 115 | BOOST_CHECK_EQUAL(a.is_exact(false),true); |
| 116 | } |
| 117 | |
| 118 | BOOST_AUTO_TEST_CASE(IsExact2) |
| 119 | { |
| 120 | Tribool a=Tribool::True; |
| 121 | |
| 122 | BOOST_CHECK_EQUAL(a.is_exact(true),true); |
| 123 | } |
| 124 | |
| 125 | BOOST_AUTO_TEST_CASE(IsExact3) |
| 126 | { |
| 127 | Tribool a=Tribool::True; |
| 128 | |
| 129 | BOOST_CHECK_EQUAL(a.is_exact(false),false); |
| 130 | } |
| 131 | |
| 132 | BOOST_AUTO_TEST_CASE(IsExact4) |
| 133 | { |
| 134 | Tribool a=Tribool::Undef; |
| 135 | |
| 136 | BOOST_CHECK_EQUAL(a.is_exact(false),false); |
| 137 | } |
| 138 | |
| 139 | BOOST_AUTO_TEST_CASE(IsExact5) |
| 140 | { |
| 141 | Tribool a=Tribool::Undef; |
| 142 | |
| 143 | BOOST_CHECK_EQUAL(a.is_exact(true),false); |
| 144 | } |
| 145 | |
| 146 | BOOST_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 | |
| 159 | BOOST_AUTO_TEST_SUITE_END() |