OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <shellapi.h> | 9 #include <shellapi.h> |
10 #include <shlobj.h> | 10 #include <shlobj.h> |
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
237 | 237 |
238 #if defined(OS_WIN) | 238 #if defined(OS_WIN) |
239 uint64 FileTimeAsUint64(const FILETIME& ft) { | 239 uint64 FileTimeAsUint64(const FILETIME& ft) { |
240 ULARGE_INTEGER u; | 240 ULARGE_INTEGER u; |
241 u.LowPart = ft.dwLowDateTime; | 241 u.LowPart = ft.dwLowDateTime; |
242 u.HighPart = ft.dwHighDateTime; | 242 u.HighPart = ft.dwHighDateTime; |
243 return u.QuadPart; | 243 return u.QuadPart; |
244 } | 244 } |
245 #endif | 245 #endif |
246 | 246 |
247 const struct append_case { | |
248 const wchar_t* path; | |
249 const wchar_t* ending; | |
250 const wchar_t* result; | |
251 } append_cases[] = { | |
252 #if defined(OS_WIN) | |
253 {L"c:\\colon\\backslash", L"path", L"c:\\colon\\backslash\\path"}, | |
254 {L"c:\\colon\\backslash\\", L"path", L"c:\\colon\\backslash\\path"}, | |
255 {L"c:\\colon\\backslash\\\\", L"path", L"c:\\colon\\backslash\\\\path"}, | |
256 {L"c:\\colon\\backslash\\", L"", L"c:\\colon\\backslash\\"}, | |
257 {L"c:\\colon\\backslash", L"", L"c:\\colon\\backslash\\"}, | |
258 {L"", L"path", L"\\path"}, | |
259 {L"", L"", L"\\"}, | |
260 #elif defined(OS_POSIX) | |
261 {L"/foo/bar", L"path", L"/foo/bar/path"}, | |
262 {L"/foo/bar/", L"path", L"/foo/bar/path"}, | |
263 {L"/foo/bar//", L"path", L"/foo/bar//path"}, | |
264 {L"/foo/bar/", L"", L"/foo/bar/"}, | |
265 {L"/foo/bar", L"", L"/foo/bar/"}, | |
266 {L"", L"path", L"/path"}, | |
267 {L"", L"", L"/"}, | |
268 #endif | |
269 }; | |
270 | |
271 static const struct filename_case { | |
272 const wchar_t* path; | |
273 const wchar_t* filename; | |
274 } filename_cases[] = { | |
275 #if defined(OS_WIN) | |
276 {L"c:\\colon\\backslash", L"backslash"}, | |
277 {L"c:\\colon\\backslash\\", L""}, | |
278 {L"\\\\filename.exe", L"filename.exe"}, | |
279 {L"filename.exe", L"filename.exe"}, | |
280 {L"", L""}, | |
281 {L"\\\\\\", L""}, | |
282 {L"c:/colon/backslash", L"backslash"}, | |
283 {L"c:/colon/backslash/", L""}, | |
284 {L"//////", L""}, | |
285 {L"///filename.exe", L"filename.exe"}, | |
286 #elif defined(OS_POSIX) | |
287 {L"/foo/bar", L"bar"}, | |
288 {L"/foo/bar/", L""}, | |
289 {L"/filename.exe", L"filename.exe"}, | |
290 {L"filename.exe", L"filename.exe"}, | |
291 {L"", L""}, | |
292 {L"/", L""}, | |
293 #endif | |
294 }; | |
295 | |
296 // Test finding the file type from a path name | |
297 static const struct extension_case { | |
298 const wchar_t* path; | |
299 const wchar_t* extension; | |
300 } extension_cases[] = { | |
301 #if defined(OS_WIN) | |
302 {L"C:\\colon\\backslash\\filename.extension", L"extension"}, | |
303 {L"C:\\colon\\backslash\\filename.", L""}, | |
304 {L"C:\\colon\\backslash\\filename", L""}, | |
305 {L"C:\\colon\\backslash\\", L""}, | |
306 {L"C:\\colon\\backslash.\\", L""}, | |
307 {L"C:\\colon\\backslash\filename.extension.extension2", L"extension2"}, | |
308 #elif defined(OS_POSIX) | |
309 {L"/foo/bar/filename.extension", L"extension"}, | |
310 {L"/foo/bar/filename.", L""}, | |
311 {L"/foo/bar/filename", L""}, | |
312 {L"/foo/bar/", L""}, | |
313 {L"/foo/bar./", L""}, | |
314 {L"/foo/bar/filename.extension.extension2", L"extension2"}, | |
315 {L".", L""}, | |
316 {L"..", L""}, | |
317 {L"./foo", L""}, | |
318 {L"./foo.extension", L"extension"}, | |
319 {L"/foo.extension1/bar.extension2", L"extension2"}, | |
320 #endif | |
321 }; | |
322 | |
323 // Test finding the directory component of a path | |
324 static const struct dir_case { | |
325 const wchar_t* full_path; | |
326 const wchar_t* directory; | |
327 } dir_cases[] = { | |
328 #if defined(OS_WIN) | |
329 {L"C:\\WINDOWS\\system32\\gdi32.dll", L"C:\\WINDOWS\\system32"}, | |
330 {L"C:\\WINDOWS\\system32\\not_exist_thx_1138", L"C:\\WINDOWS\\system32"}, | |
331 {L"C:\\WINDOWS\\system32\\", L"C:\\WINDOWS\\system32"}, | |
332 {L"C:\\WINDOWS\\system32\\\\", L"C:\\WINDOWS\\system32"}, | |
333 {L"C:\\WINDOWS\\system32", L"C:\\WINDOWS"}, | |
334 {L"C:\\WINDOWS\\system32.\\", L"C:\\WINDOWS\\system32."}, | |
335 {L"C:\\", L"C:\\"}, | |
336 #elif defined(OS_POSIX) | |
337 {L"/foo/bar/gdi32.dll", L"/foo/bar"}, | |
338 {L"/foo/bar/not_exist_thx_1138", L"/foo/bar"}, | |
339 {L"/foo/bar/", L"/foo/bar"}, | |
340 {L"/foo/bar//", L"/foo/bar"}, | |
341 {L"/foo/bar", L"/foo"}, | |
342 {L"/foo/bar./", L"/foo/bar."}, | |
343 {L"/", L"/"}, | |
344 {L".", L"."}, | |
345 {L"..", L"."}, // yes, ".." technically lives in "." | |
346 #endif | |
347 }; | |
348 | |
349 TEST_F(FileUtilTest, FileAndDirectorySize) { | 247 TEST_F(FileUtilTest, FileAndDirectorySize) { |
350 // Create three files of 20, 30 and 3 chars (utf8). ComputeDirectorySize | 248 // Create three files of 20, 30 and 3 chars (utf8). ComputeDirectorySize |
351 // should return 53 bytes. | 249 // should return 53 bytes. |
352 FilePath file_01 = temp_dir_.path().Append(FPL("The file 01.txt")); | 250 FilePath file_01 = temp_dir_.path().Append(FPL("The file 01.txt")); |
353 CreateTextFile(file_01, L"12345678901234567890"); | 251 CreateTextFile(file_01, L"12345678901234567890"); |
354 int64 size_f1 = 0; | 252 int64 size_f1 = 0; |
355 ASSERT_TRUE(file_util::GetFileSize(file_01, &size_f1)); | 253 ASSERT_TRUE(file_util::GetFileSize(file_01, &size_f1)); |
356 EXPECT_EQ(20ll, size_f1); | 254 EXPECT_EQ(20ll, size_f1); |
357 | 255 |
358 FilePath subdir_path = temp_dir_.path().Append(FPL("Level2")); | 256 FilePath subdir_path = temp_dir_.path().Append(FPL("Level2")); |
(...skipping 2058 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2417 file_util::VerifyPathControlledByUser( | 2315 file_util::VerifyPathControlledByUser( |
2418 base_dir_, text_file_, uid_, ok_gids_)); | 2316 base_dir_, text_file_, uid_, ok_gids_)); |
2419 EXPECT_TRUE( | 2317 EXPECT_TRUE( |
2420 file_util::VerifyPathControlledByUser( | 2318 file_util::VerifyPathControlledByUser( |
2421 sub_dir_, text_file_, uid_, ok_gids_)); | 2319 sub_dir_, text_file_, uid_, ok_gids_)); |
2422 } | 2320 } |
2423 | 2321 |
2424 #endif // defined(OS_POSIX) | 2322 #endif // defined(OS_POSIX) |
2425 | 2323 |
2426 } // namespace | 2324 } // namespace |
OLD | NEW |