blob: 6b5a75e903faae4dd8886d16a5b7fdf8dea46bbd [file] [log] [blame]
David Zeuthen8a3e88b2013-08-06 12:09:09 -07001// Copyright (c) 2013 The Chromium OS Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
Gilad Arnoldcf175a02014-07-10 16:48:47 -07005#ifndef UPDATE_ENGINE_MOCK_P2P_MANAGER_H_
6#define UPDATE_ENGINE_MOCK_P2P_MANAGER_H_
David Zeuthen8a3e88b2013-08-06 12:09:09 -07007
Alex Vakulenkod2779df2014-06-16 13:19:00 -07008#include <string>
9
Alex Deymo04f2b382014-03-21 15:45:17 -070010#include "update_engine/fake_p2p_manager.h"
David Zeuthen8a3e88b2013-08-06 12:09:09 -070011
12#include <gmock/gmock.h>
13
14namespace chromeos_update_engine {
15
16// A mocked, fake implementation of P2PManager.
17class MockP2PManager : public P2PManager {
Alex Vakulenkod2779df2014-06-16 13:19:00 -070018 public:
David Zeuthen8a3e88b2013-08-06 12:09:09 -070019 MockP2PManager() {
20 // Delegate all calls to the fake instance
David Zeuthen92d9c8b2013-09-11 10:58:11 -070021 ON_CALL(*this, SetDevicePolicy(testing::_))
22 .WillByDefault(testing::Invoke(&fake_,
23 &FakeP2PManager::SetDevicePolicy));
David Zeuthen8a3e88b2013-08-06 12:09:09 -070024 ON_CALL(*this, IsP2PEnabled())
25 .WillByDefault(testing::Invoke(&fake_,
26 &FakeP2PManager::IsP2PEnabled));
27 ON_CALL(*this, EnsureP2PRunning())
28 .WillByDefault(testing::Invoke(&fake_,
29 &FakeP2PManager::EnsureP2PRunning));
30 ON_CALL(*this, EnsureP2PNotRunning())
31 .WillByDefault(testing::Invoke(&fake_,
32 &FakeP2PManager::EnsureP2PNotRunning));
33 ON_CALL(*this, PerformHousekeeping())
34 .WillByDefault(testing::Invoke(&fake_,
35 &FakeP2PManager::PerformHousekeeping));
36 ON_CALL(*this, LookupUrlForFile(testing::_, testing::_, testing::_,
37 testing::_))
38 .WillByDefault(testing::Invoke(&fake_,
39 &FakeP2PManager::LookupUrlForFile));
40 ON_CALL(*this, FileShare(testing::_, testing::_))
41 .WillByDefault(testing::Invoke(&fake_,
42 &FakeP2PManager::FileShare));
43 ON_CALL(*this, FileGetPath(testing::_))
44 .WillByDefault(testing::Invoke(&fake_,
45 &FakeP2PManager::FileGetPath));
46 ON_CALL(*this, FileGetSize(testing::_))
47 .WillByDefault(testing::Invoke(&fake_,
48 &FakeP2PManager::FileGetSize));
49 ON_CALL(*this, FileGetExpectedSize(testing::_))
50 .WillByDefault(testing::Invoke(&fake_,
51 &FakeP2PManager::FileGetExpectedSize));
52 ON_CALL(*this, FileGetVisible(testing::_, testing::_))
53 .WillByDefault(testing::Invoke(&fake_,
54 &FakeP2PManager::FileGetVisible));
55 ON_CALL(*this, FileMakeVisible(testing::_))
56 .WillByDefault(testing::Invoke(&fake_,
57 &FakeP2PManager::FileMakeVisible));
58 ON_CALL(*this, CountSharedFiles())
59 .WillByDefault(testing::Invoke(&fake_,
60 &FakeP2PManager::CountSharedFiles));
61 }
62
Alex Deymo610277e2014-11-11 21:18:11 -080063 ~MockP2PManager() override {}
David Zeuthen8a3e88b2013-08-06 12:09:09 -070064
65 // P2PManager overrides.
David Zeuthen92d9c8b2013-09-11 10:58:11 -070066 MOCK_METHOD1(SetDevicePolicy, void(const policy::DevicePolicy*));
David Zeuthen8a3e88b2013-08-06 12:09:09 -070067 MOCK_METHOD0(IsP2PEnabled, bool());
68 MOCK_METHOD0(EnsureP2PRunning, bool());
69 MOCK_METHOD0(EnsureP2PNotRunning, bool());
70 MOCK_METHOD0(PerformHousekeeping, bool());
71 MOCK_METHOD4(LookupUrlForFile, void(const std::string&,
72 size_t,
73 base::TimeDelta,
74 LookupCallback));
75 MOCK_METHOD2(FileShare, bool(const std::string&, size_t));
76 MOCK_METHOD1(FileGetPath, base::FilePath(const std::string&));
77 MOCK_METHOD1(FileGetSize, ssize_t(const std::string&));
78 MOCK_METHOD1(FileGetExpectedSize, ssize_t(const std::string&));
79 MOCK_METHOD2(FileGetVisible, bool(const std::string&, bool*));
80 MOCK_METHOD1(FileMakeVisible, bool(const std::string&));
81 MOCK_METHOD0(CountSharedFiles, int());
82
83 // Returns a reference to the underlying FakeP2PManager.
84 FakeP2PManager& fake() {
85 return fake_;
86 }
87
Alex Vakulenkod2779df2014-06-16 13:19:00 -070088 private:
David Zeuthen8a3e88b2013-08-06 12:09:09 -070089 // The underlying FakeP2PManager.
90 FakeP2PManager fake_;
91
92 DISALLOW_COPY_AND_ASSIGN(MockP2PManager);
93};
94
95} // namespace chromeos_update_engine
96
Gilad Arnoldcf175a02014-07-10 16:48:47 -070097#endif // UPDATE_ENGINE_MOCK_P2P_MANAGER_H_