testSBufList.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 "sbuf/Algorithms.h"
11#include "sbuf/List.h"
12#include "tests/testSBufList.h"
13#include "unitTestMain.h"
14
16
17SBuf literal("The quick brown fox jumped over the lazy dog");
18static int sbuf_tokens_number=9;
19static SBuf tokens[]= {
20 SBuf("The",3), SBuf("quick",5), SBuf("brown",5), SBuf("fox",3),
21 SBuf("jumped",6), SBuf("over",4), SBuf("the",3), SBuf("lazy",4),
22 SBuf("dog",3)
23};
24
25void
27{
28 SBufList foo;
29 for (int j=0; j<sbuf_tokens_number; ++j)
30 foo.push_back(tokens[j]);
31 CPPUNIT_ASSERT_EQUAL(true,IsMember(foo,SBuf("fox")));
32 CPPUNIT_ASSERT_EQUAL(true,IsMember(foo,SBuf("Fox"),caseInsensitive));
33 CPPUNIT_ASSERT_EQUAL(false,IsMember(foo,SBuf("garble")));
34}
35
36void
38{
39 SBufList foo;
40 CPPUNIT_ASSERT_EQUAL(SBuf(""),JoinContainerToSBuf(foo.begin(), foo.end(),SBuf()));
41 for (int j = 0; j < sbuf_tokens_number; ++j)
42 foo.push_back(tokens[j]);
43 SBuf joined=JoinContainerToSBuf(foo.begin(), foo.end(),SBuf(" "));
44 CPPUNIT_ASSERT_EQUAL(literal,joined);
45 SBuf s1("1"), s2("2"), s3("3"), full("(1,2,3)");
46 SBufList sl {s1,s2,s3};
47 CPPUNIT_ASSERT_EQUAL(full, JoinContainerToSBuf(sl.begin(),
48 sl.end(), SBuf(","), SBuf("("), SBuf(")")));
49
50 CPPUNIT_ASSERT_EQUAL(SBuf(""),JoinContainerToSBuf(foo.begin(), foo.begin(),SBuf()));
51
52}
53
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
void testSBufListMembership()
Definition: testSBufList.cc:26
void testSBufListJoin()
Definition: testSBufList.cc:37
std::list< SBuf > SBufList
Definition: forward.h:23
static SBuf tokens[]
Definition: testSBufList.cc:19
static int sbuf_tokens_number
Definition: testSBufList.cc:18
CPPUNIT_TEST_SUITE_REGISTRATION(testSBufList)
SBuf literal("The quick brown fox jumped over the lazy dog")

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors