]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/tests/testString.cc
0882393d6326e454f78639137baf23e79a7e391c
2 * Copyright (C) 1996-2017 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.
11 #include "SquidString.h"
12 #include "testString.h"
13 #include "unitTestMain.h"
15 CPPUNIT_TEST_SUITE_REGISTRATION( testString
);
17 /* let this test link sanely */
19 eventAdd(const char *name
, EVH
* func
, void *arg
, double when
, int, bool cbdata
)
22 /* init memory pools */
31 testString::testCmpDefault()
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));
41 testString::testCmpEmptyString()
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));
56 testString::testCmpNotEmptyDefault()
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);
70 void testString::testSubstr()
72 String
s("0123456789");
73 String check
=s
.substr(3,5);
75 CPPUNIT_ASSERT(check
== ref
);