OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "tools/json_schema_compiler/test/functions_as_parameters.h" | 5 #include "tools/json_schema_compiler/test/functions_as_parameters.h" |
6 | 6 |
| 7 #include "base/memory/ptr_util.h" |
| 8 #include "base/values.h" |
7 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
8 | 10 |
9 using namespace test::api::functions_as_parameters; | 11 using namespace test::api::functions_as_parameters; |
10 | 12 |
11 TEST(JsonSchemaCompilerFunctionsAsParametersTest, PopulateRequiredFunction) { | 13 TEST(JsonSchemaCompilerFunctionsAsParametersTest, PopulateRequiredFunction) { |
12 // The expectation is that if any value is set for the function, then | 14 // The expectation is that if any value is set for the function, then |
13 // the function is "present". | 15 // the function is "present". |
14 { | 16 { |
15 base::DictionaryValue empty_value; | 17 base::DictionaryValue empty_value; |
16 FunctionType out; | 18 FunctionType out; |
17 EXPECT_FALSE(FunctionType::Populate(empty_value, &out)); | 19 EXPECT_FALSE(FunctionType::Populate(empty_value, &out)); |
18 } | 20 } |
19 { | 21 { |
20 base::DictionaryValue value; | 22 base::DictionaryValue value; |
21 base::DictionaryValue function_dict; | 23 base::DictionaryValue function_dict; |
22 value.Set("event_callback", function_dict.DeepCopy()); | 24 value.Set("event_callback", base::MakeUnique<base::Value>(function_dict)); |
23 FunctionType out; | 25 FunctionType out; |
24 ASSERT_TRUE(FunctionType::Populate(value, &out)); | 26 ASSERT_TRUE(FunctionType::Populate(value, &out)); |
25 EXPECT_TRUE(out.event_callback.empty()); | 27 EXPECT_TRUE(out.event_callback.empty()); |
26 } | 28 } |
27 } | 29 } |
28 | 30 |
29 TEST(JsonSchemaCompilerFunctionsAsParametersTest, RequiredFunctionToValue) { | 31 TEST(JsonSchemaCompilerFunctionsAsParametersTest, RequiredFunctionToValue) { |
30 { | 32 { |
31 base::DictionaryValue value; | 33 base::DictionaryValue value; |
32 base::DictionaryValue function_dict; | 34 base::DictionaryValue function_dict; |
33 value.Set("event_callback", function_dict.DeepCopy()); | 35 value.Set("event_callback", base::MakeUnique<base::Value>(function_dict)); |
34 | 36 |
35 FunctionType out; | 37 FunctionType out; |
36 ASSERT_TRUE(FunctionType::Populate(value, &out)); | 38 ASSERT_TRUE(FunctionType::Populate(value, &out)); |
37 EXPECT_TRUE(value.Equals(out.ToValue().get())); | 39 EXPECT_TRUE(value.Equals(out.ToValue().get())); |
38 } | 40 } |
39 { | 41 { |
40 base::DictionaryValue value; | 42 base::DictionaryValue value; |
41 base::DictionaryValue expected_value; | 43 base::DictionaryValue expected_value; |
42 base::DictionaryValue function_dict; | 44 base::DictionaryValue function_dict; |
43 value.Set("event_callback", function_dict.DeepCopy()); | 45 value.Set("event_callback", base::MakeUnique<base::Value>(function_dict)); |
44 expected_value.Set("event_callback", function_dict.DeepCopy()); | 46 expected_value.Set("event_callback", |
| 47 base::MakeUnique<base::Value>(function_dict)); |
45 | 48 |
46 FunctionType out; | 49 FunctionType out; |
47 ASSERT_TRUE(FunctionType::Populate(value, &out)); | 50 ASSERT_TRUE(FunctionType::Populate(value, &out)); |
48 EXPECT_TRUE(expected_value.Equals(out.ToValue().get())); | 51 EXPECT_TRUE(expected_value.Equals(out.ToValue().get())); |
49 } | 52 } |
50 } | 53 } |
51 | 54 |
52 TEST(JsonSchemaCompilerFunctionsAsParametersTest, PopulateOptionalFunction) { | 55 TEST(JsonSchemaCompilerFunctionsAsParametersTest, PopulateOptionalFunction) { |
53 { | 56 { |
54 base::DictionaryValue empty_value; | 57 base::DictionaryValue empty_value; |
55 OptionalFunctionType out; | 58 OptionalFunctionType out; |
56 ASSERT_TRUE(OptionalFunctionType::Populate(empty_value, &out)); | 59 ASSERT_TRUE(OptionalFunctionType::Populate(empty_value, &out)); |
57 EXPECT_FALSE(out.event_callback.get()); | 60 EXPECT_FALSE(out.event_callback.get()); |
58 } | 61 } |
59 { | 62 { |
60 base::DictionaryValue value; | 63 base::DictionaryValue value; |
61 base::DictionaryValue function_value; | 64 base::DictionaryValue function_value; |
62 value.Set("event_callback", function_value.DeepCopy()); | 65 value.Set("event_callback", base::MakeUnique<base::Value>(function_value)); |
63 OptionalFunctionType out; | 66 OptionalFunctionType out; |
64 ASSERT_TRUE(OptionalFunctionType::Populate(value, &out)); | 67 ASSERT_TRUE(OptionalFunctionType::Populate(value, &out)); |
65 EXPECT_TRUE(out.event_callback.get()); | 68 EXPECT_TRUE(out.event_callback.get()); |
66 } | 69 } |
67 { | 70 { |
68 base::DictionaryValue value; | 71 base::DictionaryValue value; |
69 base::DictionaryValue function_value; | 72 base::DictionaryValue function_value; |
70 value.Set("event_callback", function_value.DeepCopy()); | 73 value.Set("event_callback", base::MakeUnique<base::Value>(function_value)); |
71 OptionalFunctionType out; | 74 OptionalFunctionType out; |
72 ASSERT_TRUE(OptionalFunctionType::Populate(value, &out)); | 75 ASSERT_TRUE(OptionalFunctionType::Populate(value, &out)); |
73 EXPECT_TRUE(out.event_callback.get()); | 76 EXPECT_TRUE(out.event_callback.get()); |
74 } | 77 } |
75 } | 78 } |
76 | 79 |
77 TEST(JsonSchemaCompilerFunctionsAsParametersTest, OptionalFunctionToValue) { | 80 TEST(JsonSchemaCompilerFunctionsAsParametersTest, OptionalFunctionToValue) { |
78 { | 81 { |
79 base::DictionaryValue empty_value; | 82 base::DictionaryValue empty_value; |
80 OptionalFunctionType out; | 83 OptionalFunctionType out; |
81 ASSERT_TRUE(OptionalFunctionType::Populate(empty_value, &out)); | 84 ASSERT_TRUE(OptionalFunctionType::Populate(empty_value, &out)); |
82 // event_callback should not be set in the return from ToValue. | 85 // event_callback should not be set in the return from ToValue. |
83 EXPECT_TRUE(empty_value.Equals(out.ToValue().get())); | 86 EXPECT_TRUE(empty_value.Equals(out.ToValue().get())); |
84 } | 87 } |
85 { | 88 { |
86 base::DictionaryValue value; | 89 base::DictionaryValue value; |
87 base::DictionaryValue function_value; | 90 base::DictionaryValue function_value; |
88 value.Set("event_callback", function_value.DeepCopy()); | 91 value.Set("event_callback", base::MakeUnique<base::Value>(function_value)); |
89 | 92 |
90 OptionalFunctionType out; | 93 OptionalFunctionType out; |
91 ASSERT_TRUE(OptionalFunctionType::Populate(value, &out)); | 94 ASSERT_TRUE(OptionalFunctionType::Populate(value, &out)); |
92 EXPECT_TRUE(value.Equals(out.ToValue().get())); | 95 EXPECT_TRUE(value.Equals(out.ToValue().get())); |
93 } | 96 } |
94 } | 97 } |
OLD | NEW |