]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/tests/testSBuf.cc
2 #include "base/CharacterSet.h"
5 #include "SBufFindTest.h"
6 #include "SBufStream.h"
7 #include "SquidString.h"
13 CPPUNIT_TEST_SUITE_REGISTRATION( testSBuf
);
15 /* let this test link sanely */
17 #include "MemObject.h"
19 eventAdd(const char *name
, EVH
* func
, void *arg
, double when
, int, bool cbdata
)
22 MemObject::endOffset() const
27 static char fox
[]="The quick brown fox jumped over the lazy dog";
28 static char fox1
[]="The quick brown fox ";
29 static char fox2
[]="jumped over the lazy dog";
31 // TEST: globals variables (default/empty and with contents) are
32 // created outside and before any unit tests and memory subsystem
33 // initialization. Check for correct constructor operation.
35 SBuf
literal("The quick brown fox jumped over the lazy dog");
38 testSBuf::testSBufConstructDestruct()
40 /* NOTE: Do not initialize memory here because we need
41 * to test correct operation before and after Mem::Init
44 // XXX: partial demo below of how to do constructor unit-test. use scope to ensure each test
45 // is working on local-scope variables constructed fresh for the test, and destructed when
46 // scope exists. use nested scopes to test destructor affects on copied data (MemBlob etc)
48 // TEST: default constructor (implicit destructor non-crash test)
49 // test accessors on empty SBuf.
52 CPPUNIT_ASSERT_EQUAL(0U,s1
.length());
53 CPPUNIT_ASSERT_EQUAL(SBuf(""),s1
);
54 CPPUNIT_ASSERT_EQUAL(empty_sbuf
,s1
);
55 CPPUNIT_ASSERT_EQUAL(0,strcmp("",s1
.c_str()));
58 // TEST: copy-construct NULL string (implicit destructor non-crash test)
61 CPPUNIT_ASSERT_EQUAL(0U,s1
.length());
62 CPPUNIT_ASSERT_EQUAL(SBuf(""),s1
);
63 CPPUNIT_ASSERT_EQUAL(empty_sbuf
,s1
);
64 CPPUNIT_ASSERT_EQUAL(0,strcmp("",s1
.c_str()));
67 // TEST: copy-construct empty string (implicit destructor non-crash test)
70 CPPUNIT_ASSERT_EQUAL(0U,s1
.length());
71 CPPUNIT_ASSERT_EQUAL(SBuf(""),s1
);
72 CPPUNIT_ASSERT_EQUAL(empty_sbuf
,s1
);
73 CPPUNIT_ASSERT_EQUAL(0,strcmp("",s1
.c_str()));
76 // TEST: copy-construct from a SBuf
79 CPPUNIT_ASSERT_EQUAL(0U,s1
.length());
80 CPPUNIT_ASSERT_EQUAL(SBuf(""),s1
);
81 CPPUNIT_ASSERT_EQUAL(empty_sbuf
,s1
);
82 CPPUNIT_ASSERT_EQUAL(0,strcmp("",s1
.c_str()));
85 CPPUNIT_ASSERT_EQUAL(literal
,s5
);
87 CPPUNIT_ASSERT_EQUAL(literal
,s6
);
88 // XXX: other state checks. expected result of calling any state accessor on s4 ?
91 // TEST: check that COW doesn't happen upon copy-construction
93 SBuf
s1(empty_sbuf
), s2(s1
);
94 CPPUNIT_ASSERT_EQUAL(s1
.rawContent(), s2
.rawContent());
95 SBuf
s3(literal
), s4(literal
);
96 CPPUNIT_ASSERT_EQUAL(s3
.rawContent(), s4
.rawContent());
99 // TEST: sub-string copy
101 SBuf s1
=SBuf(fox
+4), s2(fox
);
102 SBuf s3
=s2
.substr(4,s2
.length()); //n is out-of-bounds
103 CPPUNIT_ASSERT_EQUAL(s1
,s3
);
106 CPPUNIT_ASSERT_EQUAL(s4
,s3
);
109 // TEST: go via SquidString adapters.
113 CPPUNIT_ASSERT_EQUAL(literal
,s1
);
116 // TEST: go via std::string adapter.
118 std::string
str(fox
);
120 CPPUNIT_ASSERT_EQUAL(literal
,s1
);
125 testSBuf::testSBufConstructDestructAfterMemInit()
128 testSBufConstructDestruct();
132 testSBuf::testEqualityTest()
134 SBuf
s1(fox
),s2(fox
);
135 CPPUNIT_ASSERT_EQUAL(s1
,s1
); //self-equality
136 CPPUNIT_ASSERT_EQUAL(s1
,s2
); //same contents
137 s2
.assign("The quick brown fox jumped over the lazy doe");
138 CPPUNIT_ASSERT(!(s1
== s2
)); //same length, different contents
140 CPPUNIT_ASSERT(!(s1
== s2
)); //different length and contents
141 CPPUNIT_ASSERT(s1
!= s2
); //while we're ready, let's test inequality
143 CPPUNIT_ASSERT(!(s1
== s2
)); //null and not-null
144 CPPUNIT_ASSERT(s1
!= s2
); //while we're ready, let's test inequality
146 CPPUNIT_ASSERT_EQUAL(s1
,s2
); //null and null
150 testSBuf::testAppendSBuf()
152 SBuf
s1(fox1
),s2(fox2
);
154 CPPUNIT_ASSERT_EQUAL(s1
,literal
);
158 testSBuf::testPrintf()
161 s1
.Printf("%s:%d:%03.3f","fox",10,12345.67);
162 s2
.assign("fox:10:12345.670");
163 CPPUNIT_ASSERT_EQUAL(s1
,s2
);
167 testSBuf::testAppendCString()
171 CPPUNIT_ASSERT_EQUAL(s1
,literal
);
175 testSBuf::testAppendStdString()
177 const char *alphabet
="abcdefghijklmnopqrstuvwxyz";
179 SBuf
alpha(alphabet
), s
;
180 s
.append(alphabet
,5).append(alphabet
+5);
181 CPPUNIT_ASSERT_EQUAL(alpha
,s
);
186 s
.append(alphabet
,5).append("\0",1).append(alphabet
+6,SBuf::npos
);
187 control
.append(alphabet
,5).append(1,'\0').append(alphabet
,6,std::string::npos
);
188 SBuf
scontrol(control
); // we need this to test the equality. sigh.
189 CPPUNIT_ASSERT_EQUAL(scontrol
,s
);
192 const char *alphazero
="abcdefghijk\0mnopqrstuvwxyz";
193 SBuf
s(alphazero
,26);
194 std::string
str(alphazero
,26);
195 CPPUNIT_ASSERT_EQUAL(0,memcmp(str
.data(),s
.rawContent(),26));
200 testSBuf::testAppendf()
203 s1
.appendf("%s:%d:%03.2f",fox
,1234,1234.56);
204 s2
.assign("The quick brown fox jumped over the lazy dog:1234:1234.56");
205 CPPUNIT_ASSERT_EQUAL(s2
,s1
);
209 testSBuf::testDumpStats()
211 SBuf::GetStats().dump(std::cout
);
212 MemBlob::GetStats().dump(std::cout
);
213 std::cout
<< "sizeof(SBuf): " << sizeof(SBuf
) << std::endl
;
214 std::cout
<< "sizeof(MemBlob): " << sizeof(MemBlob
) << std::endl
;
218 testSBuf::testSubscriptOp()
221 CPPUNIT_ASSERT_EQUAL(chg
[5],'u');
223 CPPUNIT_ASSERT_EQUAL(literal
[5],'u');
224 CPPUNIT_ASSERT_EQUAL(chg
[5],'e');
227 // note: can't use cppunit's CPPUNIT_TEST_EXCEPTION because TextException asserts, and
228 // so the test can't be properly completed.
230 testSBuf::testSubscriptOpFail()
233 c
=literal
.at(literal
.length()); //out of bounds by 1
235 std::cout
<< c
<< std::endl
;
238 static int sign(int v
)
248 testSBuf::testComparisons()
251 SBuf
s1("foo"),s2("foe");
252 CPPUNIT_ASSERT(s1
.cmp(s2
)>0);
253 CPPUNIT_ASSERT(s1
.caseCmp(s2
)>0);
254 CPPUNIT_ASSERT(s2
.cmp(s1
)<0);
255 CPPUNIT_ASSERT_EQUAL(0,s1
.cmp(s2
,2));
256 CPPUNIT_ASSERT_EQUAL(0,s1
.caseCmp(s2
,2));
257 CPPUNIT_ASSERT(s1
> s2
);
258 CPPUNIT_ASSERT(s2
< s1
);
259 CPPUNIT_ASSERT_EQUAL(sign(s1
.cmp(s2
)),sign(strcmp(s1
.c_str(),s2
.c_str())));
263 CPPUNIT_ASSERT(s1
.cmp(s2
)<0);
264 CPPUNIT_ASSERT_EQUAL(sign(s1
.cmp(s2
)),sign(strcmp(s1
.c_str(),s2
.c_str())));
265 CPPUNIT_ASSERT(s1
< s2
);
266 // specifying the max-length and overhanging size
267 CPPUNIT_ASSERT_EQUAL(1,SBuf("foolong").caseCmp(SBuf("foo"), 5));
268 // case-insensive comaprison
271 CPPUNIT_ASSERT_EQUAL(0,s1
.caseCmp(s2
));
272 CPPUNIT_ASSERT_EQUAL(0,s1
.caseCmp(s2
,2));
273 // \0-clenliness test
274 s1
.assign("f\0oo",4);
275 s2
.assign("f\0Oo",4);
276 CPPUNIT_ASSERT(s1
.cmp(s2
) > 0);
277 CPPUNIT_ASSERT_EQUAL(0,s1
.caseCmp(s2
));
278 CPPUNIT_ASSERT_EQUAL(0,s1
.caseCmp(s2
,3));
279 CPPUNIT_ASSERT_EQUAL(0,s1
.caseCmp(s2
,2));
280 CPPUNIT_ASSERT_EQUAL(0,s1
.cmp(s2
,2));
284 testSBuf::testConsume()
286 SBuf
s1(literal
),s2
,s3
;
289 CPPUNIT_ASSERT_EQUAL(s2
,s3
);
290 s3
.assign("quick brown fox jumped over the lazy dog");
291 CPPUNIT_ASSERT_EQUAL(s1
,s3
);
293 CPPUNIT_ASSERT_EQUAL(s1
,SBuf());
297 testSBuf::testRawContent()
303 foo
= s1
.rawContent();
304 CPPUNIT_ASSERT_EQUAL(0,strncmp(fox
,foo
,s1
.length()));
306 CPPUNIT_ASSERT(!strcmp(fox
,foo
));
310 testSBuf::testRawSpace()
314 SBuf::size_type sz
=s2
.length();
315 char *rb
=s2
.rawSpace(strlen(fox2
)+1);
317 s2
.forceSize(sz
+strlen(fox2
));
318 CPPUNIT_ASSERT_EQUAL(s1
,s2
);
327 CPPUNIT_ASSERT_EQUAL(s1
,s2
);
331 CPPUNIT_ASSERT_EQUAL(s1
,s2
);
332 const char *alphabet
="abcdefghijklmnopqrstuvwxyz";
334 std::string
s(alphabet
); // TODO
339 CPPUNIT_ASSERT_EQUAL(ref
,b
);
343 b
.chop(b
.length()-3);
345 CPPUNIT_ASSERT_EQUAL(ref
,b
);
347 { // chop at beginning
351 CPPUNIT_ASSERT_EQUAL(ref
,b
);
353 { // chop to zero length
357 CPPUNIT_ASSERT_EQUAL(ref
,b
);
359 { // chop beyond end (at npos)
361 b
.chop(SBuf::npos
,4);
363 CPPUNIT_ASSERT_EQUAL(ref
,b
);
367 b
.chop(b
.length()+2,4);
369 CPPUNIT_ASSERT_EQUAL(ref
,b
);
373 b
.chop(0,b
.length());
375 CPPUNIT_ASSERT_EQUAL(ref
,b
);
377 { // overflow chopped area
379 b
.chop(b
.length()-3,b
.length());
381 CPPUNIT_ASSERT_EQUAL(ref
,b
);
386 testSBuf::testChomp()
388 SBuf
s1("complete string");
391 CPPUNIT_ASSERT_EQUAL(s1
,s2
);
392 s2
.assign(" complete string ,");
394 CPPUNIT_ASSERT_EQUAL(s1
,s2
);
395 s1
.assign(", complete string ,");
398 CPPUNIT_ASSERT_EQUAL(s1
,s2
);
401 // inspired by SBufFindTest; to be expanded.
402 class SBufSubstrAutoTest
405 std::string fullReference
, str
;
407 void performEqualityTest() {
409 CPPUNIT_ASSERT_EQUAL(ref
,sb
);
411 SBufSubstrAutoTest() : fullString(fox
), fullReference(fox
) {
412 for (int offset
=fullString
.length()-1; offset
>= 0; --offset
) {
413 for (int length
=fullString
.length()-1-offset
; length
>= 0; --length
) {
414 sb
=fullString
.substr(offset
,length
);
415 str
=fullReference
.substr(offset
,length
);
416 performEqualityTest();
423 testSBuf::testSubstr()
425 SBuf
s1(literal
),s2
,s3
;
428 CPPUNIT_ASSERT_EQUAL(s2
,s3
);
430 CPPUNIT_ASSERT_EQUAL(s1
,s2
);
431 SBufSubstrAutoTest sat
; // work done in the constructor
435 testSBuf::testFindChar()
437 const char *alphabet
="abcdefghijklmnopqrstuvwxyz";
440 SBuf::size_type nposResult
=SBuf::npos
;
443 // needle in haystack
445 CPPUNIT_ASSERT_EQUAL(3U,idx
);
446 CPPUNIT_ASSERT_EQUAL('d',s1
[idx
]);
448 // needle not present in haystack
449 idx
=s1
.find(' '); //fails
450 CPPUNIT_ASSERT_EQUAL(nposResult
,idx
);
454 CPPUNIT_ASSERT_EQUAL(4U,idx
);
456 // char not in searched portion
458 CPPUNIT_ASSERT_EQUAL(nposResult
,idx
);
460 // invalid start position
461 idx
=s1
.find('d',SBuf::npos
);
462 CPPUNIT_ASSERT_EQUAL(nposResult
,idx
);
464 // search outside of haystack
465 idx
=s1
.find('d',s1
.length()+1);
466 CPPUNIT_ASSERT_EQUAL(nposResult
,idx
);
469 // needle in haystack
471 CPPUNIT_ASSERT_EQUAL(3U, idx
);
472 CPPUNIT_ASSERT_EQUAL('d', s1
[idx
]);
474 // needle not present in haystack
475 idx
=s1
.rfind(' '); //fails
476 CPPUNIT_ASSERT_EQUAL(nposResult
,idx
);
480 CPPUNIT_ASSERT_EQUAL(4U,idx
);
482 // char not in searched portion
484 CPPUNIT_ASSERT_EQUAL(nposResult
,idx
);
486 // overlong haystack specification
487 idx
=s1
.rfind('d',s1
.length()+1);
488 CPPUNIT_ASSERT_EQUAL(3U,idx
);
492 testSBuf::testFindSBuf()
494 const char *alphabet
="abcdefghijklmnopqrstuvwxyz";
495 SBuf
haystack(alphabet
);
497 SBuf::size_type nposResult
=SBuf::npos
;
500 // needle in haystack
501 idx
= haystack
.find(SBuf("def"));
502 CPPUNIT_ASSERT_EQUAL(3U,idx
);
504 idx
= haystack
.find(SBuf("xyz"));
505 CPPUNIT_ASSERT_EQUAL(23U,idx
);
507 // needle not in haystack, no initial char match
508 idx
= haystack
.find(SBuf(" eq"));
509 CPPUNIT_ASSERT_EQUAL(nposResult
, idx
);
511 // needle not in haystack, initial sequence match
512 idx
= haystack
.find(SBuf("deg"));
513 CPPUNIT_ASSERT_EQUAL(nposResult
, idx
);
515 // needle past end of haystack
516 idx
= haystack
.find(SBuf("xyz1"));
517 CPPUNIT_ASSERT_EQUAL(nposResult
, idx
);
519 // search in portion: needle not in searched part
520 idx
= haystack
.find(SBuf("def"),7);
521 CPPUNIT_ASSERT_EQUAL(nposResult
, idx
);
523 // search in portion: overhang
524 idx
= haystack
.find(SBuf("def"),4);
525 CPPUNIT_ASSERT_EQUAL(nposResult
, idx
);
527 // invalid start position
528 idx
= haystack
.find(SBuf("def"),SBuf::npos
);
529 CPPUNIT_ASSERT_EQUAL(nposResult
, idx
);
531 // needle bigger than haystack
532 idx
= SBuf("def").find(haystack
);
533 CPPUNIT_ASSERT_EQUAL(nposResult
, idx
);
535 // search in a double-matching haystack
540 idx
= h2
.find(SBuf("def"));
541 CPPUNIT_ASSERT_EQUAL(3U,idx
);
543 idx
= h2
.find(SBuf("xyzab"));
544 CPPUNIT_ASSERT_EQUAL(23U,idx
);
548 // needle in haystack
549 idx
= haystack
.rfind(SBuf("def"));
550 CPPUNIT_ASSERT_EQUAL(3U,idx
);
552 idx
= haystack
.rfind(SBuf("xyz"));
553 CPPUNIT_ASSERT_EQUAL(23U,idx
);
555 // needle not in haystack, no initial char match
556 idx
= haystack
.rfind(SBuf(" eq"));
557 CPPUNIT_ASSERT_EQUAL(nposResult
, idx
);
559 // needle not in haystack, initial sequence match
560 idx
= haystack
.rfind(SBuf("deg"));
561 CPPUNIT_ASSERT_EQUAL(nposResult
, idx
);
563 // needle past end of haystack
564 idx
= haystack
.rfind(SBuf("xyz1"));
565 CPPUNIT_ASSERT_EQUAL(nposResult
, idx
);
567 // search in portion: needle in searched part
568 idx
= haystack
.rfind(SBuf("def"),7);
569 CPPUNIT_ASSERT_EQUAL(3U, idx
);
571 // search in portion: needle not in searched part
572 idx
= haystack
.rfind(SBuf("mno"),3);
573 CPPUNIT_ASSERT_EQUAL(nposResult
, idx
);
575 // search in portion: overhang
576 idx
= haystack
.rfind(SBuf("def"),4);
577 CPPUNIT_ASSERT_EQUAL(3U, idx
);
579 // npos start position
580 idx
= haystack
.rfind(SBuf("def"),SBuf::npos
);
581 CPPUNIT_ASSERT_EQUAL(3U, idx
);
583 // needle bigger than haystack
584 idx
= SBuf("def").rfind(haystack
);
585 CPPUNIT_ASSERT_EQUAL(nposResult
, idx
);
587 // search in a double-matching haystack
592 idx
= h2
.rfind(SBuf("def"));
593 CPPUNIT_ASSERT_EQUAL(29U,idx
);
595 idx
= h2
.find(SBuf("xyzab"));
596 CPPUNIT_ASSERT_EQUAL(23U,idx
);
601 testSBuf::testRFindChar()
606 CPPUNIT_ASSERT_EQUAL(40U,idx
);
607 CPPUNIT_ASSERT_EQUAL(' ',s1
[idx
]);
611 testSBuf::testRFindSBuf()
613 SBuf
haystack(literal
),afox("fox");
614 SBuf
goobar("goobar");
617 // corner case: search for a zero-length SBuf
618 idx
=haystack
.rfind(SBuf(""));
619 CPPUNIT_ASSERT_EQUAL(haystack
.length(),idx
);
621 // corner case: search for a needle longer than the haystack
622 idx
=afox
.rfind(SBuf(" "));
623 CPPUNIT_ASSERT_EQUAL(SBuf::npos
,idx
);
625 idx
=haystack
.rfind(SBuf("fox"));
626 CPPUNIT_ASSERT_EQUAL(16U,idx
);
628 // needle not found, no match for first char
629 idx
=goobar
.rfind(SBuf("foo"));
630 CPPUNIT_ASSERT_EQUAL(SBuf::npos
,idx
);
632 // needle not found, match for first char but no match for SBuf
633 idx
=haystack
.rfind(SBuf("foe"));
634 CPPUNIT_ASSERT_EQUAL(SBuf::npos
,idx
);
636 SBuf
g("g"); //match at the last char
637 idx
=haystack
.rfind(g
);
638 CPPUNIT_ASSERT_EQUAL(43U,idx
);
639 CPPUNIT_ASSERT_EQUAL('g',haystack
[idx
]);
641 idx
=haystack
.rfind(SBuf("The"));
642 CPPUNIT_ASSERT_EQUAL(0U,idx
);
644 haystack
.append("The");
645 idx
=haystack
.rfind(SBuf("The"));
646 CPPUNIT_ASSERT_EQUAL(44U,idx
);
649 haystack
="The quick brown fox";
650 SBuf
needle("foxy lady");
651 idx
=haystack
.rfind(needle
);
652 CPPUNIT_ASSERT_EQUAL(SBuf::npos
,idx
);
656 testSBuf::testSBufLength()
659 CPPUNIT_ASSERT_EQUAL(strlen(fox
),(size_t)s
.length());
663 testSBuf::testScanf()
670 s1
.assign("string , 123 , 123.50");
671 rv
=s1
.scanf("%s , %d , %f",s
,&i
,&f
);
672 CPPUNIT_ASSERT_EQUAL(3,rv
);
673 CPPUNIT_ASSERT_EQUAL(0,strcmp(s
,"string"));
674 CPPUNIT_ASSERT_EQUAL(123,i
);
675 CPPUNIT_ASSERT_EQUAL(static_cast<float>(123.5),f
);
681 char buf
[40]; //shorter than literal()
683 CPPUNIT_ASSERT_EQUAL(s
.length(),s
.copy(buf
,40));
684 CPPUNIT_ASSERT_EQUAL(0,strncmp(s
.rawContent(),buf
,s
.length()));
686 CPPUNIT_ASSERT_EQUAL(40U,s
.copy(buf
,40));
689 CPPUNIT_ASSERT_EQUAL(s2
,s
);
693 testSBuf::testStringOps()
695 SBuf
sng(literal
.toLower()),
696 ref("the quick brown fox jumped over the lazy dog");
697 CPPUNIT_ASSERT_EQUAL(ref
,sng
);
699 CPPUNIT_ASSERT_EQUAL(0,sng
.compare(ref
,caseInsensitive
));
700 // max-size comparison
701 CPPUNIT_ASSERT_EQUAL(0,ref
.compare(SBuf("THE"),caseInsensitive
,3));
702 CPPUNIT_ASSERT_EQUAL(1,ref
.compare(SBuf("THE"),caseInsensitive
,6));
703 CPPUNIT_ASSERT_EQUAL(0,SBuf("the").compare(SBuf("THE"),caseInsensitive
,6));
711 const char *ref
=t
.rawContent();
712 t
.reserveCapacity(10240);
713 const char *match
=t
.rawContent();
714 CPPUNIT_ASSERT(match
!=ref
);
716 t
.append(literal
).append(literal
).append(literal
).append(literal
).append(literal
);
717 t
.append(t
).append(t
).append(t
).append(t
).append(t
);
718 CPPUNIT_ASSERT_EQUAL(ref
,match
);
722 testSBuf::testStartsWith()
724 static SBuf
casebuf("THE QUICK");
725 CPPUNIT_ASSERT(literal
.startsWith(SBuf(fox1
)));
726 CPPUNIT_ASSERT(!SBuf("The quick brown").startsWith(SBuf(fox1
))); //too short
727 CPPUNIT_ASSERT(!literal
.startsWith(SBuf(fox2
))); //different contents
729 // case-insensitive checks
730 CPPUNIT_ASSERT(literal
.startsWith(casebuf
,caseInsensitive
));
731 casebuf
=SBuf(fox1
).toUpper();
732 CPPUNIT_ASSERT(literal
.startsWith(casebuf
,caseInsensitive
));
733 CPPUNIT_ASSERT(literal
.startsWith(SBuf(fox1
),caseInsensitive
));
734 casebuf
= "tha quick";
735 CPPUNIT_ASSERT_EQUAL(false,literal
.startsWith(casebuf
,caseInsensitive
));
739 testSBuf::testSBufStream()
741 SBuf
b("const.string, int 10 and a float 10.5");
743 ss
<< "const.string, int " << 10 << " and a float " << 10.5;
745 CPPUNIT_ASSERT_EQUAL(b
,o
);
748 CPPUNIT_ASSERT_EQUAL(SBuf(),o
);
752 CPPUNIT_ASSERT_EQUAL(ss2
.buf(),literal
);
753 CPPUNIT_ASSERT_EQUAL(f1
,SBuf(fox1
));
757 testSBuf::testFindFirstOf()
759 SBuf
haystack(literal
);
763 idx
=haystack
.findFirstOf(CharacterSet("t1","ADHRWYP"));
764 CPPUNIT_ASSERT_EQUAL(SBuf::npos
,idx
);
766 // found at beginning
767 idx
=haystack
.findFirstOf(CharacterSet("t2","THANDF"));
768 CPPUNIT_ASSERT_EQUAL(0U,idx
);
770 //found at end of haystack
771 idx
=haystack
.findFirstOf(CharacterSet("t3","QWERYVg"));
772 CPPUNIT_ASSERT_EQUAL(haystack
.length()-1,idx
);
774 //found in the middle of haystack
775 idx
=haystack
.findFirstOf(CharacterSet("t4","QWERqYV"));
776 CPPUNIT_ASSERT_EQUAL(4U,idx
);
780 testSBuf::testFindFirstNotOf()
782 SBuf
haystack(literal
);
785 // all chars from the set
786 idx
=haystack
.findFirstNotOf(CharacterSet("t1",literal
.c_str()));
787 CPPUNIT_ASSERT_EQUAL(SBuf::npos
,idx
);
789 // found at beginning
790 idx
=haystack
.findFirstNotOf(CharacterSet("t2","a"));
791 CPPUNIT_ASSERT_EQUAL(0U,idx
);
793 //found at end of haystack
794 idx
=haystack
.findFirstNotOf(CharacterSet("t3",literal
.substr(0,literal
.length()-1).c_str()));
795 CPPUNIT_ASSERT_EQUAL(haystack
.length()-1,idx
);
797 //found in the middle of haystack
798 idx
=haystack
.findFirstNotOf(CharacterSet("t4","The"));
799 CPPUNIT_ASSERT_EQUAL(3U,idx
);
804 testSBuf::testAutoFind()
811 testSBuf::testStdStringOps()
813 const char *alphabet
="abcdefghijklmnopqrstuvwxyz";
814 std::string
astr(alphabet
);
816 CPPUNIT_ASSERT_EQUAL(astr
,sb
.toStdString());