]> git.ipfire.org Git - thirdparty/squid.git/blob - src/tests/testString.cc
Docs: Copyright updates for 2018 (#114)
[thirdparty/squid.git] / src / tests / testString.cc
1 /*
2 * Copyright (C) 1996-2018 The Squid Software Foundation and contributors
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
9 #include "squid.h"
10 #include "event.h"
11 #include "SquidString.h"
12 #include "testString.h"
13 #include "unitTestMain.h"
14
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
24 void
25 testString::setUp()
26 {
27 Mem::Init();
28 }
29
30 void
31 testString::testCmpDefault()
32 {
33 String left, right;
34 /* two default strings are equal */
35 CPPUNIT_ASSERT(!left.cmp(right));
36 CPPUNIT_ASSERT(!left.cmp(NULL));
37 CPPUNIT_ASSERT(!left.cmp(NULL, 1));
38 }
39
40 void
41 testString::testCmpEmptyString()
42 {
43 String left("");
44 String right;
45 /* an empty string ("") is equal to a default string */
46 CPPUNIT_ASSERT(!left.cmp(right));
47 CPPUNIT_ASSERT(!left.cmp(NULL));
48 CPPUNIT_ASSERT(!left.cmp(NULL, 1));
49 /* reverse the order to catch corners */
50 CPPUNIT_ASSERT(!right.cmp(left));
51 CPPUNIT_ASSERT(!right.cmp(""));
52 CPPUNIT_ASSERT(!right.cmp("", 1));
53 }
54
55 void
56 testString::testCmpNotEmptyDefault()
57 {
58 String left("foo");
59 String right;
60 /* empty string sorts before everything */
61 CPPUNIT_ASSERT(left.cmp(right) > 0);
62 CPPUNIT_ASSERT(left.cmp(NULL) > 0);
63 CPPUNIT_ASSERT(left.cmp(NULL, 1) > 0);
64 /* reverse for symmetry tests */
65 CPPUNIT_ASSERT(right.cmp(left) < 0);
66 CPPUNIT_ASSERT(right.cmp("foo") < 0);
67 CPPUNIT_ASSERT(right.cmp("foo", 1) < 0);
68 }
69
70 void testString::testSubstr()
71 {
72 String s("0123456789");
73 String check=s.substr(3,5);
74 String ref("34");
75 CPPUNIT_ASSERT(check == ref);
76 }
77