OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "build/build_config.h" | 5 #include "build/build_config.h" |
6 | 6 |
7 #if defined(OS_WIN) | 7 #if defined(OS_WIN) |
8 #include <windows.h> | 8 #include <windows.h> |
9 #include <winioctl.h> | 9 #include <winioctl.h> |
10 #include <shellapi.h> | 10 #include <shellapi.h> |
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
285 {FPL("/bar.baz/foodll"), FPL("txt"), FPL("/bar.baz/foodlltxt")}, | 285 {FPL("/bar.baz/foodll"), FPL("txt"), FPL("/bar.baz/foodlltxt")}, |
286 {FPL("/bar.baz/foo.dll"), FPL("txt"), FPL("/bar.baz/footxt.dll")}, | 286 {FPL("/bar.baz/foo.dll"), FPL("txt"), FPL("/bar.baz/footxt.dll")}, |
287 {FPL("/bar.baz/foo.dll.exe"), FPL("txt"), FPL("/bar.baz/foo.dlltxt.exe")}, | 287 {FPL("/bar.baz/foo.dll.exe"), FPL("txt"), FPL("/bar.baz/foo.dlltxt.exe")}, |
288 {FPL("/bar.baz/foo"), FPL(""), FPL("/bar.baz/foo")}, | 288 {FPL("/bar.baz/foo"), FPL(""), FPL("/bar.baz/foo")}, |
289 {FPL("/bar.baz/foo.exe"), FPL(""), FPL("/bar.baz/foo.exe")}, | 289 {FPL("/bar.baz/foo.exe"), FPL(""), FPL("/bar.baz/foo.exe")}, |
290 {FPL("/bar.baz/foo.dll.exe"), FPL(""), FPL("/bar.baz/foo.dll.exe")}, | 290 {FPL("/bar.baz/foo.dll.exe"), FPL(""), FPL("/bar.baz/foo.dll.exe")}, |
291 {FPL("/bar/baz/foo.exe"), FPL(" (1)"), FPL("/bar/baz/foo (1).exe")}, | 291 {FPL("/bar/baz/foo.exe"), FPL(" (1)"), FPL("/bar/baz/foo (1).exe")}, |
292 #endif | 292 #endif |
293 }; | 293 }; |
294 | 294 |
| 295 #if defined(OS_WIN) |
| 296 // This function has been deprecated on non-Windows. |
295 TEST_F(FileUtilTest, InsertBeforeExtensionTest) { | 297 TEST_F(FileUtilTest, InsertBeforeExtensionTest) { |
296 for (unsigned int i = 0; i < arraysize(kInsertBeforeExtension); ++i) { | 298 for (unsigned int i = 0; i < arraysize(kInsertBeforeExtension); ++i) { |
297 FilePath path(kInsertBeforeExtension[i].path); | 299 FilePath path(kInsertBeforeExtension[i].path); |
298 file_util::InsertBeforeExtension(&path, kInsertBeforeExtension[i].suffix); | 300 file_util::InsertBeforeExtension(&path, kInsertBeforeExtension[i].suffix); |
299 EXPECT_EQ(kInsertBeforeExtension[i].result, path.value()); | 301 EXPECT_EQ(kInsertBeforeExtension[i].result, path.value()); |
300 } | 302 } |
301 } | 303 } |
| 304 #endif |
302 | 305 |
303 static const struct filename_case { | 306 static const struct filename_case { |
304 const wchar_t* path; | 307 const wchar_t* path; |
305 const wchar_t* filename; | 308 const wchar_t* filename; |
306 } filename_cases[] = { | 309 } filename_cases[] = { |
307 #if defined(OS_WIN) | 310 #if defined(OS_WIN) |
308 {L"c:\\colon\\backslash", L"backslash"}, | 311 {L"c:\\colon\\backslash", L"backslash"}, |
309 {L"c:\\colon\\backslash\\", L""}, | 312 {L"c:\\colon\\backslash\\", L""}, |
310 {L"\\\\filename.exe", L"filename.exe"}, | 313 {L"\\\\filename.exe", L"filename.exe"}, |
311 {L"filename.exe", L"filename.exe"}, | 314 {L"filename.exe", L"filename.exe"}, |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
356 {L"/foo/bar./", L""}, | 359 {L"/foo/bar./", L""}, |
357 {L"/foo/bar/filename.extension.extension2", L"extension2"}, | 360 {L"/foo/bar/filename.extension.extension2", L"extension2"}, |
358 {L".", L""}, | 361 {L".", L""}, |
359 {L"..", L""}, | 362 {L"..", L""}, |
360 {L"./foo", L""}, | 363 {L"./foo", L""}, |
361 {L"./foo.extension", L"extension"}, | 364 {L"./foo.extension", L"extension"}, |
362 {L"/foo.extension1/bar.extension2", L"extension2"}, | 365 {L"/foo.extension1/bar.extension2", L"extension2"}, |
363 #endif | 366 #endif |
364 }; | 367 }; |
365 | 368 |
| 369 #if defined(OS_WIN) |
| 370 // This function has been deprecated on non-Windows. |
366 TEST_F(FileUtilTest, GetFileExtensionFromPath) { | 371 TEST_F(FileUtilTest, GetFileExtensionFromPath) { |
367 for (unsigned int i = 0; i < arraysize(extension_cases); ++i) { | 372 for (unsigned int i = 0; i < arraysize(extension_cases); ++i) { |
368 const extension_case& ext = extension_cases[i]; | 373 const extension_case& ext = extension_cases[i]; |
369 const std::wstring fext = file_util::GetFileExtensionFromPath(ext.path); | 374 const std::wstring fext = file_util::GetFileExtensionFromPath(ext.path); |
370 EXPECT_EQ(ext.extension, fext); | 375 EXPECT_EQ(ext.extension, fext); |
371 } | 376 } |
372 } | 377 } |
| 378 #endif |
373 | 379 |
374 // Test finding the directory component of a path | 380 // Test finding the directory component of a path |
375 static const struct dir_case { | 381 static const struct dir_case { |
376 const wchar_t* full_path; | 382 const wchar_t* full_path; |
377 const wchar_t* directory; | 383 const wchar_t* directory; |
378 } dir_cases[] = { | 384 } dir_cases[] = { |
379 #if defined(OS_WIN) | 385 #if defined(OS_WIN) |
380 {L"C:\\WINDOWS\\system32\\gdi32.dll", L"C:\\WINDOWS\\system32"}, | 386 {L"C:\\WINDOWS\\system32\\gdi32.dll", L"C:\\WINDOWS\\system32"}, |
381 {L"C:\\WINDOWS\\system32\\not_exist_thx_1138", L"C:\\WINDOWS\\system32"}, | 387 {L"C:\\WINDOWS\\system32\\not_exist_thx_1138", L"C:\\WINDOWS\\system32"}, |
382 {L"C:\\WINDOWS\\system32\\", L"C:\\WINDOWS\\system32"}, | 388 {L"C:\\WINDOWS\\system32\\", L"C:\\WINDOWS\\system32"}, |
(...skipping 1469 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1852 EXPECT_TRUE(file_util::IsDirectoryEmpty(empty_dir)); | 1858 EXPECT_TRUE(file_util::IsDirectoryEmpty(empty_dir)); |
1853 | 1859 |
1854 FilePath foo(empty_dir.Append(FILE_PATH_LITERAL("foo.txt"))); | 1860 FilePath foo(empty_dir.Append(FILE_PATH_LITERAL("foo.txt"))); |
1855 std::string bar("baz"); | 1861 std::string bar("baz"); |
1856 ASSERT_TRUE(file_util::WriteFile(foo, bar.c_str(), bar.length())); | 1862 ASSERT_TRUE(file_util::WriteFile(foo, bar.c_str(), bar.length())); |
1857 | 1863 |
1858 EXPECT_FALSE(file_util::IsDirectoryEmpty(empty_dir)); | 1864 EXPECT_FALSE(file_util::IsDirectoryEmpty(empty_dir)); |
1859 } | 1865 } |
1860 | 1866 |
1861 } // namespace | 1867 } // namespace |
OLD | NEW |