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 { return &config_provider_; } 50 device_policy_provider()51 FakeDevicePolicyProvider* device_policy_provider() override { 52 return &device_policy_provider_; 53 } 54 random_provider()55 FakeRandomProvider* random_provider() override { return &random_provider_; } 56 shill_provider()57 FakeShillProvider* shill_provider() override { return &shill_provider_; } 58 system_provider()59 FakeSystemProvider* system_provider() override { return &system_provider_; } 60 time_provider()61 FakeTimeProvider* time_provider() override { return &time_provider_; } 62 updater_provider()63 FakeUpdaterProvider* updater_provider() override { 64 return &updater_provider_; 65 } 66 67 private: 68 FakeConfigProvider config_provider_; 69 FakeDevicePolicyProvider device_policy_provider_; 70 FakeRandomProvider random_provider_; 71 FakeShillProvider shill_provider_; 72 FakeSystemProvider system_provider_; 73 FakeTimeProvider time_provider_; 74 FakeUpdaterProvider updater_provider_; 75 76 DISALLOW_COPY_AND_ASSIGN(FakeState); 77 }; 78 79 } // namespace chromeos_update_manager 80 81 #endif // UPDATE_ENGINE_UPDATE_MANAGER_FAKE_STATE_H_ 82