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