| 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()) | 
 | 34 |       .WillByDefault(testing::Invoke(&fake_, | 
 | 35 |             &FakeHardware::IsOfficialBuild)); | 
 | 36 |     ON_CALL(*this, IsNormalBootMode()) | 
 | 37 |       .WillByDefault(testing::Invoke(&fake_, | 
 | 38 |             &FakeHardware::IsNormalBootMode)); | 
| Sen Jiang | e67bb5b | 2016-06-20 15:53:56 -0700 | [diff] [blame] | 39 |     ON_CALL(*this, AreDevFeaturesEnabled()) | 
 | 40 |       .WillByDefault(testing::Invoke(&fake_, | 
 | 41 |             &FakeHardware::AreDevFeaturesEnabled)); | 
| Alex Deymo | 46a9aae | 2016-05-04 20:20:11 -0700 | [diff] [blame] | 42 |     ON_CALL(*this, IsOOBEEnabled()) | 
 | 43 |       .WillByDefault(testing::Invoke(&fake_, | 
 | 44 |             &FakeHardware::IsOOBEEnabled)); | 
| Alex Deymo | bccbc38 | 2014-04-03 13:38:55 -0700 | [diff] [blame] | 45 |     ON_CALL(*this, IsOOBEComplete(testing::_)) | 
 | 46 |       .WillByDefault(testing::Invoke(&fake_, | 
 | 47 |             &FakeHardware::IsOOBEComplete)); | 
| Don Garrett | 83692e4 | 2013-11-08 10:11:30 -0800 | [diff] [blame] | 48 |     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 Deymo | ebbe7ef | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 57 |     ON_CALL(*this, GetPowerwashCount()) | 
 | 58 |       .WillByDefault(testing::Invoke(&fake_, | 
 | 59 |             &FakeHardware::GetPowerwashCount)); | 
| Alex Deymo | dd132f3 | 2015-09-14 19:12:07 -0700 | [diff] [blame] | 60 |     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)); | 
| Don Garrett | 83692e4 | 2013-11-08 10:11:30 -0800 | [diff] [blame] | 66 |   } | 
 | 67 |  | 
| Alex Deymo | 763e7db | 2015-08-27 21:08:08 -0700 | [diff] [blame] | 68 |   ~MockHardware() override = default; | 
| Don Garrett | 83692e4 | 2013-11-08 10:11:30 -0800 | [diff] [blame] | 69 |  | 
 | 70 |   // Hardware overrides. | 
| Alex Vakulenko | d0fdfb3 | 2014-02-21 15:26:26 -0800 | [diff] [blame] | 71 |   MOCK_CONST_METHOD0(IsOfficialBuild, bool()); | 
 | 72 |   MOCK_CONST_METHOD0(IsNormalBootMode, bool()); | 
| Alex Deymo | 46a9aae | 2016-05-04 20:20:11 -0700 | [diff] [blame] | 73 |   MOCK_CONST_METHOD0(IsOOBEEnabled, bool()); | 
| Alex Deymo | bccbc38 | 2014-04-03 13:38:55 -0700 | [diff] [blame] | 74 |   MOCK_CONST_METHOD1(IsOOBEComplete, bool(base::Time* out_time_of_oobe)); | 
| Alex Vakulenko | d0fdfb3 | 2014-02-21 15:26:26 -0800 | [diff] [blame] | 75 |   MOCK_CONST_METHOD0(GetHardwareClass, std::string()); | 
 | 76 |   MOCK_CONST_METHOD0(GetFirmwareVersion, std::string()); | 
 | 77 |   MOCK_CONST_METHOD0(GetECVersion, std::string()); | 
| Alex Deymo | ebbe7ef | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 78 |   MOCK_CONST_METHOD0(GetPowerwashCount, int()); | 
| Alex Deymo | dd132f3 | 2015-09-14 19:12:07 -0700 | [diff] [blame] | 79 |   MOCK_CONST_METHOD1(GetNonVolatileDirectory, bool(base::FilePath*)); | 
 | 80 |   MOCK_CONST_METHOD1(GetPowerwashSafeDirectory, bool(base::FilePath*)); | 
| Don Garrett | 83692e4 | 2013-11-08 10:11:30 -0800 | [diff] [blame] | 81 |  | 
 | 82 |   // Returns a reference to the underlying FakeHardware. | 
 | 83 |   FakeHardware& fake() { | 
 | 84 |     return fake_; | 
 | 85 |   } | 
 | 86 |  | 
| Alex Deymo | df632d1 | 2014-04-29 20:04:36 -0700 | [diff] [blame] | 87 |  private: | 
| Don Garrett | 83692e4 | 2013-11-08 10:11:30 -0800 | [diff] [blame] | 88 |   // The underlying FakeHardware. | 
 | 89 |   FakeHardware fake_; | 
 | 90 |  | 
 | 91 |   DISALLOW_COPY_AND_ASSIGN(MockHardware); | 
 | 92 | }; | 
 | 93 |  | 
 | 94 |  | 
 | 95 | }  // namespace chromeos_update_engine | 
 | 96 |  | 
| Alex Deymo | 39910dc | 2015-11-09 17:04:30 -0800 | [diff] [blame] | 97 | #endif  // UPDATE_ENGINE_COMMON_MOCK_HARDWARE_H_ |