OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 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. |
| 4 |
| 5 #include <CoreFoundation/CoreFoundation.h> |
| 6 |
| 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" |
| 13 |
| 14 namespace policy { |
| 15 |
| 16 TEST(PolicyMacUtilTest, PropertyToValue) { |
| 17 base::DictionaryValue root; |
| 18 |
| 19 // base::Value::TYPE_NULL |
| 20 root.Set("null", base::Value::CreateNullValue()); |
| 21 |
| 22 // base::Value::TYPE_BOOLEAN |
| 23 root.SetBoolean("false", false); |
| 24 root.SetBoolean("true", true); |
| 25 |
| 26 // base::Value::TYPE_INTEGER |
| 27 root.SetInteger("int", 123); |
| 28 root.SetInteger("zero", 0); |
| 29 |
| 30 // base::Value::TYPE_DOUBLE |
| 31 root.SetDouble("double", 123.456); |
| 32 root.SetDouble("zerod", 0.0); |
| 33 |
| 34 // base::Value::TYPE_STRING |
| 35 root.SetString("string", "the fox jumps over something"); |
| 36 root.SetString("empty", ""); |
| 37 |
| 38 // base::Value::TYPE_LIST |
| 39 base::ListValue 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()); |
| 46 |
| 47 // base::Value::TYPE_DICTIONARY |
| 48 base::DictionaryValue dict; |
| 49 root.Set("emptyd", dict.DeepCopy()); |
| 50 // Very meta. |
| 51 root.Set("dict", root.DeepCopy()); |
| 52 |
| 53 base::ScopedCFTypeRef<CFPropertyListRef> property(ValueToProperty(&root)); |
| 54 ASSERT_TRUE(property); |
| 55 scoped_ptr<base::Value> value = PropertyToValue(property); |
| 56 ASSERT_TRUE(value); |
| 57 EXPECT_TRUE(root.Equals(value.get())); |
| 58 } |
| 59 |
| 60 } // namespace policy |
OLD | NEW |