blob: 183130fbcc4fc21632634a9aa7a997ecf728c398 [file] [log] [blame]
Alex Deymoaea4c1c2015-08-19 20:24:43 -07001//
2// Copyright (C) 2014 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//
Alex Deymoc705cc82014-02-19 11:15:00 -080016
Gilad Arnold48415f12014-06-27 07:10:58 -070017#ifndef UPDATE_ENGINE_UPDATE_MANAGER_MOCK_POLICY_H_
18#define UPDATE_ENGINE_UPDATE_MANAGER_MOCK_POLICY_H_
19
20#include <string>
Alex Deymoc705cc82014-02-19 11:15:00 -080021
22#include <gmock/gmock.h>
23
Gilad Arnold7fb6e252014-10-29 11:49:19 -070024#include "update_engine/update_manager/default_policy.h"
Alex Deymo63784a52014-05-28 10:46:14 -070025#include "update_engine/update_manager/policy.h"
Alex Deymoc705cc82014-02-19 11:15:00 -080026
Alex Deymo63784a52014-05-28 10:46:14 -070027namespace chromeos_update_manager {
Alex Deymoc705cc82014-02-19 11:15:00 -080028
29// A mocked implementation of Policy.
30class MockPolicy : public Policy {
Alex Deymo0d11c602014-04-23 20:12:20 -070031 public:
Gilad Arnold7fb6e252014-10-29 11:49:19 -070032 explicit MockPolicy(chromeos_update_engine::ClockInterface* clock)
33 : default_policy_(clock) {
34 // We defer to the corresponding DefaultPolicy methods, by default.
Amin Hassani4b717432019-01-14 16:24:20 -080035 ON_CALL(*this,
36 UpdateCheckAllowed(testing::_, testing::_, testing::_, testing::_))
37 .WillByDefault(testing::Invoke(&default_policy_,
38 &DefaultPolicy::UpdateCheckAllowed));
Aaron Wood23bd3392017-10-06 14:48:25 -070039 ON_CALL(*this,
40 UpdateCanBeApplied(
41 testing::_, testing::_, testing::_, testing::_, testing::_))
42 .WillByDefault(testing::Invoke(&default_policy_,
43 &DefaultPolicy::UpdateCanBeApplied));
Amin Hassani4b717432019-01-14 16:24:20 -080044 ON_CALL(*this,
45 UpdateCanStart(
46 testing::_, testing::_, testing::_, testing::_, testing::_))
47 .WillByDefault(
48 testing::Invoke(&default_policy_, &DefaultPolicy::UpdateCanStart));
Gilad Arnold7fb6e252014-10-29 11:49:19 -070049 ON_CALL(*this, P2PEnabled(testing::_, testing::_, testing::_, testing::_))
Amin Hassani4b717432019-01-14 16:24:20 -080050 .WillByDefault(
51 testing::Invoke(&default_policy_, &DefaultPolicy::P2PEnabled));
52 ON_CALL(*this,
53 P2PEnabledChanged(
54 testing::_, testing::_, testing::_, testing::_, testing::_))
55 .WillByDefault(testing::Invoke(&default_policy_,
56 &DefaultPolicy::P2PEnabledChanged));
Gilad Arnold7fb6e252014-10-29 11:49:19 -070057 }
58
59 MockPolicy() : MockPolicy(nullptr) {}
Alex Deymo610277e2014-11-11 21:18:11 -080060 ~MockPolicy() override {}
Alex Deymoc705cc82014-02-19 11:15:00 -080061
62 // Policy overrides.
Amin Hassani4b717432019-01-14 16:24:20 -080063 MOCK_CONST_METHOD4(
64 UpdateCheckAllowed,
65 EvalStatus(EvaluationContext*, State*, std::string*, UpdateCheckParams*));
Alex Deymoc705cc82014-02-19 11:15:00 -080066
Aaron Wood23bd3392017-10-06 14:48:25 -070067 MOCK_CONST_METHOD5(UpdateCanBeApplied,
68 EvalStatus(EvaluationContext*,
69 State*,
70 std::string*,
71 chromeos_update_engine::ErrorCode*,
72 chromeos_update_engine::InstallPlan*));
73
Gilad Arnolddc4bb262014-07-23 10:45:19 -070074 MOCK_CONST_METHOD5(UpdateCanStart,
Amin Hassani4b717432019-01-14 16:24:20 -080075 EvalStatus(EvaluationContext*,
76 State*,
77 std::string*,
78 UpdateDownloadParams*,
79 UpdateState));
Gilad Arnoldaf2f6ae2014-04-28 14:14:52 -070080
Amin Hassani4b717432019-01-14 16:24:20 -080081 MOCK_CONST_METHOD4(
82 UpdateDownloadAllowed,
83 EvalStatus(EvaluationContext*, State*, std::string*, bool*));
Gilad Arnold0adbc942014-05-12 10:35:43 -070084
Amin Hassani4b717432019-01-14 16:24:20 -080085 MOCK_CONST_METHOD4(
86 P2PEnabled, EvalStatus(EvaluationContext*, State*, std::string*, bool*));
Gilad Arnold78ecbfc2014-10-22 14:38:25 -070087
Amin Hassani4b717432019-01-14 16:24:20 -080088 MOCK_CONST_METHOD5(
89 P2PEnabledChanged,
90 EvalStatus(EvaluationContext*, State*, std::string*, bool*, bool));
Gilad Arnold78ecbfc2014-10-22 14:38:25 -070091
Gilad Arnold7fb6e252014-10-29 11:49:19 -070092 protected:
93 // Policy override.
94 std::string PolicyName() const override { return "MockPolicy"; }
95
Alex Deymo0d11c602014-04-23 20:12:20 -070096 private:
Gilad Arnold7fb6e252014-10-29 11:49:19 -070097 DefaultPolicy default_policy_;
98
Alex Deymoc705cc82014-02-19 11:15:00 -080099 DISALLOW_COPY_AND_ASSIGN(MockPolicy);
100};
101
Alex Deymo63784a52014-05-28 10:46:14 -0700102} // namespace chromeos_update_manager
Alex Deymoc705cc82014-02-19 11:15:00 -0800103
Gilad Arnold48415f12014-06-27 07:10:58 -0700104#endif // UPDATE_ENGINE_UPDATE_MANAGER_MOCK_POLICY_H_