1 #include "StringEscapeTest.h" 2 #include "cppunit/TestCaller.h" 3 #include <String.h> 4 5 StringEscapeTest::StringEscapeTest(std::string name) : 6 BTestCase(name) 7 { 8 } 9 10 11 12 StringEscapeTest::~StringEscapeTest() 13 { 14 } 15 16 17 void 18 StringEscapeTest::PerformTest(void) 19 { 20 BString *string1, *string2; 21 22 //CharacterEscape(char*, char) 23 NextSubTest(); 24 string1 = new BString("abcdefghi"); 25 string1->CharacterEscape("acf", '/'); 26 CPPUNIT_ASSERT(strcmp(string1->String(), "/ab/cde/fghi") == 0); 27 delete string1; 28 29 //BString is null 30 NextSubTest(); 31 string1 = new BString; 32 string1->CharacterEscape("abc", '/'); 33 CPPUNIT_ASSERT(strcmp(string1->String(), "") == 0); 34 delete string1; 35 36 //BString doesn't contain wanted characters 37 NextSubTest(); 38 string1 = new BString("abcdefghi"); 39 string1->CharacterEscape("z34", 'z'); 40 CPPUNIT_ASSERT(strcmp(string1->String(), "abcdefghi") == 0); 41 delete string1; 42 43 //CharacterEscape(char *, char*, char) 44 NextSubTest(); 45 string1 = new BString("something"); 46 string1->CharacterEscape("newstring", "esi", '0'); 47 CPPUNIT_ASSERT(strcmp(string1->String(), "n0ew0str0ing") == 0); 48 delete string1; 49 50 //assigned string is NULL 51 //commented out as it crashes r5 implementation 52 //NextSubTest(); 53 //string1 = new BString("something"); 54 //string1->CharacterEscape((char*)NULL, "ei", '-'); 55 //CPPUNIT_ASSERT(strcmp(string1->String(), "") == 0); 56 //delete string1; 57 58 //String was empty 59 NextSubTest(); 60 string1 = new BString; 61 string1->CharacterEscape("newstring", "esi", '0'); 62 CPPUNIT_ASSERT(strcmp(string1->String(), "n0ew0str0ing") == 0); 63 delete string1; 64 65 //CharacterDeescape(char) 66 NextSubTest(); 67 string1 = new BString("/a/nh/g/bhhgy/fgtuhjkb/"); 68 string1->CharacterDeescape('/'); 69 CPPUNIT_ASSERT(strcmp(string1->String(), "anhgbhhgyfgtuhjkb") == 0); 70 delete string1; 71 72 //String was empty 73 NextSubTest(); 74 string1 = new BString; 75 string1->CharacterDeescape('/'); 76 CPPUNIT_ASSERT(strcmp(string1->String(), "") == 0); 77 delete string1; 78 79 //String doesn't contain character to escape 80 NextSubTest(); 81 string1 = new BString("/a/nh/g/bhhgy/fgtuhjkb/"); 82 string1->CharacterDeescape('-'); 83 CPPUNIT_ASSERT(strcmp(string1->String(), "/a/nh/g/bhhgy/fgtuhjkb/") == 0); 84 delete string1; 85 86 //CharacterDeescape(char* original, char) 87 NextSubTest(); 88 string1 = new BString("oldString"); 89 string1->CharacterDeescape("-ne-ws-tri-ng-", '-'); 90 CPPUNIT_ASSERT(strcmp(string1->String(), "newstring") == 0); 91 delete string1; 92 93 //String was empty 94 NextSubTest(); 95 string1 = new BString; 96 string1->CharacterDeescape("new/str/ing", '/'); 97 CPPUNIT_ASSERT(strcmp(string1->String(), "newstring") == 0); 98 delete string1; 99 100 //assigned string is empty 101 //commented out as it crashes r5 implementation 102 //NextSubTest(); 103 //string1 = new BString("pippo"); 104 //string1->CharacterDeescape((char*)NULL, '/'); 105 //CPPUNIT_ASSERT(strcmp(string1->String(), "") == 0); 106 //delete string1; 107 108 //String doesn't contain character to escape 109 NextSubTest(); 110 string1 = new BString("Old"); 111 string1->CharacterDeescape("/a/nh/g/bhhgy/fgtuhjkb/", '-'); 112 CPPUNIT_ASSERT(strcmp(string1->String(), "/a/nh/g/bhhgy/fgtuhjkb/") == 0); 113 delete string1; 114 } 115 116 117 CppUnit::Test *StringEscapeTest::suite(void) 118 { 119 typedef CppUnit::TestCaller<StringEscapeTest> 120 StringEscapeTestCaller; 121 122 return(new StringEscapeTestCaller("BString::Escape Test", &StringEscapeTest::PerformTest)); 123 } 124