blob: fd6703454cd3165f710366faad764a902fd0a98f [file] [log] [blame]
Alex Deymoaea4c1c2015-08-19 20:24:43 -07001//
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 Zeuthen8a3e88b2013-08-06 12:09:09 -070016
Gilad Arnoldcf175a02014-07-10 16:48:47 -070017#ifndef UPDATE_ENGINE_MOCK_P2P_MANAGER_H_
18#define UPDATE_ENGINE_MOCK_P2P_MANAGER_H_
David Zeuthen8a3e88b2013-08-06 12:09:09 -070019
Alex Vakulenkod2779df2014-06-16 13:19:00 -070020#include <string>
21
Alex Deymo04f2b382014-03-21 15:45:17 -070022#include "update_engine/fake_p2p_manager.h"
David Zeuthen8a3e88b2013-08-06 12:09:09 -070023
24#include <gmock/gmock.h>
25
26namespace chromeos_update_engine {
27
28// A mocked, fake implementation of P2PManager.
29class MockP2PManager : public P2PManager {
Alex Vakulenkod2779df2014-06-16 13:19:00 -070030 public:
David Zeuthen8a3e88b2013-08-06 12:09:09 -070031 MockP2PManager() {
32 // Delegate all calls to the fake instance
David Zeuthen92d9c8b2013-09-11 10:58:11 -070033 ON_CALL(*this, SetDevicePolicy(testing::_))
Amin Hassani7cc8bb02019-01-14 16:29:47 -080034 .WillByDefault(
35 testing::Invoke(&fake_, &FakeP2PManager::SetDevicePolicy));
David Zeuthen8a3e88b2013-08-06 12:09:09 -070036 ON_CALL(*this, IsP2PEnabled())
Amin Hassani7cc8bb02019-01-14 16:29:47 -080037 .WillByDefault(testing::Invoke(&fake_, &FakeP2PManager::IsP2PEnabled));
David Zeuthen8a3e88b2013-08-06 12:09:09 -070038 ON_CALL(*this, EnsureP2PRunning())
Amin Hassani7cc8bb02019-01-14 16:29:47 -080039 .WillByDefault(
40 testing::Invoke(&fake_, &FakeP2PManager::EnsureP2PRunning));
David Zeuthen8a3e88b2013-08-06 12:09:09 -070041 ON_CALL(*this, EnsureP2PNotRunning())
Amin Hassani7cc8bb02019-01-14 16:29:47 -080042 .WillByDefault(
43 testing::Invoke(&fake_, &FakeP2PManager::EnsureP2PNotRunning));
David Zeuthen8a3e88b2013-08-06 12:09:09 -070044 ON_CALL(*this, PerformHousekeeping())
Amin Hassani7cc8bb02019-01-14 16:29:47 -080045 .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));
David Zeuthen8a3e88b2013-08-06 12:09:09 -070051 ON_CALL(*this, FileShare(testing::_, testing::_))
Amin Hassani7cc8bb02019-01-14 16:29:47 -080052 .WillByDefault(testing::Invoke(&fake_, &FakeP2PManager::FileShare));
David Zeuthen8a3e88b2013-08-06 12:09:09 -070053 ON_CALL(*this, FileGetPath(testing::_))
Amin Hassani7cc8bb02019-01-14 16:29:47 -080054 .WillByDefault(testing::Invoke(&fake_, &FakeP2PManager::FileGetPath));
David Zeuthen8a3e88b2013-08-06 12:09:09 -070055 ON_CALL(*this, FileGetSize(testing::_))
Amin Hassani7cc8bb02019-01-14 16:29:47 -080056 .WillByDefault(testing::Invoke(&fake_, &FakeP2PManager::FileGetSize));
David Zeuthen8a3e88b2013-08-06 12:09:09 -070057 ON_CALL(*this, FileGetExpectedSize(testing::_))
Amin Hassani7cc8bb02019-01-14 16:29:47 -080058 .WillByDefault(
59 testing::Invoke(&fake_, &FakeP2PManager::FileGetExpectedSize));
David Zeuthen8a3e88b2013-08-06 12:09:09 -070060 ON_CALL(*this, FileGetVisible(testing::_, testing::_))
Amin Hassani7cc8bb02019-01-14 16:29:47 -080061 .WillByDefault(
62 testing::Invoke(&fake_, &FakeP2PManager::FileGetVisible));
David Zeuthen8a3e88b2013-08-06 12:09:09 -070063 ON_CALL(*this, FileMakeVisible(testing::_))
Amin Hassani7cc8bb02019-01-14 16:29:47 -080064 .WillByDefault(
65 testing::Invoke(&fake_, &FakeP2PManager::FileMakeVisible));
David Zeuthen8a3e88b2013-08-06 12:09:09 -070066 ON_CALL(*this, CountSharedFiles())
Amin Hassani7cc8bb02019-01-14 16:29:47 -080067 .WillByDefault(
68 testing::Invoke(&fake_, &FakeP2PManager::CountSharedFiles));
David Zeuthen8a3e88b2013-08-06 12:09:09 -070069 }
70
Alex Deymo610277e2014-11-11 21:18:11 -080071 ~MockP2PManager() override {}
David Zeuthen8a3e88b2013-08-06 12:09:09 -070072
73 // P2PManager overrides.
David Zeuthen92d9c8b2013-09-11 10:58:11 -070074 MOCK_METHOD1(SetDevicePolicy, void(const policy::DevicePolicy*));
David Zeuthen8a3e88b2013-08-06 12:09:09 -070075 MOCK_METHOD0(IsP2PEnabled, bool());
76 MOCK_METHOD0(EnsureP2PRunning, bool());
77 MOCK_METHOD0(EnsureP2PNotRunning, bool());
78 MOCK_METHOD0(PerformHousekeeping, bool());
Amin Hassani7cc8bb02019-01-14 16:29:47 -080079 MOCK_METHOD4(
80 LookupUrlForFile,
81 void(const std::string&, size_t, base::TimeDelta, LookupCallback));
David Zeuthen8a3e88b2013-08-06 12:09:09 -070082 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.
Amin Hassani7cc8bb02019-01-14 16:29:47 -080091 FakeP2PManager& fake() { return fake_; }
David Zeuthen8a3e88b2013-08-06 12:09:09 -070092
Alex Vakulenkod2779df2014-06-16 13:19:00 -070093 private:
David Zeuthen8a3e88b2013-08-06 12:09:09 -070094 // The underlying FakeP2PManager.
95 FakeP2PManager fake_;
96
97 DISALLOW_COPY_AND_ASSIGN(MockP2PManager);
98};
99
100} // namespace chromeos_update_engine
101
Gilad Arnoldcf175a02014-07-10 16:48:47 -0700102#endif // UPDATE_ENGINE_MOCK_P2P_MANAGER_H_