Jay Srinivasan | 08fce04 | 2012-06-07 16:31:01 -0700 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium OS Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef CHROMEOS_PLATFORM_UPDATE_ENGINE_MOCK_SYSTEM_STATE_H__ |
| 6 | #define CHROMEOS_PLATFORM_UPDATE_ENGINE_MOCK_SYSTEM_STATE_H__ |
| 7 | |
| 8 | #include <gmock/gmock.h> |
| 9 | |
Jay Srinivasan | f057205 | 2012-10-23 18:12:56 -0700 | [diff] [blame] | 10 | #include <metrics/metrics_library_mock.h> |
Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 11 | #include <policy/mock_device_policy.h> |
Jay Srinivasan | f057205 | 2012-10-23 18:12:56 -0700 | [diff] [blame] | 12 | |
Jay Srinivasan | 55f50c2 | 2013-01-10 19:24:35 -0800 | [diff] [blame^] | 13 | #include "update_engine/mock_dbus_interface.h" |
Gilad Arnold | bf7919b | 2013-01-08 13:07:37 -0800 | [diff] [blame] | 14 | #include "update_engine/mock_gpio_handler.h" |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 15 | #include "update_engine/mock_payload_state.h" |
| 16 | #include "update_engine/prefs_mock.h" |
Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 17 | #include "update_engine/system_state.h" |
Jay Srinivasan | 08fce04 | 2012-06-07 16:31:01 -0700 | [diff] [blame] | 18 | |
| 19 | namespace chromeos_update_engine { |
| 20 | |
Jay Srinivasan | 55f50c2 | 2013-01-10 19:24:35 -0800 | [diff] [blame^] | 21 | class UpdateAttempterMock; |
| 22 | |
Jay Srinivasan | 08fce04 | 2012-06-07 16:31:01 -0700 | [diff] [blame] | 23 | // Mock the SystemStateInterface so that we could lie that |
| 24 | // OOBE is completed even when there's no such marker file, etc. |
| 25 | class MockSystemState : public SystemState { |
Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 26 | public: |
Jay Srinivasan | 55f50c2 | 2013-01-10 19:24:35 -0800 | [diff] [blame^] | 27 | MockSystemState(); |
| 28 | |
| 29 | virtual ~MockSystemState(); |
Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 30 | |
| 31 | MOCK_METHOD0(IsOOBEComplete, bool()); |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 32 | MOCK_METHOD1(set_device_policy, void(const policy::DevicePolicy*)); |
| 33 | MOCK_CONST_METHOD0(device_policy, const policy::DevicePolicy*()); |
Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 34 | |
Gilad Arnold | bf7919b | 2013-01-08 13:07:37 -0800 | [diff] [blame] | 35 | inline virtual ConnectionManager* connection_manager() { |
Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 36 | return connection_manager_; |
| 37 | } |
| 38 | |
Gilad Arnold | bf7919b | 2013-01-08 13:07:37 -0800 | [diff] [blame] | 39 | inline virtual MetricsLibraryInterface* metrics_lib() { |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 40 | return &mock_metrics_lib_; |
Jay Srinivasan | f057205 | 2012-10-23 18:12:56 -0700 | [diff] [blame] | 41 | } |
| 42 | |
Gilad Arnold | bf7919b | 2013-01-08 13:07:37 -0800 | [diff] [blame] | 43 | inline virtual PrefsInterface* prefs() { |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 44 | return prefs_; |
| 45 | } |
| 46 | |
Gilad Arnold | bf7919b | 2013-01-08 13:07:37 -0800 | [diff] [blame] | 47 | inline virtual PayloadStateInterface* payload_state() { |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 48 | return &mock_payload_state_; |
| 49 | } |
| 50 | |
Gilad Arnold | bf7919b | 2013-01-08 13:07:37 -0800 | [diff] [blame] | 51 | inline virtual GpioHandler* gpio_handler() const { |
| 52 | return mock_gpio_handler_; |
| 53 | } |
| 54 | |
Jay Srinivasan | 55f50c2 | 2013-01-10 19:24:35 -0800 | [diff] [blame^] | 55 | virtual UpdateAttempter* update_attempter(); |
| 56 | |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 57 | // MockSystemState-specific public method. |
Gilad Arnold | bf7919b | 2013-01-08 13:07:37 -0800 | [diff] [blame] | 58 | inline void set_connection_manager(ConnectionManager* connection_manager) { |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 59 | connection_manager_ = connection_manager; |
| 60 | } |
| 61 | |
Gilad Arnold | bf7919b | 2013-01-08 13:07:37 -0800 | [diff] [blame] | 62 | inline MetricsLibraryMock* mock_metrics_lib() { |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 63 | return &mock_metrics_lib_; |
| 64 | } |
| 65 | |
Gilad Arnold | bf7919b | 2013-01-08 13:07:37 -0800 | [diff] [blame] | 66 | inline void set_prefs(PrefsInterface* prefs) { |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 67 | prefs_ = prefs; |
| 68 | } |
| 69 | |
Gilad Arnold | bf7919b | 2013-01-08 13:07:37 -0800 | [diff] [blame] | 70 | inline testing::NiceMock<PrefsMock> *mock_prefs() { |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 71 | return &mock_prefs_; |
| 72 | } |
| 73 | |
Gilad Arnold | bf7919b | 2013-01-08 13:07:37 -0800 | [diff] [blame] | 74 | inline MockPayloadState* mock_payload_state() { |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 75 | return &mock_payload_state_; |
| 76 | } |
Jay Srinivasan | f057205 | 2012-10-23 18:12:56 -0700 | [diff] [blame] | 77 | |
Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 78 | private: |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 79 | // These are Mock objects or objects we own. |
Jay Srinivasan | 55f50c2 | 2013-01-10 19:24:35 -0800 | [diff] [blame^] | 80 | testing::NiceMock<MetricsLibraryMock> mock_metrics_lib_; |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 81 | testing::NiceMock<PrefsMock> mock_prefs_; |
Jay Srinivasan | 2b5a0f0 | 2012-12-19 17:25:56 -0800 | [diff] [blame] | 82 | testing::NiceMock<MockPayloadState> mock_payload_state_; |
Gilad Arnold | bf7919b | 2013-01-08 13:07:37 -0800 | [diff] [blame] | 83 | testing::NiceMock<MockGpioHandler>* mock_gpio_handler_; |
Jay Srinivasan | 55f50c2 | 2013-01-10 19:24:35 -0800 | [diff] [blame^] | 84 | testing::NiceMock<UpdateAttempterMock>* mock_update_attempter_; |
| 85 | |
| 86 | MockDbusGlib dbus_; |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 87 | |
| 88 | // These are pointers to objects which caller can override. |
| 89 | PrefsInterface* prefs_; |
| 90 | ConnectionManager* connection_manager_; |
Jay Srinivasan | 08fce04 | 2012-06-07 16:31:01 -0700 | [diff] [blame] | 91 | }; |
| 92 | |
| 93 | } // namespeace chromeos_update_engine |
| 94 | |
| 95 | #endif // CHROMEOS_PLATFORM_UPDATE_ENGINE_MOCK_SYSTEM_STATE_H__ |