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_FAKE_STATE_H_ 18 #define UPDATE_ENGINE_UPDATE_MANAGER_FAKE_STATE_H_ 19 20 #include "update_engine/update_manager/fake_config_provider.h" 21 #include "update_engine/update_manager/fake_device_policy_provider.h" 22 #include "update_engine/update_manager/fake_random_provider.h" 23 #include "update_engine/update_manager/fake_shill_provider.h" 24 #include "update_engine/update_manager/fake_system_provider.h" 25 #include "update_engine/update_manager/fake_time_provider.h" 26 #include "update_engine/update_manager/fake_updater_provider.h" 27 #include "update_engine/update_manager/state.h" 28 29 namespace chromeos_update_manager { 30 31 // A fake State class that creates fake providers for all the providers. 32 // This fake can be used in unit testing of Policy subclasses. To fake out the 33 // value a variable is exposing, just call FakeVariable<T>::SetValue() on the 34 // variable you fake out. For example: 35 // 36 // FakeState fake_state_; 37 // fake_state_.random_provider_->var_seed()->SetValue(new uint64_t(12345)); 38 // 39 // You can call SetValue more than once and the FakeVariable will take care of 40 // the memory, but only the last value will remain. 41 class FakeState : public State { 42 public: 43 // Creates and initializes the FakeState using fake providers. FakeState()44 FakeState() {} 45 ~FakeState()46 ~FakeState() override {} 47 48 // Downcasted getters to access the fake instances during testing. config_provider()49 FakeConfigProvider* config_provider() override { 50 return &config_provider_; 51 } 52 device_policy_provider()53 FakeDevicePolicyProvider* device_policy_provider() override { 54 return &device_policy_provider_; 55 } 56 random_provider()57 FakeRandomProvider* random_provider() override { 58 return &random_provider_; 59 } 60 shill_provider()61 FakeShillProvider* shill_provider() override { 62 return &shill_provider_; 63 } 64 system_provider()65 FakeSystemProvider* system_provider() override { 66 return &system_provider_; 67 } 68 time_provider()69 FakeTimeProvider* time_provider() override { 70 return &time_provider_; 71 } 72 updater_provider()73 FakeUpdaterProvider* updater_provider() override { 74 return &updater_provider_; 75 } 76 77 private: 78 FakeConfigProvider config_provider_; 79 FakeDevicePolicyProvider device_policy_provider_; 80 FakeRandomProvider random_provider_; 81 FakeShillProvider shill_provider_; 82 FakeSystemProvider system_provider_; 83 FakeTimeProvider time_provider_; 84 FakeUpdaterProvider updater_provider_; 85 86 DISALLOW_COPY_AND_ASSIGN(FakeState); 87 }; 88 89 } // namespace chromeos_update_manager 90 91 #endif // UPDATE_ENGINE_UPDATE_MANAGER_FAKE_STATE_H_ 92