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 // 16 17 #ifndef UPDATE_ENGINE_UPDATE_MANAGER_MOCK_POLICY_H_ 18 #define UPDATE_ENGINE_UPDATE_MANAGER_MOCK_POLICY_H_ 19 20 #include <string> 21 22 #include <gmock/gmock.h> 23 24 #include "update_engine/update_manager/default_policy.h" 25 #include "update_engine/update_manager/policy.h" 26 27 namespace chromeos_update_manager { 28 29 // A mocked implementation of Policy. 30 class MockPolicy : public Policy { 31 public: MockPolicy(chromeos_update_engine::ClockInterface * clock)32 explicit MockPolicy(chromeos_update_engine::ClockInterface* clock) 33 : default_policy_(clock) { 34 // We defer to the corresponding DefaultPolicy methods, by default. 35 ON_CALL(*this, UpdateCheckAllowed(testing::_, testing::_, testing::_, 36 testing::_)) 37 .WillByDefault(testing::Invoke( 38 &default_policy_, &DefaultPolicy::UpdateCheckAllowed)); 39 ON_CALL(*this, UpdateCanStart(testing::_, testing::_, testing::_, 40 testing::_, testing::_)) 41 .WillByDefault(testing::Invoke( 42 &default_policy_, &DefaultPolicy::UpdateCanStart)); 43 ON_CALL(*this, UpdateDownloadAllowed(testing::_, testing::_, testing::_, 44 testing::_)) 45 .WillByDefault(testing::Invoke( 46 &default_policy_, &DefaultPolicy::UpdateDownloadAllowed)); 47 ON_CALL(*this, P2PEnabled(testing::_, testing::_, testing::_, testing::_)) 48 .WillByDefault(testing::Invoke( 49 &default_policy_, &DefaultPolicy::P2PEnabled)); 50 ON_CALL(*this, P2PEnabledChanged(testing::_, testing::_, testing::_, 51 testing::_, testing::_)) 52 .WillByDefault(testing::Invoke( 53 &default_policy_, &DefaultPolicy::P2PEnabledChanged)); 54 } 55 MockPolicy()56 MockPolicy() : MockPolicy(nullptr) {} ~MockPolicy()57 ~MockPolicy() override {} 58 59 // Policy overrides. 60 MOCK_CONST_METHOD4(UpdateCheckAllowed, 61 EvalStatus(EvaluationContext*, State*, std::string*, 62 UpdateCheckParams*)); 63 64 MOCK_CONST_METHOD5(UpdateCanStart, 65 EvalStatus(EvaluationContext*, State*, std::string*, 66 UpdateDownloadParams*, UpdateState)); 67 68 MOCK_CONST_METHOD4(UpdateDownloadAllowed, 69 EvalStatus(EvaluationContext*, State*, std::string*, 70 bool*)); 71 72 MOCK_CONST_METHOD4(P2PEnabled, 73 EvalStatus(EvaluationContext*, State*, std::string*, 74 bool*)); 75 76 MOCK_CONST_METHOD5(P2PEnabledChanged, 77 EvalStatus(EvaluationContext*, State*, std::string*, 78 bool*, bool)); 79 80 protected: 81 // Policy override. PolicyName()82 std::string PolicyName() const override { return "MockPolicy"; } 83 84 private: 85 DefaultPolicy default_policy_; 86 87 DISALLOW_COPY_AND_ASSIGN(MockPolicy); 88 }; 89 90 } // namespace chromeos_update_manager 91 92 #endif // UPDATE_ENGINE_UPDATE_MANAGER_MOCK_POLICY_H_ 93