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 // 16 17 #ifndef UPDATE_ENGINE_COMMON_MOCK_HARDWARE_H_ 18 #define UPDATE_ENGINE_COMMON_MOCK_HARDWARE_H_ 19 20 #include <string> 21 22 #include "update_engine/common/fake_hardware.h" 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 { 30 public: MockHardware()31 MockHardware() { 32 // Delegate all calls to the fake instance 33 ON_CALL(*this, IsOfficialBuild()) 34 .WillByDefault(testing::Invoke(&fake_, &FakeHardware::IsOfficialBuild)); 35 ON_CALL(*this, IsNormalBootMode()) 36 .WillByDefault( 37 testing::Invoke(&fake_, &FakeHardware::IsNormalBootMode)); 38 ON_CALL(*this, AreDevFeaturesEnabled()) 39 .WillByDefault( 40 testing::Invoke(&fake_, &FakeHardware::AreDevFeaturesEnabled)); 41 ON_CALL(*this, IsOOBEEnabled()) 42 .WillByDefault(testing::Invoke(&fake_, &FakeHardware::IsOOBEEnabled)); 43 ON_CALL(*this, IsOOBEComplete(testing::_)) 44 .WillByDefault(testing::Invoke(&fake_, &FakeHardware::IsOOBEComplete)); 45 ON_CALL(*this, GetHardwareClass()) 46 .WillByDefault( 47 testing::Invoke(&fake_, &FakeHardware::GetHardwareClass)); 48 ON_CALL(*this, GetFirmwareVersion()) 49 .WillByDefault( 50 testing::Invoke(&fake_, &FakeHardware::GetFirmwareVersion)); 51 ON_CALL(*this, GetECVersion()) 52 .WillByDefault(testing::Invoke(&fake_, &FakeHardware::GetECVersion)); 53 ON_CALL(*this, GetMinKernelKeyVersion()) 54 .WillByDefault( 55 testing::Invoke(&fake_, &FakeHardware::GetMinKernelKeyVersion)); 56 ON_CALL(*this, GetMinFirmwareKeyVersion()) 57 .WillByDefault( 58 testing::Invoke(&fake_, &FakeHardware::GetMinFirmwareKeyVersion)); 59 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)); 65 ON_CALL(*this, SetMaxKernelKeyRollforward()) 66 .WillByDefault( 67 testing::Invoke(&fake_, &FakeHardware::SetMaxKernelKeyRollforward)); 68 ON_CALL(*this, GetPowerwashCount()) 69 .WillByDefault( 70 testing::Invoke(&fake_, &FakeHardware::GetPowerwashCount)); 71 ON_CALL(*this, GetNonVolatileDirectory(testing::_)) 72 .WillByDefault( 73 testing::Invoke(&fake_, &FakeHardware::GetNonVolatileDirectory)); 74 ON_CALL(*this, GetPowerwashSafeDirectory(testing::_)) 75 .WillByDefault( 76 testing::Invoke(&fake_, &FakeHardware::GetPowerwashSafeDirectory)); 77 ON_CALL(*this, GetFirstActiveOmahaPingSent()) 78 .WillByDefault(testing::Invoke( 79 &fake_, &FakeHardware::GetFirstActiveOmahaPingSent())); 80 ON_CALL(*this, SetFirstActiveOmahaPingSent()) 81 .WillByDefault(testing::Invoke( 82 &fake_, &FakeHardware::SetFirstActiveOmahaPingSent())); 83 } 84 85 ~MockHardware() override = default; 86 87 // Hardware overrides. 88 MOCK_CONST_METHOD0(IsOfficialBuild, bool()); 89 MOCK_CONST_METHOD0(IsNormalBootMode, bool()); 90 MOCK_CONST_METHOD0(IsOOBEEnabled, bool()); 91 MOCK_CONST_METHOD1(IsOOBEComplete, bool(base::Time* out_time_of_oobe)); 92 MOCK_CONST_METHOD0(GetHardwareClass, std::string()); 93 MOCK_CONST_METHOD0(GetFirmwareVersion, std::string()); 94 MOCK_CONST_METHOD0(GetECVersion, std::string()); 95 MOCK_CONST_METHOD0(GetMinKernelKeyVersion, int()); 96 MOCK_CONST_METHOD0(GetMinFirmwareKeyVersion, int()); 97 MOCK_CONST_METHOD0(GetMaxFirmwareKeyRollforward, int()); 98 MOCK_CONST_METHOD1(SetMaxFirmwareKeyRollforward, 99 bool(int firmware_max_rollforward)); 100 MOCK_CONST_METHOD1(SetMaxKernelKeyRollforward, 101 bool(int kernel_max_rollforward)); 102 MOCK_CONST_METHOD0(GetPowerwashCount, int()); 103 MOCK_CONST_METHOD1(GetNonVolatileDirectory, bool(base::FilePath*)); 104 MOCK_CONST_METHOD1(GetPowerwashSafeDirectory, bool(base::FilePath*)); 105 MOCK_CONST_METHOD0(GetFirstActiveOmahaPingSent, bool()); 106 107 // Returns a reference to the underlying FakeHardware. fake()108 FakeHardware& fake() { return fake_; } 109 110 private: 111 // The underlying FakeHardware. 112 FakeHardware fake_; 113 114 DISALLOW_COPY_AND_ASSIGN(MockHardware); 115 }; 116 117 } // namespace chromeos_update_engine 118 119 #endif // UPDATE_ENGINE_COMMON_MOCK_HARDWARE_H_ 120