blob: 4d2e9f3e924b1d17e0cc67bb6aed2616c3e3c0c8 [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
Alex Deymo759c2752014-03-17 21:09:36 -07005#ifndef CHROMEOS_PLATFORM_UPDATE_ENGINE_MOCK_P2P_MANAGER_H_
6#define CHROMEOS_PLATFORM_UPDATE_ENGINE_MOCK_P2P_MANAGER_H_
David Zeuthen8a3e88b2013-08-06 12:09:09 -07007
Alex Deymo04f2b382014-03-21 15:45:17 -07008#include "update_engine/fake_p2p_manager.h"
David Zeuthen8a3e88b2013-08-06 12:09:09 -07009
10#include <gmock/gmock.h>
11
12namespace chromeos_update_engine {
13
14// A mocked, fake implementation of P2PManager.
15class MockP2PManager : public P2PManager {
16public:
17 MockP2PManager() {
18 // Delegate all calls to the fake instance
David Zeuthen92d9c8b2013-09-11 10:58:11 -070019 ON_CALL(*this, SetDevicePolicy(testing::_))
20 .WillByDefault(testing::Invoke(&fake_,
21 &FakeP2PManager::SetDevicePolicy));
David Zeuthen8a3e88b2013-08-06 12:09:09 -070022 ON_CALL(*this, IsP2PEnabled())
23 .WillByDefault(testing::Invoke(&fake_,
24 &FakeP2PManager::IsP2PEnabled));
25 ON_CALL(*this, EnsureP2PRunning())
26 .WillByDefault(testing::Invoke(&fake_,
27 &FakeP2PManager::EnsureP2PRunning));
28 ON_CALL(*this, EnsureP2PNotRunning())
29 .WillByDefault(testing::Invoke(&fake_,
30 &FakeP2PManager::EnsureP2PNotRunning));
31 ON_CALL(*this, PerformHousekeeping())
32 .WillByDefault(testing::Invoke(&fake_,
33 &FakeP2PManager::PerformHousekeeping));
34 ON_CALL(*this, LookupUrlForFile(testing::_, testing::_, testing::_,
35 testing::_))
36 .WillByDefault(testing::Invoke(&fake_,
37 &FakeP2PManager::LookupUrlForFile));
38 ON_CALL(*this, FileShare(testing::_, testing::_))
39 .WillByDefault(testing::Invoke(&fake_,
40 &FakeP2PManager::FileShare));
41 ON_CALL(*this, FileGetPath(testing::_))
42 .WillByDefault(testing::Invoke(&fake_,
43 &FakeP2PManager::FileGetPath));
44 ON_CALL(*this, FileGetSize(testing::_))
45 .WillByDefault(testing::Invoke(&fake_,
46 &FakeP2PManager::FileGetSize));
47 ON_CALL(*this, FileGetExpectedSize(testing::_))
48 .WillByDefault(testing::Invoke(&fake_,
49 &FakeP2PManager::FileGetExpectedSize));
50 ON_CALL(*this, FileGetVisible(testing::_, testing::_))
51 .WillByDefault(testing::Invoke(&fake_,
52 &FakeP2PManager::FileGetVisible));
53 ON_CALL(*this, FileMakeVisible(testing::_))
54 .WillByDefault(testing::Invoke(&fake_,
55 &FakeP2PManager::FileMakeVisible));
56 ON_CALL(*this, CountSharedFiles())
57 .WillByDefault(testing::Invoke(&fake_,
58 &FakeP2PManager::CountSharedFiles));
59 }
60
61 virtual ~MockP2PManager() {}
62
63 // P2PManager overrides.
David Zeuthen92d9c8b2013-09-11 10:58:11 -070064 MOCK_METHOD1(SetDevicePolicy, void(const policy::DevicePolicy*));
David Zeuthen8a3e88b2013-08-06 12:09:09 -070065 MOCK_METHOD0(IsP2PEnabled, bool());
66 MOCK_METHOD0(EnsureP2PRunning, bool());
67 MOCK_METHOD0(EnsureP2PNotRunning, bool());
68 MOCK_METHOD0(PerformHousekeeping, bool());
69 MOCK_METHOD4(LookupUrlForFile, void(const std::string&,
70 size_t,
71 base::TimeDelta,
72 LookupCallback));
73 MOCK_METHOD2(FileShare, bool(const std::string&, size_t));
74 MOCK_METHOD1(FileGetPath, base::FilePath(const std::string&));
75 MOCK_METHOD1(FileGetSize, ssize_t(const std::string&));
76 MOCK_METHOD1(FileGetExpectedSize, ssize_t(const std::string&));
77 MOCK_METHOD2(FileGetVisible, bool(const std::string&, bool*));
78 MOCK_METHOD1(FileMakeVisible, bool(const std::string&));
79 MOCK_METHOD0(CountSharedFiles, int());
80
81 // Returns a reference to the underlying FakeP2PManager.
82 FakeP2PManager& fake() {
83 return fake_;
84 }
85
86private:
87 // The underlying FakeP2PManager.
88 FakeP2PManager fake_;
89
90 DISALLOW_COPY_AND_ASSIGN(MockP2PManager);
91};
92
93} // namespace chromeos_update_engine
94
Alex Deymo759c2752014-03-17 21:09:36 -070095#endif // CHROMEOS_PLATFORM_UPDATE_ENGINE_MOCK_P2P_MANAGER_H_