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, GetMinKernelKeyVersion()) 49 .WillByDefault( 50 testing::Invoke(&fake_, &FakeHardware::GetMinKernelKeyVersion)); 51 ON_CALL(*this, GetMinFirmwareKeyVersion()) 52 .WillByDefault( 53 testing::Invoke(&fake_, &FakeHardware::GetMinFirmwareKeyVersion)); 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)); 60 ON_CALL(*this, SetMaxKernelKeyRollforward()) 61 .WillByDefault( 62 testing::Invoke(&fake_, &FakeHardware::SetMaxKernelKeyRollforward)); 63 ON_CALL(*this, GetPowerwashCount()) 64 .WillByDefault( 65 testing::Invoke(&fake_, &FakeHardware::GetPowerwashCount)); 66 ON_CALL(*this, GetNonVolatileDirectory(testing::_)) 67 .WillByDefault( 68 testing::Invoke(&fake_, &FakeHardware::GetNonVolatileDirectory)); 69 ON_CALL(*this, GetPowerwashSafeDirectory(testing::_)) 70 .WillByDefault( 71 testing::Invoke(&fake_, &FakeHardware::GetPowerwashSafeDirectory)); 72 ON_CALL(*this, GetFirstActiveOmahaPingSent()) 73 .WillByDefault(testing::Invoke( 74 &fake_, &FakeHardware::GetFirstActiveOmahaPingSent())); 75 ON_CALL(*this, SetFirstActiveOmahaPingSent()) 76 .WillByDefault(testing::Invoke( 77 &fake_, &FakeHardware::SetFirstActiveOmahaPingSent())); 78 } 79 80 ~MockHardware() override = default; 81 82 // Hardware overrides. 83 MOCK_CONST_METHOD0(IsOfficialBuild, bool()); 84 MOCK_CONST_METHOD0(IsNormalBootMode, bool()); 85 MOCK_CONST_METHOD0(IsOOBEEnabled, bool()); 86 MOCK_CONST_METHOD1(IsOOBEComplete, bool(base::Time* out_time_of_oobe)); 87 MOCK_CONST_METHOD0(GetHardwareClass, std::string()); 88 MOCK_CONST_METHOD0(GetMinKernelKeyVersion, int()); 89 MOCK_CONST_METHOD0(GetMinFirmwareKeyVersion, int()); 90 MOCK_CONST_METHOD0(GetMaxFirmwareKeyRollforward, int()); 91 MOCK_CONST_METHOD1(SetMaxFirmwareKeyRollforward, 92 bool(int firmware_max_rollforward)); 93 MOCK_CONST_METHOD1(SetMaxKernelKeyRollforward, 94 bool(int kernel_max_rollforward)); 95 MOCK_CONST_METHOD0(GetPowerwashCount, int()); 96 MOCK_CONST_METHOD1(GetNonVolatileDirectory, bool(base::FilePath*)); 97 MOCK_CONST_METHOD1(GetPowerwashSafeDirectory, bool(base::FilePath*)); 98 MOCK_CONST_METHOD0(GetFirstActiveOmahaPingSent, bool()); 99 100 // Returns a reference to the underlying FakeHardware. fake()101 FakeHardware& fake() { return fake_; } 102 103 private: 104 // The underlying FakeHardware. 105 FakeHardware fake_; 106 107 DISALLOW_COPY_AND_ASSIGN(MockHardware); 108 }; 109 110 } // namespace chromeos_update_engine 111 112 #endif // UPDATE_ENGINE_COMMON_MOCK_HARDWARE_H_ 113