]>
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 "compat/cppunit.h"
11 #include "mem/forward.h"
12 #include "SquidString.h"
13 #include "unitTestMain.h"
16 * test the store framework
19 class TestString
: public CPPUNIT_NS::TestFixture
21 CPPUNIT_TEST_SUITE(TestString
);
22 CPPUNIT_TEST(testCmpDefault
);
23 CPPUNIT_TEST(testCmpEmptyString
);
24 CPPUNIT_TEST(testCmpNotEmptyDefault
);
25 CPPUNIT_TEST(testSubstr
);
27 CPPUNIT_TEST_SUITE_END();
30 void testCmpDefault();
31 void testCmpEmptyString();
32 void testCmpNotEmptyDefault();
35 CPPUNIT_TEST_SUITE_REGISTRATION(TestString
);
38 TestString::testCmpDefault()
41 /* two default strings are equal */
42 CPPUNIT_ASSERT(!left
.cmp(right
));
43 CPPUNIT_ASSERT(!left
.cmp(nullptr));
44 CPPUNIT_ASSERT(!left
.cmp(nullptr, 1));
48 TestString::testCmpEmptyString()
52 /* an empty string ("") is equal to a default string */
53 CPPUNIT_ASSERT(!left
.cmp(right
));
54 CPPUNIT_ASSERT(!left
.cmp(nullptr));
55 CPPUNIT_ASSERT(!left
.cmp(nullptr, 1));
56 /* reverse the order to catch corners */
57 CPPUNIT_ASSERT(!right
.cmp(left
));
58 CPPUNIT_ASSERT(!right
.cmp(""));
59 CPPUNIT_ASSERT(!right
.cmp("", 1));
63 TestString::testCmpNotEmptyDefault()
67 /* empty string sorts before everything */
68 CPPUNIT_ASSERT(left
.cmp(right
) > 0);
69 CPPUNIT_ASSERT(left
.cmp(nullptr) > 0);
70 CPPUNIT_ASSERT(left
.cmp(nullptr, 1) > 0);
71 /* reverse for symmetry tests */
72 CPPUNIT_ASSERT(right
.cmp(left
) < 0);
73 CPPUNIT_ASSERT(right
.cmp("foo") < 0);
74 CPPUNIT_ASSERT(right
.cmp("foo", 1) < 0);
77 void TestString::testSubstr()
79 String
s("0123456789");
80 String check
=s
.substr(3,5);
82 CPPUNIT_ASSERT(check
== ref
);
85 /// customizes our test setup
86 class MyTestProgram
: public TestProgram
90 void startup() override
{ Mem::Init(); }
94 main(int argc
, char *argv
[])
96 return MyTestProgram().run(argc
, argv
);