2 TEST_NAMEX(operators_init)
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());
10 const XCHAR* cstring = (const XCHAR*)test;
11 ok(cstring != NULL, "Expected a valid pointer\n");
14 ok(cstring[0] == '\0', "Expected \\0, got: %c (%i)\n", cstring[0], (int)cstring[0]);
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(first.GetAllocLength() == ALLOC_EXPECT(7, 6), "Expected GetAllocLength() to be %i, was: %i\n", ALLOC_EXPECT(7, 6), first.GetAllocLength());
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(second.GetAllocLength() == ALLOC_EXPECT(7, 6), "Expected GetAllocLength() to be %i, was: %i\n", ALLOC_EXPECT(7, 6), second.GetAllocLength());
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(test.GetAllocLength() == ALLOC_EXPECT(7, 6), "Expected GetAllocLength() to be %i, was: %i\n", ALLOC_EXPECT(7, 6), test.GetAllocLength());
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(test.GetAllocLength() == 0, "Expected GetAllocLength() to be 0, was: %i\n", test.GetAllocLength());
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(test.GetAllocLength() == ALLOC_EXPECT(7, 6), "Expected GetAllocLength() to be %i, was: %i\n", ALLOC_EXPECT(7, 6), test.GetAllocLength());
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(test.GetAllocLength() == ALLOC_EXPECT(15, 12), "Expected GetAllocLength() to be %i, was: %i\n", ALLOC_EXPECT(15, 12), test.GetAllocLength());
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(test.GetAllocLength() == ALLOC_EXPECT(15, 12), "Expected GetAllocLength() to be %i, was: %i\n", ALLOC_EXPECT(15, 12), test.GetAllocLength());
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(test.GetAllocLength() == ALLOC_EXPECT(15, 18), "Expected GetAllocLength() to be %i, was: %i\n", ALLOC_EXPECT(15, 18), test.GetAllocLength());
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(test2.GetAllocLength() == ALLOC_EXPECT(15, 18), "Expected GetAllocLength() to be %i, was: %i\n", ALLOC_EXPECT(15, 18), test2.GetAllocLength());
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(test.GetAllocLength() == 0, "Expected GetAllocLength() to be 0, was: %i\n", test.GetAllocLength());
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(test.GetAllocLength() == ALLOC_EXPECT(7, 6), "Expected GetAllocLength() to be 7, was: %i\n", test.GetAllocLength());
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(testA.GetAllocLength() == ALLOC_EXPECT(7, 6), "Expected GetAllocLength() to be 7, was: %i\n", testA.GetAllocLength());
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(testW.GetAllocLength() == ALLOC_EXPECT(7, 6), "Expected GetAllocLength() to be 7, was: %i\n", testW.GetAllocLength());
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(test.GetAllocLength() == ALLOC_EXPECT(7, 6), "Expected GetAllocLength() to be 7, was: %i\n", test.GetAllocLength());
95 s1 = s2 = _X("some text 1!");
97 int c = s1.Compare(s2);
98 ok(c == 0, "Expected c to be 1, was: %i\n", c);
100 c = s1.Compare(_X("r"));
101 ok(c == 1, "Expected c to be 1, was: %i\n", c);
103 c = s1.Compare(_X("s"));
104 ok(c == 1, "Expected c to be 1, was: %i\n", c);
106 c = s1.Compare(_X("t"));
107 ok(c == -1, "Expected c to be -1, was: %i\n", c);
109 c = s1.Compare(_X("R"));
110 ok(c == 1, "Expected c to be 1, was: %i\n", c);
112 c = s1.Compare(_X("S"));
113 ok(c == 1, "Expected c to be 1, was: %i\n", c);
115 c = s1.Compare(_X("T"));
116 ok(c == 1, "Expected c to be 1, was: %i\n", c);
118 ok(s1 == s2, "Expected s1 and s2 to be equal: '%s' == '%s'\n", dbgstrx(s1), dbgstrx(s2));
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]);
124 ok(s1 == _X("SOME TEXT 1!"), "Expected s1 to be 'SOME TEXT 1!', was: %s\n", dbgstrx(s1));
126 CStringX s3 = s1.MakeLower();
127 ok(s1 == _X("some text 1!"), "Expected s1 to be 'some text 1!', was: %s\n", dbgstrx(s1));
128 ok(s1 == s3, "Expected s1 and s3 to be equal: '%s' == '%s'\n", dbgstrx(s1), dbgstrx(s3));
134 CStringX s(_X("adbcdef"));
135 int n = s.Find(_X('c'));
136 ok(n == 3, "Expected n to be 2, was %i\n", n);
137 n = s.Find(_X("de"));
138 ok(n == 4, "Expected n to be 4, was %i\n", n);
140 CStringX str(_X("The waves are still"));
141 n = str.Find(_X('e'), 5);
142 ok(n == 7, "Expected n to be 7, was %i\n", n);
143 n = str.Find(_X('e'), 7);
144 ok(n == 7, "Expected n to be 7, was %i\n", n);
146 s = _X("abcdefGHIJKLMNop");
147 n = s.FindOneOf(_X("Nd"));
148 ok(n == 3, "Expected n to be 3, was %i\n", n);
149 n = s.FindOneOf(_X("Np"));
150 ok(n == 13, "Expected n to be 13, was %i\n", n);
152 n = str.ReverseFind(_X('l'));
153 ok(n == 18, "Expected n to be 18, was %i\n", n);
155 n = str.ReverseFind(_X('e'));
156 ok(n == 12, "Expected n to be 12, was %i\n", n);
160 void WriteString(const XCHAR* pstrFormat, ...)
165 va_start(args, pstrFormat);
167 str.FormatV(pstrFormat, args);
170 ok(str == _X("10e 1351l"), "Expected str to be '10e 1351l', was: %s\n", dbgstrx(str));
177 str.Format(_X("FP: %.2f"), 12345.12345);
178 ok(str == _X("FP: 12345.12"), "Expected str to be 'FP: 12345.12', was: %s\n", dbgstrx(str));
180 str.Format(_X("int: %.6d"), 35);
181 ok(str == _X("int: 000035"), "Expected str to be 'int: 000035', was: %s\n", dbgstrx(str));
183 WriteString(_X("%de %dl"), 10, 1351);
189 CStringX s(_X("abcdef"));
191 CStringX m = s.Mid(2, 3);
192 ok(m == _X("cde"), "Expected str to be 'cde', was: %s\n", dbgstrx(m));
193 ok(m.GetLength() == 3, "Expected GetLength() to be 3, was: %i\n", m.GetLength());
196 ok(m == _X("abc"), "Expected str to be 'abc', was: %s\n", dbgstrx(m));
197 ok(m.GetLength() == 3, "Expected GetLength() to be 3, was: %i\n", m.GetLength());
200 ok(m == _X("def"), "Expected str to be 'def', was: %s\n", dbgstrx(m));
201 ok(m.GetLength() == 3, "Expected GetLength() to be 3, was: %i\n", m.GetLength());
204 ok(m == _X(""), "Expected str to be '', was: %s\n", dbgstrx(m));
205 ok(m.GetLength() == 0, "Expected GetLength() to be 0, was: %i\n", m.GetLength());
208 ok(m == _X("cdef"), "Expected str to be 'cdef', was: %s\n", dbgstrx(m));
209 ok(m.GetLength() == 4, "Expected GetLength() to be 4, was: %i\n", m.GetLength());
212 ok(m == _X("abcdef"), "Expected str to be 'abcdef', was: %s\n", dbgstrx(m));
213 ok(m.GetLength() == 6, "Expected GetLength() to be 6, was: %i\n", m.GetLength());
216 ok(m == _X(""), "Expected str to be '', was: %s\n", dbgstrx(m));
217 ok(m.GetLength() == 0, "Expected GetLength() to be 0, was: %i\n", m.GetLength());
220 ok(m == _X("ab"), "Expected str to be 'ab', was: %s\n", dbgstrx(m));
221 ok(m.GetLength() == 2, "Expected GetLength() to be 2, was: %i\n", m.GetLength());
224 ok(m == _X("abcdef"), "Expected str to be 'abcdef', was: %s\n", dbgstrx(m));
225 ok(m.GetLength() == 6, "Expected GetLength() to be 6, was: %i\n", m.GetLength());
228 ok(m == _X(""), "Expected str to be '', was: %s\n", dbgstrx(m));
229 ok(m.GetLength() == 0, "Expected GetLength() to be 0, was: %i\n", m.GetLength());
232 ok(m == _X("ef"), "Expected str to be 'ef', was: %s\n", dbgstrx(m));
233 ok(m.GetLength() == 2, "Expected GetLength() to be 2, was: %i\n", m.GetLength());
236 ok(m == _X(""), "Expected str to be '', was: %s\n", dbgstrx(m));
237 ok(m.GetLength() == 0, "Expected GetLength() to be 0, was: %i\n", m.GetLength());
240 ok(m == _X("abcdef"), "Expected str to be 'abcdef', was: %s\n", dbgstrx(m));
241 ok(m.GetLength() == 6, "Expected GetLength() to be 6, was: %i\n", m.GetLength());
247 CStringX str(_X("abcde"));
248 int n = str.Replace(_X("b"), _X("bx"));
249 ok(n == 1, "Expected n to be 1, was %i\n", n);
250 ok(str == _X("abxcde"), "Expected str to be 'abxcde', was: %s\n", dbgstrx(str));
251 ok(str.GetLength() == 6, "Expected GetLength() to be 6, was: %i\n", str.GetLength());
253 CStringX strBang(_X("The quick brown fox is lazy today of all days"));
255 n = strBang.Replace(_X("is"), _X("was"));
256 ok(n == 1, "Expected n to be 1, was %i\n", n);
257 ok(strBang == _X("The quick brown fox was lazy today of all days"),
258 "Expected str to be 'The quick brown fox was lazy today of all days', was: %s\n", dbgstrx(strBang));
259 ok(strBang.GetLength() == 46, "Expected GetLength() to be 46, was: %i\n", strBang.GetLength());
261 n = strBang.Replace(_X("is"), _X("was"));
262 ok(n == 0, "Expected n to be 0, was %i\n", n);
263 ok(strBang == _X("The quick brown fox was lazy today of all days"),
264 "Expected str to be 'The quick brown fox was lazy today of all days', was: %s\n", dbgstrx(strBang));
265 ok(strBang.GetLength() == 46, "Expected GetLength() to be 46, was: %i\n", strBang.GetLength());
267 n = strBang.Replace(_X('o'), _X('0'));
268 ok(n == 4, "Expected n to be 4, was %i\n", n);
269 ok(strBang == _X("The quick br0wn f0x was lazy t0day 0f all days"),
270 "Expected str to be 'The quick br0wn f0x was lazy t0day 0f all days', was: %s\n", dbgstrx(strBang));
271 ok(strBang.GetLength() == 46, "Expected GetLength() to be 46, was: %i\n", strBang.GetLength());
273 n = strBang.Replace(_X('o'), _X('0'));
274 ok(n == 0, "Expected n to be 0, was %i\n", n);
275 ok(strBang == _X("The quick br0wn f0x was lazy t0day 0f all days"),
276 "Expected str to be 'The quick br0wn f0x was lazy t0day 0f all days', was: %s\n", dbgstrx(strBang));
277 ok(strBang.GetLength() == 46, "Expected GetLength() to be 46, was: %i\n", strBang.GetLength());
279 n = strBang.Replace(_X("y "), _X("y, "));
280 ok(n == 2, "Expected n to be 2, was %i\n", n);
281 ok(strBang == _X("The quick br0wn f0x was lazy, t0day, 0f all days"),
282 "Expected str to be 'The quick br0wn f0x was lazy, t0day, 0f all days', was: %s\n", dbgstrx(strBang));
283 ok(strBang.GetLength() == 48, "Expected GetLength() to be 48, was: %i\n", strBang.GetLength());
285 n = strBang.Replace(_X(", 0f all days"), _X(""));
286 ok(n == 1, "Expected n to be 1, was %i\n", n);
287 ok(strBang == _X("The quick br0wn f0x was lazy, t0day"),
288 "Expected str to be 'The quick br0wn f0x was lazy, t0day', was: %s\n", dbgstrx(strBang));
289 ok(strBang.GetLength() == 35, "Expected GetLength() to be 35, was: %i\n", strBang.GetLength());
291 n = strBang.Replace(_X(" lazy, "), _X(" fast "));
292 ok(n == 1, "Expected n to be 1, was %i\n", n);
293 ok(strBang == _X("The quick br0wn f0x was fast t0day"),
294 "Expected str to be 'The quick br0wn f0x was fast t0day', was: %s\n", dbgstrx(strBang));
295 ok(strBang.GetLength() == 34, "Expected GetLength() to be 34, was: %i\n", strBang.GetLength());
297 n = strBang.Replace(_X("The "), _X(""));
298 ok(n == 1, "Expected n to be 1, was %i\n", n);
299 ok(strBang == _X("quick br0wn f0x was fast t0day"),
300 "Expected str to be 'quick br0wn f0x was fast t0day', was: %s\n", dbgstrx(strBang));
301 ok(strBang.GetLength() == 30, "Expected GetLength() to be 30, was: %i\n", strBang.GetLength());
303 n = strBang.Replace(_X(" t0day"), _X(""));
304 ok(n == 1, "Expected n to be 1, was %i\n", n);
305 ok(strBang == _X("quick br0wn f0x was fast"),
306 "Expected str to be 'quick br0wn f0x was fast', was: %s\n", dbgstrx(strBang));
307 ok(strBang.GetLength() == 24, "Expected GetLength() to be 24, was: %i\n", strBang.GetLength());
309 n = strBang.Replace(_X("quick"), _X("The fast, quick"));
310 ok(n == 1, "Expected n to be 1, was %i\n", n);
311 ok(strBang == _X("The fast, quick br0wn f0x was fast"),
312 "Expected str to be 'The fast, quick br0wn f0x was fast', was: %s\n", dbgstrx(strBang));
313 ok(strBang.GetLength() == 34, "Expected GetLength() to be 34, was: %i\n", strBang.GetLength());
320 str = _X(" \t\r\n******Trim some text!?!?!?!?!\n\r\t ");
323 ok(str == _X("******Trim some text!?!?!?!?!\n\r\t "), "Expected str to be '******Trim some text!?!?!?!?!\n\r\t ', was: %s\n", dbgstrx(str));
324 ok(str.GetLength() == 33, "Expected GetLength() to be 33, was: %i\n", str.GetLength());
327 ok(str == _X("******Trim some text!?!?!?!?!"), "Expected str to be '******Trim some text!?!?!?!?!', was: %s\n", dbgstrx(str));
328 ok(str.GetLength() == 29, "Expected GetLength() to be 29, was: %i\n", str.GetLength());
330 CStringX str2 = str.Trim(_X("?!*"));
331 ok(str2 == _X("Trim some text"), "Expected str to be 'Trim some text', was: %s\n", dbgstrx(str2));
332 ok(str2.GetLength() == 14, "Expected GetLength() to be 14, was: %i\n", str2.GetLength());
334 str = _X("\t\t ****Trim some text!");
335 str2 = str.TrimLeft(_X("\t *"));
336 ok(str2 == _X("Trim some text!"), "Expected str to be 'Trim some text!', was: %s\n", dbgstrx(str2));
337 ok(str2.GetLength() == 15, "Expected GetLength() to be 15, was: %i\n", str2.GetLength());
339 str = _X("Trim some text!?!?!?!?!");
340 str2 = str.TrimRight(_X("?!"));
341 ok(str2 == _X("Trim some text"), "Expected str to be 'Trim some text', was: %s\n", dbgstrx(str2));
342 ok(str2.GetLength() == 14, "Expected GetLength() to be 14, was: %i\n", str2.GetLength());
344 str = _X("\t\t\t\t\t");
345 str2 = str.TrimLeft();
346 ok(str2 == _X(""), "Expected str2 to be '', was: %s\n", dbgstrx(str2));
347 ok(str2.GetLength() == 0, "Expected GetLength() to be 0, was: %i\n", str2.GetLength());
349 str = _X("\t\t\t\t\t");
350 str2 = str.TrimRight();
351 ok(str2 == _X(""), "Expected str2 to be '', was: %s\n", dbgstrx(str2));
352 ok(str2.GetLength() == 0, "Expected GetLength() to be 0, was: %i\n", str2.GetLength());
354 str = _X("\t\t\t\t\t");
356 ok(str2 == _X(""), "Expected str2 to be '', was: %s\n", dbgstrx(str2));
357 ok(str2.GetLength() == 0, "Expected GetLength() to be 0, was: %i\n", str2.GetLength());
364 ok(test.IsEmpty() == true, "Expected test to be empty\n");
365 ok(test.GetLength() == 0, "Expected GetLength() to be 0, was: %i\n", test.GetLength());
366 ok(test.GetAllocLength() == 0, "Expected GetAllocLength() to be 0, was: %i\n", test.GetAllocLength());
369 GetWindowsDirectoryX(buf, _countof(buf));
371 ret = test.GetEnvironmentVariable(_X("SystemDrive"));
372 ok(!!ret, "Expected %%SystemDrive%% to exist\n");
373 ok(test.IsEmpty() == false, "Expected test to have a valid result\n");
374 ok(test.GetLength() == 2, "Expected GetLength() to be 2, was: %i\n", test.GetLength());
375 if (test.GetLength() == 2)
377 ok(test[0] == buf[0], "Expected test[0] to equal buf[0], was: %c, %c\n", test[0], buf[0]);
378 ok(test[1] == buf[1], "Expected test[1] to equal buf[1], was: %c, %c\n", test[1], buf[1]);
381 ret = test.GetEnvironmentVariable(_X("SystemRoot"));
382 ok(!!ret, "Expected %%SystemRoot%% to exist\n");
383 ok(test.IsEmpty() == false, "Expected test to have a valid result\n");
384 ok(test == buf, "Expected test to be %s, was %s\n", dbgstrx(buf), dbgstrx(test));
386 ret = test.GetEnvironmentVariable(_X("some non existing env var"));
387 ok(!ret, "Expected %%some non existing env var%% to not exist\n");
388 ok(test.IsEmpty() == true, "Expected test to be empty\n");
389 ok(test.GetLength() == 0, "Expected GetLength() to be 0, was: %i\n", test.GetLength());
396 ok(str.LoadString(0) == FALSE, "LoadString should fail.\n");
398 ok(str.LoadString(IDS_TEST1) == TRUE, "LoadString failed.\n");
399 ok(str == _X("Test string one."), "The value was '%s'\n", dbgstrx(str));
401 ok(str.LoadString(IDS_TEST2) == TRUE, "LoadString failed.\n");
402 ok(str == _X("I am a happy BSTR"), "The value was '%s'\n", dbgstrx(str));
404 ok(str.LoadString(0) == FALSE, "LoadString should fail.\n");
405 ok(str == _X("I am a happy BSTR"), "The value was '%s'\n", dbgstrx(str));
408 CStringX str0(xNULL);
409 ok(str0.IsEmpty(), "str0 should be empty.\n");
412 CStringX str1(yNULL);
413 ok(str1.IsEmpty(), "str1 should be empty.\n");
415 CStringX str2(MAKEINTRESOURCEX(IDS_TEST1));
416 ok(str2 == _X("Test string one."), "The value was '%s'\n", dbgstrx(str2));
418 CStringX str3(MAKEINTRESOURCEX(IDS_TEST2));
419 ok(str3 == _X("I am a happy BSTR"), "The value was '%s'\n", dbgstrx(str3));
421 CStringX str4(MAKEINTRESOURCEY(IDS_TEST1));
422 ok(str4 == _X("Test string one."), "The value was '%s'\n", dbgstrx(str4));
424 CStringX str5(MAKEINTRESOURCEY(IDS_TEST2));
425 ok(str5 == _X("I am a happy BSTR"), "The value was '%s'\n", dbgstrx(str5));