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

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

Issue 116543010: Remove the Value class names from the global namespace. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fixes Created 6 years, 12 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 | Annotate | Revision Log
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/error_generation.h" 5 #include "tools/json_schema_compiler/test/error_generation.h"
6 6
7 #include "base/json/json_writer.h" 7 #include "base/json/json_writer.h"
8 #include "base/strings/utf_string_conversions.h" 8 #include "base/strings/utf_string_conversions.h"
9 #include "testing/gtest/include/gtest/gtest.h" 9 #include "testing/gtest/include/gtest/gtest.h"
10 #include "tools/json_schema_compiler/test/test_util.h" 10 #include "tools/json_schema_compiler/test/test_util.h"
(...skipping 15 matching lines...) Expand all
26 const base::string16& actual) { 26 const base::string16& actual) {
27 if (ASCIIToUTF16(expected) != actual) 27 if (ASCIIToUTF16(expected) != actual)
28 return testing::AssertionFailure() << expected << " != " << actual; 28 return testing::AssertionFailure() << expected << " != " << actual;
29 return testing::AssertionSuccess(); 29 return testing::AssertionSuccess();
30 } 30 }
31 31
32 // GenerateTypePopulate errors 32 // GenerateTypePopulate errors
33 33
34 TEST(JsonSchemaCompilerErrorTest, RequiredPropertyPopulate) { 34 TEST(JsonSchemaCompilerErrorTest, RequiredPropertyPopulate) {
35 { 35 {
36 scoped_ptr<DictionaryValue> value = Dictionary( 36 scoped_ptr<base::DictionaryValue> value = Dictionary(
37 "string", new StringValue("bling")); 37 "string", new base::StringValue("bling"));
38 EXPECT_TRUE(EqualsUtf16("", GetPopulateError<TestType>(*value))); 38 EXPECT_TRUE(EqualsUtf16("", GetPopulateError<TestType>(*value)));
39 } 39 }
40 { 40 {
41 scoped_ptr<base::BinaryValue> value(new base::BinaryValue()); 41 scoped_ptr<base::BinaryValue> value(new base::BinaryValue());
42 EXPECT_TRUE(EqualsUtf16("expected dictionary, got binary", 42 EXPECT_TRUE(EqualsUtf16("expected dictionary, got binary",
43 GetPopulateError<TestType>(*value))); 43 GetPopulateError<TestType>(*value)));
44 } 44 }
45 } 45 }
46 46
47 TEST(JsonSchemaCompilerErrorTest, UnexpectedTypePopulation) { 47 TEST(JsonSchemaCompilerErrorTest, UnexpectedTypePopulation) {
48 { 48 {
49 scoped_ptr<base::ListValue> value(new base::ListValue()); 49 scoped_ptr<base::ListValue> value(new base::ListValue());
50 EXPECT_TRUE(EqualsUtf16("", 50 EXPECT_TRUE(EqualsUtf16("",
51 GetPopulateError<ChoiceType::Integers>(*value))); 51 GetPopulateError<ChoiceType::Integers>(*value)));
52 } 52 }
53 { 53 {
54 scoped_ptr<base::BinaryValue> value(new base::BinaryValue()); 54 scoped_ptr<base::BinaryValue> value(new base::BinaryValue());
55 EXPECT_TRUE(EqualsUtf16("expected integers or integer, got binary", 55 EXPECT_TRUE(EqualsUtf16("expected integers or integer, got binary",
56 GetPopulateError<ChoiceType::Integers>(*value))); 56 GetPopulateError<ChoiceType::Integers>(*value)));
57 } 57 }
58 } 58 }
59 59
60 // GenerateTypePopulateProperty errors 60 // GenerateTypePopulateProperty errors
61 61
62 TEST(JsonSchemaCompilerErrorTest, TypeIsRequired) { 62 TEST(JsonSchemaCompilerErrorTest, TypeIsRequired) {
63 { 63 {
64 scoped_ptr<DictionaryValue> value = Dictionary( 64 scoped_ptr<base::DictionaryValue> value = Dictionary(
65 "integers", new FundamentalValue(5)); 65 "integers", new FundamentalValue(5));
66 EXPECT_TRUE(EqualsUtf16("", GetPopulateError<ChoiceType>(*value))); 66 EXPECT_TRUE(EqualsUtf16("", GetPopulateError<ChoiceType>(*value)));
67 } 67 }
68 { 68 {
69 scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue()); 69 scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue());
70 EXPECT_TRUE(EqualsUtf16("'integers' is required", 70 EXPECT_TRUE(EqualsUtf16("'integers' is required",
71 GetPopulateError<ChoiceType>(*value))); 71 GetPopulateError<ChoiceType>(*value)));
72 } 72 }
73 } 73 }
74 74
(...skipping 18 matching lines...) Expand all
93 // GenerateFunctionParamsCreate errors 93 // GenerateFunctionParamsCreate errors
94 94
95 TEST(JsonSchemaCompilerErrorTest, ParamIsRequired) { 95 TEST(JsonSchemaCompilerErrorTest, ParamIsRequired) {
96 { 96 {
97 scoped_ptr<base::ListValue> params_value = List( 97 scoped_ptr<base::ListValue> params_value = List(
98 new FundamentalValue(5)); 98 new FundamentalValue(5));
99 EXPECT_TRUE(TestFunction::Params::Create(*params_value)); 99 EXPECT_TRUE(TestFunction::Params::Create(*params_value));
100 } 100 }
101 { 101 {
102 scoped_ptr<base::ListValue> params_value = List( 102 scoped_ptr<base::ListValue> params_value = List(
103 Value::CreateNullValue()); 103 base::Value::CreateNullValue());
104 base::string16 error; 104 base::string16 error;
105 EXPECT_FALSE(TestFunction::Params::Create(*params_value, &error)); 105 EXPECT_FALSE(TestFunction::Params::Create(*params_value, &error));
106 EXPECT_TRUE(EqualsUtf16("'num' is required", error)); 106 EXPECT_TRUE(EqualsUtf16("'num' is required", error));
107 } 107 }
108 } 108 }
109 109
110 // GeneratePopulateVariableFromValue errors 110 // GeneratePopulateVariableFromValue errors
111 111
112 TEST(JsonSchemaCompilerErrorTest, WrongPropertyValueType) { 112 TEST(JsonSchemaCompilerErrorTest, WrongPropertyValueType) {
113 { 113 {
114 scoped_ptr<DictionaryValue> value = Dictionary( 114 scoped_ptr<base::DictionaryValue> value = Dictionary(
115 "string", new StringValue("yes")); 115 "string", new base::StringValue("yes"));
116 EXPECT_TRUE(EqualsUtf16("", GetPopulateError<TestType>(*value))); 116 EXPECT_TRUE(EqualsUtf16("", GetPopulateError<TestType>(*value)));
117 } 117 }
118 { 118 {
119 scoped_ptr<DictionaryValue> value = Dictionary( 119 scoped_ptr<base::DictionaryValue> value = Dictionary(
120 "string", new FundamentalValue(1.1)); 120 "string", new FundamentalValue(1.1));
121 EXPECT_TRUE(EqualsUtf16("'string': expected string, got number", 121 EXPECT_TRUE(EqualsUtf16("'string': expected string, got number",
122 GetPopulateError<TestType>(*value))); 122 GetPopulateError<TestType>(*value)));
123 } 123 }
124 } 124 }
125 125
126 TEST(JsonSchemaCompilerErrorTest, WrongParameterCreationType) { 126 TEST(JsonSchemaCompilerErrorTest, WrongParameterCreationType) {
127 { 127 {
128 scoped_ptr<base::ListValue> params_value = List( 128 scoped_ptr<base::ListValue> params_value = List(
129 new StringValue("Yeah!")); 129 new base::StringValue("Yeah!"));
130 EXPECT_TRUE(TestString::Params::Create(*params_value)); 130 EXPECT_TRUE(TestString::Params::Create(*params_value));
131 } 131 }
132 { 132 {
133 scoped_ptr<base::ListValue> params_value = List( 133 scoped_ptr<base::ListValue> params_value = List(
134 new FundamentalValue(5)); 134 new FundamentalValue(5));
135 base::string16 error; 135 base::string16 error;
136 EXPECT_FALSE(TestTypeInObject::Params::Create(*params_value, &error)); 136 EXPECT_FALSE(TestTypeInObject::Params::Create(*params_value, &error));
137 EXPECT_TRUE(EqualsUtf16("'paramObject': expected dictionary, got integer", 137 EXPECT_TRUE(EqualsUtf16("'paramObject': expected dictionary, got integer",
138 error)); 138 error));
139 } 139 }
140 } 140 }
141 141
142 TEST(JsonSchemaCompilerErrorTest, WrongTypeValueType) { 142 TEST(JsonSchemaCompilerErrorTest, WrongTypeValueType) {
143 { 143 {
144 scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue()); 144 scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue());
145 EXPECT_TRUE(EqualsUtf16("", GetPopulateError<ObjectType>(*value))); 145 EXPECT_TRUE(EqualsUtf16("", GetPopulateError<ObjectType>(*value)));
146 } 146 }
147 { 147 {
148 scoped_ptr<DictionaryValue> value = Dictionary( 148 scoped_ptr<base::DictionaryValue> value = Dictionary(
149 "otherType", new FundamentalValue(1.1)); 149 "otherType", new FundamentalValue(1.1));
150 EXPECT_TRUE(EqualsUtf16("'otherType': expected dictionary, got number", 150 EXPECT_TRUE(EqualsUtf16("'otherType': expected dictionary, got number",
151 GetPopulateError<ObjectType>(*value))); 151 GetPopulateError<ObjectType>(*value)));
152 } 152 }
153 } 153 }
154 154
155 TEST(JsonSchemaCompilerErrorTest, UnableToPopulateArray) { 155 TEST(JsonSchemaCompilerErrorTest, UnableToPopulateArray) {
156 { 156 {
157 scoped_ptr<base::ListValue> params_value = List( 157 scoped_ptr<base::ListValue> params_value = List(
158 new FundamentalValue(5)); 158 new FundamentalValue(5));
159 EXPECT_TRUE(EqualsUtf16("", 159 EXPECT_TRUE(EqualsUtf16("",
160 GetPopulateError<ChoiceType::Integers>(*params_value))); 160 GetPopulateError<ChoiceType::Integers>(*params_value)));
161 } 161 }
162 { 162 {
163 scoped_ptr<base::ListValue> params_value = List( 163 scoped_ptr<base::ListValue> params_value = List(
164 new FundamentalValue(5), 164 new FundamentalValue(5),
165 new FundamentalValue(false)); 165 new FundamentalValue(false));
166 EXPECT_TRUE(EqualsUtf16("unable to populate array 'integers'", 166 EXPECT_TRUE(EqualsUtf16("unable to populate array 'integers'",
167 GetPopulateError<ChoiceType::Integers>(*params_value))); 167 GetPopulateError<ChoiceType::Integers>(*params_value)));
168 } 168 }
169 } 169 }
170 170
171 TEST(JsonSchemaCompilerErrorTest, BinaryTypeExpected) { 171 TEST(JsonSchemaCompilerErrorTest, BinaryTypeExpected) {
172 { 172 {
173 scoped_ptr<DictionaryValue> value = Dictionary( 173 scoped_ptr<base::DictionaryValue> value = Dictionary(
174 "data", new base::BinaryValue()); 174 "data", new base::BinaryValue());
175 EXPECT_TRUE(EqualsUtf16("", GetPopulateError<BinaryData>(*value))); 175 EXPECT_TRUE(EqualsUtf16("", GetPopulateError<BinaryData>(*value)));
176 } 176 }
177 { 177 {
178 scoped_ptr<DictionaryValue> value = Dictionary( 178 scoped_ptr<base::DictionaryValue> value = Dictionary(
179 "data", new FundamentalValue(1.1)); 179 "data", new FundamentalValue(1.1));
180 EXPECT_TRUE(EqualsUtf16("'data': expected binary, got number", 180 EXPECT_TRUE(EqualsUtf16("'data': expected binary, got number",
181 GetPopulateError<BinaryData>(*value))); 181 GetPopulateError<BinaryData>(*value)));
182 } 182 }
183 } 183 }
184 184
185 TEST(JsonSchemaCompilerErrorTest, ListExpected) { 185 TEST(JsonSchemaCompilerErrorTest, ListExpected) {
186 { 186 {
187 scoped_ptr<DictionaryValue> value = Dictionary( 187 scoped_ptr<base::DictionaryValue> value = Dictionary(
188 "TheArray", new base::ListValue()); 188 "TheArray", new base::ListValue());
189 EXPECT_TRUE(EqualsUtf16("", GetPopulateError<ArrayObject>(*value))); 189 EXPECT_TRUE(EqualsUtf16("", GetPopulateError<ArrayObject>(*value)));
190 } 190 }
191 { 191 {
192 scoped_ptr<DictionaryValue> value = Dictionary( 192 scoped_ptr<base::DictionaryValue> value = Dictionary(
193 "TheArray", new FundamentalValue(5)); 193 "TheArray", new FundamentalValue(5));
194 EXPECT_TRUE(EqualsUtf16("'TheArray': expected list, got integer", 194 EXPECT_TRUE(EqualsUtf16("'TheArray': expected list, got integer",
195 GetPopulateError<ArrayObject>(*value))); 195 GetPopulateError<ArrayObject>(*value)));
196 } 196 }
197 } 197 }
198 198
199 // GenerateStringToEnumConversion errors 199 // GenerateStringToEnumConversion errors
200 200
201 TEST(JsonSchemaCompilerErrorTest, BadEnumValue) { 201 TEST(JsonSchemaCompilerErrorTest, BadEnumValue) {
202 { 202 {
203 scoped_ptr<DictionaryValue> value = Dictionary( 203 scoped_ptr<base::DictionaryValue> value = Dictionary(
204 "enumeration", new StringValue("one")); 204 "enumeration", new base::StringValue("one"));
205 EXPECT_TRUE(EqualsUtf16("", GetPopulateError<HasEnumeration>(*value))); 205 EXPECT_TRUE(EqualsUtf16("", GetPopulateError<HasEnumeration>(*value)));
206 } 206 }
207 { 207 {
208 scoped_ptr<DictionaryValue> value = Dictionary( 208 scoped_ptr<base::DictionaryValue> value = Dictionary(
209 "enumeration", new StringValue("bad sauce")); 209 "enumeration", new base::StringValue("bad sauce"));
210 EXPECT_TRUE(EqualsUtf16("'enumeration': expected \"one\" or \"two\" " 210 EXPECT_TRUE(EqualsUtf16("'enumeration': expected \"one\" or \"two\" "
211 "or \"three\", got \"bad sauce\"", 211 "or \"three\", got \"bad sauce\"",
212 GetPopulateError<HasEnumeration>(*value))); 212 GetPopulateError<HasEnumeration>(*value)));
213 } 213 }
214 } 214 }
OLDNEW
« no previous file with comments | « tools/json_schema_compiler/test/enums_unittest.cc ('k') | tools/json_schema_compiler/test/functions_as_parameters_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698