mock_omaha_request_params.h 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. //
  2. // Copyright (C) 2014 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_MOCK_OMAHA_REQUEST_PARAMS_H_
  17. #define UPDATE_ENGINE_MOCK_OMAHA_REQUEST_PARAMS_H_
  18. #include <string>
  19. #include <gmock/gmock.h>
  20. #include "update_engine/omaha_request_params.h"
  21. namespace chromeos_update_engine {
  22. class MockOmahaRequestParams : public OmahaRequestParams {
  23. public:
  24. explicit MockOmahaRequestParams(SystemState* system_state)
  25. : OmahaRequestParams(system_state) {
  26. // Delegate all calls to the parent instance by default. This helps the
  27. // migration from tests using the real RequestParams when they should have
  28. // use a fake or mock.
  29. ON_CALL(*this, GetAppId())
  30. .WillByDefault(
  31. testing::Invoke(this, &MockOmahaRequestParams::FakeGetAppId));
  32. ON_CALL(*this, SetTargetChannel(testing::_, testing::_, testing::_))
  33. .WillByDefault(testing::Invoke(
  34. this, &MockOmahaRequestParams::FakeSetTargetChannel));
  35. ON_CALL(*this, UpdateDownloadChannel())
  36. .WillByDefault(testing::Invoke(
  37. this, &MockOmahaRequestParams::FakeUpdateDownloadChannel));
  38. ON_CALL(*this, ShouldPowerwash())
  39. .WillByDefault(testing::Invoke(
  40. this, &MockOmahaRequestParams::FakeShouldPowerwash));
  41. }
  42. MOCK_CONST_METHOD0(GetAppId, std::string(void));
  43. MOCK_METHOD3(SetTargetChannel,
  44. bool(const std::string& channel,
  45. bool is_powerwash_allowed,
  46. std::string* error));
  47. MOCK_CONST_METHOD0(target_version_prefix, std::string(void));
  48. MOCK_METHOD0(UpdateDownloadChannel, void(void));
  49. MOCK_CONST_METHOD0(IsUpdateUrlOfficial, bool(void));
  50. MOCK_CONST_METHOD0(ShouldPowerwash, bool(void));
  51. private:
  52. // Wrappers to call the parent class and behave like the real object by
  53. // default. See "Delegating Calls to a Parent Class" in gmock's documentation.
  54. std::string FakeGetAppId() const { return OmahaRequestParams::GetAppId(); }
  55. bool FakeSetTargetChannel(const std::string& channel,
  56. bool is_powerwash_allowed,
  57. std::string* error) {
  58. return OmahaRequestParams::SetTargetChannel(
  59. channel, is_powerwash_allowed, error);
  60. }
  61. void FakeUpdateDownloadChannel() {
  62. return OmahaRequestParams::UpdateDownloadChannel();
  63. }
  64. bool FakeShouldPowerwash() const {
  65. return OmahaRequestParams::ShouldPowerwash();
  66. }
  67. };
  68. } // namespace chromeos_update_engine
  69. #endif // UPDATE_ENGINE_MOCK_OMAHA_REQUEST_PARAMS_H_