Home | History | Annotate | Download | only in common
      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:
     31   MockHardware() {
     32     // Delegate all calls to the fake instance
     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));
     39     ON_CALL(*this, AreDevFeaturesEnabled())
     40       .WillByDefault(testing::Invoke(&fake_,
     41             &FakeHardware::AreDevFeaturesEnabled));
     42     ON_CALL(*this, IsOOBEEnabled())
     43       .WillByDefault(testing::Invoke(&fake_,
     44             &FakeHardware::IsOOBEEnabled));
     45     ON_CALL(*this, IsOOBEComplete(testing::_))
     46       .WillByDefault(testing::Invoke(&fake_,
     47             &FakeHardware::IsOOBEComplete));
     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));
     57     ON_CALL(*this, GetPowerwashCount())
     58       .WillByDefault(testing::Invoke(&fake_,
     59             &FakeHardware::GetPowerwashCount));
     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));
     66     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()));
     72   }
     73 
     74   ~MockHardware() override = default;
     75 
     76   // Hardware overrides.
     77   MOCK_CONST_METHOD0(IsOfficialBuild, bool());
     78   MOCK_CONST_METHOD0(IsNormalBootMode, bool());
     79   MOCK_CONST_METHOD0(IsOOBEEnabled, bool());
     80   MOCK_CONST_METHOD1(IsOOBEComplete, bool(base::Time* out_time_of_oobe));
     81   MOCK_CONST_METHOD0(GetHardwareClass, std::string());
     82   MOCK_CONST_METHOD0(GetFirmwareVersion, std::string());
     83   MOCK_CONST_METHOD0(GetECVersion, std::string());
     84   MOCK_CONST_METHOD0(GetPowerwashCount, int());
     85   MOCK_CONST_METHOD1(GetNonVolatileDirectory, bool(base::FilePath*));
     86   MOCK_CONST_METHOD1(GetPowerwashSafeDirectory, bool(base::FilePath*));
     87   MOCK_CONST_METHOD0(GetFirstActiveOmahaPingSent, bool());
     88 
     89   // Returns a reference to the underlying FakeHardware.
     90   FakeHardware& fake() {
     91     return fake_;
     92   }
     93 
     94  private:
     95   // The underlying FakeHardware.
     96   FakeHardware fake_;
     97 
     98   DISALLOW_COPY_AND_ASSIGN(MockHardware);
     99 };
    100 
    101 
    102 }  // namespace chromeos_update_engine
    103 
    104 #endif  // UPDATE_ENGINE_COMMON_MOCK_HARDWARE_H_
    105