Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(625)

Side by Side Diff: base/platform_file_unittest.cc

Issue 5349007: Some additions to support symlinks better on platforms that support them. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: removing TODO Created 10 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « base/platform_file_posix.cc ('k') | base/platform_file_win.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "base/file_util.h" 5 #include "base/file_util.h"
6 #include "base/platform_file.h" 6 #include "base/platform_file.h"
7 #include "base/scoped_temp_dir.h" 7 #include "base/scoped_temp_dir.h"
8 #include "base/time.h" 8 #include "base/time.h"
9 #include "testing/gtest/include/gtest/gtest.h" 9 #include "testing/gtest/include/gtest/gtest.h"
10 10
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after
262 262
263 // Get info for a newly created file. 263 // Get info for a newly created file.
264 base::PlatformFileInfo info; 264 base::PlatformFileInfo info;
265 EXPECT_TRUE(base::GetPlatformFileInfo(file, &info)); 265 EXPECT_TRUE(base::GetPlatformFileInfo(file, &info));
266 266
267 // Add 2 seconds to account for possible rounding errors on 267 // Add 2 seconds to account for possible rounding errors on
268 // filesystems that use a 1s or 2s timestamp granularity. 268 // filesystems that use a 1s or 2s timestamp granularity.
269 base::Time now = base::Time::Now() + base::TimeDelta::FromSeconds(2); 269 base::Time now = base::Time::Now() + base::TimeDelta::FromSeconds(2);
270 EXPECT_EQ(0, info.size); 270 EXPECT_EQ(0, info.size);
271 EXPECT_FALSE(info.is_directory); 271 EXPECT_FALSE(info.is_directory);
272 EXPECT_FALSE(info.is_symbolic_link);
272 EXPECT_LE(info.last_accessed.ToInternalValue(), now.ToInternalValue()); 273 EXPECT_LE(info.last_accessed.ToInternalValue(), now.ToInternalValue());
273 EXPECT_LE(info.last_modified.ToInternalValue(), now.ToInternalValue()); 274 EXPECT_LE(info.last_modified.ToInternalValue(), now.ToInternalValue());
274 EXPECT_LE(info.creation_time.ToInternalValue(), now.ToInternalValue()); 275 EXPECT_LE(info.creation_time.ToInternalValue(), now.ToInternalValue());
275 base::Time creation_time = info.creation_time; 276 base::Time creation_time = info.creation_time;
276 277
277 // Write "test" to the file. 278 // Write "test" to the file.
278 char data[] = "test"; 279 char data[] = "test";
279 const int kTestDataSize = 4; 280 const int kTestDataSize = 4;
280 int bytes_written = WriteFully(file, 0, data, kTestDataSize); 281 int bytes_written = WriteFully(file, 0, data, kTestDataSize);
281 EXPECT_EQ(kTestDataSize, bytes_written); 282 EXPECT_EQ(kTestDataSize, bytes_written);
282 283
283 // Change the last_accessed and last_modified dates. 284 // Change the last_accessed and last_modified dates.
284 // It's best to add values that are multiples of 2 (in seconds) 285 // It's best to add values that are multiples of 2 (in seconds)
285 // to the current last_accessed and last_modified times, because 286 // to the current last_accessed and last_modified times, because
286 // FATxx uses a 2s timestamp granularity. 287 // FATxx uses a 2s timestamp granularity.
287 base::Time new_last_accessed = 288 base::Time new_last_accessed =
288 info.last_accessed + base::TimeDelta::FromSeconds(234); 289 info.last_accessed + base::TimeDelta::FromSeconds(234);
289 base::Time new_last_modified = 290 base::Time new_last_modified =
290 info.last_modified + base::TimeDelta::FromMinutes(567); 291 info.last_modified + base::TimeDelta::FromMinutes(567);
291 292
292 EXPECT_TRUE(base::TouchPlatformFile(file, new_last_accessed, 293 EXPECT_TRUE(base::TouchPlatformFile(file, new_last_accessed,
293 new_last_modified)); 294 new_last_modified));
294 295
295 // Make sure the file info was updated accordingly. 296 // Make sure the file info was updated accordingly.
296 EXPECT_TRUE(base::GetPlatformFileInfo(file, &info)); 297 EXPECT_TRUE(base::GetPlatformFileInfo(file, &info));
297 EXPECT_EQ(info.size, kTestDataSize); 298 EXPECT_EQ(info.size, kTestDataSize);
298 EXPECT_FALSE(info.is_directory); 299 EXPECT_FALSE(info.is_directory);
300 EXPECT_FALSE(info.is_symbolic_link);
299 301
300 // ext2/ext3 and HPS/HPS+ seem to have a timestamp granularity of 1s. 302 // ext2/ext3 and HPS/HPS+ seem to have a timestamp granularity of 1s.
301 #if defined(OS_POSIX) 303 #if defined(OS_POSIX)
302 EXPECT_EQ(info.last_accessed.ToTimeVal().tv_sec, 304 EXPECT_EQ(info.last_accessed.ToTimeVal().tv_sec,
303 new_last_accessed.ToTimeVal().tv_sec); 305 new_last_accessed.ToTimeVal().tv_sec);
304 EXPECT_EQ(info.last_modified.ToTimeVal().tv_sec, 306 EXPECT_EQ(info.last_modified.ToTimeVal().tv_sec,
305 new_last_modified.ToTimeVal().tv_sec); 307 new_last_modified.ToTimeVal().tv_sec);
306 #else 308 #else
307 EXPECT_EQ(info.last_accessed.ToInternalValue(), 309 EXPECT_EQ(info.last_accessed.ToInternalValue(),
308 new_last_accessed.ToInternalValue()); 310 new_last_accessed.ToInternalValue());
309 EXPECT_EQ(info.last_modified.ToInternalValue(), 311 EXPECT_EQ(info.last_modified.ToInternalValue(),
310 new_last_modified.ToInternalValue()); 312 new_last_modified.ToInternalValue());
311 #endif 313 #endif
312 314
313 EXPECT_EQ(info.creation_time.ToInternalValue(), 315 EXPECT_EQ(info.creation_time.ToInternalValue(),
314 creation_time.ToInternalValue()); 316 creation_time.ToInternalValue());
315 317
316 // Close the file handle to allow the temp directory to be deleted. 318 // Close the file handle to allow the temp directory to be deleted.
317 base::ClosePlatformFile(file); 319 base::ClosePlatformFile(file);
318 } 320 }
OLDNEW
« no previous file with comments | « base/platform_file_posix.cc ('k') | base/platform_file_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698