blob: 80693db621b9a1a2b28df0e1703ff010337b5f41 [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//
Gilad Arnolda87340b2014-01-30 11:10:18 -080016
Gilad Arnold48415f12014-06-27 07:10:58 -070017#ifndef UPDATE_ENGINE_UPDATE_MANAGER_UMTEST_UTILS_H_
18#define UPDATE_ENGINE_UPDATE_MANAGER_UMTEST_UTILS_H_
Gilad Arnolda87340b2014-01-30 11:10:18 -080019
Gilad Arnold48415f12014-06-27 07:10:58 -070020#include <iostream> // NOLINT(readability/streams)
Ben Chan02f7c1d2014-10-18 15:18:02 -070021#include <memory>
Alex Deymo0d11c602014-04-23 20:12:20 -070022
Gilad Arnold67ed78d2014-04-23 13:17:46 -070023#include <base/time/time.h>
24#include <gtest/gtest.h>
25
Alex Deymo63784a52014-05-28 10:46:14 -070026#include "update_engine/update_manager/policy.h"
27#include "update_engine/update_manager/variable.h"
Gilad Arnold67ed78d2014-04-23 13:17:46 -070028
Alex Deymo63784a52014-05-28 10:46:14 -070029namespace chromeos_update_manager {
Gilad Arnold67ed78d2014-04-23 13:17:46 -070030
Alex Deymo63784a52014-05-28 10:46:14 -070031// A help class with common functionality for use in Update Manager testing.
32class UmTestUtils {
Gilad Arnold67ed78d2014-04-23 13:17:46 -070033 public:
34 // A default timeout to use when making various queries.
35 static const base::TimeDelta DefaultTimeout() {
36 return base::TimeDelta::FromSeconds(kDefaultTimeoutInSeconds);
37 }
38
39 // Calls GetValue on |variable| and expects its result to be |expected|.
40 template<typename T>
41 static void ExpectVariableHasValue(const T& expected, Variable<T>* variable) {
Alex Vakulenko88b591f2014-08-28 16:48:57 -070042 ASSERT_NE(nullptr, variable);
Ben Chan02f7c1d2014-10-18 15:18:02 -070043 std::unique_ptr<const T> value(
44 variable->GetValue(DefaultTimeout(), nullptr));
Alex Vakulenko88b591f2014-08-28 16:48:57 -070045 ASSERT_NE(nullptr, value.get()) << "Variable: " << variable->GetName();
Gilad Arnold67ed78d2014-04-23 13:17:46 -070046 EXPECT_EQ(expected, *value) << "Variable: " << variable->GetName();
47 }
48
49 // Calls GetValue on |variable| and expects its result to be null.
50 template<typename T>
51 static void ExpectVariableNotSet(Variable<T>* variable) {
Alex Vakulenko88b591f2014-08-28 16:48:57 -070052 ASSERT_NE(nullptr, variable);
Ben Chan02f7c1d2014-10-18 15:18:02 -070053 std::unique_ptr<const T> value(
54 variable->GetValue(DefaultTimeout(), nullptr));
Alex Vakulenko88b591f2014-08-28 16:48:57 -070055 EXPECT_EQ(nullptr, value.get()) << "Variable: " << variable->GetName();
Gilad Arnold67ed78d2014-04-23 13:17:46 -070056 }
57
58 private:
59 static const unsigned kDefaultTimeoutInSeconds;
60};
61
Alex Deymo0d11c602014-04-23 20:12:20 -070062// PrintTo() functions are used by gtest to print these values. They need to be
63// defined on the same namespace where the type was defined.
64void PrintTo(const EvalStatus& status, ::std::ostream* os);
65
Alex Deymo63784a52014-05-28 10:46:14 -070066} // namespace chromeos_update_manager
Gilad Arnold67ed78d2014-04-23 13:17:46 -070067
Gilad Arnold48415f12014-06-27 07:10:58 -070068#endif // UPDATE_ENGINE_UPDATE_MANAGER_UMTEST_UTILS_H_