| 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/set_bootable_flag_action.h" | 13 #include "update_engine/set_bootable_flag_action.h" |
| 14 #include "update_engine/update_attempter.h" | 14 #include "update_engine/update_attempter.h" |
| 15 | 15 |
| 16 using std::string; | 16 using std::string; |
| 17 using testing::_; | 17 using testing::_; |
| 18 using testing::DoAll; | 18 using testing::DoAll; |
| 19 using testing::InSequence; | 19 using testing::InSequence; |
| 20 using testing::Ne; |
| 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 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 124 | 125 |
| 125 TEST_F(UpdateAttempterTest, MarkDeltaUpdateFailureTest) { | 126 TEST_F(UpdateAttempterTest, MarkDeltaUpdateFailureTest) { |
| 126 attempter_.is_full_update_ = false; | 127 attempter_.is_full_update_ = false; |
| 127 EXPECT_CALL(prefs_, GetInt64(kPrefsDeltaUpdateFailures, _)) | 128 EXPECT_CALL(prefs_, GetInt64(kPrefsDeltaUpdateFailures, _)) |
| 128 .WillOnce(Return(false)) | 129 .WillOnce(Return(false)) |
| 129 .WillOnce(DoAll(SetArgumentPointee<1>(-1), Return(true))) | 130 .WillOnce(DoAll(SetArgumentPointee<1>(-1), Return(true))) |
| 130 .WillOnce(DoAll(SetArgumentPointee<1>(1), Return(true))) | 131 .WillOnce(DoAll(SetArgumentPointee<1>(1), Return(true))) |
| 131 .WillOnce(DoAll( | 132 .WillOnce(DoAll( |
| 132 SetArgumentPointee<1>(UpdateAttempter::kMaxDeltaUpdateFailures), | 133 SetArgumentPointee<1>(UpdateAttempter::kMaxDeltaUpdateFailures), |
| 133 Return(true))); | 134 Return(true))); |
| 135 EXPECT_CALL(prefs_, SetInt64(Ne(kPrefsDeltaUpdateFailures), _)) |
| 136 .WillRepeatedly(Return(true)); |
| 134 EXPECT_CALL(prefs_, SetInt64(kPrefsDeltaUpdateFailures, 1)).Times(2); | 137 EXPECT_CALL(prefs_, SetInt64(kPrefsDeltaUpdateFailures, 1)).Times(2); |
| 135 EXPECT_CALL(prefs_, SetInt64(kPrefsDeltaUpdateFailures, 2)).Times(1); | 138 EXPECT_CALL(prefs_, SetInt64(kPrefsDeltaUpdateFailures, 2)).Times(1); |
| 136 EXPECT_CALL(prefs_, SetInt64(kPrefsDeltaUpdateFailures, | 139 EXPECT_CALL(prefs_, SetInt64(kPrefsDeltaUpdateFailures, |
| 137 UpdateAttempter::kMaxDeltaUpdateFailures + 1)) | 140 UpdateAttempter::kMaxDeltaUpdateFailures + 1)) |
| 138 .Times(1); | 141 .Times(1); |
| 139 for (int i = 0; i < 4; i ++) | 142 for (int i = 0; i < 4; i ++) |
| 140 attempter_.MarkDeltaUpdateFailure(); | 143 attempter_.MarkDeltaUpdateFailure(); |
| 141 } | 144 } |
| 142 | 145 |
| 143 TEST_F(UpdateAttempterTest, UpdateStatusToStringTest) { | 146 TEST_F(UpdateAttempterTest, UpdateStatusToStringTest) { |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 195 EXPECT_EQ(attempter_.response_handler_action_.get(), | 198 EXPECT_EQ(attempter_.response_handler_action_.get(), |
| 196 attempter_.actions_[1].get()); | 199 attempter_.actions_[1].get()); |
| 197 DownloadAction* download_action = | 200 DownloadAction* download_action = |
| 198 dynamic_cast<DownloadAction*>(attempter_.actions_[5].get()); | 201 dynamic_cast<DownloadAction*>(attempter_.actions_[5].get()); |
| 199 ASSERT_TRUE(download_action != NULL); | 202 ASSERT_TRUE(download_action != NULL); |
| 200 EXPECT_EQ(&attempter_, download_action->delegate()); | 203 EXPECT_EQ(&attempter_, download_action->delegate()); |
| 201 EXPECT_EQ(UPDATE_STATUS_CHECKING_FOR_UPDATE, attempter_.status()); | 204 EXPECT_EQ(UPDATE_STATUS_CHECKING_FOR_UPDATE, attempter_.status()); |
| 202 } | 205 } |
| 203 | 206 |
| 204 } // namespace chromeos_update_engine | 207 } // namespace chromeos_update_engine |
| OLD | NEW |