]> git.ipfire.org Git - thirdparty/squid.git/blob - src/tests/testSBufList.cc
initial version of libsbuf
[thirdparty/squid.git] / src / tests / testSBufList.cc
1 /*
2 * Copyright (C) 1996-2016 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/SBufAlgos.h"
11 #include "sbuf/SBufList.h"
12 #include "testSBufList.h"
13 #include "unitTestMain.h"
14
15 CPPUNIT_TEST_SUITE_REGISTRATION( testSBufList );
16
17 SBuf literal("The quick brown fox jumped over the lazy dog");
18 static int sbuf_tokens_number=9;
19 static 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
25 void
26 testSBufList::testSBufListMembership()
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
36 void
37 testSBufList::testSBufListJoin()
38 {
39 SBufList foo;
40 CPPUNIT_ASSERT_EQUAL(SBuf(""),SBufContainerJoin(foo,SBuf()));
41 CPPUNIT_ASSERT_EQUAL(SBuf(""),SBufContainerJoin(foo,SBuf()));
42 for (int j = 0; j < sbuf_tokens_number; ++j)
43 foo.push_back(tokens[j]);
44 SBuf joined=SBufContainerJoin(foo,SBuf(" "));
45 CPPUNIT_ASSERT_EQUAL(literal,joined);
46 }
47