]> git.ipfire.org Git - thirdparty/squid.git/blob - src/tests/testSBufList.cc
Merge from trunk rev.13584
[thirdparty/squid.git] / src / tests / testSBufList.cc
1 /*
2 * Copyright (C) 1996-2014 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 "SBufAlgos.h"
11 #include "SBufList.h"
12 #include "testSBufList.h"
13
14 CPPUNIT_TEST_SUITE_REGISTRATION( testSBufList );
15
16 SBuf literal("The quick brown fox jumped over the lazy dog");
17 static int sbuf_tokens_number=9;
18 static SBuf tokens[]={
19 SBuf("The",3), SBuf("quick",5), SBuf("brown",5), SBuf("fox",3),
20 SBuf("jumped",6), SBuf("over",4), SBuf("the",3), SBuf("lazy",4),
21 SBuf("dog",3)
22 };
23
24 void
25 testSBufList::testSBufListMembership()
26 {
27 SBufList foo;
28 for (int j=0; j<sbuf_tokens_number; ++j)
29 foo.push_back(tokens[j]);
30 CPPUNIT_ASSERT_EQUAL(true,IsMember(foo,SBuf("fox")));
31 CPPUNIT_ASSERT_EQUAL(true,IsMember(foo,SBuf("Fox"),caseInsensitive));
32 CPPUNIT_ASSERT_EQUAL(false,IsMember(foo,SBuf("garble")));
33 }
34
35 void
36 testSBufList::testSBufListJoin()
37 {
38 SBufList foo;
39 CPPUNIT_ASSERT_EQUAL(SBuf(""),SBufContainerJoin(foo,SBuf()));
40 CPPUNIT_ASSERT_EQUAL(SBuf(""),SBufContainerJoin(foo,SBuf()));
41 for (int j = 0; j < sbuf_tokens_number; ++j)
42 foo.push_back(tokens[j]);
43 SBuf joined=SBufContainerJoin(foo,SBuf(" "));
44 CPPUNIT_ASSERT_EQUAL(literal,joined);
45 }