]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/tests/testString.cc
1 #define SQUID_UNIT_TEST 1
6 #include "SquidString.h"
7 #include "testString.h"
9 CPPUNIT_TEST_SUITE_REGISTRATION( testString
);
11 /* let this test link sanely */
13 eventAdd(const char *name
, EVH
* func
, void *arg
, double when
, int, bool cbdata
)
16 /* init memory pools */
25 testString::testCmpDefault()
28 /* two default strings are equal */
29 CPPUNIT_ASSERT(!left
.cmp(right
));
30 CPPUNIT_ASSERT(!left
.cmp(NULL
));
31 CPPUNIT_ASSERT(!left
.cmp(NULL
, 1));
35 testString::testCmpEmptyString()
39 /* an empty string ("") is equal to a default string */
40 CPPUNIT_ASSERT(!left
.cmp(right
));
41 CPPUNIT_ASSERT(!left
.cmp(NULL
));
42 CPPUNIT_ASSERT(!left
.cmp(NULL
, 1));
43 /* reverse the order to catch corners */
44 CPPUNIT_ASSERT(!right
.cmp(left
));
45 CPPUNIT_ASSERT(!right
.cmp(""));
46 CPPUNIT_ASSERT(!right
.cmp("", 1));
50 testString::testCmpNotEmptyDefault()
54 /* empty string sorts before everything */
55 CPPUNIT_ASSERT(left
.cmp(right
) > 0);
56 CPPUNIT_ASSERT(left
.cmp(NULL
) > 0);
57 CPPUNIT_ASSERT(left
.cmp(NULL
, 1) > 0);
58 /* reverse for symmetry tests */
59 CPPUNIT_ASSERT(right
.cmp(left
) < 0);
60 CPPUNIT_ASSERT(right
.cmp("foo") < 0);
61 CPPUNIT_ASSERT(right
.cmp("foo", 1) < 0);
64 void testString::testSubstr()
66 String
s("0123456789");
67 String check
=s
.substr(3,5);
69 CPPUNIT_ASSERT(check
== ref
);