Alex Deymo | aea4c1c | 2015-08-19 20:24:43 -0700 | [diff] [blame] | 1 | // |
| 2 | // Copyright (C) 2013 The Android Open Source Project |
| 3 | // |
| 4 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | // you may not use this file except in compliance with the License. |
| 6 | // You may obtain a copy of the License at |
| 7 | // |
| 8 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | // |
| 10 | // Unless required by applicable law or agreed to in writing, software |
| 11 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | // See the License for the specific language governing permissions and |
| 14 | // limitations under the License. |
| 15 | // |
Don Garrett | 83692e4 | 2013-11-08 10:11:30 -0800 | [diff] [blame] | 16 | |
Gilad Arnold | cf175a0 | 2014-07-10 16:48:47 -0700 | [diff] [blame] | 17 | #ifndef UPDATE_ENGINE_MOCK_HARDWARE_H_ |
| 18 | #define UPDATE_ENGINE_MOCK_HARDWARE_H_ |
Don Garrett | 83692e4 | 2013-11-08 10:11:30 -0800 | [diff] [blame] | 19 | |
Alex Deymo | df632d1 | 2014-04-29 20:04:36 -0700 | [diff] [blame] | 20 | #include <string> |
| 21 | #include <vector> |
| 22 | |
Alex Deymo | 04f2b38 | 2014-03-21 15:45:17 -0700 | [diff] [blame] | 23 | #include "update_engine/fake_hardware.h" |
Don Garrett | 83692e4 | 2013-11-08 10:11:30 -0800 | [diff] [blame] | 24 | |
| 25 | #include <gmock/gmock.h> |
| 26 | |
| 27 | namespace chromeos_update_engine { |
| 28 | |
| 29 | // A mocked, fake implementation of HardwareInterface. |
| 30 | class MockHardware : public HardwareInterface { |
Alex Deymo | df632d1 | 2014-04-29 20:04:36 -0700 | [diff] [blame] | 31 | public: |
Don Garrett | 83692e4 | 2013-11-08 10:11:30 -0800 | [diff] [blame] | 32 | MockHardware() { |
| 33 | // Delegate all calls to the fake instance |
| 34 | ON_CALL(*this, BootKernelDevice()) |
| 35 | .WillByDefault(testing::Invoke(&fake_, |
| 36 | &FakeHardware::BootKernelDevice)); |
| 37 | ON_CALL(*this, BootDevice()) |
| 38 | .WillByDefault(testing::Invoke(&fake_, |
| 39 | &FakeHardware::BootDevice)); |
Alex Deymo | 5708ecd | 2014-04-29 19:44:50 -0700 | [diff] [blame] | 40 | ON_CALL(*this, IsBootDeviceRemovable()) |
| 41 | .WillByDefault(testing::Invoke(&fake_, |
| 42 | &FakeHardware::IsBootDeviceRemovable)); |
Alex Vakulenko | 59e253e | 2014-02-24 10:40:21 -0800 | [diff] [blame] | 43 | ON_CALL(*this, GetKernelDevices()) |
| 44 | .WillByDefault(testing::Invoke(&fake_, |
| 45 | &FakeHardware::GetKernelDevices)); |
Don Garrett | 83692e4 | 2013-11-08 10:11:30 -0800 | [diff] [blame] | 46 | ON_CALL(*this, IsKernelBootable(testing::_, testing::_)) |
| 47 | .WillByDefault(testing::Invoke(&fake_, |
| 48 | &FakeHardware::IsKernelBootable)); |
| 49 | ON_CALL(*this, MarkKernelUnbootable(testing::_)) |
| 50 | .WillByDefault(testing::Invoke(&fake_, |
| 51 | &FakeHardware::MarkKernelUnbootable)); |
| 52 | ON_CALL(*this, IsOfficialBuild()) |
| 53 | .WillByDefault(testing::Invoke(&fake_, |
| 54 | &FakeHardware::IsOfficialBuild)); |
| 55 | ON_CALL(*this, IsNormalBootMode()) |
| 56 | .WillByDefault(testing::Invoke(&fake_, |
| 57 | &FakeHardware::IsNormalBootMode)); |
Alex Deymo | bccbc38 | 2014-04-03 13:38:55 -0700 | [diff] [blame] | 58 | ON_CALL(*this, IsOOBEComplete(testing::_)) |
| 59 | .WillByDefault(testing::Invoke(&fake_, |
| 60 | &FakeHardware::IsOOBEComplete)); |
Don Garrett | 83692e4 | 2013-11-08 10:11:30 -0800 | [diff] [blame] | 61 | ON_CALL(*this, GetHardwareClass()) |
| 62 | .WillByDefault(testing::Invoke(&fake_, |
| 63 | &FakeHardware::GetHardwareClass)); |
| 64 | ON_CALL(*this, GetFirmwareVersion()) |
| 65 | .WillByDefault(testing::Invoke(&fake_, |
| 66 | &FakeHardware::GetFirmwareVersion)); |
| 67 | ON_CALL(*this, GetECVersion()) |
| 68 | .WillByDefault(testing::Invoke(&fake_, |
| 69 | &FakeHardware::GetECVersion)); |
Alex Deymo | ebbe7ef | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 70 | ON_CALL(*this, GetPowerwashCount()) |
| 71 | .WillByDefault(testing::Invoke(&fake_, |
| 72 | &FakeHardware::GetPowerwashCount)); |
Don Garrett | 83692e4 | 2013-11-08 10:11:30 -0800 | [diff] [blame] | 73 | } |
| 74 | |
Alex Deymo | 610277e | 2014-11-11 21:18:11 -0800 | [diff] [blame] | 75 | ~MockHardware() override {} |
Don Garrett | 83692e4 | 2013-11-08 10:11:30 -0800 | [diff] [blame] | 76 | |
| 77 | // Hardware overrides. |
Alex Vakulenko | d0fdfb3 | 2014-02-21 15:26:26 -0800 | [diff] [blame] | 78 | MOCK_CONST_METHOD0(BootKernelDevice, std::string()); |
| 79 | MOCK_CONST_METHOD0(BootDevice, std::string()); |
Alex Deymo | 5708ecd | 2014-04-29 19:44:50 -0700 | [diff] [blame] | 80 | MOCK_CONST_METHOD0(IsBootDeviceRemovable, bool()); |
Alex Vakulenko | d0fdfb3 | 2014-02-21 15:26:26 -0800 | [diff] [blame] | 81 | MOCK_CONST_METHOD0(GetKernelDevices, std::vector<std::string>()); |
| 82 | MOCK_CONST_METHOD2(IsKernelBootable, |
Don Garrett | 83692e4 | 2013-11-08 10:11:30 -0800 | [diff] [blame] | 83 | bool(const std::string& kernel_device, bool* bootable)); |
| 84 | MOCK_METHOD1(MarkKernelUnbootable, |
| 85 | bool(const std::string& kernel_device)); |
Alex Vakulenko | d0fdfb3 | 2014-02-21 15:26:26 -0800 | [diff] [blame] | 86 | MOCK_CONST_METHOD0(IsOfficialBuild, bool()); |
| 87 | MOCK_CONST_METHOD0(IsNormalBootMode, bool()); |
Alex Deymo | bccbc38 | 2014-04-03 13:38:55 -0700 | [diff] [blame] | 88 | MOCK_CONST_METHOD1(IsOOBEComplete, bool(base::Time* out_time_of_oobe)); |
Alex Vakulenko | d0fdfb3 | 2014-02-21 15:26:26 -0800 | [diff] [blame] | 89 | MOCK_CONST_METHOD0(GetHardwareClass, std::string()); |
| 90 | MOCK_CONST_METHOD0(GetFirmwareVersion, std::string()); |
| 91 | MOCK_CONST_METHOD0(GetECVersion, std::string()); |
Alex Deymo | ebbe7ef | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 92 | MOCK_CONST_METHOD0(GetPowerwashCount, int()); |
Don Garrett | 83692e4 | 2013-11-08 10:11:30 -0800 | [diff] [blame] | 93 | |
| 94 | // Returns a reference to the underlying FakeHardware. |
| 95 | FakeHardware& fake() { |
| 96 | return fake_; |
| 97 | } |
| 98 | |
Alex Deymo | df632d1 | 2014-04-29 20:04:36 -0700 | [diff] [blame] | 99 | private: |
Don Garrett | 83692e4 | 2013-11-08 10:11:30 -0800 | [diff] [blame] | 100 | // The underlying FakeHardware. |
| 101 | FakeHardware fake_; |
| 102 | |
| 103 | DISALLOW_COPY_AND_ASSIGN(MockHardware); |
| 104 | }; |
| 105 | |
| 106 | |
| 107 | } // namespace chromeos_update_engine |
| 108 | |
Gilad Arnold | cf175a0 | 2014-07-10 16:48:47 -0700 | [diff] [blame] | 109 | #endif // UPDATE_ENGINE_MOCK_HARDWARE_H_ |