blob: c50a5a2e51e9b5e71a3c6aa7c65d6742cacea18a [file] [log] [blame]
Gilad Arnolda87340b2014-01-30 11:10:18 -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_UMTEST_UTILS_H_
6#define UPDATE_ENGINE_UPDATE_MANAGER_UMTEST_UTILS_H_
Gilad Arnolda87340b2014-01-30 11:10:18 -08007
Gilad Arnold48415f12014-06-27 07:10:58 -07008#include <iostream> // NOLINT(readability/streams)
Ben Chan02f7c1d2014-10-18 15:18:02 -07009#include <memory>
Alex Deymo0d11c602014-04-23 20:12:20 -070010
Gilad Arnold67ed78d2014-04-23 13:17:46 -070011#include <base/time/time.h>
12#include <gtest/gtest.h>
13
Alex Deymo63784a52014-05-28 10:46:14 -070014#include "update_engine/update_manager/policy.h"
15#include "update_engine/update_manager/variable.h"
Gilad Arnold67ed78d2014-04-23 13:17:46 -070016
Alex Deymo63784a52014-05-28 10:46:14 -070017namespace chromeos_update_manager {
Gilad Arnold67ed78d2014-04-23 13:17:46 -070018
Alex Deymo63784a52014-05-28 10:46:14 -070019// A help class with common functionality for use in Update Manager testing.
20class UmTestUtils {
Gilad Arnold67ed78d2014-04-23 13:17:46 -070021 public:
22 // A default timeout to use when making various queries.
23 static const base::TimeDelta DefaultTimeout() {
24 return base::TimeDelta::FromSeconds(kDefaultTimeoutInSeconds);
25 }
26
27 // Calls GetValue on |variable| and expects its result to be |expected|.
28 template<typename T>
29 static void ExpectVariableHasValue(const T& expected, Variable<T>* variable) {
Alex Vakulenko88b591f2014-08-28 16:48:57 -070030 ASSERT_NE(nullptr, variable);
Ben Chan02f7c1d2014-10-18 15:18:02 -070031 std::unique_ptr<const T> value(
32 variable->GetValue(DefaultTimeout(), nullptr));
Alex Vakulenko88b591f2014-08-28 16:48:57 -070033 ASSERT_NE(nullptr, value.get()) << "Variable: " << variable->GetName();
Gilad Arnold67ed78d2014-04-23 13:17:46 -070034 EXPECT_EQ(expected, *value) << "Variable: " << variable->GetName();
35 }
36
37 // Calls GetValue on |variable| and expects its result to be null.
38 template<typename T>
39 static void ExpectVariableNotSet(Variable<T>* variable) {
Alex Vakulenko88b591f2014-08-28 16:48:57 -070040 ASSERT_NE(nullptr, variable);
Ben Chan02f7c1d2014-10-18 15:18:02 -070041 std::unique_ptr<const T> value(
42 variable->GetValue(DefaultTimeout(), nullptr));
Alex Vakulenko88b591f2014-08-28 16:48:57 -070043 EXPECT_EQ(nullptr, value.get()) << "Variable: " << variable->GetName();
Gilad Arnold67ed78d2014-04-23 13:17:46 -070044 }
45
46 private:
47 static const unsigned kDefaultTimeoutInSeconds;
48};
49
Alex Deymo0d11c602014-04-23 20:12:20 -070050// PrintTo() functions are used by gtest to print these values. They need to be
51// defined on the same namespace where the type was defined.
52void PrintTo(const EvalStatus& status, ::std::ostream* os);
53
Alex Deymo63784a52014-05-28 10:46:14 -070054} // namespace chromeos_update_manager
Gilad Arnold67ed78d2014-04-23 13:17:46 -070055
Gilad Arnold48415f12014-06-27 07:10:58 -070056#endif // UPDATE_ENGINE_UPDATE_MANAGER_UMTEST_UTILS_H_