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