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:
Stefano Ceccherini 2002-11-04 10:54:04 +00:00
parent 10beef3e41
commit eb071be319
4 changed files with 107 additions and 0 deletions

View File

@ -64,6 +64,7 @@ CommonTestLib libsupporttest.so
StringFormatAppendTest.cpp
StringCharAccessTest.cpp
StringSearchTest.cpp
StringReplaceTest.cpp
: <boot!home!config!lib>libopenbeos.so
be stdc++.r4

View 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));
}

View 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

View File

@ -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);