]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/tests/testString.cc
2 * Copyright (C) 1996-2023 The Squid Software Foundation and contributors
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.
10 #include "mem/forward.h"
11 #include "SquidString.h"
12 #include "testString.h"
13 #include "unitTestMain.h"
15 CPPUNIT_TEST_SUITE_REGISTRATION( testString
);
17 /* init memory pools */
26 testString::testCmpDefault()
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));
36 testString::testCmpEmptyString()
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));
51 testString::testCmpNotEmptyDefault()
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);
65 void testString::testSubstr()
67 String
s("0123456789");
68 String check
=s
.substr(3,5);
70 CPPUNIT_ASSERT(check
== ref
);