diff --git a/src/check/dt_cxxlib.cpp b/src/check/dt_cxxlib.cpp index cbba0117..0f68fea6 100644 --- a/src/check/dt_cxxlib.cpp +++ b/src/check/dt_cxxlib.cpp @@ -24,10 +24,10 @@ */ -#include "../conf.h" +// lots of tests (and probably quite a number of redundant tests) +// modern compilers will optimize away quite a lot of this code -// various cxxlib checks -// (modern compilers will optimize away much of this code) +#include "../conf.h" /************************************************************************* // compile-time checks @@ -169,6 +169,9 @@ struct TestTriBool { static_assert(sizeof(T) == sizeof(typename T::underlying_type)); static_assert(alignof(T) == alignof(typename T::underlying_type)); #endif + static_assert(!bool(T(false))); + static_assert(bool(T(true))); + static_assert(bool(T(T::Third)) == (T::Third > T::False)); static_assert(T(false) == T::False); static_assert(T(true) == T::True); static_assert(T(T::False) == T::False); @@ -188,37 +191,58 @@ struct TestTriBool { static_assert(array[2].isThird()); static_assert(sizeof(array) == 3 * sizeof(T)); T a; + CHECK(a.getValue() == T::False); CHECK(!a); + CHECK(!bool(a)); + CHECK((!a ? true : false)); CHECK(a.isStrictFalse()); CHECK(!a.isStrictTrue()); CHECK(a.isStrictBool()); CHECK(!a.isThird()); a = false; + CHECK(a.getValue() == T::False); CHECK(!a); + CHECK(!bool(a)); + CHECK((!a ? true : false)); CHECK(a.isStrictFalse()); CHECK(!a.isStrictTrue()); CHECK(a.isStrictBool()); CHECK(!a.isThird()); a = true; + CHECK(a.getValue() == T::True); CHECK(a); + CHECK(bool(a)); + CHECK((a ? true : false)); CHECK(!a.isStrictFalse()); CHECK(a.isStrictTrue()); CHECK(a.isStrictBool()); CHECK(!a.isThird()); a = T::Third; - if (expect_true) + CHECK(a.getValue() == T::Third); + if (expect_true) { CHECK(a); - else + CHECK(bool(a)); + CHECK((a ? true : false)); + } else { CHECK(!a); + CHECK(!bool(a)); + CHECK((!a ? true : false)); + } CHECK(!a.isStrictFalse()); CHECK(!a.isStrictTrue()); CHECK(!a.isStrictBool()); CHECK(a.isThird()); a = x; - if (expect_true) + CHECK(a.getValue() == T::Third); + if (expect_true) { CHECK(a); - else + CHECK(bool(a)); + CHECK((a ? true : false)); + } else { CHECK(!a); + CHECK(!bool(a)); + CHECK((!a ? true : false)); + } CHECK(!a.isStrictFalse()); CHECK(!a.isStrictTrue()); CHECK(!a.isStrictBool()); @@ -237,20 +261,20 @@ TEST_CASE("TriBool") { static_assert(!tribool(tribool::Third)); TestTriBool::test(false, -1); // - TestTriBool >::test(false, -1); - TestTriBool >::test(false, -1); - TestTriBool >::test(false, -1); - TestTriBool >::test(false, -1); + TestTriBool >::test(false, -99990); + TestTriBool >::test(false, -99991); + TestTriBool >::test(false, -99992); + TestTriBool >::test(false, -99993); // - TestTriBool >::test(true, 2); - TestTriBool >::test(true, 2); - TestTriBool >::test(true, 2); - TestTriBool >::test(true, 2); - TestTriBool >::test(true, 2); - TestTriBool >::test(true, 2); - TestTriBool >::test(true, 2); - TestTriBool >::test(true, 2); - TestTriBool >::test(true, 2); + TestTriBool >::test(true, 99); + TestTriBool >::test(true, 99990); + TestTriBool >::test(true, 99991); + TestTriBool >::test(true, 99992); + TestTriBool >::test(true, 99993); + TestTriBool >::test(true, 99994); + TestTriBool >::test(true, 99995); + TestTriBool >::test(true, 99996); + TestTriBool >::test(true, 99997); } /* vim:set ts=4 sw=4 et: */