PolicyManager: Add an base Variable class without type.
The Variable<T> is a parametric type that requires to know the type T
of the exported variable. This new BaseVariable class isn't
parametric and allows to keep a list of variable pointers on the
EvaluationContext to cache their provided results and dump the names
of those variables.
BUG=chromium:338590
TEST=unittest passes.
Change-Id: I1677e3975d44575ed12f35c36381101d4379c5fc
Reviewed-on: https://chromium-review.googlesource.com/184428
Tested-by: Alex Deymo <deymo@chromium.org>
Reviewed-by: Alex Deymo <deymo@chromium.org>
Commit-Queue: Alex Deymo <deymo@chromium.org>
diff --git a/policy_manager/variable_unittest.cc b/policy_manager/variable_unittest.cc
new file mode 100644
index 0000000..f4aa084
--- /dev/null
+++ b/policy_manager/variable_unittest.cc
@@ -0,0 +1,35 @@
+// Copyright (c) 2014 The Chromium OS Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include <gtest/gtest.h>
+
+#include "policy_manager/variable.h"
+
+using std::string;
+
+namespace chromeos_policy_manager {
+
+// Variable class that returns a value constructed with the default value.
+template <typename T>
+class DefaultVariable : public Variable<T> {
+ public:
+ DefaultVariable(const string& name) : Variable<T>(name) {}
+ virtual ~DefaultVariable() {}
+
+ protected:
+ virtual const T* GetValue(base::TimeDelta /* timeout */,
+ string* /* errmsg */) {
+ return new T();
+ }
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(DefaultVariable);
+};
+
+TEST(PmBaseVariableTest, GetNameTest) {
+ DefaultVariable<int> var("var");
+ EXPECT_EQ(var.GetName(), string("var"));
+}
+
+} // namespace chromeos_policy_manager