blob: 84c0c5ba74b4891aef589be2653b06f06e4d84cc [file] [log] [blame]
Alex Deymoaea4c1c2015-08-19 20:24:43 -07001//
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 Garrett83692e42013-11-08 10:11:30 -080016
Alex Deymo39910dc2015-11-09 17:04:30 -080017#ifndef UPDATE_ENGINE_COMMON_MOCK_HARDWARE_H_
18#define UPDATE_ENGINE_COMMON_MOCK_HARDWARE_H_
Don Garrett83692e42013-11-08 10:11:30 -080019
Alex Deymodf632d12014-04-29 20:04:36 -070020#include <string>
Alex Deymodf632d12014-04-29 20:04:36 -070021
Alex Deymo39910dc2015-11-09 17:04:30 -080022#include "update_engine/common/fake_hardware.h"
Don Garrett83692e42013-11-08 10:11:30 -080023
24#include <gmock/gmock.h>
25
26namespace chromeos_update_engine {
27
28// A mocked, fake implementation of HardwareInterface.
29class MockHardware : public HardwareInterface {
Alex Deymodf632d12014-04-29 20:04:36 -070030 public:
Don Garrett83692e42013-11-08 10:11:30 -080031 MockHardware() {
32 // Delegate all calls to the fake instance
Don Garrett83692e42013-11-08 10:11:30 -080033 ON_CALL(*this, IsOfficialBuild())
Amin Hassanib2689592019-01-13 17:04:28 -080034 .WillByDefault(testing::Invoke(&fake_, &FakeHardware::IsOfficialBuild));
Don Garrett83692e42013-11-08 10:11:30 -080035 ON_CALL(*this, IsNormalBootMode())
Amin Hassanib2689592019-01-13 17:04:28 -080036 .WillByDefault(
37 testing::Invoke(&fake_, &FakeHardware::IsNormalBootMode));
Sen Jiange67bb5b2016-06-20 15:53:56 -070038 ON_CALL(*this, AreDevFeaturesEnabled())
Amin Hassanib2689592019-01-13 17:04:28 -080039 .WillByDefault(
40 testing::Invoke(&fake_, &FakeHardware::AreDevFeaturesEnabled));
Alex Deymo46a9aae2016-05-04 20:20:11 -070041 ON_CALL(*this, IsOOBEEnabled())
Amin Hassanib2689592019-01-13 17:04:28 -080042 .WillByDefault(testing::Invoke(&fake_, &FakeHardware::IsOOBEEnabled));
Alex Deymobccbc382014-04-03 13:38:55 -070043 ON_CALL(*this, IsOOBEComplete(testing::_))
Amin Hassanib2689592019-01-13 17:04:28 -080044 .WillByDefault(testing::Invoke(&fake_, &FakeHardware::IsOOBEComplete));
Don Garrett83692e42013-11-08 10:11:30 -080045 ON_CALL(*this, GetHardwareClass())
Amin Hassanib2689592019-01-13 17:04:28 -080046 .WillByDefault(
47 testing::Invoke(&fake_, &FakeHardware::GetHardwareClass));
Don Garrett83692e42013-11-08 10:11:30 -080048 ON_CALL(*this, GetFirmwareVersion())
Amin Hassanib2689592019-01-13 17:04:28 -080049 .WillByDefault(
50 testing::Invoke(&fake_, &FakeHardware::GetFirmwareVersion));
Don Garrett83692e42013-11-08 10:11:30 -080051 ON_CALL(*this, GetECVersion())
Amin Hassanib2689592019-01-13 17:04:28 -080052 .WillByDefault(testing::Invoke(&fake_, &FakeHardware::GetECVersion));
Zentaro Kavanaghbaacb982018-02-20 17:48:39 -080053 ON_CALL(*this, GetMinKernelKeyVersion())
54 .WillByDefault(
55 testing::Invoke(&fake_, &FakeHardware::GetMinKernelKeyVersion));
Marton Hunyady99ced782018-05-08 12:59:50 +020056 ON_CALL(*this, GetMinFirmwareKeyVersion())
57 .WillByDefault(
58 testing::Invoke(&fake_, &FakeHardware::GetMinFirmwareKeyVersion));
Zentaro Kavanagh8f6f2432018-05-16 13:48:12 -070059 ON_CALL(*this, GetMaxFirmwareKeyRollforward())
60 .WillByDefault(testing::Invoke(
61 &fake_, &FakeHardware::GetMaxFirmwareKeyRollforward));
62 ON_CALL(*this, SetMaxFirmwareKeyRollforward())
63 .WillByDefault(testing::Invoke(
64 &fake_, &FakeHardware::SetMaxFirmwareKeyRollforward));
Zentaro Kavanaghbaacb982018-02-20 17:48:39 -080065 ON_CALL(*this, SetMaxKernelKeyRollforward())
66 .WillByDefault(
67 testing::Invoke(&fake_, &FakeHardware::SetMaxKernelKeyRollforward));
Alex Deymoebbe7ef2014-10-30 13:02:49 -070068 ON_CALL(*this, GetPowerwashCount())
Amin Hassanib2689592019-01-13 17:04:28 -080069 .WillByDefault(
70 testing::Invoke(&fake_, &FakeHardware::GetPowerwashCount));
Alex Deymodd132f32015-09-14 19:12:07 -070071 ON_CALL(*this, GetNonVolatileDirectory(testing::_))
Amin Hassanib2689592019-01-13 17:04:28 -080072 .WillByDefault(
73 testing::Invoke(&fake_, &FakeHardware::GetNonVolatileDirectory));
Alex Deymodd132f32015-09-14 19:12:07 -070074 ON_CALL(*this, GetPowerwashSafeDirectory(testing::_))
Amin Hassanib2689592019-01-13 17:04:28 -080075 .WillByDefault(
76 testing::Invoke(&fake_, &FakeHardware::GetPowerwashSafeDirectory));
Amin Hassani1677e812017-06-21 13:36:36 -070077 ON_CALL(*this, GetFirstActiveOmahaPingSent())
Amin Hassanib2689592019-01-13 17:04:28 -080078 .WillByDefault(testing::Invoke(
79 &fake_, &FakeHardware::GetFirstActiveOmahaPingSent()));
Amin Hassani1677e812017-06-21 13:36:36 -070080 ON_CALL(*this, SetFirstActiveOmahaPingSent())
Amin Hassanib2689592019-01-13 17:04:28 -080081 .WillByDefault(testing::Invoke(
82 &fake_, &FakeHardware::SetFirstActiveOmahaPingSent()));
Don Garrett83692e42013-11-08 10:11:30 -080083 }
84
Alex Deymo763e7db2015-08-27 21:08:08 -070085 ~MockHardware() override = default;
Don Garrett83692e42013-11-08 10:11:30 -080086
87 // Hardware overrides.
Alex Vakulenkod0fdfb32014-02-21 15:26:26 -080088 MOCK_CONST_METHOD0(IsOfficialBuild, bool());
89 MOCK_CONST_METHOD0(IsNormalBootMode, bool());
Alex Deymo46a9aae2016-05-04 20:20:11 -070090 MOCK_CONST_METHOD0(IsOOBEEnabled, bool());
Alex Deymobccbc382014-04-03 13:38:55 -070091 MOCK_CONST_METHOD1(IsOOBEComplete, bool(base::Time* out_time_of_oobe));
Alex Vakulenkod0fdfb32014-02-21 15:26:26 -080092 MOCK_CONST_METHOD0(GetHardwareClass, std::string());
93 MOCK_CONST_METHOD0(GetFirmwareVersion, std::string());
94 MOCK_CONST_METHOD0(GetECVersion, std::string());
Zentaro Kavanaghbaacb982018-02-20 17:48:39 -080095 MOCK_CONST_METHOD0(GetMinKernelKeyVersion, int());
Marton Hunyady99ced782018-05-08 12:59:50 +020096 MOCK_CONST_METHOD0(GetMinFirmwareKeyVersion, int());
Zentaro Kavanagh8f6f2432018-05-16 13:48:12 -070097 MOCK_CONST_METHOD0(GetMaxFirmwareKeyRollforward, int());
98 MOCK_CONST_METHOD1(SetMaxFirmwareKeyRollforward,
99 bool(int firmware_max_rollforward));
Zentaro Kavanaghbaacb982018-02-20 17:48:39 -0800100 MOCK_CONST_METHOD1(SetMaxKernelKeyRollforward,
Zentaro Kavanagh5d956152018-05-15 09:40:33 -0700101 bool(int kernel_max_rollforward));
Alex Deymoebbe7ef2014-10-30 13:02:49 -0700102 MOCK_CONST_METHOD0(GetPowerwashCount, int());
Alex Deymodd132f32015-09-14 19:12:07 -0700103 MOCK_CONST_METHOD1(GetNonVolatileDirectory, bool(base::FilePath*));
104 MOCK_CONST_METHOD1(GetPowerwashSafeDirectory, bool(base::FilePath*));
Amin Hassani1677e812017-06-21 13:36:36 -0700105 MOCK_CONST_METHOD0(GetFirstActiveOmahaPingSent, bool());
Don Garrett83692e42013-11-08 10:11:30 -0800106
107 // Returns a reference to the underlying FakeHardware.
Amin Hassanib2689592019-01-13 17:04:28 -0800108 FakeHardware& fake() { return fake_; }
Don Garrett83692e42013-11-08 10:11:30 -0800109
Alex Deymodf632d12014-04-29 20:04:36 -0700110 private:
Don Garrett83692e42013-11-08 10:11:30 -0800111 // The underlying FakeHardware.
112 FakeHardware fake_;
113
114 DISALLOW_COPY_AND_ASSIGN(MockHardware);
115};
116
Don Garrett83692e42013-11-08 10:11:30 -0800117} // namespace chromeos_update_engine
118
Alex Deymo39910dc2015-11-09 17:04:30 -0800119#endif // UPDATE_ENGINE_COMMON_MOCK_HARDWARE_H_