PM: CopyVariable can determine whether the source value was set.
CopyVariable is now capable of checking an (optional) flag to see
whether the referenced value is set, instead of blindly copying it. This
preserves the existing interface, which defaults to an "always set"
state. The general interface also accepts a error message that is
returned to the caller of GetValue() in the case where a requested value
was not set.
BUG=None
TEST=Unit tests.
Change-Id: I983ea7b8c3985853cecce7a7b44f208b8b968e21
Reviewed-on: https://chromium-review.googlesource.com/195594
Tested-by: Gilad Arnold <garnold@chromium.org>
Reviewed-by: Alex Deymo <deymo@chromium.org>
Commit-Queue: Gilad Arnold <garnold@chromium.org>
diff --git a/policy_manager/generic_variables_unittest.cc b/policy_manager/generic_variables_unittest.cc
index 96de97e..7783e9f 100644
--- a/policy_manager/generic_variables_unittest.cc
+++ b/policy_manager/generic_variables_unittest.cc
@@ -41,6 +41,22 @@
EXPECT_EQ(42, *copy_2);
}
+TEST_F(PmCopyVariableTest, SetFlagTest) {
+ // Tests that the set flag is being referred to as expected.
+ int source = 5;
+ bool is_set = false;
+ CopyVariable<int> var("var", kVariableModePoll, source, &is_set);
+
+ // Flag marked unset, nothing should be returned.
+ PMTEST_ASSERT_NULL(var.GetValue(default_timeout_, NULL));
+
+ // Flag marked set, we should be getting a value.
+ is_set = true;
+ scoped_ptr<const int> copy(var.GetValue(default_timeout_, NULL));
+ PMTEST_ASSERT_NOT_NULL(copy.get());
+ EXPECT_EQ(5, *copy);
+}
+
class CopyConstructorTestClass {
public: