squid-
cache.org
Optimising Web Delivery
Docs
Download
Donate
Support
About
Contact
Shop
Blog
src
tests
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
15
CPPUNIT_TEST_SUITE_REGISTRATION
(
testString
);
16
17
/* init memory pools */
18
19
void
20
testString::setUp
()
21
{
22
Mem::Init
();
23
}
24
25
void
26
testString::testCmpDefault
()
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
36
testString::testCmpEmptyString
()
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
51
testString::testCmpNotEmptyDefault
()
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
65
void
testString::testSubstr
()
66
{
67
String
s(
"0123456789"
);
68
String
check=s.
substr
(3,5);
69
String
ref(
"34"
);
70
CPPUNIT_ASSERT(check == ref);
71
}
72
SquidString.h
testString::testCmpEmptyString
void testCmpEmptyString()
Definition:
testString.cc:36
CPPUNIT_TEST_SUITE_REGISTRATION
CPPUNIT_TEST_SUITE_REGISTRATION(testString)
testString.h
String::cmp
int cmp(char const *) const
Definition:
String.cc:255
testString::testSubstr
void testSubstr()
Definition:
testString.cc:65
unitTestMain.h
NULL
#define NULL
Definition:
types.h:166
testString::testCmpDefault
void testCmpDefault()
Definition:
testString.cc:26
testString::setUp
void setUp()
Definition:
testString.cc:20
String
Definition:
SquidString.h:26
testString::testCmpNotEmptyDefault
void testCmpNotEmptyDefault()
Definition:
testString.cc:51
Mem::Init
void Init()
Definition:
old_api.cc:425
String::substr
String substr(size_type from, size_type to) const
Definition:
String.cc:209
squid.h
testString
Definition:
testString.h:19
Introduction
About Squid
Why Squid?
Squid Developers
How to Donate
How to Help Out
Getting Squid
Squid Source Packages
Squid Deployment Case-Studies
Squid Software Foundation
Documentation
Configuration:
Reference
Examples
FAQ
and
Wiki
Guide Books:
Beginners
Definitive
Non-English
More...
Support
Security Advisories
Bugzilla Database
Mailing lists
Contacting us
Commercial services
Project Sponsors
Squid-based products
Miscellaneous
Developer Resources
Related Writings
Related Software:
Authenticators
Ecap
Icap
Ident
Log Analysis
Monitor
Proxies
Redirectors
General
Squid Artwork
Web Site Translations
Japanese
Mirrors
Website:
gr
il
jp
pl
...
full list
FTP Package Archive