summaryrefslogtreecommitdiff
path: root/chromium/components/policy/core/common/mac_util_unittest.cc
blob: b3e7826b8714087937e6b654694747c96c69ea7a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// Copyright 2014 The Chromium 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 "components/policy/core/common/mac_util.h"

#include <CoreFoundation/CoreFoundation.h>

#include <memory>

#include "base/mac/scoped_cftyperef.h"
#include "base/values.h"
#include "components/policy/core/common/policy_test_utils.h"
#include "testing/gtest/include/gtest/gtest.h"

namespace policy {

TEST(PolicyMacUtilTest, PropertyToValue) {
  base::DictionaryValue root;

  // base::Value::Type::NONE
  root.Set("null", std::make_unique<base::Value>());

  // base::Value::Type::BOOLEAN
  root.SetBoolKey("false", false);
  root.SetBoolKey("true", true);

  // base::Value::Type::INTEGER
  root.SetIntKey("int", 123);
  root.SetIntKey("zero", 0);

  // base::Value::Type::DOUBLE
  root.SetDoubleKey("double", 123.456);
  root.SetDoubleKey("zerod", 0.0);

  // base::Value::Type::STRING
  root.SetStringKey("string", "the fox jumps over something");
  root.SetStringKey("empty", "");

  // base::Value::Type::LIST
  root.Set("emptyl", std::make_unique<base::Value>(base::Value::Type::LIST));
  base::ListValue list;
  for (base::DictionaryValue::Iterator it(root); !it.IsAtEnd(); it.Advance())
    list.Append(std::make_unique<base::Value>(it.value().Clone()));
  EXPECT_EQ(root.DictSize(), list.GetListDeprecated().size());
  list.Append(std::make_unique<base::Value>(root.Clone()));
  root.SetKey("list", list.Clone());

  // base::Value::Type::DICTIONARY
  root.Set("emptyd",
           std::make_unique<base::Value>(base::Value::Type::DICTIONARY));
  // Very meta.
  root.SetKey("dict", root.Clone());

  base::ScopedCFTypeRef<CFPropertyListRef> property(ValueToProperty(root));
  ASSERT_TRUE(property);
  std::unique_ptr<base::Value> value = PropertyToValue(property);
  ASSERT_TRUE(value);
  EXPECT_TRUE(root.Equals(value.get()));
}

}  // namespace policy