1 // Copyright 2014 The Chromium 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.
5 #include <CoreFoundation/CoreFoundation.h>
7 #include "base/mac/scoped_cftyperef.h"
8 #include "base/memory/scoped_ptr.h"
9 #include "base/values.h"
10 #include "components/policy/core/common/mac_util.h"
11 #include "components/policy/core/common/policy_test_utils.h"
12 #include "testing/gtest/include/gtest/gtest.h"
16 TEST(PolicyMacUtilTest
, PropertyToValue
) {
17 base::DictionaryValue root
;
19 // base::Value::TYPE_NULL
20 root
.Set("null", base::Value::CreateNullValue());
22 // base::Value::TYPE_BOOLEAN
23 root
.SetBoolean("false", false);
24 root
.SetBoolean("true", true);
26 // base::Value::TYPE_INTEGER
27 root
.SetInteger("int", 123);
28 root
.SetInteger("zero", 0);
30 // base::Value::TYPE_DOUBLE
31 root
.SetDouble("double", 123.456);
32 root
.SetDouble("zerod", 0.0);
34 // base::Value::TYPE_STRING
35 root
.SetString("string", "the fox jumps over something");
36 root
.SetString("empty", "");
38 // base::Value::TYPE_LIST
40 root
.Set("emptyl", list
.DeepCopy());
41 for (base::DictionaryValue::Iterator
it(root
); !it
.IsAtEnd(); it
.Advance())
42 list
.Append(it
.value().DeepCopy());
43 EXPECT_EQ(root
.size(), list
.GetSize());
44 list
.Append(root
.DeepCopy());
45 root
.Set("list", list
.DeepCopy());
47 // base::Value::TYPE_DICTIONARY
48 base::DictionaryValue dict
;
49 root
.Set("emptyd", dict
.DeepCopy());
51 root
.Set("dict", root
.DeepCopy());
53 base::ScopedCFTypeRef
<CFPropertyListRef
> property(ValueToProperty(&root
));
54 ASSERT_TRUE(property
);
55 scoped_ptr
<base::Value
> value
= PropertyToValue(property
);
57 EXPECT_TRUE(root
.Equals(value
.get()));