1 #include "StringInsertTest.h" 2 #include "cppunit/TestCaller.h" 3 #include <String.h> 4 5 StringInsertTest::StringInsertTest(std::string name) : 6 BTestCase(name) 7 { 8 } 9 10 11 12 StringInsertTest::~StringInsertTest() 13 { 14 } 15 16 17 void 18 StringInsertTest::PerformTest(void) 19 { 20 BString *str1, *str2; 21 22 //&Insert(const char *, int32 pos); 23 NextSubTest(); 24 str1 = new BString("String"); 25 str1->Insert("INSERTED", 3); 26 CPPUNIT_ASSERT(strcmp(str1->String(), "StrINSERTEDing") == 0); 27 delete str1; 28 29 //This test crashes both implementations 30 //NextSubTest(); 31 //str1 = new BString("String"); 32 //str1->Insert("INSERTED", 10); 33 //CPPUNIT_ASSERT(strcmp(str1->String(), "string") == 0); 34 //delete str1; 35 36 NextSubTest(); 37 str1 = new BString; 38 str1->Insert("INSERTED", -1); 39 CPPUNIT_ASSERT(strcmp(str1->String(), "NSERTED") == 0); 40 delete str1; 41 42 //&Insert(const char *, int32 length, int32 pos); 43 NextSubTest(); 44 str1 = new BString("string"); 45 str1->Insert("INSERTED", 2, 2); 46 CPPUNIT_ASSERT(strcmp(str1->String(), "stINring") == 0); 47 delete str1; 48 49 //This test crashes both implementations 50 //NextSubTest(); 51 //str1 = new BString("string"); 52 //str1->Insert("INSERTED", 2, 30); 53 //CPPUNIT_ASSERT(strcmp(str1->String(), "stINring") == 0); 54 //delete str1; 55 56 NextSubTest(); 57 str1 = new BString("string"); 58 str1->Insert("INSERTED", 10, 2); 59 CPPUNIT_ASSERT(strcmp(str1->String(), "stINSERTEDring") == 0); 60 delete str1; 61 62 //&Insert(const char *, int32 fromOffset, int32 length, int32 pos); 63 NextSubTest(); 64 str1 = new BString("string"); 65 str1->Insert("INSERTED", 4, 30, 2); 66 CPPUNIT_ASSERT(strcmp(str1->String(), "stRTEDring") == 0); 67 delete str1; 68 69 //Insert(char c, int32 count, int32 pos) 70 NextSubTest(); 71 str1 = new BString("string"); 72 str1->Insert('P', 5, 3); 73 CPPUNIT_ASSERT(strcmp(str1->String(), "strPPPPPing") == 0); 74 delete str1; 75 76 //Insert(BString&) 77 NextSubTest(); 78 str1 = new BString("string"); 79 str2 = new BString("INSERTED"); 80 str1->Insert(*str2, 0); 81 CPPUNIT_ASSERT(strcmp(str1->String(), "INSERTEDstring") == 0); 82 delete str1; 83 delete str2; 84 85 NextSubTest(); 86 str1 = new BString("string"); 87 str1->Insert(*str1, 0); 88 CPPUNIT_ASSERT(strcmp(str1->String(), "string") == 0); 89 delete str1; 90 91 NextSubTest(); 92 str1 = new BString; 93 str2 = new BString("INSERTED"); 94 str1->Insert(*str2, -1); 95 CPPUNIT_ASSERT(strcmp(str1->String(), "NSERTED") == 0); 96 delete str1; 97 delete str2; 98 99 //&Insert(BString &, int32 length, int32 pos); 100 NextSubTest(); 101 str1 = new BString("string"); 102 str2 = new BString("INSERTED"); 103 str1->Insert(*str2, 2, 2); 104 CPPUNIT_ASSERT(strcmp(str1->String(), "stINring") == 0); 105 delete str1; 106 delete str2; 107 108 //&Insert(BString&, int32 fromOffset, int32 length, int32 pos); 109 NextSubTest(); 110 str1 = new BString("string"); 111 str2 = new BString("INSERTED"); 112 str1->Insert(*str2, 4, 30, 2); 113 CPPUNIT_ASSERT(strcmp(str1->String(), "stRTEDring") == 0); 114 delete str1; 115 delete str2; 116 } 117 118 119 CppUnit::Test *StringInsertTest::suite(void) 120 { 121 typedef CppUnit::TestCaller<StringInsertTest> 122 StringInsertTestCaller; 123 124 return(new StringInsertTestCaller("BString::Insert Test", &StringInsertTest::PerformTest)); 125 } 126