Alex Deymo | 391ad9f | 2014-01-29 14:36:20 -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 | |
| 5 | #include <gtest/gtest.h> |
| 6 | |
Alex Deymo | 6e97bb2 | 2014-02-05 16:46:16 -0800 | [diff] [blame] | 7 | #include "update_engine/policy_manager/variable.h" |
Alex Deymo | 391ad9f | 2014-01-29 14:36:20 -0800 | [diff] [blame] | 8 | |
| 9 | using std::string; |
| 10 | |
| 11 | namespace chromeos_policy_manager { |
| 12 | |
| 13 | // Variable class that returns a value constructed with the default value. |
| 14 | template <typename T> |
| 15 | class DefaultVariable : public Variable<T> { |
| 16 | public: |
Alex Deymo | 0e43369 | 2014-02-20 07:23:03 -0800 | [diff] [blame] | 17 | DefaultVariable(const string& name, VariableMode mode) |
| 18 | : Variable<T>(name, mode) {} |
Alex Deymo | 391ad9f | 2014-01-29 14:36:20 -0800 | [diff] [blame] | 19 | virtual ~DefaultVariable() {} |
| 20 | |
| 21 | protected: |
| 22 | virtual const T* GetValue(base::TimeDelta /* timeout */, |
| 23 | string* /* errmsg */) { |
| 24 | return new T(); |
| 25 | } |
| 26 | |
| 27 | private: |
| 28 | DISALLOW_COPY_AND_ASSIGN(DefaultVariable); |
| 29 | }; |
| 30 | |
| 31 | TEST(PmBaseVariableTest, GetNameTest) { |
Alex Deymo | 0e43369 | 2014-02-20 07:23:03 -0800 | [diff] [blame] | 32 | DefaultVariable<int> var("var", kVariableModeConst); |
Alex Deymo | 391ad9f | 2014-01-29 14:36:20 -0800 | [diff] [blame] | 33 | EXPECT_EQ(var.GetName(), string("var")); |
| 34 | } |
| 35 | |
Alex Deymo | 0e43369 | 2014-02-20 07:23:03 -0800 | [diff] [blame] | 36 | TEST(PmBaseVariableTest, GetModeTest) { |
| 37 | DefaultVariable<int> var("var", kVariableModeConst); |
| 38 | EXPECT_EQ(var.GetMode(), kVariableModeConst); |
| 39 | DefaultVariable<int> other_var("other_var", kVariableModePoll); |
| 40 | EXPECT_EQ(other_var.GetMode(), kVariableModePoll); |
| 41 | } |
| 42 | |
Alex Deymo | 391ad9f | 2014-01-29 14:36:20 -0800 | [diff] [blame] | 43 | } // namespace chromeos_policy_manager |