blob: 5f4418eeaae5c3ae30560c05321579206ce653c7 [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::_))
34 .WillByDefault(testing::Invoke(&fake_,
35 &FakeP2PManager::SetDevicePolicy));
David Zeuthen8a3e88b2013-08-06 12:09:09 -070036 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
Alex Deymo610277e2014-11-11 21:18:11 -080075 ~MockP2PManager() override {}
David Zeuthen8a3e88b2013-08-06 12:09:09 -070076
77 // P2PManager overrides.
David Zeuthen92d9c8b2013-09-11 10:58:11 -070078 MOCK_METHOD1(SetDevicePolicy, void(const policy::DevicePolicy*));
David Zeuthen8a3e88b2013-08-06 12:09:09 -070079 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.
96 FakeP2PManager& fake() {
97 return fake_;
98 }
99
Alex Vakulenkod2779df2014-06-16 13:19:00 -0700100 private:
David Zeuthen8a3e88b2013-08-06 12:09:09 -0700101 // The underlying FakeP2PManager.
102 FakeP2PManager fake_;
103
104 DISALLOW_COPY_AND_ASSIGN(MockP2PManager);
105};
106
107} // namespace chromeos_update_engine
108
Gilad Arnoldcf175a02014-07-10 16:48:47 -0700109#endif // UPDATE_ENGINE_MOCK_P2P_MANAGER_H_