testString.cc
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1996-2022 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 "mem/forward.h"
11 #include "SquidString.h"
12 #include "testString.h"
13 #include "unitTestMain.h"
14 
16 
17 /* init memory pools */
18 
19 void
21 {
22  Mem::Init();
23 }
24 
25 void
27 {
28  String left, right;
29  /* two default strings are equal */
30  CPPUNIT_ASSERT(!left.cmp(right));
31  CPPUNIT_ASSERT(!left.cmp(NULL));
32  CPPUNIT_ASSERT(!left.cmp(NULL, 1));
33 }
34 
35 void
37 {
38  String left("");
39  String right;
40  /* an empty string ("") is equal to a default string */
41  CPPUNIT_ASSERT(!left.cmp(right));
42  CPPUNIT_ASSERT(!left.cmp(NULL));
43  CPPUNIT_ASSERT(!left.cmp(NULL, 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));
48 }
49 
50 void
52 {
53  String left("foo");
54  String right;
55  /* empty string sorts before everything */
56  CPPUNIT_ASSERT(left.cmp(right) > 0);
57  CPPUNIT_ASSERT(left.cmp(NULL) > 0);
58  CPPUNIT_ASSERT(left.cmp(NULL, 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);
63 }
64 
66 {
67  String s("0123456789");
68  String check=s.substr(3,5);
69  String ref("34");
70  CPPUNIT_ASSERT(check == ref);
71 }
72 
void testCmpEmptyString()
Definition: testString.cc:36
CPPUNIT_TEST_SUITE_REGISTRATION(testString)
int cmp(char const *) const
Definition: String.cc:255
void testSubstr()
Definition: testString.cc:65
#define NULL
Definition: types.h:166
void testCmpDefault()
Definition: testString.cc:26
void setUp()
Definition: testString.cc:20
void testCmpNotEmptyDefault()
Definition: testString.cc:51
void Init()
Definition: old_api.cc:425
String substr(size_type from, size_type to) const
Definition: String.cc:209

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors