More tests for BString
git-svn-id: file:///srv/svn/repos/haiku/trunk/current@1487 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
1be7ab5229
commit
6903f4c65f
@ -60,6 +60,7 @@ CommonTestLib libsupporttest.so
|
||||
StringCaseTest.cpp
|
||||
StringInsertTest.cpp
|
||||
StringEscapeTest.cpp
|
||||
StringRemoveTest.cpp
|
||||
|
||||
: <boot!home!config!lib>libopenbeos.so
|
||||
be stdc++.r4
|
||||
|
@ -19,11 +19,98 @@ StringEscapeTest::PerformTest(void)
|
||||
{
|
||||
BString *string1, *string2;
|
||||
|
||||
//CharacterEscape(char*, char)
|
||||
NextSubTest();
|
||||
string1 = new BString("abcdefghi");
|
||||
string1->CharacterEscape("acf", '/');
|
||||
CPPUNIT_ASSERT(strcmp(string1->String(), "/ab/cde/fghi") == 0);
|
||||
delete string1;
|
||||
delete string1;
|
||||
|
||||
//BString is null
|
||||
NextSubTest();
|
||||
string1 = new BString;
|
||||
string1->CharacterEscape("abc", '/');
|
||||
CPPUNIT_ASSERT(strcmp(string1->String(), "") == 0);
|
||||
delete string1;
|
||||
|
||||
//BString doesn't contain wanted characters
|
||||
NextSubTest();
|
||||
string1 = new BString("abcdefghi");
|
||||
string1->CharacterEscape("z34", 'z');
|
||||
CPPUNIT_ASSERT(strcmp(string1->String(), "abcdefghi") == 0);
|
||||
delete string1;
|
||||
|
||||
//CharacterEscape(char *, char*, char)
|
||||
NextSubTest();
|
||||
string1 = new BString("something");
|
||||
string1->CharacterEscape("newstring", "esi", '0');
|
||||
CPPUNIT_ASSERT(strcmp(string1->String(), "n0ew0str0ing") == 0);
|
||||
delete string1;
|
||||
|
||||
//assigned string is NULL
|
||||
//commented out as it crashes r5 implementation
|
||||
//NextSubTest();
|
||||
//string1 = new BString("something");
|
||||
//string1->CharacterEscape((char*)NULL, "ei", '-');
|
||||
//CPPUNIT_ASSERT(strcmp(string1->String(), "") == 0);
|
||||
//delete string1;
|
||||
|
||||
//String was empty
|
||||
NextSubTest();
|
||||
string1 = new BString;
|
||||
string1->CharacterEscape("newstring", "esi", '0');
|
||||
CPPUNIT_ASSERT(strcmp(string1->String(), "n0ew0str0ing") == 0);
|
||||
delete string1;
|
||||
|
||||
//CharacterDeescape(char)
|
||||
NextSubTest();
|
||||
string1 = new BString("/a/nh/g/bhhgy/fgtuhjkb/");
|
||||
string1->CharacterDeescape('/');
|
||||
CPPUNIT_ASSERT(strcmp(string1->String(), "anhgbhhgyfgtuhjkb") == 0);
|
||||
delete string1;
|
||||
|
||||
//String was empty
|
||||
NextSubTest();
|
||||
string1 = new BString;
|
||||
string1->CharacterDeescape('/');
|
||||
CPPUNIT_ASSERT(strcmp(string1->String(), "") == 0);
|
||||
delete string1;
|
||||
|
||||
//String doesn't contain character to escape
|
||||
NextSubTest();
|
||||
string1 = new BString("/a/nh/g/bhhgy/fgtuhjkb/");
|
||||
string1->CharacterDeescape('-');
|
||||
CPPUNIT_ASSERT(strcmp(string1->String(), "/a/nh/g/bhhgy/fgtuhjkb/") == 0);
|
||||
delete string1;
|
||||
|
||||
//CharacterDeescape(char* original, char)
|
||||
NextSubTest();
|
||||
string1 = new BString("oldString");
|
||||
string1->CharacterDeescape("-ne-ws-tri-ng-", '-');
|
||||
CPPUNIT_ASSERT(strcmp(string1->String(), "newstring") == 0);
|
||||
delete string1;
|
||||
|
||||
//String was empty
|
||||
NextSubTest();
|
||||
string1 = new BString;
|
||||
string1->CharacterDeescape("new/str/ing", '/');
|
||||
CPPUNIT_ASSERT(strcmp(string1->String(), "newstring") == 0);
|
||||
delete string1;
|
||||
|
||||
//assigned string is empty
|
||||
//commented out as it crashes r5 implementation
|
||||
//NextSubTest();
|
||||
//string1 = new BString("pippo");
|
||||
//string1->CharacterDeescape((char*)NULL, '/');
|
||||
//CPPUNIT_ASSERT(strcmp(string1->String(), "") == 0);
|
||||
//delete string1;
|
||||
|
||||
//String doesn't contain character to escape
|
||||
NextSubTest();
|
||||
string1 = new BString("Old");
|
||||
string1->CharacterDeescape("/a/nh/g/bhhgy/fgtuhjkb/", '-');
|
||||
CPPUNIT_ASSERT(strcmp(string1->String(), "/a/nh/g/bhhgy/fgtuhjkb/") == 0);
|
||||
delete string1;
|
||||
}
|
||||
|
||||
|
||||
|
@ -1,7 +1,6 @@
|
||||
#include "StringInsertTest.h"
|
||||
#include "cppunit/TestCaller.h"
|
||||
#include <String.h>
|
||||
#include <iostream>
|
||||
|
||||
StringInsertTest::StringInsertTest(std::string name) :
|
||||
BTestCase(name)
|
||||
@ -67,12 +66,14 @@ StringInsertTest::PerformTest(void)
|
||||
CPPUNIT_ASSERT(strcmp(str1->String(), "stRTEDring") == 0);
|
||||
delete str1;
|
||||
|
||||
//Insert(char c, int32 count, int32 pos)
|
||||
NextSubTest();
|
||||
str1 = new BString("string");
|
||||
str1->Insert('P', 5, 3);
|
||||
cerr << str1->String() << endl;
|
||||
CPPUNIT_ASSERT(strcmp(str1->String(), "strPPPPPing") == 0);
|
||||
delete str1;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
107
src/tests/kits/support/bstring/StringRemoveTest.cpp
Normal file
107
src/tests/kits/support/bstring/StringRemoveTest.cpp
Normal file
@ -0,0 +1,107 @@
|
||||
#include "StringRemoveTest.h"
|
||||
#include "cppunit/TestCaller.h"
|
||||
#include <String.h>
|
||||
#include <stdio.h>
|
||||
|
||||
StringRemoveTest::StringRemoveTest(std::string name) :
|
||||
BTestCase(name)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
|
||||
StringRemoveTest::~StringRemoveTest()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
StringRemoveTest::PerformTest(void)
|
||||
{
|
||||
BString *string1, *string2;
|
||||
|
||||
//Truncate(int32 newLength, bool lazy);
|
||||
//lazy = true
|
||||
NextSubTest();
|
||||
string1 = new BString("This is a long string");
|
||||
string1->Truncate(14, true);
|
||||
CPPUNIT_ASSERT(strcmp(string1->String(), "This is a long") == 0);
|
||||
CPPUNIT_ASSERT(string1->Length() == 14);
|
||||
delete string1;
|
||||
|
||||
//lazy = false
|
||||
NextSubTest();
|
||||
string1 = new BString("This is a long string");
|
||||
string1->Truncate(14, false);
|
||||
CPPUNIT_ASSERT(strcmp(string1->String(), "This is a long") == 0);
|
||||
CPPUNIT_ASSERT(string1->Length() == 14);
|
||||
delete string1;
|
||||
|
||||
//new length is < 0
|
||||
//commented out as it crashes r5 implementation
|
||||
//NextSubTest();
|
||||
//string1 = new BString("This is a long string");
|
||||
//string1->Truncate(-3);
|
||||
//CPPUNIT_ASSERT(strcmp(string1->String(), "This is a long string") == 0);
|
||||
//CPPUNIT_ASSERT(string1->Length() == 21);
|
||||
//delete string1;
|
||||
|
||||
//new length is > old length
|
||||
NextSubTest();
|
||||
string1 = new BString("This is a long string");
|
||||
string1->Truncate(45);
|
||||
CPPUNIT_ASSERT(strcmp(string1->String(), "This is a long string") == 0);
|
||||
CPPUNIT_ASSERT(string1->Length() == 21);
|
||||
delete string1;
|
||||
|
||||
//String was empty
|
||||
NextSubTest();
|
||||
string1 = new BString;
|
||||
string1->Truncate(0);
|
||||
CPPUNIT_ASSERT(strcmp(string1->String(), "") == 0);
|
||||
CPPUNIT_ASSERT(string1->Length() == 0);
|
||||
delete string1;
|
||||
|
||||
//Remove(int32 from, int32 length)
|
||||
NextSubTest();
|
||||
string1 = new BString("a String");
|
||||
string1->Remove(2, 2);
|
||||
CPPUNIT_ASSERT(strcmp(string1->String(), "a ring") == 0);
|
||||
delete string1;
|
||||
|
||||
//String was empty
|
||||
NextSubTest();
|
||||
string1 = new BString;
|
||||
string1->Remove(2, 1);
|
||||
CPPUNIT_ASSERT(strcmp(string1->String(), "") == 0);
|
||||
delete string1;
|
||||
|
||||
//from is beyond the end of the string
|
||||
NextSubTest();
|
||||
string1 = new BString("a String");
|
||||
string1->Remove(20, 2);
|
||||
CPPUNIT_ASSERT(strcmp(string1->String(), "a String") == 0);
|
||||
delete string1;
|
||||
|
||||
//from + length is > Length()
|
||||
NextSubTest();
|
||||
string1 = new BString("a String");
|
||||
string1->Remove(4, 30);
|
||||
CPPUNIT_ASSERT(strcmp(string1->String(), "a String") == 0);
|
||||
delete string1;
|
||||
|
||||
NextSubTest();
|
||||
string1 = new BString("a String");
|
||||
string1->Remove(-3, 5);
|
||||
CPPUNIT_ASSERT(strcmp(string1->String(), "ing") == 0);
|
||||
delete string1;
|
||||
}
|
||||
|
||||
|
||||
CppUnit::Test *StringRemoveTest::suite(void)
|
||||
{
|
||||
typedef CppUnit::TestCaller<StringRemoveTest>
|
||||
StringRemoveTestCaller;
|
||||
|
||||
return(new StringRemoveTestCaller("BString::Remove Test", &StringRemoveTest::PerformTest));
|
||||
}
|
22
src/tests/kits/support/bstring/StringRemoveTest.h
Normal file
22
src/tests/kits/support/bstring/StringRemoveTest.h
Normal file
@ -0,0 +1,22 @@
|
||||
#ifndef StringRemoveTest_H
|
||||
#define StringRemoveTest_H
|
||||
|
||||
#include "TestCase.h"
|
||||
#include <String.h>
|
||||
|
||||
|
||||
class StringRemoveTest : public BTestCase
|
||||
{
|
||||
|
||||
private:
|
||||
|
||||
protected:
|
||||
|
||||
public:
|
||||
static Test *suite(void);
|
||||
void PerformTest(void);
|
||||
StringRemoveTest(std::string name = "");
|
||||
virtual ~StringRemoveTest();
|
||||
};
|
||||
|
||||
#endif
|
@ -10,6 +10,7 @@
|
||||
#include "StringCaseTest.h"
|
||||
#include "StringInsertTest.h"
|
||||
#include "StringEscapeTest.h"
|
||||
#include "StringRemoveTest.h"
|
||||
|
||||
CppUnit::Test *StringTestSuite()
|
||||
{
|
||||
@ -24,6 +25,7 @@ CppUnit::Test *StringTestSuite()
|
||||
testSuite->addTest(StringCaseTest::suite());
|
||||
testSuite->addTest(StringInsertTest::suite());
|
||||
testSuite->addTest(StringEscapeTest::suite());
|
||||
testSuite->addTest(StringRemoveTest::suite());
|
||||
|
||||
return(testSuite);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user