| OLD | NEW |
| 1 // Copyright (c) 2008 The Chromium Authors. All rights reserved. Use of this | 1 // Copyright (c) 2008 The Chromium Authors. All rights reserved. Use of this |
| 2 // source code is governed by a BSD-style license that can be found in the | 2 // source code is governed by a BSD-style license that can be found in the |
| 3 // LICENSE file. | 3 // LICENSE file. |
| 4 | 4 |
| 5 #include "base/file_util.h" | 5 #include "base/file_util.h" |
| 6 #include "base/path_service.h" | 6 #include "base/path_service.h" |
| 7 #include "net/base/file_stream.h" | 7 #include "net/base/file_stream.h" |
| 8 #include "net/base/net_errors.h" | 8 #include "net/base/net_errors.h" |
| 9 #include "net/base/test_completion_callback.h" | 9 #include "net/base/test_completion_callback.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
| 11 #include "testing/platform_test.h" | 11 #include "testing/platform_test.h" |
| 12 | 12 |
| 13 static const char kTestData[] = "0123456789"; | 13 static const char kTestData[] = "0123456789"; |
| 14 static const int kTestDataSize = arraysize(kTestData) - 1; | 14 static const int kTestDataSize = arraysize(kTestData) - 1; |
| 15 | 15 |
| 16 class FileStreamTest : public PlatformTest { | 16 class FileStreamTest : public PlatformTest { |
| 17 public: | 17 public: |
| 18 virtual void SetUp() { | 18 virtual void SetUp() { |
| 19 PlatformTest::SetUp(); | 19 PlatformTest::SetUp(); |
| 20 | 20 |
| 21 file_util::CreateTemporaryFileName(&temp_file_path_); | 21 file_util::CreateTemporaryFileName(&temp_file_path_); |
| 22 file_util::WriteFile(temp_file_path_, kTestData, kTestDataSize); | 22 file_util::WriteFile(temp_file_path_.ToWStringHack(), |
| 23 kTestData, kTestDataSize); |
| 23 } | 24 } |
| 24 virtual void TearDown() { | 25 virtual void TearDown() { |
| 25 file_util::Delete(temp_file_path_, false); | 26 file_util::Delete(temp_file_path_, false); |
| 26 | 27 |
| 27 PlatformTest::TearDown(); | 28 PlatformTest::TearDown(); |
| 28 } | 29 } |
| 29 const std::wstring temp_file_path() const { return temp_file_path_; } | 30 const FilePath temp_file_path() const { return temp_file_path_; } |
| 30 private: | 31 private: |
| 31 std::wstring temp_file_path_; | 32 FilePath temp_file_path_; |
| 32 }; | 33 }; |
| 33 | 34 |
| 34 TEST_F(FileStreamTest, BasicOpenClose) { | 35 TEST_F(FileStreamTest, BasicOpenClose) { |
| 35 net::FileStream stream; | 36 net::FileStream stream; |
| 36 int rv = stream.Open(temp_file_path(), | 37 int rv = stream.Open(temp_file_path(), |
| 37 base::PLATFORM_FILE_OPEN | base::PLATFORM_FILE_READ); | 38 base::PLATFORM_FILE_OPEN | base::PLATFORM_FILE_READ); |
| 38 EXPECT_EQ(net::OK, rv); | 39 EXPECT_EQ(net::OK, rv); |
| 39 } | 40 } |
| 40 | 41 |
| 41 TEST_F(FileStreamTest, UseClosedStream) { | 42 TEST_F(FileStreamTest, UseClosedStream) { |
| (...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 360 rv = stream.Write(kTestData, kTestDataSize, NULL); | 361 rv = stream.Write(kTestData, kTestDataSize, NULL); |
| 361 EXPECT_EQ(kTestDataSize, rv); | 362 EXPECT_EQ(kTestDataSize, rv); |
| 362 stream.Close(); | 363 stream.Close(); |
| 363 | 364 |
| 364 ok = file_util::GetFileSize(temp_file_path(), &file_size); | 365 ok = file_util::GetFileSize(temp_file_path(), &file_size); |
| 365 EXPECT_TRUE(ok); | 366 EXPECT_TRUE(ok); |
| 366 EXPECT_EQ(kTestDataSize * 2, file_size); | 367 EXPECT_EQ(kTestDataSize * 2, file_size); |
| 367 } | 368 } |
| 368 | 369 |
| 369 // TODO(erikkay): more READ_WRITE tests? | 370 // TODO(erikkay): more READ_WRITE tests? |
| OLD | NEW |