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 "testing/gtest/include/gtest/gtest.h" | 7 #include "testing/gtest/include/gtest/gtest.h" |
8 | 8 |
9 using namespace test::api::functions_as_parameters; | 9 using namespace test::api::functions_as_parameters; |
10 | 10 |
11 TEST(JsonSchemaCompilerFunctionsAsParametersTest, PopulateRequiredFunction) { | 11 TEST(JsonSchemaCompilerFunctionsAsParametersTest, PopulateRequiredFunction) { |
12 // The expectation is that if any value is set for the function, then | 12 // The expectation is that if any value is set for the function, then |
13 // the function is "present". | 13 // the function is "present". |
14 { | 14 { |
15 DictionaryValue empty_value; | 15 base::DictionaryValue empty_value; |
16 FunctionType out; | 16 FunctionType out; |
17 EXPECT_FALSE(FunctionType::Populate(empty_value, &out)); | 17 EXPECT_FALSE(FunctionType::Populate(empty_value, &out)); |
18 } | 18 } |
19 { | 19 { |
20 DictionaryValue value; | 20 base::DictionaryValue value; |
21 DictionaryValue function_dict; | 21 base::DictionaryValue function_dict; |
22 value.Set("event_callback", function_dict.DeepCopy()); | 22 value.Set("event_callback", function_dict.DeepCopy()); |
23 FunctionType out; | 23 FunctionType out; |
24 ASSERT_TRUE(FunctionType::Populate(value, &out)); | 24 ASSERT_TRUE(FunctionType::Populate(value, &out)); |
25 EXPECT_TRUE(out.event_callback.empty()); | 25 EXPECT_TRUE(out.event_callback.empty()); |
26 } | 26 } |
27 } | 27 } |
28 | 28 |
29 TEST(JsonSchemaCompilerFunctionsAsParametersTest, RequiredFunctionToValue) { | 29 TEST(JsonSchemaCompilerFunctionsAsParametersTest, RequiredFunctionToValue) { |
30 { | 30 { |
31 DictionaryValue value; | 31 base::DictionaryValue value; |
32 DictionaryValue function_dict; | 32 base::DictionaryValue function_dict; |
33 value.Set("event_callback", function_dict.DeepCopy()); | 33 value.Set("event_callback", function_dict.DeepCopy()); |
34 | 34 |
35 FunctionType out; | 35 FunctionType out; |
36 ASSERT_TRUE(FunctionType::Populate(value, &out)); | 36 ASSERT_TRUE(FunctionType::Populate(value, &out)); |
37 EXPECT_TRUE(value.Equals(out.ToValue().get())); | 37 EXPECT_TRUE(value.Equals(out.ToValue().get())); |
38 } | 38 } |
39 { | 39 { |
40 DictionaryValue value; | 40 base::DictionaryValue value; |
41 DictionaryValue expected_value; | 41 base::DictionaryValue expected_value; |
42 DictionaryValue function_dict; | 42 base::DictionaryValue function_dict; |
43 value.Set("event_callback", function_dict.DeepCopy()); | 43 value.Set("event_callback", function_dict.DeepCopy()); |
44 expected_value.Set("event_callback", function_dict.DeepCopy()); | 44 expected_value.Set("event_callback", function_dict.DeepCopy()); |
45 | 45 |
46 FunctionType out; | 46 FunctionType out; |
47 ASSERT_TRUE(FunctionType::Populate(value, &out)); | 47 ASSERT_TRUE(FunctionType::Populate(value, &out)); |
48 EXPECT_TRUE(expected_value.Equals(out.ToValue().get())); | 48 EXPECT_TRUE(expected_value.Equals(out.ToValue().get())); |
49 } | 49 } |
50 } | 50 } |
51 | 51 |
52 TEST(JsonSchemaCompilerFunctionsAsParametersTest, PopulateOptionalFunction) { | 52 TEST(JsonSchemaCompilerFunctionsAsParametersTest, PopulateOptionalFunction) { |
53 { | 53 { |
54 DictionaryValue empty_value; | 54 base::DictionaryValue empty_value; |
55 OptionalFunctionType out; | 55 OptionalFunctionType out; |
56 ASSERT_TRUE(OptionalFunctionType::Populate(empty_value, &out)); | 56 ASSERT_TRUE(OptionalFunctionType::Populate(empty_value, &out)); |
57 EXPECT_FALSE(out.event_callback.get()); | 57 EXPECT_FALSE(out.event_callback.get()); |
58 } | 58 } |
59 { | 59 { |
60 DictionaryValue value; | 60 base::DictionaryValue value; |
61 DictionaryValue function_value; | 61 base::DictionaryValue function_value; |
62 value.Set("event_callback", function_value.DeepCopy()); | 62 value.Set("event_callback", function_value.DeepCopy()); |
63 OptionalFunctionType out; | 63 OptionalFunctionType out; |
64 ASSERT_TRUE(OptionalFunctionType::Populate(value, &out)); | 64 ASSERT_TRUE(OptionalFunctionType::Populate(value, &out)); |
65 EXPECT_TRUE(out.event_callback.get()); | 65 EXPECT_TRUE(out.event_callback.get()); |
66 } | 66 } |
67 { | 67 { |
68 DictionaryValue value; | 68 base::DictionaryValue value; |
69 DictionaryValue function_value; | 69 base::DictionaryValue function_value; |
70 value.Set("event_callback", function_value.DeepCopy()); | 70 value.Set("event_callback", function_value.DeepCopy()); |
71 OptionalFunctionType out; | 71 OptionalFunctionType out; |
72 ASSERT_TRUE(OptionalFunctionType::Populate(value, &out)); | 72 ASSERT_TRUE(OptionalFunctionType::Populate(value, &out)); |
73 EXPECT_TRUE(out.event_callback.get()); | 73 EXPECT_TRUE(out.event_callback.get()); |
74 } | 74 } |
75 } | 75 } |
76 | 76 |
77 TEST(JsonSchemaCompilerFunctionsAsParametersTest, OptionalFunctionToValue) { | 77 TEST(JsonSchemaCompilerFunctionsAsParametersTest, OptionalFunctionToValue) { |
78 { | 78 { |
79 DictionaryValue empty_value; | 79 base::DictionaryValue empty_value; |
80 OptionalFunctionType out; | 80 OptionalFunctionType out; |
81 ASSERT_TRUE(OptionalFunctionType::Populate(empty_value, &out)); | 81 ASSERT_TRUE(OptionalFunctionType::Populate(empty_value, &out)); |
82 // event_callback should not be set in the return from ToValue. | 82 // event_callback should not be set in the return from ToValue. |
83 EXPECT_TRUE(empty_value.Equals(out.ToValue().get())); | 83 EXPECT_TRUE(empty_value.Equals(out.ToValue().get())); |
84 } | 84 } |
85 { | 85 { |
86 DictionaryValue value; | 86 base::DictionaryValue value; |
87 DictionaryValue function_value; | 87 base::DictionaryValue function_value; |
88 value.Set("event_callback", function_value.DeepCopy()); | 88 value.Set("event_callback", function_value.DeepCopy()); |
89 | 89 |
90 OptionalFunctionType out; | 90 OptionalFunctionType out; |
91 ASSERT_TRUE(OptionalFunctionType::Populate(value, &out)); | 91 ASSERT_TRUE(OptionalFunctionType::Populate(value, &out)); |
92 EXPECT_TRUE(value.Equals(out.ToValue().get())); | 92 EXPECT_TRUE(value.Equals(out.ToValue().get())); |
93 } | 93 } |
94 } | 94 } |
OLD | NEW |