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

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

Issue 10790040: JSON Schema Compiler now supports conversion from Choice to base::Value. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: added comments/style 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/choices.h" 5 #include "tools/json_schema_compiler/test/choices.h"
6 6
7 #include "testing/gtest/include/gtest/gtest.h" 7 #include "testing/gtest/include/gtest/gtest.h"
8 8
9 using namespace test::api::choices; 9 using namespace test::api::choices;
10 10
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 object_param->SetWithoutPathExpansion("integers", 104 object_param->SetWithoutPathExpansion("integers",
105 Value::CreateIntegerValue(6)); 105 Value::CreateIntegerValue(6));
106 scoped_ptr<ListValue> params_value(new ListValue()); 106 scoped_ptr<ListValue> params_value(new ListValue());
107 params_value->Append(object_param.release()); 107 params_value->Append(object_param.release());
108 scoped_ptr<ObjectWithChoices::Params> params( 108 scoped_ptr<ObjectWithChoices::Params> params(
109 ObjectWithChoices::Params::Create(*params_value)); 109 ObjectWithChoices::Params::Create(*params_value));
110 EXPECT_FALSE(params.get()); 110 EXPECT_FALSE(params.get());
111 } 111 }
112 } 112 }
113 113
114 TEST(JsonSchemaCompilerChoicesTest, PopulateChoiceType) {
115 Value* integers_value = Value::CreateIntegerValue(5);
116 ListValue* strings_value(new ListValue());
not at google - send to devlin 2012/07/18 01:21:35 nit: = new ListValue()
chebert 2012/07/19 00:56:01 Done.
117 strings_value->Append(Value::CreateStringValue("list"));
118 strings_value->Append(Value::CreateStringValue("of"));
119 strings_value->Append(Value::CreateStringValue("strings"));
120
121 scoped_ptr<DictionaryValue> value(new DictionaryValue());
not at google - send to devlin 2012/07/18 01:21:35 value on stack
chebert 2012/07/19 00:56:01 Done.
122 value->Set("integers", integers_value);
not at google - send to devlin 2012/07/18 01:21:35 just inline integers_value here. Should be able to
chebert 2012/07/19 00:56:01 Done.
123 value->Set("strings", strings_value);
124
125 scoped_ptr<ChoiceType> out(new ChoiceType);
not at google - send to devlin 2012/07/18 01:21:35 Just put on stack, use &out rather than out.get()
chebert 2012/07/19 00:56:01 Done.
126 ASSERT_TRUE(ChoiceType::Populate(*value, out.get()));
127 EXPECT_EQ(ChoiceType::INTEGERS_INTEGER, out->integers_type);
128 EXPECT_EQ(ChoiceType::STRINGS_ARRAY, out->strings_type);
not at google - send to devlin 2012/07/18 01:21:35 check values are correct too?
chebert 2012/07/19 00:56:01 Done.
129 }
130
131 TEST(JsonSchemaCompilerChoicesTest, ChoiceTypeToValue) {
132 Value* integers_value = Value::CreateIntegerValue(5);
133 ListValue* strings_value(new ListValue());
134 strings_value->Append(Value::CreateStringValue("list"));
135 strings_value->Append(Value::CreateStringValue("of"));
136 strings_value->Append(Value::CreateStringValue("strings"));
137
138 scoped_ptr<DictionaryValue> value(new DictionaryValue());
not at google - send to devlin 2012/07/18 01:21:35 ditto value on stack
chebert 2012/07/19 00:56:01 Done.
139 value->Set("integers", integers_value);
not at google - send to devlin 2012/07/18 01:21:35 ditto inline integers_value
chebert 2012/07/19 00:56:01 Done.
140 value->Set("strings", strings_value);
141
142 scoped_ptr<ChoiceType> out(new ChoiceType);
not at google - send to devlin 2012/07/18 01:21:35 ditto ChoiceType()
chebert 2012/07/19 00:56:01 Done.
143 ASSERT_TRUE(ChoiceType::Populate(*value, out.get()));
144
145 EXPECT_TRUE(value->Equals(out->ToValue().get()));
146 }
147
114 TEST(JsonSchemaCompilerChoicesTest, ReturnChoices) { 148 TEST(JsonSchemaCompilerChoicesTest, ReturnChoices) {
115 { 149 {
116 std::vector<int> integers; 150 std::vector<int> integers;
117 integers.push_back(1); 151 integers.push_back(1);
118 integers.push_back(2); 152 integers.push_back(2);
119 scoped_ptr<ListValue> array_results = 153 scoped_ptr<ListValue> array_results =
120 ReturnChoices::Results::Create(integers); 154 ReturnChoices::Results::Create(integers);
121 155
122 ListValue expected; 156 ListValue expected;
123 ListValue* expected_argument = new ListValue(); 157 ListValue* expected_argument = new ListValue();
124 expected_argument->Append(Value::CreateIntegerValue(1)); 158 expected_argument->Append(Value::CreateIntegerValue(1));
125 expected_argument->Append(Value::CreateIntegerValue(2)); 159 expected_argument->Append(Value::CreateIntegerValue(2));
126 expected.Append(expected_argument); 160 expected.Append(expected_argument);
127 EXPECT_TRUE(array_results->Equals(&expected)); 161 EXPECT_TRUE(array_results->Equals(&expected));
128 } 162 }
129 { 163 {
130 scoped_ptr<ListValue> integer_results = ReturnChoices::Results::Create(5); 164 scoped_ptr<ListValue> integer_results = ReturnChoices::Results::Create(5);
131 ListValue expected; 165 ListValue expected;
132 expected.Append(Value::CreateIntegerValue(5)); 166 expected.Append(Value::CreateIntegerValue(5));
133 EXPECT_TRUE(integer_results->Equals(&expected)); 167 EXPECT_TRUE(integer_results->Equals(&expected));
134 } 168 }
135 } 169 }
OLDNEW
« tools/json_schema_compiler/h_generator.py ('K') | « tools/json_schema_compiler/test/choices.json ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698