1 #include "StringInsertTest.h" 2 #include "cppunit/TestCaller.h" 3 #include <String.h> 4 5 6 StringInsertTest::StringInsertTest(std::string name) 7 : BTestCase(name) 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 #ifndef TEST_R5 30 // This test crashes R5 and should drop into the debugger in Haiku 31 // (if compiled with DEBUG): 32 NextSubTest(); 33 str1 = new BString("String"); 34 str1->Insert("INSERTED", 10); 35 CPPUNIT_ASSERT(strcmp(str1->String(), "String") == 0); 36 delete str1; 37 #endif 38 39 NextSubTest(); 40 str1 = new BString; 41 str1->Insert("INSERTED", -1); 42 CPPUNIT_ASSERT(strcmp(str1->String(), "NSERTED") == 0); 43 delete str1; 44 45 #ifndef TEST_R5 46 // check limitation of negative values (R5 doesn't): 47 NextSubTest(); 48 str1 = new BString; 49 str1->Insert("INSERTED", -142364253); 50 CPPUNIT_ASSERT(strcmp(str1->String(), "") == 0); 51 delete str1; 52 #endif 53 54 // &Insert(const char *, int32 length, int32 pos); 55 NextSubTest(); 56 str1 = new BString("string"); 57 str1->Insert("INSERTED", 2, 2); 58 CPPUNIT_ASSERT(strcmp(str1->String(), "stINring") == 0); 59 delete str1; 60 61 #ifndef TEST_R5 62 // This test crashes R5 and should drop into the debugger in Haiku 63 // (if compiled with DEBUG): 64 NextSubTest(); 65 str1 = new BString("string"); 66 str1->Insert("INSERTED", 2, 30); 67 CPPUNIT_ASSERT(strcmp(str1->String(), "string") == 0); 68 delete str1; 69 #endif 70 71 NextSubTest(); 72 str1 = new BString("string"); 73 str1->Insert("INSERTED", 10, 2); 74 CPPUNIT_ASSERT(strcmp(str1->String(), "stINSERTEDring") == 0); 75 delete str1; 76 77 // &Insert(const char *, int32 fromOffset, int32 length, int32 pos); 78 NextSubTest(); 79 str1 = new BString("string"); 80 str1->Insert("INSERTED", 4, 30, 2); 81 CPPUNIT_ASSERT(strcmp(str1->String(), "stRTEDring") == 0); 82 delete str1; 83 84 // Insert(char c, int32 count, int32 pos) 85 NextSubTest(); 86 str1 = new BString("string"); 87 str1->Insert('P', 5, 3); 88 CPPUNIT_ASSERT(strcmp(str1->String(), "strPPPPPing") == 0); 89 delete str1; 90 91 // Insert(char c, int32 count, int32 pos) 92 NextSubTest(); 93 str1 = new BString("string"); 94 str1->Insert('P', 5, -2); 95 CPPUNIT_ASSERT(strcmp(str1->String(), "PPPstring") == 0); 96 delete str1; 97 98 // Insert(BString&) 99 NextSubTest(); 100 str1 = new BString("string"); 101 str2 = new BString("INSERTED"); 102 str1->Insert(*str2, 0); 103 CPPUNIT_ASSERT(strcmp(str1->String(), "INSERTEDstring") == 0); 104 delete str1; 105 delete str2; 106 107 NextSubTest(); 108 str1 = new BString("string"); 109 str1->Insert(*str1, 0); 110 CPPUNIT_ASSERT(strcmp(str1->String(), "string") == 0); 111 delete str1; 112 113 NextSubTest(); 114 str1 = new BString; 115 str2 = new BString("INSERTED"); 116 str1->Insert(*str2, -1); 117 CPPUNIT_ASSERT(strcmp(str1->String(), "NSERTED") == 0); 118 delete str1; 119 delete str2; 120 121 // &Insert(BString &, int32 length, int32 pos); 122 NextSubTest(); 123 str1 = new BString("string"); 124 str2 = new BString("INSERTED"); 125 str1->Insert(*str2, 2, 2); 126 CPPUNIT_ASSERT(strcmp(str1->String(), "stINring") == 0); 127 delete str1; 128 delete str2; 129 130 // &Insert(BString&, int32 fromOffset, int32 length, int32 pos); 131 NextSubTest(); 132 str1 = new BString("string"); 133 str2 = new BString("INSERTED"); 134 str1->Insert(*str2, 4, 30, 2); 135 CPPUNIT_ASSERT(strcmp(str1->String(), "stRTEDring") == 0); 136 delete str1; 137 delete str2; 138 } 139 140 141 CppUnit::Test *StringInsertTest::suite(void) 142 { 143 typedef CppUnit::TestCaller<StringInsertTest> 144 StringInsertTestCaller; 145 146 return(new StringInsertTestCaller("BString::Insert Test", 147 &StringInsertTest::PerformTest)); 148 } 149