Fixed: Tests for fromStringwith a boolean

This commit is contained in:
kervala 2016-02-02 11:38:08 +01:00
parent 54001f553d
commit e77a8b17b7

View file

@ -682,60 +682,59 @@ struct CUTMiscStringCommon : public Test::Suite
// tests for bool // tests for bool
bool val; bool val;
// true value // true values
val = false;
ret = NLMISC::fromString("1", val); ret = NLMISC::fromString("1", val);
TEST_ASSERT(val); TEST_ASSERT(ret && val);
TEST_ASSERT_MSG(ret, "should succeed");
val = false; ret = NLMISC::fromString("t", val);
NLMISC::fromString("t", val); TEST_ASSERT(ret && val);
TEST_ASSERT(val);
val = false; ret = NLMISC::fromString("y", val);
NLMISC::fromString("y", val); TEST_ASSERT(ret && val);
TEST_ASSERT(val);
val = false; ret = NLMISC::fromString("T", val);
NLMISC::fromString("T", val); TEST_ASSERT(ret && val);
TEST_ASSERT(val);
val = false; ret = NLMISC::fromString("Y", val);
NLMISC::fromString("Y", val); TEST_ASSERT(ret && val);
TEST_ASSERT(val);
val = true; ret = NLMISC::fromString("true", val);
TEST_ASSERT(ret && val);
ret = NLMISC::fromString("yes", val);
TEST_ASSERT(ret && val);
// false values
ret = NLMISC::fromString("0", val); ret = NLMISC::fromString("0", val);
TEST_ASSERT(!val); TEST_ASSERT(ret && !val);
TEST_ASSERT_MSG(ret, "should succeed");
val = true; ret = NLMISC::fromString("f", val);
NLMISC::fromString("f", val); TEST_ASSERT(ret && !val);
TEST_ASSERT(!val);
val = true; ret = NLMISC::fromString("n", val);
NLMISC::fromString("n", val); TEST_ASSERT(ret && !val);
TEST_ASSERT(!val);
val = true; ret = NLMISC::fromString("F", val);
NLMISC::fromString("F", val); TEST_ASSERT(ret && !val);
TEST_ASSERT(!val);
val = true; ret = NLMISC::fromString("N", val);
NLMISC::fromString("N", val); TEST_ASSERT(ret && !val);
TEST_ASSERT(!val);
ret = NLMISC::fromString("false", val);
TEST_ASSERT(ret && !val);
ret = NLMISC::fromString("no", val);
TEST_ASSERT(ret && !val);
// wrong values
ret = NLMISC::fromString("YES", val);
TEST_ASSERT(!ret && !val);
ret = NLMISC::fromString("foo", val);
TEST_ASSERT(!ret && !val);
// bad character
ret = NLMISC::fromString("a", val); ret = NLMISC::fromString("a", val);
TEST_ASSERT_MSG(!ret, "should not succeed"); TEST_ASSERT(!ret && !val);
val = true;
NLMISC::fromString("a", val);
TEST_ASSERT_MSG(val, "should not modify the value");
val = false;
NLMISC::fromString("a", val);
TEST_ASSERT_MSG(!val, "should not modify the value");
} }
}; };