]>
Commit | Line | Data |
---|---|---|
4e0938ef | 1 | /* |
bde978a6 | 2 | * Copyright (C) 1996-2015 The Squid Software Foundation and contributors |
4e0938ef AJ |
3 | * |
4 | * Squid software is distributed under GPLv2+ license and includes | |
5 | * contributions from numerous individuals and organizations. | |
6 | * Please see the COPYING and CONTRIBUTORS files for details. | |
7 | */ | |
8 | ||
3d41e53a | 9 | #include "squid.h" |
e1f7507e | 10 | #include "event.h" |
602d9612 A |
11 | #include "SquidString.h" |
12 | #include "testString.h" | |
7f861c77 AJ |
13 | #include "unitTestMain.h" |
14 | ||
c21ad0f5 | 15 | CPPUNIT_TEST_SUITE_REGISTRATION( testString ); |
16 | ||
17 | /* let this test link sanely */ | |
18 | void | |
19 | eventAdd(const char *name, EVH * func, void *arg, double when, int, bool cbdata) | |
20 | {} | |
21 | ||
22 | /* init memory pools */ | |
23 | ||
16555581 | 24 | void |
25 | testString::setUp() | |
c21ad0f5 | 26 | { |
16555581 | 27 | Mem::Init(); |
28 | } | |
c21ad0f5 | 29 | |
30 | void | |
31 | testString::testCmpDefault() | |
32 | { | |
30abd221 | 33 | String left, right; |
c21ad0f5 | 34 | /* two default strings are equal */ |
30abd221 | 35 | CPPUNIT_ASSERT(!left.cmp(right)); |
36 | CPPUNIT_ASSERT(!left.cmp(NULL)); | |
37 | CPPUNIT_ASSERT(!left.cmp(NULL, 1)); | |
c21ad0f5 | 38 | } |
39 | ||
40 | void | |
41 | testString::testCmpEmptyString() | |
42 | { | |
30abd221 | 43 | String left(""); |
44 | String right; | |
c21ad0f5 | 45 | /* an empty string ("") is equal to a default string */ |
30abd221 | 46 | CPPUNIT_ASSERT(!left.cmp(right)); |
47 | CPPUNIT_ASSERT(!left.cmp(NULL)); | |
48 | CPPUNIT_ASSERT(!left.cmp(NULL, 1)); | |
c21ad0f5 | 49 | /* reverse the order to catch corners */ |
30abd221 | 50 | CPPUNIT_ASSERT(!right.cmp(left)); |
51 | CPPUNIT_ASSERT(!right.cmp("")); | |
52 | CPPUNIT_ASSERT(!right.cmp("", 1)); | |
c21ad0f5 | 53 | } |
54 | ||
55 | void | |
56 | testString::testCmpNotEmptyDefault() | |
57 | { | |
30abd221 | 58 | String left("foo"); |
59 | String right; | |
c21ad0f5 | 60 | /* empty string sorts before everything */ |
30abd221 | 61 | CPPUNIT_ASSERT(left.cmp(right) > 0); |
62 | CPPUNIT_ASSERT(left.cmp(NULL) > 0); | |
63 | CPPUNIT_ASSERT(left.cmp(NULL, 1) > 0); | |
c21ad0f5 | 64 | /* reverse for symmetry tests */ |
30abd221 | 65 | CPPUNIT_ASSERT(right.cmp(left) < 0); |
66 | CPPUNIT_ASSERT(right.cmp("foo") < 0); | |
67 | CPPUNIT_ASSERT(right.cmp("foo", 1) < 0); | |
c21ad0f5 | 68 | } |
9b558d8a FC |
69 | |
70 | void testString::testSubstr() | |
71 | { | |
72 | String s("0123456789"); | |
73 | String check=s.substr(3,5); | |
74 | String ref("34"); | |
696a257c | 75 | CPPUNIT_ASSERT(check == ref); |
9b558d8a | 76 | } |
f53969cc | 77 |