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
190TEST_NAMEX(format)
191{
192    CStringX str;
193
194    str.Format(_X("FP: %.2f"), 12345.12345);
195    ok(str == _X("FP: 12345.12"), "Expected str to be 'FP: 12345.12', was: %s\n", dbgstrx(str));
196
197    str.Format(_X("int: %.6d"), 35);
198    ok(str == _X("int: 000035"), "Expected str to be 'int: 000035', was: %s\n", dbgstrx(str));
199
200    WriteString(_X("%de %dl"), 10, 1351);
201}
202
203
204TEST_NAMEX(substr)
205{
206    CStringX s(_X("abcdef"));
207
208    CStringX m = s.Mid(2, 3);
209    ok(m == _X("cde"), "Expected str to be 'cde', was: %s\n", dbgstrx(m));
210    ok(m.GetLength() == 3, "Expected GetLength() to be 3, was: %i\n", m.GetLength());
211
212    m = s.Mid(-5, 3);
213    ok(m == _X("abc"), "Expected str to be 'abc', was: %s\n", dbgstrx(m));
214    ok(m.GetLength() == 3, "Expected GetLength() to be 3, was: %i\n", m.GetLength());
215
216    m = s.Mid(3, 20);
217    ok(m == _X("def"), "Expected str to be 'def', was: %s\n", dbgstrx(m));
218    ok(m.GetLength() == 3, "Expected GetLength() to be 3, was: %i\n", m.GetLength());
219
220    m = s.Mid(3, -1);
221    ok(m == _X(""), "Expected str to be '', was: %s\n", dbgstrx(m));
222    ok(m.GetLength() == 0, "Expected GetLength() to be 0, was: %i\n", m.GetLength());
223
224    m = s.Mid(2);
225    ok(m == _X("cdef"), "Expected str to be 'cdef', was: %s\n", dbgstrx(m));
226    ok(m.GetLength() == 4, "Expected GetLength() to be 4, was: %i\n", m.GetLength());
227
228    m = s.Mid(-3);
229    ok(m == _X("abcdef"), "Expected str to be 'abcdef', was: %s\n", dbgstrx(m));
230    ok(m.GetLength() == 6, "Expected GetLength() to be 6, was: %i\n", m.GetLength());
231
232    m = s.Mid(20);
233    ok(m == _X(""), "Expected str to be '', was: %s\n", dbgstrx(m));
234    ok(m.GetLength() == 0, "Expected GetLength() to be 0, was: %i\n", m.GetLength());
235
236    m = s.Left(2);
237    ok(m == _X("ab"), "Expected str to be 'ab', was: %s\n", dbgstrx(m));
238    ok(m.GetLength() == 2, "Expected GetLength() to be 2, was: %i\n", m.GetLength());
239
240    m = s.Left(40);
241    ok(m == _X("abcdef"), "Expected str to be 'abcdef', was: %s\n", dbgstrx(m));
242    ok(m.GetLength() == 6, "Expected GetLength() to be 6, was: %i\n", m.GetLength());
243
244    m = s.Left(-10);
245    ok(m == _X(""), "Expected str to be '', was: %s\n", dbgstrx(m));
246    ok(m.GetLength() == 0, "Expected GetLength() to be 0, was: %i\n", m.GetLength());
247
248    m = s.Right(2);
249    ok(m == _X("ef"), "Expected str to be 'ef', was: %s\n", dbgstrx(m));
250    ok(m.GetLength() == 2, "Expected GetLength() to be 2, was: %i\n", m.GetLength());
251
252    m = s.Right(-40);
253    ok(m == _X(""), "Expected str to be '', was: %s\n", dbgstrx(m));
254    ok(m.GetLength() == 0, "Expected GetLength() to be 0, was: %i\n", m.GetLength());
255
256    m = s.Right(99);
257    ok(m == _X("abcdef"), "Expected str to be 'abcdef', was: %s\n", dbgstrx(m));
258    ok(m.GetLength() == 6, "Expected GetLength() to be 6, was: %i\n", m.GetLength());
259}
260
261
262TEST_NAMEX(replace)
263{
264    CStringX str(_X("abcde"));
265    int n = str.Replace(_X("b"), _X("bx"));
266    ok(n == 1, "Expected n to be 1, was %i\n", n);
267    ok(str == _X("abxcde"), "Expected str to be 'abxcde', was: %s\n", dbgstrx(str));
268    ok(str.GetLength() == 6, "Expected GetLength() to be 6, was: %i\n", str.GetLength());
269
270    CStringX strBang(_X("The quick brown fox is lazy today of all days"));
271
272    n = strBang.Replace(_X("is"), _X("was"));
273    ok(n == 1, "Expected n to be 1, was %i\n", n);
274    ok(strBang == _X("The quick brown fox was lazy today of all days"),
275        "Expected str to be 'The quick brown fox was lazy today of all days', was: %s\n", dbgstrx(strBang));
276    ok(strBang.GetLength() == 46, "Expected GetLength() to be 46, was: %i\n", strBang.GetLength());
277
278    n = strBang.Replace(_X("is"), _X("was"));
279    ok(n == 0, "Expected n to be 0, was %i\n", n);
280    ok(strBang == _X("The quick brown fox was lazy today of all days"),
281        "Expected str to be 'The quick brown fox was lazy today of all days', was: %s\n", dbgstrx(strBang));
282    ok(strBang.GetLength() == 46, "Expected GetLength() to be 46, was: %i\n", strBang.GetLength());
283
284    n = strBang.Replace(_X('o'), _X('0'));
285    ok(n == 4, "Expected n to be 4, was %i\n", n);
286    ok(strBang == _X("The quick br0wn f0x was lazy t0day 0f all days"),
287        "Expected str to be 'The quick br0wn f0x was lazy t0day 0f all days', was: %s\n", dbgstrx(strBang));
288    ok(strBang.GetLength() == 46, "Expected GetLength() to be 46, was: %i\n", strBang.GetLength());
289
290    n = strBang.Replace(_X('o'), _X('0'));
291    ok(n == 0, "Expected n to be 0, was %i\n", n);
292    ok(strBang == _X("The quick br0wn f0x was lazy t0day 0f all days"),
293        "Expected str to be 'The quick br0wn f0x was lazy t0day 0f all days', was: %s\n", dbgstrx(strBang));
294    ok(strBang.GetLength() == 46, "Expected GetLength() to be 46, was: %i\n", strBang.GetLength());
295
296    n = strBang.Replace(_X("y "), _X("y, "));
297    ok(n == 2, "Expected n to be 2, was %i\n", n);
298    ok(strBang == _X("The quick br0wn f0x was lazy, t0day, 0f all days"),
299        "Expected str to be 'The quick br0wn f0x was lazy, t0day, 0f all days', was: %s\n", dbgstrx(strBang));
300    ok(strBang.GetLength() == 48, "Expected GetLength() to be 48, was: %i\n", strBang.GetLength());
301
302    n = strBang.Replace(_X(", 0f all days"), _X(""));
303    ok(n == 1, "Expected n to be 1, was %i\n", n);
304    ok(strBang == _X("The quick br0wn f0x was lazy, t0day"),
305        "Expected str to be 'The quick br0wn f0x was lazy, t0day', was: %s\n", dbgstrx(strBang));
306    ok(strBang.GetLength() == 35, "Expected GetLength() to be 35, was: %i\n", strBang.GetLength());
307
308    n = strBang.Replace(_X(" lazy, "), _X(" fast "));
309    ok(n == 1, "Expected n to be 1, was %i\n", n);
310    ok(strBang == _X("The quick br0wn f0x was fast t0day"),
311        "Expected str to be 'The quick br0wn f0x was fast t0day', was: %s\n", dbgstrx(strBang));
312    ok(strBang.GetLength() == 34, "Expected GetLength() to be 34, was: %i\n", strBang.GetLength());
313
314    n = strBang.Replace(_X("The "), _X(""));
315    ok(n == 1, "Expected n to be 1, was %i\n", n);
316    ok(strBang == _X("quick br0wn f0x was fast t0day"),
317        "Expected str to be 'quick br0wn f0x was fast t0day', was: %s\n", dbgstrx(strBang));
318    ok(strBang.GetLength() == 30, "Expected GetLength() to be 30, was: %i\n", strBang.GetLength());
319
320    n = strBang.Replace(_X(" t0day"), _X(""));
321    ok(n == 1, "Expected n to be 1, was %i\n", n);
322    ok(strBang == _X("quick br0wn f0x was fast"),
323        "Expected str to be 'quick br0wn f0x was fast', was: %s\n", dbgstrx(strBang));
324    ok(strBang.GetLength() == 24, "Expected GetLength() to be 24, was: %i\n", strBang.GetLength());
325
326    n = strBang.Replace(_X("quick"), _X("The fast, quick"));
327    ok(n == 1, "Expected n to be 1, was %i\n", n);
328    ok(strBang == _X("The fast, quick br0wn f0x was fast"),
329        "Expected str to be 'The fast, quick br0wn f0x was fast', was: %s\n", dbgstrx(strBang));
330    ok(strBang.GetLength() == 34, "Expected GetLength() to be 34, was: %i\n", strBang.GetLength());
331}
332
333
334TEST_NAMEX(trim)
335{
336    CStringX str;
337    str = _X(" \t\r\n******Trim some text!?!?!?!?!\n\r\t ");
338
339    str.TrimLeft();
340    ok(str == _X("******Trim some text!?!?!?!?!\n\r\t "), "Expected str to be '******Trim some text!?!?!?!?!\n\r\t ', was: %s\n", dbgstrx(str));
341    ok(str.GetLength() == 33, "Expected GetLength() to be 33, was: %i\n", str.GetLength());
342
343    str.TrimRight();
344    ok(str == _X("******Trim some text!?!?!?!?!"), "Expected str to be '******Trim some text!?!?!?!?!', was: %s\n", dbgstrx(str));
345    ok(str.GetLength() == 29, "Expected GetLength() to be 29, was: %i\n", str.GetLength());
346
347    CStringX str2 = str.Trim(_X("?!*"));
348    ok(str2 == _X("Trim some text"), "Expected str to be 'Trim some text', was: %s\n", dbgstrx(str2));
349    ok(str2.GetLength() == 14, "Expected GetLength() to be 14, was: %i\n", str2.GetLength());
350
351    str = _X("\t\t   ****Trim some text!");
352    str2 = str.TrimLeft(_X("\t *"));
353    ok(str2 == _X("Trim some text!"), "Expected str to be 'Trim some text!', was: %s\n", dbgstrx(str2));
354    ok(str2.GetLength() == 15, "Expected GetLength() to be 15, was: %i\n", str2.GetLength());
355
356    str = _X("Trim some text!?!?!?!?!");
357    str2 = str.TrimRight(_X("?!"));
358    ok(str2 == _X("Trim some text"), "Expected str to be 'Trim some text', was: %s\n", dbgstrx(str2));
359    ok(str2.GetLength() == 14, "Expected GetLength() to be 14, was: %i\n", str2.GetLength());
360
361    str = _X("\t\t\t\t\t");
362    str2 = str.TrimLeft();
363    ok(str2 == _X(""), "Expected str2 to be '', was: %s\n", dbgstrx(str2));
364    ok(str2.GetLength() == 0, "Expected GetLength() to be 0, was: %i\n", str2.GetLength());
365
366    str = _X("\t\t\t\t\t");
367    str2 = str.TrimRight();
368    ok(str2 == _X(""), "Expected str2 to be '', was: %s\n", dbgstrx(str2));
369    ok(str2.GetLength() == 0, "Expected GetLength() to be 0, was: %i\n", str2.GetLength());
370
371    str = _X("\t\t\t\t\t");
372    str2 = str.Trim();
373    ok(str2 == _X(""), "Expected str2 to be '', was: %s\n", dbgstrx(str2));
374    ok(str2.GetLength() == 0, "Expected GetLength() to be 0, was: %i\n", str2.GetLength());
375}
376
377TEST_NAMEX(env)
378{
379    CStringX test;
380    BOOL ret;
381    ok(test.IsEmpty() == true, "Expected test to be empty\n");
382    ok(test.GetLength() == 0, "Expected GetLength() to be 0, was: %i\n", test.GetLength());
383    ok(test.GetAllocLength() == 0, "Expected GetAllocLength() to be 0, was: %i\n", test.GetAllocLength());
384
385    XCHAR buf[512];
386    GetWindowsDirectoryX(buf, _countof(buf));
387
388    ret = test.GetEnvironmentVariable(_X("SystemDrive"));
389    ok(!!ret, "Expected %%SystemDrive%% to exist\n");
390    ok(test.IsEmpty() == false, "Expected test to have a valid result\n");
391    ok(test.GetLength() == 2, "Expected GetLength() to be 2, was: %i\n", test.GetLength());
392    if (test.GetLength() == 2)
393    {
394        ok(test[0] == buf[0], "Expected test[0] to equal buf[0], was: %c, %c\n", test[0], buf[0]);
395        ok(test[1] == buf[1], "Expected test[1] to equal buf[1], was: %c, %c\n", test[1], buf[1]);
396    }
397
398    ret = test.GetEnvironmentVariable(_X("SystemRoot"));
399    ok(!!ret, "Expected %%SystemRoot%% to exist\n");
400    ok(test.IsEmpty() == false, "Expected test to have a valid result\n");
401    ok(test == buf, "Expected test to be %s, was %s\n", dbgstrx(buf), dbgstrx(test));
402
403    ret = test.GetEnvironmentVariable(_X("some non existing env var"));
404    ok(!ret, "Expected %%some non existing env var%% to not exist\n");
405    ok(test.IsEmpty() == true, "Expected test to be empty\n");
406    ok(test.GetLength() == 0, "Expected GetLength() to be 0, was: %i\n", test.GetLength());
407}
408
409TEST_NAMEX(load_str)
410{
411    CStringX str;
412
413    ok(str.LoadString(0) == FALSE, "LoadString should fail.\n");
414
415    ok(str.LoadString(IDS_TEST1) == TRUE, "LoadString failed.\n");
416    ok(str == _X("Test string one."), "The value was '%s'\n", dbgstrx(str));
417
418    ok(str.LoadString(IDS_TEST2) == TRUE, "LoadString failed.\n");
419    ok(str == _X("I am a happy BSTR"), "The value was '%s'\n", dbgstrx(str));
420
421    ok(str.LoadString(0) == FALSE, "LoadString should fail.\n");
422    ok(str == _X("I am a happy BSTR"), "The value was '%s'\n", dbgstrx(str));
423
424    XCHAR *xNULL = NULL;
425    CStringX str0(xNULL);
426    ok(str0.IsEmpty(), "str0 should be empty.\n");
427
428    YCHAR *yNULL = NULL;
429    CStringX str1(yNULL);
430    ok(str1.IsEmpty(), "str1 should be empty.\n");
431
432    CStringX str2(MAKEINTRESOURCEX(IDS_TEST1));
433    ok(str2 == _X("Test string one."), "The value was '%s'\n", dbgstrx(str2));
434
435    CStringX str3(MAKEINTRESOURCEX(IDS_TEST2));
436    ok(str3 == _X("I am a happy BSTR"), "The value was '%s'\n", dbgstrx(str3));
437
438    CStringX str4(MAKEINTRESOURCEY(IDS_TEST1));
439    ok(str4 == _X("Test string one."), "The value was '%s'\n", dbgstrx(str4));
440
441    CStringX str5(MAKEINTRESOURCEY(IDS_TEST2));
442    ok(str5 == _X("I am a happy BSTR"), "The value was '%s'\n", dbgstrx(str5));
443}
444
445TEST_NAMEX(bstr)
446{
447    CStringX str;
448
449    str = _X("Some test text here...");
450
451    BSTR bstr = str.AllocSysString();
452    ok(!!bstr, "Expected a valid pointer\n");
453    if (bstr)
454    {
455        ok(!wcscmp(bstr, L"Some test text here..."), "Expected 'Some test text here...', got: '%S'\n", bstr);
456        ::SysFreeString(bstr);
457    }
458}
459
460TEST_NAMEX(tokenize)
461{
462    CStringX str(_X("%#First Second#Third"));
463    const XCHAR* Tokens = _X("% #");
464    CStringX res;
465
466    int nCurPos = 0;
467
468    // All 'current' tokens are skipped
469    res = str.Tokenize(Tokens, nCurPos);
470    ok(res == _X("First"), "Expected str to be 'First', was: %s\n", dbgstrx(res));
471    ok_dec(nCurPos, 8);
472
473    res = str.Tokenize(Tokens, nCurPos);
474    ok(res == _X("Second"), "Expected str to be 'Second', was: %s\n", dbgstrx(res));
475    ok_dec(nCurPos, 15);
476
477    res = str.Tokenize(Tokens, nCurPos);
478    ok(res == _X("Third"), "Expected str to be 'Third', was: %s\n", dbgstrx(res));
479    ok_dec(nCurPos, 21);
480
481    // The final 'token' is empty, and nCurPos is set to -1
482    // (Calling with nCurPos=-1 will assert)
483    res = str.Tokenize(Tokens, nCurPos);
484    ok(res == _X(""), "Expected str to be '', was: %s\n", dbgstrx(res));
485    ok_dec(nCurPos, -1);
486
487    str =_X("StartWithToken#%#");
488    nCurPos = 0;
489
490    res = str.Tokenize(Tokens, nCurPos);
491    ok(res == _X("StartWithToken"), "Expected str to be 'StartWithToken', was: %s\n", dbgstrx(res));
492    ok_dec(nCurPos, 15);
493
494    // Ending with tokens acts as if there were no tokens at the end
495    res = str.Tokenize(Tokens, nCurPos);
496    ok(res == _X(""), "Expected str to be '', was: %s\n", dbgstrx(res));
497    ok_dec(nCurPos, -1);
498
499
500    str = _X("");
501    nCurPos = 0;
502
503    // Calling with an empty string returns 'no tokens'
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    str = _X("");
509    nCurPos = 20;
510
511    // Calling with a current position outside the strings acts the same as 'no tokens left'
512    res = str.Tokenize(Tokens, nCurPos);
513    ok(res == _X(""), "Expected str to be '', was: %s\n", dbgstrx(res));
514    ok_dec(nCurPos, -1);
515
516
517    str = _X("test");
518    nCurPos = 2;
519
520    // Calling with a NULL pszTokens returns a substring starting at 'nCurPos', but not updating nCurPos!
521    res = str.Tokenize(NULL, nCurPos);
522    ok(res == _X("st"), "Expected str to be 'st', was: %s\n", dbgstrx(res));
523    ok_dec(nCurPos, 2);
524
525
526    // Calling with an empty pszTokens behaves exactly the same
527    res = str.Tokenize(_X(""), nCurPos);
528    ok(res == _X("st"), "Expected str to be 'st', was: %s\n", dbgstrx(res));
529    ok_dec(nCurPos, 2);
530
531    nCurPos = 8;
532
533    // Calling with a NULL pszTokens and an nCurPos out of bounds returns 'no tokens left'
534    res = str.Tokenize(NULL, nCurPos);
535    ok(res == _X(""), "Expected str to be '', was: %s\n", dbgstrx(res));
536    ok_dec(nCurPos, -1);
537
538    nCurPos = 8;
539
540    // Calling with an empty pszTokens behaves exactly the same
541    res = str.Tokenize(_X(""), nCurPos);
542    ok(res == _X(""), "Expected str to be '', was: %s\n", dbgstrx(res));
543    ok_dec(nCurPos, -1);
544}
545