xref: /haiku/src/tests/kits/support/bstring/StringReplaceTest.cpp (revision eb071be3190b875efcb1da7dd5771ddcaf49b73b)
1 #include "StringReplaceTest.h"
2 #include "cppunit/TestCaller.h"
3 #include <String.h>
4 
5 StringReplaceTest::StringReplaceTest(std::string name) :
6 		BTestCase(name)
7 {
8 }
9 
10 
11 
12 StringReplaceTest::~StringReplaceTest()
13 {
14 }
15 
16 
17 void
18 StringReplaceTest::PerformTest(void)
19 {
20 	BString *str1, *str2;
21 
22 	//&ReplaceFirst(char, char);
23 	NextSubTest();
24 	str1 = new BString("test string");
25 	str1->ReplaceFirst('t', 'b');
26 	CPPUNIT_ASSERT(strcmp(str1->String(), "best string") == 0);
27 	delete str1;
28 
29 	NextSubTest();
30 	str1 = new BString("test string");
31 	str1->ReplaceFirst('x', 'b');
32 	CPPUNIT_ASSERT(strcmp(str1->String(), "test string") == 0);
33 	delete str1;
34 
35 	//&ReplaceLast(char, char);
36 	NextSubTest();
37 	str1 = new BString("test string");
38 	str1->ReplaceLast('t', 'w');
39 	CPPUNIT_ASSERT(strcmp(str1->String(), "test swring") == 0);
40 	delete str1;
41 
42 	NextSubTest();
43 	str1 = new BString("test string");
44 	str1->ReplaceLast('x', 'b');
45 	CPPUNIT_ASSERT(strcmp(str1->String(), "test string") == 0);
46 	delete str1;
47 
48 	//&ReplaceAll(char, char, int32);
49 	NextSubTest();
50 	str1 = new BString("test string");
51 	str1->ReplaceAll('t', 'i');
52 	CPPUNIT_ASSERT(strcmp(str1->String(), "iesi siring") == 0);
53 	delete str1;
54 
55 	NextSubTest();
56 	str1 = new BString("test string");
57 	str1->ReplaceAll('x', 'b');
58 	CPPUNIT_ASSERT(strcmp(str1->String(), "test string") == 0);
59 	delete str1;
60 
61 	NextSubTest();
62 	str1 = new BString("test string");
63 	str1->ReplaceAll('t', 'i', 2);
64 	CPPUNIT_ASSERT(strcmp(str1->String(), "tesi siring") == 0);
65 	delete str1;
66 
67 	//&Replace(char, char, int32, int32)
68 	NextSubTest();
69 	str1 = new BString("she sells sea shells on the sea shore");
70 	str1->Replace('s' 't', 4, 2);
71 	CPPUNIT_ASSERT(strcmp(str1->String(), "she tellt tea thells on the sea shore") == 0);
72 	delete str1;
73 }
74 
75 
76 CppUnit::Test *StringReplaceTest::suite(void)
77 {
78 	typedef CppUnit::TestCaller<StringReplaceTest>
79 		StringReplaceTestCaller;
80 
81 	return(new StringReplaceTestCaller("BString::Replace Test", &StringReplaceTest::PerformTest));
82 }
83