From e440e9f42353c5875a8890f95b5c36b2308c9ec0 Mon Sep 17 00:00:00 2001 From: Stefano Ceccherini Date: Mon, 28 Oct 2002 08:42:18 +0000 Subject: [PATCH] BString char access tests git-svn-id: file:///srv/svn/repos/haiku/trunk/current@1729 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- .../support/bstring/StringCharAccessTest.cpp | 48 +++++++++++++++++++ .../support/bstring/StringCharAccessTest.h | 22 +++++++++ src/tests/kits/support/bstring/StringTest.cpp | 2 + 3 files changed, 72 insertions(+) create mode 100644 src/tests/kits/support/bstring/StringCharAccessTest.cpp create mode 100644 src/tests/kits/support/bstring/StringCharAccessTest.h 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); }