blob: f47aa78c76d6b9d1f815de3552bcb5e9a772d3a1 [file] [log] [blame]
Alex Deymo2de23f52014-02-26 14:30:13 -08001// Copyright (c) 2014 The Chromium OS Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
Gilad Arnold48415f12014-06-27 07:10:58 -07005#ifndef UPDATE_ENGINE_UPDATE_MANAGER_FAKE_STATE_H_
6#define UPDATE_ENGINE_UPDATE_MANAGER_FAKE_STATE_H_
Alex Deymo2de23f52014-02-26 14:30:13 -08007
Alex Deymo63784a52014-05-28 10:46:14 -07008#include "update_engine/update_manager/fake_config_provider.h"
9#include "update_engine/update_manager/fake_device_policy_provider.h"
10#include "update_engine/update_manager/fake_random_provider.h"
11#include "update_engine/update_manager/fake_shill_provider.h"
12#include "update_engine/update_manager/fake_system_provider.h"
13#include "update_engine/update_manager/fake_time_provider.h"
14#include "update_engine/update_manager/fake_updater_provider.h"
15#include "update_engine/update_manager/state.h"
Alex Deymo2de23f52014-02-26 14:30:13 -080016
Alex Deymo63784a52014-05-28 10:46:14 -070017namespace chromeos_update_manager {
Alex Deymo2de23f52014-02-26 14:30:13 -080018
Alex Deymo94c06162014-03-21 20:34:46 -070019// A fake State class that creates fake providers for all the providers.
Alex Deymo42c30c32014-04-24 18:41:18 -070020// This fake can be used in unit testing of Policy subclasses. To fake out the
21// value a variable is exposing, just call FakeVariable<T>::SetValue() on the
22// variable you fake out. For example:
23//
24// FakeState fake_state_;
25// fake_state_.random_provider_->var_seed()->SetValue(new uint64_t(12345));
26//
27// You can call SetValue more than once and the FakeVariable will take care of
28// the memory, but only the last value will remain.
Alex Deymo2de23f52014-02-26 14:30:13 -080029class FakeState : public State {
30 public:
Alex Deymo42c30c32014-04-24 18:41:18 -070031 // Creates and initializes the FakeState using fake providers.
32 FakeState() {}
Alex Deymo94c06162014-03-21 20:34:46 -070033
Alex Deymo2de23f52014-02-26 14:30:13 -080034 virtual ~FakeState() {}
35
Alex Vakulenko072359c2014-07-18 11:41:07 -070036 // Downcasted getters to access the fake instances during testing.
Alex Deymof9f12632014-04-17 13:51:26 -070037 virtual FakeConfigProvider* config_provider() override {
David Zeuthen4e89e2c2014-04-24 11:47:00 -070038 return &config_provider_;
Alex Deymof9f12632014-04-17 13:51:26 -070039 }
40
Alex Deymoc83baf62014-04-02 17:43:35 -070041 virtual FakeDevicePolicyProvider* device_policy_provider() override {
David Zeuthen4e89e2c2014-04-24 11:47:00 -070042 return &device_policy_provider_;
Alex Deymoc83baf62014-04-02 17:43:35 -070043 }
Alex Deymof9f12632014-04-17 13:51:26 -070044
Alex Deymo94c06162014-03-21 20:34:46 -070045 virtual FakeRandomProvider* random_provider() override {
David Zeuthen4e89e2c2014-04-24 11:47:00 -070046 return &random_provider_;
Alex Deymo94c06162014-03-21 20:34:46 -070047 }
Gilad Arnoldae47a9a2014-03-26 12:16:47 -070048
Alex Deymo94c06162014-03-21 20:34:46 -070049 virtual FakeShillProvider* shill_provider() override {
David Zeuthen4e89e2c2014-04-24 11:47:00 -070050 return &shill_provider_;
Alex Deymo94c06162014-03-21 20:34:46 -070051 }
Gilad Arnoldae47a9a2014-03-26 12:16:47 -070052
53 virtual FakeSystemProvider* system_provider() override {
David Zeuthen4e89e2c2014-04-24 11:47:00 -070054 return &system_provider_;
Gilad Arnoldae47a9a2014-03-26 12:16:47 -070055 }
56
Alex Deymo94c06162014-03-21 20:34:46 -070057 virtual FakeTimeProvider* time_provider() override {
David Zeuthen4e89e2c2014-04-24 11:47:00 -070058 return &time_provider_;
Alex Deymo94c06162014-03-21 20:34:46 -070059 }
Gilad Arnoldae47a9a2014-03-26 12:16:47 -070060
61 virtual FakeUpdaterProvider* updater_provider() override {
David Zeuthen4e89e2c2014-04-24 11:47:00 -070062 return &updater_provider_;
Alex Deymo94c06162014-03-21 20:34:46 -070063 }
64
Alex Deymo2de23f52014-02-26 14:30:13 -080065 private:
David Zeuthen4e89e2c2014-04-24 11:47:00 -070066 FakeConfigProvider config_provider_;
67 FakeDevicePolicyProvider device_policy_provider_;
68 FakeRandomProvider random_provider_;
69 FakeShillProvider shill_provider_;
70 FakeSystemProvider system_provider_;
71 FakeTimeProvider time_provider_;
72 FakeUpdaterProvider updater_provider_;
Alex Deymo94c06162014-03-21 20:34:46 -070073
Alex Deymo2de23f52014-02-26 14:30:13 -080074 DISALLOW_COPY_AND_ASSIGN(FakeState);
75};
76
Alex Deymo63784a52014-05-28 10:46:14 -070077} // namespace chromeos_update_manager
Alex Deymo2de23f52014-02-26 14:30:13 -080078
Gilad Arnold48415f12014-06-27 07:10:58 -070079#endif // UPDATE_ENGINE_UPDATE_MANAGER_FAKE_STATE_H_