OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 <string> | 5 #include <string> |
6 | 6 |
7 #include "base/files/file_util.h" | 7 #include "base/files/file_util.h" |
8 #include "base/files/scoped_temp_dir.h" | 8 #include "base/files/scoped_temp_dir.h" |
9 #include "base/run_loop.h" | 9 #include "base/run_loop.h" |
10 #include "chrome/utility/image_writer/error_messages.h" | 10 #include "chrome/utility/image_writer/error_messages.h" |
11 #include "chrome/utility/image_writer/image_writer.h" | 11 #include "chrome/utility/image_writer/image_writer.h" |
12 #include "chrome/utility/image_writer/image_writer_handler.h" | 12 #include "chrome/utility/image_writer/image_writer_handler.h" |
13 #include "testing/gmock/include/gmock/gmock.h" | 13 #include "testing/gmock/include/gmock/gmock.h" |
14 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
15 | 15 |
16 namespace image_writer { | 16 namespace image_writer { |
17 | 17 |
18 using testing::_; | 18 using testing::_; |
19 using testing::AnyNumber; | 19 using testing::AnyNumber; |
20 using testing::AtLeast; | 20 using testing::AtLeast; |
21 using testing::Lt; | 21 using testing::Lt; |
22 | 22 |
23 namespace { | 23 namespace { |
24 | 24 |
25 const int64 kTestFileSize = 1 << 15; // 32 kB | 25 const int64 kTestFileSize = 1 << 15; // 32 kB |
26 const int kTestPattern = 0x55555555; | 26 const int kTestPattern = 0x55555555; |
27 | 27 |
28 class ImageWriterUtilityTest : public testing::Test { | 28 class ImageWriterUtilityTest : public testing::Test { |
29 protected: | 29 protected: |
30 virtual void SetUp() OVERRIDE { | 30 virtual void SetUp() override { |
31 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | 31 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
32 ASSERT_TRUE(base::CreateTemporaryFileInDir(temp_dir_.path(), &image_path_)); | 32 ASSERT_TRUE(base::CreateTemporaryFileInDir(temp_dir_.path(), &image_path_)); |
33 ASSERT_TRUE( | 33 ASSERT_TRUE( |
34 base::CreateTemporaryFileInDir(temp_dir_.path(), &device_path_)); | 34 base::CreateTemporaryFileInDir(temp_dir_.path(), &device_path_)); |
35 } | 35 } |
36 | 36 |
37 virtual void TearDown() OVERRIDE {} | 37 virtual void TearDown() override {} |
38 | 38 |
39 void FillFile(const base::FilePath& path, int pattern) { | 39 void FillFile(const base::FilePath& path, int pattern) { |
40 scoped_ptr<char[]> buffer(new char[kTestFileSize]); | 40 scoped_ptr<char[]> buffer(new char[kTestFileSize]); |
41 memset(buffer.get(), pattern, kTestFileSize); | 41 memset(buffer.get(), pattern, kTestFileSize); |
42 | 42 |
43 ASSERT_TRUE(base::WriteFile(path, buffer.get(), kTestFileSize)); | 43 ASSERT_TRUE(base::WriteFile(path, buffer.get(), kTestFileSize)); |
44 } | 44 } |
45 | 45 |
46 void FillDefault(const base::FilePath& path) { FillFile(path, kTestPattern); } | 46 void FillDefault(const base::FilePath& path) { FillFile(path, kTestPattern); } |
47 | 47 |
(...skipping 12 matching lines...) Expand all Loading... |
60 MOCK_METHOD0(SendSucceeded, void()); | 60 MOCK_METHOD0(SendSucceeded, void()); |
61 MOCK_METHOD1(OnMessageReceived, bool(const IPC::Message& message)); | 61 MOCK_METHOD1(OnMessageReceived, bool(const IPC::Message& message)); |
62 }; | 62 }; |
63 | 63 |
64 // This Mock has the additional feature that it will start verification when | 64 // This Mock has the additional feature that it will start verification when |
65 // the write completes. | 65 // the write completes. |
66 class VerifyingHandler : public MockHandler { | 66 class VerifyingHandler : public MockHandler { |
67 public: | 67 public: |
68 VerifyingHandler() : image_writer_(NULL), verified_(false) {} | 68 VerifyingHandler() : image_writer_(NULL), verified_(false) {} |
69 | 69 |
70 virtual void SendSucceeded() OVERRIDE { | 70 virtual void SendSucceeded() override { |
71 MockHandler::SendSucceeded(); | 71 MockHandler::SendSucceeded(); |
72 if (!verified_) { | 72 if (!verified_) { |
73 image_writer_->Verify(); | 73 image_writer_->Verify(); |
74 verified_ = true; | 74 verified_ = true; |
75 } | 75 } |
76 } | 76 } |
77 ImageWriter* image_writer_; | 77 ImageWriter* image_writer_; |
78 | 78 |
79 private: | 79 private: |
80 bool verified_; | 80 bool verified_; |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
221 EXPECT_CALL(mock_handler, SendFailed(_)).Times(0); | 221 EXPECT_CALL(mock_handler, SendFailed(_)).Times(0); |
222 | 222 |
223 FillDefault(image_path_); | 223 FillDefault(image_path_); |
224 | 224 |
225 image_writer.Write(); | 225 image_writer.Write(); |
226 | 226 |
227 base::RunLoop().RunUntilIdle(); | 227 base::RunLoop().RunUntilIdle(); |
228 } | 228 } |
229 | 229 |
230 } // namespace image_writer | 230 } // namespace image_writer |
OLD | NEW |