aboutsummaryrefslogtreecommitdiff
path: root/test/common
diff options
context:
space:
mode:
Diffstat (limited to 'test/common')
-rw-r--r--test/common/hash-str.h164
-rw-r--r--test/common/huffman.h144
-rw-r--r--test/common/rendermode.h84
-rw-r--r--test/common/str.h8
-rw-r--r--test/common/util.h237
5 files changed, 637 insertions, 0 deletions
diff --git a/test/common/hash-str.h b/test/common/hash-str.h
new file mode 100644
index 0000000000..0391e7167f
--- /dev/null
+++ b/test/common/hash-str.h
@@ -0,0 +1,164 @@
+#include <cxxtest/TestSuite.h>
+#include "common/hash-str.h"
+
+/**
+ * Test suite for common/hash-str.h
+ * We test a number of case sensitive/insensitive hash and compare functions
+ * using example strings and known hashes, trying to tackle
+ * as much edge cases as possible.
+ */
+class HashStrTestSuite : public CxxTest::TestSuite {
+
+ public:
+ void test_case_sensitive_string_equal_to() {
+
+ // Name says it all.
+ // This verifies that the function returns true
+ // for exactly the same string, false for the same
+ // string in mixed case and false for some edge cases
+ // with various spacings plus one character replaced
+ // by itself+128 (if there's some processing done after
+ // conversion to 7-bit ASCII this might yield funny results).
+
+ const Common::String lower("test");
+ const Common::String lower1("test");
+ const Common::String mixed("tESt");
+ const Common::String spaced("test ");
+ const Common::String doublespaced("test ");
+ const Common::String tabbed("test\t");
+ const Common::String plus128("t\345est");
+ // 'e'+128 = 0xE5 = 0o345
+
+ Common::CaseSensitiveString_EqualTo css_et;
+ TS_ASSERT_EQUALS(css_et(lower, mixed), false);
+ TS_ASSERT_EQUALS(css_et(lower, lower1), true);
+ TS_ASSERT_EQUALS(css_et(lower, lower), true);
+
+ // Different sorts of whitespace are to be treated differently.
+ TS_ASSERT_EQUALS(css_et(lower, spaced), false);
+ TS_ASSERT_EQUALS(css_et(lower, tabbed), false);
+ TS_ASSERT_EQUALS(css_et(spaced, tabbed), false);
+ TS_ASSERT_EQUALS(css_et(spaced, doublespaced), false);
+ TS_ASSERT_EQUALS(css_et(lower, plus128), false);
+ }
+
+ void test_ignore_case_equal_to() {
+
+ // This should be probably called case_insensitive_string_equal_to
+ // or something,but it's basically the same thing as
+ // test_case_sensitive_string_equal_to, only it's case
+ // insensitive.
+
+ const Common::String lower("test");
+ const Common::String lower1("test");
+ const Common::String mixed("tESt");
+ const Common::String spaced("test ");
+ const Common::String mixedspaced("tESt ");
+ const Common::String doublespaced("test ");
+ const Common::String tabbed("test\t");
+ const Common::String plus128("t\345est");
+
+ Common::IgnoreCase_EqualTo ic_et;
+ TS_ASSERT_EQUALS(ic_et(lower, mixed), true);
+ TS_ASSERT_EQUALS(ic_et(lower, lower1), true);
+ TS_ASSERT_EQUALS(ic_et(lower, lower), true);
+ // Edge case:
+ TS_ASSERT_EQUALS(ic_et(spaced, mixedspaced), true);
+
+ // Different sorts of whitespace are to be treated differently.
+ TS_ASSERT_EQUALS(ic_et(lower, spaced), false);
+ TS_ASSERT_EQUALS(ic_et(lower, tabbed), false);
+ TS_ASSERT_EQUALS(ic_et(spaced, tabbed), false);
+ TS_ASSERT_EQUALS(ic_et(spaced, doublespaced), false);
+ TS_ASSERT_EQUALS(ic_et(lower, plus128), false);
+ }
+
+ void test_case_sensitive_string_hash() {
+
+ // Here we compute string hashes for different
+ // strings and see that the functor is case sensitive
+ // and does not ignore spaces.
+
+ const Common::String lower("test");
+ const Common::String lower1("test");
+ const Common::String mixed("tESt");
+ const Common::String spaced("test ");
+ const Common::String mixedspaced("tESt ");
+ const Common::String doublespaced("test ");
+ const Common::String tabbed("test\t");
+
+ Common::CaseSensitiveString_Hash css_h;
+ TS_ASSERT_EQUALS(css_h(lower), css_h(lower1));
+ TS_ASSERT_DIFFERS(css_h(mixed), css_h(lower));
+ TS_ASSERT_DIFFERS(css_h(spaced), css_h(lower));
+ TS_ASSERT_DIFFERS(css_h(tabbed), css_h(spaced));
+ TS_ASSERT_DIFFERS(css_h(spaced), css_h(doublespaced));
+ }
+
+ void test_ignore_case_hash() {
+ // Same as test_case_sensitive_string_hash, but case insensitive.
+ const Common::String lower("test");
+ const Common::String lower1("test");
+ const Common::String mixed("tESt");
+ const Common::String spaced("test ");
+ const Common::String mixedspaced("tESt ");
+ const Common::String doublespaced("test ");
+ const Common::String tabbed("test\t");
+
+ Common::IgnoreCase_Hash ic_h;
+ TS_ASSERT_EQUALS(ic_h(lower), ic_h(lower1));
+ TS_ASSERT_EQUALS(ic_h(mixed), ic_h(lower));
+ TS_ASSERT_EQUALS(ic_h(spaced), ic_h(mixedspaced));
+ TS_ASSERT_DIFFERS(ic_h(tabbed), ic_h(lower));
+ TS_ASSERT_DIFFERS(ic_h(spaced), ic_h(doublespaced));
+ }
+
+ void test_cpp_string_hash()
+ {
+ // We run the same tests with Hash<String>,
+ // a template specialization of Hash, also a functor.
+ // It is supposed to be case sensitive.
+
+ const Common::String lower("test");
+ const Common::String lower1("test");
+ const Common::String mixed("tESt");
+ const Common::String spaced("test ");
+ const Common::String mixedspaced("tESt ");
+ const Common::String doublespaced("test ");
+ const Common::String tabbed("test\t");
+
+ Common::Hash<Common::String> h;
+ TS_ASSERT_EQUALS(h(lower), h(lower1));
+ TS_ASSERT_DIFFERS(h(mixed), h(lower));
+ TS_ASSERT_DIFFERS(h(spaced), h(lower));
+ TS_ASSERT_DIFFERS(h(tabbed), h(spaced));
+ TS_ASSERT_DIFFERS(h(spaced), h(doublespaced));
+ }
+
+ void test_c_style_string_hash()
+ {
+ // Same as test_cpp_string_hash but with Hash<const char*>,
+ // a template specialization of Hash, also a functor,
+ // that works with C-Style strings.
+ // It is supposed to be case sensitive.
+
+ char lower[] = "test";
+ char lower1[] = "test";
+ char mixed[] = "tESt";
+ char spaced[] = "test ";
+ char mixedspaced[] = "tESt ";
+ char doublespaced[] = "test ";
+ char tabbed[] = "test\t";
+
+ Common::Hash<const char *> h;
+ TS_ASSERT_EQUALS(h(lower), h(lower1));
+ TS_ASSERT_DIFFERS(h(mixed), h(lower));
+ TS_ASSERT_DIFFERS(h(spaced), h(lower));
+ TS_ASSERT_DIFFERS(h(spaced), h(mixedspaced));
+ TS_ASSERT_DIFFERS(h(tabbed), h(spaced));
+ TS_ASSERT_DIFFERS(h(spaced), h(doublespaced));
+
+ }
+
+
+};
diff --git a/test/common/huffman.h b/test/common/huffman.h
new file mode 100644
index 0000000000..53353aaa60
--- /dev/null
+++ b/test/common/huffman.h
@@ -0,0 +1,144 @@
+#include <cxxtest/TestSuite.h>
+#include "common/huffman.h"
+#include "common/bitstream.h"
+#include "common/memstream.h"
+
+/**
+* A test suite for the Huffman decoder in common/huffman.h
+* The encoding used comes from the example on the Wikipedia page
+* for Huffman.
+* TODO: It could be improved by generating one at runtime.
+*/
+class HuffmanTestSuite : public CxxTest::TestSuite {
+ public:
+ void test_get_with_full_symbols() {
+
+ /*
+ * The class can be initialized with or without providing
+ * a max_length and a symbol table.
+ * We test with a table.
+ *
+ * Encoding (arbitrary, for testing purpouses):
+ * 0xA=010
+ * 0xB=011
+ * 0xC=11
+ * 0xD=00
+ * 0xE=10
+ */
+
+ uint32 codeCount = 5;
+ uint8 maxLength = 3;
+ const uint8 lengths[] = {3,3,2,2,2};
+ const uint32 codes[] = {0x2, 0x3, 0x3, 0x0, 0x2};
+ const uint32 symbols[] = {0xA, 0xB, 0xC, 0xD, 0xE};
+
+ Common::Huffman h(maxLength, codeCount, codes, lengths, symbols);
+
+ byte input[] = {0x4F, 0x20};
+ // Provided input...
+ uint32 expected[] = {0xA, 0xB, 0xC, 0xD, 0xE, 0xD, 0xD};
+ // ..and expected output.
+
+ /*
+ * What should be going on:
+ * 010 011 11 00 10 00 00 = A B C D E D D
+ * = 0100 1111 0010 0000 = 0x4F20
+ */
+
+ Common::MemoryReadStream ms(input, sizeof(input));
+ Common::BitStream8MSB bs(ms);
+
+ TS_ASSERT_EQUALS(h.getSymbol(bs), expected[0]);
+ TS_ASSERT_EQUALS(h.getSymbol(bs), expected[1]);
+ TS_ASSERT_EQUALS(h.getSymbol(bs), expected[2]);
+ TS_ASSERT_EQUALS(h.getSymbol(bs), expected[3]);
+ TS_ASSERT_EQUALS(h.getSymbol(bs), expected[4]);
+ TS_ASSERT_EQUALS(h.getSymbol(bs), expected[5]);
+ TS_ASSERT_EQUALS(h.getSymbol(bs), expected[6]);
+ }
+
+ void test_get_without_symbols() {
+
+ /*
+ * This is basically the same as test_get_with_full_symbols, but
+ * I only pass the minimal required arguments.
+ * Specifically, I avoid passing the symbols table, so that
+ * array indices are used instead.
+ *
+ * Encoding becomes:
+ *
+ * 0=010
+ * 1=011
+ * 2=11
+ * 3=00
+ * 4=10
+ */
+
+ uint32 codeCount = 5;
+ const uint8 lengths[] = {3,3,2,2,2};
+ const uint32 codes[] = {0x2, 0x3, 0x3, 0x0, 0x2};
+
+ Common::Huffman h(0, codeCount, codes, lengths, 0);
+
+ byte input[] = {0x4F, 0x20};
+ uint32 expected[] = {0, 1, 2, 3, 4, 3 ,3};
+
+ Common::MemoryReadStream ms(input, sizeof(input));
+ Common::BitStream8MSB bs(ms);
+
+ TS_ASSERT_EQUALS(h.getSymbol(bs), expected[0]);
+ TS_ASSERT_EQUALS(h.getSymbol(bs), expected[1]);
+ TS_ASSERT_EQUALS(h.getSymbol(bs), expected[2]);
+ TS_ASSERT_EQUALS(h.getSymbol(bs), expected[3]);
+ TS_ASSERT_EQUALS(h.getSymbol(bs), expected[4]);
+ TS_ASSERT_EQUALS(h.getSymbol(bs), expected[5]);
+ TS_ASSERT_EQUALS(h.getSymbol(bs), expected[6]);
+ }
+
+ void test_get_after_set_symbols() {
+
+ /*
+ * Another variation of test_get_with_full_symbols.
+ * I use the setSymbols method to define, a posteriori,
+ * an alphabet to be used in place of array indices.
+ * The encoding is, at first,
+ * 0=010
+ * 1=011
+ * 2=11
+ * 3=00
+ * 4=10
+ * (=array indices).
+ */
+
+ uint32 codeCount = 5;
+ const uint8 lengths[] = {3,3,2,2,2};
+ const uint32 codes[] = {0x2, 0x3, 0x3, 0x0, 0x2};
+
+ Common::Huffman h(0, codeCount, codes, lengths, 0);
+
+ const uint32 symbols[] = {0xA, 0xB, 0xC, 0xD, 0xE};
+ h.setSymbols(symbols);
+
+ byte input[] = {0x4F, 0x20};
+ uint32 expected[] = {0xA, 0xB, 0xC, 0xD, 0xE, 0xD, 0xD};
+
+ Common::MemoryReadStream ms(input, sizeof(input));
+ Common::BitStream8MSB bs(ms);
+
+ /* New symbols:
+ * A=010
+ * B=011
+ * C=11
+ * D=00
+ * E=10
+ */
+
+ TS_ASSERT_EQUALS(h.getSymbol(bs), expected[0]);
+ TS_ASSERT_EQUALS(h.getSymbol(bs), expected[1]);
+ TS_ASSERT_EQUALS(h.getSymbol(bs), expected[2]);
+ TS_ASSERT_EQUALS(h.getSymbol(bs), expected[3]);
+ TS_ASSERT_EQUALS(h.getSymbol(bs), expected[4]);
+ TS_ASSERT_EQUALS(h.getSymbol(bs), expected[5]);
+ TS_ASSERT_EQUALS(h.getSymbol(bs), expected[6]);
+ }
+};
diff --git a/test/common/rendermode.h b/test/common/rendermode.h
new file mode 100644
index 0000000000..e5e277f16b
--- /dev/null
+++ b/test/common/rendermode.h
@@ -0,0 +1,84 @@
+#include <cxxtest/TestSuite.h>
+#include "common/rendermode.h"
+#include "common/gui_options.h"
+#include "common/str.h"
+
+class RenderModeTestSuite : public CxxTest::TestSuite {
+ public:
+ void test_parse_render_mode_good() {
+ /*
+ * Tests for parseRenderMode.
+ * It takes a code (case-insensitive) and spits a RenderMode back at you.
+ * These cases should work - the inputs are standard, there's just some
+ * fun with caps being had in here.
+ */
+ TS_ASSERT_EQUALS(Common::parseRenderMode("fMTOwNs"), Common::kRenderFMTowns);
+ TS_ASSERT_EQUALS(Common::parseRenderMode("hercGrEen"), Common::kRenderHercG);
+ TS_ASSERT_EQUALS(Common::parseRenderMode("hercAmbeR"), Common::kRenderHercA);
+ TS_ASSERT_EQUALS(Common::parseRenderMode("CgA"), Common::kRenderCGA);
+ TS_ASSERT_EQUALS(Common::parseRenderMode("ega"), Common::kRenderEGA);
+ TS_ASSERT_EQUALS(Common::parseRenderMode("Vga"), Common::kRenderVGA);
+ TS_ASSERT_EQUALS(Common::parseRenderMode("AmigA"), Common::kRenderAmiga);
+ TS_ASSERT_EQUALS(Common::parseRenderMode("pc9821"), Common::kRenderPC9821);
+ TS_ASSERT_EQUALS(Common::parseRenderMode("PC9801"), Common::kRenderPC9801);
+ TS_ASSERT_EQUALS(Common::parseRenderMode("0"), Common::kRenderDefault);
+ }
+
+
+ void test_parse_render_mode_bad() {
+ /*
+ * These cases, according to the specification, should return the default.
+ * It is only mentioned that the function must be case insensitive.
+ * Whitespaces, in particular, should not be automatically trimmed.
+ */
+ TS_ASSERT_EQUALS(Common::parseRenderMode("fmtowns "), Common::kRenderDefault);
+ TS_ASSERT_EQUALS(Common::parseRenderMode("FM-TOWNS "), Common::kRenderDefault);
+ TS_ASSERT_EQUALS(Common::parseRenderMode(" cga"), Common::kRenderDefault);
+ TS_ASSERT_EQUALS(Common::parseRenderMode("\tC g A"), Common::kRenderDefault);
+ TS_ASSERT_EQUALS(Common::parseRenderMode("\t"), Common::kRenderDefault);
+ // This is the only interesting bit: if the function was really, really
+ // broken it could be tempted to test for +-0x20.
+ TS_ASSERT_EQUALS(Common::parseRenderMode("pc Y8 21 "), Common::kRenderDefault);
+ TS_ASSERT_EQUALS(Common::parseRenderMode(" PC\t9801 "), Common::kRenderDefault);
+ TS_ASSERT_EQUALS(Common::parseRenderMode("0"), Common::kRenderDefault);
+ }
+
+ void test_get_render_mode_code_back_and_forth() {
+ /*
+ * What does getRenderModeCode return?
+ * Notably, the output should not be in mixed case.
+ */
+ TS_ASSERT_SAME_DATA(Common::getRenderModeCode(Common::parseRenderMode("FMTOWNS")), "fmtowns", 7);
+ TS_ASSERT_DIFFERS(Common::getRenderModeCode(Common::parseRenderMode("FMTOWNS")), "fmtowns");
+ TS_ASSERT_SAME_DATA(Common::getRenderModeCode(Common::parseRenderMode("CGA")), "cga", 3);
+ TS_ASSERT_SAME_DATA(Common::getRenderModeCode(Common::parseRenderMode("vga")), "vga", 3);
+ TS_ASSERT_SAME_DATA(Common::getRenderModeCode(Common::parseRenderMode("Ega")), "ega", 3);
+ TS_ASSERT_SAME_DATA(Common::getRenderModeCode(Common::parseRenderMode("AmiGa")), "amiga", 5);
+ TS_ASSERT_SAME_DATA(Common::getRenderModeCode(Common::parseRenderMode("PC9821")), "pc9821", 6);
+ TS_ASSERT_SAME_DATA(Common::getRenderModeCode(Common::parseRenderMode("PC9801")), "pc9801", 6);
+ // Slightly more interesting:
+ // Make sure that we get a null pointer for 0 (and not the "0" string or stuff)
+ char *null_p = 0;
+ TS_ASSERT_EQUALS(Common::getRenderModeCode(Common::kRenderDefault), null_p);
+ }
+
+ void test_render_2_guio() {
+ /*
+ * Verify that a rendermode is taken and the corresponding
+ * GUIO_xxxxx is returned.
+ */
+ TS_ASSERT_EQUALS(Common::renderMode2GUIO(Common::kRenderHercG), GUIO_RENDERHERCGREEN);
+ TS_ASSERT_EQUALS(Common::renderMode2GUIO(Common::kRenderHercA), GUIO_RENDERHERCAMBER);
+ TS_ASSERT_EQUALS(Common::renderMode2GUIO(Common::kRenderCGA), GUIO_RENDERCGA);
+ TS_ASSERT_EQUALS(Common::renderMode2GUIO(Common::kRenderEGA), GUIO_RENDEREGA);
+ TS_ASSERT_EQUALS(Common::renderMode2GUIO(Common::kRenderVGA), GUIO_RENDERVGA);
+ TS_ASSERT_EQUALS(Common::renderMode2GUIO(Common::kRenderAmiga), GUIO_RENDERAMIGA);
+ TS_ASSERT_EQUALS(Common::renderMode2GUIO(Common::kRenderFMTowns), GUIO_RENDERFMTOWNS);
+ TS_ASSERT_EQUALS(Common::renderMode2GUIO(Common::kRenderPC9821), GUIO_RENDERPC9821);
+ TS_ASSERT_EQUALS(Common::renderMode2GUIO(Common::kRenderPC9801), GUIO_RENDERPC9801);
+ // renderMode2GUIO is supposed to return an empty string
+ // if given kRenderDefault as an argument
+ Common::String empty;
+ TS_ASSERT_EQUALS(Common::renderMode2GUIO(Common::kRenderDefault), empty);
+ }
+};
diff --git a/test/common/str.h b/test/common/str.h
index 2c563f3132..adc6a099e4 100644
--- a/test/common/str.h
+++ b/test/common/str.h
@@ -243,6 +243,14 @@ class StringTestSuite : public CxxTest::TestSuite
TS_ASSERT_EQUALS(str, "012345678923456789012345678901");
}
+ void test_erase() {
+ Common::String str("01234567890123456789012345678901");
+ str.erase(18);
+ TS_ASSERT_EQUALS(str, "012345678901234567");
+ str.erase(7, 5);
+ TS_ASSERT_EQUALS(str, "0123456234567");
+ }
+
void test_sharing() {
Common::String str("01234567890123456789012345678901");
Common::String str2(str);
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);
+ }
+ }
+ }
+};