blob: 0fd584fecc3f3dc1d60a75274c44931fcd833338 [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.
Amin Hassani4b717432019-01-14 16:24:20 -080049 FakeConfigProvider* config_provider() override { return &config_provider_; }
Alex Deymof9f12632014-04-17 13:51:26 -070050
Alex Vakulenko157fe302014-08-11 15:59:58 -070051 FakeDevicePolicyProvider* device_policy_provider() override {
David Zeuthen4e89e2c2014-04-24 11:47:00 -070052 return &device_policy_provider_;
Alex Deymoc83baf62014-04-02 17:43:35 -070053 }
Alex Deymof9f12632014-04-17 13:51:26 -070054
Amin Hassani4b717432019-01-14 16:24:20 -080055 FakeRandomProvider* random_provider() override { return &random_provider_; }
Gilad Arnoldae47a9a2014-03-26 12:16:47 -070056
Amin Hassani4b717432019-01-14 16:24:20 -080057 FakeShillProvider* shill_provider() override { return &shill_provider_; }
Gilad Arnoldae47a9a2014-03-26 12:16:47 -070058
Amin Hassani4b717432019-01-14 16:24:20 -080059 FakeSystemProvider* system_provider() override { return &system_provider_; }
Gilad Arnoldae47a9a2014-03-26 12:16:47 -070060
Amin Hassani4b717432019-01-14 16:24:20 -080061 FakeTimeProvider* time_provider() override { return &time_provider_; }
Gilad Arnoldae47a9a2014-03-26 12:16:47 -070062
Alex Vakulenko157fe302014-08-11 15:59:58 -070063 FakeUpdaterProvider* updater_provider() override {
David Zeuthen4e89e2c2014-04-24 11:47:00 -070064 return &updater_provider_;
Alex Deymo94c06162014-03-21 20:34:46 -070065 }
66
Alex Deymo2de23f52014-02-26 14:30:13 -080067 private:
David Zeuthen4e89e2c2014-04-24 11:47:00 -070068 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_;
Alex Deymo94c06162014-03-21 20:34:46 -070075
Alex Deymo2de23f52014-02-26 14:30:13 -080076 DISALLOW_COPY_AND_ASSIGN(FakeState);
77};
78
Alex Deymo63784a52014-05-28 10:46:14 -070079} // namespace chromeos_update_manager
Alex Deymo2de23f52014-02-26 14:30:13 -080080
Gilad Arnold48415f12014-06-27 07:10:58 -070081#endif // UPDATE_ENGINE_UPDATE_MANAGER_FAKE_STATE_H_