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 "testing/gtest/include/gtest/gtest.h"
6 #include "tools/json_schema_compiler/test/additional_properties.h"
8 using namespace test::api::additional_properties
;
10 TEST(JsonSchemaCompilerAdditionalPropertiesTest
,
11 AdditionalPropertiesTypePopulate
) {
13 scoped_ptr
<base::ListValue
> list_value(new base::ListValue());
14 list_value
->Append(new base::StringValue("asdf"));
15 list_value
->Append(new base::FundamentalValue(4));
16 scoped_ptr
<base::DictionaryValue
> type_value(new base::DictionaryValue());
17 type_value
->SetString("string", "value");
18 type_value
->SetInteger("other", 9);
19 type_value
->Set("another", list_value
.release());
20 scoped_ptr
<AdditionalPropertiesType
> type(new AdditionalPropertiesType());
21 ASSERT_TRUE(AdditionalPropertiesType::Populate(*type_value
, type
.get()));
22 EXPECT_TRUE(type
->additional_properties
.Equals(type_value
.get()));
25 scoped_ptr
<base::DictionaryValue
> type_value(new base::DictionaryValue());
26 type_value
->SetInteger("string", 3);
27 scoped_ptr
<AdditionalPropertiesType
> type(new AdditionalPropertiesType());
28 EXPECT_FALSE(AdditionalPropertiesType::Populate(*type_value
, type
.get()));
32 TEST(JsonSchemaCompilerAdditionalPropertiesTest
,
33 AdditionalPropertiesParamsCreate
) {
34 scoped_ptr
<base::DictionaryValue
> param_object_value(
35 new base::DictionaryValue());
36 param_object_value
->SetString("str", "a");
37 param_object_value
->SetInteger("num", 1);
38 scoped_ptr
<base::ListValue
> params_value(new base::ListValue());
39 params_value
->Append(param_object_value
->DeepCopy());
40 scoped_ptr
<AdditionalProperties::Params
> params(
41 AdditionalProperties::Params::Create(*params_value
));
42 EXPECT_TRUE(params
.get());
43 EXPECT_TRUE(params
->param_object
.additional_properties
.Equals(
44 param_object_value
.get()));
47 TEST(JsonSchemaCompilerAdditionalPropertiesTest
,
48 ReturnAdditionalPropertiesResultCreate
) {
49 ReturnAdditionalProperties::Results::ResultObject result_object
;
50 result_object
.integer
= 5;
51 result_object
.additional_properties
["key"] = "value";
53 base::ListValue expected
;
55 base::DictionaryValue
* dict
= new base::DictionaryValue();
56 dict
->SetInteger("integer", 5);
57 dict
->SetString("key", "value");
58 expected
.Append(dict
);
61 EXPECT_TRUE(base::Value::Equals(
62 ReturnAdditionalProperties::Results::Create(result_object
).get(),