blob: 42fa7ba4f8baffe1a7a4bf087d97d57df27e1d4e [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())
34 .WillByDefault(testing::Invoke(&fake_,
35 &FakeHardware::IsOfficialBuild));
36 ON_CALL(*this, IsNormalBootMode())
37 .WillByDefault(testing::Invoke(&fake_,
38 &FakeHardware::IsNormalBootMode));
Sen Jiange67bb5b2016-06-20 15:53:56 -070039 ON_CALL(*this, AreDevFeaturesEnabled())
40 .WillByDefault(testing::Invoke(&fake_,
41 &FakeHardware::AreDevFeaturesEnabled));
Alex Deymo46a9aae2016-05-04 20:20:11 -070042 ON_CALL(*this, IsOOBEEnabled())
43 .WillByDefault(testing::Invoke(&fake_,
44 &FakeHardware::IsOOBEEnabled));
Alex Deymobccbc382014-04-03 13:38:55 -070045 ON_CALL(*this, IsOOBEComplete(testing::_))
46 .WillByDefault(testing::Invoke(&fake_,
47 &FakeHardware::IsOOBEComplete));
Don Garrett83692e42013-11-08 10:11:30 -080048 ON_CALL(*this, GetHardwareClass())
49 .WillByDefault(testing::Invoke(&fake_,
50 &FakeHardware::GetHardwareClass));
51 ON_CALL(*this, GetFirmwareVersion())
52 .WillByDefault(testing::Invoke(&fake_,
53 &FakeHardware::GetFirmwareVersion));
54 ON_CALL(*this, GetECVersion())
55 .WillByDefault(testing::Invoke(&fake_,
56 &FakeHardware::GetECVersion));
Alex Deymoebbe7ef2014-10-30 13:02:49 -070057 ON_CALL(*this, GetPowerwashCount())
58 .WillByDefault(testing::Invoke(&fake_,
59 &FakeHardware::GetPowerwashCount));
Alex Deymodd132f32015-09-14 19:12:07 -070060 ON_CALL(*this, GetNonVolatileDirectory(testing::_))
61 .WillByDefault(testing::Invoke(&fake_,
62 &FakeHardware::GetNonVolatileDirectory));
63 ON_CALL(*this, GetPowerwashSafeDirectory(testing::_))
64 .WillByDefault(testing::Invoke(&fake_,
65 &FakeHardware::GetPowerwashSafeDirectory));
Amin Hassani1677e812017-06-21 13:36:36 -070066 ON_CALL(*this, GetFirstActiveOmahaPingSent())
67 .WillByDefault(testing::Invoke(&fake_,
68 &FakeHardware::GetFirstActiveOmahaPingSent()));
69 ON_CALL(*this, SetFirstActiveOmahaPingSent())
70 .WillByDefault(testing::Invoke(&fake_,
71 &FakeHardware::SetFirstActiveOmahaPingSent()));
Don Garrett83692e42013-11-08 10:11:30 -080072 }
73
Alex Deymo763e7db2015-08-27 21:08:08 -070074 ~MockHardware() override = default;
Don Garrett83692e42013-11-08 10:11:30 -080075
76 // Hardware overrides.
Alex Vakulenkod0fdfb32014-02-21 15:26:26 -080077 MOCK_CONST_METHOD0(IsOfficialBuild, bool());
78 MOCK_CONST_METHOD0(IsNormalBootMode, bool());
Alex Deymo46a9aae2016-05-04 20:20:11 -070079 MOCK_CONST_METHOD0(IsOOBEEnabled, bool());
Alex Deymobccbc382014-04-03 13:38:55 -070080 MOCK_CONST_METHOD1(IsOOBEComplete, bool(base::Time* out_time_of_oobe));
Alex Vakulenkod0fdfb32014-02-21 15:26:26 -080081 MOCK_CONST_METHOD0(GetHardwareClass, std::string());
82 MOCK_CONST_METHOD0(GetFirmwareVersion, std::string());
83 MOCK_CONST_METHOD0(GetECVersion, std::string());
Alex Deymoebbe7ef2014-10-30 13:02:49 -070084 MOCK_CONST_METHOD0(GetPowerwashCount, int());
Alex Deymodd132f32015-09-14 19:12:07 -070085 MOCK_CONST_METHOD1(GetNonVolatileDirectory, bool(base::FilePath*));
86 MOCK_CONST_METHOD1(GetPowerwashSafeDirectory, bool(base::FilePath*));
Amin Hassani1677e812017-06-21 13:36:36 -070087 MOCK_CONST_METHOD0(GetFirstActiveOmahaPingSent, bool());
Don Garrett83692e42013-11-08 10:11:30 -080088
89 // Returns a reference to the underlying FakeHardware.
90 FakeHardware& fake() {
91 return fake_;
92 }
93
Alex Deymodf632d12014-04-29 20:04:36 -070094 private:
Don Garrett83692e42013-11-08 10:11:30 -080095 // The underlying FakeHardware.
96 FakeHardware fake_;
97
98 DISALLOW_COPY_AND_ASSIGN(MockHardware);
99};
100
101
102} // namespace chromeos_update_engine
103
Alex Deymo39910dc2015-11-09 17:04:30 -0800104#endif // UPDATE_ENGINE_COMMON_MOCK_HARDWARE_H_