Some more tests for BString
git-svn-id: file:///srv/svn/repos/haiku/trunk/current@1533 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
21b4758ca8
commit
96acb96728
134
src/tests/kits/support/bstring/StringCompareTest.cpp
Normal file
134
src/tests/kits/support/bstring/StringCompareTest.cpp
Normal file
@ -0,0 +1,134 @@
|
||||
#include "StringCompareTest.h"
|
||||
#include "cppunit/TestCaller.h"
|
||||
#include <String.h>
|
||||
|
||||
StringCompareTest::StringCompareTest(std::string name) :
|
||||
BTestCase(name)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
|
||||
StringCompareTest::~StringCompareTest()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
StringCompareTest::PerformTest(void)
|
||||
{
|
||||
BString *string1, *string2;
|
||||
|
||||
//operator<(const BString &) const;
|
||||
NextSubTest();
|
||||
string1 = new BString("11111_a");
|
||||
string2 = new BString("22222_b");
|
||||
CPPUNIT_ASSERT(*string1 < *string2);
|
||||
delete string1;
|
||||
delete string2;
|
||||
|
||||
//operator<=(const BString &) const;
|
||||
NextSubTest();
|
||||
string1 = new BString("11111_a");
|
||||
string2 = new BString("22222_b");
|
||||
CPPUNIT_ASSERT(*string1 <= *string2);
|
||||
delete string1;
|
||||
delete string2;
|
||||
|
||||
NextSubTest();
|
||||
string1 = new BString("11111");
|
||||
string2 = new BString("11111");
|
||||
CPPUNIT_ASSERT(*string1 <= *string2);
|
||||
delete string1;
|
||||
delete string2;
|
||||
|
||||
//operator==(const BString &) const;
|
||||
NextSubTest();
|
||||
string1 = new BString("string");
|
||||
string2 = new BString("string");
|
||||
CPPUNIT_ASSERT(*string1 == *string2);
|
||||
delete string1;
|
||||
delete string2;
|
||||
|
||||
NextSubTest();
|
||||
string1 = new BString("text");
|
||||
string2 = new BString("string");
|
||||
CPPUNIT_ASSERT((*string1 == *string2) == false);
|
||||
delete string1;
|
||||
delete string2;
|
||||
|
||||
//operator>=(const BString &) const;
|
||||
NextSubTest();
|
||||
string1 = new BString("BBBBB");
|
||||
string2 = new BString("AAAAA");
|
||||
CPPUNIT_ASSERT(*string1 >= *string2);
|
||||
delete string1;
|
||||
delete string2;
|
||||
|
||||
NextSubTest();
|
||||
string1 = new BString("11111");
|
||||
string2 = new BString("11111");
|
||||
CPPUNIT_ASSERT(*string1 >= *string2);
|
||||
delete string1;
|
||||
delete string2;
|
||||
|
||||
//operator>(const BString &) const;
|
||||
NextSubTest();
|
||||
string1 = new BString("BBBBB");
|
||||
string2 = new BString("AAAAA");
|
||||
CPPUNIT_ASSERT(*string1 > *string2);
|
||||
delete string1;
|
||||
delete string2;
|
||||
|
||||
//operator!=(const BString &) const;
|
||||
NextSubTest();
|
||||
string1 = new BString("string");
|
||||
string2 = new BString("string");
|
||||
CPPUNIT_ASSERT((*string1 != *string2) == false);
|
||||
delete string1;
|
||||
delete string2;
|
||||
|
||||
NextSubTest();
|
||||
string1 = new BString("text");
|
||||
string2 = new BString("string");
|
||||
CPPUNIT_ASSERT(*string1 != *string2);
|
||||
delete string1;
|
||||
delete string2;
|
||||
|
||||
//operator<(const char *) const;
|
||||
NextSubTest();
|
||||
string1 = new BString("AAAAA");
|
||||
CPPUNIT_ASSERT(*string1 < "BBBBB");
|
||||
delete string1;
|
||||
|
||||
//operator<=(const char *) const;
|
||||
NextSubTest();
|
||||
string1 = new BString("AAAAA");
|
||||
CPPUNIT_ASSERT(*string1 <= "BBBBB");
|
||||
CPPUNIT_ASSERT(*string1 <= "AAAAA");
|
||||
delete string1;
|
||||
|
||||
//operator==(const char *) const;
|
||||
NextSubTest();
|
||||
string1 = new BString("AAAAA");
|
||||
CPPUNIT_ASSERT(*string1 == "AAAAA");
|
||||
delete string1;
|
||||
|
||||
NextSubTest();
|
||||
string1 = new BString("AAAAA");
|
||||
CPPUNIT_ASSERT((*string1 == "BBBB") == false);
|
||||
delete string1;
|
||||
|
||||
//operator>=(const char *) const;
|
||||
//operator>(const char *) const;
|
||||
//operator!=(const char *) const;
|
||||
}
|
||||
|
||||
|
||||
CppUnit::Test *StringCompareTest::suite(void)
|
||||
{
|
||||
typedef CppUnit::TestCaller<StringCompareTest>
|
||||
StringCompareTestCaller;
|
||||
|
||||
return(new StringCompareTestCaller("BString::Compare Test", &StringCompareTest::PerformTest));
|
||||
}
|
22
src/tests/kits/support/bstring/StringCompareTest.h
Normal file
22
src/tests/kits/support/bstring/StringCompareTest.h
Normal file
@ -0,0 +1,22 @@
|
||||
#ifndef StringCompareTest_H
|
||||
#define StringCompareTest_H
|
||||
|
||||
#include "TestCase.h"
|
||||
#include <String.h>
|
||||
|
||||
|
||||
class StringCompareTest : public BTestCase
|
||||
{
|
||||
|
||||
private:
|
||||
|
||||
protected:
|
||||
|
||||
public:
|
||||
static Test *suite(void);
|
||||
void PerformTest(void);
|
||||
StringCompareTest(std::string name = "");
|
||||
virtual ~StringCompareTest();
|
||||
};
|
||||
|
||||
#endif
|
@ -73,7 +73,46 @@ StringInsertTest::PerformTest(void)
|
||||
CPPUNIT_ASSERT(strcmp(str1->String(), "strPPPPPing") == 0);
|
||||
delete str1;
|
||||
|
||||
//Insert(BString&)
|
||||
NextSubTest();
|
||||
str1 = new BString("string");
|
||||
str2 = new BString("INSERTED");
|
||||
str1->Insert(*str2, 0);
|
||||
CPPUNIT_ASSERT(strcmp(str1->String(), "INSERTEDstring") == 0);
|
||||
delete str1;
|
||||
delete str2;
|
||||
|
||||
NextSubTest();
|
||||
str1 = new BString("string");
|
||||
str1->Insert(*str1, 0);
|
||||
CPPUNIT_ASSERT(strcmp(str1->String(), "string") == 0);
|
||||
delete str1;
|
||||
|
||||
NextSubTest();
|
||||
str1 = new BString;
|
||||
str2 = new BString("INSERTED");
|
||||
str1->Insert(*str2, -1);
|
||||
CPPUNIT_ASSERT(strcmp(str1->String(), "NSERTED") == 0);
|
||||
delete str1;
|
||||
delete str2;
|
||||
|
||||
//&Insert(BString &, int32 length, int32 pos);
|
||||
NextSubTest();
|
||||
str1 = new BString("string");
|
||||
str2 = new BString("INSERTED");
|
||||
str1->Insert(*str2, 2, 2);
|
||||
CPPUNIT_ASSERT(strcmp(str1->String(), "stINring") == 0);
|
||||
delete str1;
|
||||
delete str2;
|
||||
|
||||
//&Insert(BString&, int32 fromOffset, int32 length, int32 pos);
|
||||
NextSubTest();
|
||||
str1 = new BString("string");
|
||||
str2 = new BString("INSERTED");
|
||||
str1->Insert(*str2, 4, 30, 2);
|
||||
CPPUNIT_ASSERT(strcmp(str1->String(), "stRTEDring") == 0);
|
||||
delete str1;
|
||||
delete str2;
|
||||
}
|
||||
|
||||
|
||||
|
@ -95,6 +95,152 @@ StringRemoveTest::PerformTest(void)
|
||||
string1->Remove(-3, 5);
|
||||
CPPUNIT_ASSERT(strcmp(string1->String(), "ing") == 0);
|
||||
delete string1;
|
||||
|
||||
//RemoveFirst(BString&)
|
||||
NextSubTest();
|
||||
string1 = new BString("first second first");
|
||||
string2 = new BString("first");
|
||||
string1->RemoveFirst(*string2);
|
||||
CPPUNIT_ASSERT(strcmp(string1->String(), " second first") == 0);
|
||||
delete string1;
|
||||
delete string2;
|
||||
|
||||
NextSubTest();
|
||||
string1 = new BString("first second first");
|
||||
string2 = new BString("noway");
|
||||
string1->RemoveFirst(*string2);
|
||||
CPPUNIT_ASSERT(strcmp(string1->String(), "first second first") == 0);
|
||||
delete string1;
|
||||
delete string2;
|
||||
|
||||
//RemoveLast(Bstring&)
|
||||
NextSubTest();
|
||||
string1 = new BString("first second first");
|
||||
string2 = new BString("first");
|
||||
string1->RemoveLast(*string2);
|
||||
CPPUNIT_ASSERT(strcmp(string1->String(), "first second ") == 0);
|
||||
delete string1;
|
||||
delete string2;
|
||||
|
||||
NextSubTest();
|
||||
string1 = new BString("first second first");
|
||||
string2 = new BString("noway");
|
||||
string1->RemoveLast(*string2);
|
||||
CPPUNIT_ASSERT(strcmp(string1->String(), "first second first") == 0);
|
||||
delete string1;
|
||||
delete string2;
|
||||
|
||||
//RemoveAll(BString&)
|
||||
NextSubTest();
|
||||
string1 = new BString("first second first");
|
||||
string2 = new BString("first");
|
||||
string1->RemoveAll(*string2);
|
||||
CPPUNIT_ASSERT(strcmp(string1->String(), " second ") == 0);
|
||||
delete string1;
|
||||
delete string2;
|
||||
|
||||
NextSubTest();
|
||||
string1 = new BString("first second first");
|
||||
string2 = new BString("noway");
|
||||
string1->RemoveAll(*string2);
|
||||
CPPUNIT_ASSERT(strcmp(string1->String(), "first second first") == 0);
|
||||
delete string1;
|
||||
delete string2;
|
||||
|
||||
//RemoveFirst(const char*)
|
||||
NextSubTest();
|
||||
string1 = new BString("first second first");
|
||||
string1->RemoveFirst("first");
|
||||
CPPUNIT_ASSERT(strcmp(string1->String(), " second first") == 0);
|
||||
delete string1;
|
||||
|
||||
NextSubTest();
|
||||
string1 = new BString("first second first");
|
||||
string1->RemoveFirst("noway");
|
||||
CPPUNIT_ASSERT(strcmp(string1->String(), "first second first") == 0);
|
||||
delete string1;
|
||||
|
||||
NextSubTest();
|
||||
string1 = new BString("first second first");
|
||||
string1->RemoveFirst((char*)NULL);
|
||||
CPPUNIT_ASSERT(strcmp(string1->String(), "first second first") == 0);
|
||||
delete string1;
|
||||
|
||||
//RemoveLast(const char*)
|
||||
NextSubTest();
|
||||
string1 = new BString("first second first");
|
||||
string1->RemoveLast("first");
|
||||
CPPUNIT_ASSERT(strcmp(string1->String(), "first second ") == 0);
|
||||
delete string1;
|
||||
|
||||
NextSubTest();
|
||||
string1 = new BString("first second first");
|
||||
string1->RemoveLast("noway");
|
||||
CPPUNIT_ASSERT(strcmp(string1->String(), "first second first") == 0);
|
||||
delete string1;
|
||||
|
||||
//RemoveAll(const char*)
|
||||
NextSubTest();
|
||||
string1 = new BString("first second first");
|
||||
string1->RemoveAll("first");
|
||||
CPPUNIT_ASSERT(strcmp(string1->String(), " second ") == 0);
|
||||
delete string1;
|
||||
|
||||
NextSubTest();
|
||||
string1 = new BString("first second first");
|
||||
string1->RemoveAll("noway");
|
||||
CPPUNIT_ASSERT(strcmp(string1->String(), "first second first") == 0);
|
||||
delete string1;
|
||||
|
||||
//RemoveSet(const char*)
|
||||
NextSubTest();
|
||||
string1 = new BString("a sentence with (3) (642) numbers (2) in it");
|
||||
string1->RemoveSet("()3624 ");
|
||||
CPPUNIT_ASSERT(strcmp(string1->String(), "asentencewithnumbersinit") == 0);
|
||||
delete string1;
|
||||
|
||||
NextSubTest();
|
||||
string1 = new BString("a string");
|
||||
string1->RemoveSet("1345");
|
||||
CPPUNIT_ASSERT(strcmp(string1->String(), "a string") == 0);
|
||||
delete string1;
|
||||
|
||||
//MoveInto(BString &into, int32, int32)
|
||||
NextSubTest();
|
||||
string1 = new BString("some text");
|
||||
string2 = new BString("string");
|
||||
string2->MoveInto(*string1, 3, 2);
|
||||
CPPUNIT_ASSERT(strcmp(string1->String(), "in") == 0);
|
||||
CPPUNIT_ASSERT(strcmp(string2->String(), "strg") == 0);
|
||||
delete string1;
|
||||
delete string2;
|
||||
|
||||
NextSubTest();
|
||||
string1 = new BString("some text");
|
||||
string2 = new BString("string");
|
||||
string2->MoveInto(*string1, 0, 200);
|
||||
CPPUNIT_ASSERT(strcmp(string1->String(), "string") == 0);
|
||||
CPPUNIT_ASSERT(strcmp(string2->String(), "string") == 0);
|
||||
delete string1;
|
||||
delete string2;
|
||||
|
||||
//MoveInto(char *, int32, int32)
|
||||
NextSubTest();
|
||||
char dest[100];
|
||||
memset(dest, 0, 100);
|
||||
string1 = new BString("some text");
|
||||
string1->MoveInto(dest, 3, 2);
|
||||
CPPUNIT_ASSERT(strcmp(dest, "e ") == 0);
|
||||
CPPUNIT_ASSERT(strcmp(string1->String(), "somtext") == 0);
|
||||
delete string1;
|
||||
|
||||
NextSubTest();
|
||||
string1 = new BString("some text");
|
||||
memset(dest, 0, 100);
|
||||
string1->MoveInto(dest, 0, 50);
|
||||
CPPUNIT_ASSERT(strcmp(dest, "some text") == 0);
|
||||
CPPUNIT_ASSERT(strcmp(string1->String(), "some text") == 0);
|
||||
delete string1;
|
||||
}
|
||||
|
||||
|
||||
|
@ -11,6 +11,7 @@
|
||||
#include "StringInsertTest.h"
|
||||
#include "StringEscapeTest.h"
|
||||
#include "StringRemoveTest.h"
|
||||
#include "StringCompareTest.h"
|
||||
|
||||
CppUnit::Test *StringTestSuite()
|
||||
{
|
||||
@ -26,6 +27,7 @@ CppUnit::Test *StringTestSuite()
|
||||
testSuite->addTest(StringInsertTest::suite());
|
||||
testSuite->addTest(StringEscapeTest::suite());
|
||||
testSuite->addTest(StringRemoveTest::suite());
|
||||
testSuite->addTest(StringCompareTest::suite());
|
||||
|
||||
return(testSuite);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user