Gilad Arnold | a87340b | 2014-01-30 11:10:18 -0800 | [diff] [blame] | 1 | // 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 Arnold | 48415f1 | 2014-06-27 07:10:58 -0700 | [diff] [blame] | 5 | #ifndef UPDATE_ENGINE_UPDATE_MANAGER_UMTEST_UTILS_H_ |
| 6 | #define UPDATE_ENGINE_UPDATE_MANAGER_UMTEST_UTILS_H_ |
Gilad Arnold | a87340b | 2014-01-30 11:10:18 -0800 | [diff] [blame] | 7 | |
Gilad Arnold | 48415f1 | 2014-06-27 07:10:58 -0700 | [diff] [blame] | 8 | #include <iostream> // NOLINT(readability/streams) |
Ben Chan | 02f7c1d | 2014-10-18 15:18:02 -0700 | [diff] [blame^] | 9 | #include <memory> |
Alex Deymo | 0d11c60 | 2014-04-23 20:12:20 -0700 | [diff] [blame] | 10 | |
Gilad Arnold | 67ed78d | 2014-04-23 13:17:46 -0700 | [diff] [blame] | 11 | #include <base/time/time.h> |
| 12 | #include <gtest/gtest.h> |
| 13 | |
Alex Deymo | 63784a5 | 2014-05-28 10:46:14 -0700 | [diff] [blame] | 14 | #include "update_engine/update_manager/policy.h" |
| 15 | #include "update_engine/update_manager/variable.h" |
Gilad Arnold | 67ed78d | 2014-04-23 13:17:46 -0700 | [diff] [blame] | 16 | |
Alex Deymo | 63784a5 | 2014-05-28 10:46:14 -0700 | [diff] [blame] | 17 | namespace chromeos_update_manager { |
Gilad Arnold | 67ed78d | 2014-04-23 13:17:46 -0700 | [diff] [blame] | 18 | |
Alex Deymo | 63784a5 | 2014-05-28 10:46:14 -0700 | [diff] [blame] | 19 | // A help class with common functionality for use in Update Manager testing. |
| 20 | class UmTestUtils { |
Gilad Arnold | 67ed78d | 2014-04-23 13:17:46 -0700 | [diff] [blame] | 21 | 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 Vakulenko | 88b591f | 2014-08-28 16:48:57 -0700 | [diff] [blame] | 30 | ASSERT_NE(nullptr, variable); |
Ben Chan | 02f7c1d | 2014-10-18 15:18:02 -0700 | [diff] [blame^] | 31 | std::unique_ptr<const T> value( |
| 32 | variable->GetValue(DefaultTimeout(), nullptr)); |
Alex Vakulenko | 88b591f | 2014-08-28 16:48:57 -0700 | [diff] [blame] | 33 | ASSERT_NE(nullptr, value.get()) << "Variable: " << variable->GetName(); |
Gilad Arnold | 67ed78d | 2014-04-23 13:17:46 -0700 | [diff] [blame] | 34 | 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 Vakulenko | 88b591f | 2014-08-28 16:48:57 -0700 | [diff] [blame] | 40 | ASSERT_NE(nullptr, variable); |
Ben Chan | 02f7c1d | 2014-10-18 15:18:02 -0700 | [diff] [blame^] | 41 | std::unique_ptr<const T> value( |
| 42 | variable->GetValue(DefaultTimeout(), nullptr)); |
Alex Vakulenko | 88b591f | 2014-08-28 16:48:57 -0700 | [diff] [blame] | 43 | EXPECT_EQ(nullptr, value.get()) << "Variable: " << variable->GetName(); |
Gilad Arnold | 67ed78d | 2014-04-23 13:17:46 -0700 | [diff] [blame] | 44 | } |
| 45 | |
| 46 | private: |
| 47 | static const unsigned kDefaultTimeoutInSeconds; |
| 48 | }; |
| 49 | |
Alex Deymo | 0d11c60 | 2014-04-23 20:12:20 -0700 | [diff] [blame] | 50 | // 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. |
| 52 | void PrintTo(const EvalStatus& status, ::std::ostream* os); |
| 53 | |
Alex Deymo | 63784a5 | 2014-05-28 10:46:14 -0700 | [diff] [blame] | 54 | } // namespace chromeos_update_manager |
Gilad Arnold | 67ed78d | 2014-04-23 13:17:46 -0700 | [diff] [blame] | 55 | |
Gilad Arnold | 48415f1 | 2014-06-27 07:10:58 -0700 | [diff] [blame] | 56 | #endif // UPDATE_ENGINE_UPDATE_MANAGER_UMTEST_UTILS_H_ |