1*e3402acaSMark Jansen
2*e3402acaSMark JansenTEST_NAMEX(init)
3*e3402acaSMark Jansen{
4*e3402acaSMark Jansen    CPathX test1;
5*e3402acaSMark Jansen    CPathX test2(_X("C:\\SomePath\\.\\That\\..\\is.txt.exe.bin"));
6*e3402acaSMark Jansen    CPathX test3(test2);
7*e3402acaSMark Jansen
8*e3402acaSMark Jansen    ok(CStringX("").Compare(test1) == 0, "Expected test1 to be '', was: '%s'\n", dbgstrx(test1));
9*e3402acaSMark Jansen    ok(CStringX("C:\\SomePath\\.\\That\\..\\is.txt.exe.bin").Compare(test2) == 0, "Expected test2 to be 'C:\\SomePath\\.\\That\\..\\is.txt.exe.bin', was: '%s'\n", dbgstrx(test2));
10*e3402acaSMark Jansen    ok(CStringX("C:\\SomePath\\.\\That\\..\\is.txt.exe.bin").Compare(test3) == 0, "Expected test3 to be 'C:\\SomePath\\.\\That\\..\\is.txt.exe.bin', was: '%s'\n", dbgstrx(test3));
11*e3402acaSMark Jansen
12*e3402acaSMark Jansen    test1 = _X("test");
13*e3402acaSMark Jansen    test2 = _X("test");
14*e3402acaSMark Jansen    ok(CStringX("test").Compare(test1) == 0, "Expected test1 to be 'test', was: '%s'\n", dbgstrx(test1));
15*e3402acaSMark Jansen    ok(CStringX("test").Compare(test2) == 0, "Expected test2 to be 'test', was: '%s'\n", dbgstrx(test1));
16*e3402acaSMark Jansen
17*e3402acaSMark Jansen
18*e3402acaSMark Jansen#if 0
19*e3402acaSMark Jansen    // this does not compile:
20*e3402acaSMark Jansen    test3 = test1 + _X("test");
21*e3402acaSMark Jansen    test3 = test1 + test2;
22*e3402acaSMark Jansen    CPathX test4(test1 + test2);
23*e3402acaSMark Jansen#endif
24*e3402acaSMark Jansen    // This one compiles, but does not behave as wanted!
25*e3402acaSMark Jansen    CPathX test5(test1 + _X("test"));
26*e3402acaSMark Jansen    ok(CStringX("testtest").Compare(test5) == 0, "Expected test5 to be 'testtest', was: '%s'\n", dbgstrx(test1));
27*e3402acaSMark Jansen}
28*e3402acaSMark Jansen
29*e3402acaSMark JansenTEST_NAMEX(modify)
30*e3402acaSMark Jansen{
31*e3402acaSMark Jansen    CPathX test(_X("C:\\Some Path\\.\\That\\..\\is.txt.exe.bin"));
32*e3402acaSMark Jansen    CPathX canon;
33*e3402acaSMark Jansen    CPathX empty;
34*e3402acaSMark Jansen
35*e3402acaSMark Jansen    test.Canonicalize();
36*e3402acaSMark Jansen    ok(CStringX("C:\\Some Path\\is.txt.exe.bin").Compare(test) == 0,
37*e3402acaSMark Jansen        "Expected test to be 'C:\\Some Path\\is.txt.exe.bin', was: '%s'\n", dbgstrx(test));
38*e3402acaSMark Jansen
39*e3402acaSMark Jansen    canon.Canonicalize();
40*e3402acaSMark Jansen    ok(CStringX("\\").Compare(canon) == 0,
41*e3402acaSMark Jansen        "Expected canon to be '\\', was: '%s'\n", dbgstrx(canon));
42*e3402acaSMark Jansen
43*e3402acaSMark Jansen    ok(test.FileExists() == FALSE, "FileExists succeeded for '%s'\n", dbgstrx(test));
44*e3402acaSMark Jansen
45*e3402acaSMark Jansen    int ext = test.FindExtension();
46*e3402acaSMark Jansen    ok(ext == 23, "Expected ext to be 23, was: %i\n", ext);
47*e3402acaSMark Jansen    ext = empty.FindExtension();
48*e3402acaSMark Jansen    ok(ext == -1, "Expected ext to be -1, was: %i\n", ext);
49*e3402acaSMark Jansen
50*e3402acaSMark Jansen    int name = test.FindFileName();
51*e3402acaSMark Jansen    ok(name == 13, "Expected name to be 13, was: %i\n", name);
52*e3402acaSMark Jansen    name = empty.FindFileName();
53*e3402acaSMark Jansen    ok(name == -1, "Expected name to be -1, was: %i\n", name);
54*e3402acaSMark Jansen
55*e3402acaSMark Jansen    int drive = test.GetDriveNumber();
56*e3402acaSMark Jansen    ok(drive == 2, "Expected drive to be 2, was: %i\n", drive);
57*e3402acaSMark Jansen    drive = empty.GetDriveNumber();
58*e3402acaSMark Jansen    ok(drive == -1, "Expected drive to be -1, was: %i\n", drive);
59*e3402acaSMark Jansen
60*e3402acaSMark Jansen    int skiproot = test.SkipRoot();
61*e3402acaSMark Jansen    ok(skiproot == 3, "Expected skiproot to be 3, was: %i\n", skiproot);
62*e3402acaSMark Jansen
63*e3402acaSMark Jansen#if 0
64*e3402acaSMark Jansen    // Does not handle an empty string correctly
65*e3402acaSMark Jansen    skiproot = empty.SkipRoot();
66*e3402acaSMark Jansen    ok(skiproot == -1, "Expected skiproot to be -1, was: %i\n", skiproot);
67*e3402acaSMark Jansen#endif
68*e3402acaSMark Jansen
69*e3402acaSMark Jansen
70*e3402acaSMark Jansen    test.RemoveExtension();
71*e3402acaSMark Jansen    ok(CStringX("C:\\Some Path\\is.txt.exe").Compare(test) == 0,
72*e3402acaSMark Jansen        "Expected test to be 'C:\\Some Path\\is.txt.exe', was: '%s'\n", dbgstrx(test));
73*e3402acaSMark Jansen
74*e3402acaSMark Jansen    empty.RemoveExtension();
75*e3402acaSMark Jansen    ok(CStringX("").Compare(empty) == 0,
76*e3402acaSMark Jansen        "Expected empty to be '', was: '%s'\n", dbgstrx(empty));
77*e3402acaSMark Jansen
78*e3402acaSMark Jansen    CStringX extName = test.GetExtension();
79*e3402acaSMark Jansen    ok(CStringX(".exe").Compare(extName) == 0,
80*e3402acaSMark Jansen        "Expected test.GetExtension() to be '.exe', was: '%s'\n", dbgstrx(extName));
81*e3402acaSMark Jansen
82*e3402acaSMark Jansen    extName = empty.GetExtension();
83*e3402acaSMark Jansen    ok(CStringX("").Compare(extName) == 0,
84*e3402acaSMark Jansen        "Expected empty.GetExtension() to be '', was: '%s'\n", dbgstrx(extName));
85*e3402acaSMark Jansen
86*e3402acaSMark Jansen    test.QuoteSpaces();
87*e3402acaSMark Jansen    ok(CStringX("\"C:\\Some Path\\is.txt.exe\"").Compare(test) == 0,
88*e3402acaSMark Jansen        "Expected test to be '\"C:\\Some Path\\is.txt.exe\"', was: '%s'\n", dbgstrx(test));
89*e3402acaSMark Jansen
90*e3402acaSMark Jansen    empty.QuoteSpaces();
91*e3402acaSMark Jansen    ok(CStringX("").Compare(empty) == 0,
92*e3402acaSMark Jansen        "Expected empty to be '', was: '%s'\n", dbgstrx(empty));
93*e3402acaSMark Jansen
94*e3402acaSMark Jansen    ok(test.RemoveFileSpec(), "RemoveFileSpec failed\n");
95*e3402acaSMark Jansen    ok(CStringX("\"C:\\Some Path").Compare(test) == 0,
96*e3402acaSMark Jansen        "Expected test to be '\"C:\\Some Path', was: '%s'\n", dbgstrx(test));
97*e3402acaSMark Jansen
98*e3402acaSMark Jansen    ok(empty.RemoveFileSpec() == FALSE, "RemoveFileSpec succeeded\n");
99*e3402acaSMark Jansen    ok(CStringX("").Compare(empty) == 0,
100*e3402acaSMark Jansen        "Expected empty to be '', was: '%s'\n", dbgstrx(empty));
101*e3402acaSMark Jansen
102*e3402acaSMark Jansen    test.UnquoteSpaces();
103*e3402acaSMark Jansen    ok(CStringX("\"C:\\Some Path").Compare(test) == 0,
104*e3402acaSMark Jansen        "Expected test to be '\"C:\\Some Path\\is.txt.exe\"', was: '%s'\n", dbgstrx(test));
105*e3402acaSMark Jansen
106*e3402acaSMark Jansen    empty.UnquoteSpaces();
107*e3402acaSMark Jansen    ok(CStringX("").Compare(empty) == 0,
108*e3402acaSMark Jansen        "Expected empty to be '', was: '%s'\n", dbgstrx(empty));
109*e3402acaSMark Jansen
110*e3402acaSMark Jansen    test.m_strPath += _X('"');
111*e3402acaSMark Jansen
112*e3402acaSMark Jansen    test.UnquoteSpaces();
113*e3402acaSMark Jansen    ok(CStringX("C:\\Some Path").Compare(test) == 0,
114*e3402acaSMark Jansen        "Expected test to be 'C:\\Some Path', was: '%s'\n", dbgstrx(test));
115*e3402acaSMark Jansen
116*e3402acaSMark Jansen    empty.UnquoteSpaces();
117*e3402acaSMark Jansen    ok(CStringX("").Compare(empty) == 0,
118*e3402acaSMark Jansen        "Expected empty to be '', was: '%s'\n", dbgstrx(empty));
119*e3402acaSMark Jansen
120*e3402acaSMark Jansen    ok(test.AddExtension(_X(".dummy")), "AddExtension failed\n");
121*e3402acaSMark Jansen    ok(CStringX("C:\\Some Path.dummy").Compare(test) == 0,
122*e3402acaSMark Jansen        "Expected test to be 'C:\\Some Path.dummy', was: '%s'\n", dbgstrx(test));
123*e3402acaSMark Jansen
124*e3402acaSMark Jansen    ok(empty.AddExtension(_X(".dummy")), "AddExtension failed\n");
125*e3402acaSMark Jansen    ok(CStringX(".dummy").Compare(empty) == 0,
126*e3402acaSMark Jansen        "Expected empty to be '.dummy', was: '%s'\n", dbgstrx(empty));
127*e3402acaSMark Jansen    empty = _X("");
128*e3402acaSMark Jansen
129*e3402acaSMark Jansen    test.AddBackslash();
130*e3402acaSMark Jansen    ok(CStringX("C:\\Some Path.dummy\\").Compare(test) == 0,
131*e3402acaSMark Jansen        "Expected test to be 'C:\\Some Path.dummy\\', was: '%s'\n", dbgstrx(test));
132*e3402acaSMark Jansen
133*e3402acaSMark Jansen    empty.AddBackslash();
134*e3402acaSMark Jansen    ok(CStringX("").Compare(empty) == 0,
135*e3402acaSMark Jansen        "Expected empty to be '', was: '%s'\n", dbgstrx(empty));
136*e3402acaSMark Jansen
137*e3402acaSMark Jansen    test.AddBackslash();
138*e3402acaSMark Jansen    ok(CStringX("C:\\Some Path.dummy\\").Compare(test) == 0,
139*e3402acaSMark Jansen        "Expected test to be 'C:\\Some Path.dummy\\', was: '%s'\n", dbgstrx(test));
140*e3402acaSMark Jansen
141*e3402acaSMark Jansen    empty.AddBackslash();
142*e3402acaSMark Jansen    ok(CStringX("").Compare(empty) == 0,
143*e3402acaSMark Jansen        "Expected empty to be '', was: '%s'\n", dbgstrx(empty));
144*e3402acaSMark Jansen
145*e3402acaSMark Jansen    test.RemoveBlanks();
146*e3402acaSMark Jansen    ok(CStringX("C:\\Some Path.dummy\\").Compare(test) == 0,
147*e3402acaSMark Jansen        "Expected test to be 'C:\\Some Path.dummy\\', was: '%s'\n", dbgstrx(test));
148*e3402acaSMark Jansen
149*e3402acaSMark Jansen    empty.RemoveBlanks();
150*e3402acaSMark Jansen    ok(CStringX("").Compare(empty) == 0,
151*e3402acaSMark Jansen        "Expected empty to be '', was: '%s'\n", dbgstrx(empty));
152*e3402acaSMark Jansen
153*e3402acaSMark Jansen    test = _X(" C:\\Some Path.dummy\\   ");
154*e3402acaSMark Jansen    empty = _X("      ");
155*e3402acaSMark Jansen
156*e3402acaSMark Jansen    test.RemoveBlanks();
157*e3402acaSMark Jansen    ok(CStringX("C:\\Some Path.dummy\\").Compare(test) == 0,
158*e3402acaSMark Jansen        "Expected test to be 'C:\\Some Path.dummy\\', was: '%s'\n", dbgstrx(test));
159*e3402acaSMark Jansen
160*e3402acaSMark Jansen    empty.RemoveBlanks();
161*e3402acaSMark Jansen    ok(CStringX("").Compare(empty) == 0,
162*e3402acaSMark Jansen        "Expected empty to be '', was: '%s'\n", dbgstrx(empty));
163*e3402acaSMark Jansen
164*e3402acaSMark Jansen    test.RemoveBackslash();
165*e3402acaSMark Jansen    ok(CStringX("C:\\Some Path.dummy").Compare(test) == 0,
166*e3402acaSMark Jansen        "Expected test to be 'C:\\Some Path.dummy', was: '%s'\n", dbgstrx(test));
167*e3402acaSMark Jansen
168*e3402acaSMark Jansen    empty.RemoveBackslash();
169*e3402acaSMark Jansen    ok(CStringX("").Compare(empty) == 0,
170*e3402acaSMark Jansen        "Expected empty to be '', was: '%s'\n", dbgstrx(empty));
171*e3402acaSMark Jansen
172*e3402acaSMark Jansen    ok(test.RenameExtension(_X(".txt")), "RenameExtension failed\n");
173*e3402acaSMark Jansen    ok(CStringX("C:\\Some Path.txt").Compare(test) == 0,
174*e3402acaSMark Jansen        "Expected test to be 'C:\\Some Path.txt', was: '%s'\n", dbgstrx(test));
175*e3402acaSMark Jansen
176*e3402acaSMark Jansen    ok(empty.RenameExtension(_X(".txt")), "RenameExtension failed\n");
177*e3402acaSMark Jansen    ok(CStringX(".txt").Compare(empty) == 0,
178*e3402acaSMark Jansen        "Expected empty to be '.txt', was: '%s'\n", dbgstrx(empty));
179*e3402acaSMark Jansen
180*e3402acaSMark Jansen    empty = _X("");
181*e3402acaSMark Jansen
182*e3402acaSMark Jansen    test += _X("something");
183*e3402acaSMark Jansen    ok(CStringX("C:\\Some Path.txt\\something").Compare(test) == 0,
184*e3402acaSMark Jansen        "Expected test to be 'C:\\Some Path.txt', was: '%s'\n", dbgstrx(test));
185*e3402acaSMark Jansen
186*e3402acaSMark Jansen    empty += _X("something");
187*e3402acaSMark Jansen    ok(CStringX("something").Compare(empty) == 0,
188*e3402acaSMark Jansen        "Expected empty to be 'something', was: '%s'\n", dbgstrx(empty));
189*e3402acaSMark Jansen
190*e3402acaSMark Jansen    ok(test.Append(_X("stuff.txt")), "Append failed\n");
191*e3402acaSMark Jansen    ok(CStringX("C:\\Some Path.txt\\something\\stuff.txt").Compare(test) == 0,
192*e3402acaSMark Jansen        "Expected test to be 'C:\\Some Path.txt\\something\\stuff.txt', was: '%s'\n", dbgstrx(test));
193*e3402acaSMark Jansen
194*e3402acaSMark Jansen    ok(empty.Append(_X("")), "Append failed\n");
195*e3402acaSMark Jansen    ok(CStringX("something").Compare(empty) == 0,
196*e3402acaSMark Jansen        "Expected empty to be 'something', was: '%s'\n", dbgstrx(empty));
197*e3402acaSMark Jansen
198*e3402acaSMark Jansen    ok(test.MatchSpec(_X("stuff.txt")) == FALSE, "MatchSpec succeeded for 'stuff.txt'\n");
199*e3402acaSMark Jansen    ok(test.MatchSpec(_X("stuff.exe")) == FALSE, "MatchSpec succeeded for 'stuff.exe'\n");
200*e3402acaSMark Jansen    ok(test.MatchSpec(_X(".txt")) == FALSE, "MatchSpec succeeded for '.txt'\n");
201*e3402acaSMark Jansen    ok(test.MatchSpec(_X("txt")) == FALSE, "MatchSpec succeeded for 'txt'\n");
202*e3402acaSMark Jansen    ok(test.MatchSpec(_X("*.txt")), "MatchSpec failed for '*.txt'\n");
203*e3402acaSMark Jansen    ok(test.MatchSpec(_X("C:\\*.txt")), "MatchSpec failed for 'C:\\*.txt'\n");
204*e3402acaSMark Jansen    ok(test.MatchSpec(_X("D:\\*.txt")) == FALSE, "MatchSpec succeeded for 'D:\\*.txt'\n");
205*e3402acaSMark Jansen
206*e3402acaSMark Jansen    CStringX same("C:\\Some Path.txt\\something\\stuff.txt");
207*e3402acaSMark Jansen
208*e3402acaSMark Jansen    const CStringX& constref = test;
209*e3402acaSMark Jansen    ok(same.Compare(constref) == 0,
210*e3402acaSMark Jansen        "Expected constref to be '%s', was: '%s'\n", dbgstrx(same), dbgstrx(constref));
211*e3402acaSMark Jansen
212*e3402acaSMark Jansen
213*e3402acaSMark Jansen    CStringX& ref = test;
214*e3402acaSMark Jansen    ok(same.Compare(ref) == 0,
215*e3402acaSMark Jansen        "Expected ref to be '%s', was: '%s'\n", dbgstrx(same), dbgstrx(ref));
216*e3402acaSMark Jansen
217*e3402acaSMark Jansen    const XCHAR* rawptr = test;
218*e3402acaSMark Jansen    ok(same.Compare(rawptr) == 0,
219*e3402acaSMark Jansen        "Expected rawptr to be '%s', was: '%s'\n", dbgstrx(same), dbgstrx(rawptr));
220*e3402acaSMark Jansen
221*e3402acaSMark Jansen    test.BuildRoot(5);
222*e3402acaSMark Jansen    ok(CStringX("F:\\").Compare(test) == 0,
223*e3402acaSMark Jansen        "Expected test to be 'F:\\', was: '%s'\n", dbgstrx(test));
224*e3402acaSMark Jansen
225*e3402acaSMark Jansen#if 0
226*e3402acaSMark Jansen    // Asserts 'iDrive <= 25'
227*e3402acaSMark Jansen    test.BuildRoot(105);
228*e3402acaSMark Jansen    ok(CStringX("f:").Compare(test) == 0,
229*e3402acaSMark Jansen        "Expected test to be 'f:', was: '%s'\n", dbgstrx(test));
230*e3402acaSMark Jansen#endif
231*e3402acaSMark Jansen
232*e3402acaSMark Jansen    test.Combine(_X("C:"), _X("test"));
233*e3402acaSMark Jansen    ok(CStringX("C:\\test").Compare(test) == 0,
234*e3402acaSMark Jansen        "Expected test to be 'C:\\test', was: '%s'\n", dbgstrx(test));
235*e3402acaSMark Jansen
236*e3402acaSMark Jansen    test.Combine(_X("C:\\"), _X("\\test\\"));
237*e3402acaSMark Jansen    ok(CStringX("C:\\test\\").Compare(test) == 0,
238*e3402acaSMark Jansen        "Expected test to be 'C:\\test\\', was: '%s'\n", dbgstrx(test));
239*e3402acaSMark Jansen
240*e3402acaSMark Jansen    test.Combine(_X("C:\\"), _X("\\test\\\\"));
241*e3402acaSMark Jansen    ok(CStringX("C:\\test\\\\").Compare(test) == 0,
242*e3402acaSMark Jansen        "Expected test to be 'C:\\test\\\\', was: '%s'\n", dbgstrx(test));
243*e3402acaSMark Jansen}
244*e3402acaSMark Jansen
245*e3402acaSMark JansenTEST_NAMEX(is_something)
246*e3402acaSMark Jansen{
247*e3402acaSMark Jansen    XCHAR Buffer[MAX_PATH] = { 0 };
248*e3402acaSMark Jansen    GetModuleFileNameX(NULL, Buffer, MAX_PATH);
249*e3402acaSMark Jansen
250*e3402acaSMark Jansen    CPathX test(Buffer);
251*e3402acaSMark Jansen
252*e3402acaSMark Jansen    ok(test.IsDirectory() == FALSE, "IsDirectory succeeded for '%s'\n", dbgstrx(test));
253*e3402acaSMark Jansen    ok(test.IsFileSpec() == FALSE, "IsFileSpec succeeded for '%s'\n", dbgstrx(test));
254*e3402acaSMark Jansen    ok(test.IsRelative() == FALSE, "IsRelative succeeded for '%s'\n", dbgstrx(test));
255*e3402acaSMark Jansen    ok(test.IsRoot() == FALSE, "IsRoot succeeded for '%s'\n", dbgstrx(test));
256*e3402acaSMark Jansen    ok(test.FileExists(), "FileExists failed for '%s'\n", dbgstrx(test));
257*e3402acaSMark Jansen
258*e3402acaSMark Jansen    test.StripPath();
259*e3402acaSMark Jansen    ok(test.IsFileSpec(), "IsFileSpec failed for '%s'\n", dbgstrx(test));
260*e3402acaSMark Jansen    ok(test.IsRelative(), "IsRelative failed for '%s'\n", dbgstrx(test));
261*e3402acaSMark Jansen    ok(test.IsRoot() == FALSE, "IsRoot succeeded for '%s'\n", dbgstrx(test));
262*e3402acaSMark Jansen
263*e3402acaSMark Jansen
264*e3402acaSMark Jansen    ok(test.StripToRoot() == FALSE, "StripToRoot succeeded for '%s'\n", dbgstrx(test));
265*e3402acaSMark Jansen    ok(CStringX("").Compare(test) == 0,
266*e3402acaSMark Jansen        "Expected test to be '', was: '%s'\n", dbgstrx(test));
267*e3402acaSMark Jansen
268*e3402acaSMark Jansen    test = Buffer;
269*e3402acaSMark Jansen
270*e3402acaSMark Jansen    ok(test.StripToRoot(), "StripToRoot failed for '%s'\n", dbgstrx(test));
271*e3402acaSMark Jansen    ok(test.IsRoot(), "IsRoot failed for '%s'\n", dbgstrx(test));
272*e3402acaSMark Jansen
273*e3402acaSMark Jansen    {
274*e3402acaSMark Jansen        CStringX help = test;
275*e3402acaSMark Jansen        ok(help.GetLength() == 3, "IsRoot weird result for '%s'\n", dbgstrx(help));
276*e3402acaSMark Jansen    }
277*e3402acaSMark Jansen
278*e3402acaSMark Jansen    test = Buffer;
279*e3402acaSMark Jansen
280*e3402acaSMark Jansen    test.RemoveFileSpec();
281*e3402acaSMark Jansen    ok(test.IsDirectory(), "IsDirectory failed for '%s'\n", dbgstrx(test));
282*e3402acaSMark Jansen}
283*e3402acaSMark Jansen
284