mock_p2p_manager.h revision 8a3e88b436f9fb8bcafd439aa405f71b900d8984
18a3e88b436f9fb8bcafd439aa405f71b900d8984David Zeuthen// Copyright (c) 2013 The Chromium OS Authors. All rights reserved. 28a3e88b436f9fb8bcafd439aa405f71b900d8984David Zeuthen// Use of this source code is governed by a BSD-style license that can be 38a3e88b436f9fb8bcafd439aa405f71b900d8984David Zeuthen// found in the LICENSE file. 48a3e88b436f9fb8bcafd439aa405f71b900d8984David Zeuthen 58a3e88b436f9fb8bcafd439aa405f71b900d8984David Zeuthen#ifndef CHROMEOS_PLATFORM_UPDATE_ENGINE_MOCK_P2P_MANAGER_H__ 68a3e88b436f9fb8bcafd439aa405f71b900d8984David Zeuthen#define CHROMEOS_PLATFORM_UPDATE_ENGINE_MOCK_P2P_MANAGER_H__ 78a3e88b436f9fb8bcafd439aa405f71b900d8984David Zeuthen 88a3e88b436f9fb8bcafd439aa405f71b900d8984David Zeuthen#include "fake_p2p_manager.h" 98a3e88b436f9fb8bcafd439aa405f71b900d8984David Zeuthen 108a3e88b436f9fb8bcafd439aa405f71b900d8984David Zeuthen#include <gmock/gmock.h> 118a3e88b436f9fb8bcafd439aa405f71b900d8984David Zeuthen 128a3e88b436f9fb8bcafd439aa405f71b900d8984David Zeuthennamespace chromeos_update_engine { 138a3e88b436f9fb8bcafd439aa405f71b900d8984David Zeuthen 148a3e88b436f9fb8bcafd439aa405f71b900d8984David Zeuthen// A mocked, fake implementation of P2PManager. 158a3e88b436f9fb8bcafd439aa405f71b900d8984David Zeuthenclass MockP2PManager : public P2PManager { 168a3e88b436f9fb8bcafd439aa405f71b900d8984David Zeuthenpublic: 178a3e88b436f9fb8bcafd439aa405f71b900d8984David Zeuthen MockP2PManager() { 188a3e88b436f9fb8bcafd439aa405f71b900d8984David Zeuthen // Delegate all calls to the fake instance 198a3e88b436f9fb8bcafd439aa405f71b900d8984David Zeuthen ON_CALL(*this, IsP2PEnabled()) 208a3e88b436f9fb8bcafd439aa405f71b900d8984David Zeuthen .WillByDefault(testing::Invoke(&fake_, 218a3e88b436f9fb8bcafd439aa405f71b900d8984David Zeuthen &FakeP2PManager::IsP2PEnabled)); 228a3e88b436f9fb8bcafd439aa405f71b900d8984David Zeuthen ON_CALL(*this, EnsureP2PRunning()) 238a3e88b436f9fb8bcafd439aa405f71b900d8984David Zeuthen .WillByDefault(testing::Invoke(&fake_, 248a3e88b436f9fb8bcafd439aa405f71b900d8984David Zeuthen &FakeP2PManager::EnsureP2PRunning)); 258a3e88b436f9fb8bcafd439aa405f71b900d8984David Zeuthen ON_CALL(*this, EnsureP2PNotRunning()) 268a3e88b436f9fb8bcafd439aa405f71b900d8984David Zeuthen .WillByDefault(testing::Invoke(&fake_, 278a3e88b436f9fb8bcafd439aa405f71b900d8984David Zeuthen &FakeP2PManager::EnsureP2PNotRunning)); 288a3e88b436f9fb8bcafd439aa405f71b900d8984David Zeuthen ON_CALL(*this, PerformHousekeeping()) 298a3e88b436f9fb8bcafd439aa405f71b900d8984David Zeuthen .WillByDefault(testing::Invoke(&fake_, 308a3e88b436f9fb8bcafd439aa405f71b900d8984David Zeuthen &FakeP2PManager::PerformHousekeeping)); 318a3e88b436f9fb8bcafd439aa405f71b900d8984David Zeuthen ON_CALL(*this, LookupUrlForFile(testing::_, testing::_, testing::_, 328a3e88b436f9fb8bcafd439aa405f71b900d8984David Zeuthen testing::_)) 338a3e88b436f9fb8bcafd439aa405f71b900d8984David Zeuthen .WillByDefault(testing::Invoke(&fake_, 348a3e88b436f9fb8bcafd439aa405f71b900d8984David Zeuthen &FakeP2PManager::LookupUrlForFile)); 358a3e88b436f9fb8bcafd439aa405f71b900d8984David Zeuthen ON_CALL(*this, FileShare(testing::_, testing::_)) 368a3e88b436f9fb8bcafd439aa405f71b900d8984David Zeuthen .WillByDefault(testing::Invoke(&fake_, 378a3e88b436f9fb8bcafd439aa405f71b900d8984David Zeuthen &FakeP2PManager::FileShare)); 388a3e88b436f9fb8bcafd439aa405f71b900d8984David Zeuthen ON_CALL(*this, FileGetPath(testing::_)) 398a3e88b436f9fb8bcafd439aa405f71b900d8984David Zeuthen .WillByDefault(testing::Invoke(&fake_, 408a3e88b436f9fb8bcafd439aa405f71b900d8984David Zeuthen &FakeP2PManager::FileGetPath)); 418a3e88b436f9fb8bcafd439aa405f71b900d8984David Zeuthen ON_CALL(*this, FileGetSize(testing::_)) 428a3e88b436f9fb8bcafd439aa405f71b900d8984David Zeuthen .WillByDefault(testing::Invoke(&fake_, 438a3e88b436f9fb8bcafd439aa405f71b900d8984David Zeuthen &FakeP2PManager::FileGetSize)); 448a3e88b436f9fb8bcafd439aa405f71b900d8984David Zeuthen ON_CALL(*this, FileGetExpectedSize(testing::_)) 458a3e88b436f9fb8bcafd439aa405f71b900d8984David Zeuthen .WillByDefault(testing::Invoke(&fake_, 468a3e88b436f9fb8bcafd439aa405f71b900d8984David Zeuthen &FakeP2PManager::FileGetExpectedSize)); 478a3e88b436f9fb8bcafd439aa405f71b900d8984David Zeuthen ON_CALL(*this, FileGetVisible(testing::_, testing::_)) 488a3e88b436f9fb8bcafd439aa405f71b900d8984David Zeuthen .WillByDefault(testing::Invoke(&fake_, 498a3e88b436f9fb8bcafd439aa405f71b900d8984David Zeuthen &FakeP2PManager::FileGetVisible)); 508a3e88b436f9fb8bcafd439aa405f71b900d8984David Zeuthen ON_CALL(*this, FileMakeVisible(testing::_)) 518a3e88b436f9fb8bcafd439aa405f71b900d8984David Zeuthen .WillByDefault(testing::Invoke(&fake_, 528a3e88b436f9fb8bcafd439aa405f71b900d8984David Zeuthen &FakeP2PManager::FileMakeVisible)); 538a3e88b436f9fb8bcafd439aa405f71b900d8984David Zeuthen ON_CALL(*this, CountSharedFiles()) 548a3e88b436f9fb8bcafd439aa405f71b900d8984David Zeuthen .WillByDefault(testing::Invoke(&fake_, 558a3e88b436f9fb8bcafd439aa405f71b900d8984David Zeuthen &FakeP2PManager::CountSharedFiles)); 568a3e88b436f9fb8bcafd439aa405f71b900d8984David Zeuthen } 578a3e88b436f9fb8bcafd439aa405f71b900d8984David Zeuthen 588a3e88b436f9fb8bcafd439aa405f71b900d8984David Zeuthen virtual ~MockP2PManager() {} 598a3e88b436f9fb8bcafd439aa405f71b900d8984David Zeuthen 608a3e88b436f9fb8bcafd439aa405f71b900d8984David Zeuthen // P2PManager overrides. 618a3e88b436f9fb8bcafd439aa405f71b900d8984David Zeuthen MOCK_METHOD0(IsP2PEnabled, bool()); 628a3e88b436f9fb8bcafd439aa405f71b900d8984David Zeuthen MOCK_METHOD0(EnsureP2PRunning, bool()); 638a3e88b436f9fb8bcafd439aa405f71b900d8984David Zeuthen MOCK_METHOD0(EnsureP2PNotRunning, bool()); 648a3e88b436f9fb8bcafd439aa405f71b900d8984David Zeuthen MOCK_METHOD0(PerformHousekeeping, bool()); 658a3e88b436f9fb8bcafd439aa405f71b900d8984David Zeuthen MOCK_METHOD4(LookupUrlForFile, void(const std::string&, 668a3e88b436f9fb8bcafd439aa405f71b900d8984David Zeuthen size_t, 678a3e88b436f9fb8bcafd439aa405f71b900d8984David Zeuthen base::TimeDelta, 688a3e88b436f9fb8bcafd439aa405f71b900d8984David Zeuthen LookupCallback)); 698a3e88b436f9fb8bcafd439aa405f71b900d8984David Zeuthen MOCK_METHOD2(FileShare, bool(const std::string&, size_t)); 708a3e88b436f9fb8bcafd439aa405f71b900d8984David Zeuthen MOCK_METHOD1(FileGetPath, base::FilePath(const std::string&)); 718a3e88b436f9fb8bcafd439aa405f71b900d8984David Zeuthen MOCK_METHOD1(FileGetSize, ssize_t(const std::string&)); 728a3e88b436f9fb8bcafd439aa405f71b900d8984David Zeuthen MOCK_METHOD1(FileGetExpectedSize, ssize_t(const std::string&)); 738a3e88b436f9fb8bcafd439aa405f71b900d8984David Zeuthen MOCK_METHOD2(FileGetVisible, bool(const std::string&, bool*)); 748a3e88b436f9fb8bcafd439aa405f71b900d8984David Zeuthen MOCK_METHOD1(FileMakeVisible, bool(const std::string&)); 758a3e88b436f9fb8bcafd439aa405f71b900d8984David Zeuthen MOCK_METHOD0(CountSharedFiles, int()); 768a3e88b436f9fb8bcafd439aa405f71b900d8984David Zeuthen 778a3e88b436f9fb8bcafd439aa405f71b900d8984David Zeuthen // Returns a reference to the underlying FakeP2PManager. 788a3e88b436f9fb8bcafd439aa405f71b900d8984David Zeuthen FakeP2PManager& fake() { 798a3e88b436f9fb8bcafd439aa405f71b900d8984David Zeuthen return fake_; 808a3e88b436f9fb8bcafd439aa405f71b900d8984David Zeuthen } 818a3e88b436f9fb8bcafd439aa405f71b900d8984David Zeuthen 828a3e88b436f9fb8bcafd439aa405f71b900d8984David Zeuthenprivate: 838a3e88b436f9fb8bcafd439aa405f71b900d8984David Zeuthen // The underlying FakeP2PManager. 848a3e88b436f9fb8bcafd439aa405f71b900d8984David Zeuthen FakeP2PManager fake_; 858a3e88b436f9fb8bcafd439aa405f71b900d8984David Zeuthen 868a3e88b436f9fb8bcafd439aa405f71b900d8984David Zeuthen DISALLOW_COPY_AND_ASSIGN(MockP2PManager); 878a3e88b436f9fb8bcafd439aa405f71b900d8984David Zeuthen}; 888a3e88b436f9fb8bcafd439aa405f71b900d8984David Zeuthen 898a3e88b436f9fb8bcafd439aa405f71b900d8984David Zeuthen} // namespace chromeos_update_engine 908a3e88b436f9fb8bcafd439aa405f71b900d8984David Zeuthen 918a3e88b436f9fb8bcafd439aa405f71b900d8984David Zeuthen#endif // CHROMEOS_PLATFORM_UPDATE_ENGINE_MOCK_P2P_MANAGER_H__ 92