blob: fd7a88cff903cc1e2faa0133872b7dbaa5d8613b [file] [log] [blame]
Alex Deymoaea4c1c2015-08-19 20:24:43 -07001//
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 Deymo2de23f52014-02-26 14:30:13 -080016
Gilad Arnold48415f12014-06-27 07:10:58 -070017#ifndef UPDATE_ENGINE_UPDATE_MANAGER_FAKE_STATE_H_
18#define UPDATE_ENGINE_UPDATE_MANAGER_FAKE_STATE_H_
Alex Deymo2de23f52014-02-26 14:30:13 -080019
Alex Deymo63784a52014-05-28 10:46:14 -070020#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 Deymo2de23f52014-02-26 14:30:13 -080028
Alex Deymo63784a52014-05-28 10:46:14 -070029namespace chromeos_update_manager {
Alex Deymo2de23f52014-02-26 14:30:13 -080030
Alex Deymo94c06162014-03-21 20:34:46 -070031// A fake State class that creates fake providers for all the providers.
Alex Deymo42c30c32014-04-24 18:41:18 -070032// 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 Deymo2de23f52014-02-26 14:30:13 -080041class FakeState : public State {
42 public:
Alex Deymo42c30c32014-04-24 18:41:18 -070043 // Creates and initializes the FakeState using fake providers.
44 FakeState() {}
Alex Deymo94c06162014-03-21 20:34:46 -070045
Alex Deymo610277e2014-11-11 21:18:11 -080046 ~FakeState() override {}
Alex Deymo2de23f52014-02-26 14:30:13 -080047
Alex Vakulenko072359c2014-07-18 11:41:07 -070048 // Downcasted getters to access the fake instances during testing.
Alex Vakulenko157fe302014-08-11 15:59:58 -070049 FakeConfigProvider* config_provider() override {
David Zeuthen4e89e2c2014-04-24 11:47:00 -070050 return &config_provider_;
Alex Deymof9f12632014-04-17 13:51:26 -070051 }
52
Alex Vakulenko157fe302014-08-11 15:59:58 -070053 FakeDevicePolicyProvider* device_policy_provider() override {
David Zeuthen4e89e2c2014-04-24 11:47:00 -070054 return &device_policy_provider_;
Alex Deymoc83baf62014-04-02 17:43:35 -070055 }
Alex Deymof9f12632014-04-17 13:51:26 -070056
Alex Vakulenko157fe302014-08-11 15:59:58 -070057 FakeRandomProvider* random_provider() override {
David Zeuthen4e89e2c2014-04-24 11:47:00 -070058 return &random_provider_;
Alex Deymo94c06162014-03-21 20:34:46 -070059 }
Gilad Arnoldae47a9a2014-03-26 12:16:47 -070060
Alex Vakulenko157fe302014-08-11 15:59:58 -070061 FakeShillProvider* shill_provider() override {
David Zeuthen4e89e2c2014-04-24 11:47:00 -070062 return &shill_provider_;
Alex Deymo94c06162014-03-21 20:34:46 -070063 }
Gilad Arnoldae47a9a2014-03-26 12:16:47 -070064
Alex Vakulenko157fe302014-08-11 15:59:58 -070065 FakeSystemProvider* system_provider() override {
David Zeuthen4e89e2c2014-04-24 11:47:00 -070066 return &system_provider_;
Gilad Arnoldae47a9a2014-03-26 12:16:47 -070067 }
68
Alex Vakulenko157fe302014-08-11 15:59:58 -070069 FakeTimeProvider* time_provider() override {
David Zeuthen4e89e2c2014-04-24 11:47:00 -070070 return &time_provider_;
Alex Deymo94c06162014-03-21 20:34:46 -070071 }
Gilad Arnoldae47a9a2014-03-26 12:16:47 -070072
Alex Vakulenko157fe302014-08-11 15:59:58 -070073 FakeUpdaterProvider* updater_provider() override {
David Zeuthen4e89e2c2014-04-24 11:47:00 -070074 return &updater_provider_;
Alex Deymo94c06162014-03-21 20:34:46 -070075 }
76
Alex Deymo2de23f52014-02-26 14:30:13 -080077 private:
David Zeuthen4e89e2c2014-04-24 11:47:00 -070078 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 Deymo94c06162014-03-21 20:34:46 -070085
Alex Deymo2de23f52014-02-26 14:30:13 -080086 DISALLOW_COPY_AND_ASSIGN(FakeState);
87};
88
Alex Deymo63784a52014-05-28 10:46:14 -070089} // namespace chromeos_update_manager
Alex Deymo2de23f52014-02-26 14:30:13 -080090
Gilad Arnold48415f12014-06-27 07:10:58 -070091#endif // UPDATE_ENGINE_UPDATE_MANAGER_FAKE_STATE_H_