|
|
@ -443,11 +443,13 @@ struct CUTMiscStringCommon : public Test::Suite
|
|
|
|
|
|
|
|
|
|
|
|
// min limit -1
|
|
|
|
// min limit -1
|
|
|
|
ret = NLMISC::fromString("-9223372036854775809", val);
|
|
|
|
ret = NLMISC::fromString("-9223372036854775809", val);
|
|
|
|
TEST_ASSERT(!ret && val == 0);
|
|
|
|
TEST_ASSERT_MSG(ret, "should succeed");
|
|
|
|
|
|
|
|
TEST_ASSERT(LLONG_MIN == val);
|
|
|
|
|
|
|
|
|
|
|
|
// max limit +1
|
|
|
|
// max limit +1
|
|
|
|
ret = NLMISC::fromString("9223372036854775808", val);
|
|
|
|
ret = NLMISC::fromString("9223372036854775808", val);
|
|
|
|
TEST_ASSERT(!ret && val == 0);
|
|
|
|
TEST_ASSERT_MSG(ret, "should succeed");
|
|
|
|
|
|
|
|
TEST_ASSERT(LLONG_MAX == val);
|
|
|
|
|
|
|
|
|
|
|
|
// with period
|
|
|
|
// with period
|
|
|
|
ret = NLMISC::fromString("1.2", val);
|
|
|
|
ret = NLMISC::fromString("1.2", val);
|
|
|
@ -498,16 +500,19 @@ struct CUTMiscStringCommon : public Test::Suite
|
|
|
|
TEST_ASSERT(ret && val == 0);
|
|
|
|
TEST_ASSERT(ret && val == 0);
|
|
|
|
|
|
|
|
|
|
|
|
// max limit
|
|
|
|
// max limit
|
|
|
|
ret = NLMISC::fromString("4294967295", val);
|
|
|
|
ret = NLMISC::fromString("18446744073709551615", val);
|
|
|
|
TEST_ASSERT(ret && val == 4294967295);
|
|
|
|
TEST_ASSERT_MSG(ret, "should succeed");
|
|
|
|
|
|
|
|
TEST_ASSERT(ULLONG_MAX == val);
|
|
|
|
|
|
|
|
|
|
|
|
// min limit -1
|
|
|
|
// min limit -1
|
|
|
|
ret = NLMISC::fromString("-1", val);
|
|
|
|
ret = NLMISC::fromString("-1", val);
|
|
|
|
TEST_ASSERT(!ret && val == 0);
|
|
|
|
TEST_ASSERT_MSG(ret, "should succeed");
|
|
|
|
|
|
|
|
TEST_ASSERT(ULLONG_MAX == val);
|
|
|
|
|
|
|
|
|
|
|
|
// max limit +1
|
|
|
|
// max limit +1
|
|
|
|
ret = NLMISC::fromString("4294967296", val);
|
|
|
|
ret = NLMISC::fromString("18446744073709551616", val);
|
|
|
|
TEST_ASSERT(!ret && val == 0);
|
|
|
|
TEST_ASSERT_MSG(ret, "should succeed");
|
|
|
|
|
|
|
|
TEST_ASSERT(ULLONG_MAX == val);
|
|
|
|
|
|
|
|
|
|
|
|
// with period
|
|
|
|
// with period
|
|
|
|
ret = NLMISC::fromString("1.2", val);
|
|
|
|
ret = NLMISC::fromString("1.2", val);
|
|
|
@ -559,23 +564,28 @@ struct CUTMiscStringCommon : public Test::Suite
|
|
|
|
|
|
|
|
|
|
|
|
// min limit
|
|
|
|
// min limit
|
|
|
|
ret = NLMISC::fromString("-2147483648", val);
|
|
|
|
ret = NLMISC::fromString("-2147483648", val);
|
|
|
|
TEST_ASSERT(ret && val == INT_MIN);
|
|
|
|
TEST_ASSERT_MSG(ret, "should succeed");
|
|
|
|
|
|
|
|
TEST_ASSERT(INT_MIN == val);
|
|
|
|
|
|
|
|
|
|
|
|
// max limit
|
|
|
|
// max limit
|
|
|
|
ret = NLMISC::fromString("2147483647", val);
|
|
|
|
ret = NLMISC::fromString("2147483647", val);
|
|
|
|
TEST_ASSERT(ret && val == INT_MAX);
|
|
|
|
TEST_ASSERT_MSG(ret, "should succeed");
|
|
|
|
|
|
|
|
TEST_ASSERT(INT_MAX == val);
|
|
|
|
|
|
|
|
|
|
|
|
// min limit -1
|
|
|
|
// min limit -1
|
|
|
|
ret = NLMISC::fromString("-2147483649", val);
|
|
|
|
ret = NLMISC::fromString("-2147483649", val);
|
|
|
|
TEST_ASSERT(!ret && val == 0);
|
|
|
|
TEST_ASSERT_MSG(ret, "should succeed");
|
|
|
|
|
|
|
|
TEST_ASSERT(INT_MIN == val);
|
|
|
|
|
|
|
|
|
|
|
|
// max limit +1
|
|
|
|
// max limit +1
|
|
|
|
ret = NLMISC::fromString("2147483648", val);
|
|
|
|
ret = NLMISC::fromString("2147483648", val);
|
|
|
|
TEST_ASSERT(!ret && val == 0);
|
|
|
|
TEST_ASSERT_MSG(ret, "should succeed");
|
|
|
|
|
|
|
|
TEST_ASSERT(INT_MAX == val);
|
|
|
|
|
|
|
|
|
|
|
|
// with period
|
|
|
|
// with period
|
|
|
|
ret = NLMISC::fromString("1.2", val);
|
|
|
|
ret = NLMISC::fromString("1.2", val);
|
|
|
|
TEST_ASSERT(ret && val == 1);
|
|
|
|
TEST_ASSERT_MSG(ret, "should succeed");
|
|
|
|
|
|
|
|
TEST_ASSERT(1.2f == val);
|
|
|
|
|
|
|
|
|
|
|
|
// with coma
|
|
|
|
// with coma
|
|
|
|
ret = NLMISC::fromString("1,2", val);
|
|
|
|
ret = NLMISC::fromString("1,2", val);
|
|
|
@ -623,19 +633,23 @@ struct CUTMiscStringCommon : public Test::Suite
|
|
|
|
|
|
|
|
|
|
|
|
// min limit
|
|
|
|
// min limit
|
|
|
|
ret = NLMISC::fromString("2.2250738585072014e-308", val);
|
|
|
|
ret = NLMISC::fromString("2.2250738585072014e-308", val);
|
|
|
|
TEST_ASSERT(ret && val == DBL_MIN);
|
|
|
|
TEST_ASSERT_MSG(ret, "should succeed");
|
|
|
|
|
|
|
|
TEST_ASSERT(DBL_MIN == val);
|
|
|
|
|
|
|
|
|
|
|
|
// max limit
|
|
|
|
// max limit
|
|
|
|
ret = NLMISC::fromString("1.7976931348623158e+308", val);
|
|
|
|
ret = NLMISC::fromString("1.7976931348623158e+308", val);
|
|
|
|
TEST_ASSERT(ret && val == DBL_MAX);
|
|
|
|
TEST_ASSERT_MSG(ret, "should succeed");
|
|
|
|
|
|
|
|
TEST_ASSERT(DBL_MAX == val);
|
|
|
|
|
|
|
|
|
|
|
|
// min limit -1
|
|
|
|
// min limit -1
|
|
|
|
ret = NLMISC::fromString("3e-408", val);
|
|
|
|
ret = NLMISC::fromString("3e-408", val);
|
|
|
|
TEST_ASSERT(!ret && val == 0.0);
|
|
|
|
TEST_ASSERT_MSG(ret, "should succeed");
|
|
|
|
|
|
|
|
TEST_ASSERT(0 == val);
|
|
|
|
|
|
|
|
|
|
|
|
// max limit +1
|
|
|
|
// max limit +1
|
|
|
|
ret = NLMISC::fromString("2e+308", val);
|
|
|
|
ret = NLMISC::fromString("2e+308", val);
|
|
|
|
TEST_ASSERT(!ret && val == 0.0);
|
|
|
|
TEST_ASSERT_MSG(ret, "should succeed");
|
|
|
|
|
|
|
|
TEST_ASSERT(INFINITY == val);
|
|
|
|
|
|
|
|
|
|
|
|
// with period
|
|
|
|
// with period
|
|
|
|
ret = NLMISC::fromString("1.2", val);
|
|
|
|
ret = NLMISC::fromString("1.2", val);
|
|
|
@ -670,60 +684,59 @@ struct CUTMiscStringCommon : public Test::Suite
|
|
|
|
bool val;
|
|
|
|
bool val;
|
|
|
|
|
|
|
|
|
|
|
|
// true value
|
|
|
|
// true value
|
|
|
|
|
|
|
|
val = false;
|
|
|
|
ret = NLMISC::fromString("1", val);
|
|
|
|
ret = NLMISC::fromString("1", val);
|
|
|
|
TEST_ASSERT(ret && val);
|
|
|
|
TEST_ASSERT(val);
|
|
|
|
|
|
|
|
TEST_ASSERT_MSG(ret, "should succeed");
|
|
|
|
|
|
|
|
|
|
|
|
// false value
|
|
|
|
val = false;
|
|
|
|
ret = NLMISC::fromString("0", val);
|
|
|
|
NLMISC::fromString("t", val);
|
|
|
|
TEST_ASSERT(ret && !val);
|
|
|
|
TEST_ASSERT(val);
|
|
|
|
|
|
|
|
|
|
|
|
// bad character
|
|
|
|
val = false;
|
|
|
|
ret = NLMISC::fromString("a", val);
|
|
|
|
NLMISC::fromString("y", val);
|
|
|
|
TEST_ASSERT(!ret && val);
|
|
|
|
TEST_ASSERT(val);
|
|
|
|
|
|
|
|
|
|
|
|
// right character and bad character
|
|
|
|
val = false;
|
|
|
|
ret = NLMISC::fromString("1a", val);
|
|
|
|
NLMISC::fromString("T", val);
|
|
|
|
TEST_ASSERT(!ret && val);
|
|
|
|
TEST_ASSERT(val);
|
|
|
|
|
|
|
|
|
|
|
|
// min limit
|
|
|
|
val = false;
|
|
|
|
ret = NLMISC::fromString("-2147483648", val);
|
|
|
|
NLMISC::fromString("Y", val);
|
|
|
|
TEST_ASSERT(!ret && val);
|
|
|
|
TEST_ASSERT(val);
|
|
|
|
|
|
|
|
|
|
|
|
// max limit
|
|
|
|
val = true;
|
|
|
|
ret = NLMISC::fromString("2147483647", val);
|
|
|
|
ret = NLMISC::fromString("0", val);
|
|
|
|
TEST_ASSERT(!ret && val);
|
|
|
|
TEST_ASSERT(!val);
|
|
|
|
|
|
|
|
TEST_ASSERT_MSG(ret, "should succeed");
|
|
|
|
// min limit -1
|
|
|
|
|
|
|
|
ret = NLMISC::fromString("-2147483649", val);
|
|
|
|
|
|
|
|
TEST_ASSERT(!ret && val);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// max limit +1
|
|
|
|
val = true;
|
|
|
|
ret = NLMISC::fromString("2147483648", val);
|
|
|
|
NLMISC::fromString("f", val);
|
|
|
|
TEST_ASSERT(!ret && val);
|
|
|
|
TEST_ASSERT(!val);
|
|
|
|
|
|
|
|
|
|
|
|
// with period
|
|
|
|
val = true;
|
|
|
|
ret = NLMISC::fromString("1.2", val);
|
|
|
|
NLMISC::fromString("n", val);
|
|
|
|
TEST_ASSERT(!ret && val);
|
|
|
|
TEST_ASSERT(!val);
|
|
|
|
|
|
|
|
|
|
|
|
// with coma
|
|
|
|
val = true;
|
|
|
|
ret = NLMISC::fromString("1,2", val);
|
|
|
|
NLMISC::fromString("F", val);
|
|
|
|
TEST_ASSERT(!ret && val);
|
|
|
|
TEST_ASSERT(!val);
|
|
|
|
|
|
|
|
|
|
|
|
// with spaces before
|
|
|
|
val = true;
|
|
|
|
ret = NLMISC::fromString(" 10", val);
|
|
|
|
NLMISC::fromString("N", val);
|
|
|
|
TEST_ASSERT(!ret && val);
|
|
|
|
TEST_ASSERT(!val);
|
|
|
|
|
|
|
|
|
|
|
|
// with spaces after
|
|
|
|
// bad character
|
|
|
|
ret = NLMISC::fromString("10 ", val);
|
|
|
|
ret = NLMISC::fromString("a", val);
|
|
|
|
TEST_ASSERT(!ret && val);
|
|
|
|
TEST_ASSERT_MSG(!ret, "should not succeed");
|
|
|
|
|
|
|
|
|
|
|
|
// with 0s before
|
|
|
|
val = true;
|
|
|
|
ret = NLMISC::fromString("001", val);
|
|
|
|
NLMISC::fromString("a", val);
|
|
|
|
TEST_ASSERT(!ret && val);
|
|
|
|
TEST_ASSERT_MSG(val, "should not modify the value");
|
|
|
|
|
|
|
|
|
|
|
|
// with + before
|
|
|
|
val = false;
|
|
|
|
ret = NLMISC::fromString("+1", val);
|
|
|
|
NLMISC::fromString("a", val);
|
|
|
|
TEST_ASSERT(!ret && val);
|
|
|
|
TEST_ASSERT_MSG(!val, "should not modify the value");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|