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

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

Issue 2149253003: Switch various ValueTypeToString()s to base::Value::GetTypeName(). (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@value
Patch Set: fix tests Created 4 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 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"
11 11
12 using namespace test::api::error_generation; 12 using namespace test::api::error_generation;
13 using base::FundamentalValue; 13 using base::FundamentalValue;
14 using json_schema_compiler::test_util::Dictionary; 14 using json_schema_compiler::test_util::Dictionary;
15 using json_schema_compiler::test_util::List; 15 using json_schema_compiler::test_util::List;
16 16
17 template <typename T> 17 template <typename T>
18 base::string16 GetPopulateError(const base::Value& value) { 18 base::string16 GetPopulateError(const base::Value& value) {
19 base::string16 error; 19 base::string16 error;
20 T test_type; 20 T test_type;
21 T::Populate(value, &test_type, &error); 21 T::Populate(value, &test_type, &error);
22 return error; 22 return error;
23 } 23 }
24 24
25 testing::AssertionResult EqualsUtf16(const std::string& expected, 25 testing::AssertionResult EqualsUtf16(const std::string& expected,
26 const base::string16& actual) { 26 const base::string16& actual) {
27 if (base::ASCIIToUTF16(expected) != actual) 27 if (base::ASCIIToUTF16(expected) == actual)
28 return testing::AssertionFailure() << expected << " != " << actual; 28 return testing::AssertionSuccess();
29 return testing::AssertionSuccess(); 29 return testing::AssertionFailure() << "\n actual: " << actual
30 << "\n expected: " << expected;
30 } 31 }
31 32
32 // GenerateTypePopulate errors 33 // GenerateTypePopulate errors
33 34
34 TEST(JsonSchemaCompilerErrorTest, RequiredPropertyPopulate) { 35 TEST(JsonSchemaCompilerErrorTest, RequiredPropertyPopulate) {
35 { 36 {
36 std::unique_ptr<base::DictionaryValue> value = 37 std::unique_ptr<base::DictionaryValue> value =
37 Dictionary("string", new base::StringValue("bling")); 38 Dictionary("string", new base::StringValue("bling"));
38 EXPECT_TRUE(EqualsUtf16("", GetPopulateError<TestType>(*value))); 39 EXPECT_TRUE(EqualsUtf16("", GetPopulateError<TestType>(*value)));
39 } 40 }
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 113
113 TEST(JsonSchemaCompilerErrorTest, WrongPropertyValueType) { 114 TEST(JsonSchemaCompilerErrorTest, WrongPropertyValueType) {
114 { 115 {
115 std::unique_ptr<base::DictionaryValue> value = 116 std::unique_ptr<base::DictionaryValue> value =
116 Dictionary("string", new base::StringValue("yes")); 117 Dictionary("string", new base::StringValue("yes"));
117 EXPECT_TRUE(EqualsUtf16("", GetPopulateError<TestType>(*value))); 118 EXPECT_TRUE(EqualsUtf16("", GetPopulateError<TestType>(*value)));
118 } 119 }
119 { 120 {
120 std::unique_ptr<base::DictionaryValue> value = 121 std::unique_ptr<base::DictionaryValue> value =
121 Dictionary("string", new FundamentalValue(1.1)); 122 Dictionary("string", new FundamentalValue(1.1));
122 EXPECT_TRUE(EqualsUtf16("'string': expected string, got number", 123 EXPECT_TRUE(EqualsUtf16("'string': expected string, got double",
123 GetPopulateError<TestType>(*value))); 124 GetPopulateError<TestType>(*value)));
124 } 125 }
125 } 126 }
126 127
127 TEST(JsonSchemaCompilerErrorTest, WrongParameterCreationType) { 128 TEST(JsonSchemaCompilerErrorTest, WrongParameterCreationType) {
128 { 129 {
129 base::string16 error; 130 base::string16 error;
130 std::unique_ptr<base::ListValue> params_value = 131 std::unique_ptr<base::ListValue> params_value =
131 List(new base::StringValue("Yeah!")); 132 List(new base::StringValue("Yeah!"));
132 EXPECT_TRUE(TestString::Params::Create(*params_value, &error)); 133 EXPECT_TRUE(TestString::Params::Create(*params_value, &error));
(...skipping 12 matching lines...) Expand all
145 { 146 {
146 std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue()); 147 std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue());
147 EXPECT_TRUE(EqualsUtf16("", GetPopulateError<ObjectType>(*value))); 148 EXPECT_TRUE(EqualsUtf16("", GetPopulateError<ObjectType>(*value)));
148 } 149 }
149 { 150 {
150 std::unique_ptr<base::DictionaryValue> value = 151 std::unique_ptr<base::DictionaryValue> value =
151 Dictionary("otherType", new FundamentalValue(1.1)); 152 Dictionary("otherType", new FundamentalValue(1.1));
152 ObjectType out; 153 ObjectType out;
153 base::string16 error; 154 base::string16 error;
154 EXPECT_TRUE(ObjectType::Populate(*value, &out, &error)); 155 EXPECT_TRUE(ObjectType::Populate(*value, &out, &error));
155 EXPECT_TRUE(EqualsUtf16("'otherType': expected dictionary, got number", 156 EXPECT_TRUE(EqualsUtf16("'otherType': expected dictionary, got double",
156 error)); 157 error));
157 EXPECT_EQ(NULL, out.other_type.get()); 158 EXPECT_EQ(NULL, out.other_type.get());
158 } 159 }
159 } 160 }
160 161
161 TEST(JsonSchemaCompilerErrorTest, UnableToPopulateArray) { 162 TEST(JsonSchemaCompilerErrorTest, UnableToPopulateArray) {
162 { 163 {
163 std::unique_ptr<base::ListValue> params_value = 164 std::unique_ptr<base::ListValue> params_value =
164 List(new FundamentalValue(5)); 165 List(new FundamentalValue(5));
165 EXPECT_TRUE(EqualsUtf16("", 166 EXPECT_TRUE(EqualsUtf16("",
(...skipping 10 matching lines...) Expand all
176 177
177 TEST(JsonSchemaCompilerErrorTest, BinaryTypeExpected) { 178 TEST(JsonSchemaCompilerErrorTest, BinaryTypeExpected) {
178 { 179 {
179 std::unique_ptr<base::DictionaryValue> value = 180 std::unique_ptr<base::DictionaryValue> value =
180 Dictionary("data", new base::BinaryValue()); 181 Dictionary("data", new base::BinaryValue());
181 EXPECT_TRUE(EqualsUtf16("", GetPopulateError<BinaryData>(*value))); 182 EXPECT_TRUE(EqualsUtf16("", GetPopulateError<BinaryData>(*value)));
182 } 183 }
183 { 184 {
184 std::unique_ptr<base::DictionaryValue> value = 185 std::unique_ptr<base::DictionaryValue> value =
185 Dictionary("data", new FundamentalValue(1.1)); 186 Dictionary("data", new FundamentalValue(1.1));
186 EXPECT_TRUE(EqualsUtf16("'data': expected binary, got number", 187 EXPECT_TRUE(EqualsUtf16("'data': expected binary, got double",
187 GetPopulateError<BinaryData>(*value))); 188 GetPopulateError<BinaryData>(*value)));
188 } 189 }
189 } 190 }
190 191
191 TEST(JsonSchemaCompilerErrorTest, ListExpected) { 192 TEST(JsonSchemaCompilerErrorTest, ListExpected) {
192 { 193 {
193 std::unique_ptr<base::DictionaryValue> value = 194 std::unique_ptr<base::DictionaryValue> value =
194 Dictionary("TheArray", new base::ListValue()); 195 Dictionary("TheArray", new base::ListValue());
195 EXPECT_TRUE(EqualsUtf16("", GetPopulateError<ArrayObject>(*value))); 196 EXPECT_TRUE(EqualsUtf16("", GetPopulateError<ArrayObject>(*value)));
196 } 197 }
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
325 EXPECT_TRUE(EqualsUtf16("", GetPopulateError<TestType>(*value))); 326 EXPECT_TRUE(EqualsUtf16("", GetPopulateError<TestType>(*value)));
326 } 327 }
327 { 328 {
328 std::unique_ptr<base::DictionaryValue> value = 329 std::unique_ptr<base::DictionaryValue> value =
329 Dictionary("string", new base::StringValue("yes"), "ohno", 330 Dictionary("string", new base::StringValue("yes"), "ohno",
330 new base::StringValue("many values")); 331 new base::StringValue("many values"));
331 EXPECT_TRUE(EqualsUtf16("found unexpected key 'ohno'", 332 EXPECT_TRUE(EqualsUtf16("found unexpected key 'ohno'",
332 GetPopulateError<TestType>(*value))); 333 GetPopulateError<TestType>(*value)));
333 } 334 }
334 } 335 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698