blob: e346c0d23c084b062e58357645724a12f4ade44b [file] [log] [blame]
Alex Deymo391ad9f2014-01-29 14:36:20 -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
5#include <gtest/gtest.h>
6
Alex Deymo6e97bb22014-02-05 16:46:16 -08007#include "update_engine/policy_manager/variable.h"
Alex Deymo391ad9f2014-01-29 14:36:20 -08008
9using std::string;
10
11namespace chromeos_policy_manager {
12
13// Variable class that returns a value constructed with the default value.
14template <typename T>
15class DefaultVariable : public Variable<T> {
16 public:
Alex Deymo0e433692014-02-20 07:23:03 -080017 DefaultVariable(const string& name, VariableMode mode)
18 : Variable<T>(name, mode) {}
Alex Deymo391ad9f2014-01-29 14:36:20 -080019 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
31TEST(PmBaseVariableTest, GetNameTest) {
Alex Deymo0e433692014-02-20 07:23:03 -080032 DefaultVariable<int> var("var", kVariableModeConst);
Alex Deymo391ad9f2014-01-29 14:36:20 -080033 EXPECT_EQ(var.GetName(), string("var"));
34}
35
Alex Deymo0e433692014-02-20 07:23:03 -080036TEST(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 Deymo391ad9f2014-01-29 14:36:20 -080043} // namespace chromeos_policy_manager