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