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
3 // found in the LICENSE file.
5 #include "tools/json_schema_compiler/test/functions_as_parameters.h"
7 #include "testing/gtest/include/gtest/gtest.h"
9 using namespace test::api::functions_as_parameters
;
11 TEST(JsonSchemaCompilerFunctionsAsParametersTest
, PopulateRequiredFunction
) {
12 // The expectation is that if any value is set for the function, then
13 // the function is "present".
15 base::DictionaryValue empty_value
;
17 EXPECT_FALSE(FunctionType::Populate(empty_value
, &out
));
20 base::DictionaryValue value
;
21 base::DictionaryValue function_dict
;
22 value
.Set("event_callback", function_dict
.DeepCopy());
24 ASSERT_TRUE(FunctionType::Populate(value
, &out
));
25 EXPECT_TRUE(out
.event_callback
.empty());
29 TEST(JsonSchemaCompilerFunctionsAsParametersTest
, RequiredFunctionToValue
) {
31 base::DictionaryValue value
;
32 base::DictionaryValue function_dict
;
33 value
.Set("event_callback", function_dict
.DeepCopy());
36 ASSERT_TRUE(FunctionType::Populate(value
, &out
));
37 EXPECT_TRUE(value
.Equals(out
.ToValue().get()));
40 base::DictionaryValue value
;
41 base::DictionaryValue expected_value
;
42 base::DictionaryValue function_dict
;
43 value
.Set("event_callback", function_dict
.DeepCopy());
44 expected_value
.Set("event_callback", function_dict
.DeepCopy());
47 ASSERT_TRUE(FunctionType::Populate(value
, &out
));
48 EXPECT_TRUE(expected_value
.Equals(out
.ToValue().get()));
52 TEST(JsonSchemaCompilerFunctionsAsParametersTest
, PopulateOptionalFunction
) {
54 base::DictionaryValue empty_value
;
55 OptionalFunctionType out
;
56 ASSERT_TRUE(OptionalFunctionType::Populate(empty_value
, &out
));
57 EXPECT_FALSE(out
.event_callback
.get());
60 base::DictionaryValue value
;
61 base::DictionaryValue function_value
;
62 value
.Set("event_callback", function_value
.DeepCopy());
63 OptionalFunctionType out
;
64 ASSERT_TRUE(OptionalFunctionType::Populate(value
, &out
));
65 EXPECT_TRUE(out
.event_callback
.get());
68 base::DictionaryValue value
;
69 base::DictionaryValue function_value
;
70 value
.Set("event_callback", function_value
.DeepCopy());
71 OptionalFunctionType out
;
72 ASSERT_TRUE(OptionalFunctionType::Populate(value
, &out
));
73 EXPECT_TRUE(out
.event_callback
.get());
77 TEST(JsonSchemaCompilerFunctionsAsParametersTest
, OptionalFunctionToValue
) {
79 base::DictionaryValue empty_value
;
80 OptionalFunctionType out
;
81 ASSERT_TRUE(OptionalFunctionType::Populate(empty_value
, &out
));
82 // event_callback should not be set in the return from ToValue.
83 EXPECT_TRUE(empty_value
.Equals(out
.ToValue().get()));
86 base::DictionaryValue value
;
87 base::DictionaryValue function_value
;
88 value
.Set("event_callback", function_value
.DeepCopy());
90 OptionalFunctionType out
;
91 ASSERT_TRUE(OptionalFunctionType::Populate(value
, &out
));
92 EXPECT_TRUE(value
.Equals(out
.ToValue().get()));