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: MockP2PManager()31 MockP2PManager() { 32 // Delegate all calls to the fake instance 33 ON_CALL(*this, SetDevicePolicy(testing::_)) 34 .WillByDefault(testing::Invoke(&fake_, 35 &FakeP2PManager::SetDevicePolicy)); 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 ~MockP2PManager()75 ~MockP2PManager() override {} 76 77 // P2PManager overrides. 78 MOCK_METHOD1(SetDevicePolicy, void(const policy::DevicePolicy*)); 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. fake()96 FakeP2PManager& fake() { 97 return fake_; 98 } 99 100 private: 101 // The underlying FakeP2PManager. 102 FakeP2PManager fake_; 103 104 DISALLOW_COPY_AND_ASSIGN(MockP2PManager); 105 }; 106 107 } // namespace chromeos_update_engine 108 109 #endif // UPDATE_ENGINE_MOCK_P2P_MANAGER_H_ 110