src: introduce type tribool
This commit is contained in:
@@ -787,4 +787,60 @@ TEST_CASE("get_ratio") {
|
||||
CHECK(get_ratio(2 * UPX_RSIZE_MAX, 1024ull * UPX_RSIZE_MAX) == 9999999);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
struct TestTriBool {
|
||||
static void test(bool expect_true, int x) noexcept {
|
||||
CHECK(T(false) == T::False);
|
||||
CHECK(T(true) == T::True);
|
||||
CHECK(T(T::Other) == T::Other);
|
||||
T a;
|
||||
CHECK(!a);
|
||||
CHECK(a.isStrictFalse());
|
||||
CHECK(!a.isStrictTrue());
|
||||
CHECK(a.isStrictBool());
|
||||
CHECK(!a.isOther());
|
||||
a = false;
|
||||
CHECK(!a);
|
||||
CHECK(a.isStrictFalse());
|
||||
CHECK(!a.isStrictTrue());
|
||||
CHECK(a.isStrictBool());
|
||||
CHECK(!a.isOther());
|
||||
a = true;
|
||||
CHECK(a);
|
||||
CHECK(!a.isStrictFalse());
|
||||
CHECK(a.isStrictTrue());
|
||||
CHECK(a.isStrictBool());
|
||||
CHECK(!a.isOther());
|
||||
a = T::Other;
|
||||
if (expect_true)
|
||||
CHECK(a);
|
||||
else
|
||||
CHECK(!a);
|
||||
CHECK(!a.isStrictFalse());
|
||||
CHECK(!a.isStrictTrue());
|
||||
CHECK(!a.isStrictBool());
|
||||
CHECK(a.isOther());
|
||||
a = x;
|
||||
if (expect_true)
|
||||
CHECK(a);
|
||||
else
|
||||
CHECK(!a);
|
||||
CHECK(!a.isStrictFalse());
|
||||
CHECK(!a.isStrictTrue());
|
||||
CHECK(!a.isStrictBool());
|
||||
CHECK(a.isOther());
|
||||
}
|
||||
};
|
||||
|
||||
TEST_CASE("TriBool") {
|
||||
TestTriBool<tribool>::test(false, -1);
|
||||
TestTriBool<TriBool<upx_int8_t> >::test(false, -1);
|
||||
TestTriBool<TriBool<upx_int64_t> >::test(false, -1);
|
||||
//
|
||||
TestTriBool<TriBool<upx_int8_t, 2> >::test(true, 2);
|
||||
TestTriBool<TriBool<upx_uint8_t, 2> >::test(true, 2);
|
||||
TestTriBool<TriBool<upx_int64_t, 2> >::test(true, 2);
|
||||
TestTriBool<TriBool<upx_uint64_t, 2> >::test(true, 2);
|
||||
}
|
||||
|
||||
/* vim:set ts=4 sw=4 et: */
|
||||
|
||||
Reference in New Issue
Block a user