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

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

Issue 9491002: json_schema_compiler: any, additionalProperties, functions on types (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: add any in arrays to util.h Created 8 years, 9 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/additionalProperties.h"
6
7 #include "testing/gtest/include/gtest/gtest.h"
8
9 using namespace test::api::additional_properties;
10
11 TEST(JsonSchemaCompilerAdditionalPropertiesTest,
12 AdditionalPropertiesTypePopulate) {
13 {
14 scoped_ptr<ListValue> list_value(new ListValue());
15 list_value->Append(Value::CreateStringValue("asdf"));
16 list_value->Append(Value::CreateIntegerValue(4));
17 scoped_ptr<DictionaryValue> type_value(new DictionaryValue());
18 type_value->SetString("string", "value");
19 type_value->SetInteger("other", 9);
20 type_value->Set("another", list_value.release());
21 scoped_ptr<AdditionalPropertiesType> type(new AdditionalPropertiesType());
22 EXPECT_TRUE(AdditionalPropertiesType::Populate(*type_value, type.get()));
23 EXPECT_EQ("value", type->string);
24 EXPECT_TRUE(type_value->Remove("string", NULL));
25 EXPECT_TRUE(type->additional_properties.Equals(type_value.get()));
26 }
27 {
28 scoped_ptr<DictionaryValue> type_value(new DictionaryValue());
29 type_value->SetInteger("string", 3);
30 scoped_ptr<AdditionalPropertiesType> type(new AdditionalPropertiesType());
31 EXPECT_FALSE(AdditionalPropertiesType::Populate(*type_value, type.get()));
32 }
33 }
34
35 TEST(JsonSchemaCompilerAdditionalPropertiesTest,
36 AdditionalPropertiesParamsCreate) {
37 scoped_ptr<DictionaryValue> param_object_value(new DictionaryValue());
38 param_object_value->SetString("str", "a");
39 param_object_value->SetInteger("num", 1);
40 scoped_ptr<ListValue> params_value(new ListValue());
41 params_value->Append(param_object_value->DeepCopy());
42 scoped_ptr<AdditionalProperties::Params> params(
43 AdditionalProperties::Params::Create(*params_value));
44 EXPECT_TRUE(params.get());
45 EXPECT_TRUE(params->param_object.additional_properties.Equals(
46 param_object_value.get()));
47 }
48
49 TEST(JsonSchemaCompilerAdditionalPropertiesTest,
50 ReturnAdditionalPropertiesResultCreate) {
51 scoped_ptr<DictionaryValue> result_object_value(new DictionaryValue());
52 result_object_value->SetString("key", "value");
53 scoped_ptr<ReturnAdditionalProperties::Result::ResultObject> result_object(
54 new ReturnAdditionalProperties::Result::ResultObject());
55 result_object->integer = 5;
56 result_object->additional_properties.MergeDictionary(
57 result_object_value.get());
58 scoped_ptr<Value> result(
59 ReturnAdditionalProperties::Result::Create(*result_object));
60 DictionaryValue* result_dict = NULL;
61 EXPECT_TRUE(result->GetAsDictionary(&result_dict));
62
63 Value* int_temp_value = NULL;
64 int int_temp = 0;
65 EXPECT_TRUE(result_dict->Remove("integer", &int_temp_value));
66 EXPECT_TRUE(int_temp_value->GetAsInteger(&int_temp));
67 EXPECT_EQ(5, int_temp);
68
69 EXPECT_TRUE(result_dict->Equals(result_object_value.get()));
70 }
OLDNEW
« no previous file with comments | « tools/json_schema_compiler/test/additionalProperties.json ('k') | tools/json_schema_compiler/test/any.json » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698