]>
Commit | Line | Data |
---|---|---|
f5bffbd5 | 1 | #include "config.h" |
e1f7507e | 2 | |
c21ad0f5 | 3 | #include "testString.h" |
e1f7507e AJ |
4 | #include "SquidString.h" |
5 | #include "Mem.h" | |
6 | #include "event.h" | |
c21ad0f5 | 7 | |
8 | CPPUNIT_TEST_SUITE_REGISTRATION( testString ); | |
9 | ||
10 | /* let this test link sanely */ | |
11 | void | |
12 | eventAdd(const char *name, EVH * func, void *arg, double when, int, bool cbdata) | |
13 | {} | |
14 | ||
15 | /* init memory pools */ | |
16 | ||
16555581 | 17 | void |
18 | testString::setUp() | |
c21ad0f5 | 19 | { |
16555581 | 20 | Mem::Init(); |
21 | } | |
c21ad0f5 | 22 | |
23 | void | |
24 | testString::testCmpDefault() | |
25 | { | |
30abd221 | 26 | String left, right; |
c21ad0f5 | 27 | /* two default strings are equal */ |
30abd221 | 28 | CPPUNIT_ASSERT(!left.cmp(right)); |
29 | CPPUNIT_ASSERT(!left.cmp(NULL)); | |
30 | CPPUNIT_ASSERT(!left.cmp(NULL, 1)); | |
c21ad0f5 | 31 | } |
32 | ||
33 | void | |
34 | testString::testCmpEmptyString() | |
35 | { | |
30abd221 | 36 | String left(""); |
37 | String right; | |
c21ad0f5 | 38 | /* an empty string ("") is equal to a default string */ |
30abd221 | 39 | CPPUNIT_ASSERT(!left.cmp(right)); |
40 | CPPUNIT_ASSERT(!left.cmp(NULL)); | |
41 | CPPUNIT_ASSERT(!left.cmp(NULL, 1)); | |
c21ad0f5 | 42 | /* reverse the order to catch corners */ |
30abd221 | 43 | CPPUNIT_ASSERT(!right.cmp(left)); |
44 | CPPUNIT_ASSERT(!right.cmp("")); | |
45 | CPPUNIT_ASSERT(!right.cmp("", 1)); | |
c21ad0f5 | 46 | } |
47 | ||
48 | void | |
49 | testString::testCmpNotEmptyDefault() | |
50 | { | |
30abd221 | 51 | String left("foo"); |
52 | String right; | |
c21ad0f5 | 53 | /* empty string sorts before everything */ |
30abd221 | 54 | CPPUNIT_ASSERT(left.cmp(right) > 0); |
55 | CPPUNIT_ASSERT(left.cmp(NULL) > 0); | |
56 | CPPUNIT_ASSERT(left.cmp(NULL, 1) > 0); | |
c21ad0f5 | 57 | /* reverse for symmetry tests */ |
30abd221 | 58 | CPPUNIT_ASSERT(right.cmp(left) < 0); |
59 | CPPUNIT_ASSERT(right.cmp("foo") < 0); | |
60 | CPPUNIT_ASSERT(right.cmp("foo", 1) < 0); | |
c21ad0f5 | 61 | } |
9b558d8a FC |
62 | |
63 | void testString::testSubstr() | |
64 | { | |
65 | String s("0123456789"); | |
66 | String check=s.substr(3,5); | |
67 | String ref("34"); | |
68 | CPPUNIT_ASSERT(s1 == ref); | |
69 | } |