diff --git a/src/tests/kits/support/Jamfile b/src/tests/kits/support/Jamfile index 87fc1dd13d..00d3a63627 100644 --- a/src/tests/kits/support/Jamfile +++ b/src/tests/kits/support/Jamfile @@ -64,6 +64,7 @@ CommonTestLib libsupporttest.so StringFormatAppendTest.cpp StringCharAccessTest.cpp StringSearchTest.cpp + StringReplaceTest.cpp : libopenbeos.so be stdc++.r4 diff --git a/src/tests/kits/support/bstring/StringReplaceTest.cpp b/src/tests/kits/support/bstring/StringReplaceTest.cpp new file mode 100644 index 0000000000..69ec726463 --- /dev/null +++ b/src/tests/kits/support/bstring/StringReplaceTest.cpp @@ -0,0 +1,82 @@ +#include "StringReplaceTest.h" +#include "cppunit/TestCaller.h" +#include + +StringReplaceTest::StringReplaceTest(std::string name) : + BTestCase(name) +{ +} + + + +StringReplaceTest::~StringReplaceTest() +{ +} + + +void +StringReplaceTest::PerformTest(void) +{ + BString *str1, *str2; + + //&ReplaceFirst(char, char); + NextSubTest(); + str1 = new BString("test string"); + str1->ReplaceFirst('t', 'b'); + CPPUNIT_ASSERT(strcmp(str1->String(), "best string") == 0); + delete str1; + + NextSubTest(); + str1 = new BString("test string"); + str1->ReplaceFirst('x', 'b'); + CPPUNIT_ASSERT(strcmp(str1->String(), "test string") == 0); + delete str1; + + //&ReplaceLast(char, char); + NextSubTest(); + str1 = new BString("test string"); + str1->ReplaceLast('t', 'w'); + CPPUNIT_ASSERT(strcmp(str1->String(), "test swring") == 0); + delete str1; + + NextSubTest(); + str1 = new BString("test string"); + str1->ReplaceLast('x', 'b'); + CPPUNIT_ASSERT(strcmp(str1->String(), "test string") == 0); + delete str1; + + //&ReplaceAll(char, char, int32); + NextSubTest(); + str1 = new BString("test string"); + str1->ReplaceAll('t', 'i'); + CPPUNIT_ASSERT(strcmp(str1->String(), "iesi siring") == 0); + delete str1; + + NextSubTest(); + str1 = new BString("test string"); + str1->ReplaceAll('x', 'b'); + CPPUNIT_ASSERT(strcmp(str1->String(), "test string") == 0); + delete str1; + + NextSubTest(); + str1 = new BString("test string"); + str1->ReplaceAll('t', 'i', 2); + CPPUNIT_ASSERT(strcmp(str1->String(), "tesi siring") == 0); + delete str1; + + //&Replace(char, char, int32, int32) + NextSubTest(); + str1 = new BString("she sells sea shells on the sea shore"); + str1->Replace('s' 't', 4, 2); + CPPUNIT_ASSERT(strcmp(str1->String(), "she tellt tea thells on the sea shore") == 0); + delete str1; +} + + +CppUnit::Test *StringReplaceTest::suite(void) +{ + typedef CppUnit::TestCaller + StringReplaceTestCaller; + + return(new StringReplaceTestCaller("BString::Replace Test", &StringReplaceTest::PerformTest)); +} diff --git a/src/tests/kits/support/bstring/StringReplaceTest.h b/src/tests/kits/support/bstring/StringReplaceTest.h new file mode 100644 index 0000000000..96877396bd --- /dev/null +++ b/src/tests/kits/support/bstring/StringReplaceTest.h @@ -0,0 +1,22 @@ +#ifndef StringReplaceTest_H +#define StringReplaceTest_H + +#include "TestCase.h" +#include + + +class StringReplaceTest : public BTestCase +{ + +private: + +protected: + +public: + static Test *suite(void); + void PerformTest(void); + StringReplaceTest(std::string name = ""); + virtual ~StringReplaceTest(); + }; + +#endif diff --git a/src/tests/kits/support/bstring/StringTest.cpp b/src/tests/kits/support/bstring/StringTest.cpp index a754430559..5153b6077b 100644 --- a/src/tests/kits/support/bstring/StringTest.cpp +++ b/src/tests/kits/support/bstring/StringTest.cpp @@ -14,6 +14,7 @@ #include "StringCompareTest.h" #include "StringFormatAppendTest.h" #include "StringCharAccessTest.h" +#include "StringReplaceTest.h" #include "StringSearchTest.h" CppUnit::Test *StringTestSuite() @@ -33,6 +34,7 @@ CppUnit::Test *StringTestSuite() testSuite->addTest(StringCompareTest::suite()); testSuite->addTest(StringFormatAppendTest::suite()); testSuite->addTest(StringCharAccessTest::suite()); + testSuite->addTest(StringReplaceTest::suite()); testSuite->addTest(StringSearchTest::suite()); return(testSuite);