]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/tests/testSBuf.cc
4 #include "SBufStream.h"
5 #include "SquidString.h"
7 #include "SBufFindTest.h"
12 CPPUNIT_TEST_SUITE_REGISTRATION( testSBuf
);
14 /* let this test link sanely */
16 #include "MemObject.h"
18 eventAdd(const char *name
, EVH
* func
, void *arg
, double when
, int, bool cbdata
)
21 MemObject::endOffset() const
26 static char fox
[]="The quick brown fox jumped over the lazy dog";
27 static char fox1
[]="The quick brown fox ";
28 static char fox2
[]="jumped over the lazy dog";
30 // TEST: globals variables (default/empty and with contents) are
31 // created outside and before any unit tests and memory subsystem
32 // initialization. Check for correct constructor operation.
34 SBuf
literal("The quick brown fox jumped over the lazy dog");
37 testSBuf::testSBufConstructDestruct()
39 /* NOTE: Do not initialize memory here because we need
40 * to test correct operation before and after Mem::Init
43 // XXX: partial demo below of how to do constructor unit-test. use scope to ensure each test
44 // is working on local-scope variables constructed fresh for the test, and destructed when
45 // scope exists. use nested scopes to test destructor affects on copied data (MemBlob etc)
47 // TEST: default constructor (implicit destructor non-crash test)
48 // test accessors on empty SBuf.
51 CPPUNIT_ASSERT_EQUAL(0,s1
.length());
52 CPPUNIT_ASSERT_EQUAL(SBuf(""),s1
);
53 CPPUNIT_ASSERT_EQUAL(empty_sbuf
,s1
);
54 CPPUNIT_ASSERT_EQUAL(0,strcmp("",s1
.c_str()));
57 // TEST: copy-construct NULL string (implicit destructor non-crash test)
60 CPPUNIT_ASSERT_EQUAL(0,s1
.length());
61 CPPUNIT_ASSERT_EQUAL(SBuf(""),s1
);
62 CPPUNIT_ASSERT_EQUAL(empty_sbuf
,s1
);
63 CPPUNIT_ASSERT_EQUAL(0,strcmp("",s1
.c_str()));
66 // TEST: copy-construct empty string (implicit destructor non-crash test)
69 CPPUNIT_ASSERT_EQUAL(0,s1
.length());
70 CPPUNIT_ASSERT_EQUAL(SBuf(""),s1
);
71 CPPUNIT_ASSERT_EQUAL(empty_sbuf
,s1
);
72 CPPUNIT_ASSERT_EQUAL(0,strcmp("",s1
.c_str()));
75 // TEST: copy-construct from a SBuf
78 CPPUNIT_ASSERT_EQUAL(0,s1
.length());
79 CPPUNIT_ASSERT_EQUAL(SBuf(""),s1
);
80 CPPUNIT_ASSERT_EQUAL(empty_sbuf
,s1
);
81 CPPUNIT_ASSERT_EQUAL(0,strcmp("",s1
.c_str()));
84 CPPUNIT_ASSERT_EQUAL(literal
,s5
);
86 CPPUNIT_ASSERT_EQUAL(literal
,s6
);
87 // XXX: other state checks. expected result of calling any state accessor on s4 ?
90 // TEST: check that COW doesn't happen upon copy-construction
92 SBuf
s1(empty_sbuf
), s2(s1
);
93 CPPUNIT_ASSERT_EQUAL(s1
.rawContent(), s2
.rawContent());
94 SBuf
s3(literal
), s4(literal
);
95 CPPUNIT_ASSERT_EQUAL(s3
.rawContent(), s4
.rawContent());
98 // TEST: sub-string copy
100 SBuf s1
=SBuf(fox
+4), s2(fox
);
101 SBuf s3
=s2
.substr(4,s2
.length()); //n is out-of-bounds
102 CPPUNIT_ASSERT_EQUAL(s1
,s3
);
105 CPPUNIT_ASSERT_EQUAL(s4
,s3
);
108 // TEST: go via SquidString adapters.
112 CPPUNIT_ASSERT_EQUAL(literal
,s1
);
115 // TEST: go via std::string adapter.
117 std::string
str(fox
);
119 CPPUNIT_ASSERT_EQUAL(literal
,s1
);
124 testSBuf::testSBufConstructDestructAfterMemInit()
127 testSBufConstructDestruct();
131 testSBuf::testEqualityTest()
133 SBuf
s1(fox
),s2(fox
);
134 CPPUNIT_ASSERT_EQUAL(s1
,s1
); //self-equality
135 CPPUNIT_ASSERT_EQUAL(s1
,s2
); //same contents
136 s2
.assign("The quick brown fox jumped over the lazy doe");
137 CPPUNIT_ASSERT(!(s1
== s2
)); //same length, different contents
139 CPPUNIT_ASSERT(!(s1
== s2
)); //different length and contents
140 CPPUNIT_ASSERT(s1
!= s2
); //while we're ready, let's test inequality
142 CPPUNIT_ASSERT(!(s1
== s2
)); //null and not-null
143 CPPUNIT_ASSERT(s1
!= s2
); //while we're ready, let's test inequality
145 CPPUNIT_ASSERT_EQUAL(s1
,s2
); //null and null
149 testSBuf::testAppendSBuf()
151 SBuf
s1(fox1
),s2(fox2
);
153 CPPUNIT_ASSERT_EQUAL(s1
,literal
);
157 testSBuf::testPrintf()
160 s1
.Printf("%s:%d:%03.3f","fox",10,12345.67);
161 s2
.assign("fox:10:12345.670");
162 CPPUNIT_ASSERT_EQUAL(s1
,s2
);
166 testSBuf::testAppendCString()
170 CPPUNIT_ASSERT_EQUAL(s1
,literal
);
174 testSBuf::testAppendStdString()
176 const char *alphabet
="abcdefghijklmnopqrstuvwxyz";
178 SBuf
alpha(alphabet
), s
;
179 s
.append(alphabet
,5).append(alphabet
+5);
180 CPPUNIT_ASSERT_EQUAL(alpha
,s
);
185 s
.append(alphabet
,5).append("\0",1).append(alphabet
+6,SBuf::npos
);
186 control
.append(alphabet
,5).append(1,'\0').append(alphabet
,6,std::string::npos
);
187 SBuf
scontrol(control
); // we need this to test the equality. sigh.
188 CPPUNIT_ASSERT_EQUAL(scontrol
,s
);
191 const char *alphazero
="abcdefghijk\0mnopqrstuvwxyz";
192 SBuf
s(alphazero
,26);
193 std::string
str(alphazero
,26);
194 CPPUNIT_ASSERT_EQUAL(0,memcmp(str
.data(),s
.rawContent(),26));
199 testSBuf::testAppendf()
202 s1
.appendf("%s:%d:%03.2f",fox
,1234,1234.56);
203 s2
.assign("The quick brown fox jumped over the lazy dog:1234:1234.56");
204 CPPUNIT_ASSERT_EQUAL(s1
,s2
);
208 testSBuf::testDumpStats()
210 SBuf::GetStats().dump(std::cout
);
211 MemBlob::GetStats().dump(std::cout
);
212 std::cout
<< "sizeof(SBuf): " << sizeof(SBuf
) << std::endl
;
213 std::cout
<< "sizeof(MemBlob): " << sizeof(MemBlob
) << std::endl
;
217 testSBuf::testSubscriptOp()
220 CPPUNIT_ASSERT_EQUAL(chg
[5],'u');
222 CPPUNIT_ASSERT_EQUAL(literal
[5],'u');
223 CPPUNIT_ASSERT_EQUAL(chg
[5],'e');
226 // note: can't use cppunit's CPPUNIT_TEST_EXCEPTION because TextException asserts, and
227 // so the test can't be properly completed.
229 testSBuf::testSubscriptOpFail()
232 c
=literal
.at(literal
.length()); //out of bounds by 1
234 std::cout
<< c
<< std::endl
;
237 static int sign(int v
)
247 testSBuf::testComparisons()
250 SBuf
s1("foo"),s2("foe");
251 CPPUNIT_ASSERT(s1
.cmp(s2
)>0);
252 CPPUNIT_ASSERT(s1
.caseCmp(s2
)>0);
253 CPPUNIT_ASSERT(s2
.cmp(s1
)<0);
254 CPPUNIT_ASSERT_EQUAL(0,s1
.cmp(s2
,2));
255 CPPUNIT_ASSERT_EQUAL(0,s1
.caseCmp(s2
,2));
256 CPPUNIT_ASSERT(s1
> s2
);
257 CPPUNIT_ASSERT(s2
< s1
);
258 CPPUNIT_ASSERT_EQUAL(sign(s1
.cmp(s2
)),sign(strcmp(s1
.c_str(),s2
.c_str())));
262 CPPUNIT_ASSERT(s1
.cmp(s2
)<0);
263 CPPUNIT_ASSERT_EQUAL(sign(s1
.cmp(s2
)),sign(strcmp(s1
.c_str(),s2
.c_str())));
264 CPPUNIT_ASSERT(s1
< s2
);
265 // specifying the max-length and overhanging size
266 CPPUNIT_ASSERT_EQUAL(1,SBuf("foolong").caseCmp(SBuf("foo"), 5));
267 // case-insensive comaprison
270 CPPUNIT_ASSERT_EQUAL(0,s1
.caseCmp(s2
));
271 CPPUNIT_ASSERT_EQUAL(0,s1
.caseCmp(s2
,2));
272 // \0-clenliness test
273 s1
.assign("f\0oo",4);
274 s2
.assign("f\0Oo",4);
275 CPPUNIT_ASSERT_EQUAL(1,s1
.cmp(s2
));
276 CPPUNIT_ASSERT_EQUAL(0,s1
.caseCmp(s2
));
277 CPPUNIT_ASSERT_EQUAL(0,s1
.caseCmp(s2
,3));
278 CPPUNIT_ASSERT_EQUAL(0,s1
.caseCmp(s2
,2));
279 CPPUNIT_ASSERT_EQUAL(0,s1
.cmp(s2
,2));
283 testSBuf::testConsume()
285 SBuf
s1(literal
),s2
,s3
;
288 CPPUNIT_ASSERT_EQUAL(s2
,s3
);
289 s3
.assign("quick brown fox jumped over the lazy dog");
290 CPPUNIT_ASSERT_EQUAL(s1
,s3
);
292 CPPUNIT_ASSERT_EQUAL(s1
,SBuf());
296 testSBuf::testRawContent()
302 foo
= s1
.rawContent();
303 CPPUNIT_ASSERT_EQUAL(0,strncmp(fox
,foo
,s1
.length()));
305 CPPUNIT_ASSERT(!strcmp(fox
,foo
));
309 testSBuf::testRawSpace()
313 SBuf::size_type sz
=s2
.length();
314 char *rb
=s2
.rawSpace(strlen(fox2
)+1);
316 s2
.forceSize(sz
+strlen(fox2
));
317 CPPUNIT_ASSERT_EQUAL(s1
,s2
);
326 CPPUNIT_ASSERT_EQUAL(s1
,s2
);
330 CPPUNIT_ASSERT_EQUAL(s1
,s2
);
331 const char *alphabet
="abcdefghijklmnopqrstuvwxyz";
333 std::string
s(alphabet
); // TODO
338 CPPUNIT_ASSERT_EQUAL(ref
,b
);
342 b
.chop(b
.length()-3);
344 CPPUNIT_ASSERT_EQUAL(ref
,b
);
346 { // chop at beginning
350 CPPUNIT_ASSERT_EQUAL(ref
,b
);
352 { // chop to zero length
356 CPPUNIT_ASSERT_EQUAL(ref
,b
);
358 { // chop beyond end (at npos)
360 b
.chop(SBuf::npos
,4);
362 CPPUNIT_ASSERT_EQUAL(ref
,b
);
366 b
.chop(b
.length()+2,4);
368 CPPUNIT_ASSERT_EQUAL(ref
,b
);
372 b
.chop(0,b
.length());
374 CPPUNIT_ASSERT_EQUAL(ref
,b
);
376 { // overflow chopped area
378 b
.chop(b
.length()-3,b
.length());
380 CPPUNIT_ASSERT_EQUAL(ref
,b
);
385 testSBuf::testChomp()
387 SBuf
s1("complete string");
390 CPPUNIT_ASSERT_EQUAL(s1
,s2
);
391 s2
.assign(" complete string ,");
393 CPPUNIT_ASSERT_EQUAL(s1
,s2
);
394 s1
.assign(", complete string ,");
397 CPPUNIT_ASSERT_EQUAL(s1
,s2
);
400 // inspired to SBufFindTest; to be expanded.
401 class SBufSubstrAutoTest
404 std::string fullReference
, str
;
406 void performEqualityTest() {
408 CPPUNIT_ASSERT_EQUAL(ref
,sb
);
410 SBufSubstrAutoTest() : fullString(fox
), fullReference(fox
) {
411 for (int offset
=fullString
.length()-1; offset
>= 0; --offset
) {
412 for (int length
=fullString
.length()-1-offset
; length
>= 0; --length
) {
413 sb
=fullString
.substr(offset
,length
);
414 str
=fullReference
.substr(offset
,length
);
415 performEqualityTest();
422 testSBuf::testSubstr()
424 SBuf
s1(literal
),s2
,s3
;
427 CPPUNIT_ASSERT_EQUAL(s2
,s3
);
429 CPPUNIT_ASSERT_EQUAL(s1
,s2
);
430 SBufSubstrAutoTest sat
; // work done in the constructor
434 testSBuf::testFindChar()
436 const char *alphabet
="abcdefghijklmnopqrstuvwxyz";
439 SBuf::size_type nposResult
=SBuf::npos
;
442 // needle in haystack
444 CPPUNIT_ASSERT_EQUAL(3,idx
);
445 CPPUNIT_ASSERT_EQUAL('d',s1
[idx
]);
447 // needle not present in haystack
448 idx
=s1
.find(' '); //fails
449 CPPUNIT_ASSERT_EQUAL(nposResult
,idx
);
453 CPPUNIT_ASSERT_EQUAL(4,idx
);
455 // char not in searched portion
457 CPPUNIT_ASSERT_EQUAL(nposResult
,idx
);
459 // invalid start position
460 idx
=s1
.find('d',SBuf::npos
);
461 CPPUNIT_ASSERT_EQUAL(nposResult
,idx
);
463 // invalid start position
464 idx
=s1
.find('d', -5);
465 CPPUNIT_ASSERT_EQUAL(3, idx
);
467 // search outside of haystack
468 idx
=s1
.find('d',s1
.length()+1);
469 CPPUNIT_ASSERT_EQUAL(nposResult
,idx
);
472 // needle in haystack
474 CPPUNIT_ASSERT_EQUAL(3, idx
);
475 CPPUNIT_ASSERT_EQUAL('d', s1
[idx
]);
477 // needle not present in haystack
478 idx
=s1
.rfind(' '); //fails
479 CPPUNIT_ASSERT_EQUAL(nposResult
,idx
);
483 CPPUNIT_ASSERT_EQUAL(4,idx
);
485 // char not in searched portion
487 CPPUNIT_ASSERT_EQUAL(nposResult
,idx
);
489 // invalid start position
490 idx
=s1
.rfind('d', -5);
491 CPPUNIT_ASSERT_EQUAL(nposResult
,idx
);
493 // overlong haystack specification
494 idx
=s1
.rfind('d',s1
.length()+1);
495 CPPUNIT_ASSERT_EQUAL(3,idx
);
499 testSBuf::testFindSBuf()
501 const char *alphabet
="abcdefghijklmnopqrstuvwxyz";
502 SBuf
haystack(alphabet
);
504 SBuf::size_type nposResult
=SBuf::npos
;
507 // needle in haystack
508 idx
= haystack
.find(SBuf("def"));
509 CPPUNIT_ASSERT_EQUAL(3,idx
);
511 idx
= haystack
.find(SBuf("xyz"));
512 CPPUNIT_ASSERT_EQUAL(23,idx
);
514 // needle not in haystack, no initial char match
515 idx
= haystack
.find(SBuf(" eq"));
516 CPPUNIT_ASSERT_EQUAL(nposResult
, idx
);
518 // needle not in haystack, initial sequence match
519 idx
= haystack
.find(SBuf("deg"));
520 CPPUNIT_ASSERT_EQUAL(nposResult
, idx
);
522 // needle past end of haystack
523 idx
= haystack
.find(SBuf("xyz1"));
524 CPPUNIT_ASSERT_EQUAL(nposResult
, idx
);
526 // search in portion: needle not in searched part
527 idx
= haystack
.find(SBuf("def"),7);
528 CPPUNIT_ASSERT_EQUAL(nposResult
, idx
);
530 // search in portion: overhang
531 idx
= haystack
.find(SBuf("def"),4);
532 CPPUNIT_ASSERT_EQUAL(nposResult
, idx
);
534 // invalid start position
535 idx
= haystack
.find(SBuf("def"),SBuf::npos
);
536 CPPUNIT_ASSERT_EQUAL(nposResult
, idx
);
538 // invalid start position: negative
539 idx
= haystack
.find(SBuf("def"),-5);
540 CPPUNIT_ASSERT_EQUAL(3, idx
);
542 // needle bigger than haystack
543 idx
= SBuf("def").find(haystack
);
544 CPPUNIT_ASSERT_EQUAL(nposResult
, idx
);
546 // search in a double-matching haystack
551 idx
= h2
.find(SBuf("def"));
552 CPPUNIT_ASSERT_EQUAL(3,idx
);
554 idx
= h2
.find(SBuf("xyzab"));
555 CPPUNIT_ASSERT_EQUAL(23,idx
);
559 // needle in haystack
560 idx
= haystack
.rfind(SBuf("def"));
561 CPPUNIT_ASSERT_EQUAL(3,idx
);
563 idx
= haystack
.rfind(SBuf("xyz"));
564 CPPUNIT_ASSERT_EQUAL(23,idx
);
566 // needle not in haystack, no initial char match
567 idx
= haystack
.rfind(SBuf(" eq"));
568 CPPUNIT_ASSERT_EQUAL(nposResult
, idx
);
570 // needle not in haystack, initial sequence match
571 idx
= haystack
.rfind(SBuf("deg"));
572 CPPUNIT_ASSERT_EQUAL(nposResult
, idx
);
574 // needle past end of haystack
575 idx
= haystack
.rfind(SBuf("xyz1"));
576 CPPUNIT_ASSERT_EQUAL(nposResult
, idx
);
578 // search in portion: needle in searched part
579 idx
= haystack
.rfind(SBuf("def"),7);
580 CPPUNIT_ASSERT_EQUAL(3, idx
);
582 // search in portion: needle not in searched part
583 idx
= haystack
.rfind(SBuf("mno"),3);
584 CPPUNIT_ASSERT_EQUAL(nposResult
, idx
);
586 // search in portion: overhang
587 idx
= haystack
.rfind(SBuf("def"),4);
588 CPPUNIT_ASSERT_EQUAL(3, idx
);
590 // npos start position
591 idx
= haystack
.rfind(SBuf("def"),SBuf::npos
);
592 CPPUNIT_ASSERT_EQUAL(3, idx
);
594 // invalid start position: negative
595 idx
= haystack
.rfind(SBuf("def"),-5);
596 CPPUNIT_ASSERT_EQUAL(nposResult
, idx
);
598 // needle bigger than haystack
599 idx
= SBuf("def").rfind(haystack
);
600 CPPUNIT_ASSERT_EQUAL(nposResult
, idx
);
602 // search in a double-matching haystack
607 idx
= h2
.rfind(SBuf("def"));
608 CPPUNIT_ASSERT_EQUAL(29,idx
);
610 idx
= h2
.find(SBuf("xyzab"));
611 CPPUNIT_ASSERT_EQUAL(23,idx
);
616 testSBuf::testRFindChar()
621 CPPUNIT_ASSERT_EQUAL(40,idx
);
622 CPPUNIT_ASSERT_EQUAL(' ',s1
[idx
]);
626 testSBuf::testRFindSBuf()
628 SBuf
haystack(literal
),afox("fox");
629 SBuf
goobar("goobar");
632 // corner case: search for a zero-length SBuf
633 idx
=haystack
.rfind(SBuf(""));
634 CPPUNIT_ASSERT_EQUAL(haystack
.length(),idx
);
636 // corner case: search for a needle longer than the haystack
637 idx
=afox
.rfind(SBuf(" "));
638 CPPUNIT_ASSERT_EQUAL(SBuf::npos
,idx
);
640 idx
=haystack
.rfind(SBuf("fox"));
641 CPPUNIT_ASSERT_EQUAL(16,idx
);
643 // needle not found, no match for first char
644 idx
=goobar
.rfind(SBuf("foo"));
645 CPPUNIT_ASSERT_EQUAL(SBuf::npos
,idx
);
647 // needle not found, match for first char but no match for SBuf
648 idx
=haystack
.rfind(SBuf("foe"));
649 CPPUNIT_ASSERT_EQUAL(SBuf::npos
,idx
);
651 SBuf
g("g"); //match at the last char
652 idx
=haystack
.rfind(g
);
653 CPPUNIT_ASSERT_EQUAL(43,idx
);
654 CPPUNIT_ASSERT_EQUAL('g',haystack
[idx
]);
656 idx
=haystack
.rfind(SBuf("The"));
657 CPPUNIT_ASSERT_EQUAL(0,idx
);
659 haystack
.append("The");
660 idx
=haystack
.rfind(SBuf("The"));
661 CPPUNIT_ASSERT_EQUAL(44,idx
);
664 haystack
="The quick brown fox";
665 SBuf
needle("foxy lady");
666 idx
=haystack
.rfind(needle
);
667 CPPUNIT_ASSERT_EQUAL(SBuf::npos
,idx
);
671 testSBuf::testSBufLength()
674 CPPUNIT_ASSERT_EQUAL(strlen(fox
),(size_t)s
.length());
678 testSBuf::testScanf()
685 s1
.assign("string , 123 , 123.50");
686 rv
=s1
.scanf("%s , %d , %f",s
,&i
,&f
);
687 CPPUNIT_ASSERT_EQUAL(3,rv
);
688 CPPUNIT_ASSERT_EQUAL(0,strcmp(s
,"string"));
689 CPPUNIT_ASSERT_EQUAL(123,i
);
690 CPPUNIT_ASSERT_EQUAL(static_cast<float>(123.5),f
);
693 void testSBuf::testCopy()
695 char buf
[40]; //shorter than literal()
697 CPPUNIT_ASSERT_EQUAL(s
.length(),s
.copy(buf
,40));
698 CPPUNIT_ASSERT_EQUAL(0,strncmp(s
.rawContent(),buf
,s
.length()));
700 CPPUNIT_ASSERT_EQUAL(40,s
.copy(buf
,40));
703 CPPUNIT_ASSERT_EQUAL(s2
,s
);
706 void testSBuf::testStringOps()
708 SBuf
sng(literal
.toLower()),
709 ref("the quick brown fox jumped over the lazy dog");
710 CPPUNIT_ASSERT_EQUAL(ref
,sng
);
712 CPPUNIT_ASSERT_EQUAL(0,sng
.compare(ref
,caseInsensitive
));
713 // max-size comparison
714 CPPUNIT_ASSERT_EQUAL(0,ref
.compare(SBuf("THE"),caseInsensitive
,3));
715 CPPUNIT_ASSERT_EQUAL(1,ref
.compare(SBuf("THE"),caseInsensitive
,6));
716 CPPUNIT_ASSERT_EQUAL(0,SBuf("the").compare(SBuf("THE"),caseInsensitive
,6));
719 void testSBuf::testGrow()
723 const char *ref
=t
.rawContent();
724 t
.reserveCapacity(10240);
725 const char *match
=t
.rawContent();
726 CPPUNIT_ASSERT(match
!=ref
);
728 t
.append(literal
).append(literal
).append(literal
).append(literal
).append(literal
);
729 t
.append(t
).append(t
).append(t
).append(t
).append(t
);
730 CPPUNIT_ASSERT_EQUAL(ref
,match
);
733 void testSBuf::testStartsWith()
735 static SBuf
casebuf("THE QUICK");
736 CPPUNIT_ASSERT(literal
.startsWith(SBuf(fox1
)));
737 CPPUNIT_ASSERT(!SBuf("The quick brown").startsWith(SBuf(fox1
))); //too short
738 CPPUNIT_ASSERT(!literal
.startsWith(SBuf(fox2
))); //different contents
740 // case-insensitive checks
741 CPPUNIT_ASSERT(literal
.startsWith(casebuf
,caseInsensitive
));
742 casebuf
=SBuf(fox1
).toUpper();
743 CPPUNIT_ASSERT(literal
.startsWith(casebuf
,caseInsensitive
));
744 CPPUNIT_ASSERT(literal
.startsWith(SBuf(fox1
),caseInsensitive
));
745 casebuf
= "tha quick";
746 CPPUNIT_ASSERT_EQUAL(false,literal
.startsWith(casebuf
,caseInsensitive
));
749 void testSBuf::testSBufStream()
751 SBuf
b("const.string, int 10 and a float 10.5");
753 ss
<< "const.string, int " << 10 << " and a float " << 10.5;
755 CPPUNIT_ASSERT_EQUAL(b
,o
);
758 CPPUNIT_ASSERT_EQUAL(SBuf(),o
);
762 CPPUNIT_ASSERT_EQUAL(ss2
.buf(),literal
);
763 CPPUNIT_ASSERT_EQUAL(f1
,SBuf(fox1
));
766 void testSBuf::testFindFirstOf()
768 SBuf
haystack(literal
);
772 idx
=haystack
.find_first_of(SBuf("ADHRWYP"));
773 CPPUNIT_ASSERT_EQUAL(SBuf::npos
,idx
);
775 // found at beginning
776 idx
=haystack
.find_first_of(SBuf("THANDF"));
777 CPPUNIT_ASSERT_EQUAL(0,idx
);
779 //found at end of haystack
780 idx
=haystack
.find_first_of(SBuf("QWERYVg"));
781 CPPUNIT_ASSERT_EQUAL(haystack
.length()-1,idx
);
783 //found in the middle of haystack
784 idx
=haystack
.find_first_of(SBuf("QWERqYV"));
785 CPPUNIT_ASSERT_EQUAL(4,idx
);
788 void testSBuf::testAutoFind()
794 void testSBuf::testStdStringOps()
796 const char *alphabet
="abcdefghijklmnopqrstuvwxyz";
797 std::string
astr(alphabet
);
799 CPPUNIT_ASSERT_EQUAL(astr
,sb
.toStdString());