Change policy about how we handle generated files
[amule.git] / unittests / tests / StringFunctionsTest.cpp
blobc2d7b5a249f8212a8d462ec85a3baa3cd1cf12fa
1 #include <muleunit/test.h>
2 #include <common/StringFunctions.h>
4 using namespace muleunit;
6 DECLARE_SIMPLE(StringFunctions)
9 ///////////////////////////////////////////////////////////
10 // Tests for the FuzzyStrCmp function
12 //! Returns the number of items in an array.
13 #define itemsof(x) (sizeof(x)/sizeof(x[0]))
15 TEST(StringFunctions, FuzzyStrCmp)
17 struct FuzzyTest {
18 const wxChar* a;
19 const wxChar* b;
20 int expected;
23 FuzzyTest checks[] = {
24 { wxT("a (10)"), wxT("a (2)"), 1},
25 { wxT("a (10)"), wxT("b (2)"), -1},
26 { wxT("c3 (7)"), wxT("c3 (12)"), -1},
27 { wxT("c3 (12)"), wxT("c3 (7)"), 1},
28 { wxT("c3 12d"), wxT("c3 12d"), 0},
29 { wxT("a (10) "), wxT("a (2) "), 1},
30 { wxT("a (10) "), wxT("b (2) "), -1},
31 { wxT(" c3 (7)"), wxT(" c3 (12)"), -1},
32 { wxT(" c3 (12)"), wxT(" c3 (7)"), 1},
33 { wxT("c3 12d"), wxT("c3 12d"), 0},
34 { wxT(""), wxT(""), 0},
35 { wxT(""), wxT("c3 12d"), -1},
36 { wxT("c3 12d"), wxT(""), 1},
37 { wxT(" "), wxT("c3 12d"), -1},
38 { wxT("c3 12d"), wxT(" "), 1},
39 { wxT("17.10"), wxT("17.2"), 1},
40 { wxT(" c3 (a)"), wxT(" c3 (12)"), 1},
41 { wxT(" c3 (12)"), wxT(" c3 (a)"), -1},
44 for (size_t i = 0; i < itemsof(checks); ++i) {
45 wxString a = checks[i].a;
46 wxString b = checks[i].b;
48 ASSERT_EQUALS(checks[i].expected, FuzzyStrCmp(a, b));
53 ///////////////////////////////////////////////////////////
54 // Tests for the CSimpleParser class
56 DECLARE_SIMPLE(SimpleParser)
59 TEST(SimpleParser, Constructor)
61 // Empty strings are acceptable and should just return an empty string
63 CSimpleTokenizer tkz1(wxEmptyString, wxT('-'));
64 ASSERT_EQUALS(wxT(""), tkz1.remaining());
65 ASSERT_EQUALS(wxEmptyString, tkz1.next());
66 ASSERT_EQUALS(wxT(""), tkz1.remaining());
67 ASSERT_EQUALS(wxEmptyString, tkz1.next());
70 // String with no tokens should be return immediatly
72 CSimpleTokenizer tkz2(wxT(" abc "), wxT('-'));
73 ASSERT_EQUALS(wxT(" abc "), tkz2.remaining());
74 ASSERT_EQUALS(wxT(" abc "), tkz2.next());
75 ASSERT_EQUALS(wxEmptyString, tkz2.next());
76 ASSERT_EQUALS(wxEmptyString, tkz2.next());
81 TEST(SimpleParser, EmptyTokens)
84 CSimpleTokenizer tkz1(wxT(" a"), wxT(' '));
85 ASSERT_EQUALS(wxT(" a"), tkz1.remaining());
86 ASSERT_EQUALS(0u, tkz1.tokenCount());
88 ASSERT_EQUALS(wxEmptyString, tkz1.next());
89 ASSERT_EQUALS(wxT("a"), tkz1.remaining());
90 ASSERT_EQUALS(1u, tkz1.tokenCount());
92 ASSERT_EQUALS(wxT("a"), tkz1.next());
93 ASSERT_EQUALS(wxT(""), tkz1.remaining());
94 ASSERT_EQUALS(1u, tkz1.tokenCount());
96 ASSERT_EQUALS(wxEmptyString, tkz1.next());
97 ASSERT_EQUALS(wxT(""), tkz1.remaining());
98 ASSERT_EQUALS(1u, tkz1.tokenCount());
102 CSimpleTokenizer tkz2(wxT("c "), wxT(' '));
103 ASSERT_EQUALS(wxT("c "), tkz2.remaining());
104 ASSERT_EQUALS(0u, tkz2.tokenCount());
106 ASSERT_EQUALS(wxT("c"), tkz2.next());
107 ASSERT_EQUALS(wxT(""), tkz2.remaining());
108 ASSERT_EQUALS(1u, tkz2.tokenCount());
110 ASSERT_EQUALS(wxEmptyString, tkz2.next());
111 ASSERT_EQUALS(wxT(""), tkz2.remaining());
112 ASSERT_EQUALS(1u, tkz2.tokenCount());
114 ASSERT_EQUALS(wxEmptyString, tkz2.next());
115 ASSERT_EQUALS(wxT(""), tkz2.remaining());
116 ASSERT_EQUALS(1u, tkz2.tokenCount());
120 CSimpleTokenizer tkz3(wxT(" a c "), wxT(' '));
121 ASSERT_EQUALS(wxT(" a c "), tkz3.remaining());
122 ASSERT_EQUALS(0u, tkz3.tokenCount());
124 ASSERT_EQUALS(wxEmptyString, tkz3.next());
125 ASSERT_EQUALS(wxT("a c "), tkz3.remaining());
126 ASSERT_EQUALS(1u, tkz3.tokenCount());
128 ASSERT_EQUALS(wxT("a"), tkz3.next());
129 ASSERT_EQUALS(wxT("c "), tkz3.remaining());
130 ASSERT_EQUALS(2u, tkz3.tokenCount());
132 ASSERT_EQUALS(wxT("c"), tkz3.next());
133 ASSERT_EQUALS(wxT(""), tkz3.remaining());
134 ASSERT_EQUALS(3u, tkz3.tokenCount());
136 ASSERT_EQUALS(wxEmptyString, tkz3.next());
137 ASSERT_EQUALS(wxT(""), tkz3.remaining());
138 ASSERT_EQUALS(3u, tkz3.tokenCount());
140 ASSERT_EQUALS(wxEmptyString, tkz3.next());
141 ASSERT_EQUALS(wxT(""), tkz3.remaining());
142 ASSERT_EQUALS(3u, tkz3.tokenCount());
147 TEST(SimpleParser, NormalTokens)
149 CSimpleTokenizer tkz(wxT("a c"), wxT(' '));
150 ASSERT_EQUALS(wxT("a c"), tkz.remaining());
151 ASSERT_EQUALS(0u, tkz.tokenCount());
153 ASSERT_EQUALS(wxT("a"), tkz.next());
154 ASSERT_EQUALS(wxT("c"), tkz.remaining());
155 ASSERT_EQUALS(1u, tkz.tokenCount());
157 ASSERT_EQUALS(wxT("c"), tkz.next());
158 ASSERT_EQUALS(wxT(""), tkz.remaining());
159 ASSERT_EQUALS(1u, tkz.tokenCount());
161 ASSERT_EQUALS(wxEmptyString, tkz.next());
162 ASSERT_EQUALS(wxT(""), tkz.remaining());
163 ASSERT_EQUALS(1u, tkz.tokenCount());
165 ASSERT_EQUALS(wxEmptyString, tkz.next());
166 ASSERT_EQUALS(wxT(""), tkz.remaining());
167 ASSERT_EQUALS(1u, tkz.tokenCount());