blob: 4e2de8e82040e1844222c2f90b88d37fa4fe70bd [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)
Alex Deymo0d11c602014-04-23 20:12:20 -07009
Alex Deymo1f012912014-04-24 19:08:04 -070010#include <base/memory/scoped_ptr.h>
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);
Gilad Arnold67ed78d2014-04-23 13:17:46 -070031 scoped_ptr<const T> value(variable->GetValue(DefaultTimeout(), nullptr));
Alex Vakulenko88b591f2014-08-28 16:48:57 -070032 ASSERT_NE(nullptr, value.get()) << "Variable: " << variable->GetName();
Gilad Arnold67ed78d2014-04-23 13:17:46 -070033 EXPECT_EQ(expected, *value) << "Variable: " << variable->GetName();
34 }
35
36 // Calls GetValue on |variable| and expects its result to be null.
37 template<typename T>
38 static void ExpectVariableNotSet(Variable<T>* variable) {
Alex Vakulenko88b591f2014-08-28 16:48:57 -070039 ASSERT_NE(nullptr, variable);
Gilad Arnold67ed78d2014-04-23 13:17:46 -070040 scoped_ptr<const T> value(variable->GetValue(DefaultTimeout(), nullptr));
Alex Vakulenko88b591f2014-08-28 16:48:57 -070041 EXPECT_EQ(nullptr, value.get()) << "Variable: " << variable->GetName();
Gilad Arnold67ed78d2014-04-23 13:17:46 -070042 }
43
44 private:
45 static const unsigned kDefaultTimeoutInSeconds;
46};
47
Alex Deymo0d11c602014-04-23 20:12:20 -070048// PrintTo() functions are used by gtest to print these values. They need to be
49// defined on the same namespace where the type was defined.
50void PrintTo(const EvalStatus& status, ::std::ostream* os);
51
Alex Deymo63784a52014-05-28 10:46:14 -070052} // namespace chromeos_update_manager
Gilad Arnold67ed78d2014-04-23 13:17:46 -070053
Gilad Arnold48415f12014-06-27 07:10:58 -070054#endif // UPDATE_ENGINE_UPDATE_MANAGER_UMTEST_UTILS_H_