Squid Web Cache master
Loading...
Searching...
No Matches
testString.cc
Go to the documentation of this file.
1/*
2 * Copyright (C) 1996-2025 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 "compat/cppunit.h"
11#include "mem/forward.h"
12#include "SquidString.h"
13#include "unitTestMain.h"
14
15/*
16 * test the store framework
17 */
18
36
37void
39{
40 String left, right;
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));
45}
46
47void
49{
50 String left("");
51 String right;
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));
60}
61
62void
64{
65 String left("foo");
66 String right;
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);
75}
76
78{
79 String s("0123456789");
80 String check=s.substr(3,5);
81 String ref("34");
82 CPPUNIT_ASSERT(check == ref);
83}
84
86class MyTestProgram: public TestProgram
87{
88public:
89 /* TestProgram API */
90 void startup() override { Mem::Init(); }
91};
92
93int
94main(int argc, char *argv[])
95{
96 return MyTestProgram().run(argc, argv);
97}
98
customizes our test setup
void startup() override
Definition testString.cc:90
int cmp(char const *) const
Definition String.cc:243
String substr(size_type from, size_type to) const
Definition String.cc:197
implements test program's main() function while enabling customization
int run(int argc, char *argv[])
void testCmpEmptyString()
Definition testString.cc:48
CPPUNIT_TEST(testCmpEmptyString)
void testCmpDefault()
Definition testString.cc:38
CPPUNIT_TEST_SUITE_END()
CPPUNIT_TEST_SUITE(TestString)
void testCmpNotEmptyDefault()
Definition testString.cc:63
void testSubstr()
Definition testString.cc:77
CPPUNIT_TEST(testSubstr)
CPPUNIT_TEST(testCmpNotEmptyDefault)
CPPUNIT_TEST(testCmpDefault)
int main()
void Init()
Definition old_api.cc:281
CPPUNIT_TEST_SUITE_REGISTRATION(TestString)