mock_p2p_manager.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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_MOCK_P2P_MANAGER_H_
  17. #define UPDATE_ENGINE_MOCK_P2P_MANAGER_H_
  18. #include <string>
  19. #include "update_engine/fake_p2p_manager.h"
  20. #include <gmock/gmock.h>
  21. namespace chromeos_update_engine {
  22. // A mocked, fake implementation of P2PManager.
  23. class MockP2PManager : public P2PManager {
  24. public:
  25. MockP2PManager() {
  26. // Delegate all calls to the fake instance
  27. ON_CALL(*this, SetDevicePolicy(testing::_))
  28. .WillByDefault(
  29. testing::Invoke(&fake_, &FakeP2PManager::SetDevicePolicy));
  30. ON_CALL(*this, IsP2PEnabled())
  31. .WillByDefault(testing::Invoke(&fake_, &FakeP2PManager::IsP2PEnabled));
  32. ON_CALL(*this, EnsureP2PRunning())
  33. .WillByDefault(
  34. testing::Invoke(&fake_, &FakeP2PManager::EnsureP2PRunning));
  35. ON_CALL(*this, EnsureP2PNotRunning())
  36. .WillByDefault(
  37. testing::Invoke(&fake_, &FakeP2PManager::EnsureP2PNotRunning));
  38. ON_CALL(*this, PerformHousekeeping())
  39. .WillByDefault(
  40. testing::Invoke(&fake_, &FakeP2PManager::PerformHousekeeping));
  41. ON_CALL(*this,
  42. LookupUrlForFile(testing::_, testing::_, testing::_, testing::_))
  43. .WillByDefault(
  44. testing::Invoke(&fake_, &FakeP2PManager::LookupUrlForFile));
  45. ON_CALL(*this, FileShare(testing::_, testing::_))
  46. .WillByDefault(testing::Invoke(&fake_, &FakeP2PManager::FileShare));
  47. ON_CALL(*this, FileGetPath(testing::_))
  48. .WillByDefault(testing::Invoke(&fake_, &FakeP2PManager::FileGetPath));
  49. ON_CALL(*this, FileGetSize(testing::_))
  50. .WillByDefault(testing::Invoke(&fake_, &FakeP2PManager::FileGetSize));
  51. ON_CALL(*this, FileGetExpectedSize(testing::_))
  52. .WillByDefault(
  53. testing::Invoke(&fake_, &FakeP2PManager::FileGetExpectedSize));
  54. ON_CALL(*this, FileGetVisible(testing::_, testing::_))
  55. .WillByDefault(
  56. testing::Invoke(&fake_, &FakeP2PManager::FileGetVisible));
  57. ON_CALL(*this, FileMakeVisible(testing::_))
  58. .WillByDefault(
  59. testing::Invoke(&fake_, &FakeP2PManager::FileMakeVisible));
  60. ON_CALL(*this, CountSharedFiles())
  61. .WillByDefault(
  62. testing::Invoke(&fake_, &FakeP2PManager::CountSharedFiles));
  63. }
  64. ~MockP2PManager() override {}
  65. // P2PManager overrides.
  66. MOCK_METHOD1(SetDevicePolicy, void(const policy::DevicePolicy*));
  67. MOCK_METHOD0(IsP2PEnabled, bool());
  68. MOCK_METHOD0(EnsureP2PRunning, bool());
  69. MOCK_METHOD0(EnsureP2PNotRunning, bool());
  70. MOCK_METHOD0(PerformHousekeeping, bool());
  71. MOCK_METHOD4(
  72. LookupUrlForFile,
  73. void(const std::string&, size_t, base::TimeDelta, LookupCallback));
  74. MOCK_METHOD2(FileShare, bool(const std::string&, size_t));
  75. MOCK_METHOD1(FileGetPath, base::FilePath(const std::string&));
  76. MOCK_METHOD1(FileGetSize, ssize_t(const std::string&));
  77. MOCK_METHOD1(FileGetExpectedSize, ssize_t(const std::string&));
  78. MOCK_METHOD2(FileGetVisible, bool(const std::string&, bool*));
  79. MOCK_METHOD1(FileMakeVisible, bool(const std::string&));
  80. MOCK_METHOD0(CountSharedFiles, int());
  81. // Returns a reference to the underlying FakeP2PManager.
  82. FakeP2PManager& fake() { return fake_; }
  83. private:
  84. // The underlying FakeP2PManager.
  85. FakeP2PManager fake_;
  86. DISALLOW_COPY_AND_ASSIGN(MockP2PManager);
  87. };
  88. } // namespace chromeos_update_engine
  89. #endif // UPDATE_ENGINE_MOCK_P2P_MANAGER_H_