1 #include "StringCaseTest.h" 2 #include "cppunit/TestCaller.h" 3 #include <String.h> 4 5 StringCaseTest::StringCaseTest(std::string name) : 6 BTestCase(name) 7 { 8 } 9 10 11 12 StringCaseTest::~StringCaseTest() 13 { 14 } 15 16 17 void 18 StringCaseTest::PerformTest(void) 19 { 20 BString *string; 21 22 //Capitalize 23 NextSubTest(); 24 string = new BString("this is a sentence"); 25 string->Capitalize(); 26 CPPUNIT_ASSERT(strcmp(string->String(), "This is a sentence") == 0); 27 delete string; 28 29 NextSubTest(); 30 string = new BString("134this is a sentence"); 31 string->Capitalize(); 32 CPPUNIT_ASSERT(strcmp(string->String(), "134this is a sentence") == 0); 33 delete string; 34 35 NextSubTest(); 36 string = new BString; 37 string->Capitalize(); 38 CPPUNIT_ASSERT(strcmp(string->String(), "") == 0); 39 delete string; 40 41 //ToLower 42 NextSubTest(); 43 string = new BString("1a2B3c4d5e6f7G"); 44 string->ToLower(); 45 CPPUNIT_ASSERT(strcmp(string->String(), "1a2b3c4d5e6f7g") == 0); 46 delete string; 47 48 NextSubTest(); 49 string = new BString; 50 string->ToLower(); 51 CPPUNIT_ASSERT(strcmp(string->String(), "") == 0); 52 delete string; 53 54 //ToUpper 55 NextSubTest(); 56 string = new BString("1a2b3c4d5E6f7g"); 57 string->ToUpper(); 58 CPPUNIT_ASSERT(strcmp(string->String(), "1A2B3C4D5E6F7G") == 0); 59 delete string; 60 61 NextSubTest(); 62 string = new BString; 63 string->ToUpper(); 64 CPPUNIT_ASSERT(strcmp(string->String(), "") == 0); 65 delete string; 66 67 //CapitalizeEachWord 68 NextSubTest(); 69 string = new BString("each wOrd 3will_be >capiTalized"); 70 string->CapitalizeEachWord(); 71 CPPUNIT_ASSERT(strcmp(string->String(), "Each Word 3Will_Be >Capitalized") == 0); 72 delete string; 73 74 NextSubTest(); 75 string = new BString; 76 string->CapitalizeEachWord(); 77 CPPUNIT_ASSERT(strcmp(string->String(), "") == 0); 78 delete string; 79 } 80 81 82 CppUnit::Test *StringCaseTest::suite(void) 83 { 84 typedef CppUnit::TestCaller<StringCaseTest> 85 StringCaseTestCaller; 86 87 return(new StringCaseTestCaller("BString::Case Test", &StringCaseTest::PerformTest)); 88 } 89