First tests for Replace*() methods (more should come later)
git-svn-id: file:///srv/svn/repos/haiku/trunk/current@1838 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
10beef3e41
commit
eb071be319
@ -64,6 +64,7 @@ CommonTestLib libsupporttest.so
|
|||||||
StringFormatAppendTest.cpp
|
StringFormatAppendTest.cpp
|
||||||
StringCharAccessTest.cpp
|
StringCharAccessTest.cpp
|
||||||
StringSearchTest.cpp
|
StringSearchTest.cpp
|
||||||
|
StringReplaceTest.cpp
|
||||||
|
|
||||||
: <boot!home!config!lib>libopenbeos.so
|
: <boot!home!config!lib>libopenbeos.so
|
||||||
be stdc++.r4
|
be stdc++.r4
|
||||||
|
82
src/tests/kits/support/bstring/StringReplaceTest.cpp
Normal file
82
src/tests/kits/support/bstring/StringReplaceTest.cpp
Normal file
@ -0,0 +1,82 @@
|
|||||||
|
#include "StringReplaceTest.h"
|
||||||
|
#include "cppunit/TestCaller.h"
|
||||||
|
#include <String.h>
|
||||||
|
|
||||||
|
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<StringReplaceTest>
|
||||||
|
StringReplaceTestCaller;
|
||||||
|
|
||||||
|
return(new StringReplaceTestCaller("BString::Replace Test", &StringReplaceTest::PerformTest));
|
||||||
|
}
|
22
src/tests/kits/support/bstring/StringReplaceTest.h
Normal file
22
src/tests/kits/support/bstring/StringReplaceTest.h
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
#ifndef StringReplaceTest_H
|
||||||
|
#define StringReplaceTest_H
|
||||||
|
|
||||||
|
#include "TestCase.h"
|
||||||
|
#include <String.h>
|
||||||
|
|
||||||
|
|
||||||
|
class StringReplaceTest : public BTestCase
|
||||||
|
{
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
protected:
|
||||||
|
|
||||||
|
public:
|
||||||
|
static Test *suite(void);
|
||||||
|
void PerformTest(void);
|
||||||
|
StringReplaceTest(std::string name = "");
|
||||||
|
virtual ~StringReplaceTest();
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
@ -14,6 +14,7 @@
|
|||||||
#include "StringCompareTest.h"
|
#include "StringCompareTest.h"
|
||||||
#include "StringFormatAppendTest.h"
|
#include "StringFormatAppendTest.h"
|
||||||
#include "StringCharAccessTest.h"
|
#include "StringCharAccessTest.h"
|
||||||
|
#include "StringReplaceTest.h"
|
||||||
#include "StringSearchTest.h"
|
#include "StringSearchTest.h"
|
||||||
|
|
||||||
CppUnit::Test *StringTestSuite()
|
CppUnit::Test *StringTestSuite()
|
||||||
@ -33,6 +34,7 @@ CppUnit::Test *StringTestSuite()
|
|||||||
testSuite->addTest(StringCompareTest::suite());
|
testSuite->addTest(StringCompareTest::suite());
|
||||||
testSuite->addTest(StringFormatAppendTest::suite());
|
testSuite->addTest(StringFormatAppendTest::suite());
|
||||||
testSuite->addTest(StringCharAccessTest::suite());
|
testSuite->addTest(StringCharAccessTest::suite());
|
||||||
|
testSuite->addTest(StringReplaceTest::suite());
|
||||||
testSuite->addTest(StringSearchTest::suite());
|
testSuite->addTest(StringSearchTest::suite());
|
||||||
|
|
||||||
return(testSuite);
|
return(testSuite);
|
||||||
|
Loading…
Reference in New Issue
Block a user