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 | 2de23f5 | 2014-02-26 14:30:13 -0800 | [diff] [blame] | 16 | |
Gilad Arnold | 48415f1 | 2014-06-27 07:10:58 -0700 | [diff] [blame] | 17 | #ifndef UPDATE_ENGINE_UPDATE_MANAGER_FAKE_STATE_H_ |
| 18 | #define UPDATE_ENGINE_UPDATE_MANAGER_FAKE_STATE_H_ |
Alex Deymo | 2de23f5 | 2014-02-26 14:30:13 -0800 | [diff] [blame] | 19 | |
Alex Deymo | 63784a5 | 2014-05-28 10:46:14 -0700 | [diff] [blame] | 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" |
Alex Deymo | 2de23f5 | 2014-02-26 14:30:13 -0800 | [diff] [blame] | 28 | |
Alex Deymo | 63784a5 | 2014-05-28 10:46:14 -0700 | [diff] [blame] | 29 | namespace chromeos_update_manager { |
Alex Deymo | 2de23f5 | 2014-02-26 14:30:13 -0800 | [diff] [blame] | 30 | |
Alex Deymo | 94c0616 | 2014-03-21 20:34:46 -0700 | [diff] [blame] | 31 | // A fake State class that creates fake providers for all the providers. |
Alex Deymo | 42c30c3 | 2014-04-24 18:41:18 -0700 | [diff] [blame] | 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. |
Alex Deymo | 2de23f5 | 2014-02-26 14:30:13 -0800 | [diff] [blame] | 41 | class FakeState : public State { |
| 42 | public: |
Alex Deymo | 42c30c3 | 2014-04-24 18:41:18 -0700 | [diff] [blame] | 43 | // Creates and initializes the FakeState using fake providers. |
| 44 | FakeState() {} |
Alex Deymo | 94c0616 | 2014-03-21 20:34:46 -0700 | [diff] [blame] | 45 | |
Alex Deymo | 610277e | 2014-11-11 21:18:11 -0800 | [diff] [blame] | 46 | ~FakeState() override {} |
Alex Deymo | 2de23f5 | 2014-02-26 14:30:13 -0800 | [diff] [blame] | 47 | |
Alex Vakulenko | 072359c | 2014-07-18 11:41:07 -0700 | [diff] [blame] | 48 | // Downcasted getters to access the fake instances during testing. |
Alex Vakulenko | 157fe30 | 2014-08-11 15:59:58 -0700 | [diff] [blame] | 49 | FakeConfigProvider* config_provider() override { |
David Zeuthen | 4e89e2c | 2014-04-24 11:47:00 -0700 | [diff] [blame] | 50 | return &config_provider_; |
Alex Deymo | f9f1263 | 2014-04-17 13:51:26 -0700 | [diff] [blame] | 51 | } |
| 52 | |
Alex Vakulenko | 157fe30 | 2014-08-11 15:59:58 -0700 | [diff] [blame] | 53 | FakeDevicePolicyProvider* device_policy_provider() override { |
David Zeuthen | 4e89e2c | 2014-04-24 11:47:00 -0700 | [diff] [blame] | 54 | return &device_policy_provider_; |
Alex Deymo | c83baf6 | 2014-04-02 17:43:35 -0700 | [diff] [blame] | 55 | } |
Alex Deymo | f9f1263 | 2014-04-17 13:51:26 -0700 | [diff] [blame] | 56 | |
Alex Vakulenko | 157fe30 | 2014-08-11 15:59:58 -0700 | [diff] [blame] | 57 | FakeRandomProvider* random_provider() override { |
David Zeuthen | 4e89e2c | 2014-04-24 11:47:00 -0700 | [diff] [blame] | 58 | return &random_provider_; |
Alex Deymo | 94c0616 | 2014-03-21 20:34:46 -0700 | [diff] [blame] | 59 | } |
Gilad Arnold | ae47a9a | 2014-03-26 12:16:47 -0700 | [diff] [blame] | 60 | |
Alex Vakulenko | 157fe30 | 2014-08-11 15:59:58 -0700 | [diff] [blame] | 61 | FakeShillProvider* shill_provider() override { |
David Zeuthen | 4e89e2c | 2014-04-24 11:47:00 -0700 | [diff] [blame] | 62 | return &shill_provider_; |
Alex Deymo | 94c0616 | 2014-03-21 20:34:46 -0700 | [diff] [blame] | 63 | } |
Gilad Arnold | ae47a9a | 2014-03-26 12:16:47 -0700 | [diff] [blame] | 64 | |
Alex Vakulenko | 157fe30 | 2014-08-11 15:59:58 -0700 | [diff] [blame] | 65 | FakeSystemProvider* system_provider() override { |
David Zeuthen | 4e89e2c | 2014-04-24 11:47:00 -0700 | [diff] [blame] | 66 | return &system_provider_; |
Gilad Arnold | ae47a9a | 2014-03-26 12:16:47 -0700 | [diff] [blame] | 67 | } |
| 68 | |
Alex Vakulenko | 157fe30 | 2014-08-11 15:59:58 -0700 | [diff] [blame] | 69 | FakeTimeProvider* time_provider() override { |
David Zeuthen | 4e89e2c | 2014-04-24 11:47:00 -0700 | [diff] [blame] | 70 | return &time_provider_; |
Alex Deymo | 94c0616 | 2014-03-21 20:34:46 -0700 | [diff] [blame] | 71 | } |
Gilad Arnold | ae47a9a | 2014-03-26 12:16:47 -0700 | [diff] [blame] | 72 | |
Alex Vakulenko | 157fe30 | 2014-08-11 15:59:58 -0700 | [diff] [blame] | 73 | FakeUpdaterProvider* updater_provider() override { |
David Zeuthen | 4e89e2c | 2014-04-24 11:47:00 -0700 | [diff] [blame] | 74 | return &updater_provider_; |
Alex Deymo | 94c0616 | 2014-03-21 20:34:46 -0700 | [diff] [blame] | 75 | } |
| 76 | |
Alex Deymo | 2de23f5 | 2014-02-26 14:30:13 -0800 | [diff] [blame] | 77 | private: |
David Zeuthen | 4e89e2c | 2014-04-24 11:47:00 -0700 | [diff] [blame] | 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_; |
Alex Deymo | 94c0616 | 2014-03-21 20:34:46 -0700 | [diff] [blame] | 85 | |
Alex Deymo | 2de23f5 | 2014-02-26 14:30:13 -0800 | [diff] [blame] | 86 | DISALLOW_COPY_AND_ASSIGN(FakeState); |
| 87 | }; |
| 88 | |
Alex Deymo | 63784a5 | 2014-05-28 10:46:14 -0700 | [diff] [blame] | 89 | } // namespace chromeos_update_manager |
Alex Deymo | 2de23f5 | 2014-02-26 14:30:13 -0800 | [diff] [blame] | 90 | |
Gilad Arnold | 48415f1 | 2014-06-27 07:10:58 -0700 | [diff] [blame] | 91 | #endif // UPDATE_ENGINE_UPDATE_MANAGER_FAKE_STATE_H_ |