1 2TEST_NAMEX(operators_init) 3{ 4 CStringX test; 5 ok(test.IsEmpty() == true, "Expected test to be empty\n"); 6 ok(test.GetLength() == 0, "Expected GetLength() to be 0, was: %i\n", test.GetLength()); 7 ok(test.GetAllocLength() == 0, "Expected GetAllocLength() to be 0, was: %i\n", test.GetAllocLength()); 8 9 // Operator 10 const XCHAR* cstring = (const XCHAR*)test; 11 ok(cstring != NULL, "Expected a valid pointer\n"); 12 if (cstring) 13 { 14 ok(cstring[0] == '\0', "Expected \\0, got: %c (%i)\n", cstring[0], (int)cstring[0]); 15 } 16 17 CStringX first(_X("First ")); 18 ok(first.IsEmpty() != true, "Expected first to not be empty\n"); 19 ok(first.GetLength() == 6, "Expected GetLength() to be 6, was: %i\n", first.GetLength()); 20 //ok_int(first.GetAllocLength(), 6); 21 22 CStringX second(_X("Second")); 23 ok(second.IsEmpty() != true, "Expected second to not be empty\n"); 24 ok(second.GetLength() == 6, "Expected GetLength() to be 6, was: %i\n", second.GetLength()); 25 //ok_int(second.GetAllocLength(), 6); 26 27 test = first; 28 ok(test.IsEmpty() != true, "Expected test to not be empty\n"); 29 ok(test.GetLength() == 6, "Expected GetLength() to be 6, was: %i\n", test.GetLength()); 30 //ok_int(test.GetAllocLength(), 6); 31 32 test.Empty(); 33 ok(test.IsEmpty() == true, "Expected test to be empty\n"); 34 ok(test.GetLength() == 0, "Expected GetLength() to be 0, was: %i\n", test.GetLength()); 35 //ok_int(test.GetAllocLength(), 0); 36 37 test = _X("First "); 38 ok(test.IsEmpty() != true, "Expected test to not be empty\n"); 39 ok(test.GetLength() == 6, "Expected GetLength() to be 6, was: %i\n", test.GetLength()); 40 //ok_int(test.GetAllocLength(), 6); 41 42 test += second; 43 ok(test.IsEmpty() != true, "Expected test to not be empty\n"); 44 ok(test.GetLength() == 12, "Expected GetLength() to be 12, was: %i\n", test.GetLength()); 45 //ok_int(test.GetAllocLength(), 12); 46 47 test = first + second; 48 ok(test.IsEmpty() != true, "Expected test to not be empty\n"); 49 ok(test.GetLength() == 12, "Expected GetLength() to be 12, was: %i\n", test.GetLength()); 50 //ok_int(test.GetAllocLength(), 12); 51 52 test = first + second + _X("."); 53 ok(test.IsEmpty() != true, "Expected test to not be empty\n"); 54 ok(test.GetLength() == 13, "Expected GetLength() to be 13, was: %i\n", test.GetLength()); 55 //ok_int(test.GetAllocLength(), 13); 56 57 CStringX test2(test); 58 ok(test2.IsEmpty() != true, "Expected test2 to not be empty\n"); 59 ok(test2.GetLength() == 13, "Expected GetLength() to be 13, was: %i\n", test2.GetLength()); 60 //ok_int(test2.GetAllocLength(), 13); 61 62 // Clear it again 63 test.Empty(); 64 ok(test.IsEmpty() == true, "Expected test to be empty\n"); 65 ok(test.GetLength() == 0, "Expected GetLength() to be 0, was: %i\n", test.GetLength()); 66 //ok_int(test.GetAllocLength(), 0); 67 68 // Assign string 69 test = "First "; 70 ok(test.IsEmpty() != true, "Expected test to not be empty\n"); 71 ok(test.GetLength() == 6, "Expected GetLength() to be 6, was: %i\n", test.GetLength()); 72 //ok_int(test.GetAllocLength(), 6); 73 74 CStringA testA = test; 75 ok(testA.IsEmpty() != true, "Expected testA to not be empty\n"); 76 ok(testA.GetLength() == 6, "Expected GetLength() to be 6, was: %i\n", testA.GetLength()); 77 //ok_int(testA.GetAllocLength(), 6); 78 79 CStringW testW = test; 80 ok(testW.IsEmpty() != true, "Expected testW to not be empty\n"); 81 ok(testW.GetLength() == 6, "Expected GetLength() to be 6, was: %i\n", testW.GetLength()); 82 //ok_int(testW.GetAllocLength(), 6); 83 84 // Assign wstring 85 test = L"First "; 86 ok(test.IsEmpty() != true, "Expected test to not be empty\n"); 87 ok(test.GetLength() == 6, "Expected GetLength() to be 6, was: %i\n", test.GetLength()); 88 //ok_int(test.GetAllocLength(), 6); 89} 90 91 92TEST_NAMEX(compare) 93{ 94 CStringX s1, s2; 95 s1 = s2 = _X("some text 1!"); 96 97 int c = s1.Compare(s2); 98 ok(c == 0, "Expected c to be 1, was: %i\n", c); 99 100 c = s1.Compare(_X("r")); 101 ok(c == 1, "Expected c to be 1, was: %i\n", c); 102 103 c = s1.Compare(_X("s")); 104 ok(c == 1, "Expected c to be 1, was: %i\n", c); 105 106 c = s1.Compare(_X("t")); 107 ok(c == -1, "Expected c to be -1, was: %i\n", c); 108 109 c = s1.Compare(_X("R")); 110 ok(c == 1, "Expected c to be 1, was: %i\n", c); 111 112 c = s1.Compare(_X("S")); 113 ok(c == 1, "Expected c to be 1, was: %i\n", c); 114 115 c = s1.Compare(_X("T")); 116 ok(c == 1, "Expected c to be 1, was: %i\n", c); 117 118 ok(s1 == s2, "Expected s1 and s2 to be equal: '%s' == '%s'\n", dbgstrx(s1), dbgstrx(s2)); 119 120 s1.MakeUpper(); // Does not modify s2 121 ok(s1[0] == _X('S'), "Expected s1[0] to be S, was: %c\n", (char)s1[0]); 122 ok(s2[0] == _X('s'), "Expected s2[0] to be s, was: %c\n", (char)s2[0]); 123 124 ok(s1 == _X("SOME TEXT 1!"), "Expected s1 to be 'SOME TEXT 1!', was: %s\n", dbgstrx(s1)); 125 ok(s1 != _X("SOME TEXT 2!"), "Expected s2 not to match 'SOME TEXT 2!', was: %s\n", dbgstrx(s1)); 126 ok(!(s1 != _X("SOME TEXT 1!")), "Expected s1 to be 'SOME TEXT 1!', was: %s\n", dbgstrx(s1)); 127 128 CStringX s3 = s1.MakeLower(); 129 ok(s1 == _X("some text 1!"), "Expected s1 to be 'some text 1!', was: %s\n", dbgstrx(s1)); 130 ok(s1 == s3, "Expected s1 and s3 to be equal: '%s' == '%s'\n", dbgstrx(s1), dbgstrx(s3)); 131 ok(!(s1 != s3), "Expected s1 and s3 to be equal: !('%s' == '%s')\n", dbgstrx(s1), dbgstrx(s3)); 132 133 // Compare as chars 134 s1 = _X("Q"); 135 ok(s1 == 'Q', "Expected s1 to be 'Q', was: %s\n", dbgstrx(s1)); 136 ok(!(s1 != 'Q'), "Expected s1 to be 'Q' (!=), was: %s\n", dbgstrx(s1)); 137 ok(s1 != 'S', "Expected s1 to be different from 'S', was: %s\n", dbgstrx(s1)); 138 139 s1.Empty(); 140 ok(s1 != 'S', "Expected s1 to be different from 'S', was: %s\n", dbgstrx(s1)); 141 ok(s1 != 'Q', "Expected s1 to be different from 'S', was: %s\n", dbgstrx(s1)); 142 143 s1 = _X("QQ"); 144 ok(s1 != 'S', "Expected s1 to be different from 'S', was: %s\n", dbgstrx(s1)); 145 ok(s1 != 'Q', "Expected s1 to be different from 'S', was: %s\n", dbgstrx(s1)); 146} 147 148 149TEST_NAMEX(find) 150{ 151 CStringX s(_X("adbcdef")); 152 int n = s.Find(_X('c')); 153 ok(n == 3, "Expected n to be 2, was %i\n", n); 154 n = s.Find(_X("de")); 155 ok(n == 4, "Expected n to be 4, was %i\n", n); 156 157 CStringX str(_X("The waves are still")); 158 n = str.Find(_X('e'), 5); 159 ok(n == 7, "Expected n to be 7, was %i\n", n); 160 n = str.Find(_X('e'), 7); 161 ok(n == 7, "Expected n to be 7, was %i\n", n); 162 163 s = _X("abcdefGHIJKLMNop"); 164 n = s.FindOneOf(_X("Nd")); 165 ok(n == 3, "Expected n to be 3, was %i\n", n); 166 n = s.FindOneOf(_X("Np")); 167 ok(n == 13, "Expected n to be 13, was %i\n", n); 168 169 n = str.ReverseFind(_X('l')); 170 ok(n == 18, "Expected n to be 18, was %i\n", n); 171 172 n = str.ReverseFind(_X('e')); 173 ok(n == 12, "Expected n to be 12, was %i\n", n); 174} 175 176 177void WriteString(const XCHAR* pstrFormat, ...) 178{ 179 CStringX str; 180 181 va_list args; 182 va_start(args, pstrFormat); 183 184 str.FormatV(pstrFormat, args); 185 va_end(args); 186 187 ok(str == _X("10e 1351l"), "Expected str to be '10e 1351l', was: %s\n", dbgstrx(str)); 188 189 190 va_start(args, pstrFormat); 191 str.AppendFormatV(pstrFormat, args); 192 va_end(args); 193 ok(str == _X("10e 1351l10e 1351l"), "Expected str to be '10e 1351l10e 1351l', was: %s\n", dbgstrx(str)); 194} 195 196TEST_NAMEX(format) 197{ 198 CStringX str; 199 200 str.Format(_X("FP: %.2f"), 12345.12345); 201 ok(str == _X("FP: 12345.12"), "Expected str to be 'FP: 12345.12', was: %s\n", dbgstrx(str)); 202 203 str.Format(_X("int: %.6d"), 35); 204 ok(str == _X("int: 000035"), "Expected str to be 'int: 000035', was: %s\n", dbgstrx(str)); 205 206 WriteString(_X("%de %dl"), 10, 1351); 207 208 str.AppendFormat(_X(",FP: %.2f"), 12345.12345); 209 ok(str == _X("int: 000035,FP: 12345.12"), "Expected str to be 'int: 000035,FP: 12345.12', was: %s\n", dbgstrx(str)); 210} 211 212 213TEST_NAMEX(substr) 214{ 215 CStringX s(_X("abcdef")); 216 217 CStringX m = s.Mid(2, 3); 218 ok(m == _X("cde"), "Expected str to be 'cde', was: %s\n", dbgstrx(m)); 219 ok(m.GetLength() == 3, "Expected GetLength() to be 3, was: %i\n", m.GetLength()); 220 221 m = s.Mid(-5, 3); 222 ok(m == _X("abc"), "Expected str to be 'abc', was: %s\n", dbgstrx(m)); 223 ok(m.GetLength() == 3, "Expected GetLength() to be 3, was: %i\n", m.GetLength()); 224 225 m = s.Mid(3, 20); 226 ok(m == _X("def"), "Expected str to be 'def', was: %s\n", dbgstrx(m)); 227 ok(m.GetLength() == 3, "Expected GetLength() to be 3, was: %i\n", m.GetLength()); 228 229 m = s.Mid(3, -1); 230 ok(m == _X(""), "Expected str to be '', was: %s\n", dbgstrx(m)); 231 ok(m.GetLength() == 0, "Expected GetLength() to be 0, was: %i\n", m.GetLength()); 232 233 m = s.Mid(2); 234 ok(m == _X("cdef"), "Expected str to be 'cdef', was: %s\n", dbgstrx(m)); 235 ok(m.GetLength() == 4, "Expected GetLength() to be 4, was: %i\n", m.GetLength()); 236 237 m = s.Mid(-3); 238 ok(m == _X("abcdef"), "Expected str to be 'abcdef', was: %s\n", dbgstrx(m)); 239 ok(m.GetLength() == 6, "Expected GetLength() to be 6, was: %i\n", m.GetLength()); 240 241 m = s.Mid(20); 242 ok(m == _X(""), "Expected str to be '', was: %s\n", dbgstrx(m)); 243 ok(m.GetLength() == 0, "Expected GetLength() to be 0, was: %i\n", m.GetLength()); 244 245 m = s.Left(2); 246 ok(m == _X("ab"), "Expected str to be 'ab', was: %s\n", dbgstrx(m)); 247 ok(m.GetLength() == 2, "Expected GetLength() to be 2, was: %i\n", m.GetLength()); 248 249 m = s.Left(40); 250 ok(m == _X("abcdef"), "Expected str to be 'abcdef', was: %s\n", dbgstrx(m)); 251 ok(m.GetLength() == 6, "Expected GetLength() to be 6, was: %i\n", m.GetLength()); 252 253 m = s.Left(-10); 254 ok(m == _X(""), "Expected str to be '', was: %s\n", dbgstrx(m)); 255 ok(m.GetLength() == 0, "Expected GetLength() to be 0, was: %i\n", m.GetLength()); 256 257 m = s.Right(2); 258 ok(m == _X("ef"), "Expected str to be 'ef', was: %s\n", dbgstrx(m)); 259 ok(m.GetLength() == 2, "Expected GetLength() to be 2, was: %i\n", m.GetLength()); 260 261 m = s.Right(-40); 262 ok(m == _X(""), "Expected str to be '', was: %s\n", dbgstrx(m)); 263 ok(m.GetLength() == 0, "Expected GetLength() to be 0, was: %i\n", m.GetLength()); 264 265 m = s.Right(99); 266 ok(m == _X("abcdef"), "Expected str to be 'abcdef', was: %s\n", dbgstrx(m)); 267 ok(m.GetLength() == 6, "Expected GetLength() to be 6, was: %i\n", m.GetLength()); 268} 269 270 271TEST_NAMEX(replace) 272{ 273 CStringX str(_X("abcde")); 274 int n = str.Replace(_X("b"), _X("bx")); 275 ok(n == 1, "Expected n to be 1, was %i\n", n); 276 ok(str == _X("abxcde"), "Expected str to be 'abxcde', was: %s\n", dbgstrx(str)); 277 ok(str.GetLength() == 6, "Expected GetLength() to be 6, was: %i\n", str.GetLength()); 278 279 CStringX strBang(_X("The quick brown fox is lazy today of all days")); 280 281 n = strBang.Replace(_X("is"), _X("was")); 282 ok(n == 1, "Expected n to be 1, was %i\n", n); 283 ok(strBang == _X("The quick brown fox was lazy today of all days"), 284 "Expected str to be 'The quick brown fox was lazy today of all days', was: %s\n", dbgstrx(strBang)); 285 ok(strBang.GetLength() == 46, "Expected GetLength() to be 46, was: %i\n", strBang.GetLength()); 286 287 n = strBang.Replace(_X("is"), _X("was")); 288 ok(n == 0, "Expected n to be 0, was %i\n", n); 289 ok(strBang == _X("The quick brown fox was lazy today of all days"), 290 "Expected str to be 'The quick brown fox was lazy today of all days', was: %s\n", dbgstrx(strBang)); 291 ok(strBang.GetLength() == 46, "Expected GetLength() to be 46, was: %i\n", strBang.GetLength()); 292 293 n = strBang.Replace(_X('o'), _X('0')); 294 ok(n == 4, "Expected n to be 4, was %i\n", n); 295 ok(strBang == _X("The quick br0wn f0x was lazy t0day 0f all days"), 296 "Expected str to be 'The quick br0wn f0x was lazy t0day 0f all days', was: %s\n", dbgstrx(strBang)); 297 ok(strBang.GetLength() == 46, "Expected GetLength() to be 46, was: %i\n", strBang.GetLength()); 298 299 n = strBang.Replace(_X('o'), _X('0')); 300 ok(n == 0, "Expected n to be 0, was %i\n", n); 301 ok(strBang == _X("The quick br0wn f0x was lazy t0day 0f all days"), 302 "Expected str to be 'The quick br0wn f0x was lazy t0day 0f all days', was: %s\n", dbgstrx(strBang)); 303 ok(strBang.GetLength() == 46, "Expected GetLength() to be 46, was: %i\n", strBang.GetLength()); 304 305 n = strBang.Replace(_X("y "), _X("y, ")); 306 ok(n == 2, "Expected n to be 2, was %i\n", n); 307 ok(strBang == _X("The quick br0wn f0x was lazy, t0day, 0f all days"), 308 "Expected str to be 'The quick br0wn f0x was lazy, t0day, 0f all days', was: %s\n", dbgstrx(strBang)); 309 ok(strBang.GetLength() == 48, "Expected GetLength() to be 48, was: %i\n", strBang.GetLength()); 310 311 n = strBang.Replace(_X(", 0f all days"), _X("")); 312 ok(n == 1, "Expected n to be 1, was %i\n", n); 313 ok(strBang == _X("The quick br0wn f0x was lazy, t0day"), 314 "Expected str to be 'The quick br0wn f0x was lazy, t0day', was: %s\n", dbgstrx(strBang)); 315 ok(strBang.GetLength() == 35, "Expected GetLength() to be 35, was: %i\n", strBang.GetLength()); 316 317 n = strBang.Replace(_X(" lazy, "), _X(" fast ")); 318 ok(n == 1, "Expected n to be 1, was %i\n", n); 319 ok(strBang == _X("The quick br0wn f0x was fast t0day"), 320 "Expected str to be 'The quick br0wn f0x was fast t0day', was: %s\n", dbgstrx(strBang)); 321 ok(strBang.GetLength() == 34, "Expected GetLength() to be 34, was: %i\n", strBang.GetLength()); 322 323 n = strBang.Replace(_X("The "), _X("")); 324 ok(n == 1, "Expected n to be 1, was %i\n", n); 325 ok(strBang == _X("quick br0wn f0x was fast t0day"), 326 "Expected str to be 'quick br0wn f0x was fast t0day', was: %s\n", dbgstrx(strBang)); 327 ok(strBang.GetLength() == 30, "Expected GetLength() to be 30, was: %i\n", strBang.GetLength()); 328 329 n = strBang.Replace(_X(" t0day"), _X("")); 330 ok(n == 1, "Expected n to be 1, was %i\n", n); 331 ok(strBang == _X("quick br0wn f0x was fast"), 332 "Expected str to be 'quick br0wn f0x was fast', was: %s\n", dbgstrx(strBang)); 333 ok(strBang.GetLength() == 24, "Expected GetLength() to be 24, was: %i\n", strBang.GetLength()); 334 335 n = strBang.Replace(_X("quick"), _X("The fast, quick")); 336 ok(n == 1, "Expected n to be 1, was %i\n", n); 337 ok(strBang == _X("The fast, quick br0wn f0x was fast"), 338 "Expected str to be 'The fast, quick br0wn f0x was fast', was: %s\n", dbgstrx(strBang)); 339 ok(strBang.GetLength() == 34, "Expected GetLength() to be 34, was: %i\n", strBang.GetLength()); 340} 341 342 343TEST_NAMEX(trim) 344{ 345 CStringX str; 346 str = _X(" \t\r\n******Trim some text!?!?!?!?!\n\r\t "); 347 348 str.TrimLeft(); 349 ok(str == _X("******Trim some text!?!?!?!?!\n\r\t "), "Expected str to be '******Trim some text!?!?!?!?!\n\r\t ', was: %s\n", dbgstrx(str)); 350 ok(str.GetLength() == 33, "Expected GetLength() to be 33, was: %i\n", str.GetLength()); 351 352 str.TrimRight(); 353 ok(str == _X("******Trim some text!?!?!?!?!"), "Expected str to be '******Trim some text!?!?!?!?!', was: %s\n", dbgstrx(str)); 354 ok(str.GetLength() == 29, "Expected GetLength() to be 29, was: %i\n", str.GetLength()); 355 356 CStringX str2 = str.Trim(_X("?!*")); 357 ok(str2 == _X("Trim some text"), "Expected str to be 'Trim some text', was: %s\n", dbgstrx(str2)); 358 ok(str2.GetLength() == 14, "Expected GetLength() to be 14, was: %i\n", str2.GetLength()); 359 360 str = _X("\t\t ****Trim some text!"); 361 str2 = str.TrimLeft(_X("\t *")); 362 ok(str2 == _X("Trim some text!"), "Expected str to be 'Trim some text!', was: %s\n", dbgstrx(str2)); 363 ok(str2.GetLength() == 15, "Expected GetLength() to be 15, was: %i\n", str2.GetLength()); 364 365 str = _X("Trim some text!?!?!?!?!"); 366 str2 = str.TrimRight(_X("?!")); 367 ok(str2 == _X("Trim some text"), "Expected str to be 'Trim some text', was: %s\n", dbgstrx(str2)); 368 ok(str2.GetLength() == 14, "Expected GetLength() to be 14, was: %i\n", str2.GetLength()); 369 370 str = _X("\t\t\t\t\t"); 371 str2 = str.TrimLeft(); 372 ok(str2 == _X(""), "Expected str2 to be '', was: %s\n", dbgstrx(str2)); 373 ok(str2.GetLength() == 0, "Expected GetLength() to be 0, was: %i\n", str2.GetLength()); 374 375 str = _X("\t\t\t\t\t"); 376 str2 = str.TrimRight(); 377 ok(str2 == _X(""), "Expected str2 to be '', was: %s\n", dbgstrx(str2)); 378 ok(str2.GetLength() == 0, "Expected GetLength() to be 0, was: %i\n", str2.GetLength()); 379 380 str = _X("\t\t\t\t\t"); 381 str2 = str.Trim(); 382 ok(str2 == _X(""), "Expected str2 to be '', was: %s\n", dbgstrx(str2)); 383 ok(str2.GetLength() == 0, "Expected GetLength() to be 0, was: %i\n", str2.GetLength()); 384} 385 386TEST_NAMEX(env) 387{ 388 CStringX test; 389 BOOL ret; 390 ok(test.IsEmpty() == true, "Expected test to be empty\n"); 391 ok(test.GetLength() == 0, "Expected GetLength() to be 0, was: %i\n", test.GetLength()); 392 ok(test.GetAllocLength() == 0, "Expected GetAllocLength() to be 0, was: %i\n", test.GetAllocLength()); 393 394 XCHAR buf[512]; 395 GetWindowsDirectoryX(buf, _countof(buf)); 396 397 ret = test.GetEnvironmentVariable(_X("SystemDrive")); 398 ok(!!ret, "Expected %%SystemDrive%% to exist\n"); 399 ok(test.IsEmpty() == false, "Expected test to have a valid result\n"); 400 ok(test.GetLength() == 2, "Expected GetLength() to be 2, was: %i\n", test.GetLength()); 401 if (test.GetLength() == 2) 402 { 403 ok(test[0] == buf[0], "Expected test[0] to equal buf[0], was: %c, %c\n", test[0], buf[0]); 404 ok(test[1] == buf[1], "Expected test[1] to equal buf[1], was: %c, %c\n", test[1], buf[1]); 405 } 406 407 ret = test.GetEnvironmentVariable(_X("SystemRoot")); 408 ok(!!ret, "Expected %%SystemRoot%% to exist\n"); 409 ok(test.IsEmpty() == false, "Expected test to have a valid result\n"); 410 ok(test == buf, "Expected test to be %s, was %s\n", dbgstrx(buf), dbgstrx(test)); 411 412 ret = test.GetEnvironmentVariable(_X("some non existing env var")); 413 ok(!ret, "Expected %%some non existing env var%% to not exist\n"); 414 ok(test.IsEmpty() == true, "Expected test to be empty\n"); 415 ok(test.GetLength() == 0, "Expected GetLength() to be 0, was: %i\n", test.GetLength()); 416} 417 418TEST_NAMEX(load_str) 419{ 420 CStringX str; 421 422 ok(str.LoadString(0) == FALSE, "LoadString should fail.\n"); 423 424 ok(str.LoadString(IDS_TEST1) == TRUE, "LoadString failed.\n"); 425 ok(str == _X("Test string one."), "The value was '%s'\n", dbgstrx(str)); 426 427 ok(str.LoadString(IDS_TEST2) == TRUE, "LoadString failed.\n"); 428 ok(str == _X("I am a happy BSTR"), "The value was '%s'\n", dbgstrx(str)); 429 430 ok(str.LoadString(0) == FALSE, "LoadString should fail.\n"); 431 ok(str == _X("I am a happy BSTR"), "The value was '%s'\n", dbgstrx(str)); 432 433 XCHAR *xNULL = NULL; 434 CStringX str0(xNULL); 435 ok(str0.IsEmpty(), "str0 should be empty.\n"); 436 437 YCHAR *yNULL = NULL; 438 CStringX str1(yNULL); 439 ok(str1.IsEmpty(), "str1 should be empty.\n"); 440 441 CStringX str2(MAKEINTRESOURCEX(IDS_TEST1)); 442 ok(str2 == _X("Test string one."), "The value was '%s'\n", dbgstrx(str2)); 443 444 CStringX str3(MAKEINTRESOURCEX(IDS_TEST2)); 445 ok(str3 == _X("I am a happy BSTR"), "The value was '%s'\n", dbgstrx(str3)); 446 447 CStringX str4(MAKEINTRESOURCEY(IDS_TEST1)); 448 ok(str4 == _X("Test string one."), "The value was '%s'\n", dbgstrx(str4)); 449 450 CStringX str5(MAKEINTRESOURCEY(IDS_TEST2)); 451 ok(str5 == _X("I am a happy BSTR"), "The value was '%s'\n", dbgstrx(str5)); 452} 453 454TEST_NAMEX(bstr) 455{ 456 CStringX str; 457 458 str = _X("Some test text here..."); 459 460 BSTR bstr = str.AllocSysString(); 461 ok(!!bstr, "Expected a valid pointer\n"); 462 if (bstr) 463 { 464 ok(!wcscmp(bstr, L"Some test text here..."), "Expected 'Some test text here...', got: '%S'\n", bstr); 465 ::SysFreeString(bstr); 466 } 467} 468 469TEST_NAMEX(tokenize) 470{ 471 CStringX str(_X("%#First Second#Third")); 472 const XCHAR* Tokens = _X("% #"); 473 CStringX res; 474 475 int nCurPos = 0; 476 477 // All 'current' tokens are skipped 478 res = str.Tokenize(Tokens, nCurPos); 479 ok(res == _X("First"), "Expected str to be 'First', was: %s\n", dbgstrx(res)); 480 ok_dec(nCurPos, 8); 481 482 res = str.Tokenize(Tokens, nCurPos); 483 ok(res == _X("Second"), "Expected str to be 'Second', was: %s\n", dbgstrx(res)); 484 ok_dec(nCurPos, 15); 485 486 res = str.Tokenize(Tokens, nCurPos); 487 ok(res == _X("Third"), "Expected str to be 'Third', was: %s\n", dbgstrx(res)); 488 ok_dec(nCurPos, 21); 489 490 // The final 'token' is empty, and nCurPos is set to -1 491 // (Calling with nCurPos=-1 will assert) 492 res = str.Tokenize(Tokens, nCurPos); 493 ok(res == _X(""), "Expected str to be '', was: %s\n", dbgstrx(res)); 494 ok_dec(nCurPos, -1); 495 496 str =_X("StartWithToken#%#"); 497 nCurPos = 0; 498 499 res = str.Tokenize(Tokens, nCurPos); 500 ok(res == _X("StartWithToken"), "Expected str to be 'StartWithToken', was: %s\n", dbgstrx(res)); 501 ok_dec(nCurPos, 15); 502 503 // Ending with tokens acts as if there were no tokens at the end 504 res = str.Tokenize(Tokens, nCurPos); 505 ok(res == _X(""), "Expected str to be '', was: %s\n", dbgstrx(res)); 506 ok_dec(nCurPos, -1); 507 508 509 str = _X(""); 510 nCurPos = 0; 511 512 // Calling with an empty string returns 'no tokens' 513 res = str.Tokenize(Tokens, nCurPos); 514 ok(res == _X(""), "Expected str to be '', was: %s\n", dbgstrx(res)); 515 ok_dec(nCurPos, -1); 516 517 str = _X(""); 518 nCurPos = 20; 519 520 // Calling with a current position outside the strings acts the same as 'no tokens left' 521 res = str.Tokenize(Tokens, nCurPos); 522 ok(res == _X(""), "Expected str to be '', was: %s\n", dbgstrx(res)); 523 ok_dec(nCurPos, -1); 524 525 526 str = _X("test"); 527 nCurPos = 2; 528 529 // Calling with a NULL pszTokens returns a substring starting at 'nCurPos', but not updating nCurPos! 530 res = str.Tokenize(NULL, nCurPos); 531 ok(res == _X("st"), "Expected str to be 'st', was: %s\n", dbgstrx(res)); 532 ok_dec(nCurPos, 2); 533 534 535 // Calling with an empty pszTokens behaves exactly the same 536 res = str.Tokenize(_X(""), nCurPos); 537 ok(res == _X("st"), "Expected str to be 'st', was: %s\n", dbgstrx(res)); 538 ok_dec(nCurPos, 2); 539 540 nCurPos = 8; 541 542 // Calling with a NULL pszTokens and an nCurPos out of bounds returns 'no tokens left' 543 res = str.Tokenize(NULL, nCurPos); 544 ok(res == _X(""), "Expected str to be '', was: %s\n", dbgstrx(res)); 545 ok_dec(nCurPos, -1); 546 547 nCurPos = 8; 548 549 // Calling with an empty pszTokens behaves exactly the same 550 res = str.Tokenize(_X(""), nCurPos); 551 ok(res == _X(""), "Expected str to be '', was: %s\n", dbgstrx(res)); 552 ok_dec(nCurPos, -1); 553} 554