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 17 #ifndef UPDATE_ENGINE_MOCK_P2P_MANAGER_H_ 18 #define UPDATE_ENGINE_MOCK_P2P_MANAGER_H_ 19 20 #include <string> 21 22 #include "update_engine/fake_p2p_manager.h" 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 { 30 public: 31 MockP2PManager() { 32 // Delegate all calls to the fake instance 33 ON_CALL(*this, SetDevicePolicy(testing::_)) 34 .WillByDefault( 35 testing::Invoke(&fake_, &FakeP2PManager::SetDevicePolicy)); 36 ON_CALL(*this, IsP2PEnabled()) 37 .WillByDefault(testing::Invoke(&fake_, &FakeP2PManager::IsP2PEnabled)); 38 ON_CALL(*this, EnsureP2PRunning()) 39 .WillByDefault( 40 testing::Invoke(&fake_, &FakeP2PManager::EnsureP2PRunning)); 41 ON_CALL(*this, EnsureP2PNotRunning()) 42 .WillByDefault( 43 testing::Invoke(&fake_, &FakeP2PManager::EnsureP2PNotRunning)); 44 ON_CALL(*this, PerformHousekeeping()) 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)); 51 ON_CALL(*this, FileShare(testing::_, testing::_)) 52 .WillByDefault(testing::Invoke(&fake_, &FakeP2PManager::FileShare)); 53 ON_CALL(*this, FileGetPath(testing::_)) 54 .WillByDefault(testing::Invoke(&fake_, &FakeP2PManager::FileGetPath)); 55 ON_CALL(*this, FileGetSize(testing::_)) 56 .WillByDefault(testing::Invoke(&fake_, &FakeP2PManager::FileGetSize)); 57 ON_CALL(*this, FileGetExpectedSize(testing::_)) 58 .WillByDefault( 59 testing::Invoke(&fake_, &FakeP2PManager::FileGetExpectedSize)); 60 ON_CALL(*this, FileGetVisible(testing::_, testing::_)) 61 .WillByDefault( 62 testing::Invoke(&fake_, &FakeP2PManager::FileGetVisible)); 63 ON_CALL(*this, FileMakeVisible(testing::_)) 64 .WillByDefault( 65 testing::Invoke(&fake_, &FakeP2PManager::FileMakeVisible)); 66 ON_CALL(*this, CountSharedFiles()) 67 .WillByDefault( 68 testing::Invoke(&fake_, &FakeP2PManager::CountSharedFiles)); 69 } 70 71 ~MockP2PManager() override {} 72 73 // P2PManager overrides. 74 MOCK_METHOD1(SetDevicePolicy, void(const policy::DevicePolicy*)); 75 MOCK_METHOD0(IsP2PEnabled, bool()); 76 MOCK_METHOD0(EnsureP2PRunning, bool()); 77 MOCK_METHOD0(EnsureP2PNotRunning, bool()); 78 MOCK_METHOD0(PerformHousekeeping, bool()); 79 MOCK_METHOD4( 80 LookupUrlForFile, 81 void(const std::string&, size_t, base::TimeDelta, LookupCallback)); 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. 91 FakeP2PManager& fake() { return fake_; } 92 93 private: 94 // The underlying FakeP2PManager. 95 FakeP2PManager fake_; 96 97 DISALLOW_COPY_AND_ASSIGN(MockP2PManager); 98 }; 99 100 } // namespace chromeos_update_engine 101 102 #endif // UPDATE_ENGINE_MOCK_P2P_MANAGER_H_ 103