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 | |
Gilad Arnold | cf175a0 | 2014-07-10 16:48:47 -0700 | [diff] [blame] | 5 | #ifndef UPDATE_ENGINE_MOCK_P2P_MANAGER_H_ |
| 6 | #define UPDATE_ENGINE_MOCK_P2P_MANAGER_H_ |
David Zeuthen | 8a3e88b | 2013-08-06 12:09:09 -0700 | [diff] [blame] | 7 | |
Alex Vakulenko | d2779df | 2014-06-16 13:19:00 -0700 | [diff] [blame] | 8 | #include <string> |
| 9 | |
Alex Deymo | 04f2b38 | 2014-03-21 15:45:17 -0700 | [diff] [blame] | 10 | #include "update_engine/fake_p2p_manager.h" |
David Zeuthen | 8a3e88b | 2013-08-06 12:09:09 -0700 | [diff] [blame] | 11 | |
| 12 | #include <gmock/gmock.h> |
| 13 | |
| 14 | namespace chromeos_update_engine { |
| 15 | |
| 16 | // A mocked, fake implementation of P2PManager. |
| 17 | class MockP2PManager : public P2PManager { |
Alex Vakulenko | d2779df | 2014-06-16 13:19:00 -0700 | [diff] [blame] | 18 | public: |
David Zeuthen | 8a3e88b | 2013-08-06 12:09:09 -0700 | [diff] [blame] | 19 | MockP2PManager() { |
| 20 | // Delegate all calls to the fake instance |
David Zeuthen | 92d9c8b | 2013-09-11 10:58:11 -0700 | [diff] [blame] | 21 | ON_CALL(*this, SetDevicePolicy(testing::_)) |
| 22 | .WillByDefault(testing::Invoke(&fake_, |
| 23 | &FakeP2PManager::SetDevicePolicy)); |
David Zeuthen | 8a3e88b | 2013-08-06 12:09:09 -0700 | [diff] [blame] | 24 | ON_CALL(*this, IsP2PEnabled()) |
| 25 | .WillByDefault(testing::Invoke(&fake_, |
| 26 | &FakeP2PManager::IsP2PEnabled)); |
| 27 | ON_CALL(*this, EnsureP2PRunning()) |
| 28 | .WillByDefault(testing::Invoke(&fake_, |
| 29 | &FakeP2PManager::EnsureP2PRunning)); |
| 30 | ON_CALL(*this, EnsureP2PNotRunning()) |
| 31 | .WillByDefault(testing::Invoke(&fake_, |
| 32 | &FakeP2PManager::EnsureP2PNotRunning)); |
| 33 | ON_CALL(*this, PerformHousekeeping()) |
| 34 | .WillByDefault(testing::Invoke(&fake_, |
| 35 | &FakeP2PManager::PerformHousekeeping)); |
| 36 | ON_CALL(*this, LookupUrlForFile(testing::_, testing::_, testing::_, |
| 37 | testing::_)) |
| 38 | .WillByDefault(testing::Invoke(&fake_, |
| 39 | &FakeP2PManager::LookupUrlForFile)); |
| 40 | ON_CALL(*this, FileShare(testing::_, testing::_)) |
| 41 | .WillByDefault(testing::Invoke(&fake_, |
| 42 | &FakeP2PManager::FileShare)); |
| 43 | ON_CALL(*this, FileGetPath(testing::_)) |
| 44 | .WillByDefault(testing::Invoke(&fake_, |
| 45 | &FakeP2PManager::FileGetPath)); |
| 46 | ON_CALL(*this, FileGetSize(testing::_)) |
| 47 | .WillByDefault(testing::Invoke(&fake_, |
| 48 | &FakeP2PManager::FileGetSize)); |
| 49 | ON_CALL(*this, FileGetExpectedSize(testing::_)) |
| 50 | .WillByDefault(testing::Invoke(&fake_, |
| 51 | &FakeP2PManager::FileGetExpectedSize)); |
| 52 | ON_CALL(*this, FileGetVisible(testing::_, testing::_)) |
| 53 | .WillByDefault(testing::Invoke(&fake_, |
| 54 | &FakeP2PManager::FileGetVisible)); |
| 55 | ON_CALL(*this, FileMakeVisible(testing::_)) |
| 56 | .WillByDefault(testing::Invoke(&fake_, |
| 57 | &FakeP2PManager::FileMakeVisible)); |
| 58 | ON_CALL(*this, CountSharedFiles()) |
| 59 | .WillByDefault(testing::Invoke(&fake_, |
| 60 | &FakeP2PManager::CountSharedFiles)); |
| 61 | } |
| 62 | |
Alex Deymo | 610277e | 2014-11-11 21:18:11 -0800 | [diff] [blame] | 63 | ~MockP2PManager() override {} |
David Zeuthen | 8a3e88b | 2013-08-06 12:09:09 -0700 | [diff] [blame] | 64 | |
| 65 | // P2PManager overrides. |
David Zeuthen | 92d9c8b | 2013-09-11 10:58:11 -0700 | [diff] [blame] | 66 | MOCK_METHOD1(SetDevicePolicy, void(const policy::DevicePolicy*)); |
David Zeuthen | 8a3e88b | 2013-08-06 12:09:09 -0700 | [diff] [blame] | 67 | MOCK_METHOD0(IsP2PEnabled, bool()); |
| 68 | MOCK_METHOD0(EnsureP2PRunning, bool()); |
| 69 | MOCK_METHOD0(EnsureP2PNotRunning, bool()); |
| 70 | MOCK_METHOD0(PerformHousekeeping, bool()); |
| 71 | MOCK_METHOD4(LookupUrlForFile, void(const std::string&, |
| 72 | size_t, |
| 73 | base::TimeDelta, |
| 74 | LookupCallback)); |
| 75 | MOCK_METHOD2(FileShare, bool(const std::string&, size_t)); |
| 76 | MOCK_METHOD1(FileGetPath, base::FilePath(const std::string&)); |
| 77 | MOCK_METHOD1(FileGetSize, ssize_t(const std::string&)); |
| 78 | MOCK_METHOD1(FileGetExpectedSize, ssize_t(const std::string&)); |
| 79 | MOCK_METHOD2(FileGetVisible, bool(const std::string&, bool*)); |
| 80 | MOCK_METHOD1(FileMakeVisible, bool(const std::string&)); |
| 81 | MOCK_METHOD0(CountSharedFiles, int()); |
| 82 | |
| 83 | // Returns a reference to the underlying FakeP2PManager. |
| 84 | FakeP2PManager& fake() { |
| 85 | return fake_; |
| 86 | } |
| 87 | |
Alex Vakulenko | d2779df | 2014-06-16 13:19:00 -0700 | [diff] [blame] | 88 | private: |
David Zeuthen | 8a3e88b | 2013-08-06 12:09:09 -0700 | [diff] [blame] | 89 | // The underlying FakeP2PManager. |
| 90 | FakeP2PManager fake_; |
| 91 | |
| 92 | DISALLOW_COPY_AND_ASSIGN(MockP2PManager); |
| 93 | }; |
| 94 | |
| 95 | } // namespace chromeos_update_engine |
| 96 | |
Gilad Arnold | cf175a0 | 2014-07-10 16:48:47 -0700 | [diff] [blame] | 97 | #endif // UPDATE_ENGINE_MOCK_P2P_MANAGER_H_ |