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

Unified Diff: base/platform_file_unittest.cc

Issue 7821013: Base: Change ReadPlatformFile to perform a best (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 9 years, 4 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/platform_file_posix.cc ('k') | base/platform_file_win.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/platform_file_unittest.cc
===================================================================
--- base/platform_file_unittest.cc (revision 99047)
+++ base/platform_file_unittest.cc (working copy)
@@ -13,24 +13,7 @@
// Reads from a file the given number of bytes, or until EOF is reached.
// Returns the number of bytes read.
int ReadFully(base::PlatformFile file, int64 offset, char* data, int size) {
- int total_bytes_read = 0;
- int bytes_read;
- while (total_bytes_read < size) {
- bytes_read = base::ReadPlatformFile(
- file, offset + total_bytes_read, &data[total_bytes_read],
- size - total_bytes_read);
-
- // If we reached EOF, bytes_read will be 0.
- if (bytes_read == 0)
- return total_bytes_read;
-
- if ((bytes_read < 0) || (bytes_read > size - total_bytes_read))
- return -1;
-
- total_bytes_read += bytes_read;
- }
-
- return total_bytes_read;
+ return base::ReadPlatformFile(file, offset, data, size);
}
// Writes the given number of bytes to a file.
@@ -192,6 +175,13 @@
for (int i = 0; i < bytes_read; i++)
EXPECT_EQ(data_to_write[i], data_read_1[i]);
+ // Read again, but using the trivial native wrapper.
+ bytes_read = base::ReadPlatformFileNoBestEffort(file, 0, data_read_1,
+ kTestDataSize);
+ EXPECT_LE(bytes_read, kTestDataSize);
+ for (int i = 0; i < bytes_read; i++)
+ EXPECT_EQ(data_to_write[i], data_read_1[i]);
+
// Write past the end of the file.
const int kOffsetBeyondEndOfFile = 10;
const int kPartialWriteLength = 2;
« 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