]> git.ipfire.org Git - thirdparty/squid.git/blob - src/tests/testString.cc
Source Format Enforcement (#1234)
[thirdparty/squid.git] / src / tests / testString.cc
1 /*
2 * Copyright (C) 1996-2023 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 "mem/forward.h"
11 #include "SquidString.h"
12 #include "testString.h"
13 #include "unitTestMain.h"
14
15 CPPUNIT_TEST_SUITE_REGISTRATION( testString );
16
17 /* init memory pools */
18
19 void
20 testString::setUp()
21 {
22 Mem::Init();
23 }
24
25 void
26 testString::testCmpDefault()
27 {
28 String left, right;
29 /* two default strings are equal */
30 CPPUNIT_ASSERT(!left.cmp(right));
31 CPPUNIT_ASSERT(!left.cmp(nullptr));
32 CPPUNIT_ASSERT(!left.cmp(nullptr, 1));
33 }
34
35 void
36 testString::testCmpEmptyString()
37 {
38 String left("");
39 String right;
40 /* an empty string ("") is equal to a default string */
41 CPPUNIT_ASSERT(!left.cmp(right));
42 CPPUNIT_ASSERT(!left.cmp(nullptr));
43 CPPUNIT_ASSERT(!left.cmp(nullptr, 1));
44 /* reverse the order to catch corners */
45 CPPUNIT_ASSERT(!right.cmp(left));
46 CPPUNIT_ASSERT(!right.cmp(""));
47 CPPUNIT_ASSERT(!right.cmp("", 1));
48 }
49
50 void
51 testString::testCmpNotEmptyDefault()
52 {
53 String left("foo");
54 String right;
55 /* empty string sorts before everything */
56 CPPUNIT_ASSERT(left.cmp(right) > 0);
57 CPPUNIT_ASSERT(left.cmp(nullptr) > 0);
58 CPPUNIT_ASSERT(left.cmp(nullptr, 1) > 0);
59 /* reverse for symmetry tests */
60 CPPUNIT_ASSERT(right.cmp(left) < 0);
61 CPPUNIT_ASSERT(right.cmp("foo") < 0);
62 CPPUNIT_ASSERT(right.cmp("foo", 1) < 0);
63 }
64
65 void testString::testSubstr()
66 {
67 String s("0123456789");
68 String check=s.substr(3,5);
69 String ref("34");
70 CPPUNIT_ASSERT(check == ref);
71 }
72