| Alex Deymo | aea4c1c | 2015-08-19 20:24:43 -0700 | [diff] [blame] | 1 | // | 
|  | 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 Deymo | c705cc8 | 2014-02-19 11:15:00 -0800 | [diff] [blame] | 16 |  | 
| Gilad Arnold | 48415f1 | 2014-06-27 07:10:58 -0700 | [diff] [blame] | 17 | #ifndef UPDATE_ENGINE_UPDATE_MANAGER_MOCK_POLICY_H_ | 
|  | 18 | #define UPDATE_ENGINE_UPDATE_MANAGER_MOCK_POLICY_H_ | 
|  | 19 |  | 
|  | 20 | #include <string> | 
| Alex Deymo | c705cc8 | 2014-02-19 11:15:00 -0800 | [diff] [blame] | 21 |  | 
|  | 22 | #include <gmock/gmock.h> | 
|  | 23 |  | 
| Gilad Arnold | 7fb6e25 | 2014-10-29 11:49:19 -0700 | [diff] [blame] | 24 | #include "update_engine/update_manager/default_policy.h" | 
| Alex Deymo | 63784a5 | 2014-05-28 10:46:14 -0700 | [diff] [blame] | 25 | #include "update_engine/update_manager/policy.h" | 
| Alex Deymo | c705cc8 | 2014-02-19 11:15:00 -0800 | [diff] [blame] | 26 |  | 
| Alex Deymo | 63784a5 | 2014-05-28 10:46:14 -0700 | [diff] [blame] | 27 | namespace chromeos_update_manager { | 
| Alex Deymo | c705cc8 | 2014-02-19 11:15:00 -0800 | [diff] [blame] | 28 |  | 
|  | 29 | // A mocked implementation of Policy. | 
|  | 30 | class MockPolicy : public Policy { | 
| Alex Deymo | 0d11c60 | 2014-04-23 20:12:20 -0700 | [diff] [blame] | 31 | public: | 
| Gilad Arnold | 7fb6e25 | 2014-10-29 11:49:19 -0700 | [diff] [blame] | 32 | explicit MockPolicy(chromeos_update_engine::ClockInterface* clock) | 
|  | 33 | : default_policy_(clock) { | 
|  | 34 | // We defer to the corresponding DefaultPolicy methods, by default. | 
| Amin Hassani | 4b71743 | 2019-01-14 16:24:20 -0800 | [diff] [blame] | 35 | ON_CALL(*this, | 
|  | 36 | UpdateCheckAllowed(testing::_, testing::_, testing::_, testing::_)) | 
|  | 37 | .WillByDefault(testing::Invoke(&default_policy_, | 
|  | 38 | &DefaultPolicy::UpdateCheckAllowed)); | 
| Aaron Wood | 23bd339 | 2017-10-06 14:48:25 -0700 | [diff] [blame] | 39 | ON_CALL(*this, | 
|  | 40 | UpdateCanBeApplied( | 
|  | 41 | testing::_, testing::_, testing::_, testing::_, testing::_)) | 
|  | 42 | .WillByDefault(testing::Invoke(&default_policy_, | 
|  | 43 | &DefaultPolicy::UpdateCanBeApplied)); | 
| Amin Hassani | 4b71743 | 2019-01-14 16:24:20 -0800 | [diff] [blame] | 44 | ON_CALL(*this, | 
|  | 45 | UpdateCanStart( | 
|  | 46 | testing::_, testing::_, testing::_, testing::_, testing::_)) | 
|  | 47 | .WillByDefault( | 
|  | 48 | testing::Invoke(&default_policy_, &DefaultPolicy::UpdateCanStart)); | 
|  | 49 | ON_CALL( | 
|  | 50 | *this, | 
|  | 51 | UpdateDownloadAllowed(testing::_, testing::_, testing::_, testing::_)) | 
|  | 52 | .WillByDefault(testing::Invoke(&default_policy_, | 
|  | 53 | &DefaultPolicy::UpdateDownloadAllowed)); | 
| Gilad Arnold | 7fb6e25 | 2014-10-29 11:49:19 -0700 | [diff] [blame] | 54 | ON_CALL(*this, P2PEnabled(testing::_, testing::_, testing::_, testing::_)) | 
| Amin Hassani | 4b71743 | 2019-01-14 16:24:20 -0800 | [diff] [blame] | 55 | .WillByDefault( | 
|  | 56 | testing::Invoke(&default_policy_, &DefaultPolicy::P2PEnabled)); | 
|  | 57 | ON_CALL(*this, | 
|  | 58 | P2PEnabledChanged( | 
|  | 59 | testing::_, testing::_, testing::_, testing::_, testing::_)) | 
|  | 60 | .WillByDefault(testing::Invoke(&default_policy_, | 
|  | 61 | &DefaultPolicy::P2PEnabledChanged)); | 
| Gilad Arnold | 7fb6e25 | 2014-10-29 11:49:19 -0700 | [diff] [blame] | 62 | } | 
|  | 63 |  | 
|  | 64 | MockPolicy() : MockPolicy(nullptr) {} | 
| Alex Deymo | 610277e | 2014-11-11 21:18:11 -0800 | [diff] [blame] | 65 | ~MockPolicy() override {} | 
| Alex Deymo | c705cc8 | 2014-02-19 11:15:00 -0800 | [diff] [blame] | 66 |  | 
|  | 67 | // Policy overrides. | 
| Amin Hassani | 4b71743 | 2019-01-14 16:24:20 -0800 | [diff] [blame] | 68 | MOCK_CONST_METHOD4( | 
|  | 69 | UpdateCheckAllowed, | 
|  | 70 | EvalStatus(EvaluationContext*, State*, std::string*, UpdateCheckParams*)); | 
| Alex Deymo | c705cc8 | 2014-02-19 11:15:00 -0800 | [diff] [blame] | 71 |  | 
| Aaron Wood | 23bd339 | 2017-10-06 14:48:25 -0700 | [diff] [blame] | 72 | MOCK_CONST_METHOD5(UpdateCanBeApplied, | 
|  | 73 | EvalStatus(EvaluationContext*, | 
|  | 74 | State*, | 
|  | 75 | std::string*, | 
|  | 76 | chromeos_update_engine::ErrorCode*, | 
|  | 77 | chromeos_update_engine::InstallPlan*)); | 
|  | 78 |  | 
| Gilad Arnold | dc4bb26 | 2014-07-23 10:45:19 -0700 | [diff] [blame] | 79 | MOCK_CONST_METHOD5(UpdateCanStart, | 
| Amin Hassani | 4b71743 | 2019-01-14 16:24:20 -0800 | [diff] [blame] | 80 | EvalStatus(EvaluationContext*, | 
|  | 81 | State*, | 
|  | 82 | std::string*, | 
|  | 83 | UpdateDownloadParams*, | 
|  | 84 | UpdateState)); | 
| Gilad Arnold | af2f6ae | 2014-04-28 14:14:52 -0700 | [diff] [blame] | 85 |  | 
| Amin Hassani | 4b71743 | 2019-01-14 16:24:20 -0800 | [diff] [blame] | 86 | MOCK_CONST_METHOD4( | 
|  | 87 | UpdateDownloadAllowed, | 
|  | 88 | EvalStatus(EvaluationContext*, State*, std::string*, bool*)); | 
| Gilad Arnold | 0adbc94 | 2014-05-12 10:35:43 -0700 | [diff] [blame] | 89 |  | 
| Amin Hassani | 4b71743 | 2019-01-14 16:24:20 -0800 | [diff] [blame] | 90 | MOCK_CONST_METHOD4( | 
|  | 91 | P2PEnabled, EvalStatus(EvaluationContext*, State*, std::string*, bool*)); | 
| Gilad Arnold | 78ecbfc | 2014-10-22 14:38:25 -0700 | [diff] [blame] | 92 |  | 
| Amin Hassani | 4b71743 | 2019-01-14 16:24:20 -0800 | [diff] [blame] | 93 | MOCK_CONST_METHOD5( | 
|  | 94 | P2PEnabledChanged, | 
|  | 95 | EvalStatus(EvaluationContext*, State*, std::string*, bool*, bool)); | 
| Gilad Arnold | 78ecbfc | 2014-10-22 14:38:25 -0700 | [diff] [blame] | 96 |  | 
| Gilad Arnold | 7fb6e25 | 2014-10-29 11:49:19 -0700 | [diff] [blame] | 97 | protected: | 
|  | 98 | // Policy override. | 
|  | 99 | std::string PolicyName() const override { return "MockPolicy"; } | 
|  | 100 |  | 
| Alex Deymo | 0d11c60 | 2014-04-23 20:12:20 -0700 | [diff] [blame] | 101 | private: | 
| Gilad Arnold | 7fb6e25 | 2014-10-29 11:49:19 -0700 | [diff] [blame] | 102 | DefaultPolicy default_policy_; | 
|  | 103 |  | 
| Alex Deymo | c705cc8 | 2014-02-19 11:15:00 -0800 | [diff] [blame] | 104 | DISALLOW_COPY_AND_ASSIGN(MockPolicy); | 
|  | 105 | }; | 
|  | 106 |  | 
| Alex Deymo | 63784a5 | 2014-05-28 10:46:14 -0700 | [diff] [blame] | 107 | }  // namespace chromeos_update_manager | 
| Alex Deymo | c705cc8 | 2014-02-19 11:15:00 -0800 | [diff] [blame] | 108 |  | 
| Gilad Arnold | 48415f1 | 2014-06-27 07:10:58 -0700 | [diff] [blame] | 109 | #endif  // UPDATE_ENGINE_UPDATE_MANAGER_MOCK_POLICY_H_ |