Commit 4c1eb167 authored by Peter Kasting's avatar Peter Kasting Committed by Commit Bot

Remove using directives ("using namespace x") in tools/json_schema_compiler/.

Also replaces bare new with make_unique.

Bug: 82078
Change-Id: I2c189d65fab3cee98297f32aa1454ac0f4555453
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1881942
Commit-Queue: Peter Kasting <pkasting@chromium.org>
Auto-Submit: Peter Kasting <pkasting@chromium.org>
Reviewed-by: default avatarDevlin <rdevlin.cronin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#710664}
parent 3c81611f
......@@ -9,44 +9,41 @@
#include "testing/gtest/include/gtest/gtest.h"
using namespace test::api::additional_properties;
namespace ap = test::api::additional_properties;
TEST(JsonSchemaCompilerAdditionalPropertiesTest,
AdditionalPropertiesTypePopulate) {
{
std::unique_ptr<base::ListValue> list_value(new base::ListValue());
auto list_value = std::make_unique<base::ListValue>();
list_value->AppendString("asdf");
list_value->AppendInteger(4);
std::unique_ptr<base::DictionaryValue> type_value(
new base::DictionaryValue());
auto type_value = std::make_unique<base::DictionaryValue>();
type_value->SetString("string", "value");
type_value->SetInteger("other", 9);
type_value->Set("another", std::move(list_value));
std::unique_ptr<AdditionalPropertiesType> type(
new AdditionalPropertiesType());
ASSERT_TRUE(AdditionalPropertiesType::Populate(*type_value, type.get()));
auto type = std::make_unique<ap::AdditionalPropertiesType>();
ASSERT_TRUE(
ap::AdditionalPropertiesType::Populate(*type_value, type.get()));
EXPECT_TRUE(type->additional_properties.Equals(type_value.get()));
}
{
std::unique_ptr<base::DictionaryValue> type_value(
new base::DictionaryValue());
auto type_value = std::make_unique<base::DictionaryValue>();
type_value->SetInteger("string", 3);
std::unique_ptr<AdditionalPropertiesType> type(
new AdditionalPropertiesType());
EXPECT_FALSE(AdditionalPropertiesType::Populate(*type_value, type.get()));
auto type = std::make_unique<ap::AdditionalPropertiesType>();
EXPECT_FALSE(
ap::AdditionalPropertiesType::Populate(*type_value, type.get()));
}
}
TEST(JsonSchemaCompilerAdditionalPropertiesTest,
AdditionalPropertiesParamsCreate) {
std::unique_ptr<base::DictionaryValue> param_object_value(
new base::DictionaryValue());
auto param_object_value = std::make_unique<base::DictionaryValue>();
param_object_value->SetString("str", "a");
param_object_value->SetInteger("num", 1);
std::unique_ptr<base::ListValue> params_value(new base::ListValue());
auto params_value = std::make_unique<base::ListValue>();
params_value->Append(param_object_value->CreateDeepCopy());
std::unique_ptr<AdditionalProperties::Params> params(
AdditionalProperties::Params::Create(*params_value));
std::unique_ptr<ap::AdditionalProperties::Params> params(
ap::AdditionalProperties::Params::Create(*params_value));
EXPECT_TRUE(params.get());
EXPECT_TRUE(params->param_object.additional_properties.Equals(
param_object_value.get()));
......@@ -54,18 +51,18 @@ TEST(JsonSchemaCompilerAdditionalPropertiesTest,
TEST(JsonSchemaCompilerAdditionalPropertiesTest,
ReturnAdditionalPropertiesResultCreate) {
ReturnAdditionalProperties::Results::ResultObject result_object;
ap::ReturnAdditionalProperties::Results::ResultObject result_object;
result_object.integer = 5;
result_object.additional_properties["key"] = "value";
base::ListValue expected;
{
std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue());
auto dict = std::make_unique<base::DictionaryValue>();
dict->SetInteger("integer", 5);
dict->SetString("key", "value");
expected.Append(std::move(dict));
}
EXPECT_EQ(expected,
*ReturnAdditionalProperties::Results::Create(result_object));
*ap::ReturnAdditionalProperties::Results::Create(result_object));
}
......@@ -5,24 +5,20 @@
#include "testing/gtest/include/gtest/gtest.h"
#include "tools/json_schema_compiler/test/any.h"
using namespace test::api::any;
TEST(JsonSchemaCompilerAnyTest, AnyTypePopulate) {
{
AnyType any_type;
std::unique_ptr<base::DictionaryValue> any_type_value(
new base::DictionaryValue());
test::api::any::AnyType any_type;
auto any_type_value = std::make_unique<base::DictionaryValue>();
any_type_value->SetString("any", "value");
EXPECT_TRUE(AnyType::Populate(*any_type_value, &any_type));
EXPECT_TRUE(test::api::any::AnyType::Populate(*any_type_value, &any_type));
std::unique_ptr<base::Value> any_type_to_value(any_type.ToValue());
EXPECT_TRUE(any_type_value->Equals(any_type_to_value.get()));
}
{
AnyType any_type;
std::unique_ptr<base::DictionaryValue> any_type_value(
new base::DictionaryValue());
test::api::any::AnyType any_type;
auto any_type_value = std::make_unique<base::DictionaryValue>();
any_type_value->SetInteger("any", 5);
EXPECT_TRUE(AnyType::Populate(*any_type_value, &any_type));
EXPECT_TRUE(test::api::any::AnyType::Populate(*any_type_value, &any_type));
std::unique_ptr<base::Value> any_type_to_value(any_type.ToValue());
EXPECT_TRUE(any_type_value->Equals(any_type_to_value.get()));
}
......@@ -30,28 +26,28 @@ TEST(JsonSchemaCompilerAnyTest, AnyTypePopulate) {
TEST(JsonSchemaCompilerAnyTest, OptionalAnyParamsCreate) {
{
std::unique_ptr<base::ListValue> params_value(new base::ListValue());
std::unique_ptr<OptionalAny::Params> params(
OptionalAny::Params::Create(*params_value));
auto params_value = std::make_unique<base::ListValue>();
std::unique_ptr<test::api::any::OptionalAny::Params> params(
test::api::any::OptionalAny::Params::Create(*params_value));
EXPECT_TRUE(params.get());
EXPECT_FALSE(params->any_name.get());
}
{
std::unique_ptr<base::ListValue> params_value(new base::ListValue());
std::unique_ptr<base::Value> param(new base::Value("asdf"));
auto params_value = std::make_unique<base::ListValue>();
auto param = std::make_unique<base::Value>("asdf");
params_value->Append(param->CreateDeepCopy());
std::unique_ptr<OptionalAny::Params> params(
OptionalAny::Params::Create(*params_value));
std::unique_ptr<test::api::any::OptionalAny::Params> params(
test::api::any::OptionalAny::Params::Create(*params_value));
ASSERT_TRUE(params);
ASSERT_TRUE(params->any_name);
EXPECT_TRUE(params->any_name->Equals(param.get()));
}
{
std::unique_ptr<base::ListValue> params_value(new base::ListValue());
std::unique_ptr<base::Value> param(new base::Value(true));
auto params_value = std::make_unique<base::ListValue>();
auto param = std::make_unique<base::Value>(true);
params_value->Append(param->CreateDeepCopy());
std::unique_ptr<OptionalAny::Params> params(
OptionalAny::Params::Create(*params_value));
std::unique_ptr<test::api::any::OptionalAny::Params> params(
test::api::any::OptionalAny::Params::Create(*params_value));
ASSERT_TRUE(params);
ASSERT_TRUE(params->any_name);
EXPECT_TRUE(params->any_name->Equals(param.get()));
......
......@@ -14,7 +14,7 @@
#include "testing/gtest/include/gtest/gtest.h"
#include "tools/json_schema_compiler/test/enums.h"
using namespace test::api::arrays;
namespace arrays = test::api::arrays;
namespace {
......@@ -54,8 +54,9 @@ TEST(JsonSchemaCompilerArrayTest, BasicArrayType) {
{
std::unique_ptr<base::DictionaryValue> value =
CreateBasicArrayTypeDictionary();
std::unique_ptr<BasicArrayType> basic_array_type(new BasicArrayType());
ASSERT_TRUE(BasicArrayType::Populate(*value, basic_array_type.get()));
auto basic_array_type = std::make_unique<arrays::BasicArrayType>();
ASSERT_TRUE(
arrays::BasicArrayType::Populate(*value, basic_array_type.get()));
EXPECT_TRUE(value->Equals(basic_array_type->ToValue().get()));
}
}
......@@ -69,14 +70,16 @@ TEST(JsonSchemaCompilerArrayTest, EnumArrayReference) {
base::DictionaryValue value;
value.Set("types", std::move(types));
EnumArrayReference enum_array_reference;
arrays::EnumArrayReference enum_array_reference;
// Test Populate.
ASSERT_TRUE(EnumArrayReference::Populate(value, &enum_array_reference));
ASSERT_TRUE(
arrays::EnumArrayReference::Populate(value, &enum_array_reference));
Enumeration expected_types[] = {ENUMERATION_ONE, ENUMERATION_TWO,
ENUMERATION_THREE};
EXPECT_EQ(std::vector<Enumeration>(
arrays::Enumeration expected_types[] = {arrays::ENUMERATION_ONE,
arrays::ENUMERATION_TWO,
arrays::ENUMERATION_THREE};
EXPECT_EQ(std::vector<arrays::Enumeration>(
expected_types, expected_types + base::size(expected_types)),
enum_array_reference.types);
......@@ -101,14 +104,15 @@ TEST(JsonSchemaCompilerArrayTest, EnumArrayMixed) {
value.Set("infile_enums", std::move(infile_enums));
value.Set("external_enums", std::move(external_enums));
EnumArrayMixed enum_array_mixed;
arrays::EnumArrayMixed enum_array_mixed;
// Test Populate.
ASSERT_TRUE(EnumArrayMixed::Populate(value, &enum_array_mixed));
ASSERT_TRUE(arrays::EnumArrayMixed::Populate(value, &enum_array_mixed));
Enumeration expected_infile_types[] = {ENUMERATION_ONE, ENUMERATION_TWO,
ENUMERATION_THREE};
EXPECT_EQ(std::vector<Enumeration>(
arrays::Enumeration expected_infile_types[] = {arrays::ENUMERATION_ONE,
arrays::ENUMERATION_TWO,
arrays::ENUMERATION_THREE};
EXPECT_EQ(std::vector<arrays::Enumeration>(
expected_infile_types,
expected_infile_types + base::size(expected_infile_types)),
enum_array_mixed.infile_enums);
......@@ -128,10 +132,10 @@ TEST(JsonSchemaCompilerArrayTest, EnumArrayMixed) {
TEST(JsonSchemaCompilerArrayTest, OptionalEnumArrayType) {
{
std::vector<Enumeration> enums;
enums.push_back(ENUMERATION_ONE);
enums.push_back(ENUMERATION_TWO);
enums.push_back(ENUMERATION_THREE);
std::vector<arrays::Enumeration> enums;
enums.push_back(arrays::ENUMERATION_ONE);
enums.push_back(arrays::ENUMERATION_TWO);
enums.push_back(arrays::ENUMERATION_THREE);
auto types = std::make_unique<base::ListValue>();
for (size_t i = 0; i < enums.size(); ++i)
......@@ -140,8 +144,9 @@ TEST(JsonSchemaCompilerArrayTest, OptionalEnumArrayType) {
base::DictionaryValue value;
value.Set("types", std::move(types));
OptionalEnumArrayType enum_array_type;
ASSERT_TRUE(OptionalEnumArrayType::Populate(value, &enum_array_type));
arrays::OptionalEnumArrayType enum_array_type;
ASSERT_TRUE(
arrays::OptionalEnumArrayType::Populate(value, &enum_array_type));
EXPECT_EQ(enums, *enum_array_type.types);
}
{
......@@ -150,8 +155,9 @@ TEST(JsonSchemaCompilerArrayTest, OptionalEnumArrayType) {
enum_array->AppendString("invalid");
value.Set("types", std::move(enum_array));
OptionalEnumArrayType enum_array_type;
ASSERT_FALSE(OptionalEnumArrayType::Populate(value, &enum_array_type));
arrays::OptionalEnumArrayType enum_array_type;
ASSERT_FALSE(
arrays::OptionalEnumArrayType::Populate(value, &enum_array_type));
EXPECT_TRUE(enum_array_type.types->empty());
}
}
......@@ -164,8 +170,8 @@ TEST(JsonSchemaCompilerArrayTest, RefArrayType) {
ref_array->Append(CreateItemValue(2));
ref_array->Append(CreateItemValue(3));
value->Set("refs", std::move(ref_array));
auto ref_array_type = std::make_unique<RefArrayType>();
EXPECT_TRUE(RefArrayType::Populate(*value, ref_array_type.get()));
auto ref_array_type = std::make_unique<arrays::RefArrayType>();
EXPECT_TRUE(arrays::RefArrayType::Populate(*value, ref_array_type.get()));
ASSERT_EQ(3u, ref_array_type->refs.size());
EXPECT_EQ(1, ref_array_type->refs[0].val);
EXPECT_EQ(2, ref_array_type->refs[1].val);
......@@ -177,20 +183,20 @@ TEST(JsonSchemaCompilerArrayTest, RefArrayType) {
not_ref_array->Append(CreateItemValue(1));
not_ref_array->AppendInteger(3);
value->Set("refs", std::move(not_ref_array));
auto ref_array_type = std::make_unique<RefArrayType>();
EXPECT_FALSE(RefArrayType::Populate(*value, ref_array_type.get()));
auto ref_array_type = std::make_unique<arrays::RefArrayType>();
EXPECT_FALSE(arrays::RefArrayType::Populate(*value, ref_array_type.get()));
}
}
TEST(JsonSchemaCompilerArrayTest, IntegerArrayParamsCreate) {
std::unique_ptr<base::ListValue> params_value(new base::ListValue());
std::unique_ptr<base::ListValue> integer_array(new base::ListValue());
auto params_value = std::make_unique<base::ListValue>();
auto integer_array = std::make_unique<base::ListValue>();
integer_array->AppendInteger(2);
integer_array->AppendInteger(4);
integer_array->AppendInteger(8);
params_value->Append(std::move(integer_array));
std::unique_ptr<IntegerArray::Params> params(
IntegerArray::Params::Create(*params_value));
std::unique_ptr<arrays::IntegerArray::Params> params(
arrays::IntegerArray::Params::Create(*params_value));
EXPECT_TRUE(params.get());
ASSERT_EQ(3u, params->nums.size());
EXPECT_EQ(2, params->nums[0]);
......@@ -199,14 +205,14 @@ TEST(JsonSchemaCompilerArrayTest, IntegerArrayParamsCreate) {
}
TEST(JsonSchemaCompilerArrayTest, AnyArrayParamsCreate) {
std::unique_ptr<base::ListValue> params_value(new base::ListValue());
std::unique_ptr<base::ListValue> any_array(new base::ListValue());
auto params_value = std::make_unique<base::ListValue>();
auto any_array = std::make_unique<base::ListValue>();
any_array->AppendInteger(1);
any_array->AppendString("test");
any_array->Append(CreateItemValue(2));
params_value->Append(std::move(any_array));
std::unique_ptr<AnyArray::Params> params(
AnyArray::Params::Create(*params_value));
std::unique_ptr<arrays::AnyArray::Params> params(
arrays::AnyArray::Params::Create(*params_value));
EXPECT_TRUE(params.get());
ASSERT_EQ(3u, params->anys.size());
int int_temp = 0;
......@@ -215,13 +221,13 @@ TEST(JsonSchemaCompilerArrayTest, AnyArrayParamsCreate) {
}
TEST(JsonSchemaCompilerArrayTest, ObjectArrayParamsCreate) {
std::unique_ptr<base::ListValue> params_value(new base::ListValue());
std::unique_ptr<base::ListValue> item_array(new base::ListValue());
auto params_value = std::make_unique<base::ListValue>();
auto item_array = std::make_unique<base::ListValue>();
item_array->Append(CreateItemValue(1));
item_array->Append(CreateItemValue(2));
params_value->Append(std::move(item_array));
std::unique_ptr<ObjectArray::Params> params(
ObjectArray::Params::Create(*params_value));
std::unique_ptr<arrays::ObjectArray::Params> params(
arrays::ObjectArray::Params::Create(*params_value));
EXPECT_TRUE(params.get());
ASSERT_EQ(2u, params->objects.size());
EXPECT_EQ(1, params->objects[0].additional_properties["val"]);
......@@ -229,13 +235,13 @@ TEST(JsonSchemaCompilerArrayTest, ObjectArrayParamsCreate) {
}
TEST(JsonSchemaCompilerArrayTest, RefArrayParamsCreate) {
std::unique_ptr<base::ListValue> params_value(new base::ListValue());
std::unique_ptr<base::ListValue> item_array(new base::ListValue());
auto params_value = std::make_unique<base::ListValue>();
auto item_array = std::make_unique<base::ListValue>();
item_array->Append(CreateItemValue(1));
item_array->Append(CreateItemValue(2));
params_value->Append(std::move(item_array));
std::unique_ptr<RefArray::Params> params(
RefArray::Params::Create(*params_value));
std::unique_ptr<arrays::RefArray::Params> params(
arrays::RefArray::Params::Create(*params_value));
EXPECT_TRUE(params.get());
ASSERT_EQ(2u, params->refs.size());
EXPECT_EQ(1, params->refs[0].val);
......@@ -247,10 +253,10 @@ TEST(JsonSchemaCompilerArrayTest, ReturnIntegerArrayResultCreate) {
integers.push_back(1);
integers.push_back(2);
std::unique_ptr<base::ListValue> results =
ReturnIntegerArray::Results::Create(integers);
arrays::ReturnIntegerArray::Results::Create(integers);
base::ListValue expected;
std::unique_ptr<base::ListValue> expected_argument(new base::ListValue());
auto expected_argument = std::make_unique<base::ListValue>();
expected_argument->AppendInteger(1);
expected_argument->AppendInteger(2);
expected.Append(std::move(expected_argument));
......@@ -258,20 +264,20 @@ TEST(JsonSchemaCompilerArrayTest, ReturnIntegerArrayResultCreate) {
}
TEST(JsonSchemaCompilerArrayTest, ReturnRefArrayResultCreate) {
std::vector<Item> items;
items.push_back(Item());
items.push_back(Item());
std::vector<arrays::Item> items;
items.push_back(arrays::Item());
items.push_back(arrays::Item());
items[0].val = 1;
items[1].val = 2;
std::unique_ptr<base::ListValue> results =
ReturnRefArray::Results::Create(items);
arrays::ReturnRefArray::Results::Create(items);
base::ListValue expected;
std::unique_ptr<base::ListValue> expected_argument(new base::ListValue());
std::unique_ptr<base::DictionaryValue> first(new base::DictionaryValue());
auto expected_argument = std::make_unique<base::ListValue>();
auto first = std::make_unique<base::DictionaryValue>();
first->SetInteger("val", 1);
expected_argument->Append(std::move(first));
std::unique_ptr<base::DictionaryValue> second(new base::DictionaryValue());
auto second = std::make_unique<base::DictionaryValue>();
second->SetInteger("val", 2);
expected_argument->Append(std::move(second));
expected.Append(std::move(expected_argument));
......
......@@ -9,16 +9,13 @@
#include "testing/gtest/include/gtest/gtest.h"
using namespace test::api::callbacks;
TEST(JsonSchemaCompilerCallbacksTest, ReturnsObjectResultCreate) {
ReturnsObject::Results::SomeObject some_object;
some_object.state = ENUMERATION_FOO;
test::api::callbacks::ReturnsObject::Results::SomeObject some_object;
some_object.state = test::api::callbacks::ENUMERATION_FOO;
std::unique_ptr<base::ListValue> results =
ReturnsObject::Results::Create(some_object);
test::api::callbacks::ReturnsObject::Results::Create(some_object);
std::unique_ptr<base::DictionaryValue> expected_dict(
new base::DictionaryValue());
auto expected_dict = std::make_unique<base::DictionaryValue>();
expected_dict->SetString("state", "foo");
base::ListValue expected;
expected.Append(std::move(expected_dict));
......@@ -26,13 +23,12 @@ TEST(JsonSchemaCompilerCallbacksTest, ReturnsObjectResultCreate) {
}
TEST(JsonSchemaCompilerCallbacksTest, ReturnsMultipleResultCreate) {
ReturnsMultiple::Results::SomeObject some_object;
some_object.state = ENUMERATION_FOO;
test::api::callbacks::ReturnsMultiple::Results::SomeObject some_object;
some_object.state = test::api::callbacks::ENUMERATION_FOO;
std::unique_ptr<base::ListValue> results =
ReturnsMultiple::Results::Create(5, some_object);
test::api::callbacks::ReturnsMultiple::Results::Create(5, some_object);
std::unique_ptr<base::DictionaryValue> expected_dict(
new base::DictionaryValue());
auto expected_dict = std::make_unique<base::DictionaryValue>();
expected_dict->SetString("state", "foo");
base::ListValue expected;
expected.AppendInteger(5);
......
......@@ -15,7 +15,9 @@
namespace {
using namespace test::api::choices;
namespace choices = test::api::choices;
namespace TakesIntegers = choices::TakesIntegers;
using choices::NestedChoice;
using json_schema_compiler::test_util::Dictionary;
using json_schema_compiler::test_util::List;
using json_schema_compiler::test_util::ReadJson;
......@@ -47,8 +49,8 @@ TEST(JsonSchemaCompilerChoicesTest, TakesIntegersParamsCreate) {
TEST(JsonSchemaCompilerChoicesTest, ObjectWithChoicesParamsCreate) {
{
std::unique_ptr<ObjectWithChoices::Params> params(
ObjectWithChoices::Params::Create(*List(
std::unique_ptr<choices::ObjectWithChoices::Params> params(
choices::ObjectWithChoices::Params::Create(*List(
Dictionary("strings", std::make_unique<base::Value>("asdf")))));
ASSERT_TRUE(params);
EXPECT_FALSE(params->string_info.strings.as_strings);
......@@ -56,8 +58,8 @@ TEST(JsonSchemaCompilerChoicesTest, ObjectWithChoicesParamsCreate) {
EXPECT_FALSE(params->string_info.integers);
}
{
std::unique_ptr<ObjectWithChoices::Params> params(
ObjectWithChoices::Params::Create(
std::unique_ptr<choices::ObjectWithChoices::Params> params(
choices::ObjectWithChoices::Params::Create(
*List(Dictionary("strings", std::make_unique<base::Value>("asdf"),
"integers", std::make_unique<base::Value>(6)))));
ASSERT_TRUE(params);
......@@ -74,34 +76,31 @@ TEST(JsonSchemaCompilerChoicesTest, ObjectWithChoicesParamsCreate) {
TEST(JsonSchemaCompilerChoicesTest, ObjectWithChoicesParamsCreateFail) {
{
std::unique_ptr<base::DictionaryValue> object_param(
new base::DictionaryValue());
auto object_param = std::make_unique<base::DictionaryValue>();
object_param->SetKey("strings", base::Value(5));
std::unique_ptr<base::ListValue> params_value(new base::ListValue());
params_value->Append(std::move(object_param));
std::unique_ptr<ObjectWithChoices::Params> params(
ObjectWithChoices::Params::Create(*params_value));
std::unique_ptr<choices::ObjectWithChoices::Params> params(
choices::ObjectWithChoices::Params::Create(*params_value));
EXPECT_FALSE(params.get());
}
{
std::unique_ptr<base::DictionaryValue> object_param(
new base::DictionaryValue());
auto object_param = std::make_unique<base::DictionaryValue>();
object_param->SetKey("strings", base::Value("asdf"));
object_param->SetKey("integers", base::Value("asdf"));
std::unique_ptr<base::ListValue> params_value(new base::ListValue());
params_value->Append(std::move(object_param));
std::unique_ptr<ObjectWithChoices::Params> params(
ObjectWithChoices::Params::Create(*params_value));
std::unique_ptr<choices::ObjectWithChoices::Params> params(
choices::ObjectWithChoices::Params::Create(*params_value));
EXPECT_FALSE(params.get());
}
{
std::unique_ptr<base::DictionaryValue> object_param(
new base::DictionaryValue());
auto object_param = std::make_unique<base::DictionaryValue>();
object_param->SetKey("integers", base::Value(6));
std::unique_ptr<base::ListValue> params_value(new base::ListValue());
params_value->Append(std::move(object_param));
std::unique_ptr<ObjectWithChoices::Params> params(
ObjectWithChoices::Params::Create(*params_value));
std::unique_ptr<choices::ObjectWithChoices::Params> params(
choices::ObjectWithChoices::Params::Create(*params_value));
EXPECT_FALSE(params.get());
}
}
......@@ -119,8 +118,8 @@ TEST(JsonSchemaCompilerChoicesTest, PopulateChoiceType) {
value.SetInteger("integers", 4);
value.Set("strings", std::move(strings_value));
ChoiceType out;
ASSERT_TRUE(ChoiceType::Populate(value, &out));
choices::ChoiceType out;
ASSERT_TRUE(choices::ChoiceType::Populate(value, &out));
ASSERT_TRUE(out.integers.as_integer.get());
EXPECT_FALSE(out.integers.as_integers.get());
EXPECT_EQ(4, *out.integers.as_integer);
......@@ -140,16 +139,16 @@ TEST(JsonSchemaCompilerChoicesTest, ChoiceTypeToValue) {
value.SetInteger("integers", 5);
value.Set("strings", std::move(strings_value));
ChoiceType out;
ASSERT_TRUE(ChoiceType::Populate(value, &out));
choices::ChoiceType out;
ASSERT_TRUE(choices::ChoiceType::Populate(value, &out));
EXPECT_TRUE(value.Equals(out.ToValue().get()));
}
TEST(JsonSchemaCompilerChoicesTest, ReturnChoices) {
{
ReturnChoices::Results::Result results;
results.as_integers.reset(new std::vector<int>(Vector(1, 2)));
choices::ReturnChoices::Results::Result results;
results.as_integers = std::make_unique<std::vector<int>>(Vector(1, 2));
std::unique_ptr<base::Value> results_value = results.ToValue();
ASSERT_TRUE(results_value);
......@@ -161,8 +160,8 @@ TEST(JsonSchemaCompilerChoicesTest, ReturnChoices) {
EXPECT_TRUE(expected.Equals(results_value.get()));
}
{
ReturnChoices::Results::Result results;
results.as_integer.reset(new int(5));
choices::ReturnChoices::Results::Result results;
results.as_integer = std::make_unique<int>(5);
std::unique_ptr<base::Value> results_value = results.ToValue();
ASSERT_TRUE(results_value);
......@@ -253,7 +252,7 @@ TEST(JsonSchemaCompilerChoicesTest, NestedChoices) {
ASSERT_TRUE(obj->as_choice2->as_choice_type);
EXPECT_FALSE(obj->as_choice2->as_choice_types);
{
ChoiceType* choice_type = obj->as_choice2->as_choice_type.get();
choices::ChoiceType* choice_type = obj->as_choice2->as_choice_type.get();
ASSERT_TRUE(choice_type->integers.as_integers);
EXPECT_FALSE(choice_type->integers.as_integer);
EXPECT_EQ(Vector(1, 2), *choice_type->integers.as_integers);
......@@ -282,12 +281,8 @@ TEST(JsonSchemaCompilerChoicesTest, NestedChoices) {
EXPECT_FALSE(obj->as_choice2->as_double);
EXPECT_FALSE(obj->as_choice2->as_choice_type);
ASSERT_TRUE(obj->as_choice2->as_choice_types);
{
std::vector<ChoiceType>* choice_types =
obj->as_choice2->as_choice_types.get();
// Bleh too much effort to test everything.
ASSERT_EQ(2u, choice_types->size());
}
ASSERT_EQ(2u, obj->as_choice2->as_choice_types->size());
EXPECT_EQ(*value, *obj->ToValue());
}
......
......@@ -11,7 +11,8 @@
#include "testing/gtest/include/gtest/gtest.h"
#include "tools/json_schema_compiler/test/simple_api.h"
using namespace test::api;
namespace crossref = test::api::crossref;
namespace simple_api = test::api::simple_api;
namespace {
......@@ -51,7 +52,7 @@ TEST(JsonSchemaCompilerCrossrefTest, CrossrefTypePopulateAndToValue) {
}
TEST(JsonSchemaCompilerCrossrefTest, TestTypeOptionalParamCreate) {
std::unique_ptr<base::ListValue> params_value(new base::ListValue());
auto params_value = std::make_unique<base::ListValue>();
params_value->Append(CreateTestTypeValue());
std::unique_ptr<crossref::TestTypeOptionalParam::Params> params(
crossref::TestTypeOptionalParam::Params::Create(*params_value));
......@@ -62,7 +63,7 @@ TEST(JsonSchemaCompilerCrossrefTest, TestTypeOptionalParamCreate) {
}
TEST(JsonSchemaCompilerCrossrefTest, TestTypeOptionalParamFail) {
std::unique_ptr<base::ListValue> params_value(new base::ListValue());
auto params_value = std::make_unique<base::ListValue>();
std::unique_ptr<base::DictionaryValue> test_type_value =
CreateTestTypeValue();
test_type_value->RemoveWithoutPathExpansion("number", NULL);
......@@ -74,7 +75,7 @@ TEST(JsonSchemaCompilerCrossrefTest, TestTypeOptionalParamFail) {
TEST(JsonSchemaCompilerCrossrefTest, GetTestType) {
std::unique_ptr<base::DictionaryValue> value = CreateTestTypeValue();
std::unique_ptr<simple_api::TestType> test_type(new simple_api::TestType());
auto test_type = std::make_unique<simple_api::TestType>();
EXPECT_TRUE(simple_api::TestType::Populate(*value, test_type.get()));
std::unique_ptr<base::ListValue> results =
......
......@@ -8,23 +8,23 @@
#include "testing/gtest/include/gtest/gtest.h"
#include "tools/json_schema_compiler/test/test_util.h"
using namespace test::api::enums;
namespace enums = test::api::enums;
using json_schema_compiler::test_util::List;
TEST(JsonSchemaCompilerEnumsTest, EnumTypePopulate) {
{
EnumType enum_type;
enums::EnumType enum_type;
base::DictionaryValue value;
value.SetString("type", "one");
EXPECT_TRUE(EnumType::Populate(value, &enum_type));
EXPECT_EQ(ENUMERATION_ONE, enum_type.type);
EXPECT_TRUE(enums::EnumType::Populate(value, &enum_type));
EXPECT_EQ(enums::ENUMERATION_ONE, enum_type.type);
EXPECT_TRUE(value.Equals(enum_type.ToValue().get()));
}
{
EnumType enum_type;
enums::EnumType enum_type;
base::DictionaryValue value;
value.SetString("type", "invalid");
EXPECT_FALSE(EnumType::Populate(value, &enum_type));
EXPECT_FALSE(enums::EnumType::Populate(value, &enum_type));
}
}
......@@ -33,39 +33,40 @@ TEST(JsonSchemaCompilerEnumsTest, EnumsAsTypes) {
base::ListValue args;
args.AppendString("one");
std::unique_ptr<TakesEnumAsType::Params> params(
TakesEnumAsType::Params::Create(args));
std::unique_ptr<enums::TakesEnumAsType::Params> params(
enums::TakesEnumAsType::Params::Create(args));
ASSERT_TRUE(params.get());
EXPECT_EQ(ENUMERATION_ONE, params->enumeration);
EXPECT_EQ(enums::ENUMERATION_ONE, params->enumeration);
EXPECT_TRUE(args.Equals(ReturnsEnumAsType::Results::Create(
ENUMERATION_ONE).get()));
EXPECT_TRUE(args.Equals(
enums::ReturnsEnumAsType::Results::Create(enums::ENUMERATION_ONE)
.get()));
}
{
HasEnumeration enumeration;
EXPECT_EQ(ENUMERATION_NONE, enumeration.enumeration);
EXPECT_EQ(ENUMERATION_NONE, enumeration.optional_enumeration);
enums::HasEnumeration enumeration;
EXPECT_EQ(enums::ENUMERATION_NONE, enumeration.enumeration);
EXPECT_EQ(enums::ENUMERATION_NONE, enumeration.optional_enumeration);
}
{
HasEnumeration enumeration;
enums::HasEnumeration enumeration;
base::DictionaryValue value;
ASSERT_FALSE(HasEnumeration::Populate(value, &enumeration));
ASSERT_FALSE(enums::HasEnumeration::Populate(value, &enumeration));
value.SetString("enumeration", "one");
ASSERT_TRUE(HasEnumeration::Populate(value, &enumeration));
ASSERT_TRUE(enums::HasEnumeration::Populate(value, &enumeration));
EXPECT_TRUE(value.Equals(enumeration.ToValue().get()));
value.SetString("optional_enumeration", "two");
ASSERT_TRUE(HasEnumeration::Populate(value, &enumeration));
ASSERT_TRUE(enums::HasEnumeration::Populate(value, &enumeration));
EXPECT_TRUE(value.Equals(enumeration.ToValue().get()));
}
{
ReferenceEnum enumeration;
enums::ReferenceEnum enumeration;
base::DictionaryValue value;
ASSERT_FALSE(ReferenceEnum::Populate(value, &enumeration));
ASSERT_FALSE(enums::ReferenceEnum::Populate(value, &enumeration));
value.SetString("reference_enum", "one");
ASSERT_TRUE(ReferenceEnum::Populate(value, &enumeration));
ASSERT_TRUE(enums::ReferenceEnum::Populate(value, &enumeration));
EXPECT_TRUE(value.Equals(enumeration.ToValue().get()));
}
}
......@@ -75,33 +76,33 @@ TEST(JsonSchemaCompilerEnumsTest, EnumsArrayAsType) {
base::ListValue params_value;
params_value.Append(List(std::make_unique<base::Value>("one"),
std::make_unique<base::Value>("two")));
std::unique_ptr<TakesEnumArrayAsType::Params> params(
TakesEnumArrayAsType::Params::Create(params_value));
std::unique_ptr<enums::TakesEnumArrayAsType::Params> params(
enums::TakesEnumArrayAsType::Params::Create(params_value));
ASSERT_TRUE(params);
EXPECT_EQ(2U, params->values.size());
EXPECT_EQ(ENUMERATION_ONE, params->values[0]);
EXPECT_EQ(ENUMERATION_TWO, params->values[1]);
EXPECT_EQ(enums::ENUMERATION_ONE, params->values[0]);
EXPECT_EQ(enums::ENUMERATION_TWO, params->values[1]);
}
{
base::ListValue params_value;
params_value.Append(List(std::make_unique<base::Value>("invalid")));
std::unique_ptr<TakesEnumArrayAsType::Params> params(
TakesEnumArrayAsType::Params::Create(params_value));
std::unique_ptr<enums::TakesEnumArrayAsType::Params> params(
enums::TakesEnumArrayAsType::Params::Create(params_value));
EXPECT_FALSE(params);
}
}
TEST(JsonSchemaCompilerEnumsTest, ReturnsEnumCreate) {
{
Enumeration state = ENUMERATION_ONE;
std::unique_ptr<base::Value> result(new base::Value(ToString(state)));
std::unique_ptr<base::Value> expected(new base::Value("one"));
enums::Enumeration state = enums::ENUMERATION_ONE;
auto result = std::make_unique<base::Value>(ToString(state));
auto expected = std::make_unique<base::Value>("one");
EXPECT_TRUE(result->Equals(expected.get()));
}
{
Enumeration state = ENUMERATION_ONE;
enums::Enumeration state = enums::ENUMERATION_ONE;
std::unique_ptr<base::ListValue> results =
ReturnsEnum::Results::Create(state);
enums::ReturnsEnum::Results::Create(state);
base::ListValue expected;
expected.AppendString("one");
EXPECT_TRUE(results->Equals(&expected));
......@@ -110,8 +111,9 @@ TEST(JsonSchemaCompilerEnumsTest, ReturnsEnumCreate) {
TEST(JsonSchemaCompilerEnumsTest, ReturnsTwoEnumsCreate) {
{
std::unique_ptr<base::ListValue> results = ReturnsTwoEnums::Results::Create(
ENUMERATION_ONE, OTHER_ENUMERATION_HAM);
std::unique_ptr<base::ListValue> results =
enums::ReturnsTwoEnums::Results::Create(enums::ENUMERATION_ONE,
enums::OTHER_ENUMERATION_HAM);
base::ListValue expected;
expected.AppendString("one");
expected.AppendString("ham");
......@@ -121,25 +123,25 @@ TEST(JsonSchemaCompilerEnumsTest, ReturnsTwoEnumsCreate) {
TEST(JsonSchemaCompilerEnumsTest, OptionalEnumTypePopulate) {
{
OptionalEnumType enum_type;
enums::OptionalEnumType enum_type;
base::DictionaryValue value;
value.SetString("type", "two");
EXPECT_TRUE(OptionalEnumType::Populate(value, &enum_type));
EXPECT_EQ(ENUMERATION_TWO, enum_type.type);
EXPECT_TRUE(enums::OptionalEnumType::Populate(value, &enum_type));
EXPECT_EQ(enums::ENUMERATION_TWO, enum_type.type);
EXPECT_TRUE(value.Equals(enum_type.ToValue().get()));
}
{
OptionalEnumType enum_type;
enums::OptionalEnumType enum_type;
base::DictionaryValue value;
EXPECT_TRUE(OptionalEnumType::Populate(value, &enum_type));
EXPECT_EQ(ENUMERATION_NONE, enum_type.type);
EXPECT_TRUE(enums::OptionalEnumType::Populate(value, &enum_type));
EXPECT_EQ(enums::ENUMERATION_NONE, enum_type.type);
EXPECT_TRUE(value.Equals(enum_type.ToValue().get()));
}
{
OptionalEnumType enum_type;
enums::OptionalEnumType enum_type;
base::DictionaryValue value;
value.SetString("type", "invalid");
EXPECT_FALSE(OptionalEnumType::Populate(value, &enum_type));
EXPECT_FALSE(enums::OptionalEnumType::Populate(value, &enum_type));
}
}
......@@ -147,16 +149,16 @@ TEST(JsonSchemaCompilerEnumsTest, TakesEnumParamsCreate) {
{
base::ListValue params_value;
params_value.AppendString("two");
std::unique_ptr<TakesEnum::Params> params(
TakesEnum::Params::Create(params_value));
std::unique_ptr<enums::TakesEnum::Params> params(
enums::TakesEnum::Params::Create(params_value));
EXPECT_TRUE(params.get());
EXPECT_EQ(ENUMERATION_TWO, params->state);
EXPECT_EQ(enums::ENUMERATION_TWO, params->state);
}
{
base::ListValue params_value;
params_value.AppendString("invalid");
std::unique_ptr<TakesEnum::Params> params(
TakesEnum::Params::Create(params_value));
std::unique_ptr<enums::TakesEnum::Params> params(
enums::TakesEnum::Params::Create(params_value));
EXPECT_FALSE(params.get());
}
}
......@@ -166,18 +168,18 @@ TEST(JsonSchemaCompilerEnumsTest, TakesEnumArrayParamsCreate) {
base::ListValue params_value;
params_value.Append(List(std::make_unique<base::Value>("one"),
std::make_unique<base::Value>("two")));
std::unique_ptr<TakesEnumArray::Params> params(
TakesEnumArray::Params::Create(params_value));
std::unique_ptr<enums::TakesEnumArray::Params> params(
enums::TakesEnumArray::Params::Create(params_value));
ASSERT_TRUE(params);
EXPECT_EQ(2U, params->values.size());
EXPECT_EQ(ENUMERATION_ONE, params->values[0]);
EXPECT_EQ(ENUMERATION_TWO, params->values[1]);
EXPECT_EQ(enums::ENUMERATION_ONE, params->values[0]);
EXPECT_EQ(enums::ENUMERATION_TWO, params->values[1]);
}
{
base::ListValue params_value;
params_value.Append(List(std::make_unique<base::Value>("invalid")));
std::unique_ptr<TakesEnumArray::Params> params(
TakesEnumArray::Params::Create(params_value));
std::unique_ptr<enums::TakesEnumArray::Params> params(
enums::TakesEnumArray::Params::Create(params_value));
EXPECT_FALSE(params);
}
}
......@@ -186,23 +188,23 @@ TEST(JsonSchemaCompilerEnumsTest, TakesOptionalEnumParamsCreate) {
{
base::ListValue params_value;
params_value.AppendString("three");
std::unique_ptr<TakesOptionalEnum::Params> params(
TakesOptionalEnum::Params::Create(params_value));
std::unique_ptr<enums::TakesOptionalEnum::Params> params(
enums::TakesOptionalEnum::Params::Create(params_value));
EXPECT_TRUE(params.get());
EXPECT_EQ(ENUMERATION_THREE, params->state);
EXPECT_EQ(enums::ENUMERATION_THREE, params->state);
}
{
base::ListValue params_value;
std::unique_ptr<TakesOptionalEnum::Params> params(
TakesOptionalEnum::Params::Create(params_value));
std::unique_ptr<enums::TakesOptionalEnum::Params> params(
enums::TakesOptionalEnum::Params::Create(params_value));
EXPECT_TRUE(params.get());
EXPECT_EQ(ENUMERATION_NONE, params->state);
EXPECT_EQ(enums::ENUMERATION_NONE, params->state);
}
{
base::ListValue params_value;
params_value.AppendString("invalid");
std::unique_ptr<TakesOptionalEnum::Params> params(
TakesOptionalEnum::Params::Create(params_value));
std::unique_ptr<enums::TakesOptionalEnum::Params> params(
enums::TakesOptionalEnum::Params::Create(params_value));
EXPECT_FALSE(params.get());
}
}
......@@ -212,49 +214,50 @@ TEST(JsonSchemaCompilerEnumsTest, TakesMultipleOptionalEnumsParamsCreate) {
base::ListValue params_value;
params_value.AppendString("one");
params_value.AppendString("ham");
std::unique_ptr<TakesMultipleOptionalEnums::Params> params(
TakesMultipleOptionalEnums::Params::Create(params_value));
std::unique_ptr<enums::TakesMultipleOptionalEnums::Params> params(
enums::TakesMultipleOptionalEnums::Params::Create(params_value));
EXPECT_TRUE(params.get());
EXPECT_EQ(ENUMERATION_ONE, params->state);
EXPECT_EQ(OTHER_ENUMERATION_HAM, params->type);
EXPECT_EQ(enums::ENUMERATION_ONE, params->state);
EXPECT_EQ(enums::OTHER_ENUMERATION_HAM, params->type);
}
{
base::ListValue params_value;
params_value.AppendString("one");
std::unique_ptr<TakesMultipleOptionalEnums::Params> params(
TakesMultipleOptionalEnums::Params::Create(params_value));
std::unique_ptr<enums::TakesMultipleOptionalEnums::Params> params(
enums::TakesMultipleOptionalEnums::Params::Create(params_value));
EXPECT_TRUE(params.get());
EXPECT_EQ(ENUMERATION_ONE, params->state);
EXPECT_EQ(OTHER_ENUMERATION_NONE, params->type);
EXPECT_EQ(enums::ENUMERATION_ONE, params->state);
EXPECT_EQ(enums::OTHER_ENUMERATION_NONE, params->type);
}
{
base::ListValue params_value;
std::unique_ptr<TakesMultipleOptionalEnums::Params> params(
TakesMultipleOptionalEnums::Params::Create(params_value));
std::unique_ptr<enums::TakesMultipleOptionalEnums::Params> params(
enums::TakesMultipleOptionalEnums::Params::Create(params_value));
EXPECT_TRUE(params.get());
EXPECT_EQ(ENUMERATION_NONE, params->state);
EXPECT_EQ(OTHER_ENUMERATION_NONE, params->type);
EXPECT_EQ(enums::ENUMERATION_NONE, params->state);
EXPECT_EQ(enums::OTHER_ENUMERATION_NONE, params->type);
}
{
base::ListValue params_value;
params_value.AppendString("three");
params_value.AppendString("invalid");
std::unique_ptr<TakesMultipleOptionalEnums::Params> params(
TakesMultipleOptionalEnums::Params::Create(params_value));
std::unique_ptr<enums::TakesMultipleOptionalEnums::Params> params(
enums::TakesMultipleOptionalEnums::Params::Create(params_value));
EXPECT_FALSE(params.get());
}
}
TEST(JsonSchemaCompilerEnumsTest, OnEnumFiredCreate) {
{
Enumeration some_enum = ENUMERATION_ONE;
std::unique_ptr<base::Value> result(new base::Value(ToString(some_enum)));
std::unique_ptr<base::Value> expected(new base::Value("one"));
enums::Enumeration some_enum = enums::ENUMERATION_ONE;
auto result = std::make_unique<base::Value>(ToString(some_enum));
auto expected = std::make_unique<base::Value>("one");
EXPECT_TRUE(result->Equals(expected.get()));
}
{
Enumeration some_enum = ENUMERATION_ONE;
std::unique_ptr<base::ListValue> results(OnEnumFired::Create(some_enum));
enums::Enumeration some_enum = enums::ENUMERATION_ONE;
std::unique_ptr<base::ListValue> results(
enums::OnEnumFired::Create(some_enum));
base::ListValue expected;
expected.AppendString("one");
EXPECT_TRUE(results->Equals(&expected));
......@@ -263,8 +266,8 @@ TEST(JsonSchemaCompilerEnumsTest, OnEnumFiredCreate) {
TEST(JsonSchemaCompilerEnumsTest, OnTwoEnumsFiredCreate) {
{
std::unique_ptr<base::Value> results(
OnTwoEnumsFired::Create(ENUMERATION_ONE, OTHER_ENUMERATION_HAM));
std::unique_ptr<base::Value> results(enums::OnTwoEnumsFired::Create(
enums::ENUMERATION_ONE, enums::OTHER_ENUMERATION_HAM));
base::ListValue expected;
expected.AppendString("one");
expected.AppendString("ham");
......
......@@ -11,13 +11,13 @@
#include "testing/gtest/include/gtest/gtest.h"
#include "tools/json_schema_compiler/test/test_util.h"
using namespace test::api::error_generation;
namespace errors = test::api::error_generation;
using base::Value;
using json_schema_compiler::test_util::Dictionary;
using json_schema_compiler::test_util::List;
template <typename T>
base::string16 GetPopulateError(const base::Value& value) {
base::string16 GetPopulateError(const Value& value) {
base::string16 error;
T test_type;
T::Populate(value, &test_type, &error);
......@@ -37,26 +37,27 @@ testing::AssertionResult EqualsUtf16(const std::string& expected,
TEST(JsonSchemaCompilerErrorTest, RequiredPropertyPopulate) {
{
std::unique_ptr<base::DictionaryValue> value =
Dictionary("string", std::make_unique<base::Value>("bling"));
EXPECT_TRUE(EqualsUtf16("", GetPopulateError<TestType>(*value)));
Dictionary("string", std::make_unique<Value>("bling"));
EXPECT_TRUE(EqualsUtf16("", GetPopulateError<errors::TestType>(*value)));
}
{
auto value = std::make_unique<base::Value>(base::Value::Type::BINARY);
auto value = std::make_unique<Value>(Value::Type::BINARY);
EXPECT_TRUE(EqualsUtf16("expected dictionary, got binary",
GetPopulateError<TestType>(*value)));
GetPopulateError<errors::TestType>(*value)));
}
}
TEST(JsonSchemaCompilerErrorTest, UnexpectedTypePopulation) {
{
std::unique_ptr<base::ListValue> value(new base::ListValue());
EXPECT_TRUE(EqualsUtf16("",
GetPopulateError<ChoiceType::Integers>(*value)));
auto value = std::make_unique<base::ListValue>();
EXPECT_TRUE(EqualsUtf16(
"", GetPopulateError<errors::ChoiceType::Integers>(*value)));
}
{
auto value = std::make_unique<base::Value>(base::Value::Type::BINARY);
EXPECT_TRUE(EqualsUtf16("expected integers or integer, got binary",
GetPopulateError<ChoiceType::Integers>(*value)));
auto value = std::make_unique<Value>(Value::Type::BINARY);
EXPECT_TRUE(
EqualsUtf16("expected integers or integer, got binary",
GetPopulateError<errors::ChoiceType::Integers>(*value)));
}
}
......@@ -66,12 +67,12 @@ TEST(JsonSchemaCompilerErrorTest, TypeIsRequired) {
{
std::unique_ptr<base::DictionaryValue> value =
Dictionary("integers", std::make_unique<Value>(5));
EXPECT_TRUE(EqualsUtf16("", GetPopulateError<ChoiceType>(*value)));
EXPECT_TRUE(EqualsUtf16("", GetPopulateError<errors::ChoiceType>(*value)));
}
{
std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue());
auto value = std::make_unique<base::DictionaryValue>();
EXPECT_TRUE(EqualsUtf16("'integers' is required",
GetPopulateError<ChoiceType>(*value)));
GetPopulateError<errors::ChoiceType>(*value)));
}
}
......@@ -82,13 +83,13 @@ TEST(JsonSchemaCompilerErrorTest, TooManyParameters) {
std::unique_ptr<base::ListValue> params_value =
List(std::make_unique<Value>(5));
base::string16 error;
EXPECT_TRUE(TestFunction::Params::Create(*params_value, &error));
EXPECT_TRUE(errors::TestFunction::Params::Create(*params_value, &error));
}
{
std::unique_ptr<base::ListValue> params_value =
List(std::make_unique<Value>(5), std::make_unique<Value>(5));
base::string16 error;
EXPECT_FALSE(TestFunction::Params::Create(*params_value, &error));
EXPECT_FALSE(errors::TestFunction::Params::Create(*params_value, &error));
EXPECT_TRUE(EqualsUtf16("expected 1 arguments, got 2", error));
}
}
......@@ -100,13 +101,13 @@ TEST(JsonSchemaCompilerErrorTest, ParamIsRequired) {
std::unique_ptr<base::ListValue> params_value =
List(std::make_unique<Value>(5));
base::string16 error;
EXPECT_TRUE(TestFunction::Params::Create(*params_value, &error));
EXPECT_TRUE(errors::TestFunction::Params::Create(*params_value, &error));
}
{
std::unique_ptr<base::ListValue> params_value =
List(std::make_unique<Value>());
base::string16 error;
EXPECT_FALSE(TestFunction::Params::Create(*params_value, &error));
EXPECT_FALSE(errors::TestFunction::Params::Create(*params_value, &error));
EXPECT_TRUE(EqualsUtf16("'num' is required", error));
}
}
......@@ -116,14 +117,14 @@ TEST(JsonSchemaCompilerErrorTest, ParamIsRequired) {
TEST(JsonSchemaCompilerErrorTest, WrongPropertyValueType) {
{
std::unique_ptr<base::DictionaryValue> value =
Dictionary("string", std::make_unique<base::Value>("yes"));
EXPECT_TRUE(EqualsUtf16("", GetPopulateError<TestType>(*value)));
Dictionary("string", std::make_unique<Value>("yes"));
EXPECT_TRUE(EqualsUtf16("", GetPopulateError<errors::TestType>(*value)));
}
{
std::unique_ptr<base::DictionaryValue> value =
Dictionary("string", std::make_unique<Value>(1.1));
EXPECT_TRUE(EqualsUtf16("'string': expected string, got double",
GetPopulateError<TestType>(*value)));
GetPopulateError<errors::TestType>(*value)));
}
}
......@@ -131,14 +132,15 @@ TEST(JsonSchemaCompilerErrorTest, WrongParameterCreationType) {
{
base::string16 error;
std::unique_ptr<base::ListValue> params_value =
List(std::make_unique<base::Value>("Yeah!"));
EXPECT_TRUE(TestString::Params::Create(*params_value, &error));
List(std::make_unique<Value>("Yeah!"));
EXPECT_TRUE(errors::TestString::Params::Create(*params_value, &error));
}
{
std::unique_ptr<base::ListValue> params_value =
List(std::make_unique<Value>(5));
base::string16 error;
EXPECT_FALSE(TestTypeInObject::Params::Create(*params_value, &error));
EXPECT_FALSE(
errors::TestTypeInObject::Params::Create(*params_value, &error));
EXPECT_TRUE(EqualsUtf16("'paramObject': expected dictionary, got integer",
error));
}
......@@ -146,15 +148,15 @@ TEST(JsonSchemaCompilerErrorTest, WrongParameterCreationType) {
TEST(JsonSchemaCompilerErrorTest, WrongTypeValueType) {
{
std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue());
EXPECT_TRUE(EqualsUtf16("", GetPopulateError<ObjectType>(*value)));
auto value = std::make_unique<base::DictionaryValue>();
EXPECT_TRUE(EqualsUtf16("", GetPopulateError<errors::ObjectType>(*value)));
}
{
std::unique_ptr<base::DictionaryValue> value =
Dictionary("otherType", std::make_unique<Value>(1.1));
ObjectType out;
errors::ObjectType out;
base::string16 error;
EXPECT_TRUE(ObjectType::Populate(*value, &out, &error));
EXPECT_TRUE(errors::ObjectType::Populate(*value, &out, &error));
EXPECT_TRUE(EqualsUtf16("'otherType': expected dictionary, got double",
error));
EXPECT_EQ(NULL, out.other_type.get());
......@@ -165,29 +167,29 @@ TEST(JsonSchemaCompilerErrorTest, UnableToPopulateArray) {
{
std::unique_ptr<base::ListValue> params_value =
List(std::make_unique<Value>(5));
EXPECT_TRUE(EqualsUtf16("",
GetPopulateError<ChoiceType::Integers>(*params_value)));
EXPECT_TRUE(EqualsUtf16(
"", GetPopulateError<errors::ChoiceType::Integers>(*params_value)));
}
{
std::unique_ptr<base::ListValue> params_value =
List(std::make_unique<Value>(5), std::make_unique<Value>(false));
EXPECT_TRUE(EqualsUtf16(
"expected integer, got boolean; unable to populate array 'integers'",
GetPopulateError<ChoiceType::Integers>(*params_value)));
GetPopulateError<errors::ChoiceType::Integers>(*params_value)));
}
}
TEST(JsonSchemaCompilerErrorTest, BinaryTypeExpected) {
{
std::unique_ptr<base::DictionaryValue> value = Dictionary(
"data", std::make_unique<base::Value>(base::Value::Type::BINARY));
EXPECT_TRUE(EqualsUtf16("", GetPopulateError<BinaryData>(*value)));
std::unique_ptr<base::DictionaryValue> value =
Dictionary("data", std::make_unique<Value>(Value::Type::BINARY));
EXPECT_TRUE(EqualsUtf16("", GetPopulateError<errors::BinaryData>(*value)));
}
{
std::unique_ptr<base::DictionaryValue> value =
Dictionary("data", std::make_unique<Value>(1.1));
EXPECT_TRUE(EqualsUtf16("'data': expected binary, got double",
GetPopulateError<BinaryData>(*value)));
GetPopulateError<errors::BinaryData>(*value)));
}
}
......@@ -195,13 +197,13 @@ TEST(JsonSchemaCompilerErrorTest, ListExpected) {
{
std::unique_ptr<base::DictionaryValue> value =
Dictionary("TheArray", std::make_unique<base::ListValue>());
EXPECT_TRUE(EqualsUtf16("", GetPopulateError<ArrayObject>(*value)));
EXPECT_TRUE(EqualsUtf16("", GetPopulateError<errors::ArrayObject>(*value)));
}
{
std::unique_ptr<base::DictionaryValue> value =
Dictionary("TheArray", std::make_unique<Value>(5));
EXPECT_TRUE(EqualsUtf16("'TheArray': expected list, got integer",
GetPopulateError<ArrayObject>(*value)));
GetPopulateError<errors::ArrayObject>(*value)));
}
}
......@@ -210,15 +212,17 @@ TEST(JsonSchemaCompilerErrorTest, ListExpected) {
TEST(JsonSchemaCompilerErrorTest, BadEnumValue) {
{
std::unique_ptr<base::DictionaryValue> value =
Dictionary("enumeration", std::make_unique<base::Value>("one"));
EXPECT_TRUE(EqualsUtf16("", GetPopulateError<HasEnumeration>(*value)));
Dictionary("enumeration", std::make_unique<Value>("one"));
EXPECT_TRUE(
EqualsUtf16("", GetPopulateError<errors::HasEnumeration>(*value)));
}
{
std::unique_ptr<base::DictionaryValue> value =
Dictionary("enumeration", std::make_unique<base::Value>("bad sauce"));
EXPECT_TRUE(EqualsUtf16("'Enumeration': expected \"one\" or \"two\" "
Dictionary("enumeration", std::make_unique<Value>("bad sauce"));
EXPECT_TRUE(
EqualsUtf16("'Enumeration': expected \"one\" or \"two\" "
"or \"three\", got \"bad sauce\"",
GetPopulateError<HasEnumeration>(*value)));
GetPopulateError<errors::HasEnumeration>(*value)));
}
}
......@@ -227,16 +231,17 @@ TEST(JsonSchemaCompilerErrorTest, BadEnumValue) {
TEST(JsonSchemaCompilerErrorTest, WarnOnOptionalFailure) {
{
std::unique_ptr<base::DictionaryValue> value =
Dictionary("string", std::make_unique<base::Value>("bling"));
EXPECT_TRUE(EqualsUtf16("", GetPopulateError<OptionalTestType>(*value)));
Dictionary("string", std::make_unique<Value>("bling"));
EXPECT_TRUE(
EqualsUtf16("", GetPopulateError<errors::OptionalTestType>(*value)));
}
{
std::unique_ptr<base::DictionaryValue> value =
Dictionary("string", std::make_unique<base::Value>(1));
Dictionary("string", std::make_unique<Value>(1));
OptionalTestType out;
errors::OptionalTestType out;
base::string16 error;
EXPECT_TRUE(OptionalTestType::Populate(*value, &out, &error));
EXPECT_TRUE(errors::OptionalTestType::Populate(*value, &out, &error));
EXPECT_TRUE(EqualsUtf16("'string': expected string, got integer",
error));
EXPECT_EQ(NULL, out.string.get());
......@@ -245,18 +250,19 @@ TEST(JsonSchemaCompilerErrorTest, WarnOnOptionalFailure) {
TEST(JsonSchemaCompilerErrorTest, OptionalBinaryTypeFailure) {
{
std::unique_ptr<base::DictionaryValue> value = Dictionary(
"data", std::make_unique<base::Value>(base::Value::Type::BINARY));
EXPECT_TRUE(EqualsUtf16("", GetPopulateError<OptionalBinaryData>(*value)));
std::unique_ptr<base::DictionaryValue> value =
Dictionary("data", std::make_unique<Value>(Value::Type::BINARY));
EXPECT_TRUE(
EqualsUtf16("", GetPopulateError<errors::OptionalBinaryData>(*value)));
}
{
// There's a bug with silent failures if the key doesn't exist.
std::unique_ptr<base::DictionaryValue> value =
Dictionary("data", std::make_unique<base::Value>(1));
Dictionary("data", std::make_unique<Value>(1));
OptionalBinaryData out;
errors::OptionalBinaryData out;
base::string16 error;
EXPECT_TRUE(OptionalBinaryData::Populate(*value, &out, &error));
EXPECT_TRUE(errors::OptionalBinaryData::Populate(*value, &out, &error));
EXPECT_TRUE(EqualsUtf16("'data': expected binary, got integer",
error));
EXPECT_EQ(NULL, out.data.get());
......@@ -267,14 +273,14 @@ TEST(JsonSchemaCompilerErrorTest, OptionalArrayTypeFailure) {
{
std::unique_ptr<base::DictionaryValue> value =
Dictionary("TheArray", std::make_unique<base::ListValue>());
EXPECT_TRUE(EqualsUtf16("", GetPopulateError<ArrayObject>(*value)));
EXPECT_TRUE(EqualsUtf16("", GetPopulateError<errors::ArrayObject>(*value)));
}
{
std::unique_ptr<base::DictionaryValue> value =
Dictionary("TheArray", std::make_unique<Value>(5));
ArrayObject out;
errors::ArrayObject out;
base::string16 error;
EXPECT_TRUE(ArrayObject::Populate(*value, &out, &error));
EXPECT_TRUE(errors::ArrayObject::Populate(*value, &out, &error));
EXPECT_TRUE(EqualsUtf16("'TheArray': expected list, got integer",
error));
EXPECT_EQ(NULL, out.the_array.get());
......@@ -285,16 +291,17 @@ TEST(JsonSchemaCompilerErrorTest, OptionalUnableToPopulateArray) {
{
std::unique_ptr<base::ListValue> params_value =
List(std::make_unique<Value>(5));
EXPECT_TRUE(EqualsUtf16("",
GetPopulateError<OptionalChoiceType::Integers>(*params_value)));
EXPECT_TRUE(EqualsUtf16(
"",
GetPopulateError<errors::OptionalChoiceType::Integers>(*params_value)));
}
{
std::unique_ptr<base::ListValue> params_value =
List(std::make_unique<Value>(5), std::make_unique<Value>(false));
OptionalChoiceType::Integers out;
errors::OptionalChoiceType::Integers out;
base::string16 error;
EXPECT_TRUE(OptionalChoiceType::Integers::Populate(*params_value, &out,
&error));
EXPECT_TRUE(errors::OptionalChoiceType::Integers::Populate(*params_value,
&out, &error));
EXPECT_TRUE(EqualsUtf16(
"expected integer, got boolean; unable to populate array 'integers'",
error));
......@@ -306,14 +313,14 @@ TEST(JsonSchemaCompilerErrorTest, MultiplePopulationErrors) {
{
std::unique_ptr<base::DictionaryValue> value =
Dictionary("TheArray", std::make_unique<Value>(5));
ArrayObject out;
errors::ArrayObject out;
base::string16 error;
EXPECT_TRUE(ArrayObject::Populate(*value, &out, &error));
EXPECT_TRUE(errors::ArrayObject::Populate(*value, &out, &error));
EXPECT_TRUE(EqualsUtf16("'TheArray': expected list, got integer",
error));
EXPECT_EQ(NULL, out.the_array.get());
EXPECT_TRUE(ArrayObject::Populate(*value, &out, &error));
EXPECT_TRUE(errors::ArrayObject::Populate(*value, &out, &error));
EXPECT_TRUE(EqualsUtf16("'TheArray': expected list, got integer; "
"'TheArray': expected list, got integer",
error));
......@@ -324,14 +331,14 @@ TEST(JsonSchemaCompilerErrorTest, MultiplePopulationErrors) {
TEST(JsonSchemaCompilerErrorTest, TooManyKeys) {
{
std::unique_ptr<base::DictionaryValue> value =
Dictionary("string", std::make_unique<base::Value>("yes"));
EXPECT_TRUE(EqualsUtf16("", GetPopulateError<TestType>(*value)));
Dictionary("string", std::make_unique<Value>("yes"));
EXPECT_TRUE(EqualsUtf16("", GetPopulateError<errors::TestType>(*value)));
}
{
std::unique_ptr<base::DictionaryValue> value =
Dictionary("string", std::make_unique<base::Value>("yes"), "ohno",
std::make_unique<base::Value>("many values"));
Dictionary("string", std::make_unique<Value>("yes"), "ohno",
std::make_unique<Value>("many values"));
EXPECT_TRUE(EqualsUtf16("found unexpected key 'ohno'",
GetPopulateError<TestType>(*value)));
GetPopulateError<errors::TestType>(*value)));
}
}
......@@ -9,7 +9,8 @@
#include "base/values.h"
#include "testing/gtest/include/gtest/gtest.h"
using namespace test::api::functions_as_parameters;
using test::api::functions_as_parameters::FunctionType;
using test::api::functions_as_parameters::OptionalFunctionType;
TEST(JsonSchemaCompilerFunctionsAsParametersTest, PopulateRequiredFunction) {
// The expectation is that if any value is set for the function, then
......
......@@ -9,41 +9,40 @@
#include "base/values.h"
#include "testing/gtest/include/gtest/gtest.h"
using namespace test::api::functions_on_types;
namespace functions_on_types = test::api::functions_on_types;
TEST(JsonSchemaCompilerFunctionsOnTypesTest, StorageAreaGetParamsCreate) {
{
std::unique_ptr<base::ListValue> params_value(new base::ListValue());
std::unique_ptr<StorageArea::Get::Params> params(
StorageArea::Get::Params::Create(*params_value));
auto params_value = std::make_unique<base::ListValue>();
std::unique_ptr<functions_on_types::StorageArea::Get::Params> params(
functions_on_types::StorageArea::Get::Params::Create(*params_value));
ASSERT_TRUE(params);
EXPECT_FALSE(params->keys);
}
{
std::unique_ptr<base::ListValue> params_value(new base::ListValue());
auto params_value = std::make_unique<base::ListValue>();
params_value->AppendInteger(9);
std::unique_ptr<StorageArea::Get::Params> params(
StorageArea::Get::Params::Create(*params_value));
std::unique_ptr<functions_on_types::StorageArea::Get::Params> params(
functions_on_types::StorageArea::Get::Params::Create(*params_value));
EXPECT_FALSE(params);
}
{
std::unique_ptr<base::ListValue> params_value(new base::ListValue());
auto params_value = std::make_unique<base::ListValue>();
params_value->AppendString("test");
std::unique_ptr<StorageArea::Get::Params> params(
StorageArea::Get::Params::Create(*params_value));
std::unique_ptr<functions_on_types::StorageArea::Get::Params> params(
functions_on_types::StorageArea::Get::Params::Create(*params_value));
ASSERT_TRUE(params);
ASSERT_TRUE(params->keys);
EXPECT_EQ("test", *params->keys->as_string);
}
{
std::unique_ptr<base::DictionaryValue> keys_object_value(
new base::DictionaryValue());
auto keys_object_value = std::make_unique<base::DictionaryValue>();
keys_object_value->SetInteger("integer", 5);
keys_object_value->SetString("string", "string");
std::unique_ptr<base::ListValue> params_value(new base::ListValue());
auto params_value = std::make_unique<base::ListValue>();
params_value->Append(keys_object_value->CreateDeepCopy());
std::unique_ptr<StorageArea::Get::Params> params(
StorageArea::Get::Params::Create(*params_value));
std::unique_ptr<functions_on_types::StorageArea::Get::Params> params(
functions_on_types::StorageArea::Get::Params::Create(*params_value));
ASSERT_TRUE(params);
ASSERT_TRUE(params->keys);
EXPECT_TRUE(keys_object_value->Equals(
......@@ -52,24 +51,23 @@ TEST(JsonSchemaCompilerFunctionsOnTypesTest, StorageAreaGetParamsCreate) {
}
TEST(JsonSchemaCompilerFunctionsOnTypesTest, StorageAreaGetResultCreate) {
StorageArea::Get::Results::Items items;
functions_on_types::StorageArea::Get::Results::Items items;
items.additional_properties.SetDouble("asdf", 0.1);
items.additional_properties.SetString("sdfg", "zxcv");
std::unique_ptr<base::ListValue> results =
StorageArea::Get::Results::Create(items);
functions_on_types::StorageArea::Get::Results::Create(items);
base::DictionaryValue* item_result = NULL;
ASSERT_TRUE(results->GetDictionary(0, &item_result));
EXPECT_TRUE(item_result->Equals(&items.additional_properties));
}
TEST(JsonSchemaCompilerFunctionsOnTypesTest, ChromeSettingGetParamsCreate) {
std::unique_ptr<base::DictionaryValue> details_value(
new base::DictionaryValue());
auto details_value = std::make_unique<base::DictionaryValue>();
details_value->SetBoolean("incognito", true);
std::unique_ptr<base::ListValue> params_value(new base::ListValue());
auto params_value = std::make_unique<base::ListValue>();
params_value->Append(std::move(details_value));
std::unique_ptr<ChromeSetting::Get::Params> params(
ChromeSetting::Get::Params::Create(*params_value));
std::unique_ptr<functions_on_types::ChromeSetting::Get::Params> params(
functions_on_types::ChromeSetting::Get::Params::Create(*params_value));
EXPECT_TRUE(params.get());
EXPECT_TRUE(*params->details.incognito);
}
......@@ -15,9 +15,7 @@
#include "tools/json_schema_compiler/test/objects_movable.h"
#include "tools/json_schema_compiler/test/objects_movable_json.h"
using namespace test::api::objects;
using namespace test::api::objects_movable;
using namespace test::api::objects_movable_json;
namespace objects_movable = test::api::objects_movable;
TEST(JsonSchemaCompilerObjectsTest, ObjectParamParamsCreate) {
{
......@@ -31,8 +29,8 @@ TEST(JsonSchemaCompilerObjectsTest, ObjectParamParamsCreate) {
auto params_value = std::make_unique<base::ListValue>();
params_value->Append(std::move(info_value));
std::unique_ptr<ObjectParam::Params> params(
ObjectParam::Params::Create(*params_value));
std::unique_ptr<test::api::objects::ObjectParam::Params> params(
test::api::objects::ObjectParam::Params::Create(*params_value));
EXPECT_TRUE(params.get());
EXPECT_EQ((size_t) 2, params->info.strings.size());
EXPECT_EQ("one", params->info.strings[0]);
......@@ -50,17 +48,17 @@ TEST(JsonSchemaCompilerObjectsTest, ObjectParamParamsCreate) {
auto params_value = std::make_unique<base::ListValue>();
params_value->Append(std::move(info_value));
std::unique_ptr<ObjectParam::Params> params(
ObjectParam::Params::Create(*params_value));
std::unique_ptr<test::api::objects::ObjectParam::Params> params(
test::api::objects::ObjectParam::Params::Create(*params_value));
EXPECT_FALSE(params.get());
}
}
TEST(JsonSchemaCompilerObjectsTest, ReturnsObjectResultCreate) {
ReturnsObject::Results::Info info;
info.state = FIRST_STATE_FOO;
test::api::objects::ReturnsObject::Results::Info info;
info.state = test::api::objects::FIRST_STATE_FOO;
std::unique_ptr<base::ListValue> results =
ReturnsObject::Results::Create(info);
test::api::objects::ReturnsObject::Results::Create(info);
base::DictionaryValue expected;
expected.SetString("state", "foo");
......@@ -70,9 +68,10 @@ TEST(JsonSchemaCompilerObjectsTest, ReturnsObjectResultCreate) {
}
TEST(JsonSchemaCompilerObjectsTest, OnObjectFiredCreate) {
OnObjectFired::SomeObject object;
object.state = FIRST_STATE_BAR;
std::unique_ptr<base::ListValue> results(OnObjectFired::Create(object));
test::api::objects::OnObjectFired::SomeObject object;
object.state = test::api::objects::FIRST_STATE_BAR;
std::unique_ptr<base::ListValue> results(
test::api::objects::OnObjectFired::Create(object));
base::DictionaryValue expected;
expected.SetString("state", "bar");
......@@ -81,36 +80,36 @@ TEST(JsonSchemaCompilerObjectsTest, OnObjectFiredCreate) {
ASSERT_TRUE(result->Equals(&expected));
}
TEST(JsonSchemaCompilerMovableObjectsTest, MovableObjectsTest) {
std::vector<MovablePod> pods;
std::vector<objects_movable::MovablePod> pods;
{
MovablePod pod;
pod.foo = FOO_BAR;
objects_movable::MovablePod pod;
pod.foo = objects_movable::FOO_BAR;
pod.str = "str1";
pod.num = 42;
pod.b = true;
pods.push_back(std::move(pod));
}
{
MovablePod pod;
pod.foo = FOO_BAZ;
objects_movable::MovablePod pod;
pod.foo = objects_movable::FOO_BAZ;
pod.str = "str2";
pod.num = 45;
pod.b = false;
pods.push_back(std::move(pod));
}
MovableParent parent;
objects_movable::MovableParent parent;
parent.pods = std::move(pods);
parent.strs.push_back("pstr");
parent.blob.additional_properties.SetString("key", "val");
parent.choice.as_string.reset(new std::string("string"));
parent.choice.as_string = std::make_unique<std::string>("string");
MovableParent parent2(std::move(parent));
objects_movable::MovableParent parent2(std::move(parent));
ASSERT_EQ(2u, parent2.pods.size());
EXPECT_EQ(FOO_BAR, parent2.pods[0].foo);
EXPECT_EQ(objects_movable::FOO_BAR, parent2.pods[0].foo);
EXPECT_EQ("str1", parent2.pods[0].str);
EXPECT_EQ(42, parent2.pods[0].num);
EXPECT_TRUE(parent2.pods[0].b);
EXPECT_EQ(FOO_BAZ, parent2.pods[1].foo);
EXPECT_EQ(objects_movable::FOO_BAZ, parent2.pods[1].foo);
EXPECT_EQ("str2", parent2.pods[1].str);
EXPECT_EQ(45, parent2.pods[1].num);
EXPECT_FALSE(parent2.pods[1].b);
......@@ -125,14 +124,14 @@ TEST(JsonSchemaCompilerMovableObjectsTest, MovableObjectsTest) {
EXPECT_EQ("val", blob_string);
{
MovableParent parent_with_pod_choice;
MovablePod pod;
pod.foo = FOO_BAZ;
objects_movable::MovableParent parent_with_pod_choice;
objects_movable::MovablePod pod;
pod.foo = objects_movable::FOO_BAZ;
pod.str = "str";
pod.num = 10;
pod.b = false;
parent_with_pod_choice.choice.as_movable_pod.reset(
new MovablePod(std::move(pod)));
parent_with_pod_choice.choice.as_movable_pod =
std::make_unique<objects_movable::MovablePod>(std::move(pod));
parent2 = std::move(parent_with_pod_choice);
}
EXPECT_TRUE(parent2.pods.empty());
......@@ -140,12 +139,12 @@ TEST(JsonSchemaCompilerMovableObjectsTest, MovableObjectsTest) {
EXPECT_TRUE(parent2.blob.additional_properties.empty());
EXPECT_FALSE(parent2.choice.as_string.get());
ASSERT_TRUE(parent2.choice.as_movable_pod.get());
EXPECT_EQ(FOO_BAZ, parent2.choice.as_movable_pod->foo);
EXPECT_EQ(objects_movable::FOO_BAZ, parent2.choice.as_movable_pod->foo);
EXPECT_EQ("str", parent2.choice.as_movable_pod->str);
EXPECT_EQ(10, parent2.choice.as_movable_pod->num);
EXPECT_FALSE(parent2.choice.as_movable_pod->b);
MovableWithAdditional with_additional;
test::api::objects_movable_json::MovableWithAdditional with_additional;
with_additional.str = "str";
std::vector<std::string> vals1;
vals1.push_back("vals1a");
......@@ -156,7 +155,8 @@ TEST(JsonSchemaCompilerMovableObjectsTest, MovableObjectsTest) {
vals2.push_back("vals2b");
with_additional.additional_properties["key2"] = vals2;
MovableWithAdditional with_additional2(std::move(with_additional));
test::api::objects_movable_json::MovableWithAdditional with_additional2(
std::move(with_additional));
EXPECT_EQ("str", with_additional2.str);
EXPECT_EQ(2u, with_additional2.additional_properties.size());
EXPECT_EQ(vals1, with_additional2.additional_properties["key1"]);
......
......@@ -9,12 +9,12 @@
#include "base/values.h"
#include "testing/gtest/include/gtest/gtest.h"
using namespace test::api::simple_api;
namespace simple_api = test::api::simple_api;
namespace {
static std::unique_ptr<base::DictionaryValue> CreateTestTypeDictionary() {
std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue());
auto value = std::make_unique<base::DictionaryValue>();
value->SetKey("number", base::Value(1.1));
value->SetKey("integer", base::Value(4));
value->SetKey("string", base::Value("bling"));
......@@ -26,51 +26,51 @@ static std::unique_ptr<base::DictionaryValue> CreateTestTypeDictionary() {
TEST(JsonSchemaCompilerSimpleTest, IncrementIntegerResultCreate) {
std::unique_ptr<base::ListValue> results =
IncrementInteger::Results::Create(5);
simple_api::IncrementInteger::Results::Create(5);
base::ListValue expected;
expected.AppendInteger(5);
EXPECT_TRUE(results->Equals(&expected));
}
TEST(JsonSchemaCompilerSimpleTest, IncrementIntegerParamsCreate) {
std::unique_ptr<base::ListValue> params_value(new base::ListValue());
auto params_value = std::make_unique<base::ListValue>();
params_value->AppendInteger(6);
std::unique_ptr<IncrementInteger::Params> params(
IncrementInteger::Params::Create(*params_value));
std::unique_ptr<simple_api::IncrementInteger::Params> params(
simple_api::IncrementInteger::Params::Create(*params_value));
EXPECT_TRUE(params.get());
EXPECT_EQ(6, params->num);
}
TEST(JsonSchemaCompilerSimpleTest, NumberOfParams) {
{
std::unique_ptr<base::ListValue> params_value(new base::ListValue());
auto params_value = std::make_unique<base::ListValue>();
params_value->AppendString("text");
params_value->AppendString("text");
std::unique_ptr<OptionalString::Params> params(
OptionalString::Params::Create(*params_value));
std::unique_ptr<simple_api::OptionalString::Params> params(
simple_api::OptionalString::Params::Create(*params_value));
EXPECT_FALSE(params.get());
}
{
std::unique_ptr<base::ListValue> params_value(new base::ListValue());
std::unique_ptr<IncrementInteger::Params> params(
IncrementInteger::Params::Create(*params_value));
auto params_value = std::make_unique<base::ListValue>();
std::unique_ptr<simple_api::IncrementInteger::Params> params(
simple_api::IncrementInteger::Params::Create(*params_value));
EXPECT_FALSE(params.get());
}
}
TEST(JsonSchemaCompilerSimpleTest, OptionalStringParamsCreate) {
{
std::unique_ptr<base::ListValue> params_value(new base::ListValue());
std::unique_ptr<OptionalString::Params> params(
OptionalString::Params::Create(*params_value));
auto params_value = std::make_unique<base::ListValue>();
std::unique_ptr<simple_api::OptionalString::Params> params(
simple_api::OptionalString::Params::Create(*params_value));
EXPECT_TRUE(params.get());
EXPECT_FALSE(params->str.get());
}
{
std::unique_ptr<base::ListValue> params_value(new base::ListValue());
auto params_value = std::make_unique<base::ListValue>();
params_value->AppendString("asdf");
std::unique_ptr<OptionalString::Params> params(
OptionalString::Params::Create(*params_value));
std::unique_ptr<simple_api::OptionalString::Params> params(
simple_api::OptionalString::Params::Create(*params_value));
EXPECT_TRUE(params.get());
EXPECT_TRUE(params->str.get());
EXPECT_EQ("asdf", *params->str);
......@@ -79,10 +79,10 @@ TEST(JsonSchemaCompilerSimpleTest, OptionalStringParamsCreate) {
TEST(JsonSchemaCompilerSimpleTest, OptionalParamsTakingNull) {
{
std::unique_ptr<base::ListValue> params_value(new base::ListValue());
auto params_value = std::make_unique<base::ListValue>();
params_value->Append(std::make_unique<base::Value>());
std::unique_ptr<OptionalString::Params> params(
OptionalString::Params::Create(*params_value));
std::unique_ptr<simple_api::OptionalString::Params> params(
simple_api::OptionalString::Params::Create(*params_value));
EXPECT_TRUE(params.get());
EXPECT_FALSE(params->str.get());
}
......@@ -90,21 +90,21 @@ TEST(JsonSchemaCompilerSimpleTest, OptionalParamsTakingNull) {
TEST(JsonSchemaCompilerSimpleTest, OptionalStringParamsWrongType) {
{
std::unique_ptr<base::ListValue> params_value(new base::ListValue());
auto params_value = std::make_unique<base::ListValue>();
params_value->AppendInteger(5);
std::unique_ptr<OptionalString::Params> params(
OptionalString::Params::Create(*params_value));
std::unique_ptr<simple_api::OptionalString::Params> params(
simple_api::OptionalString::Params::Create(*params_value));
EXPECT_FALSE(params.get());
}
}
TEST(JsonSchemaCompilerSimpleTest, OptionalBeforeRequired) {
{
std::unique_ptr<base::ListValue> params_value(new base::ListValue());
auto params_value = std::make_unique<base::ListValue>();
params_value->Append(std::make_unique<base::Value>());
params_value->AppendString("asdf");
std::unique_ptr<OptionalBeforeRequired::Params> params(
OptionalBeforeRequired::Params::Create(*params_value));
std::unique_ptr<simple_api::OptionalBeforeRequired::Params> params(
simple_api::OptionalBeforeRequired::Params::Create(*params_value));
EXPECT_TRUE(params.get());
EXPECT_FALSE(params->first.get());
EXPECT_EQ("asdf", params->second);
......@@ -112,16 +112,17 @@ TEST(JsonSchemaCompilerSimpleTest, OptionalBeforeRequired) {
}
TEST(JsonSchemaCompilerSimpleTest, NoParamsResultCreate) {
std::unique_ptr<base::ListValue> results = OptionalString::Results::Create();
std::unique_ptr<base::ListValue> results =
simple_api::OptionalString::Results::Create();
base::ListValue expected;
EXPECT_TRUE(results->Equals(&expected));
}
TEST(JsonSchemaCompilerSimpleTest, TestTypePopulate) {
{
std::unique_ptr<TestType> test_type(new TestType());
auto test_type = std::make_unique<simple_api::TestType>();
std::unique_ptr<base::DictionaryValue> value = CreateTestTypeDictionary();
EXPECT_TRUE(TestType::Populate(*value, test_type.get()));
EXPECT_TRUE(simple_api::TestType::Populate(*value, test_type.get()));
EXPECT_EQ("bling", test_type->string);
EXPECT_EQ(1.1, test_type->number);
EXPECT_EQ(4, test_type->integer);
......@@ -129,20 +130,20 @@ TEST(JsonSchemaCompilerSimpleTest, TestTypePopulate) {
EXPECT_TRUE(value->Equals(test_type->ToValue().get()));
}
{
std::unique_ptr<TestType> test_type(new TestType());
auto test_type = std::make_unique<simple_api::TestType>();
std::unique_ptr<base::DictionaryValue> value = CreateTestTypeDictionary();
value->Remove("number", NULL);
EXPECT_FALSE(TestType::Populate(*value, test_type.get()));
EXPECT_FALSE(simple_api::TestType::Populate(*value, test_type.get()));
}
}
TEST(JsonSchemaCompilerSimpleTest, GetTestType) {
{
std::unique_ptr<base::DictionaryValue> value = CreateTestTypeDictionary();
std::unique_ptr<TestType> test_type(new TestType());
EXPECT_TRUE(TestType::Populate(*value, test_type.get()));
auto test_type = std::make_unique<simple_api::TestType>();
EXPECT_TRUE(simple_api::TestType::Populate(*value, test_type.get()));
std::unique_ptr<base::ListValue> results =
GetTestType::Results::Create(*test_type);
simple_api::GetTestType::Results::Create(*test_type);
base::DictionaryValue* result = NULL;
results->GetDictionary(0, &result);
......@@ -152,7 +153,8 @@ TEST(JsonSchemaCompilerSimpleTest, GetTestType) {
TEST(JsonSchemaCompilerSimpleTest, OnIntegerFiredCreate) {
{
std::unique_ptr<base::ListValue> results(OnIntegerFired::Create(5));
std::unique_ptr<base::ListValue> results(
simple_api::OnIntegerFired::Create(5));
base::ListValue expected;
expected.AppendInteger(5);
EXPECT_TRUE(results->Equals(&expected));
......@@ -161,7 +163,8 @@ TEST(JsonSchemaCompilerSimpleTest, OnIntegerFiredCreate) {
TEST(JsonSchemaCompilerSimpleTest, OnStringFiredCreate) {
{
std::unique_ptr<base::ListValue> results(OnStringFired::Create("yo dawg"));
std::unique_ptr<base::ListValue> results(
simple_api::OnStringFired::Create("yo dawg"));
base::ListValue expected;
expected.AppendString("yo dawg");
EXPECT_TRUE(results->Equals(&expected));
......@@ -170,7 +173,7 @@ TEST(JsonSchemaCompilerSimpleTest, OnStringFiredCreate) {
TEST(JsonSchemaCompilerSimpleTest, OnTestTypeFiredCreate) {
{
TestType some_test_type;
simple_api::TestType some_test_type;
std::unique_ptr<base::DictionaryValue> expected =
CreateTestTypeDictionary();
ASSERT_TRUE(expected->GetDouble("number", &some_test_type.number));
......@@ -179,7 +182,7 @@ TEST(JsonSchemaCompilerSimpleTest, OnTestTypeFiredCreate) {
ASSERT_TRUE(expected->GetBoolean("boolean", &some_test_type.boolean));
std::unique_ptr<base::ListValue> results(
OnTestTypeFired::Create(some_test_type));
simple_api::OnTestTypeFired::Create(some_test_type));
base::DictionaryValue* result = NULL;
results->GetDictionary(0, &result);
EXPECT_TRUE(result->Equals(expected.get()));
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment