OLD | NEW |
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 (ASCIIToUTF16(expected) != actual) | 27 if (base::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<base::DictionaryValue> value = Dictionary( | 36 scoped_ptr<base::DictionaryValue> value = Dictionary( |
37 "string", new base::StringValue("bling")); | 37 "string", new base::StringValue("bling")); |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
205 EXPECT_TRUE(EqualsUtf16("", GetPopulateError<HasEnumeration>(*value))); | 205 EXPECT_TRUE(EqualsUtf16("", GetPopulateError<HasEnumeration>(*value))); |
206 } | 206 } |
207 { | 207 { |
208 scoped_ptr<base::DictionaryValue> value = Dictionary( | 208 scoped_ptr<base::DictionaryValue> value = Dictionary( |
209 "enumeration", new base::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 } |
OLD | NEW |