blob: 071906b5a5f5fa5699a0433aaa6300a8b60584b7 [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));
Zentaro Kavanaghbaacb982018-02-20 17:48:39 -080048 ON_CALL(*this, GetMinKernelKeyVersion())
49 .WillByDefault(
50 testing::Invoke(&fake_, &FakeHardware::GetMinKernelKeyVersion));
Marton Hunyady99ced782018-05-08 12:59:50 +020051 ON_CALL(*this, GetMinFirmwareKeyVersion())
52 .WillByDefault(
53 testing::Invoke(&fake_, &FakeHardware::GetMinFirmwareKeyVersion));
Zentaro Kavanagh8f6f2432018-05-16 13:48:12 -070054 ON_CALL(*this, GetMaxFirmwareKeyRollforward())
55 .WillByDefault(testing::Invoke(
56 &fake_, &FakeHardware::GetMaxFirmwareKeyRollforward));
57 ON_CALL(*this, SetMaxFirmwareKeyRollforward())
58 .WillByDefault(testing::Invoke(
59 &fake_, &FakeHardware::SetMaxFirmwareKeyRollforward));
Zentaro Kavanaghbaacb982018-02-20 17:48:39 -080060 ON_CALL(*this, SetMaxKernelKeyRollforward())
61 .WillByDefault(
62 testing::Invoke(&fake_, &FakeHardware::SetMaxKernelKeyRollforward));
Alex Deymoebbe7ef2014-10-30 13:02:49 -070063 ON_CALL(*this, GetPowerwashCount())
Amin Hassanib2689592019-01-13 17:04:28 -080064 .WillByDefault(
65 testing::Invoke(&fake_, &FakeHardware::GetPowerwashCount));
Alex Deymodd132f32015-09-14 19:12:07 -070066 ON_CALL(*this, GetNonVolatileDirectory(testing::_))
Amin Hassanib2689592019-01-13 17:04:28 -080067 .WillByDefault(
68 testing::Invoke(&fake_, &FakeHardware::GetNonVolatileDirectory));
Alex Deymodd132f32015-09-14 19:12:07 -070069 ON_CALL(*this, GetPowerwashSafeDirectory(testing::_))
Amin Hassanib2689592019-01-13 17:04:28 -080070 .WillByDefault(
71 testing::Invoke(&fake_, &FakeHardware::GetPowerwashSafeDirectory));
Amin Hassani1677e812017-06-21 13:36:36 -070072 ON_CALL(*this, GetFirstActiveOmahaPingSent())
Amin Hassanib2689592019-01-13 17:04:28 -080073 .WillByDefault(testing::Invoke(
74 &fake_, &FakeHardware::GetFirstActiveOmahaPingSent()));
Amin Hassani1677e812017-06-21 13:36:36 -070075 ON_CALL(*this, SetFirstActiveOmahaPingSent())
Amin Hassanib2689592019-01-13 17:04:28 -080076 .WillByDefault(testing::Invoke(
77 &fake_, &FakeHardware::SetFirstActiveOmahaPingSent()));
Don Garrett83692e42013-11-08 10:11:30 -080078 }
79
Alex Deymo763e7db2015-08-27 21:08:08 -070080 ~MockHardware() override = default;
Don Garrett83692e42013-11-08 10:11:30 -080081
82 // Hardware overrides.
Alex Vakulenkod0fdfb32014-02-21 15:26:26 -080083 MOCK_CONST_METHOD0(IsOfficialBuild, bool());
84 MOCK_CONST_METHOD0(IsNormalBootMode, bool());
Alex Deymo46a9aae2016-05-04 20:20:11 -070085 MOCK_CONST_METHOD0(IsOOBEEnabled, bool());
Alex Deymobccbc382014-04-03 13:38:55 -070086 MOCK_CONST_METHOD1(IsOOBEComplete, bool(base::Time* out_time_of_oobe));
Alex Vakulenkod0fdfb32014-02-21 15:26:26 -080087 MOCK_CONST_METHOD0(GetHardwareClass, std::string());
Zentaro Kavanaghbaacb982018-02-20 17:48:39 -080088 MOCK_CONST_METHOD0(GetMinKernelKeyVersion, int());
Marton Hunyady99ced782018-05-08 12:59:50 +020089 MOCK_CONST_METHOD0(GetMinFirmwareKeyVersion, int());
Zentaro Kavanagh8f6f2432018-05-16 13:48:12 -070090 MOCK_CONST_METHOD0(GetMaxFirmwareKeyRollforward, int());
91 MOCK_CONST_METHOD1(SetMaxFirmwareKeyRollforward,
92 bool(int firmware_max_rollforward));
Zentaro Kavanaghbaacb982018-02-20 17:48:39 -080093 MOCK_CONST_METHOD1(SetMaxKernelKeyRollforward,
Zentaro Kavanagh5d956152018-05-15 09:40:33 -070094 bool(int kernel_max_rollforward));
Alex Deymoebbe7ef2014-10-30 13:02:49 -070095 MOCK_CONST_METHOD0(GetPowerwashCount, int());
Alex Deymodd132f32015-09-14 19:12:07 -070096 MOCK_CONST_METHOD1(GetNonVolatileDirectory, bool(base::FilePath*));
97 MOCK_CONST_METHOD1(GetPowerwashSafeDirectory, bool(base::FilePath*));
Amin Hassani1677e812017-06-21 13:36:36 -070098 MOCK_CONST_METHOD0(GetFirstActiveOmahaPingSent, bool());
Don Garrett83692e42013-11-08 10:11:30 -080099
100 // Returns a reference to the underlying FakeHardware.
Amin Hassanib2689592019-01-13 17:04:28 -0800101 FakeHardware& fake() { return fake_; }
Don Garrett83692e42013-11-08 10:11:30 -0800102
Alex Deymodf632d12014-04-29 20:04:36 -0700103 private:
Don Garrett83692e42013-11-08 10:11:30 -0800104 // The underlying FakeHardware.
105 FakeHardware fake_;
106
107 DISALLOW_COPY_AND_ASSIGN(MockHardware);
108};
109
Don Garrett83692e42013-11-08 10:11:30 -0800110} // namespace chromeos_update_engine
111
Alex Deymo39910dc2015-11-09 17:04:30 -0800112#endif // UPDATE_ENGINE_COMMON_MOCK_HARDWARE_H_