testSBufList.cc
Go to the documentation of this file.
1/*
2 * Copyright (C) 1996-2023 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 "sbuf/Algorithms.h"
12#include "sbuf/List.h"
13#include "unitTestMain.h"
14
15class TestSBufList : public CPPUNIT_NS::TestFixture
16{
21
22protected:
24 void testSBufListJoin();
25};
27
28SBuf literal("The quick brown fox jumped over the lazy dog");
29static int sbuf_tokens_number=9;
30static SBuf tokens[]= {
31 SBuf("The",3), SBuf("quick",5), SBuf("brown",5), SBuf("fox",3),
32 SBuf("jumped",6), SBuf("over",4), SBuf("the",3), SBuf("lazy",4),
33 SBuf("dog",3)
34};
35
36void
38{
39 SBufList foo;
40 for (int j=0; j<sbuf_tokens_number; ++j)
41 foo.push_back(tokens[j]);
42 CPPUNIT_ASSERT_EQUAL(true,IsMember(foo,SBuf("fox")));
43 CPPUNIT_ASSERT_EQUAL(true,IsMember(foo,SBuf("Fox"),caseInsensitive));
44 CPPUNIT_ASSERT_EQUAL(false,IsMember(foo,SBuf("garble")));
45}
46
47void
49{
50 SBufList foo;
51 CPPUNIT_ASSERT_EQUAL(SBuf(""),JoinContainerToSBuf(foo.begin(), foo.end(),SBuf()));
52 for (int j = 0; j < sbuf_tokens_number; ++j)
53 foo.push_back(tokens[j]);
54 SBuf joined=JoinContainerToSBuf(foo.begin(), foo.end(),SBuf(" "));
55 CPPUNIT_ASSERT_EQUAL(literal,joined);
56 SBuf s1("1"), s2("2"), s3("3"), full("(1,2,3)");
57 SBufList sl {s1,s2,s3};
58 CPPUNIT_ASSERT_EQUAL(full, JoinContainerToSBuf(sl.begin(),
59 sl.end(), SBuf(","), SBuf("("), SBuf(")")));
60
61 CPPUNIT_ASSERT_EQUAL(SBuf(""),JoinContainerToSBuf(foo.begin(), foo.begin(),SBuf()));
62
63}
64
65int
66main(int argc, char *argv[])
67{
68 return TestProgram().run(argc, argv);
69}
70
SBuf JoinContainerToSBuf(const ContainerIterator &begin, const ContainerIterator &end, const SBuf &separator, const SBuf &prefix=SBuf(), const SBuf &suffix=SBuf())
convenience wrapper of JoinContainerIntoSBuf with no caller-supplied SBuf
Definition: Algorithms.h:98
bool IsMember(const SBufList &sl, const SBuf &S, const SBufCaseSensitive case_sensitive)
Definition: List.cc:14
@ caseInsensitive
Definition: SBuf.h:38
@ s1
Definition: cf_gen.cc:55
Definition: SBuf.h:94
implements test program's main() function while enabling customization
Definition: unitTestMain.h:26
int run(int argc, char *argv[])
Definition: unitTestMain.h:44
CPPUNIT_TEST_SUITE(TestSBufList)
CPPUNIT_TEST(testSBufListJoin)
CPPUNIT_TEST_SUITE_END()
void testSBufListMembership()
Definition: testSBufList.cc:37
void testSBufListJoin()
Definition: testSBufList.cc:48
CPPUNIT_TEST(testSBufListMembership)
std::list< SBuf > SBufList
Definition: forward.h:23
int main(int argc, char *argv[])
Definition: testSBufList.cc:66
static SBuf tokens[]
Definition: testSBufList.cc:30
static int sbuf_tokens_number
Definition: testSBufList.cc:29
CPPUNIT_TEST_SUITE_REGISTRATION(TestSBufList)
SBuf literal("The quick brown fox jumped over the lazy dog")

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors