mock_hardware.h 4.8 KB

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