| Alex Deymo | aea4c1c | 2015-08-19 20:24:43 -0700 | [diff] [blame] | 1 | // | 
|  | 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 Garrett | 83692e4 | 2013-11-08 10:11:30 -0800 | [diff] [blame] | 16 |  | 
| Alex Deymo | 39910dc | 2015-11-09 17:04:30 -0800 | [diff] [blame] | 17 | #ifndef UPDATE_ENGINE_COMMON_MOCK_HARDWARE_H_ | 
|  | 18 | #define UPDATE_ENGINE_COMMON_MOCK_HARDWARE_H_ | 
| Don Garrett | 83692e4 | 2013-11-08 10:11:30 -0800 | [diff] [blame] | 19 |  | 
| Alex Deymo | df632d1 | 2014-04-29 20:04:36 -0700 | [diff] [blame] | 20 | #include <string> | 
| Alex Deymo | df632d1 | 2014-04-29 20:04:36 -0700 | [diff] [blame] | 21 |  | 
| Alex Deymo | 39910dc | 2015-11-09 17:04:30 -0800 | [diff] [blame] | 22 | #include "update_engine/common/fake_hardware.h" | 
| Don Garrett | 83692e4 | 2013-11-08 10:11:30 -0800 | [diff] [blame] | 23 |  | 
|  | 24 | #include <gmock/gmock.h> | 
|  | 25 |  | 
|  | 26 | namespace chromeos_update_engine { | 
|  | 27 |  | 
|  | 28 | // A mocked, fake implementation of HardwareInterface. | 
|  | 29 | class MockHardware : public HardwareInterface { | 
| Alex Deymo | df632d1 | 2014-04-29 20:04:36 -0700 | [diff] [blame] | 30 | public: | 
| Don Garrett | 83692e4 | 2013-11-08 10:11:30 -0800 | [diff] [blame] | 31 | MockHardware() { | 
|  | 32 | // Delegate all calls to the fake instance | 
| Don Garrett | 83692e4 | 2013-11-08 10:11:30 -0800 | [diff] [blame] | 33 | ON_CALL(*this, IsOfficialBuild()) | 
| Amin Hassani | b268959 | 2019-01-13 17:04:28 -0800 | [diff] [blame] | 34 | .WillByDefault(testing::Invoke(&fake_, &FakeHardware::IsOfficialBuild)); | 
| Don Garrett | 83692e4 | 2013-11-08 10:11:30 -0800 | [diff] [blame] | 35 | ON_CALL(*this, IsNormalBootMode()) | 
| Amin Hassani | b268959 | 2019-01-13 17:04:28 -0800 | [diff] [blame] | 36 | .WillByDefault( | 
|  | 37 | testing::Invoke(&fake_, &FakeHardware::IsNormalBootMode)); | 
| Sen Jiang | e67bb5b | 2016-06-20 15:53:56 -0700 | [diff] [blame] | 38 | ON_CALL(*this, AreDevFeaturesEnabled()) | 
| Amin Hassani | b268959 | 2019-01-13 17:04:28 -0800 | [diff] [blame] | 39 | .WillByDefault( | 
|  | 40 | testing::Invoke(&fake_, &FakeHardware::AreDevFeaturesEnabled)); | 
| Alex Deymo | 46a9aae | 2016-05-04 20:20:11 -0700 | [diff] [blame] | 41 | ON_CALL(*this, IsOOBEEnabled()) | 
| Amin Hassani | b268959 | 2019-01-13 17:04:28 -0800 | [diff] [blame] | 42 | .WillByDefault(testing::Invoke(&fake_, &FakeHardware::IsOOBEEnabled)); | 
| Alex Deymo | bccbc38 | 2014-04-03 13:38:55 -0700 | [diff] [blame] | 43 | ON_CALL(*this, IsOOBEComplete(testing::_)) | 
| Amin Hassani | b268959 | 2019-01-13 17:04:28 -0800 | [diff] [blame] | 44 | .WillByDefault(testing::Invoke(&fake_, &FakeHardware::IsOOBEComplete)); | 
| Don Garrett | 83692e4 | 2013-11-08 10:11:30 -0800 | [diff] [blame] | 45 | ON_CALL(*this, GetHardwareClass()) | 
| Amin Hassani | b268959 | 2019-01-13 17:04:28 -0800 | [diff] [blame] | 46 | .WillByDefault( | 
|  | 47 | testing::Invoke(&fake_, &FakeHardware::GetHardwareClass)); | 
| Zentaro Kavanagh | baacb98 | 2018-02-20 17:48:39 -0800 | [diff] [blame] | 48 | ON_CALL(*this, GetMinKernelKeyVersion()) | 
|  | 49 | .WillByDefault( | 
|  | 50 | testing::Invoke(&fake_, &FakeHardware::GetMinKernelKeyVersion)); | 
| Marton Hunyady | 99ced78 | 2018-05-08 12:59:50 +0200 | [diff] [blame] | 51 | ON_CALL(*this, GetMinFirmwareKeyVersion()) | 
|  | 52 | .WillByDefault( | 
|  | 53 | testing::Invoke(&fake_, &FakeHardware::GetMinFirmwareKeyVersion)); | 
| Zentaro Kavanagh | 8f6f243 | 2018-05-16 13:48:12 -0700 | [diff] [blame] | 54 | 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 Kavanagh | baacb98 | 2018-02-20 17:48:39 -0800 | [diff] [blame] | 60 | ON_CALL(*this, SetMaxKernelKeyRollforward()) | 
|  | 61 | .WillByDefault( | 
|  | 62 | testing::Invoke(&fake_, &FakeHardware::SetMaxKernelKeyRollforward)); | 
| Alex Deymo | ebbe7ef | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 63 | ON_CALL(*this, GetPowerwashCount()) | 
| Amin Hassani | b268959 | 2019-01-13 17:04:28 -0800 | [diff] [blame] | 64 | .WillByDefault( | 
|  | 65 | testing::Invoke(&fake_, &FakeHardware::GetPowerwashCount)); | 
| Alex Deymo | dd132f3 | 2015-09-14 19:12:07 -0700 | [diff] [blame] | 66 | ON_CALL(*this, GetNonVolatileDirectory(testing::_)) | 
| Amin Hassani | b268959 | 2019-01-13 17:04:28 -0800 | [diff] [blame] | 67 | .WillByDefault( | 
|  | 68 | testing::Invoke(&fake_, &FakeHardware::GetNonVolatileDirectory)); | 
| Alex Deymo | dd132f3 | 2015-09-14 19:12:07 -0700 | [diff] [blame] | 69 | ON_CALL(*this, GetPowerwashSafeDirectory(testing::_)) | 
| Amin Hassani | b268959 | 2019-01-13 17:04:28 -0800 | [diff] [blame] | 70 | .WillByDefault( | 
|  | 71 | testing::Invoke(&fake_, &FakeHardware::GetPowerwashSafeDirectory)); | 
| Amin Hassani | 1677e81 | 2017-06-21 13:36:36 -0700 | [diff] [blame] | 72 | ON_CALL(*this, GetFirstActiveOmahaPingSent()) | 
| Amin Hassani | b268959 | 2019-01-13 17:04:28 -0800 | [diff] [blame] | 73 | .WillByDefault(testing::Invoke( | 
|  | 74 | &fake_, &FakeHardware::GetFirstActiveOmahaPingSent())); | 
| Amin Hassani | 1677e81 | 2017-06-21 13:36:36 -0700 | [diff] [blame] | 75 | ON_CALL(*this, SetFirstActiveOmahaPingSent()) | 
| Amin Hassani | b268959 | 2019-01-13 17:04:28 -0800 | [diff] [blame] | 76 | .WillByDefault(testing::Invoke( | 
|  | 77 | &fake_, &FakeHardware::SetFirstActiveOmahaPingSent())); | 
| Don Garrett | 83692e4 | 2013-11-08 10:11:30 -0800 | [diff] [blame] | 78 | } | 
|  | 79 |  | 
| Alex Deymo | 763e7db | 2015-08-27 21:08:08 -0700 | [diff] [blame] | 80 | ~MockHardware() override = default; | 
| Don Garrett | 83692e4 | 2013-11-08 10:11:30 -0800 | [diff] [blame] | 81 |  | 
|  | 82 | // Hardware overrides. | 
| Alex Vakulenko | d0fdfb3 | 2014-02-21 15:26:26 -0800 | [diff] [blame] | 83 | MOCK_CONST_METHOD0(IsOfficialBuild, bool()); | 
|  | 84 | MOCK_CONST_METHOD0(IsNormalBootMode, bool()); | 
| Alex Deymo | 46a9aae | 2016-05-04 20:20:11 -0700 | [diff] [blame] | 85 | MOCK_CONST_METHOD0(IsOOBEEnabled, bool()); | 
| Alex Deymo | bccbc38 | 2014-04-03 13:38:55 -0700 | [diff] [blame] | 86 | MOCK_CONST_METHOD1(IsOOBEComplete, bool(base::Time* out_time_of_oobe)); | 
| Alex Vakulenko | d0fdfb3 | 2014-02-21 15:26:26 -0800 | [diff] [blame] | 87 | MOCK_CONST_METHOD0(GetHardwareClass, std::string()); | 
| Zentaro Kavanagh | baacb98 | 2018-02-20 17:48:39 -0800 | [diff] [blame] | 88 | MOCK_CONST_METHOD0(GetMinKernelKeyVersion, int()); | 
| Marton Hunyady | 99ced78 | 2018-05-08 12:59:50 +0200 | [diff] [blame] | 89 | MOCK_CONST_METHOD0(GetMinFirmwareKeyVersion, int()); | 
| Zentaro Kavanagh | 8f6f243 | 2018-05-16 13:48:12 -0700 | [diff] [blame] | 90 | MOCK_CONST_METHOD0(GetMaxFirmwareKeyRollforward, int()); | 
|  | 91 | MOCK_CONST_METHOD1(SetMaxFirmwareKeyRollforward, | 
|  | 92 | bool(int firmware_max_rollforward)); | 
| Zentaro Kavanagh | baacb98 | 2018-02-20 17:48:39 -0800 | [diff] [blame] | 93 | MOCK_CONST_METHOD1(SetMaxKernelKeyRollforward, | 
| Zentaro Kavanagh | 5d95615 | 2018-05-15 09:40:33 -0700 | [diff] [blame] | 94 | bool(int kernel_max_rollforward)); | 
| Alex Deymo | ebbe7ef | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 95 | MOCK_CONST_METHOD0(GetPowerwashCount, int()); | 
| Alex Deymo | dd132f3 | 2015-09-14 19:12:07 -0700 | [diff] [blame] | 96 | MOCK_CONST_METHOD1(GetNonVolatileDirectory, bool(base::FilePath*)); | 
|  | 97 | MOCK_CONST_METHOD1(GetPowerwashSafeDirectory, bool(base::FilePath*)); | 
| Amin Hassani | 1677e81 | 2017-06-21 13:36:36 -0700 | [diff] [blame] | 98 | MOCK_CONST_METHOD0(GetFirstActiveOmahaPingSent, bool()); | 
| Don Garrett | 83692e4 | 2013-11-08 10:11:30 -0800 | [diff] [blame] | 99 |  | 
|  | 100 | // Returns a reference to the underlying FakeHardware. | 
| Amin Hassani | b268959 | 2019-01-13 17:04:28 -0800 | [diff] [blame] | 101 | FakeHardware& fake() { return fake_; } | 
| Don Garrett | 83692e4 | 2013-11-08 10:11:30 -0800 | [diff] [blame] | 102 |  | 
| Alex Deymo | df632d1 | 2014-04-29 20:04:36 -0700 | [diff] [blame] | 103 | private: | 
| Don Garrett | 83692e4 | 2013-11-08 10:11:30 -0800 | [diff] [blame] | 104 | // The underlying FakeHardware. | 
|  | 105 | FakeHardware fake_; | 
|  | 106 |  | 
|  | 107 | DISALLOW_COPY_AND_ASSIGN(MockHardware); | 
|  | 108 | }; | 
|  | 109 |  | 
| Don Garrett | 83692e4 | 2013-11-08 10:11:30 -0800 | [diff] [blame] | 110 | }  // namespace chromeos_update_engine | 
|  | 111 |  | 
| Alex Deymo | 39910dc | 2015-11-09 17:04:30 -0800 | [diff] [blame] | 112 | #endif  // UPDATE_ENGINE_COMMON_MOCK_HARDWARE_H_ |