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