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