diff options
author | Strangerke | 2013-09-08 14:49:34 +0200 |
---|---|---|
committer | Strangerke | 2013-09-08 14:49:34 +0200 |
commit | 599d2eeb06c937a4479cc751f4f9f5e94795c43b (patch) | |
tree | 6efd0f887d7a1fd5082209a585d609983031c92d /test/common/util.h | |
parent | 7df4c94aeb6c1408d26d6ada58d728b6eac17717 (diff) | |
parent | 03bf56ea82c0b89f4e61e5e0787a36473f999efa (diff) | |
download | scummvm-rg350-599d2eeb06c937a4479cc751f4f9f5e94795c43b.tar.gz scummvm-rg350-599d2eeb06c937a4479cc751f4f9f5e94795c43b.tar.bz2 scummvm-rg350-599d2eeb06c937a4479cc751f4f9f5e94795c43b.zip |
Merge branch 'master' into avalanche
Diffstat (limited to 'test/common/util.h')
-rw-r--r-- | test/common/util.h | 237 |
1 files changed, 237 insertions, 0 deletions
diff --git a/test/common/util.h b/test/common/util.h new file mode 100644 index 0000000000..cd65307612 --- /dev/null +++ b/test/common/util.h @@ -0,0 +1,237 @@ +#include <cxxtest/TestSuite.h> +#include "common/util.h" + +/** + * Test suite for the functions in common/util.h + */ +class UtilTestSuite : public CxxTest::TestSuite { + public: + void test_parsebool_yesno() { + + // First test for the parseBool function. + // These are the mixed case yes/no cases that must work + + bool valasbool; + bool success; + + Common::String string_1("Yes"); + success = Common::parseBool(string_1, valasbool); + TS_ASSERT_EQUALS(success, 1); + TS_ASSERT_EQUALS(valasbool, 1); + + Common::String string_2("nO"); + success = Common::parseBool(string_2, valasbool); + TS_ASSERT_EQUALS(success, 1); + TS_ASSERT_EQUALS(valasbool, 0); + } + + void test_parsebool_truefalse() { + + // First test for the parseBool function. + // These are the mixed case true/false cases that must work + + bool valasbool; + bool success; + + Common::String string_3("tRuE"); + success = Common::parseBool(string_3, valasbool); + TS_ASSERT_EQUALS(success, 1); + TS_ASSERT_EQUALS(valasbool, 1); + + Common::String string_4("fAlSe"); + success = Common::parseBool(string_4, valasbool); + TS_ASSERT_EQUALS(success, 1); + TS_ASSERT_EQUALS(valasbool, 0); + } + + void test_parsebool_onezero() { + + // Third test for the parseBool function. + // These are the 1/0 cases that must work. + // Note that while 'a-z'+0x20 must work just fine, + // '0-1'+0x20 should NOT; this is addressed in + // parsebool_bad + + bool valasbool; + bool success; + + Common::String string_5("1"); + success = Common::parseBool(string_5, valasbool); + TS_ASSERT_EQUALS(success, 1); + TS_ASSERT_EQUALS(valasbool, 1); + + Common::String string_6("0"); + success = Common::parseBool(string_6, valasbool); + TS_ASSERT_EQUALS(success, 1); + TS_ASSERT_EQUALS(valasbool, 0); + + } + + void test_parsebool_bad() { + + bool valasbool; + bool success; + + // Bad cases that should not return success #1: + // Random string + Common::String string_1("u_f1ght_l1k3_a_c0w"); + success = Common::parseBool(string_1, valasbool); + TS_ASSERT_EQUALS(success, 0); + + // Bad cases that should not return success #2, #3: + // The function should NOT accept trailing whitespaces: + Common::String string_2(" yes"); + success = Common::parseBool(string_2, valasbool); + TS_ASSERT_EQUALS(success, 0); + + Common::String string_3("yes "); + success = Common::parseBool(string_3, valasbool); + TS_ASSERT_EQUALS(success, 0); + + // While 'a-z'+0x20 must work just fine, + // '0-1'+0x20 should NOT. '2' is not good either. + + Common::String string_4("\x50"); + success = Common::parseBool(string_4, valasbool); + TS_ASSERT_EQUALS(success, 0); + + Common::String string_5("\x51"); + success = Common::parseBool(string_5, valasbool); + TS_ASSERT_EQUALS(success, 0); + + Common::String string_6("2"); + success = Common::parseBool(string_6, valasbool); + TS_ASSERT_EQUALS(success, 0); + } + + void test_is_al_num() { + + // Test the isAlnum function + // Should return true if and only if the input is an alphanumeric char + + TS_ASSERT_EQUALS(Common::isAlnum('a'), 1); + TS_ASSERT_EQUALS(Common::isAlnum('A'), 1); + TS_ASSERT_EQUALS(Common::isAlnum('z'), 1); + TS_ASSERT_EQUALS(Common::isAlnum('Z'), 1); + TS_ASSERT_EQUALS(Common::isAlnum('1'), 1); + TS_ASSERT_EQUALS(Common::isAlnum('0'), 1); + TS_ASSERT_EQUALS(Common::isAlnum('§'), 0); + TS_ASSERT_EQUALS(Common::isAlnum('$'), 0); + TS_ASSERT_EQUALS(Common::isAlnum(' '), 0); + TS_ASSERT_EQUALS(Common::isAlnum('\n'), 0); + TS_ASSERT_EQUALS(Common::isAlnum('\b'), 0); + TS_ASSERT_EQUALS(Common::isAlnum(0), 0); + TS_ASSERT_EQUALS(Common::isAlnum(255), 0); + + } + + void test_is_alpha() { + + // Test the isAlpha function + // Should return true if and only if the input is an alphanumeric char + + TS_ASSERT_EQUALS(Common::isAlpha('a'), 1); + TS_ASSERT_EQUALS(Common::isAlpha('A'), 1); + TS_ASSERT_EQUALS(Common::isAlpha('z'), 1); + TS_ASSERT_EQUALS(Common::isAlpha('Z'), 1); + TS_ASSERT_EQUALS(Common::isAlpha('1'), 0); + TS_ASSERT_EQUALS(Common::isAlpha('0'), 0); + TS_ASSERT_EQUALS(Common::isAlpha('§'), 0); + TS_ASSERT_EQUALS(Common::isAlpha('$'), 0); + TS_ASSERT_EQUALS(Common::isAlpha(' '), 0); + TS_ASSERT_EQUALS(Common::isAlpha('\n'), 0); + TS_ASSERT_EQUALS(Common::isAlpha('\b'), 0); + TS_ASSERT_EQUALS(Common::isAlpha(0), 0); + TS_ASSERT_EQUALS(Common::isAlpha(255), 0); + + } + + void test_is_digit() { + + // Test the isDigit function + // Should return true if and only if the input is a single digit + + TS_ASSERT_EQUALS(Common::isDigit('a'), 0); + TS_ASSERT_EQUALS(Common::isDigit('A'), 0); + TS_ASSERT_EQUALS(Common::isDigit('z'), 0); + TS_ASSERT_EQUALS(Common::isDigit('Z'), 0); + TS_ASSERT_EQUALS(Common::isDigit('1'), 1); + TS_ASSERT_EQUALS(Common::isDigit('0'), 1); + TS_ASSERT_EQUALS(Common::isDigit('§'), 0); + TS_ASSERT_EQUALS(Common::isDigit('$'), 0); + TS_ASSERT_EQUALS(Common::isDigit(' '), 0); + TS_ASSERT_EQUALS(Common::isDigit('\n'), 0); + TS_ASSERT_EQUALS(Common::isDigit('\b'), 0); + TS_ASSERT_EQUALS(Common::isDigit(0), 0); + TS_ASSERT_EQUALS(Common::isDigit(255), 0); + + } + + void test_is_lower() { + + // Test the isLower function + // Should return true if and only if the input is a lowercase char + + TS_ASSERT_EQUALS(Common::isLower('a'), 1); + TS_ASSERT_EQUALS(Common::isLower('A'), 0); + TS_ASSERT_EQUALS(Common::isLower('z'), 1); + TS_ASSERT_EQUALS(Common::isLower('Z'), 0); + TS_ASSERT_EQUALS(Common::isLower('1'), 0); + TS_ASSERT_EQUALS(Common::isLower('0'), 0); + TS_ASSERT_EQUALS(Common::isLower('§'), 0); + TS_ASSERT_EQUALS(Common::isLower('$'), 0); + TS_ASSERT_EQUALS(Common::isLower(' '), 0); + TS_ASSERT_EQUALS(Common::isLower('\n'), 0); + TS_ASSERT_EQUALS(Common::isLower('\b'), 0); + TS_ASSERT_EQUALS(Common::isLower(0), 0); + TS_ASSERT_EQUALS(Common::isLower(255), 0); + + } + + + void test_is_upper() { + + // Test the isUpper function + // Should return true if and only if the input is an uppercase char + + TS_ASSERT_EQUALS(Common::isUpper('a'), 0); + TS_ASSERT_EQUALS(Common::isUpper('A'), 1); + TS_ASSERT_EQUALS(Common::isUpper('z'), 0); + TS_ASSERT_EQUALS(Common::isUpper('Z'), 1); + TS_ASSERT_EQUALS(Common::isUpper('1'), 0); + TS_ASSERT_EQUALS(Common::isUpper('0'), 0); + TS_ASSERT_EQUALS(Common::isUpper('§'), 0); + TS_ASSERT_EQUALS(Common::isUpper('$'), 0); + TS_ASSERT_EQUALS(Common::isUpper(' '), 0); + TS_ASSERT_EQUALS(Common::isUpper('\n'), 0); + TS_ASSERT_EQUALS(Common::isUpper('\b'), 0); + TS_ASSERT_EQUALS(Common::isUpper(0), 0); + TS_ASSERT_EQUALS(Common::isUpper(255), 0); + + } + void test_is_space() { + // isSpace should return true iff the character is some kind of whitespace + // or tab character + for (int c = 0; c < 255; c++) { + if (c == ' ' || c == '\t' || + c == '\r' || c == '\n' || + c == '\v' || c == '\f') { + TS_ASSERT_EQUALS(Common::isSpace(c), 1); + } else { + TS_ASSERT_EQUALS(Common::isSpace(c), 0); + } + } + } + + void test_is_print() { + // isPrint should return true iff the input is a printable ascii char. + // That is to say, 0x20 to 0x7E. + for (int c = 0; c < 255; c++) { + if (c >= 0x20 && c <= 0x7E) { + TS_ASSERT_EQUALS(Common::isPrint(c), 1); + } else { + TS_ASSERT_EQUALS(Common::isPrint(c), 0); + } + } + } +}; |