From: Gerd von Egidy Date: Fri, 10 Feb 2012 10:38:36 +0000 (+0100) Subject: unit test for Tribool X-Git-Tag: v2.6~20 X-Git-Url: http://developer.intra2net.com/git/?a=commitdiff_plain;h=4693e3a7c950d3cf78435d871ad77e8a22a0b4dd;p=libi2ncommon unit test for Tribool --- diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index d1de23e..3dfa47c 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -18,6 +18,7 @@ SET(cpp_sources test_pidfile.cpp test_timefunc.cpp test_tmpfstream.cpp + test_tribool.cpp ) if (IMAP_UTF7_SUPPORT) SET(cpp_sources stringfunc_imaputf7.cpp ${cpp_sources}) diff --git a/test/test_tribool.cpp b/test/test_tribool.cpp new file mode 100644 index 0000000..bb81584 --- /dev/null +++ b/test/test_tribool.cpp @@ -0,0 +1,159 @@ +/* +The software in this package is distributed under the GNU General +Public License version 2 (with a special exception described below). + +A copy of GNU General Public License (GPL) is included in this distribution, +in the file COPYING.GPL. + +As a special exception, if other files instantiate templates or use macros +or inline functions from this file, or you compile this file and link it +with other works to produce a work based on this file, this file +does not by itself cause the resulting work to be covered +by the GNU General Public License. + +However the source code for this file must still be made available +in accordance with section (3) of the GNU General Public License. + +This exception does not invalidate any other reasons why a work based +on this file might be covered by the GNU General Public License. +*/ +/** @file + * test cases for Tribool + * + * (c) Copyright 2012 by Intra2net AG + */ + +//#define NOISEDEBUG + +#include +#include +#include +#include + +#define BOOST_TEST_DYN_LINK +#include + +#include + +#ifdef NOISEDEBUG +#define DOUT(msg) std::cout << msg << std::endl +#else +#define DOUT(msg) do {} while (0) +#endif + +using namespace I2n; +using namespace std; + +class TestTriboolFixture +{ +public: + TestTriboolFixture() + { + } + + ~TestTriboolFixture() + { + } +}; + +BOOST_FIXTURE_TEST_SUITE(TestTriool, TestTriboolFixture) + +BOOST_AUTO_TEST_CASE(CompareTribool1) +{ + Tribool a, b; + + a=Tribool::True; + b=Tribool::True; + + BOOST_CHECK_EQUAL(a, b); +} + +BOOST_AUTO_TEST_CASE(CompareTribool2) +{ + Tribool a, b; + + a=Tribool::False; + b=Tribool::False; + + BOOST_CHECK_EQUAL(a, b); +} + +BOOST_AUTO_TEST_CASE(CompareTribool3) +{ + Tribool a, b; + + a=Tribool::Undef; + b=Tribool::Undef; + + BOOST_CHECK_EQUAL(a, b); +} + +BOOST_AUTO_TEST_CASE(CompareTribool4) +{ + Tribool a, b; + + a=Tribool::True; + b=Tribool::Undef; + + BOOST_CHECK(a != b); +} + +BOOST_AUTO_TEST_CASE(CompareTribool5) +{ + Tribool a, b; + + a=Tribool::False; + b=Tribool::Undef; + + BOOST_CHECK(a != b); +} + +BOOST_AUTO_TEST_CASE(IsExact1) +{ + Tribool a=Tribool::False; + + BOOST_CHECK_EQUAL(a.is_exact(false),true); +} + +BOOST_AUTO_TEST_CASE(IsExact2) +{ + Tribool a=Tribool::True; + + BOOST_CHECK_EQUAL(a.is_exact(true),true); +} + +BOOST_AUTO_TEST_CASE(IsExact3) +{ + Tribool a=Tribool::True; + + BOOST_CHECK_EQUAL(a.is_exact(false),false); +} + +BOOST_AUTO_TEST_CASE(IsExact4) +{ + Tribool a=Tribool::Undef; + + BOOST_CHECK_EQUAL(a.is_exact(false),false); +} + +BOOST_AUTO_TEST_CASE(IsExact5) +{ + Tribool a=Tribool::Undef; + + BOOST_CHECK_EQUAL(a.is_exact(true),false); +} + +BOOST_AUTO_TEST_CASE(OStream) +{ + Tribool a=Tribool::True; + Tribool b=Tribool::False; + Tribool c=Tribool::Undef; + + stringstream os; + + os << a << b << c; + + BOOST_CHECK_EQUAL(os.str(), "10?"); +} + +BOOST_AUTO_TEST_SUITE_END()