Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(83)

Side by Side Diff: tools/json_schema_compiler/test/functions_as_parameters_unittest.cc

Issue 10824002: JSON Schema Compiler supports functions as PropertyTypes. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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.
4
5 #include "tools/json_schema_compiler/test/functions_as_parameters.h"
6
7 #include "testing/gtest/include/gtest/gtest.h"
8
9 using namespace test::api::functions_as_parameters;
10
11 TEST(JsonSchemaCompilerFunctionsAsParametersTest, PopulateRequiredFunction) {
12 // The expectation is that if any value is set for the function, then
13 // the function is "present".
14 {
15 DictionaryValue empty_value;
16 FunctionType out;
17 EXPECT_FALSE(FunctionType::Populate(empty_value, &out));
18 }
19 {
20 DictionaryValue value;
21 DictionaryValue function_dict;
22 value.Set("event_callback", function_dict.DeepCopy());
23 FunctionType out;
24 ASSERT_TRUE(FunctionType::Populate(value, &out));
25 EXPECT_TRUE(out.event_callback.empty());
26 }
27 }
28
29 TEST(JsonSchemaCompilerFunctionsAsParametersTest, RequiredFunctionToValue) {
30 {
31 DictionaryValue value;
32 DictionaryValue function_dict;
33 value.Set("event_callback", function_dict.DeepCopy());
34
35 FunctionType out;
36 ASSERT_TRUE(FunctionType::Populate(value, &out));
37 EXPECT_TRUE(value.Equals(out.ToValue().get()));
38 }
39 {
40 DictionaryValue value;
41 DictionaryValue expected_value;
42 DictionaryValue function_dict;
43 value.Set("event_callback", function_dict.DeepCopy());
44 expected_value.Set("event_callback", function_dict.DeepCopy());
45
46 FunctionType out;
47 ASSERT_TRUE(FunctionType::Populate(value, &out));
48 EXPECT_TRUE(expected_value.Equals(out.ToValue().get()));
49 }
50 }
51
52 TEST(JsonSchemaCompilerFunctionsAsParametersTest, PopulateOptionalFunction) {
53 {
54 DictionaryValue empty_value;
55 OptionalFunctionType out;
56 ASSERT_TRUE(OptionalFunctionType::Populate(empty_value, &out));
57 EXPECT_FALSE(out.event_callback.get());
58 }
59 {
60 DictionaryValue value;
61 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());
66 }
67 {
68 DictionaryValue value;
69 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());
74 }
75 }
76
77 TEST(JsonSchemaCompilerFunctionsAsParametersTest, OptionalFunctionToValue) {
78 {
79 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()));
84 }
85 {
86 DictionaryValue value;
87 DictionaryValue function_value;
88 value.Set("event_callback", function_value.DeepCopy());
89
90 OptionalFunctionType out;
91 ASSERT_TRUE(OptionalFunctionType::Populate(value, &out));
92 EXPECT_TRUE(value.Equals(out.ToValue().get()));
93 }
94 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698