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

Side by Side Diff: base/files/file_unittest.cc

Issue 183333004: Implement File::WriteAtCurrentPos for Windows (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 9 months 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 | « no previous file | base/files/file_win.cc » ('j') | base/files/file_win.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "base/file_util.h" 5 #include "base/file_util.h"
6 #include "base/files/file.h" 6 #include "base/files/file.h"
7 #include "base/files/scoped_temp_dir.h" 7 #include "base/files/scoped_temp_dir.h"
8 #include "base/time/time.h" 8 #include "base/time/time.h"
9 #include "testing/gtest/include/gtest/gtest.h" 9 #include "testing/gtest/include/gtest/gtest.h"
10 10
(...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after
342 EXPECT_EQ(info.last_accessed.ToInternalValue(), 342 EXPECT_EQ(info.last_accessed.ToInternalValue(),
343 new_last_accessed.ToInternalValue()); 343 new_last_accessed.ToInternalValue());
344 EXPECT_EQ(info.last_modified.ToInternalValue(), 344 EXPECT_EQ(info.last_modified.ToInternalValue(),
345 new_last_modified.ToInternalValue()); 345 new_last_modified.ToInternalValue());
346 #endif 346 #endif
347 347
348 EXPECT_EQ(info.creation_time.ToInternalValue(), 348 EXPECT_EQ(info.creation_time.ToInternalValue(),
349 creation_time.ToInternalValue()); 349 creation_time.ToInternalValue());
350 } 350 }
351 351
352 TEST(File, ReadFileAtCurrentPosition) { 352 TEST(File, ReadAtCurrentPosition) {
353 base::ScopedTempDir temp_dir; 353 base::ScopedTempDir temp_dir;
354 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); 354 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
355 FilePath file_path = 355 FilePath file_path = temp_dir.path().AppendASCII("read_at_current_position");
356 temp_dir.path().AppendASCII("read_file_at_current_position");
357 File file(file_path, 356 File file(file_path,
358 base::File::FLAG_CREATE | base::File::FLAG_READ | 357 base::File::FLAG_CREATE | base::File::FLAG_READ |
359 base::File::FLAG_WRITE); 358 base::File::FLAG_WRITE);
360 EXPECT_TRUE(file.IsValid()); 359 EXPECT_TRUE(file.IsValid());
361 360
362 const char kData[] = "test"; 361 const char kData[] = "test";
363 const int kDataSize = arraysize(kData) - 1; 362 const int kDataSize = sizeof(kData) - 1;
364 EXPECT_EQ(kDataSize, file.Write(0, kData, kDataSize)); 363 EXPECT_EQ(kDataSize, file.Write(0, kData, kDataSize));
365 364
366 EXPECT_EQ(0, file.Seek(base::File::FROM_BEGIN, 0)); 365 EXPECT_EQ(0, file.Seek(base::File::FROM_BEGIN, 0));
367 366
368 char buffer[kDataSize]; 367 char buffer[kDataSize];
369 int first_chunk_size = kDataSize / 2; 368 int first_chunk_size = kDataSize / 2;
370 EXPECT_EQ(first_chunk_size, file.ReadAtCurrentPos(buffer, first_chunk_size)); 369 EXPECT_EQ(first_chunk_size, file.ReadAtCurrentPos(buffer, first_chunk_size));
371 EXPECT_EQ(kDataSize - first_chunk_size, 370 EXPECT_EQ(kDataSize - first_chunk_size,
372 file.ReadAtCurrentPos(buffer + first_chunk_size, 371 file.ReadAtCurrentPos(buffer + first_chunk_size,
373 kDataSize - first_chunk_size)); 372 kDataSize - first_chunk_size));
374 EXPECT_EQ(std::string(buffer, buffer + kDataSize), 373 EXPECT_EQ(std::string(buffer, buffer + kDataSize), std::string(kData));
375 std::string(kData)); 374 }
375
376 TEST(File, WriteAtCurrentPosition) {
377 base::ScopedTempDir temp_dir;
378 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
379 FilePath file_path = temp_dir.path().AppendASCII("write_at_current_position");
380 File file(file_path,
381 base::File::FLAG_CREATE | base::File::FLAG_READ |
382 base::File::FLAG_WRITE);
383 EXPECT_TRUE(file.IsValid());
384
385 const char kData[] = "test";
386 const int kDataSize = sizeof(kData) - 1;
387
388 int first_chunk_size = kDataSize / 2;
389 EXPECT_EQ(first_chunk_size, file.WriteAtCurrentPos(kData, first_chunk_size));
390 EXPECT_EQ(kDataSize - first_chunk_size,
391 file.WriteAtCurrentPos(kData + first_chunk_size,
392 kDataSize - first_chunk_size));
393
394 char buffer[kDataSize];
395 EXPECT_EQ(kDataSize, file.Read(0, buffer, kDataSize));
396 EXPECT_EQ(std::string(buffer, buffer + kDataSize), std::string(kData));
376 } 397 }
377 398
378 #if defined(OS_WIN) 399 #if defined(OS_WIN)
379 TEST(File, GetInfoForDirectory) { 400 TEST(File, GetInfoForDirectory) {
380 base::ScopedTempDir temp_dir; 401 base::ScopedTempDir temp_dir;
381 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); 402 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
382 FilePath empty_dir = temp_dir.path().Append(FILE_PATH_LITERAL("gpfi_test")); 403 FilePath empty_dir = temp_dir.path().Append(FILE_PATH_LITERAL("gpfi_test"));
383 ASSERT_TRUE(CreateDirectory(empty_dir)); 404 ASSERT_TRUE(CreateDirectory(empty_dir));
384 405
385 base::File dir( 406 base::File dir(
386 ::CreateFile(empty_dir.value().c_str(), 407 ::CreateFile(empty_dir.value().c_str(),
387 FILE_ALL_ACCESS, 408 FILE_ALL_ACCESS,
388 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, 409 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
389 NULL, 410 NULL,
390 OPEN_EXISTING, 411 OPEN_EXISTING,
391 FILE_FLAG_BACKUP_SEMANTICS, // Needed to open a directory. 412 FILE_FLAG_BACKUP_SEMANTICS, // Needed to open a directory.
392 NULL)); 413 NULL));
393 ASSERT_TRUE(dir.IsValid()); 414 ASSERT_TRUE(dir.IsValid());
394 415
395 base::File::Info info; 416 base::File::Info info;
396 EXPECT_TRUE(dir.GetInfo(&info)); 417 EXPECT_TRUE(dir.GetInfo(&info));
397 EXPECT_TRUE(info.is_directory); 418 EXPECT_TRUE(info.is_directory);
398 EXPECT_FALSE(info.is_symbolic_link); 419 EXPECT_FALSE(info.is_symbolic_link);
399 EXPECT_EQ(0, info.size); 420 EXPECT_EQ(0, info.size);
400 } 421 }
401 #endif // defined(OS_WIN) 422 #endif // defined(OS_WIN)
OLDNEW
« no previous file with comments | « no previous file | base/files/file_win.cc » ('j') | base/files/file_win.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698