blob: bf268212c4e0a9ec55ded42584d01d9a95e4874e [file] [log] [blame]
Don Garrett83692e42013-11-08 10:11:30 -08001// 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
Gilad Arnoldcf175a02014-07-10 16:48:47 -07005#ifndef UPDATE_ENGINE_MOCK_HARDWARE_H_
6#define UPDATE_ENGINE_MOCK_HARDWARE_H_
Don Garrett83692e42013-11-08 10:11:30 -08007
Alex Deymodf632d12014-04-29 20:04:36 -07008#include <string>
9#include <vector>
10
Alex Deymo04f2b382014-03-21 15:45:17 -070011#include "update_engine/fake_hardware.h"
Don Garrett83692e42013-11-08 10:11:30 -080012
13#include <gmock/gmock.h>
14
15namespace chromeos_update_engine {
16
17// A mocked, fake implementation of HardwareInterface.
18class MockHardware : public HardwareInterface {
Alex Deymodf632d12014-04-29 20:04:36 -070019 public:
Don Garrett83692e42013-11-08 10:11:30 -080020 MockHardware() {
21 // Delegate all calls to the fake instance
22 ON_CALL(*this, BootKernelDevice())
23 .WillByDefault(testing::Invoke(&fake_,
24 &FakeHardware::BootKernelDevice));
25 ON_CALL(*this, BootDevice())
26 .WillByDefault(testing::Invoke(&fake_,
27 &FakeHardware::BootDevice));
Alex Deymo5708ecd2014-04-29 19:44:50 -070028 ON_CALL(*this, IsBootDeviceRemovable())
29 .WillByDefault(testing::Invoke(&fake_,
30 &FakeHardware::IsBootDeviceRemovable));
Alex Vakulenko59e253e2014-02-24 10:40:21 -080031 ON_CALL(*this, GetKernelDevices())
32 .WillByDefault(testing::Invoke(&fake_,
33 &FakeHardware::GetKernelDevices));
Don Garrett83692e42013-11-08 10:11:30 -080034 ON_CALL(*this, IsKernelBootable(testing::_, testing::_))
35 .WillByDefault(testing::Invoke(&fake_,
36 &FakeHardware::IsKernelBootable));
37 ON_CALL(*this, MarkKernelUnbootable(testing::_))
38 .WillByDefault(testing::Invoke(&fake_,
39 &FakeHardware::MarkKernelUnbootable));
40 ON_CALL(*this, IsOfficialBuild())
41 .WillByDefault(testing::Invoke(&fake_,
42 &FakeHardware::IsOfficialBuild));
43 ON_CALL(*this, IsNormalBootMode())
44 .WillByDefault(testing::Invoke(&fake_,
45 &FakeHardware::IsNormalBootMode));
Alex Deymobccbc382014-04-03 13:38:55 -070046 ON_CALL(*this, IsOOBEComplete(testing::_))
47 .WillByDefault(testing::Invoke(&fake_,
48 &FakeHardware::IsOOBEComplete));
Don Garrett83692e42013-11-08 10:11:30 -080049 ON_CALL(*this, GetHardwareClass())
50 .WillByDefault(testing::Invoke(&fake_,
51 &FakeHardware::GetHardwareClass));
52 ON_CALL(*this, GetFirmwareVersion())
53 .WillByDefault(testing::Invoke(&fake_,
54 &FakeHardware::GetFirmwareVersion));
55 ON_CALL(*this, GetECVersion())
56 .WillByDefault(testing::Invoke(&fake_,
57 &FakeHardware::GetECVersion));
Alex Deymoebbe7ef2014-10-30 13:02:49 -070058 ON_CALL(*this, GetPowerwashCount())
59 .WillByDefault(testing::Invoke(&fake_,
60 &FakeHardware::GetPowerwashCount));
Don Garrett83692e42013-11-08 10:11:30 -080061 }
62
Alex Deymo610277e2014-11-11 21:18:11 -080063 ~MockHardware() override {}
Don Garrett83692e42013-11-08 10:11:30 -080064
65 // Hardware overrides.
Alex Vakulenkod0fdfb32014-02-21 15:26:26 -080066 MOCK_CONST_METHOD0(BootKernelDevice, std::string());
67 MOCK_CONST_METHOD0(BootDevice, std::string());
Alex Deymo5708ecd2014-04-29 19:44:50 -070068 MOCK_CONST_METHOD0(IsBootDeviceRemovable, bool());
Alex Vakulenkod0fdfb32014-02-21 15:26:26 -080069 MOCK_CONST_METHOD0(GetKernelDevices, std::vector<std::string>());
70 MOCK_CONST_METHOD2(IsKernelBootable,
Don Garrett83692e42013-11-08 10:11:30 -080071 bool(const std::string& kernel_device, bool* bootable));
72 MOCK_METHOD1(MarkKernelUnbootable,
73 bool(const std::string& kernel_device));
Alex Vakulenkod0fdfb32014-02-21 15:26:26 -080074 MOCK_CONST_METHOD0(IsOfficialBuild, bool());
75 MOCK_CONST_METHOD0(IsNormalBootMode, bool());
Alex Deymobccbc382014-04-03 13:38:55 -070076 MOCK_CONST_METHOD1(IsOOBEComplete, bool(base::Time* out_time_of_oobe));
Alex Vakulenkod0fdfb32014-02-21 15:26:26 -080077 MOCK_CONST_METHOD0(GetHardwareClass, std::string());
78 MOCK_CONST_METHOD0(GetFirmwareVersion, std::string());
79 MOCK_CONST_METHOD0(GetECVersion, std::string());
Alex Deymoebbe7ef2014-10-30 13:02:49 -070080 MOCK_CONST_METHOD0(GetPowerwashCount, int());
Don Garrett83692e42013-11-08 10:11:30 -080081
82 // Returns a reference to the underlying FakeHardware.
83 FakeHardware& fake() {
84 return fake_;
85 }
86
Alex Deymodf632d12014-04-29 20:04:36 -070087 private:
Don Garrett83692e42013-11-08 10:11:30 -080088 // The underlying FakeHardware.
89 FakeHardware fake_;
90
91 DISALLOW_COPY_AND_ASSIGN(MockHardware);
92};
93
94
95} // namespace chromeos_update_engine
96
Gilad Arnoldcf175a02014-07-10 16:48:47 -070097#endif // UPDATE_ENGINE_MOCK_HARDWARE_H_