BString construction and CountChars tests
git-svn-id: file:///srv/svn/repos/haiku/trunk/current@1234 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -0,0 +1,70 @@
|
||||
#include "StringConstructionTest.h"
|
||||
#include "cppunit/TestCaller.h"
|
||||
#include <String.h>
|
||||
|
||||
|
||||
StringConstructionTest::StringConstructionTest(std::string name) :
|
||||
BTestCase(name)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
|
||||
StringConstructionTest::~StringConstructionTest()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
StringConstructionTest::PerformTest(void)
|
||||
{
|
||||
BString *string;
|
||||
const char *str = "Something";
|
||||
|
||||
NextSubTest();
|
||||
string = new BString;
|
||||
CPPUNIT_ASSERT(strcmp(string->String(), "") == 0);
|
||||
CPPUNIT_ASSERT(string->Length() == 0);
|
||||
delete string;
|
||||
|
||||
NextSubTest();
|
||||
string = new BString(str);
|
||||
CPPUNIT_ASSERT(strcmp(string->String(), str) == 0);
|
||||
CPPUNIT_ASSERT(string->Length() == strlen(str));
|
||||
delete string;
|
||||
|
||||
NextSubTest();
|
||||
string = new BString(NULL);
|
||||
CPPUNIT_ASSERT(strcmp(string->String(), "") == 0);
|
||||
CPPUNIT_ASSERT(string->Length() == 0);
|
||||
delete string;
|
||||
|
||||
NextSubTest();
|
||||
BString anotherString("Something Else");
|
||||
string = new BString(anotherString);
|
||||
CPPUNIT_ASSERT(strcmp(string->String(), anotherString.String()) == 0);
|
||||
CPPUNIT_ASSERT(string->Length() == anotherString.Length());
|
||||
delete string;
|
||||
|
||||
NextSubTest();
|
||||
string = new BString(str, 5);
|
||||
CPPUNIT_ASSERT(strcmp(string->String(), str) != 0);
|
||||
CPPUNIT_ASSERT(strncmp(string->String(), str, 5) == 0);
|
||||
CPPUNIT_ASSERT(string->Length() == 5);
|
||||
delete string;
|
||||
|
||||
NextSubTest();
|
||||
string = new BString(str, 255);
|
||||
CPPUNIT_ASSERT(strcmp(string->String(), str) == 0);
|
||||
CPPUNIT_ASSERT(string->Length() == strlen(str));
|
||||
delete string;
|
||||
}
|
||||
|
||||
|
||||
CppUnit::Test *StringConstructionTest::suite(void)
|
||||
{
|
||||
typedef CppUnit::TestCaller<StringConstructionTest>
|
||||
StringConstructionTestCaller;
|
||||
|
||||
return(new StringConstructionTestCaller("BString::Construction Test", &StringConstructionTest::PerformTest));
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
#ifndef StringConstructionTest_H
|
||||
#define StringConstructionTest_H
|
||||
|
||||
#include "TestCase.h"
|
||||
#include <String.h>
|
||||
|
||||
|
||||
class StringConstructionTest : public BTestCase
|
||||
{
|
||||
|
||||
private:
|
||||
|
||||
protected:
|
||||
|
||||
public:
|
||||
static Test *suite(void);
|
||||
void PerformTest(void);
|
||||
StringConstructionTest(std::string name = "");
|
||||
virtual ~StringConstructionTest();
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,44 @@
|
||||
#include "StringCountCharTest.h"
|
||||
#include "cppunit/TestCaller.h"
|
||||
#include <String.h>
|
||||
#include <UTF8.h>
|
||||
|
||||
StringCountCharTest::StringCountCharTest(std::string name) :
|
||||
BTestCase(name)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
|
||||
StringCountCharTest::~StringCountCharTest()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
StringCountCharTest::PerformTest(void)
|
||||
{
|
||||
NextSubTest();
|
||||
BString string("Something"B_UTF8_ELLIPSIS);
|
||||
CPPUNIT_ASSERT(string.CountChars() == 10);
|
||||
|
||||
NextSubTest();
|
||||
BString string2("ABCD");
|
||||
CPPUNIT_ASSERT(string2.CountChars() == 4);
|
||||
|
||||
NextSubTest();
|
||||
static char s[64];
|
||||
strcpy(s, B_UTF8_ELLIPSIS);
|
||||
strcat(s, B_UTF8_SMILING_FACE);
|
||||
BString string3(s);
|
||||
CPPUNIT_ASSERT(string3.CountChars() == 2);
|
||||
}
|
||||
|
||||
|
||||
CppUnit::Test *StringCountCharTest::suite(void)
|
||||
{
|
||||
typedef CppUnit::TestCaller<StringCountCharTest>
|
||||
StringCountCharTestCaller;
|
||||
|
||||
return(new StringCountCharTestCaller("BString::CountChar Test", &StringCountCharTest::PerformTest));
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
#ifndef StringCountCharTest_H
|
||||
#define StringCountCharTest_H
|
||||
|
||||
#include "TestCase.h"
|
||||
#include <String.h>
|
||||
|
||||
|
||||
class StringCountCharTest : public BTestCase
|
||||
{
|
||||
|
||||
private:
|
||||
|
||||
protected:
|
||||
|
||||
public:
|
||||
static Test *suite(void);
|
||||
void PerformTest(void);
|
||||
StringCountCharTest(std::string name = "");
|
||||
virtual ~StringCountCharTest();
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,15 @@
|
||||
#include "cppunit/Test.h"
|
||||
#include "cppunit/TestSuite.h"
|
||||
#include "StringTest.h"
|
||||
#include "StringConstructionTest.h"
|
||||
#include "StringCountCharTest.h"
|
||||
|
||||
CppUnit::Test *StringTestSuite()
|
||||
{
|
||||
CppUnit::TestSuite *testSuite = new CppUnit::TestSuite();
|
||||
|
||||
testSuite->addTest(StringConstructionTest::suite());
|
||||
testSuite->addTest(StringCountCharTest::suite());
|
||||
|
||||
return(testSuite);
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
#ifndef _string_test_h_
|
||||
#define _string_test_h_
|
||||
|
||||
class CppUnit::Test;
|
||||
|
||||
CppUnit::Test *StringTestSuite();
|
||||
|
||||
#endif // _string_test_h_
|
||||
Reference in New Issue
Block a user