Don Garrett | 83692e4 | 2013-11-08 10:11:30 -0800 | [diff] [blame] | 1 | // Copyright (c) 2013 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 | |
Alex Deymo | 759c275 | 2014-03-17 21:09:36 -0700 | [diff] [blame] | 5 | #ifndef CHROMEOS_PLATFORM_UPDATE_ENGINE_MOCK_HARDWARE_H_ |
| 6 | #define CHROMEOS_PLATFORM_UPDATE_ENGINE_MOCK_HARDWARE_H_ |
Don Garrett | 83692e4 | 2013-11-08 10:11:30 -0800 | [diff] [blame] | 7 | |
Alex Deymo | 04f2b38 | 2014-03-21 15:45:17 -0700 | [diff] [blame^] | 8 | #include "update_engine/fake_hardware.h" |
Don Garrett | 83692e4 | 2013-11-08 10:11:30 -0800 | [diff] [blame] | 9 | |
| 10 | #include <gmock/gmock.h> |
| 11 | |
| 12 | namespace chromeos_update_engine { |
| 13 | |
| 14 | // A mocked, fake implementation of HardwareInterface. |
| 15 | class MockHardware : public HardwareInterface { |
| 16 | public: |
| 17 | MockHardware() { |
| 18 | // Delegate all calls to the fake instance |
| 19 | ON_CALL(*this, BootKernelDevice()) |
| 20 | .WillByDefault(testing::Invoke(&fake_, |
| 21 | &FakeHardware::BootKernelDevice)); |
| 22 | ON_CALL(*this, BootDevice()) |
| 23 | .WillByDefault(testing::Invoke(&fake_, |
| 24 | &FakeHardware::BootDevice)); |
Alex Vakulenko | 59e253e | 2014-02-24 10:40:21 -0800 | [diff] [blame] | 25 | ON_CALL(*this, GetKernelDevices()) |
| 26 | .WillByDefault(testing::Invoke(&fake_, |
| 27 | &FakeHardware::GetKernelDevices)); |
Don Garrett | 83692e4 | 2013-11-08 10:11:30 -0800 | [diff] [blame] | 28 | ON_CALL(*this, IsKernelBootable(testing::_, testing::_)) |
| 29 | .WillByDefault(testing::Invoke(&fake_, |
| 30 | &FakeHardware::IsKernelBootable)); |
| 31 | ON_CALL(*this, MarkKernelUnbootable(testing::_)) |
| 32 | .WillByDefault(testing::Invoke(&fake_, |
| 33 | &FakeHardware::MarkKernelUnbootable)); |
| 34 | ON_CALL(*this, IsOfficialBuild()) |
| 35 | .WillByDefault(testing::Invoke(&fake_, |
| 36 | &FakeHardware::IsOfficialBuild)); |
| 37 | ON_CALL(*this, IsNormalBootMode()) |
| 38 | .WillByDefault(testing::Invoke(&fake_, |
| 39 | &FakeHardware::IsNormalBootMode)); |
| 40 | ON_CALL(*this, GetHardwareClass()) |
| 41 | .WillByDefault(testing::Invoke(&fake_, |
| 42 | &FakeHardware::GetHardwareClass)); |
| 43 | ON_CALL(*this, GetFirmwareVersion()) |
| 44 | .WillByDefault(testing::Invoke(&fake_, |
| 45 | &FakeHardware::GetFirmwareVersion)); |
| 46 | ON_CALL(*this, GetECVersion()) |
| 47 | .WillByDefault(testing::Invoke(&fake_, |
| 48 | &FakeHardware::GetECVersion)); |
| 49 | } |
| 50 | |
| 51 | virtual ~MockHardware() {} |
| 52 | |
| 53 | // Hardware overrides. |
Alex Vakulenko | d0fdfb3 | 2014-02-21 15:26:26 -0800 | [diff] [blame] | 54 | MOCK_CONST_METHOD0(BootKernelDevice, std::string()); |
| 55 | MOCK_CONST_METHOD0(BootDevice, std::string()); |
| 56 | MOCK_CONST_METHOD0(GetKernelDevices, std::vector<std::string>()); |
| 57 | MOCK_CONST_METHOD2(IsKernelBootable, |
Don Garrett | 83692e4 | 2013-11-08 10:11:30 -0800 | [diff] [blame] | 58 | bool(const std::string& kernel_device, bool* bootable)); |
| 59 | MOCK_METHOD1(MarkKernelUnbootable, |
| 60 | bool(const std::string& kernel_device)); |
Alex Vakulenko | d0fdfb3 | 2014-02-21 15:26:26 -0800 | [diff] [blame] | 61 | MOCK_CONST_METHOD0(IsOfficialBuild, bool()); |
| 62 | MOCK_CONST_METHOD0(IsNormalBootMode, bool()); |
| 63 | MOCK_CONST_METHOD0(GetHardwareClass, std::string()); |
| 64 | MOCK_CONST_METHOD0(GetFirmwareVersion, std::string()); |
| 65 | MOCK_CONST_METHOD0(GetECVersion, std::string()); |
Don Garrett | 83692e4 | 2013-11-08 10:11:30 -0800 | [diff] [blame] | 66 | |
| 67 | // Returns a reference to the underlying FakeHardware. |
| 68 | FakeHardware& fake() { |
| 69 | return fake_; |
| 70 | } |
| 71 | |
| 72 | private: |
| 73 | // The underlying FakeHardware. |
| 74 | FakeHardware fake_; |
| 75 | |
| 76 | DISALLOW_COPY_AND_ASSIGN(MockHardware); |
| 77 | }; |
| 78 | |
| 79 | |
| 80 | } // namespace chromeos_update_engine |
| 81 | |
Alex Deymo | 759c275 | 2014-03-17 21:09:36 -0700 | [diff] [blame] | 82 | #endif // CHROMEOS_PLATFORM_UPDATE_ENGINE_MOCK_HARDWARE_H_ |