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()32 MockPolicy() { 33 // We defer to the corresponding DefaultPolicy methods, by default. 34 ON_CALL(*this, 35 UpdateCheckAllowed(testing::_, testing::_, testing::_, testing::_)) 36 .WillByDefault(testing::Invoke(&default_policy_, 37 &DefaultPolicy::UpdateCheckAllowed)); 38 ON_CALL(*this, 39 UpdateCanBeApplied( 40 testing::_, testing::_, testing::_, testing::_, testing::_)) 41 .WillByDefault(testing::Invoke(&default_policy_, 42 &DefaultPolicy::UpdateCanBeApplied)); 43 ON_CALL(*this, 44 UpdateCanStart( 45 testing::_, testing::_, testing::_, testing::_, testing::_)) 46 .WillByDefault( 47 testing::Invoke(&default_policy_, &DefaultPolicy::UpdateCanStart)); 48 ON_CALL(*this, P2PEnabled(testing::_, testing::_, testing::_, testing::_)) 49 .WillByDefault( 50 testing::Invoke(&default_policy_, &DefaultPolicy::P2PEnabled)); 51 ON_CALL(*this, 52 P2PEnabledChanged( 53 testing::_, testing::_, testing::_, testing::_, testing::_)) 54 .WillByDefault(testing::Invoke(&default_policy_, 55 &DefaultPolicy::P2PEnabledChanged)); 56 } ~MockPolicy()57 ~MockPolicy() override {} 58 59 // Policy overrides. 60 MOCK_CONST_METHOD4( 61 UpdateCheckAllowed, 62 EvalStatus(EvaluationContext*, State*, std::string*, UpdateCheckParams*)); 63 64 MOCK_CONST_METHOD5(UpdateCanBeApplied, 65 EvalStatus(EvaluationContext*, 66 State*, 67 std::string*, 68 chromeos_update_engine::ErrorCode*, 69 chromeos_update_engine::InstallPlan*)); 70 71 MOCK_CONST_METHOD5(UpdateCanStart, 72 EvalStatus(EvaluationContext*, 73 State*, 74 std::string*, 75 UpdateDownloadParams*, 76 UpdateState)); 77 78 MOCK_CONST_METHOD4( 79 UpdateDownloadAllowed, 80 EvalStatus(EvaluationContext*, State*, std::string*, bool*)); 81 82 MOCK_CONST_METHOD4( 83 P2PEnabled, EvalStatus(EvaluationContext*, State*, std::string*, bool*)); 84 85 MOCK_CONST_METHOD5( 86 P2PEnabledChanged, 87 EvalStatus(EvaluationContext*, State*, std::string*, bool*, bool)); 88 89 protected: 90 // Policy override. PolicyName()91 std::string PolicyName() const override { return "MockPolicy"; } 92 93 private: 94 DefaultPolicy default_policy_; 95 96 DISALLOW_COPY_AND_ASSIGN(MockPolicy); 97 }; 98 99 } // namespace chromeos_update_manager 100 101 #endif // UPDATE_ENGINE_UPDATE_MANAGER_MOCK_POLICY_H_ 102