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

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

Issue 10701012: JSON Schema Compiler: Added event compilation. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Tested GetAllPossibleParameterLists better. Created 8 years, 5 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
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "tools/json_schema_compiler/test/additional_properties.h" 5 #include "tools/json_schema_compiler/test/additional_properties.h"
6 6
7 #include "chrome/common/extensions/value_builder.h"
7 #include "testing/gtest/include/gtest/gtest.h" 8 #include "testing/gtest/include/gtest/gtest.h"
8 9
9 using namespace test::api::additional_properties; 10 using namespace test::api::additional_properties;
11 using namespace extensions;
10 12
11 TEST(JsonSchemaCompilerAdditionalPropertiesTest, 13 TEST(JsonSchemaCompilerAdditionalPropertiesTest,
12 AdditionalPropertiesTypePopulate) { 14 AdditionalPropertiesTypePopulate) {
13 { 15 {
14 scoped_ptr<ListValue> list_value(new ListValue()); 16 scoped_ptr<DictionaryValue> type_value(DictionaryBuilder()
15 list_value->Append(Value::CreateStringValue("asdf")); 17 .Set("string", "value")
16 list_value->Append(Value::CreateIntegerValue(4)); 18 .Set("other", 9)
17 scoped_ptr<DictionaryValue> type_value(new DictionaryValue()); 19 .Set("another", ListBuilder().Append("asdf").Append(4))
18 type_value->SetString("string", "value"); 20 .Build());
19 type_value->SetInteger("other", 9); 21 AdditionalPropertiesType type;
20 type_value->Set("another", list_value.release()); 22 EXPECT_TRUE(AdditionalPropertiesType::Populate(*type_value, &type));
21 scoped_ptr<AdditionalPropertiesType> type(new AdditionalPropertiesType()); 23 EXPECT_EQ("value", type.string);
22 EXPECT_TRUE(AdditionalPropertiesType::Populate(*type_value, type.get()));
23 EXPECT_EQ("value", type->string);
24 EXPECT_TRUE(type_value->Remove("string", NULL)); 24 EXPECT_TRUE(type_value->Remove("string", NULL));
25 EXPECT_TRUE(type->additional_properties.Equals(type_value.get())); 25 EXPECT_TRUE(type.additional_properties.Equals(type_value.get()));
26 } 26 }
27 { 27 {
28 scoped_ptr<DictionaryValue> type_value(new DictionaryValue()); 28 scoped_ptr<DictionaryValue> type_value(
29 type_value->SetInteger("string", 3); 29 DictionaryBuilder().Set("string", 3).Build());
30 scoped_ptr<AdditionalPropertiesType> type(new AdditionalPropertiesType()); 30 AdditionalPropertiesType type;
31 EXPECT_FALSE(AdditionalPropertiesType::Populate(*type_value, type.get())); 31 EXPECT_FALSE(AdditionalPropertiesType::Populate(*type_value, &type));
32 } 32 }
33 } 33 }
34 34
35 TEST(JsonSchemaCompilerAdditionalPropertiesTest, 35 TEST(JsonSchemaCompilerAdditionalPropertiesTest,
36 AdditionalPropertiesParamsCreate) { 36 AdditionalPropertiesParamsCreate) {
37 scoped_ptr<DictionaryValue> param_object_value(new DictionaryValue()); 37 scoped_ptr<ListValue> params_value(ListBuilder().Append(
38 param_object_value->SetString("str", "a"); 38 DictionaryBuilder().Set("str", "a").Set("num", 1)).Build());
39 param_object_value->SetInteger("num", 1); 39 DictionaryValue* object_value = NULL;
40 scoped_ptr<ListValue> params_value(new ListValue()); 40 ASSERT_TRUE(params_value->GetDictionary(0, &object_value));
41 params_value->Append(param_object_value->DeepCopy()); 41
42 scoped_ptr<AdditionalProperties::Params> params( 42 scoped_ptr<AdditionalProperties::Params> params(
43 AdditionalProperties::Params::Create(*params_value)); 43 AdditionalProperties::Params::Create(*params_value));
44 EXPECT_TRUE(params.get()); 44 EXPECT_TRUE(params.get());
45 EXPECT_TRUE(params->param_object.additional_properties.Equals( 45 EXPECT_TRUE(params->param_object.additional_properties.Equals(object_value));
46 param_object_value.get()));
47 } 46 }
48 47
49 TEST(JsonSchemaCompilerAdditionalPropertiesTest, 48 TEST(JsonSchemaCompilerAdditionalPropertiesTest,
50 ReturnAdditionalPropertiesResultCreate) { 49 ReturnAdditionalPropertiesResultCreate) {
51 scoped_ptr<DictionaryValue> result_object_value(new DictionaryValue()); 50 scoped_ptr<DictionaryValue> additional(
52 result_object_value->SetString("key", "value"); 51 DictionaryBuilder().Set("key", "value").Build());
53 scoped_ptr<ReturnAdditionalProperties::Result::ResultObject> result_object( 52 ReturnAdditionalProperties::Result::ResultObject result_object;
54 new ReturnAdditionalProperties::Result::ResultObject()); 53 result_object.integer = 5;
55 result_object->integer = 5; 54 result_object.additional_properties.MergeDictionary(additional.get());
56 result_object->additional_properties.MergeDictionary( 55 scoped_ptr<ListValue> results(
57 result_object_value.get()); 56 ReturnAdditionalProperties::Result::Create(result_object));
58 scoped_ptr<Value> result(
59 ReturnAdditionalProperties::Result::Create(*result_object));
60 DictionaryValue* result_dict = NULL; 57 DictionaryValue* result_dict = NULL;
61 EXPECT_TRUE(result->GetAsDictionary(&result_dict)); 58 ASSERT_TRUE(results->GetDictionary(0, &result_dict));
62 59
63 Value* int_temp_value_out = NULL; 60 Value* int_temp_value_out = NULL;
64 int int_temp = 0; 61 int int_temp = 0;
65 EXPECT_TRUE(result_dict->Remove("integer", &int_temp_value_out)); 62 EXPECT_TRUE(result_dict->Remove("integer", &int_temp_value_out));
66 scoped_ptr<Value> int_temp_value(int_temp_value_out); 63 scoped_ptr<Value> int_temp_value(int_temp_value_out);
67 EXPECT_TRUE(int_temp_value->GetAsInteger(&int_temp)); 64 EXPECT_TRUE(int_temp_value->GetAsInteger(&int_temp));
68 EXPECT_EQ(5, int_temp); 65 EXPECT_EQ(5, int_temp);
69 66
70 EXPECT_TRUE(result_dict->Equals(result_object_value.get())); 67 EXPECT_TRUE(result_dict->Equals(additional.get()));
71 } 68 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698