| OLD | NEW | 
|    1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |    1 // Copyright (c) 2011 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 19 matching lines...) Expand all  Loading... | 
|   30     total_bytes_read += bytes_read; |   30     total_bytes_read += bytes_read; | 
|   31   } |   31   } | 
|   32  |   32  | 
|   33   return total_bytes_read; |   33   return total_bytes_read; | 
|   34 } |   34 } | 
|   35  |   35  | 
|   36 // Writes the given number of bytes to a file. |   36 // Writes the given number of bytes to a file. | 
|   37 // Returns the number of bytes written. |   37 // Returns the number of bytes written. | 
|   38 int WriteFully(base::PlatformFile file, int64 offset, |   38 int WriteFully(base::PlatformFile file, int64 offset, | 
|   39                const char* data, int size) { |   39                const char* data, int size) { | 
|   40   int total_bytes_written = 0; |   40   return base::WritePlatformFile(file, offset, data, size); | 
|   41   int bytes_written; |  | 
|   42   while (total_bytes_written < size) { |  | 
|   43     bytes_written = base::WritePlatformFile( |  | 
|   44         file, offset + total_bytes_written, &data[total_bytes_written], |  | 
|   45         size - total_bytes_written); |  | 
|   46  |  | 
|   47     if ((bytes_written == 0) && (size == 0)) |  | 
|   48       return 0; |  | 
|   49  |  | 
|   50     if ((bytes_written <= 0) || (bytes_written > size - total_bytes_written)) |  | 
|   51       return -1; |  | 
|   52  |  | 
|   53     total_bytes_written += bytes_written; |  | 
|   54   } |  | 
|   55  |  | 
|   56   return total_bytes_written; |  | 
|   57 } |   41 } | 
|   58  |   42  | 
|   59 } // namespace |   43 } // namespace | 
|   60  |   44  | 
|   61 TEST(PlatformFile, CreatePlatformFile) { |   45 TEST(PlatformFile, CreatePlatformFile) { | 
|   62   ScopedTempDir temp_dir; |   46   ScopedTempDir temp_dir; | 
|   63   ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |   47   ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | 
|   64   FilePath file_path = temp_dir.path().AppendASCII("create_file_1"); |   48   FilePath file_path = temp_dir.path().AppendASCII("create_file_1"); | 
|   65  |   49  | 
|   66   // Open a file that doesn't exist. |   50   // Open a file that doesn't exist. | 
| (...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  353   EXPECT_EQ(info.last_modified.ToInternalValue(), |  337   EXPECT_EQ(info.last_modified.ToInternalValue(), | 
|  354             new_last_modified.ToInternalValue()); |  338             new_last_modified.ToInternalValue()); | 
|  355 #endif |  339 #endif | 
|  356  |  340  | 
|  357   EXPECT_EQ(info.creation_time.ToInternalValue(), |  341   EXPECT_EQ(info.creation_time.ToInternalValue(), | 
|  358             creation_time.ToInternalValue()); |  342             creation_time.ToInternalValue()); | 
|  359  |  343  | 
|  360   // Close the file handle to allow the temp directory to be deleted. |  344   // Close the file handle to allow the temp directory to be deleted. | 
|  361   base::ClosePlatformFile(file); |  345   base::ClosePlatformFile(file); | 
|  362 } |  346 } | 
| OLD | NEW |