diff --git a/src/tests/kits/support/bstring/StringCharAccessTest.cpp b/src/tests/kits/support/bstring/StringCharAccessTest.cpp new file mode 100644 index 0000000000..b43dacbf0d --- /dev/null +++ b/src/tests/kits/support/bstring/StringCharAccessTest.cpp @@ -0,0 +1,48 @@ +#include "StringCharAccessTest.h" +#include "cppunit/TestCaller.h" +#include + + +StringCharAccessTest::StringCharAccessTest(std::string name) : + BTestCase(name) +{ +} + + + +StringCharAccessTest::~StringCharAccessTest() +{ +} + + +void +StringCharAccessTest::PerformTest(void) +{ + BString string("A simple string"); + + //operator[] + NextSubTest(); + CPPUNIT_ASSERT(string[0] == 'A'); + CPPUNIT_ASSERT(string[1] == ' '); + + //&operator[] + NextSubTest(); + string[0] = 'a'; + CPPUNIT_ASSERT(strcmp(string.String(), "a simple string") == 0); + + //ByteAt(int32) + NextSubTest(); + CPPUNIT_ASSERT(string[-10] == 0); + CPPUNIT_ASSERT(string[200] == 0); + CPPUNIT_ASSERT(string[1] == ' '); + CPPUNIT_ASSERT(string[7] == 'e'); +} + + +CppUnit::Test *StringCharAccessTest::suite(void) +{ + typedef CppUnit::TestCaller + StringCharAccessTestCaller; + + return(new StringCharAccessTestCaller("BString::CharAccess Test", &StringCharAccessTest::PerformTest)); +} diff --git a/src/tests/kits/support/bstring/StringCharAccessTest.h b/src/tests/kits/support/bstring/StringCharAccessTest.h new file mode 100644 index 0000000000..1875f5655a --- /dev/null +++ b/src/tests/kits/support/bstring/StringCharAccessTest.h @@ -0,0 +1,22 @@ +#ifndef StringCharAccessTest_H +#define StringCharAccessTest_H + +#include "TestCase.h" +#include + + +class StringCharAccessTest : public BTestCase +{ + +private: + +protected: + +public: + static Test *suite(void); + void PerformTest(void); + StringCharAccessTest(std::string name = ""); + virtual ~StringCharAccessTest(); + }; + +#endif diff --git a/src/tests/kits/support/bstring/StringTest.cpp b/src/tests/kits/support/bstring/StringTest.cpp index b4ae079fd4..57e050e712 100644 --- a/src/tests/kits/support/bstring/StringTest.cpp +++ b/src/tests/kits/support/bstring/StringTest.cpp @@ -13,6 +13,7 @@ #include "StringRemoveTest.h" #include "StringCompareTest.h" #include "StringFormatAppendTest.h" +#include "StringCharAccessTest.h" CppUnit::Test *StringTestSuite() { @@ -30,6 +31,7 @@ CppUnit::Test *StringTestSuite() testSuite->addTest(StringRemoveTest::suite()); testSuite->addTest(StringCompareTest::suite()); testSuite->addTest(StringFormatAppendTest::suite()); + testSuite->addTest(StringCharAccessTest::suite()); return(testSuite); }