summaryrefslogtreecommitdiffstats
path: root/tools/json_schema_compiler
diff options
context:
space:
mode:
authorDHNishi@gmail.com <DHNishi@gmail.com@0039d316-1c4b-4281-b951-d872f2087c98>2013-08-21 03:16:58 +0000
committerDHNishi@gmail.com <DHNishi@gmail.com@0039d316-1c4b-4281-b951-d872f2087c98>2013-08-21 03:16:58 +0000
commitc7b4f8fc30296a463d4db9c869604ab30c81404e (patch)
treea38582f9ee281033fb916938945e545246f9c3f0 /tools/json_schema_compiler
parente7a6b8a938bab3d6b84ae49df65f486587d001ea (diff)
downloadchromium_src-c7b4f8fc30296a463d4db9c869604ab30c81404e.zip
chromium_src-c7b4f8fc30296a463d4db9c869604ab30c81404e.tar.gz
chromium_src-c7b4f8fc30296a463d4db9c869604ab30c81404e.tar.bz2
Use base::string16 instead of std::string for errors in JSON Schema
Compiler error generation. BUG=71980,234834 Review URL: https://chromiumcodereview.appspot.com/22900009 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@218614 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'tools/json_schema_compiler')
-rw-r--r--tools/json_schema_compiler/cc_generator.py5
-rw-r--r--tools/json_schema_compiler/h_generator.py2
-rw-r--r--tools/json_schema_compiler/test/error_generation_unittest.cc83
3 files changed, 51 insertions, 39 deletions
diff --git a/tools/json_schema_compiler/cc_generator.py b/tools/json_schema_compiler/cc_generator.py
index d7d565e..45f4d9d 100644
--- a/tools/json_schema_compiler/cc_generator.py
+++ b/tools/json_schema_compiler/cc_generator.py
@@ -45,6 +45,7 @@ class _Generator(object):
.Append(self._util_cc_helper.GetIncludePath())
.Append('#include "base/logging.h"')
.Append('#include "base/strings/string_number_conversions.h"')
+ .Append('#include "base/strings/utf_string_conversions.h"')
.Append('#include "%s/%s.h"' %
(self._namespace.source_file_dir, self._namespace.unix_name))
.Cblock(self._type_helper.GenerateIncludes(include_soft=True))
@@ -925,14 +926,14 @@ class _Generator(object):
if not self._generate_error_messages:
return c
(c.Append('if (error)')
- .Append(' *error = ' + body + ';'))
+ .Append(' *error = UTF8ToUTF16(' + body + ');'))
return c
def _GenerateParams(self, params):
"""Builds the parameter list for a function, given an array of parameters.
"""
if self._generate_error_messages:
- params = list(params) + ['std::string* error']
+ params = list(params) + ['base::string16* error']
return ', '.join(str(p) for p in params)
def _GenerateArgs(self, args):
diff --git a/tools/json_schema_compiler/h_generator.py b/tools/json_schema_compiler/h_generator.py
index 9a348fe..77356b2 100644
--- a/tools/json_schema_compiler/h_generator.py
+++ b/tools/json_schema_compiler/h_generator.py
@@ -393,5 +393,5 @@ class _Generator(object):
"""Builds the parameter list for a function, given an array of parameters.
"""
if self._generate_error_messages:
- params += ('std::string* error = NULL',)
+ params += ('base::string16* error = NULL',)
return ', '.join(str(p) for p in params)
diff --git a/tools/json_schema_compiler/test/error_generation_unittest.cc b/tools/json_schema_compiler/test/error_generation_unittest.cc
index 3d56595..baf7b51 100644
--- a/tools/json_schema_compiler/test/error_generation_unittest.cc
+++ b/tools/json_schema_compiler/test/error_generation_unittest.cc
@@ -5,6 +5,7 @@
#include "tools/json_schema_compiler/test/error_generation.h"
#include "base/json/json_writer.h"
+#include "base/strings/utf_string_conversions.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "tools/json_schema_compiler/test/test_util.h"
@@ -14,37 +15,45 @@ using json_schema_compiler::test_util::Dictionary;
using json_schema_compiler::test_util::List;
template <typename T>
-std::string GetPopulateError(const base::Value& value) {
- std::string error;
+base::string16 GetPopulateError(const base::Value& value) {
+ base::string16 error;
T test_type;
T::Populate(value, &test_type, &error);
return error;
}
+testing::AssertionResult EqualsUtf16(const std::string& expected,
+ const base::string16& actual) {
+ if (ASCIIToUTF16(expected) != actual)
+ return testing::AssertionFailure() << expected << " != " << actual;
+ return testing::AssertionSuccess();
+}
+
// GenerateTypePopulate errors
TEST(JsonSchemaCompilerErrorTest, RequiredPropertyPopulate) {
{
scoped_ptr<DictionaryValue> value = Dictionary(
"string", new StringValue("bling"));
- EXPECT_EQ("", GetPopulateError<TestType>(*value));
+ EXPECT_TRUE(EqualsUtf16("", GetPopulateError<TestType>(*value)));
}
{
scoped_ptr<base::BinaryValue> value(new base::BinaryValue());
- EXPECT_EQ("expected dictionary, got binary",
- GetPopulateError<TestType>(*value));
+ EXPECT_TRUE(EqualsUtf16("expected dictionary, got binary",
+ GetPopulateError<TestType>(*value)));
}
}
TEST(JsonSchemaCompilerErrorTest, UnexpectedTypePopulation) {
{
scoped_ptr<base::ListValue> value(new base::ListValue());
- EXPECT_EQ("", GetPopulateError<ChoiceType::Integers>(*value));
+ EXPECT_TRUE(EqualsUtf16("",
+ GetPopulateError<ChoiceType::Integers>(*value)));
}
{
scoped_ptr<base::BinaryValue> value(new base::BinaryValue());
- EXPECT_EQ("expected integers or integer, got binary",
- GetPopulateError<ChoiceType::Integers>(*value));
+ EXPECT_TRUE(EqualsUtf16("expected integers or integer, got binary",
+ GetPopulateError<ChoiceType::Integers>(*value)));
}
}
@@ -54,12 +63,12 @@ TEST(JsonSchemaCompilerErrorTest, TypeIsRequired) {
{
scoped_ptr<DictionaryValue> value = Dictionary(
"integers", new FundamentalValue(5));
- EXPECT_EQ("", GetPopulateError<ChoiceType>(*value));
+ EXPECT_TRUE(EqualsUtf16("", GetPopulateError<ChoiceType>(*value)));
}
{
scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue());
- EXPECT_EQ("'integers' is required",
- GetPopulateError<ChoiceType>(*value));
+ EXPECT_TRUE(EqualsUtf16("'integers' is required",
+ GetPopulateError<ChoiceType>(*value)));
}
}
@@ -75,9 +84,9 @@ TEST(JsonSchemaCompilerErrorTest, TooManyParameters) {
scoped_ptr<base::ListValue> params_value = List(
new FundamentalValue(5),
new FundamentalValue(5));
- std::string error;
+ base::string16 error;
EXPECT_FALSE(TestFunction::Params::Create(*params_value, &error));
- EXPECT_EQ("expected 1 arguments, got 2", error);
+ EXPECT_TRUE(EqualsUtf16("expected 1 arguments, got 2", error));
}
}
@@ -92,9 +101,9 @@ TEST(JsonSchemaCompilerErrorTest, ParamIsRequired) {
{
scoped_ptr<base::ListValue> params_value = List(
Value::CreateNullValue());
- std::string error;
+ base::string16 error;
EXPECT_FALSE(TestFunction::Params::Create(*params_value, &error));
- EXPECT_EQ("'num' is required", error);
+ EXPECT_TRUE(EqualsUtf16("'num' is required", error));
}
}
@@ -104,13 +113,13 @@ TEST(JsonSchemaCompilerErrorTest, WrongPropertyValueType) {
{
scoped_ptr<DictionaryValue> value = Dictionary(
"string", new StringValue("yes"));
- EXPECT_EQ("", GetPopulateError<TestType>(*value));
+ EXPECT_TRUE(EqualsUtf16("", GetPopulateError<TestType>(*value)));
}
{
scoped_ptr<DictionaryValue> value = Dictionary(
"string", new FundamentalValue(1.1));
- EXPECT_EQ("'string': expected string, got number",
- GetPopulateError<TestType>(*value));
+ EXPECT_TRUE(EqualsUtf16("'string': expected string, got number",
+ GetPopulateError<TestType>(*value)));
}
}
@@ -123,22 +132,23 @@ TEST(JsonSchemaCompilerErrorTest, WrongParameterCreationType) {
{
scoped_ptr<base::ListValue> params_value = List(
new FundamentalValue(5));
- std::string error;
+ base::string16 error;
EXPECT_FALSE(TestTypeInObject::Params::Create(*params_value, &error));
- EXPECT_EQ("'paramObject': expected dictionary, got integer", error);
+ EXPECT_TRUE(EqualsUtf16("'paramObject': expected dictionary, got integer",
+ error));
}
}
TEST(JsonSchemaCompilerErrorTest, WrongTypeValueType) {
{
scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue());
- EXPECT_EQ("", GetPopulateError<ObjectType>(*value));
+ EXPECT_TRUE(EqualsUtf16("", GetPopulateError<ObjectType>(*value)));
}
{
scoped_ptr<DictionaryValue> value = Dictionary(
"otherType", new FundamentalValue(1.1));
- EXPECT_EQ("'otherType': expected dictionary, got number",
- GetPopulateError<ObjectType>(*value));
+ EXPECT_TRUE(EqualsUtf16("'otherType': expected dictionary, got number",
+ GetPopulateError<ObjectType>(*value)));
}
}
@@ -146,14 +156,15 @@ TEST(JsonSchemaCompilerErrorTest, UnableToPopulateArray) {
{
scoped_ptr<base::ListValue> params_value = List(
new FundamentalValue(5));
- EXPECT_EQ("", GetPopulateError<ChoiceType::Integers>(*params_value));
+ EXPECT_TRUE(EqualsUtf16("",
+ GetPopulateError<ChoiceType::Integers>(*params_value)));
}
{
scoped_ptr<base::ListValue> params_value = List(
new FundamentalValue(5),
new FundamentalValue(false));
- EXPECT_EQ("unable to populate array 'integers'",
- GetPopulateError<ChoiceType::Integers>(*params_value));
+ EXPECT_TRUE(EqualsUtf16("unable to populate array 'integers'",
+ GetPopulateError<ChoiceType::Integers>(*params_value)));
}
}
@@ -161,13 +172,13 @@ TEST(JsonSchemaCompilerErrorTest, BinaryTypeExpected) {
{
scoped_ptr<DictionaryValue> value = Dictionary(
"data", new base::BinaryValue());
- EXPECT_EQ("", GetPopulateError<BinaryData>(*value));
+ EXPECT_TRUE(EqualsUtf16("", GetPopulateError<BinaryData>(*value)));
}
{
scoped_ptr<DictionaryValue> value = Dictionary(
"data", new FundamentalValue(1.1));
- EXPECT_EQ("'data': expected binary, got number",
- GetPopulateError<BinaryData>(*value));
+ EXPECT_TRUE(EqualsUtf16("'data': expected binary, got number",
+ GetPopulateError<BinaryData>(*value)));
}
}
@@ -175,13 +186,13 @@ TEST(JsonSchemaCompilerErrorTest, ListExpected) {
{
scoped_ptr<DictionaryValue> value = Dictionary(
"TheArray", new base::ListValue());
- EXPECT_EQ("", GetPopulateError<ArrayObject>(*value));
+ EXPECT_TRUE(EqualsUtf16("", GetPopulateError<ArrayObject>(*value)));
}
{
scoped_ptr<DictionaryValue> value = Dictionary(
"TheArray", new FundamentalValue(5));
- EXPECT_EQ("'TheArray': expected list, got integer",
- GetPopulateError<ArrayObject>(*value));
+ EXPECT_TRUE(EqualsUtf16("'TheArray': expected list, got integer",
+ GetPopulateError<ArrayObject>(*value)));
}
}
@@ -191,13 +202,13 @@ TEST(JsonSchemaCompilerErrorTest, BadEnumValue) {
{
scoped_ptr<DictionaryValue> value = Dictionary(
"enumeration", new StringValue("one"));
- EXPECT_EQ("", GetPopulateError<HasEnumeration>(*value));
+ EXPECT_TRUE(EqualsUtf16("", GetPopulateError<HasEnumeration>(*value)));
}
{
scoped_ptr<DictionaryValue> value = Dictionary(
"enumeration", new StringValue("bad sauce"));
- EXPECT_EQ("'enumeration': expected \"one\" or \"two\" or \"three\", "
- "got \"bad sauce\"",
- GetPopulateError<HasEnumeration>(*value));
+ EXPECT_TRUE(EqualsUtf16("'enumeration': expected \"one\" or \"two\" "
+ "or \"three\", got \"bad sauce\"",
+ GetPopulateError<HasEnumeration>(*value)));
}
}