testString.cc
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1996-2017 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 "event.h"
11 #include "SquidString.h"
12 #include "testString.h"
13 #include "unitTestMain.h"
14 
16 
17 /* let this test link sanely */
18 void
19 eventAdd(const char *name, EVH * func, void *arg, double when, int, bool cbdata)
20 {}
21 
22 /* init memory pools */
23 
24 void
26 {
27  Mem::Init();
28 }
29 
30 void
32 {
33  String left, right;
34  /* two default strings are equal */
35  CPPUNIT_ASSERT(!left.cmp(right));
36  CPPUNIT_ASSERT(!left.cmp(NULL));
37  CPPUNIT_ASSERT(!left.cmp(NULL, 1));
38 }
39 
40 void
42 {
43  String left("");
44  String right;
45  /* an empty string ("") is equal to a default string */
46  CPPUNIT_ASSERT(!left.cmp(right));
47  CPPUNIT_ASSERT(!left.cmp(NULL));
48  CPPUNIT_ASSERT(!left.cmp(NULL, 1));
49  /* reverse the order to catch corners */
50  CPPUNIT_ASSERT(!right.cmp(left));
51  CPPUNIT_ASSERT(!right.cmp(""));
52  CPPUNIT_ASSERT(!right.cmp("", 1));
53 }
54 
55 void
57 {
58  String left("foo");
59  String right;
60  /* empty string sorts before everything */
61  CPPUNIT_ASSERT(left.cmp(right) > 0);
62  CPPUNIT_ASSERT(left.cmp(NULL) > 0);
63  CPPUNIT_ASSERT(left.cmp(NULL, 1) > 0);
64  /* reverse for symmetry tests */
65  CPPUNIT_ASSERT(right.cmp(left) < 0);
66  CPPUNIT_ASSERT(right.cmp("foo") < 0);
67  CPPUNIT_ASSERT(right.cmp("foo", 1) < 0);
68 }
69 
71 {
72  String s("0123456789");
73  String check=s.substr(3,5);
74  String ref("34");
75  CPPUNIT_ASSERT(check == ref);
76 }
77 
int cmp(char const *) const
Definition: String.cc:269
Definition: cbdata.cc:60
CPPUNIT_TEST_SUITE_REGISTRATION(testString)
void EVH void * arg
Definition: stub_event.cc:16
void EVH(void *)
Definition: event.h:19
void eventAdd(const char *name, EVH *func, void *arg, double when, int, bool cbdata)
Definition: testString.cc:19
void Init()
Definition: old_api.cc:412
String substr(size_type from, size_type to) const
Definition: String.cc:223
void testCmpDefault()
Definition: testString.cc:31
void testCmpEmptyString()
Definition: testString.cc:41
void setUp()
Definition: testString.cc:25
void EVH * func
Definition: stub_event.cc:16
#define NULL
Definition: types.h:166
void testSubstr()
Definition: testString.cc:70
void testCmpNotEmptyDefault()
Definition: testString.cc:56

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors