blob: 64c9c82821a399d5fe6c2141460c09ffd15f93e5 [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));
Gilad Arnoldccd09572014-10-27 13:37:50 -070061 ON_CALL(*this, SetP2PEnabledPref(testing::_))
62 .WillByDefault(testing::Invoke(&fake_,
63 &FakeP2PManager::SetP2PEnabledPref));
David Zeuthen8a3e88b2013-08-06 12:09:09 -070064 }
65
66 virtual ~MockP2PManager() {}
67
68 // P2PManager overrides.
David Zeuthen92d9c8b2013-09-11 10:58:11 -070069 MOCK_METHOD1(SetDevicePolicy, void(const policy::DevicePolicy*));
David Zeuthen8a3e88b2013-08-06 12:09:09 -070070 MOCK_METHOD0(IsP2PEnabled, bool());
71 MOCK_METHOD0(EnsureP2PRunning, bool());
72 MOCK_METHOD0(EnsureP2PNotRunning, bool());
73 MOCK_METHOD0(PerformHousekeeping, bool());
74 MOCK_METHOD4(LookupUrlForFile, void(const std::string&,
75 size_t,
76 base::TimeDelta,
77 LookupCallback));
78 MOCK_METHOD2(FileShare, bool(const std::string&, size_t));
79 MOCK_METHOD1(FileGetPath, base::FilePath(const std::string&));
80 MOCK_METHOD1(FileGetSize, ssize_t(const std::string&));
81 MOCK_METHOD1(FileGetExpectedSize, ssize_t(const std::string&));
82 MOCK_METHOD2(FileGetVisible, bool(const std::string&, bool*));
83 MOCK_METHOD1(FileMakeVisible, bool(const std::string&));
84 MOCK_METHOD0(CountSharedFiles, int());
Gilad Arnoldccd09572014-10-27 13:37:50 -070085 MOCK_METHOD1(SetP2PEnabledPref, bool(bool));
David Zeuthen8a3e88b2013-08-06 12:09:09 -070086
87 // Returns a reference to the underlying FakeP2PManager.
88 FakeP2PManager& fake() {
89 return fake_;
90 }
91
Alex Vakulenkod2779df2014-06-16 13:19:00 -070092 private:
David Zeuthen8a3e88b2013-08-06 12:09:09 -070093 // The underlying FakeP2PManager.
94 FakeP2PManager fake_;
95
96 DISALLOW_COPY_AND_ASSIGN(MockP2PManager);
97};
98
99} // namespace chromeos_update_engine
100
Gilad Arnoldcf175a02014-07-10 16:48:47 -0700101#endif // UPDATE_ENGINE_MOCK_P2P_MANAGER_H_