1 #include "StringCharAccessTest.h" 2 #include "cppunit/TestCaller.h" 3 #include <String.h> 4 5 6 StringCharAccessTest::StringCharAccessTest(std::string name) : 7 BTestCase(name) 8 { 9 } 10 11 12 13 StringCharAccessTest::~StringCharAccessTest() 14 { 15 } 16 17 18 void 19 StringCharAccessTest::PerformTest(void) 20 { 21 BString string("A simple string"); 22 23 //operator[] 24 NextSubTest(); 25 CPPUNIT_ASSERT(string[0] == 'A'); 26 CPPUNIT_ASSERT(string[1] == ' '); 27 28 //&operator[] 29 NextSubTest(); 30 string[0] = 'a'; 31 CPPUNIT_ASSERT(strcmp(string.String(), "a simple string") == 0); 32 33 //ByteAt(int32) 34 NextSubTest(); 35 CPPUNIT_ASSERT(string.ByteAt(-10) == 0); 36 CPPUNIT_ASSERT(string.ByteAt(200) == 0); 37 CPPUNIT_ASSERT(string.ByteAt(1) == ' '); 38 CPPUNIT_ASSERT(string.ByteAt(7) == 'e'); 39 } 40 41 42 CppUnit::Test *StringCharAccessTest::suite(void) 43 { 44 typedef CppUnit::TestCaller<StringCharAccessTest> 45 StringCharAccessTestCaller; 46 47 return(new StringCharAccessTestCaller("BString::CharAccess Test", &StringCharAccessTest::PerformTest)); 48 } 49