OLD | NEW |
1 // Copyright (c) 2010 The Chromium OS Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium OS 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 <gtest/gtest.h> | 6 #include <gtest/gtest.h> |
7 | 7 |
8 #include "update_engine/action_mock.h" | 8 #include "update_engine/action_mock.h" |
9 #include "update_engine/action_processor_mock.h" | 9 #include "update_engine/action_processor_mock.h" |
10 #include "update_engine/filesystem_copier_action.h" | 10 #include "update_engine/filesystem_copier_action.h" |
11 #include "update_engine/postinstall_runner_action.h" | 11 #include "update_engine/postinstall_runner_action.h" |
12 #include "update_engine/prefs_mock.h" | 12 #include "update_engine/prefs_mock.h" |
13 #include "update_engine/update_attempter.h" | 13 #include "update_engine/update_attempter.h" |
14 | 14 |
15 using std::string; | 15 using std::string; |
16 using testing::_; | 16 using testing::_; |
17 using testing::DoAll; | 17 using testing::DoAll; |
18 using testing::InSequence; | 18 using testing::InSequence; |
19 using testing::Ne; | 19 using testing::Ne; |
| 20 using testing::NiceMock; |
20 using testing::Property; | 21 using testing::Property; |
21 using testing::Return; | 22 using testing::Return; |
22 using testing::SetArgumentPointee; | 23 using testing::SetArgumentPointee; |
23 | 24 |
24 namespace chromeos_update_engine { | 25 namespace chromeos_update_engine { |
25 | 26 |
26 // Test a subclass rather than the main class directly so that we can mock out | 27 // Test a subclass rather than the main class directly so that we can mock out |
27 // methods within the class. There're explicit unit tests for the mocked out | 28 // methods within the class. There're explicit unit tests for the mocked out |
28 // methods. | 29 // methods. |
29 class UpdateAttempterUnderTest : public UpdateAttempter { | 30 class UpdateAttempterUnderTest : public UpdateAttempter { |
(...skipping 19 matching lines...) Expand all Loading... |
49 EXPECT_EQ("0.0.0.0", attempter_.new_version_); | 50 EXPECT_EQ("0.0.0.0", attempter_.new_version_); |
50 EXPECT_EQ(0, attempter_.new_size_); | 51 EXPECT_EQ(0, attempter_.new_size_); |
51 EXPECT_FALSE(attempter_.is_full_update_); | 52 EXPECT_FALSE(attempter_.is_full_update_); |
52 processor_ = new ActionProcessorMock(); | 53 processor_ = new ActionProcessorMock(); |
53 attempter_.processor_.reset(processor_); // Transfers ownership. | 54 attempter_.processor_.reset(processor_); // Transfers ownership. |
54 attempter_.prefs_ = &prefs_; | 55 attempter_.prefs_ = &prefs_; |
55 } | 56 } |
56 | 57 |
57 UpdateAttempterUnderTest attempter_; | 58 UpdateAttempterUnderTest attempter_; |
58 ActionProcessorMock* processor_; | 59 ActionProcessorMock* processor_; |
59 PrefsMock prefs_; | 60 NiceMock<PrefsMock> prefs_; |
60 }; | 61 }; |
61 | 62 |
62 TEST_F(UpdateAttempterTest, RunAsRootConstructWithUpdatedMarkerTest) { | 63 TEST_F(UpdateAttempterTest, RunAsRootConstructWithUpdatedMarkerTest) { |
63 extern const char* kUpdateCompletedMarker; | 64 extern const char* kUpdateCompletedMarker; |
64 const FilePath kMarker(kUpdateCompletedMarker); | 65 const FilePath kMarker(kUpdateCompletedMarker); |
65 EXPECT_EQ(0, file_util::WriteFile(kMarker, "", 0)); | 66 EXPECT_EQ(0, file_util::WriteFile(kMarker, "", 0)); |
66 UpdateAttempterUnderTest attempter; | 67 UpdateAttempterUnderTest attempter; |
67 EXPECT_EQ(UPDATE_STATUS_UPDATED_NEED_REBOOT, attempter.status()); | 68 EXPECT_EQ(UPDATE_STATUS_UPDATED_NEED_REBOOT, attempter.status()); |
68 EXPECT_TRUE(file_util::Delete(kMarker, false)); | 69 EXPECT_TRUE(file_util::Delete(kMarker, false)); |
69 } | 70 } |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
191 EXPECT_EQ(attempter_.response_handler_action_.get(), | 192 EXPECT_EQ(attempter_.response_handler_action_.get(), |
192 attempter_.actions_[1].get()); | 193 attempter_.actions_[1].get()); |
193 DownloadAction* download_action = | 194 DownloadAction* download_action = |
194 dynamic_cast<DownloadAction*>(attempter_.actions_[5].get()); | 195 dynamic_cast<DownloadAction*>(attempter_.actions_[5].get()); |
195 ASSERT_TRUE(download_action != NULL); | 196 ASSERT_TRUE(download_action != NULL); |
196 EXPECT_EQ(&attempter_, download_action->delegate()); | 197 EXPECT_EQ(&attempter_, download_action->delegate()); |
197 EXPECT_EQ(UPDATE_STATUS_CHECKING_FOR_UPDATE, attempter_.status()); | 198 EXPECT_EQ(UPDATE_STATUS_CHECKING_FOR_UPDATE, attempter_.status()); |
198 } | 199 } |
199 | 200 |
200 } // namespace chromeos_update_engine | 201 } // namespace chromeos_update_engine |
OLD | NEW |