David Zeuthen | 8a3e88b | 2013-08-06 12:09:09 -0700 | [diff] [blame^] | 1 | // Copyright (c) 2013 The Chromium OS Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef CHROMEOS_PLATFORM_UPDATE_ENGINE_MOCK_P2P_MANAGER_H__ |
| 6 | #define CHROMEOS_PLATFORM_UPDATE_ENGINE_MOCK_P2P_MANAGER_H__ |
| 7 | |
| 8 | #include "fake_p2p_manager.h" |
| 9 | |
| 10 | #include <gmock/gmock.h> |
| 11 | |
| 12 | namespace chromeos_update_engine { |
| 13 | |
| 14 | // A mocked, fake implementation of P2PManager. |
| 15 | class MockP2PManager : public P2PManager { |
| 16 | public: |
| 17 | MockP2PManager() { |
| 18 | // Delegate all calls to the fake instance |
| 19 | ON_CALL(*this, IsP2PEnabled()) |
| 20 | .WillByDefault(testing::Invoke(&fake_, |
| 21 | &FakeP2PManager::IsP2PEnabled)); |
| 22 | ON_CALL(*this, EnsureP2PRunning()) |
| 23 | .WillByDefault(testing::Invoke(&fake_, |
| 24 | &FakeP2PManager::EnsureP2PRunning)); |
| 25 | ON_CALL(*this, EnsureP2PNotRunning()) |
| 26 | .WillByDefault(testing::Invoke(&fake_, |
| 27 | &FakeP2PManager::EnsureP2PNotRunning)); |
| 28 | ON_CALL(*this, PerformHousekeeping()) |
| 29 | .WillByDefault(testing::Invoke(&fake_, |
| 30 | &FakeP2PManager::PerformHousekeeping)); |
| 31 | ON_CALL(*this, LookupUrlForFile(testing::_, testing::_, testing::_, |
| 32 | testing::_)) |
| 33 | .WillByDefault(testing::Invoke(&fake_, |
| 34 | &FakeP2PManager::LookupUrlForFile)); |
| 35 | ON_CALL(*this, FileShare(testing::_, testing::_)) |
| 36 | .WillByDefault(testing::Invoke(&fake_, |
| 37 | &FakeP2PManager::FileShare)); |
| 38 | ON_CALL(*this, FileGetPath(testing::_)) |
| 39 | .WillByDefault(testing::Invoke(&fake_, |
| 40 | &FakeP2PManager::FileGetPath)); |
| 41 | ON_CALL(*this, FileGetSize(testing::_)) |
| 42 | .WillByDefault(testing::Invoke(&fake_, |
| 43 | &FakeP2PManager::FileGetSize)); |
| 44 | ON_CALL(*this, FileGetExpectedSize(testing::_)) |
| 45 | .WillByDefault(testing::Invoke(&fake_, |
| 46 | &FakeP2PManager::FileGetExpectedSize)); |
| 47 | ON_CALL(*this, FileGetVisible(testing::_, testing::_)) |
| 48 | .WillByDefault(testing::Invoke(&fake_, |
| 49 | &FakeP2PManager::FileGetVisible)); |
| 50 | ON_CALL(*this, FileMakeVisible(testing::_)) |
| 51 | .WillByDefault(testing::Invoke(&fake_, |
| 52 | &FakeP2PManager::FileMakeVisible)); |
| 53 | ON_CALL(*this, CountSharedFiles()) |
| 54 | .WillByDefault(testing::Invoke(&fake_, |
| 55 | &FakeP2PManager::CountSharedFiles)); |
| 56 | } |
| 57 | |
| 58 | virtual ~MockP2PManager() {} |
| 59 | |
| 60 | // P2PManager overrides. |
| 61 | MOCK_METHOD0(IsP2PEnabled, bool()); |
| 62 | MOCK_METHOD0(EnsureP2PRunning, bool()); |
| 63 | MOCK_METHOD0(EnsureP2PNotRunning, bool()); |
| 64 | MOCK_METHOD0(PerformHousekeeping, bool()); |
| 65 | MOCK_METHOD4(LookupUrlForFile, void(const std::string&, |
| 66 | size_t, |
| 67 | base::TimeDelta, |
| 68 | LookupCallback)); |
| 69 | MOCK_METHOD2(FileShare, bool(const std::string&, size_t)); |
| 70 | MOCK_METHOD1(FileGetPath, base::FilePath(const std::string&)); |
| 71 | MOCK_METHOD1(FileGetSize, ssize_t(const std::string&)); |
| 72 | MOCK_METHOD1(FileGetExpectedSize, ssize_t(const std::string&)); |
| 73 | MOCK_METHOD2(FileGetVisible, bool(const std::string&, bool*)); |
| 74 | MOCK_METHOD1(FileMakeVisible, bool(const std::string&)); |
| 75 | MOCK_METHOD0(CountSharedFiles, int()); |
| 76 | |
| 77 | // Returns a reference to the underlying FakeP2PManager. |
| 78 | FakeP2PManager& fake() { |
| 79 | return fake_; |
| 80 | } |
| 81 | |
| 82 | private: |
| 83 | // The underlying FakeP2PManager. |
| 84 | FakeP2PManager fake_; |
| 85 | |
| 86 | DISALLOW_COPY_AND_ASSIGN(MockP2PManager); |
| 87 | }; |
| 88 | |
| 89 | } // namespace chromeos_update_engine |
| 90 | |
| 91 | #endif // CHROMEOS_PLATFORM_UPDATE_ENGINE_MOCK_P2P_MANAGER_H__ |