1aea4c1cea20dda7ae7e85fc8924a2d784f70d806Alex Deymo// 2aea4c1cea20dda7ae7e85fc8924a2d784f70d806Alex Deymo// Copyright (C) 2013 The Android Open Source Project 3aea4c1cea20dda7ae7e85fc8924a2d784f70d806Alex Deymo// 4aea4c1cea20dda7ae7e85fc8924a2d784f70d806Alex Deymo// Licensed under the Apache License, Version 2.0 (the "License"); 5aea4c1cea20dda7ae7e85fc8924a2d784f70d806Alex Deymo// you may not use this file except in compliance with the License. 6aea4c1cea20dda7ae7e85fc8924a2d784f70d806Alex Deymo// You may obtain a copy of the License at 7aea4c1cea20dda7ae7e85fc8924a2d784f70d806Alex Deymo// 8aea4c1cea20dda7ae7e85fc8924a2d784f70d806Alex Deymo// http://www.apache.org/licenses/LICENSE-2.0 9aea4c1cea20dda7ae7e85fc8924a2d784f70d806Alex Deymo// 10aea4c1cea20dda7ae7e85fc8924a2d784f70d806Alex Deymo// Unless required by applicable law or agreed to in writing, software 11aea4c1cea20dda7ae7e85fc8924a2d784f70d806Alex Deymo// distributed under the License is distributed on an "AS IS" BASIS, 12aea4c1cea20dda7ae7e85fc8924a2d784f70d806Alex Deymo// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13aea4c1cea20dda7ae7e85fc8924a2d784f70d806Alex Deymo// See the License for the specific language governing permissions and 14aea4c1cea20dda7ae7e85fc8924a2d784f70d806Alex Deymo// limitations under the License. 15aea4c1cea20dda7ae7e85fc8924a2d784f70d806Alex Deymo// 168a3e88b436f9fb8bcafd439aa405f71b900d8984David Zeuthen 17cf175a098081f3f0e9ca52d997a7ce1585c14c2dGilad Arnold#ifndef UPDATE_ENGINE_MOCK_P2P_MANAGER_H_ 18cf175a098081f3f0e9ca52d997a7ce1585c14c2dGilad Arnold#define UPDATE_ENGINE_MOCK_P2P_MANAGER_H_ 198a3e88b436f9fb8bcafd439aa405f71b900d8984David Zeuthen 20d2779df63aaad8b65fc5d4badee7dbc9bed7f2b6Alex Vakulenko#include <string> 21d2779df63aaad8b65fc5d4badee7dbc9bed7f2b6Alex Vakulenko 2204f2b380d4707a3903098a7459443c9509745943Alex Deymo#include "update_engine/fake_p2p_manager.h" 238a3e88b436f9fb8bcafd439aa405f71b900d8984David Zeuthen 248a3e88b436f9fb8bcafd439aa405f71b900d8984David Zeuthen#include <gmock/gmock.h> 258a3e88b436f9fb8bcafd439aa405f71b900d8984David Zeuthen 268a3e88b436f9fb8bcafd439aa405f71b900d8984David Zeuthennamespace chromeos_update_engine { 278a3e88b436f9fb8bcafd439aa405f71b900d8984David Zeuthen 288a3e88b436f9fb8bcafd439aa405f71b900d8984David Zeuthen// A mocked, fake implementation of P2PManager. 298a3e88b436f9fb8bcafd439aa405f71b900d8984David Zeuthenclass MockP2PManager : public P2PManager { 30d2779df63aaad8b65fc5d4badee7dbc9bed7f2b6Alex Vakulenko public: 318a3e88b436f9fb8bcafd439aa405f71b900d8984David Zeuthen MockP2PManager() { 328a3e88b436f9fb8bcafd439aa405f71b900d8984David Zeuthen // Delegate all calls to the fake instance 3392d9c8bc5cd418e34944d6fc4bae44e3b4370246David Zeuthen ON_CALL(*this, SetDevicePolicy(testing::_)) 3492d9c8bc5cd418e34944d6fc4bae44e3b4370246David Zeuthen .WillByDefault(testing::Invoke(&fake_, 3592d9c8bc5cd418e34944d6fc4bae44e3b4370246David Zeuthen &FakeP2PManager::SetDevicePolicy)); 368a3e88b436f9fb8bcafd439aa405f71b900d8984David Zeuthen ON_CALL(*this, IsP2PEnabled()) 378a3e88b436f9fb8bcafd439aa405f71b900d8984David Zeuthen .WillByDefault(testing::Invoke(&fake_, 388a3e88b436f9fb8bcafd439aa405f71b900d8984David Zeuthen &FakeP2PManager::IsP2PEnabled)); 398a3e88b436f9fb8bcafd439aa405f71b900d8984David Zeuthen ON_CALL(*this, EnsureP2PRunning()) 408a3e88b436f9fb8bcafd439aa405f71b900d8984David Zeuthen .WillByDefault(testing::Invoke(&fake_, 418a3e88b436f9fb8bcafd439aa405f71b900d8984David Zeuthen &FakeP2PManager::EnsureP2PRunning)); 428a3e88b436f9fb8bcafd439aa405f71b900d8984David Zeuthen ON_CALL(*this, EnsureP2PNotRunning()) 438a3e88b436f9fb8bcafd439aa405f71b900d8984David Zeuthen .WillByDefault(testing::Invoke(&fake_, 448a3e88b436f9fb8bcafd439aa405f71b900d8984David Zeuthen &FakeP2PManager::EnsureP2PNotRunning)); 458a3e88b436f9fb8bcafd439aa405f71b900d8984David Zeuthen ON_CALL(*this, PerformHousekeeping()) 468a3e88b436f9fb8bcafd439aa405f71b900d8984David Zeuthen .WillByDefault(testing::Invoke(&fake_, 478a3e88b436f9fb8bcafd439aa405f71b900d8984David Zeuthen &FakeP2PManager::PerformHousekeeping)); 488a3e88b436f9fb8bcafd439aa405f71b900d8984David Zeuthen ON_CALL(*this, LookupUrlForFile(testing::_, testing::_, testing::_, 498a3e88b436f9fb8bcafd439aa405f71b900d8984David Zeuthen testing::_)) 508a3e88b436f9fb8bcafd439aa405f71b900d8984David Zeuthen .WillByDefault(testing::Invoke(&fake_, 518a3e88b436f9fb8bcafd439aa405f71b900d8984David Zeuthen &FakeP2PManager::LookupUrlForFile)); 528a3e88b436f9fb8bcafd439aa405f71b900d8984David Zeuthen ON_CALL(*this, FileShare(testing::_, testing::_)) 538a3e88b436f9fb8bcafd439aa405f71b900d8984David Zeuthen .WillByDefault(testing::Invoke(&fake_, 548a3e88b436f9fb8bcafd439aa405f71b900d8984David Zeuthen &FakeP2PManager::FileShare)); 558a3e88b436f9fb8bcafd439aa405f71b900d8984David Zeuthen ON_CALL(*this, FileGetPath(testing::_)) 568a3e88b436f9fb8bcafd439aa405f71b900d8984David Zeuthen .WillByDefault(testing::Invoke(&fake_, 578a3e88b436f9fb8bcafd439aa405f71b900d8984David Zeuthen &FakeP2PManager::FileGetPath)); 588a3e88b436f9fb8bcafd439aa405f71b900d8984David Zeuthen ON_CALL(*this, FileGetSize(testing::_)) 598a3e88b436f9fb8bcafd439aa405f71b900d8984David Zeuthen .WillByDefault(testing::Invoke(&fake_, 608a3e88b436f9fb8bcafd439aa405f71b900d8984David Zeuthen &FakeP2PManager::FileGetSize)); 618a3e88b436f9fb8bcafd439aa405f71b900d8984David Zeuthen ON_CALL(*this, FileGetExpectedSize(testing::_)) 628a3e88b436f9fb8bcafd439aa405f71b900d8984David Zeuthen .WillByDefault(testing::Invoke(&fake_, 638a3e88b436f9fb8bcafd439aa405f71b900d8984David Zeuthen &FakeP2PManager::FileGetExpectedSize)); 648a3e88b436f9fb8bcafd439aa405f71b900d8984David Zeuthen ON_CALL(*this, FileGetVisible(testing::_, testing::_)) 658a3e88b436f9fb8bcafd439aa405f71b900d8984David Zeuthen .WillByDefault(testing::Invoke(&fake_, 668a3e88b436f9fb8bcafd439aa405f71b900d8984David Zeuthen &FakeP2PManager::FileGetVisible)); 678a3e88b436f9fb8bcafd439aa405f71b900d8984David Zeuthen ON_CALL(*this, FileMakeVisible(testing::_)) 688a3e88b436f9fb8bcafd439aa405f71b900d8984David Zeuthen .WillByDefault(testing::Invoke(&fake_, 698a3e88b436f9fb8bcafd439aa405f71b900d8984David Zeuthen &FakeP2PManager::FileMakeVisible)); 708a3e88b436f9fb8bcafd439aa405f71b900d8984David Zeuthen ON_CALL(*this, CountSharedFiles()) 718a3e88b436f9fb8bcafd439aa405f71b900d8984David Zeuthen .WillByDefault(testing::Invoke(&fake_, 728a3e88b436f9fb8bcafd439aa405f71b900d8984David Zeuthen &FakeP2PManager::CountSharedFiles)); 738a3e88b436f9fb8bcafd439aa405f71b900d8984David Zeuthen } 748a3e88b436f9fb8bcafd439aa405f71b900d8984David Zeuthen 75610277efc6f7e5239158dfa4bb3b1021804326e0Alex Deymo ~MockP2PManager() override {} 768a3e88b436f9fb8bcafd439aa405f71b900d8984David Zeuthen 778a3e88b436f9fb8bcafd439aa405f71b900d8984David Zeuthen // P2PManager overrides. 7892d9c8bc5cd418e34944d6fc4bae44e3b4370246David Zeuthen MOCK_METHOD1(SetDevicePolicy, void(const policy::DevicePolicy*)); 798a3e88b436f9fb8bcafd439aa405f71b900d8984David Zeuthen MOCK_METHOD0(IsP2PEnabled, bool()); 808a3e88b436f9fb8bcafd439aa405f71b900d8984David Zeuthen MOCK_METHOD0(EnsureP2PRunning, bool()); 818a3e88b436f9fb8bcafd439aa405f71b900d8984David Zeuthen MOCK_METHOD0(EnsureP2PNotRunning, bool()); 828a3e88b436f9fb8bcafd439aa405f71b900d8984David Zeuthen MOCK_METHOD0(PerformHousekeeping, bool()); 838a3e88b436f9fb8bcafd439aa405f71b900d8984David Zeuthen MOCK_METHOD4(LookupUrlForFile, void(const std::string&, 848a3e88b436f9fb8bcafd439aa405f71b900d8984David Zeuthen size_t, 858a3e88b436f9fb8bcafd439aa405f71b900d8984David Zeuthen base::TimeDelta, 868a3e88b436f9fb8bcafd439aa405f71b900d8984David Zeuthen LookupCallback)); 878a3e88b436f9fb8bcafd439aa405f71b900d8984David Zeuthen MOCK_METHOD2(FileShare, bool(const std::string&, size_t)); 888a3e88b436f9fb8bcafd439aa405f71b900d8984David Zeuthen MOCK_METHOD1(FileGetPath, base::FilePath(const std::string&)); 898a3e88b436f9fb8bcafd439aa405f71b900d8984David Zeuthen MOCK_METHOD1(FileGetSize, ssize_t(const std::string&)); 908a3e88b436f9fb8bcafd439aa405f71b900d8984David Zeuthen MOCK_METHOD1(FileGetExpectedSize, ssize_t(const std::string&)); 918a3e88b436f9fb8bcafd439aa405f71b900d8984David Zeuthen MOCK_METHOD2(FileGetVisible, bool(const std::string&, bool*)); 928a3e88b436f9fb8bcafd439aa405f71b900d8984David Zeuthen MOCK_METHOD1(FileMakeVisible, bool(const std::string&)); 938a3e88b436f9fb8bcafd439aa405f71b900d8984David Zeuthen MOCK_METHOD0(CountSharedFiles, int()); 948a3e88b436f9fb8bcafd439aa405f71b900d8984David Zeuthen 958a3e88b436f9fb8bcafd439aa405f71b900d8984David Zeuthen // Returns a reference to the underlying FakeP2PManager. 968a3e88b436f9fb8bcafd439aa405f71b900d8984David Zeuthen FakeP2PManager& fake() { 978a3e88b436f9fb8bcafd439aa405f71b900d8984David Zeuthen return fake_; 988a3e88b436f9fb8bcafd439aa405f71b900d8984David Zeuthen } 998a3e88b436f9fb8bcafd439aa405f71b900d8984David Zeuthen 100d2779df63aaad8b65fc5d4badee7dbc9bed7f2b6Alex Vakulenko private: 1018a3e88b436f9fb8bcafd439aa405f71b900d8984David Zeuthen // The underlying FakeP2PManager. 1028a3e88b436f9fb8bcafd439aa405f71b900d8984David Zeuthen FakeP2PManager fake_; 1038a3e88b436f9fb8bcafd439aa405f71b900d8984David Zeuthen 1048a3e88b436f9fb8bcafd439aa405f71b900d8984David Zeuthen DISALLOW_COPY_AND_ASSIGN(MockP2PManager); 1058a3e88b436f9fb8bcafd439aa405f71b900d8984David Zeuthen}; 1068a3e88b436f9fb8bcafd439aa405f71b900d8984David Zeuthen 1078a3e88b436f9fb8bcafd439aa405f71b900d8984David Zeuthen} // namespace chromeos_update_engine 1088a3e88b436f9fb8bcafd439aa405f71b900d8984David Zeuthen 109cf175a098081f3f0e9ca52d997a7ce1585c14c2dGilad Arnold#endif // UPDATE_ENGINE_MOCK_P2P_MANAGER_H_ 110