OLD | NEW |
(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 dict_with_boolean; |
| 21 dict_with_boolean.Set("event_callback", Value::CreateBooleanValue(true)); |
| 22 FunctionType out; |
| 23 ASSERT_TRUE(FunctionType::Populate(dict_with_boolean, &out)); |
| 24 EXPECT_TRUE(out.has_event_callback); |
| 25 } |
| 26 { |
| 27 DictionaryValue dict_with_string; |
| 28 dict_with_string.Set("event_callback", Value::CreateStringValue("string")); |
| 29 FunctionType out; |
| 30 ASSERT_TRUE(FunctionType::Populate(dict_with_string, &out)); |
| 31 EXPECT_TRUE(out.has_event_callback); |
| 32 } |
| 33 } |
| 34 |
| 35 TEST(JsonSchemaCompilerFunctionsAsParametersTest, RequiredFunctionToValue) { |
| 36 { |
| 37 DictionaryValue value; |
| 38 value.Set("event_callback", Value::CreateBooleanValue(true)); |
| 39 |
| 40 FunctionType out; |
| 41 ASSERT_TRUE(FunctionType::Populate(value, &out)); |
| 42 EXPECT_TRUE(value.Equals(out.ToValue().get())); |
| 43 } |
| 44 { |
| 45 DictionaryValue value; |
| 46 DictionaryValue expected_value; |
| 47 value.Set("event_callback", Value::CreateBooleanValue(false)); |
| 48 expected_value.Set("event_callback", Value::CreateBooleanValue(true)); |
| 49 |
| 50 FunctionType out; |
| 51 ASSERT_TRUE(FunctionType::Populate(value, &out)); |
| 52 EXPECT_TRUE(expected_value.Equals(out.ToValue().get())); |
| 53 } |
| 54 } |
| 55 |
| 56 TEST(JsonSchemaCompilerFunctionsAsParametersTest, PopulateOptionalFunction) { |
| 57 { |
| 58 DictionaryValue empty_value; |
| 59 OptionalFunctionType out; |
| 60 ASSERT_TRUE(OptionalFunctionType::Populate(empty_value, &out)); |
| 61 EXPECT_FALSE(out.has_event_callback); |
| 62 } |
| 63 { |
| 64 DictionaryValue dict_with_boolean; |
| 65 dict_with_boolean.Set("event_callback", Value::CreateBooleanValue(true)); |
| 66 OptionalFunctionType out; |
| 67 ASSERT_TRUE(OptionalFunctionType::Populate(dict_with_boolean, &out)); |
| 68 EXPECT_TRUE(out.has_event_callback); |
| 69 } |
| 70 { |
| 71 DictionaryValue value; |
| 72 value.Set("event_callback", Value::CreateBooleanValue(false)); |
| 73 OptionalFunctionType out; |
| 74 ASSERT_TRUE(OptionalFunctionType::Populate(value, &out)); |
| 75 EXPECT_TRUE(out.has_event_callback); |
| 76 } |
| 77 } |
| 78 |
| 79 TEST(JsonSchemaCompilerFunctionsAsParametersTest, OptionalFunctionToValue) { |
| 80 { |
| 81 DictionaryValue empty_value; |
| 82 DictionaryValue expected_value; |
| 83 expected_value.Set("event_callback", Value::CreateBooleanValue(false)); |
| 84 |
| 85 OptionalFunctionType out; |
| 86 ASSERT_TRUE(OptionalFunctionType::Populate(empty_value, &out)); |
| 87 // event_callback should be set to false in the return from ToValue. |
| 88 EXPECT_TRUE(expected_value.Equals(out.ToValue().get())); |
| 89 } |
| 90 { |
| 91 DictionaryValue value; |
| 92 value.Set("event_callback", Value::CreateBooleanValue(true)); |
| 93 |
| 94 OptionalFunctionType out; |
| 95 ASSERT_TRUE(OptionalFunctionType::Populate(value, &out)); |
| 96 EXPECT_TRUE(value.Equals(out.ToValue().get())); |
| 97 } |
| 98 } |
OLD | NEW |