[email protected] | 8effd3f6 | 2011-03-25 16:29:07 | [diff] [blame] | 1 | // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
[email protected] | 2041cf34 | 2010-02-19 03:15:59 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
[email protected] | 21da6eb | 2008-11-03 17:18:14 | [diff] [blame] | 4 | |
[email protected] | 5eb431e2 | 2011-10-12 08:51:38 | [diff] [blame^] | 5 | #include "net/base/file_stream.h" |
| 6 | |
| 7 | #include "base/bind.h" |
[email protected] | 2041cf34 | 2010-02-19 03:15:59 | [diff] [blame] | 8 | #include "base/callback.h" |
[email protected] | 21da6eb | 2008-11-03 17:18:14 | [diff] [blame] | 9 | #include "base/file_util.h" |
[email protected] | ad74a59 | 2011-01-21 18:40:55 | [diff] [blame] | 10 | #include "base/message_loop.h" |
[email protected] | 21da6eb | 2008-11-03 17:18:14 | [diff] [blame] | 11 | #include "base/path_service.h" |
[email protected] | 92aad522 | 2009-02-09 22:26:41 | [diff] [blame] | 12 | #include "base/platform_file.h" |
[email protected] | 21da6eb | 2008-11-03 17:18:14 | [diff] [blame] | 13 | #include "net/base/net_errors.h" |
| 14 | #include "net/base/test_completion_callback.h" |
| 15 | #include "testing/gtest/include/gtest/gtest.h" |
[email protected] | 23887f04f | 2008-12-02 19:20:15 | [diff] [blame] | 16 | #include "testing/platform_test.h" |
[email protected] | 21da6eb | 2008-11-03 17:18:14 | [diff] [blame] | 17 | |
[email protected] | 8effd3f6 | 2011-03-25 16:29:07 | [diff] [blame] | 18 | namespace net { |
[email protected] | 96d7382 | 2011-10-10 02:11:24 | [diff] [blame] | 19 | |
[email protected] | 4c2048a | 2009-03-24 21:02:01 | [diff] [blame] | 20 | namespace { |
| 21 | |
| 22 | const char kTestData[] = "0123456789"; |
| 23 | const int kTestDataSize = arraysize(kTestData) - 1; |
[email protected] | 21da6eb | 2008-11-03 17:18:14 | [diff] [blame] | 24 | |
[email protected] | 96d7382 | 2011-10-10 02:11:24 | [diff] [blame] | 25 | } // namespace |
| 26 | |
[email protected] | 21da6eb | 2008-11-03 17:18:14 | [diff] [blame] | 27 | class FileStreamTest : public PlatformTest { |
| 28 | public: |
| 29 | virtual void SetUp() { |
| 30 | PlatformTest::SetUp(); |
| 31 | |
[email protected] | 33edeab | 2009-08-18 16:07:55 | [diff] [blame] | 32 | file_util::CreateTemporaryFile(&temp_file_path_); |
[email protected] | 7ff3f63 | 2009-10-13 18:43:35 | [diff] [blame] | 33 | file_util::WriteFile(temp_file_path_, kTestData, kTestDataSize); |
[email protected] | 21da6eb | 2008-11-03 17:18:14 | [diff] [blame] | 34 | } |
| 35 | virtual void TearDown() { |
| 36 | file_util::Delete(temp_file_path_, false); |
| 37 | |
| 38 | PlatformTest::TearDown(); |
| 39 | } |
[email protected] | 96d7382 | 2011-10-10 02:11:24 | [diff] [blame] | 40 | |
[email protected] | 07167e8f | 2009-01-26 21:38:11 | [diff] [blame] | 41 | const FilePath temp_file_path() const { return temp_file_path_; } |
[email protected] | 96d7382 | 2011-10-10 02:11:24 | [diff] [blame] | 42 | |
| 43 | static base::PlatformFile GetFile(const FileStream& stream) { |
| 44 | return stream.file_; |
| 45 | } |
| 46 | |
[email protected] | 21da6eb | 2008-11-03 17:18:14 | [diff] [blame] | 47 | private: |
[email protected] | 07167e8f | 2009-01-26 21:38:11 | [diff] [blame] | 48 | FilePath temp_file_path_; |
[email protected] | 21da6eb | 2008-11-03 17:18:14 | [diff] [blame] | 49 | }; |
| 50 | |
[email protected] | 96d7382 | 2011-10-10 02:11:24 | [diff] [blame] | 51 | namespace { |
| 52 | |
[email protected] | 21da6eb | 2008-11-03 17:18:14 | [diff] [blame] | 53 | TEST_F(FileStreamTest, BasicOpenClose) { |
[email protected] | 96d7382 | 2011-10-10 02:11:24 | [diff] [blame] | 54 | base::PlatformFile file = base::kInvalidPlatformFileValue; |
| 55 | { |
| 56 | FileStream stream; |
| 57 | int rv = stream.Open(temp_file_path(), |
| 58 | base::PLATFORM_FILE_OPEN | base::PLATFORM_FILE_READ); |
| 59 | EXPECT_EQ(OK, rv); |
| 60 | EXPECT_TRUE(stream.IsOpen()); |
| 61 | file = GetFile(stream); |
| 62 | } |
| 63 | EXPECT_NE(base::kInvalidPlatformFileValue, file); |
| 64 | base::PlatformFileInfo info; |
| 65 | // The file should be closed. |
| 66 | EXPECT_FALSE(base::GetPlatformFileInfo(file, &info)); |
| 67 | } |
| 68 | |
| 69 | TEST_F(FileStreamTest, FileHandleLeftOpen) { |
| 70 | bool created = false; |
| 71 | ASSERT_EQ(kTestDataSize, |
| 72 | file_util::WriteFile(temp_file_path(), kTestData, kTestDataSize)); |
| 73 | int flags = base::PLATFORM_FILE_OPEN_ALWAYS | base::PLATFORM_FILE_READ; |
| 74 | base::PlatformFile file = base::CreatePlatformFile( |
| 75 | temp_file_path(), flags, &created, NULL); |
| 76 | |
| 77 | { |
| 78 | // Seek to the beginning of the file and read. |
| 79 | FileStream read_stream(file, flags); |
| 80 | EXPECT_TRUE(read_stream.IsOpen()); |
| 81 | } |
| 82 | |
| 83 | EXPECT_NE(base::kInvalidPlatformFileValue, file); |
| 84 | base::PlatformFileInfo info; |
| 85 | // The file should still be open. |
| 86 | EXPECT_TRUE(base::GetPlatformFileInfo(file, &info)); |
| 87 | // Clean up. |
| 88 | EXPECT_TRUE(base::ClosePlatformFile(file)); |
[email protected] | 21da6eb | 2008-11-03 17:18:14 | [diff] [blame] | 89 | } |
| 90 | |
[email protected] | 92aad522 | 2009-02-09 22:26:41 | [diff] [blame] | 91 | // Test the use of FileStream with a file handle provided at construction. |
| 92 | TEST_F(FileStreamTest, UseFileHandle) { |
| 93 | bool created = false; |
| 94 | |
| 95 | // 1. Test reading with a file handle. |
| 96 | ASSERT_EQ(kTestDataSize, |
| 97 | file_util::WriteFile(temp_file_path(), kTestData, kTestDataSize)); |
| 98 | int flags = base::PLATFORM_FILE_OPEN_ALWAYS | base::PLATFORM_FILE_READ; |
| 99 | base::PlatformFile file = base::CreatePlatformFile( |
[email protected] | ed65fec | 2010-08-31 19:30:27 | [diff] [blame] | 100 | temp_file_path(), flags, &created, NULL); |
[email protected] | 92aad522 | 2009-02-09 22:26:41 | [diff] [blame] | 101 | |
| 102 | // Seek to the beginning of the file and read. |
[email protected] | 8effd3f6 | 2011-03-25 16:29:07 | [diff] [blame] | 103 | FileStream read_stream(file, flags); |
| 104 | ASSERT_EQ(0, read_stream.Seek(FROM_BEGIN, 0)); |
[email protected] | 92aad522 | 2009-02-09 22:26:41 | [diff] [blame] | 105 | ASSERT_EQ(kTestDataSize, read_stream.Available()); |
| 106 | // Read into buffer and compare. |
| 107 | char buffer[kTestDataSize]; |
[email protected] | 5eb431e2 | 2011-10-12 08:51:38 | [diff] [blame^] | 108 | ASSERT_EQ(kTestDataSize, |
| 109 | read_stream.Read(buffer, kTestDataSize, CompletionCallback())); |
[email protected] | 92aad522 | 2009-02-09 22:26:41 | [diff] [blame] | 110 | ASSERT_EQ(0, memcmp(kTestData, buffer, kTestDataSize)); |
| 111 | read_stream.Close(); |
| 112 | |
| 113 | // 2. Test writing with a file handle. |
| 114 | file_util::Delete(temp_file_path(), false); |
| 115 | flags = base::PLATFORM_FILE_OPEN_ALWAYS | base::PLATFORM_FILE_WRITE; |
[email protected] | ed65fec | 2010-08-31 19:30:27 | [diff] [blame] | 116 | file = base::CreatePlatformFile(temp_file_path(), flags, &created, NULL); |
[email protected] | 92aad522 | 2009-02-09 22:26:41 | [diff] [blame] | 117 | |
[email protected] | 8effd3f6 | 2011-03-25 16:29:07 | [diff] [blame] | 118 | FileStream write_stream(file, flags); |
| 119 | ASSERT_EQ(0, write_stream.Seek(FROM_BEGIN, 0)); |
[email protected] | 5eb431e2 | 2011-10-12 08:51:38 | [diff] [blame^] | 120 | ASSERT_EQ(kTestDataSize, |
| 121 | write_stream.Write(kTestData, kTestDataSize, CompletionCallback())); |
[email protected] | 92aad522 | 2009-02-09 22:26:41 | [diff] [blame] | 122 | write_stream.Close(); |
| 123 | |
| 124 | // Read into buffer and compare to make sure the handle worked fine. |
| 125 | ASSERT_EQ(kTestDataSize, |
| 126 | file_util::ReadFile(temp_file_path(), buffer, kTestDataSize)); |
| 127 | ASSERT_EQ(0, memcmp(kTestData, buffer, kTestDataSize)); |
| 128 | } |
| 129 | |
[email protected] | 21da6eb | 2008-11-03 17:18:14 | [diff] [blame] | 130 | TEST_F(FileStreamTest, UseClosedStream) { |
[email protected] | 8effd3f6 | 2011-03-25 16:29:07 | [diff] [blame] | 131 | FileStream stream; |
[email protected] | 21da6eb | 2008-11-03 17:18:14 | [diff] [blame] | 132 | |
| 133 | EXPECT_FALSE(stream.IsOpen()); |
| 134 | |
| 135 | // Try seeking... |
[email protected] | 8effd3f6 | 2011-03-25 16:29:07 | [diff] [blame] | 136 | int64 new_offset = stream.Seek(FROM_BEGIN, 5); |
| 137 | EXPECT_EQ(ERR_UNEXPECTED, new_offset); |
[email protected] | 21da6eb | 2008-11-03 17:18:14 | [diff] [blame] | 138 | |
| 139 | // Try available... |
| 140 | int64 avail = stream.Available(); |
[email protected] | 8effd3f6 | 2011-03-25 16:29:07 | [diff] [blame] | 141 | EXPECT_EQ(ERR_UNEXPECTED, avail); |
[email protected] | 21da6eb | 2008-11-03 17:18:14 | [diff] [blame] | 142 | |
| 143 | // Try reading... |
| 144 | char buf[10]; |
[email protected] | 5eb431e2 | 2011-10-12 08:51:38 | [diff] [blame^] | 145 | int rv = stream.Read(buf, arraysize(buf), CompletionCallback()); |
[email protected] | 8effd3f6 | 2011-03-25 16:29:07 | [diff] [blame] | 146 | EXPECT_EQ(ERR_UNEXPECTED, rv); |
[email protected] | 21da6eb | 2008-11-03 17:18:14 | [diff] [blame] | 147 | } |
| 148 | |
| 149 | TEST_F(FileStreamTest, BasicRead) { |
| 150 | int64 file_size; |
| 151 | bool ok = file_util::GetFileSize(temp_file_path(), &file_size); |
| 152 | EXPECT_TRUE(ok); |
| 153 | |
[email protected] | 8effd3f6 | 2011-03-25 16:29:07 | [diff] [blame] | 154 | FileStream stream; |
[email protected] | f0a51fb5 | 2009-03-05 12:46:38 | [diff] [blame] | 155 | int flags = base::PLATFORM_FILE_OPEN | |
[email protected] | 21da6eb | 2008-11-03 17:18:14 | [diff] [blame] | 156 | base::PLATFORM_FILE_READ; |
| 157 | int rv = stream.Open(temp_file_path(), flags); |
[email protected] | 8effd3f6 | 2011-03-25 16:29:07 | [diff] [blame] | 158 | EXPECT_EQ(OK, rv); |
[email protected] | 21da6eb | 2008-11-03 17:18:14 | [diff] [blame] | 159 | |
| 160 | int64 total_bytes_avail = stream.Available(); |
| 161 | EXPECT_EQ(file_size, total_bytes_avail); |
| 162 | |
[email protected] | 4c2048a | 2009-03-24 21:02:01 | [diff] [blame] | 163 | int total_bytes_read = 0; |
[email protected] | 21da6eb | 2008-11-03 17:18:14 | [diff] [blame] | 164 | |
| 165 | std::string data_read; |
| 166 | for (;;) { |
| 167 | char buf[4]; |
[email protected] | 5eb431e2 | 2011-10-12 08:51:38 | [diff] [blame^] | 168 | rv = stream.Read(buf, arraysize(buf), CompletionCallback()); |
[email protected] | 21da6eb | 2008-11-03 17:18:14 | [diff] [blame] | 169 | EXPECT_LE(0, rv); |
| 170 | if (rv <= 0) |
| 171 | break; |
| 172 | total_bytes_read += rv; |
| 173 | data_read.append(buf, rv); |
| 174 | } |
| 175 | EXPECT_EQ(file_size, total_bytes_read); |
[email protected] | 4c2048a | 2009-03-24 21:02:01 | [diff] [blame] | 176 | EXPECT_EQ(kTestData, data_read); |
[email protected] | 21da6eb | 2008-11-03 17:18:14 | [diff] [blame] | 177 | } |
| 178 | |
| 179 | TEST_F(FileStreamTest, AsyncRead) { |
| 180 | int64 file_size; |
| 181 | bool ok = file_util::GetFileSize(temp_file_path(), &file_size); |
| 182 | EXPECT_TRUE(ok); |
| 183 | |
[email protected] | 8effd3f6 | 2011-03-25 16:29:07 | [diff] [blame] | 184 | FileStream stream; |
[email protected] | f0a51fb5 | 2009-03-05 12:46:38 | [diff] [blame] | 185 | int flags = base::PLATFORM_FILE_OPEN | |
| 186 | base::PLATFORM_FILE_READ | |
[email protected] | 21da6eb | 2008-11-03 17:18:14 | [diff] [blame] | 187 | base::PLATFORM_FILE_ASYNC; |
| 188 | int rv = stream.Open(temp_file_path(), flags); |
[email protected] | 8effd3f6 | 2011-03-25 16:29:07 | [diff] [blame] | 189 | EXPECT_EQ(OK, rv); |
[email protected] | 21da6eb | 2008-11-03 17:18:14 | [diff] [blame] | 190 | |
| 191 | int64 total_bytes_avail = stream.Available(); |
| 192 | EXPECT_EQ(file_size, total_bytes_avail); |
| 193 | |
[email protected] | 5eb431e2 | 2011-10-12 08:51:38 | [diff] [blame^] | 194 | TestCompletionCallback callback; |
[email protected] | 21da6eb | 2008-11-03 17:18:14 | [diff] [blame] | 195 | |
[email protected] | 4c2048a | 2009-03-24 21:02:01 | [diff] [blame] | 196 | int total_bytes_read = 0; |
[email protected] | 21da6eb | 2008-11-03 17:18:14 | [diff] [blame] | 197 | |
| 198 | std::string data_read; |
| 199 | for (;;) { |
| 200 | char buf[4]; |
[email protected] | 5eb431e2 | 2011-10-12 08:51:38 | [diff] [blame^] | 201 | rv = stream.Read(buf, arraysize(buf), callback.callback()); |
[email protected] | 8effd3f6 | 2011-03-25 16:29:07 | [diff] [blame] | 202 | if (rv == ERR_IO_PENDING) |
[email protected] | 21da6eb | 2008-11-03 17:18:14 | [diff] [blame] | 203 | rv = callback.WaitForResult(); |
| 204 | EXPECT_LE(0, rv); |
| 205 | if (rv <= 0) |
| 206 | break; |
| 207 | total_bytes_read += rv; |
| 208 | data_read.append(buf, rv); |
| 209 | } |
| 210 | EXPECT_EQ(file_size, total_bytes_read); |
[email protected] | 4c2048a | 2009-03-24 21:02:01 | [diff] [blame] | 211 | EXPECT_EQ(kTestData, data_read); |
| 212 | } |
| 213 | |
| 214 | TEST_F(FileStreamTest, AsyncRead_EarlyClose) { |
| 215 | int64 file_size; |
| 216 | bool ok = file_util::GetFileSize(temp_file_path(), &file_size); |
| 217 | EXPECT_TRUE(ok); |
| 218 | |
[email protected] | 8effd3f6 | 2011-03-25 16:29:07 | [diff] [blame] | 219 | FileStream stream; |
[email protected] | 4c2048a | 2009-03-24 21:02:01 | [diff] [blame] | 220 | int flags = base::PLATFORM_FILE_OPEN | |
| 221 | base::PLATFORM_FILE_READ | |
| 222 | base::PLATFORM_FILE_ASYNC; |
| 223 | int rv = stream.Open(temp_file_path(), flags); |
[email protected] | 8effd3f6 | 2011-03-25 16:29:07 | [diff] [blame] | 224 | EXPECT_EQ(OK, rv); |
[email protected] | 4c2048a | 2009-03-24 21:02:01 | [diff] [blame] | 225 | |
| 226 | int64 total_bytes_avail = stream.Available(); |
| 227 | EXPECT_EQ(file_size, total_bytes_avail); |
| 228 | |
[email protected] | 5eb431e2 | 2011-10-12 08:51:38 | [diff] [blame^] | 229 | TestCompletionCallback callback; |
[email protected] | 4c2048a | 2009-03-24 21:02:01 | [diff] [blame] | 230 | |
| 231 | char buf[4]; |
[email protected] | 5eb431e2 | 2011-10-12 08:51:38 | [diff] [blame^] | 232 | rv = stream.Read(buf, arraysize(buf), callback.callback()); |
[email protected] | 4c2048a | 2009-03-24 21:02:01 | [diff] [blame] | 233 | stream.Close(); |
[email protected] | 3828a75 | 2009-06-03 23:05:59 | [diff] [blame] | 234 | if (rv < 0) { |
[email protected] | 8effd3f6 | 2011-03-25 16:29:07 | [diff] [blame] | 235 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 3828a75 | 2009-06-03 23:05:59 | [diff] [blame] | 236 | // The callback should not be called if the request is cancelled. |
| 237 | MessageLoop::current()->RunAllPending(); |
| 238 | EXPECT_FALSE(callback.have_result()); |
| 239 | } else { |
| 240 | EXPECT_EQ(std::string(kTestData, rv), std::string(buf, rv)); |
| 241 | } |
[email protected] | 21da6eb | 2008-11-03 17:18:14 | [diff] [blame] | 242 | } |
| 243 | |
| 244 | TEST_F(FileStreamTest, BasicRead_FromOffset) { |
| 245 | int64 file_size; |
| 246 | bool ok = file_util::GetFileSize(temp_file_path(), &file_size); |
| 247 | EXPECT_TRUE(ok); |
| 248 | |
[email protected] | 8effd3f6 | 2011-03-25 16:29:07 | [diff] [blame] | 249 | FileStream stream; |
[email protected] | f0a51fb5 | 2009-03-05 12:46:38 | [diff] [blame] | 250 | int flags = base::PLATFORM_FILE_OPEN | |
[email protected] | 21da6eb | 2008-11-03 17:18:14 | [diff] [blame] | 251 | base::PLATFORM_FILE_READ; |
| 252 | int rv = stream.Open(temp_file_path(), flags); |
[email protected] | 8effd3f6 | 2011-03-25 16:29:07 | [diff] [blame] | 253 | EXPECT_EQ(OK, rv); |
[email protected] | 21da6eb | 2008-11-03 17:18:14 | [diff] [blame] | 254 | |
| 255 | const int64 kOffset = 3; |
[email protected] | 8effd3f6 | 2011-03-25 16:29:07 | [diff] [blame] | 256 | int64 new_offset = stream.Seek(FROM_BEGIN, kOffset); |
[email protected] | 21da6eb | 2008-11-03 17:18:14 | [diff] [blame] | 257 | EXPECT_EQ(kOffset, new_offset); |
| 258 | |
| 259 | int64 total_bytes_avail = stream.Available(); |
| 260 | EXPECT_EQ(file_size - kOffset, total_bytes_avail); |
| 261 | |
| 262 | int64 total_bytes_read = 0; |
| 263 | |
| 264 | std::string data_read; |
| 265 | for (;;) { |
| 266 | char buf[4]; |
[email protected] | 5eb431e2 | 2011-10-12 08:51:38 | [diff] [blame^] | 267 | rv = stream.Read(buf, arraysize(buf), CompletionCallback()); |
[email protected] | 21da6eb | 2008-11-03 17:18:14 | [diff] [blame] | 268 | EXPECT_LE(0, rv); |
| 269 | if (rv <= 0) |
| 270 | break; |
| 271 | total_bytes_read += rv; |
| 272 | data_read.append(buf, rv); |
| 273 | } |
| 274 | EXPECT_EQ(file_size - kOffset, total_bytes_read); |
| 275 | EXPECT_TRUE(data_read == kTestData + kOffset); |
[email protected] | 4c2048a | 2009-03-24 21:02:01 | [diff] [blame] | 276 | EXPECT_EQ(kTestData + kOffset, data_read); |
[email protected] | 21da6eb | 2008-11-03 17:18:14 | [diff] [blame] | 277 | } |
| 278 | |
| 279 | TEST_F(FileStreamTest, AsyncRead_FromOffset) { |
| 280 | int64 file_size; |
| 281 | bool ok = file_util::GetFileSize(temp_file_path(), &file_size); |
| 282 | EXPECT_TRUE(ok); |
| 283 | |
[email protected] | 8effd3f6 | 2011-03-25 16:29:07 | [diff] [blame] | 284 | FileStream stream; |
[email protected] | f0a51fb5 | 2009-03-05 12:46:38 | [diff] [blame] | 285 | int flags = base::PLATFORM_FILE_OPEN | |
| 286 | base::PLATFORM_FILE_READ | |
[email protected] | 21da6eb | 2008-11-03 17:18:14 | [diff] [blame] | 287 | base::PLATFORM_FILE_ASYNC; |
| 288 | int rv = stream.Open(temp_file_path(), flags); |
[email protected] | 8effd3f6 | 2011-03-25 16:29:07 | [diff] [blame] | 289 | EXPECT_EQ(OK, rv); |
[email protected] | 21da6eb | 2008-11-03 17:18:14 | [diff] [blame] | 290 | |
| 291 | const int64 kOffset = 3; |
[email protected] | 8effd3f6 | 2011-03-25 16:29:07 | [diff] [blame] | 292 | int64 new_offset = stream.Seek(FROM_BEGIN, kOffset); |
[email protected] | 21da6eb | 2008-11-03 17:18:14 | [diff] [blame] | 293 | EXPECT_EQ(kOffset, new_offset); |
| 294 | |
| 295 | int64 total_bytes_avail = stream.Available(); |
| 296 | EXPECT_EQ(file_size - kOffset, total_bytes_avail); |
| 297 | |
[email protected] | 5eb431e2 | 2011-10-12 08:51:38 | [diff] [blame^] | 298 | TestCompletionCallback callback; |
[email protected] | 21da6eb | 2008-11-03 17:18:14 | [diff] [blame] | 299 | |
[email protected] | 4c2048a | 2009-03-24 21:02:01 | [diff] [blame] | 300 | int total_bytes_read = 0; |
[email protected] | 21da6eb | 2008-11-03 17:18:14 | [diff] [blame] | 301 | |
| 302 | std::string data_read; |
| 303 | for (;;) { |
| 304 | char buf[4]; |
[email protected] | 5eb431e2 | 2011-10-12 08:51:38 | [diff] [blame^] | 305 | rv = stream.Read(buf, arraysize(buf), callback.callback()); |
[email protected] | 8effd3f6 | 2011-03-25 16:29:07 | [diff] [blame] | 306 | if (rv == ERR_IO_PENDING) |
[email protected] | 21da6eb | 2008-11-03 17:18:14 | [diff] [blame] | 307 | rv = callback.WaitForResult(); |
| 308 | EXPECT_LE(0, rv); |
| 309 | if (rv <= 0) |
| 310 | break; |
| 311 | total_bytes_read += rv; |
| 312 | data_read.append(buf, rv); |
| 313 | } |
| 314 | EXPECT_EQ(file_size - kOffset, total_bytes_read); |
[email protected] | 4c2048a | 2009-03-24 21:02:01 | [diff] [blame] | 315 | EXPECT_EQ(kTestData + kOffset, data_read); |
[email protected] | 21da6eb | 2008-11-03 17:18:14 | [diff] [blame] | 316 | } |
| 317 | |
| 318 | TEST_F(FileStreamTest, SeekAround) { |
[email protected] | 8effd3f6 | 2011-03-25 16:29:07 | [diff] [blame] | 319 | FileStream stream; |
[email protected] | f0a51fb5 | 2009-03-05 12:46:38 | [diff] [blame] | 320 | int flags = base::PLATFORM_FILE_OPEN | |
[email protected] | 21da6eb | 2008-11-03 17:18:14 | [diff] [blame] | 321 | base::PLATFORM_FILE_READ; |
| 322 | int rv = stream.Open(temp_file_path(), flags); |
[email protected] | 8effd3f6 | 2011-03-25 16:29:07 | [diff] [blame] | 323 | EXPECT_EQ(OK, rv); |
[email protected] | 21da6eb | 2008-11-03 17:18:14 | [diff] [blame] | 324 | |
| 325 | const int64 kOffset = 3; |
[email protected] | 8effd3f6 | 2011-03-25 16:29:07 | [diff] [blame] | 326 | int64 new_offset = stream.Seek(FROM_BEGIN, kOffset); |
[email protected] | 21da6eb | 2008-11-03 17:18:14 | [diff] [blame] | 327 | EXPECT_EQ(kOffset, new_offset); |
| 328 | |
[email protected] | 8effd3f6 | 2011-03-25 16:29:07 | [diff] [blame] | 329 | new_offset = stream.Seek(FROM_CURRENT, kOffset); |
[email protected] | 21da6eb | 2008-11-03 17:18:14 | [diff] [blame] | 330 | EXPECT_EQ(2 * kOffset, new_offset); |
| 331 | |
[email protected] | 8effd3f6 | 2011-03-25 16:29:07 | [diff] [blame] | 332 | new_offset = stream.Seek(FROM_CURRENT, -kOffset); |
[email protected] | 21da6eb | 2008-11-03 17:18:14 | [diff] [blame] | 333 | EXPECT_EQ(kOffset, new_offset); |
| 334 | |
| 335 | const int kTestDataLen = arraysize(kTestData) - 1; |
| 336 | |
[email protected] | 8effd3f6 | 2011-03-25 16:29:07 | [diff] [blame] | 337 | new_offset = stream.Seek(FROM_END, -kTestDataLen); |
[email protected] | 21da6eb | 2008-11-03 17:18:14 | [diff] [blame] | 338 | EXPECT_EQ(0, new_offset); |
| 339 | } |
| 340 | |
| 341 | TEST_F(FileStreamTest, BasicWrite) { |
[email protected] | 8effd3f6 | 2011-03-25 16:29:07 | [diff] [blame] | 342 | FileStream stream; |
[email protected] | f0a51fb5 | 2009-03-05 12:46:38 | [diff] [blame] | 343 | int flags = base::PLATFORM_FILE_CREATE_ALWAYS | |
[email protected] | 21da6eb | 2008-11-03 17:18:14 | [diff] [blame] | 344 | base::PLATFORM_FILE_WRITE; |
| 345 | int rv = stream.Open(temp_file_path(), flags); |
[email protected] | 8effd3f6 | 2011-03-25 16:29:07 | [diff] [blame] | 346 | EXPECT_EQ(OK, rv); |
[email protected] | 21da6eb | 2008-11-03 17:18:14 | [diff] [blame] | 347 | |
| 348 | int64 file_size; |
| 349 | bool ok = file_util::GetFileSize(temp_file_path(), &file_size); |
| 350 | EXPECT_TRUE(ok); |
| 351 | EXPECT_EQ(0, file_size); |
| 352 | |
[email protected] | 5eb431e2 | 2011-10-12 08:51:38 | [diff] [blame^] | 353 | rv = stream.Write(kTestData, kTestDataSize, CompletionCallback()); |
[email protected] | 21da6eb | 2008-11-03 17:18:14 | [diff] [blame] | 354 | EXPECT_EQ(kTestDataSize, rv); |
| 355 | stream.Close(); |
| 356 | |
| 357 | ok = file_util::GetFileSize(temp_file_path(), &file_size); |
| 358 | EXPECT_TRUE(ok); |
| 359 | EXPECT_EQ(kTestDataSize, file_size); |
| 360 | } |
| 361 | |
| 362 | TEST_F(FileStreamTest, AsyncWrite) { |
[email protected] | 8effd3f6 | 2011-03-25 16:29:07 | [diff] [blame] | 363 | FileStream stream; |
[email protected] | f0a51fb5 | 2009-03-05 12:46:38 | [diff] [blame] | 364 | int flags = base::PLATFORM_FILE_CREATE_ALWAYS | |
| 365 | base::PLATFORM_FILE_WRITE | |
[email protected] | 21da6eb | 2008-11-03 17:18:14 | [diff] [blame] | 366 | base::PLATFORM_FILE_ASYNC; |
| 367 | int rv = stream.Open(temp_file_path(), flags); |
[email protected] | 8effd3f6 | 2011-03-25 16:29:07 | [diff] [blame] | 368 | EXPECT_EQ(OK, rv); |
[email protected] | 21da6eb | 2008-11-03 17:18:14 | [diff] [blame] | 369 | |
| 370 | int64 file_size; |
| 371 | bool ok = file_util::GetFileSize(temp_file_path(), &file_size); |
| 372 | EXPECT_TRUE(ok); |
| 373 | EXPECT_EQ(0, file_size); |
| 374 | |
[email protected] | 5eb431e2 | 2011-10-12 08:51:38 | [diff] [blame^] | 375 | TestCompletionCallback callback; |
[email protected] | 4c2048a | 2009-03-24 21:02:01 | [diff] [blame] | 376 | int total_bytes_written = 0; |
[email protected] | 21da6eb | 2008-11-03 17:18:14 | [diff] [blame] | 377 | |
| 378 | while (total_bytes_written != kTestDataSize) { |
[email protected] | 4c2048a | 2009-03-24 21:02:01 | [diff] [blame] | 379 | rv = stream.Write(kTestData + total_bytes_written, |
| 380 | kTestDataSize - total_bytes_written, |
[email protected] | 5eb431e2 | 2011-10-12 08:51:38 | [diff] [blame^] | 381 | callback.callback()); |
[email protected] | 8effd3f6 | 2011-03-25 16:29:07 | [diff] [blame] | 382 | if (rv == ERR_IO_PENDING) |
[email protected] | 21da6eb | 2008-11-03 17:18:14 | [diff] [blame] | 383 | rv = callback.WaitForResult(); |
| 384 | EXPECT_LT(0, rv); |
| 385 | if (rv <= 0) |
| 386 | break; |
| 387 | total_bytes_written += rv; |
| 388 | } |
| 389 | ok = file_util::GetFileSize(temp_file_path(), &file_size); |
| 390 | EXPECT_TRUE(ok); |
| 391 | EXPECT_EQ(file_size, total_bytes_written); |
| 392 | } |
| 393 | |
[email protected] | 4c2048a | 2009-03-24 21:02:01 | [diff] [blame] | 394 | TEST_F(FileStreamTest, AsyncWrite_EarlyClose) { |
[email protected] | 8effd3f6 | 2011-03-25 16:29:07 | [diff] [blame] | 395 | FileStream stream; |
[email protected] | 4c2048a | 2009-03-24 21:02:01 | [diff] [blame] | 396 | int flags = base::PLATFORM_FILE_CREATE_ALWAYS | |
| 397 | base::PLATFORM_FILE_WRITE | |
| 398 | base::PLATFORM_FILE_ASYNC; |
| 399 | int rv = stream.Open(temp_file_path(), flags); |
[email protected] | 8effd3f6 | 2011-03-25 16:29:07 | [diff] [blame] | 400 | EXPECT_EQ(OK, rv); |
[email protected] | 4c2048a | 2009-03-24 21:02:01 | [diff] [blame] | 401 | |
| 402 | int64 file_size; |
| 403 | bool ok = file_util::GetFileSize(temp_file_path(), &file_size); |
| 404 | EXPECT_TRUE(ok); |
| 405 | EXPECT_EQ(0, file_size); |
| 406 | |
[email protected] | 5eb431e2 | 2011-10-12 08:51:38 | [diff] [blame^] | 407 | TestCompletionCallback callback; |
[email protected] | 4c2048a | 2009-03-24 21:02:01 | [diff] [blame] | 408 | int total_bytes_written = 0; |
| 409 | |
| 410 | rv = stream.Write(kTestData + total_bytes_written, |
| 411 | kTestDataSize - total_bytes_written, |
[email protected] | 5eb431e2 | 2011-10-12 08:51:38 | [diff] [blame^] | 412 | callback.callback()); |
[email protected] | 4c2048a | 2009-03-24 21:02:01 | [diff] [blame] | 413 | stream.Close(); |
[email protected] | 3828a75 | 2009-06-03 23:05:59 | [diff] [blame] | 414 | if (rv < 0) { |
[email protected] | 8effd3f6 | 2011-03-25 16:29:07 | [diff] [blame] | 415 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 3828a75 | 2009-06-03 23:05:59 | [diff] [blame] | 416 | // The callback should not be called if the request is cancelled. |
| 417 | MessageLoop::current()->RunAllPending(); |
| 418 | EXPECT_FALSE(callback.have_result()); |
| 419 | } else { |
| 420 | ok = file_util::GetFileSize(temp_file_path(), &file_size); |
| 421 | EXPECT_TRUE(ok); |
| 422 | EXPECT_EQ(file_size, rv); |
| 423 | } |
[email protected] | 4c2048a | 2009-03-24 21:02:01 | [diff] [blame] | 424 | } |
| 425 | |
[email protected] | 21da6eb | 2008-11-03 17:18:14 | [diff] [blame] | 426 | TEST_F(FileStreamTest, BasicWrite_FromOffset) { |
[email protected] | 8effd3f6 | 2011-03-25 16:29:07 | [diff] [blame] | 427 | FileStream stream; |
[email protected] | f0a51fb5 | 2009-03-05 12:46:38 | [diff] [blame] | 428 | int flags = base::PLATFORM_FILE_OPEN | |
[email protected] | 21da6eb | 2008-11-03 17:18:14 | [diff] [blame] | 429 | base::PLATFORM_FILE_WRITE; |
| 430 | int rv = stream.Open(temp_file_path(), flags); |
[email protected] | 8effd3f6 | 2011-03-25 16:29:07 | [diff] [blame] | 431 | EXPECT_EQ(OK, rv); |
[email protected] | 21da6eb | 2008-11-03 17:18:14 | [diff] [blame] | 432 | |
| 433 | int64 file_size; |
| 434 | bool ok = file_util::GetFileSize(temp_file_path(), &file_size); |
| 435 | EXPECT_TRUE(ok); |
| 436 | EXPECT_EQ(kTestDataSize, file_size); |
| 437 | |
| 438 | const int64 kOffset = 0; |
[email protected] | 8effd3f6 | 2011-03-25 16:29:07 | [diff] [blame] | 439 | int64 new_offset = stream.Seek(FROM_END, kOffset); |
[email protected] | 21da6eb | 2008-11-03 17:18:14 | [diff] [blame] | 440 | EXPECT_EQ(kTestDataSize, new_offset); |
| 441 | |
[email protected] | 5eb431e2 | 2011-10-12 08:51:38 | [diff] [blame^] | 442 | rv = stream.Write(kTestData, kTestDataSize, CompletionCallback()); |
[email protected] | 21da6eb | 2008-11-03 17:18:14 | [diff] [blame] | 443 | EXPECT_EQ(kTestDataSize, rv); |
| 444 | stream.Close(); |
| 445 | |
| 446 | ok = file_util::GetFileSize(temp_file_path(), &file_size); |
| 447 | EXPECT_TRUE(ok); |
| 448 | EXPECT_EQ(kTestDataSize * 2, file_size); |
| 449 | } |
| 450 | |
| 451 | TEST_F(FileStreamTest, AsyncWrite_FromOffset) { |
| 452 | int64 file_size; |
| 453 | bool ok = file_util::GetFileSize(temp_file_path(), &file_size); |
| 454 | EXPECT_TRUE(ok); |
| 455 | |
[email protected] | 8effd3f6 | 2011-03-25 16:29:07 | [diff] [blame] | 456 | FileStream stream; |
[email protected] | f0a51fb5 | 2009-03-05 12:46:38 | [diff] [blame] | 457 | int flags = base::PLATFORM_FILE_OPEN | |
[email protected] | 21da6eb | 2008-11-03 17:18:14 | [diff] [blame] | 458 | base::PLATFORM_FILE_WRITE | |
| 459 | base::PLATFORM_FILE_ASYNC; |
| 460 | int rv = stream.Open(temp_file_path(), flags); |
[email protected] | 8effd3f6 | 2011-03-25 16:29:07 | [diff] [blame] | 461 | EXPECT_EQ(OK, rv); |
[email protected] | 21da6eb | 2008-11-03 17:18:14 | [diff] [blame] | 462 | |
| 463 | const int64 kOffset = 0; |
[email protected] | 8effd3f6 | 2011-03-25 16:29:07 | [diff] [blame] | 464 | int64 new_offset = stream.Seek(FROM_END, kOffset); |
[email protected] | 21da6eb | 2008-11-03 17:18:14 | [diff] [blame] | 465 | EXPECT_EQ(kTestDataSize, new_offset); |
| 466 | |
[email protected] | 5eb431e2 | 2011-10-12 08:51:38 | [diff] [blame^] | 467 | TestCompletionCallback callback; |
[email protected] | 4c2048a | 2009-03-24 21:02:01 | [diff] [blame] | 468 | int total_bytes_written = 0; |
[email protected] | 21da6eb | 2008-11-03 17:18:14 | [diff] [blame] | 469 | |
| 470 | while (total_bytes_written != kTestDataSize) { |
[email protected] | 4c2048a | 2009-03-24 21:02:01 | [diff] [blame] | 471 | rv = stream.Write(kTestData + total_bytes_written, |
| 472 | kTestDataSize - total_bytes_written, |
[email protected] | 5eb431e2 | 2011-10-12 08:51:38 | [diff] [blame^] | 473 | callback.callback()); |
[email protected] | 8effd3f6 | 2011-03-25 16:29:07 | [diff] [blame] | 474 | if (rv == ERR_IO_PENDING) |
[email protected] | 21da6eb | 2008-11-03 17:18:14 | [diff] [blame] | 475 | rv = callback.WaitForResult(); |
| 476 | EXPECT_LT(0, rv); |
| 477 | if (rv <= 0) |
| 478 | break; |
| 479 | total_bytes_written += rv; |
| 480 | } |
| 481 | ok = file_util::GetFileSize(temp_file_path(), &file_size); |
| 482 | EXPECT_TRUE(ok); |
| 483 | EXPECT_EQ(file_size, kTestDataSize * 2); |
| 484 | } |
| 485 | |
| 486 | TEST_F(FileStreamTest, BasicReadWrite) { |
| 487 | int64 file_size; |
| 488 | bool ok = file_util::GetFileSize(temp_file_path(), &file_size); |
| 489 | EXPECT_TRUE(ok); |
| 490 | |
[email protected] | 8effd3f6 | 2011-03-25 16:29:07 | [diff] [blame] | 491 | FileStream stream; |
[email protected] | f0a51fb5 | 2009-03-05 12:46:38 | [diff] [blame] | 492 | int flags = base::PLATFORM_FILE_OPEN | |
| 493 | base::PLATFORM_FILE_READ | |
[email protected] | 21da6eb | 2008-11-03 17:18:14 | [diff] [blame] | 494 | base::PLATFORM_FILE_WRITE; |
| 495 | int rv = stream.Open(temp_file_path(), flags); |
[email protected] | 8effd3f6 | 2011-03-25 16:29:07 | [diff] [blame] | 496 | EXPECT_EQ(OK, rv); |
[email protected] | 21da6eb | 2008-11-03 17:18:14 | [diff] [blame] | 497 | |
| 498 | int64 total_bytes_avail = stream.Available(); |
| 499 | EXPECT_EQ(file_size, total_bytes_avail); |
| 500 | |
[email protected] | 4c2048a | 2009-03-24 21:02:01 | [diff] [blame] | 501 | int total_bytes_read = 0; |
[email protected] | 21da6eb | 2008-11-03 17:18:14 | [diff] [blame] | 502 | |
| 503 | std::string data_read; |
| 504 | for (;;) { |
| 505 | char buf[4]; |
[email protected] | 5eb431e2 | 2011-10-12 08:51:38 | [diff] [blame^] | 506 | rv = stream.Read(buf, arraysize(buf), CompletionCallback()); |
[email protected] | 21da6eb | 2008-11-03 17:18:14 | [diff] [blame] | 507 | EXPECT_LE(0, rv); |
| 508 | if (rv <= 0) |
| 509 | break; |
| 510 | total_bytes_read += rv; |
| 511 | data_read.append(buf, rv); |
| 512 | } |
| 513 | EXPECT_EQ(file_size, total_bytes_read); |
| 514 | EXPECT_TRUE(data_read == kTestData); |
| 515 | |
[email protected] | 5eb431e2 | 2011-10-12 08:51:38 | [diff] [blame^] | 516 | rv = stream.Write(kTestData, kTestDataSize, CompletionCallback()); |
[email protected] | 21da6eb | 2008-11-03 17:18:14 | [diff] [blame] | 517 | EXPECT_EQ(kTestDataSize, rv); |
| 518 | stream.Close(); |
| 519 | |
| 520 | ok = file_util::GetFileSize(temp_file_path(), &file_size); |
| 521 | EXPECT_TRUE(ok); |
| 522 | EXPECT_EQ(kTestDataSize * 2, file_size); |
| 523 | } |
| 524 | |
[email protected] | 4c2048a | 2009-03-24 21:02:01 | [diff] [blame] | 525 | TEST_F(FileStreamTest, BasicWriteRead) { |
| 526 | int64 file_size; |
| 527 | bool ok = file_util::GetFileSize(temp_file_path(), &file_size); |
| 528 | EXPECT_TRUE(ok); |
| 529 | |
[email protected] | 8effd3f6 | 2011-03-25 16:29:07 | [diff] [blame] | 530 | FileStream stream; |
[email protected] | 4c2048a | 2009-03-24 21:02:01 | [diff] [blame] | 531 | int flags = base::PLATFORM_FILE_OPEN | |
| 532 | base::PLATFORM_FILE_READ | |
| 533 | base::PLATFORM_FILE_WRITE; |
| 534 | int rv = stream.Open(temp_file_path(), flags); |
[email protected] | 8effd3f6 | 2011-03-25 16:29:07 | [diff] [blame] | 535 | EXPECT_EQ(OK, rv); |
[email protected] | 4c2048a | 2009-03-24 21:02:01 | [diff] [blame] | 536 | |
| 537 | int64 total_bytes_avail = stream.Available(); |
| 538 | EXPECT_EQ(file_size, total_bytes_avail); |
| 539 | |
[email protected] | 8effd3f6 | 2011-03-25 16:29:07 | [diff] [blame] | 540 | int64 offset = stream.Seek(FROM_END, 0); |
[email protected] | 4c2048a | 2009-03-24 21:02:01 | [diff] [blame] | 541 | EXPECT_EQ(offset, file_size); |
| 542 | |
[email protected] | 5eb431e2 | 2011-10-12 08:51:38 | [diff] [blame^] | 543 | rv = stream.Write(kTestData, kTestDataSize, CompletionCallback()); |
[email protected] | 4c2048a | 2009-03-24 21:02:01 | [diff] [blame] | 544 | EXPECT_EQ(kTestDataSize, rv); |
| 545 | |
[email protected] | 8effd3f6 | 2011-03-25 16:29:07 | [diff] [blame] | 546 | offset = stream.Seek(FROM_BEGIN, 0); |
[email protected] | 4c2048a | 2009-03-24 21:02:01 | [diff] [blame] | 547 | EXPECT_EQ(0, offset); |
| 548 | |
| 549 | int64 total_bytes_read = 0; |
| 550 | |
| 551 | std::string data_read; |
| 552 | for (;;) { |
| 553 | char buf[4]; |
[email protected] | 5eb431e2 | 2011-10-12 08:51:38 | [diff] [blame^] | 554 | rv = stream.Read(buf, arraysize(buf), CompletionCallback()); |
[email protected] | 4c2048a | 2009-03-24 21:02:01 | [diff] [blame] | 555 | EXPECT_LE(0, rv); |
| 556 | if (rv <= 0) |
| 557 | break; |
| 558 | total_bytes_read += rv; |
| 559 | data_read.append(buf, rv); |
| 560 | } |
| 561 | stream.Close(); |
| 562 | |
| 563 | ok = file_util::GetFileSize(temp_file_path(), &file_size); |
| 564 | EXPECT_TRUE(ok); |
| 565 | EXPECT_EQ(kTestDataSize * 2, file_size); |
| 566 | EXPECT_EQ(kTestDataSize * 2, total_bytes_read); |
| 567 | |
| 568 | const std::string kExpectedFileData = |
| 569 | std::string(kTestData) + std::string(kTestData); |
| 570 | EXPECT_EQ(kExpectedFileData, data_read); |
| 571 | } |
| 572 | |
| 573 | TEST_F(FileStreamTest, BasicAsyncReadWrite) { |
| 574 | int64 file_size; |
| 575 | bool ok = file_util::GetFileSize(temp_file_path(), &file_size); |
| 576 | EXPECT_TRUE(ok); |
| 577 | |
[email protected] | 8effd3f6 | 2011-03-25 16:29:07 | [diff] [blame] | 578 | FileStream stream; |
[email protected] | 4c2048a | 2009-03-24 21:02:01 | [diff] [blame] | 579 | int flags = base::PLATFORM_FILE_OPEN | |
| 580 | base::PLATFORM_FILE_READ | |
| 581 | base::PLATFORM_FILE_WRITE | |
| 582 | base::PLATFORM_FILE_ASYNC; |
| 583 | int rv = stream.Open(temp_file_path(), flags); |
[email protected] | 8effd3f6 | 2011-03-25 16:29:07 | [diff] [blame] | 584 | EXPECT_EQ(OK, rv); |
[email protected] | 4c2048a | 2009-03-24 21:02:01 | [diff] [blame] | 585 | |
| 586 | int64 total_bytes_avail = stream.Available(); |
| 587 | EXPECT_EQ(file_size, total_bytes_avail); |
| 588 | |
[email protected] | 5eb431e2 | 2011-10-12 08:51:38 | [diff] [blame^] | 589 | TestCompletionCallback callback; |
[email protected] | 4c2048a | 2009-03-24 21:02:01 | [diff] [blame] | 590 | int64 total_bytes_read = 0; |
| 591 | |
| 592 | std::string data_read; |
| 593 | for (;;) { |
| 594 | char buf[4]; |
[email protected] | 5eb431e2 | 2011-10-12 08:51:38 | [diff] [blame^] | 595 | rv = stream.Read(buf, arraysize(buf), callback.callback()); |
[email protected] | 8effd3f6 | 2011-03-25 16:29:07 | [diff] [blame] | 596 | if (rv == ERR_IO_PENDING) |
[email protected] | 4c2048a | 2009-03-24 21:02:01 | [diff] [blame] | 597 | rv = callback.WaitForResult(); |
| 598 | EXPECT_LE(0, rv); |
| 599 | if (rv <= 0) |
| 600 | break; |
| 601 | total_bytes_read += rv; |
| 602 | data_read.append(buf, rv); |
| 603 | } |
| 604 | EXPECT_EQ(file_size, total_bytes_read); |
| 605 | EXPECT_TRUE(data_read == kTestData); |
| 606 | |
| 607 | int total_bytes_written = 0; |
| 608 | |
| 609 | while (total_bytes_written != kTestDataSize) { |
| 610 | rv = stream.Write(kTestData + total_bytes_written, |
| 611 | kTestDataSize - total_bytes_written, |
[email protected] | 5eb431e2 | 2011-10-12 08:51:38 | [diff] [blame^] | 612 | callback.callback()); |
[email protected] | 8effd3f6 | 2011-03-25 16:29:07 | [diff] [blame] | 613 | if (rv == ERR_IO_PENDING) |
[email protected] | 4c2048a | 2009-03-24 21:02:01 | [diff] [blame] | 614 | rv = callback.WaitForResult(); |
| 615 | EXPECT_LT(0, rv); |
| 616 | if (rv <= 0) |
| 617 | break; |
| 618 | total_bytes_written += rv; |
| 619 | } |
| 620 | |
| 621 | stream.Close(); |
| 622 | |
| 623 | ok = file_util::GetFileSize(temp_file_path(), &file_size); |
| 624 | EXPECT_TRUE(ok); |
| 625 | EXPECT_EQ(kTestDataSize * 2, file_size); |
| 626 | } |
| 627 | |
| 628 | TEST_F(FileStreamTest, BasicAsyncWriteRead) { |
| 629 | int64 file_size; |
| 630 | bool ok = file_util::GetFileSize(temp_file_path(), &file_size); |
| 631 | EXPECT_TRUE(ok); |
| 632 | |
[email protected] | 8effd3f6 | 2011-03-25 16:29:07 | [diff] [blame] | 633 | FileStream stream; |
[email protected] | 4c2048a | 2009-03-24 21:02:01 | [diff] [blame] | 634 | int flags = base::PLATFORM_FILE_OPEN | |
| 635 | base::PLATFORM_FILE_READ | |
| 636 | base::PLATFORM_FILE_WRITE | |
| 637 | base::PLATFORM_FILE_ASYNC; |
| 638 | int rv = stream.Open(temp_file_path(), flags); |
[email protected] | 8effd3f6 | 2011-03-25 16:29:07 | [diff] [blame] | 639 | EXPECT_EQ(OK, rv); |
[email protected] | 4c2048a | 2009-03-24 21:02:01 | [diff] [blame] | 640 | |
| 641 | int64 total_bytes_avail = stream.Available(); |
| 642 | EXPECT_EQ(file_size, total_bytes_avail); |
| 643 | |
[email protected] | 8effd3f6 | 2011-03-25 16:29:07 | [diff] [blame] | 644 | int64 offset = stream.Seek(FROM_END, 0); |
[email protected] | 4c2048a | 2009-03-24 21:02:01 | [diff] [blame] | 645 | EXPECT_EQ(offset, file_size); |
| 646 | |
[email protected] | 5eb431e2 | 2011-10-12 08:51:38 | [diff] [blame^] | 647 | TestCompletionCallback callback; |
[email protected] | 4c2048a | 2009-03-24 21:02:01 | [diff] [blame] | 648 | int total_bytes_written = 0; |
| 649 | |
| 650 | while (total_bytes_written != kTestDataSize) { |
| 651 | rv = stream.Write(kTestData + total_bytes_written, |
| 652 | kTestDataSize - total_bytes_written, |
[email protected] | 5eb431e2 | 2011-10-12 08:51:38 | [diff] [blame^] | 653 | callback.callback()); |
[email protected] | 8effd3f6 | 2011-03-25 16:29:07 | [diff] [blame] | 654 | if (rv == ERR_IO_PENDING) |
[email protected] | 4c2048a | 2009-03-24 21:02:01 | [diff] [blame] | 655 | rv = callback.WaitForResult(); |
| 656 | EXPECT_LT(0, rv); |
| 657 | if (rv <= 0) |
| 658 | break; |
| 659 | total_bytes_written += rv; |
| 660 | } |
| 661 | |
| 662 | EXPECT_EQ(kTestDataSize, total_bytes_written); |
| 663 | |
[email protected] | 8effd3f6 | 2011-03-25 16:29:07 | [diff] [blame] | 664 | offset = stream.Seek(FROM_BEGIN, 0); |
[email protected] | 4c2048a | 2009-03-24 21:02:01 | [diff] [blame] | 665 | EXPECT_EQ(0, offset); |
| 666 | |
| 667 | int total_bytes_read = 0; |
| 668 | |
| 669 | std::string data_read; |
| 670 | for (;;) { |
| 671 | char buf[4]; |
[email protected] | 5eb431e2 | 2011-10-12 08:51:38 | [diff] [blame^] | 672 | rv = stream.Read(buf, arraysize(buf), callback.callback()); |
[email protected] | 8effd3f6 | 2011-03-25 16:29:07 | [diff] [blame] | 673 | if (rv == ERR_IO_PENDING) |
[email protected] | 4c2048a | 2009-03-24 21:02:01 | [diff] [blame] | 674 | rv = callback.WaitForResult(); |
| 675 | EXPECT_LE(0, rv); |
| 676 | if (rv <= 0) |
| 677 | break; |
| 678 | total_bytes_read += rv; |
| 679 | data_read.append(buf, rv); |
| 680 | } |
| 681 | stream.Close(); |
| 682 | |
| 683 | ok = file_util::GetFileSize(temp_file_path(), &file_size); |
| 684 | EXPECT_TRUE(ok); |
| 685 | EXPECT_EQ(kTestDataSize * 2, file_size); |
| 686 | |
| 687 | EXPECT_EQ(kTestDataSize * 2, total_bytes_read); |
| 688 | const std::string kExpectedFileData = |
| 689 | std::string(kTestData) + std::string(kTestData); |
| 690 | EXPECT_EQ(kExpectedFileData, data_read); |
| 691 | } |
| 692 | |
[email protected] | 5eb431e2 | 2011-10-12 08:51:38 | [diff] [blame^] | 693 | class TestWriteReadCompletionCallback { |
[email protected] | 4c2048a | 2009-03-24 21:02:01 | [diff] [blame] | 694 | public: |
[email protected] | 5eb431e2 | 2011-10-12 08:51:38 | [diff] [blame^] | 695 | TestWriteReadCompletionCallback( |
[email protected] | 8effd3f6 | 2011-03-25 16:29:07 | [diff] [blame] | 696 | FileStream* stream, |
[email protected] | 4c2048a | 2009-03-24 21:02:01 | [diff] [blame] | 697 | int* total_bytes_written, |
| 698 | int* total_bytes_read, |
| 699 | std::string* data_read) |
| 700 | : result_(0), |
| 701 | have_result_(false), |
| 702 | waiting_for_result_(false), |
| 703 | stream_(stream), |
| 704 | total_bytes_written_(total_bytes_written), |
| 705 | total_bytes_read_(total_bytes_read), |
[email protected] | 5eb431e2 | 2011-10-12 08:51:38 | [diff] [blame^] | 706 | data_read_(data_read), |
| 707 | callback_(base::Bind(&TestWriteReadCompletionCallback::OnComplete, |
| 708 | base::Unretained(this))) {} |
[email protected] | 4c2048a | 2009-03-24 21:02:01 | [diff] [blame] | 709 | |
| 710 | int WaitForResult() { |
| 711 | DCHECK(!waiting_for_result_); |
| 712 | while (!have_result_) { |
| 713 | waiting_for_result_ = true; |
| 714 | MessageLoop::current()->Run(); |
| 715 | waiting_for_result_ = false; |
| 716 | } |
| 717 | have_result_ = false; // auto-reset for next callback |
| 718 | return result_; |
| 719 | } |
| 720 | |
[email protected] | 5eb431e2 | 2011-10-12 08:51:38 | [diff] [blame^] | 721 | const CompletionCallback& callback() const { return callback_; } |
| 722 | |
[email protected] | 4c2048a | 2009-03-24 21:02:01 | [diff] [blame] | 723 | private: |
[email protected] | 5eb431e2 | 2011-10-12 08:51:38 | [diff] [blame^] | 724 | void OnComplete(int result) { |
| 725 | DCHECK_LT(0, result); |
| 726 | *total_bytes_written_ += result; |
[email protected] | 4c2048a | 2009-03-24 21:02:01 | [diff] [blame] | 727 | |
| 728 | int rv; |
| 729 | |
| 730 | if (*total_bytes_written_ != kTestDataSize) { |
| 731 | // Recurse to finish writing all data. |
| 732 | int total_bytes_written = 0, total_bytes_read = 0; |
| 733 | std::string data_read; |
[email protected] | 5eb431e2 | 2011-10-12 08:51:38 | [diff] [blame^] | 734 | TestWriteReadCompletionCallback callback( |
[email protected] | 4c2048a | 2009-03-24 21:02:01 | [diff] [blame] | 735 | stream_, &total_bytes_written, &total_bytes_read, &data_read); |
| 736 | rv = stream_->Write(kTestData + *total_bytes_written_, |
| 737 | kTestDataSize - *total_bytes_written_, |
[email protected] | 5eb431e2 | 2011-10-12 08:51:38 | [diff] [blame^] | 738 | callback.callback()); |
[email protected] | 8effd3f6 | 2011-03-25 16:29:07 | [diff] [blame] | 739 | DCHECK_EQ(ERR_IO_PENDING, rv); |
[email protected] | 4c2048a | 2009-03-24 21:02:01 | [diff] [blame] | 740 | rv = callback.WaitForResult(); |
| 741 | *total_bytes_written_ += total_bytes_written; |
| 742 | *total_bytes_read_ += total_bytes_read; |
| 743 | *data_read_ += data_read; |
| 744 | } else { // We're done writing all data. Start reading the data. |
[email protected] | 8effd3f6 | 2011-03-25 16:29:07 | [diff] [blame] | 745 | stream_->Seek(FROM_BEGIN, 0); |
[email protected] | 4c2048a | 2009-03-24 21:02:01 | [diff] [blame] | 746 | |
[email protected] | 5eb431e2 | 2011-10-12 08:51:38 | [diff] [blame^] | 747 | TestCompletionCallback callback; |
[email protected] | 4c2048a | 2009-03-24 21:02:01 | [diff] [blame] | 748 | for (;;) { |
| 749 | char buf[4]; |
[email protected] | 5eb431e2 | 2011-10-12 08:51:38 | [diff] [blame^] | 750 | rv = stream_->Read(buf, arraysize(buf), callback.callback()); |
[email protected] | 8effd3f6 | 2011-03-25 16:29:07 | [diff] [blame] | 751 | if (rv == ERR_IO_PENDING) { |
[email protected] | 4c2048a | 2009-03-24 21:02:01 | [diff] [blame] | 752 | bool old_state = MessageLoop::current()->NestableTasksAllowed(); |
| 753 | MessageLoop::current()->SetNestableTasksAllowed(true); |
| 754 | rv = callback.WaitForResult(); |
| 755 | MessageLoop::current()->SetNestableTasksAllowed(old_state); |
| 756 | } |
| 757 | EXPECT_LE(0, rv); |
| 758 | if (rv <= 0) |
| 759 | break; |
| 760 | *total_bytes_read_ += rv; |
| 761 | data_read_->append(buf, rv); |
| 762 | } |
| 763 | } |
| 764 | |
| 765 | result_ = *total_bytes_written_; |
| 766 | have_result_ = true; |
| 767 | if (waiting_for_result_) |
| 768 | MessageLoop::current()->Quit(); |
| 769 | } |
| 770 | |
| 771 | int result_; |
| 772 | bool have_result_; |
| 773 | bool waiting_for_result_; |
[email protected] | 8effd3f6 | 2011-03-25 16:29:07 | [diff] [blame] | 774 | FileStream* stream_; |
[email protected] | 4c2048a | 2009-03-24 21:02:01 | [diff] [blame] | 775 | int* total_bytes_written_; |
| 776 | int* total_bytes_read_; |
| 777 | std::string* data_read_; |
[email protected] | 5eb431e2 | 2011-10-12 08:51:38 | [diff] [blame^] | 778 | const CompletionCallback callback_; |
[email protected] | 4c2048a | 2009-03-24 21:02:01 | [diff] [blame] | 779 | |
[email protected] | 5eb431e2 | 2011-10-12 08:51:38 | [diff] [blame^] | 780 | DISALLOW_COPY_AND_ASSIGN(TestWriteReadCompletionCallback); |
[email protected] | 4c2048a | 2009-03-24 21:02:01 | [diff] [blame] | 781 | }; |
| 782 | |
| 783 | TEST_F(FileStreamTest, AsyncWriteRead) { |
| 784 | int64 file_size; |
| 785 | bool ok = file_util::GetFileSize(temp_file_path(), &file_size); |
| 786 | EXPECT_TRUE(ok); |
| 787 | |
[email protected] | 8effd3f6 | 2011-03-25 16:29:07 | [diff] [blame] | 788 | FileStream stream; |
[email protected] | 4c2048a | 2009-03-24 21:02:01 | [diff] [blame] | 789 | int flags = base::PLATFORM_FILE_OPEN | |
| 790 | base::PLATFORM_FILE_READ | |
| 791 | base::PLATFORM_FILE_WRITE | |
| 792 | base::PLATFORM_FILE_ASYNC; |
| 793 | int rv = stream.Open(temp_file_path(), flags); |
[email protected] | 8effd3f6 | 2011-03-25 16:29:07 | [diff] [blame] | 794 | EXPECT_EQ(OK, rv); |
[email protected] | 4c2048a | 2009-03-24 21:02:01 | [diff] [blame] | 795 | |
| 796 | int64 total_bytes_avail = stream.Available(); |
| 797 | EXPECT_EQ(file_size, total_bytes_avail); |
| 798 | |
[email protected] | 8effd3f6 | 2011-03-25 16:29:07 | [diff] [blame] | 799 | int64 offset = stream.Seek(FROM_END, 0); |
[email protected] | 4c2048a | 2009-03-24 21:02:01 | [diff] [blame] | 800 | EXPECT_EQ(offset, file_size); |
| 801 | |
| 802 | int total_bytes_written = 0; |
| 803 | int total_bytes_read = 0; |
| 804 | std::string data_read; |
[email protected] | 5eb431e2 | 2011-10-12 08:51:38 | [diff] [blame^] | 805 | TestWriteReadCompletionCallback callback(&stream, &total_bytes_written, |
[email protected] | 4c2048a | 2009-03-24 21:02:01 | [diff] [blame] | 806 | &total_bytes_read, &data_read); |
| 807 | |
| 808 | rv = stream.Write(kTestData + total_bytes_written, |
| 809 | kTestDataSize - static_cast<int>(total_bytes_written), |
[email protected] | 5eb431e2 | 2011-10-12 08:51:38 | [diff] [blame^] | 810 | callback.callback()); |
[email protected] | 8effd3f6 | 2011-03-25 16:29:07 | [diff] [blame] | 811 | if (rv == ERR_IO_PENDING) |
[email protected] | 4c2048a | 2009-03-24 21:02:01 | [diff] [blame] | 812 | rv = callback.WaitForResult(); |
| 813 | EXPECT_LT(0, rv); |
| 814 | EXPECT_EQ(kTestDataSize, total_bytes_written); |
| 815 | |
| 816 | stream.Close(); |
| 817 | |
| 818 | ok = file_util::GetFileSize(temp_file_path(), &file_size); |
| 819 | EXPECT_TRUE(ok); |
| 820 | EXPECT_EQ(kTestDataSize * 2, file_size); |
| 821 | |
| 822 | EXPECT_EQ(kTestDataSize * 2, total_bytes_read); |
| 823 | const std::string kExpectedFileData = |
| 824 | std::string(kTestData) + std::string(kTestData); |
| 825 | EXPECT_EQ(kExpectedFileData, data_read); |
| 826 | } |
| 827 | |
[email protected] | 5eb431e2 | 2011-10-12 08:51:38 | [diff] [blame^] | 828 | class TestWriteCloseCompletionCallback { |
[email protected] | 4c2048a | 2009-03-24 21:02:01 | [diff] [blame] | 829 | public: |
[email protected] | 5eb431e2 | 2011-10-12 08:51:38 | [diff] [blame^] | 830 | TestWriteCloseCompletionCallback(FileStream* stream, int* total_bytes_written) |
[email protected] | 4c2048a | 2009-03-24 21:02:01 | [diff] [blame] | 831 | : result_(0), |
| 832 | have_result_(false), |
| 833 | waiting_for_result_(false), |
| 834 | stream_(stream), |
[email protected] | 5eb431e2 | 2011-10-12 08:51:38 | [diff] [blame^] | 835 | total_bytes_written_(total_bytes_written), |
| 836 | callback_(base::Bind(&TestWriteCloseCompletionCallback::OnComplete, |
| 837 | base::Unretained(this))) {} |
[email protected] | 4c2048a | 2009-03-24 21:02:01 | [diff] [blame] | 838 | |
| 839 | int WaitForResult() { |
| 840 | DCHECK(!waiting_for_result_); |
| 841 | while (!have_result_) { |
| 842 | waiting_for_result_ = true; |
| 843 | MessageLoop::current()->Run(); |
| 844 | waiting_for_result_ = false; |
| 845 | } |
| 846 | have_result_ = false; // auto-reset for next callback |
| 847 | return result_; |
| 848 | } |
| 849 | |
[email protected] | 5eb431e2 | 2011-10-12 08:51:38 | [diff] [blame^] | 850 | const CompletionCallback& callback() const { return callback_; } |
| 851 | |
[email protected] | 4c2048a | 2009-03-24 21:02:01 | [diff] [blame] | 852 | private: |
[email protected] | 5eb431e2 | 2011-10-12 08:51:38 | [diff] [blame^] | 853 | void OnComplete(int result) { |
| 854 | DCHECK_LT(0, result); |
| 855 | *total_bytes_written_ += result; |
[email protected] | 4c2048a | 2009-03-24 21:02:01 | [diff] [blame] | 856 | |
| 857 | int rv; |
| 858 | |
| 859 | if (*total_bytes_written_ != kTestDataSize) { |
| 860 | // Recurse to finish writing all data. |
| 861 | int total_bytes_written = 0; |
[email protected] | 5eb431e2 | 2011-10-12 08:51:38 | [diff] [blame^] | 862 | TestWriteCloseCompletionCallback callback(stream_, &total_bytes_written); |
[email protected] | 4c2048a | 2009-03-24 21:02:01 | [diff] [blame] | 863 | rv = stream_->Write(kTestData + *total_bytes_written_, |
| 864 | kTestDataSize - *total_bytes_written_, |
[email protected] | 5eb431e2 | 2011-10-12 08:51:38 | [diff] [blame^] | 865 | callback.callback()); |
[email protected] | 8effd3f6 | 2011-03-25 16:29:07 | [diff] [blame] | 866 | DCHECK_EQ(ERR_IO_PENDING, rv); |
[email protected] | 4c2048a | 2009-03-24 21:02:01 | [diff] [blame] | 867 | rv = callback.WaitForResult(); |
| 868 | *total_bytes_written_ += total_bytes_written; |
| 869 | } else { // We're done writing all data. Close the file. |
| 870 | stream_->Close(); |
| 871 | } |
| 872 | |
| 873 | result_ = *total_bytes_written_; |
| 874 | have_result_ = true; |
| 875 | if (waiting_for_result_) |
| 876 | MessageLoop::current()->Quit(); |
| 877 | } |
| 878 | |
| 879 | int result_; |
| 880 | bool have_result_; |
| 881 | bool waiting_for_result_; |
[email protected] | 8effd3f6 | 2011-03-25 16:29:07 | [diff] [blame] | 882 | FileStream* stream_; |
[email protected] | 4c2048a | 2009-03-24 21:02:01 | [diff] [blame] | 883 | int* total_bytes_written_; |
[email protected] | 5eb431e2 | 2011-10-12 08:51:38 | [diff] [blame^] | 884 | const CompletionCallback callback_; |
[email protected] | 4c2048a | 2009-03-24 21:02:01 | [diff] [blame] | 885 | |
[email protected] | 5eb431e2 | 2011-10-12 08:51:38 | [diff] [blame^] | 886 | DISALLOW_COPY_AND_ASSIGN(TestWriteCloseCompletionCallback); |
[email protected] | 4c2048a | 2009-03-24 21:02:01 | [diff] [blame] | 887 | }; |
| 888 | |
| 889 | TEST_F(FileStreamTest, AsyncWriteClose) { |
| 890 | int64 file_size; |
| 891 | bool ok = file_util::GetFileSize(temp_file_path(), &file_size); |
| 892 | EXPECT_TRUE(ok); |
| 893 | |
[email protected] | 8effd3f6 | 2011-03-25 16:29:07 | [diff] [blame] | 894 | FileStream stream; |
[email protected] | 4c2048a | 2009-03-24 21:02:01 | [diff] [blame] | 895 | int flags = base::PLATFORM_FILE_OPEN | |
| 896 | base::PLATFORM_FILE_READ | |
| 897 | base::PLATFORM_FILE_WRITE | |
| 898 | base::PLATFORM_FILE_ASYNC; |
| 899 | int rv = stream.Open(temp_file_path(), flags); |
[email protected] | 8effd3f6 | 2011-03-25 16:29:07 | [diff] [blame] | 900 | EXPECT_EQ(OK, rv); |
[email protected] | 4c2048a | 2009-03-24 21:02:01 | [diff] [blame] | 901 | |
| 902 | int64 total_bytes_avail = stream.Available(); |
| 903 | EXPECT_EQ(file_size, total_bytes_avail); |
| 904 | |
[email protected] | 8effd3f6 | 2011-03-25 16:29:07 | [diff] [blame] | 905 | int64 offset = stream.Seek(FROM_END, 0); |
[email protected] | 4c2048a | 2009-03-24 21:02:01 | [diff] [blame] | 906 | EXPECT_EQ(offset, file_size); |
| 907 | |
| 908 | int total_bytes_written = 0; |
[email protected] | 5eb431e2 | 2011-10-12 08:51:38 | [diff] [blame^] | 909 | TestWriteCloseCompletionCallback callback(&stream, &total_bytes_written); |
[email protected] | 4c2048a | 2009-03-24 21:02:01 | [diff] [blame] | 910 | |
[email protected] | 5eb431e2 | 2011-10-12 08:51:38 | [diff] [blame^] | 911 | rv = stream.Write(kTestData, kTestDataSize, callback.callback()); |
[email protected] | 8effd3f6 | 2011-03-25 16:29:07 | [diff] [blame] | 912 | if (rv == ERR_IO_PENDING) |
[email protected] | 4c2048a | 2009-03-24 21:02:01 | [diff] [blame] | 913 | total_bytes_written = callback.WaitForResult(); |
| 914 | EXPECT_LT(0, total_bytes_written); |
| 915 | EXPECT_EQ(kTestDataSize, total_bytes_written); |
| 916 | |
| 917 | ok = file_util::GetFileSize(temp_file_path(), &file_size); |
| 918 | EXPECT_TRUE(ok); |
| 919 | EXPECT_EQ(kTestDataSize * 2, file_size); |
| 920 | } |
| 921 | |
[email protected] | 0643a49 | 2009-03-09 15:49:20 | [diff] [blame] | 922 | // Tests truncating a file. |
| 923 | TEST_F(FileStreamTest, Truncate) { |
| 924 | int flags = base::PLATFORM_FILE_CREATE_ALWAYS | base::PLATFORM_FILE_WRITE; |
| 925 | |
[email protected] | 8effd3f6 | 2011-03-25 16:29:07 | [diff] [blame] | 926 | FileStream write_stream; |
| 927 | ASSERT_EQ(OK, write_stream.Open(temp_file_path(), flags)); |
[email protected] | 0643a49 | 2009-03-09 15:49:20 | [diff] [blame] | 928 | |
| 929 | // Write some data to the file. |
| 930 | const char test_data[] = "0123456789"; |
[email protected] | 5eb431e2 | 2011-10-12 08:51:38 | [diff] [blame^] | 931 | write_stream.Write(test_data, arraysize(test_data), CompletionCallback()); |
[email protected] | 0643a49 | 2009-03-09 15:49:20 | [diff] [blame] | 932 | |
| 933 | // Truncate the file. |
| 934 | ASSERT_EQ(4, write_stream.Truncate(4)); |
| 935 | |
| 936 | // Write again. |
[email protected] | 5eb431e2 | 2011-10-12 08:51:38 | [diff] [blame^] | 937 | write_stream.Write(test_data, 4, CompletionCallback()); |
[email protected] | 0643a49 | 2009-03-09 15:49:20 | [diff] [blame] | 938 | |
| 939 | // Close the stream. |
| 940 | write_stream.Close(); |
| 941 | |
| 942 | // Read in the contents and make sure we get back what we expected. |
| 943 | std::string read_contents; |
[email protected] | 3fc364f9 | 2009-08-06 22:35:13 | [diff] [blame] | 944 | EXPECT_TRUE(file_util::ReadFileToString(temp_file_path(), &read_contents)); |
[email protected] | 0643a49 | 2009-03-09 15:49:20 | [diff] [blame] | 945 | |
[email protected] | 4c2048a | 2009-03-24 21:02:01 | [diff] [blame] | 946 | EXPECT_EQ("01230123", read_contents); |
[email protected] | 0643a49 | 2009-03-09 15:49:20 | [diff] [blame] | 947 | } |
| 948 | |
[email protected] | 4c2048a | 2009-03-24 21:02:01 | [diff] [blame] | 949 | } // namespace |
[email protected] | 96d7382 | 2011-10-10 02:11:24 | [diff] [blame] | 950 | |
[email protected] | 8effd3f6 | 2011-03-25 16:29:07 | [diff] [blame] | 951 | } // namespace net |