1 #include "StringConstructionTest.h" 2 #include "cppunit/TestCaller.h" 3 #include <String.h> 4 5 6 StringConstructionTest::StringConstructionTest(std::string name) : 7 BTestCase(name) 8 { 9 } 10 11 12 13 StringConstructionTest::~StringConstructionTest() 14 { 15 } 16 17 18 void 19 StringConstructionTest::PerformTest(void) 20 { 21 BString *string; 22 const char *str = "Something"; 23 24 //BString() 25 NextSubTest(); 26 string = new BString; 27 CPPUNIT_ASSERT(strcmp(string->String(), "") == 0); 28 CPPUNIT_ASSERT(string->Length() == 0); 29 delete string; 30 31 //BString(const char*) 32 NextSubTest(); 33 string = new BString(str); 34 CPPUNIT_ASSERT(strcmp(string->String(), str) == 0); 35 CPPUNIT_ASSERT((unsigned)string->Length() == strlen(str)); 36 delete string; 37 38 //BString(NULL) 39 NextSubTest(); 40 string = new BString(NULL); 41 CPPUNIT_ASSERT(strcmp(string->String(), "") == 0); 42 CPPUNIT_ASSERT(string->Length() == 0); 43 delete string; 44 45 //BString(BString&) 46 NextSubTest(); 47 BString anotherString("Something Else"); 48 string = new BString(anotherString); 49 CPPUNIT_ASSERT(strcmp(string->String(), anotherString.String()) == 0); 50 CPPUNIT_ASSERT(string->Length() == anotherString.Length()); 51 delete string; 52 53 //BString(const char*, int32) 54 NextSubTest(); 55 string = new BString(str, 5); 56 CPPUNIT_ASSERT(strcmp(string->String(), str) != 0); 57 CPPUNIT_ASSERT(strncmp(string->String(), str, 5) == 0); 58 CPPUNIT_ASSERT(string->Length() == 5); 59 delete string; 60 61 NextSubTest(); 62 string = new BString(str, 255); 63 CPPUNIT_ASSERT(strcmp(string->String(), str) == 0); 64 CPPUNIT_ASSERT((unsigned)string->Length() == strlen(str)); 65 delete string; 66 } 67 68 69 CppUnit::Test *StringConstructionTest::suite(void) 70 { 71 typedef CppUnit::TestCaller<StringConstructionTest> 72 StringConstructionTestCaller; 73 74 return(new StringConstructionTestCaller("BString::Construction Test", &StringConstructionTest::PerformTest)); 75 } 76