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 @@ ...@@ -9,44 +9,41 @@
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
using namespace test::api::additional_properties; namespace ap = test::api::additional_properties;
TEST(JsonSchemaCompilerAdditionalPropertiesTest, TEST(JsonSchemaCompilerAdditionalPropertiesTest,
AdditionalPropertiesTypePopulate) { 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->AppendString("asdf");
list_value->AppendInteger(4); list_value->AppendInteger(4);
std::unique_ptr<base::DictionaryValue> type_value( auto type_value = std::make_unique<base::DictionaryValue>();
new base::DictionaryValue());
type_value->SetString("string", "value"); type_value->SetString("string", "value");
type_value->SetInteger("other", 9); type_value->SetInteger("other", 9);
type_value->Set("another", std::move(list_value)); type_value->Set("another", std::move(list_value));
std::unique_ptr<AdditionalPropertiesType> type( auto type = std::make_unique<ap::AdditionalPropertiesType>();
new AdditionalPropertiesType()); ASSERT_TRUE(
ASSERT_TRUE(AdditionalPropertiesType::Populate(*type_value, type.get())); ap::AdditionalPropertiesType::Populate(*type_value, type.get()));
EXPECT_TRUE(type->additional_properties.Equals(type_value.get())); EXPECT_TRUE(type->additional_properties.Equals(type_value.get()));
} }
{ {
std::unique_ptr<base::DictionaryValue> type_value( auto type_value = std::make_unique<base::DictionaryValue>();
new base::DictionaryValue());
type_value->SetInteger("string", 3); type_value->SetInteger("string", 3);
std::unique_ptr<AdditionalPropertiesType> type( auto type = std::make_unique<ap::AdditionalPropertiesType>();
new AdditionalPropertiesType()); EXPECT_FALSE(
EXPECT_FALSE(AdditionalPropertiesType::Populate(*type_value, type.get())); ap::AdditionalPropertiesType::Populate(*type_value, type.get()));
} }
} }
TEST(JsonSchemaCompilerAdditionalPropertiesTest, TEST(JsonSchemaCompilerAdditionalPropertiesTest,
AdditionalPropertiesParamsCreate) { AdditionalPropertiesParamsCreate) {
std::unique_ptr<base::DictionaryValue> param_object_value( auto param_object_value = std::make_unique<base::DictionaryValue>();
new base::DictionaryValue());
param_object_value->SetString("str", "a"); param_object_value->SetString("str", "a");
param_object_value->SetInteger("num", 1); 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()); params_value->Append(param_object_value->CreateDeepCopy());
std::unique_ptr<AdditionalProperties::Params> params( std::unique_ptr<ap::AdditionalProperties::Params> params(
AdditionalProperties::Params::Create(*params_value)); ap::AdditionalProperties::Params::Create(*params_value));
EXPECT_TRUE(params.get()); EXPECT_TRUE(params.get());
EXPECT_TRUE(params->param_object.additional_properties.Equals( EXPECT_TRUE(params->param_object.additional_properties.Equals(
param_object_value.get())); param_object_value.get()));
...@@ -54,18 +51,18 @@ TEST(JsonSchemaCompilerAdditionalPropertiesTest, ...@@ -54,18 +51,18 @@ TEST(JsonSchemaCompilerAdditionalPropertiesTest,
TEST(JsonSchemaCompilerAdditionalPropertiesTest, TEST(JsonSchemaCompilerAdditionalPropertiesTest,
ReturnAdditionalPropertiesResultCreate) { ReturnAdditionalPropertiesResultCreate) {
ReturnAdditionalProperties::Results::ResultObject result_object; ap::ReturnAdditionalProperties::Results::ResultObject result_object;
result_object.integer = 5; result_object.integer = 5;
result_object.additional_properties["key"] = "value"; result_object.additional_properties["key"] = "value";
base::ListValue expected; base::ListValue expected;
{ {
std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); auto dict = std::make_unique<base::DictionaryValue>();
dict->SetInteger("integer", 5); dict->SetInteger("integer", 5);
dict->SetString("key", "value"); dict->SetString("key", "value");
expected.Append(std::move(dict)); expected.Append(std::move(dict));
} }
EXPECT_EQ(expected, EXPECT_EQ(expected,
*ReturnAdditionalProperties::Results::Create(result_object)); *ap::ReturnAdditionalProperties::Results::Create(result_object));
} }
...@@ -5,24 +5,20 @@ ...@@ -5,24 +5,20 @@
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
#include "tools/json_schema_compiler/test/any.h" #include "tools/json_schema_compiler/test/any.h"
using namespace test::api::any;
TEST(JsonSchemaCompilerAnyTest, AnyTypePopulate) { TEST(JsonSchemaCompilerAnyTest, AnyTypePopulate) {
{ {
AnyType any_type; test::api::any::AnyType any_type;
std::unique_ptr<base::DictionaryValue> any_type_value( auto any_type_value = std::make_unique<base::DictionaryValue>();
new base::DictionaryValue());
any_type_value->SetString("any", "value"); 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()); std::unique_ptr<base::Value> any_type_to_value(any_type.ToValue());
EXPECT_TRUE(any_type_value->Equals(any_type_to_value.get())); EXPECT_TRUE(any_type_value->Equals(any_type_to_value.get()));
} }
{ {
AnyType any_type; test::api::any::AnyType any_type;
std::unique_ptr<base::DictionaryValue> any_type_value( auto any_type_value = std::make_unique<base::DictionaryValue>();
new base::DictionaryValue());
any_type_value->SetInteger("any", 5); 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()); std::unique_ptr<base::Value> any_type_to_value(any_type.ToValue());
EXPECT_TRUE(any_type_value->Equals(any_type_to_value.get())); EXPECT_TRUE(any_type_value->Equals(any_type_to_value.get()));
} }
...@@ -30,28 +26,28 @@ TEST(JsonSchemaCompilerAnyTest, AnyTypePopulate) { ...@@ -30,28 +26,28 @@ TEST(JsonSchemaCompilerAnyTest, AnyTypePopulate) {
TEST(JsonSchemaCompilerAnyTest, OptionalAnyParamsCreate) { TEST(JsonSchemaCompilerAnyTest, OptionalAnyParamsCreate) {
{ {
std::unique_ptr<base::ListValue> params_value(new base::ListValue()); auto params_value = std::make_unique<base::ListValue>();
std::unique_ptr<OptionalAny::Params> params( std::unique_ptr<test::api::any::OptionalAny::Params> params(
OptionalAny::Params::Create(*params_value)); test::api::any::OptionalAny::Params::Create(*params_value));
EXPECT_TRUE(params.get()); EXPECT_TRUE(params.get());
EXPECT_FALSE(params->any_name.get()); EXPECT_FALSE(params->any_name.get());
} }
{ {
std::unique_ptr<base::ListValue> params_value(new base::ListValue()); auto params_value = std::make_unique<base::ListValue>();
std::unique_ptr<base::Value> param(new base::Value("asdf")); auto param = std::make_unique<base::Value>("asdf");
params_value->Append(param->CreateDeepCopy()); params_value->Append(param->CreateDeepCopy());
std::unique_ptr<OptionalAny::Params> params( std::unique_ptr<test::api::any::OptionalAny::Params> params(
OptionalAny::Params::Create(*params_value)); test::api::any::OptionalAny::Params::Create(*params_value));
ASSERT_TRUE(params); ASSERT_TRUE(params);
ASSERT_TRUE(params->any_name); ASSERT_TRUE(params->any_name);
EXPECT_TRUE(params->any_name->Equals(param.get())); EXPECT_TRUE(params->any_name->Equals(param.get()));
} }
{ {
std::unique_ptr<base::ListValue> params_value(new base::ListValue()); auto params_value = std::make_unique<base::ListValue>();
std::unique_ptr<base::Value> param(new base::Value(true)); auto param = std::make_unique<base::Value>(true);
params_value->Append(param->CreateDeepCopy()); params_value->Append(param->CreateDeepCopy());
std::unique_ptr<OptionalAny::Params> params( std::unique_ptr<test::api::any::OptionalAny::Params> params(
OptionalAny::Params::Create(*params_value)); test::api::any::OptionalAny::Params::Create(*params_value));
ASSERT_TRUE(params); ASSERT_TRUE(params);
ASSERT_TRUE(params->any_name); ASSERT_TRUE(params->any_name);
EXPECT_TRUE(params->any_name->Equals(param.get())); EXPECT_TRUE(params->any_name->Equals(param.get()));
......
...@@ -9,16 +9,13 @@ ...@@ -9,16 +9,13 @@
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
using namespace test::api::callbacks;
TEST(JsonSchemaCompilerCallbacksTest, ReturnsObjectResultCreate) { TEST(JsonSchemaCompilerCallbacksTest, ReturnsObjectResultCreate) {
ReturnsObject::Results::SomeObject some_object; test::api::callbacks::ReturnsObject::Results::SomeObject some_object;
some_object.state = ENUMERATION_FOO; some_object.state = test::api::callbacks::ENUMERATION_FOO;
std::unique_ptr<base::ListValue> results = 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( auto expected_dict = std::make_unique<base::DictionaryValue>();
new base::DictionaryValue());
expected_dict->SetString("state", "foo"); expected_dict->SetString("state", "foo");
base::ListValue expected; base::ListValue expected;
expected.Append(std::move(expected_dict)); expected.Append(std::move(expected_dict));
...@@ -26,13 +23,12 @@ TEST(JsonSchemaCompilerCallbacksTest, ReturnsObjectResultCreate) { ...@@ -26,13 +23,12 @@ TEST(JsonSchemaCompilerCallbacksTest, ReturnsObjectResultCreate) {
} }
TEST(JsonSchemaCompilerCallbacksTest, ReturnsMultipleResultCreate) { TEST(JsonSchemaCompilerCallbacksTest, ReturnsMultipleResultCreate) {
ReturnsMultiple::Results::SomeObject some_object; test::api::callbacks::ReturnsMultiple::Results::SomeObject some_object;
some_object.state = ENUMERATION_FOO; some_object.state = test::api::callbacks::ENUMERATION_FOO;
std::unique_ptr<base::ListValue> results = 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( auto expected_dict = std::make_unique<base::DictionaryValue>();
new base::DictionaryValue());
expected_dict->SetString("state", "foo"); expected_dict->SetString("state", "foo");
base::ListValue expected; base::ListValue expected;
expected.AppendInteger(5); expected.AppendInteger(5);
......
...@@ -15,7 +15,9 @@ ...@@ -15,7 +15,9 @@
namespace { 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::Dictionary;
using json_schema_compiler::test_util::List; using json_schema_compiler::test_util::List;
using json_schema_compiler::test_util::ReadJson; using json_schema_compiler::test_util::ReadJson;
...@@ -47,8 +49,8 @@ TEST(JsonSchemaCompilerChoicesTest, TakesIntegersParamsCreate) { ...@@ -47,8 +49,8 @@ TEST(JsonSchemaCompilerChoicesTest, TakesIntegersParamsCreate) {
TEST(JsonSchemaCompilerChoicesTest, ObjectWithChoicesParamsCreate) { TEST(JsonSchemaCompilerChoicesTest, ObjectWithChoicesParamsCreate) {
{ {
std::unique_ptr<ObjectWithChoices::Params> params( std::unique_ptr<choices::ObjectWithChoices::Params> params(
ObjectWithChoices::Params::Create(*List( choices::ObjectWithChoices::Params::Create(*List(
Dictionary("strings", std::make_unique<base::Value>("asdf"))))); Dictionary("strings", std::make_unique<base::Value>("asdf")))));
ASSERT_TRUE(params); ASSERT_TRUE(params);
EXPECT_FALSE(params->string_info.strings.as_strings); EXPECT_FALSE(params->string_info.strings.as_strings);
...@@ -56,8 +58,8 @@ TEST(JsonSchemaCompilerChoicesTest, ObjectWithChoicesParamsCreate) { ...@@ -56,8 +58,8 @@ TEST(JsonSchemaCompilerChoicesTest, ObjectWithChoicesParamsCreate) {
EXPECT_FALSE(params->string_info.integers); EXPECT_FALSE(params->string_info.integers);
} }
{ {
std::unique_ptr<ObjectWithChoices::Params> params( std::unique_ptr<choices::ObjectWithChoices::Params> params(
ObjectWithChoices::Params::Create( choices::ObjectWithChoices::Params::Create(
*List(Dictionary("strings", std::make_unique<base::Value>("asdf"), *List(Dictionary("strings", std::make_unique<base::Value>("asdf"),
"integers", std::make_unique<base::Value>(6))))); "integers", std::make_unique<base::Value>(6)))));
ASSERT_TRUE(params); ASSERT_TRUE(params);
...@@ -74,34 +76,31 @@ TEST(JsonSchemaCompilerChoicesTest, ObjectWithChoicesParamsCreate) { ...@@ -74,34 +76,31 @@ TEST(JsonSchemaCompilerChoicesTest, ObjectWithChoicesParamsCreate) {
TEST(JsonSchemaCompilerChoicesTest, ObjectWithChoicesParamsCreateFail) { TEST(JsonSchemaCompilerChoicesTest, ObjectWithChoicesParamsCreateFail) {
{ {
std::unique_ptr<base::DictionaryValue> object_param( auto object_param = std::make_unique<base::DictionaryValue>();
new base::DictionaryValue());
object_param->SetKey("strings", base::Value(5)); object_param->SetKey("strings", base::Value(5));
std::unique_ptr<base::ListValue> params_value(new base::ListValue()); std::unique_ptr<base::ListValue> params_value(new base::ListValue());
params_value->Append(std::move(object_param)); params_value->Append(std::move(object_param));
std::unique_ptr<ObjectWithChoices::Params> params( std::unique_ptr<choices::ObjectWithChoices::Params> params(
ObjectWithChoices::Params::Create(*params_value)); choices::ObjectWithChoices::Params::Create(*params_value));
EXPECT_FALSE(params.get()); EXPECT_FALSE(params.get());
} }
{ {
std::unique_ptr<base::DictionaryValue> object_param( auto object_param = std::make_unique<base::DictionaryValue>();
new base::DictionaryValue());
object_param->SetKey("strings", base::Value("asdf")); object_param->SetKey("strings", base::Value("asdf"));
object_param->SetKey("integers", base::Value("asdf")); object_param->SetKey("integers", base::Value("asdf"));
std::unique_ptr<base::ListValue> params_value(new base::ListValue()); std::unique_ptr<base::ListValue> params_value(new base::ListValue());
params_value->Append(std::move(object_param)); params_value->Append(std::move(object_param));
std::unique_ptr<ObjectWithChoices::Params> params( std::unique_ptr<choices::ObjectWithChoices::Params> params(
ObjectWithChoices::Params::Create(*params_value)); choices::ObjectWithChoices::Params::Create(*params_value));
EXPECT_FALSE(params.get()); EXPECT_FALSE(params.get());
} }
{ {
std::unique_ptr<base::DictionaryValue> object_param( auto object_param = std::make_unique<base::DictionaryValue>();
new base::DictionaryValue());
object_param->SetKey("integers", base::Value(6)); object_param->SetKey("integers", base::Value(6));
std::unique_ptr<base::ListValue> params_value(new base::ListValue()); std::unique_ptr<base::ListValue> params_value(new base::ListValue());
params_value->Append(std::move(object_param)); params_value->Append(std::move(object_param));
std::unique_ptr<ObjectWithChoices::Params> params( std::unique_ptr<choices::ObjectWithChoices::Params> params(
ObjectWithChoices::Params::Create(*params_value)); choices::ObjectWithChoices::Params::Create(*params_value));
EXPECT_FALSE(params.get()); EXPECT_FALSE(params.get());
} }
} }
...@@ -119,8 +118,8 @@ TEST(JsonSchemaCompilerChoicesTest, PopulateChoiceType) { ...@@ -119,8 +118,8 @@ TEST(JsonSchemaCompilerChoicesTest, PopulateChoiceType) {
value.SetInteger("integers", 4); value.SetInteger("integers", 4);
value.Set("strings", std::move(strings_value)); value.Set("strings", std::move(strings_value));
ChoiceType out; choices::ChoiceType out;
ASSERT_TRUE(ChoiceType::Populate(value, &out)); ASSERT_TRUE(choices::ChoiceType::Populate(value, &out));
ASSERT_TRUE(out.integers.as_integer.get()); ASSERT_TRUE(out.integers.as_integer.get());
EXPECT_FALSE(out.integers.as_integers.get()); EXPECT_FALSE(out.integers.as_integers.get());
EXPECT_EQ(4, *out.integers.as_integer); EXPECT_EQ(4, *out.integers.as_integer);
...@@ -140,16 +139,16 @@ TEST(JsonSchemaCompilerChoicesTest, ChoiceTypeToValue) { ...@@ -140,16 +139,16 @@ TEST(JsonSchemaCompilerChoicesTest, ChoiceTypeToValue) {
value.SetInteger("integers", 5); value.SetInteger("integers", 5);
value.Set("strings", std::move(strings_value)); value.Set("strings", std::move(strings_value));
ChoiceType out; choices::ChoiceType out;
ASSERT_TRUE(ChoiceType::Populate(value, &out)); ASSERT_TRUE(choices::ChoiceType::Populate(value, &out));
EXPECT_TRUE(value.Equals(out.ToValue().get())); EXPECT_TRUE(value.Equals(out.ToValue().get()));
} }
TEST(JsonSchemaCompilerChoicesTest, ReturnChoices) { TEST(JsonSchemaCompilerChoicesTest, ReturnChoices) {
{ {
ReturnChoices::Results::Result results; choices::ReturnChoices::Results::Result results;
results.as_integers.reset(new std::vector<int>(Vector(1, 2))); results.as_integers = std::make_unique<std::vector<int>>(Vector(1, 2));
std::unique_ptr<base::Value> results_value = results.ToValue(); std::unique_ptr<base::Value> results_value = results.ToValue();
ASSERT_TRUE(results_value); ASSERT_TRUE(results_value);
...@@ -161,8 +160,8 @@ TEST(JsonSchemaCompilerChoicesTest, ReturnChoices) { ...@@ -161,8 +160,8 @@ TEST(JsonSchemaCompilerChoicesTest, ReturnChoices) {
EXPECT_TRUE(expected.Equals(results_value.get())); EXPECT_TRUE(expected.Equals(results_value.get()));
} }
{ {
ReturnChoices::Results::Result results; choices::ReturnChoices::Results::Result results;
results.as_integer.reset(new int(5)); results.as_integer = std::make_unique<int>(5);
std::unique_ptr<base::Value> results_value = results.ToValue(); std::unique_ptr<base::Value> results_value = results.ToValue();
ASSERT_TRUE(results_value); ASSERT_TRUE(results_value);
...@@ -253,7 +252,7 @@ TEST(JsonSchemaCompilerChoicesTest, NestedChoices) { ...@@ -253,7 +252,7 @@ TEST(JsonSchemaCompilerChoicesTest, NestedChoices) {
ASSERT_TRUE(obj->as_choice2->as_choice_type); ASSERT_TRUE(obj->as_choice2->as_choice_type);
EXPECT_FALSE(obj->as_choice2->as_choice_types); 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); ASSERT_TRUE(choice_type->integers.as_integers);
EXPECT_FALSE(choice_type->integers.as_integer); EXPECT_FALSE(choice_type->integers.as_integer);
EXPECT_EQ(Vector(1, 2), *choice_type->integers.as_integers); EXPECT_EQ(Vector(1, 2), *choice_type->integers.as_integers);
...@@ -282,12 +281,8 @@ TEST(JsonSchemaCompilerChoicesTest, NestedChoices) { ...@@ -282,12 +281,8 @@ TEST(JsonSchemaCompilerChoicesTest, NestedChoices) {
EXPECT_FALSE(obj->as_choice2->as_double); EXPECT_FALSE(obj->as_choice2->as_double);
EXPECT_FALSE(obj->as_choice2->as_choice_type); EXPECT_FALSE(obj->as_choice2->as_choice_type);
ASSERT_TRUE(obj->as_choice2->as_choice_types); ASSERT_TRUE(obj->as_choice2->as_choice_types);
{ // Bleh too much effort to test everything.
std::vector<ChoiceType>* choice_types = ASSERT_EQ(2u, obj->as_choice2->as_choice_types->size());
obj->as_choice2->as_choice_types.get();
// Bleh too much effort to test everything.
ASSERT_EQ(2u, choice_types->size());
}
EXPECT_EQ(*value, *obj->ToValue()); EXPECT_EQ(*value, *obj->ToValue());
} }
......
...@@ -11,7 +11,8 @@ ...@@ -11,7 +11,8 @@
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
#include "tools/json_schema_compiler/test/simple_api.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 { namespace {
...@@ -51,7 +52,7 @@ TEST(JsonSchemaCompilerCrossrefTest, CrossrefTypePopulateAndToValue) { ...@@ -51,7 +52,7 @@ TEST(JsonSchemaCompilerCrossrefTest, CrossrefTypePopulateAndToValue) {
} }
TEST(JsonSchemaCompilerCrossrefTest, TestTypeOptionalParamCreate) { 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()); params_value->Append(CreateTestTypeValue());
std::unique_ptr<crossref::TestTypeOptionalParam::Params> params( std::unique_ptr<crossref::TestTypeOptionalParam::Params> params(
crossref::TestTypeOptionalParam::Params::Create(*params_value)); crossref::TestTypeOptionalParam::Params::Create(*params_value));
...@@ -62,7 +63,7 @@ TEST(JsonSchemaCompilerCrossrefTest, TestTypeOptionalParamCreate) { ...@@ -62,7 +63,7 @@ TEST(JsonSchemaCompilerCrossrefTest, TestTypeOptionalParamCreate) {
} }
TEST(JsonSchemaCompilerCrossrefTest, TestTypeOptionalParamFail) { 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 = std::unique_ptr<base::DictionaryValue> test_type_value =
CreateTestTypeValue(); CreateTestTypeValue();
test_type_value->RemoveWithoutPathExpansion("number", NULL); test_type_value->RemoveWithoutPathExpansion("number", NULL);
...@@ -74,7 +75,7 @@ TEST(JsonSchemaCompilerCrossrefTest, TestTypeOptionalParamFail) { ...@@ -74,7 +75,7 @@ TEST(JsonSchemaCompilerCrossrefTest, TestTypeOptionalParamFail) {
TEST(JsonSchemaCompilerCrossrefTest, GetTestType) { TEST(JsonSchemaCompilerCrossrefTest, GetTestType) {
std::unique_ptr<base::DictionaryValue> value = CreateTestTypeValue(); 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())); EXPECT_TRUE(simple_api::TestType::Populate(*value, test_type.get()));
std::unique_ptr<base::ListValue> results = std::unique_ptr<base::ListValue> results =
......
...@@ -9,7 +9,8 @@ ...@@ -9,7 +9,8 @@
#include "base/values.h" #include "base/values.h"
#include "testing/gtest/include/gtest/gtest.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) { TEST(JsonSchemaCompilerFunctionsAsParametersTest, PopulateRequiredFunction) {
// The expectation is that if any value is set for the function, then // The expectation is that if any value is set for the function, then
......
...@@ -9,41 +9,40 @@ ...@@ -9,41 +9,40 @@
#include "base/values.h" #include "base/values.h"
#include "testing/gtest/include/gtest/gtest.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) { TEST(JsonSchemaCompilerFunctionsOnTypesTest, StorageAreaGetParamsCreate) {
{ {
std::unique_ptr<base::ListValue> params_value(new base::ListValue()); auto params_value = std::make_unique<base::ListValue>();
std::unique_ptr<StorageArea::Get::Params> params( std::unique_ptr<functions_on_types::StorageArea::Get::Params> params(
StorageArea::Get::Params::Create(*params_value)); functions_on_types::StorageArea::Get::Params::Create(*params_value));
ASSERT_TRUE(params); ASSERT_TRUE(params);
EXPECT_FALSE(params->keys); 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); params_value->AppendInteger(9);
std::unique_ptr<StorageArea::Get::Params> params( std::unique_ptr<functions_on_types::StorageArea::Get::Params> params(
StorageArea::Get::Params::Create(*params_value)); functions_on_types::StorageArea::Get::Params::Create(*params_value));
EXPECT_FALSE(params); 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"); params_value->AppendString("test");
std::unique_ptr<StorageArea::Get::Params> params( std::unique_ptr<functions_on_types::StorageArea::Get::Params> params(
StorageArea::Get::Params::Create(*params_value)); functions_on_types::StorageArea::Get::Params::Create(*params_value));
ASSERT_TRUE(params); ASSERT_TRUE(params);
ASSERT_TRUE(params->keys); ASSERT_TRUE(params->keys);
EXPECT_EQ("test", *params->keys->as_string); EXPECT_EQ("test", *params->keys->as_string);
} }
{ {
std::unique_ptr<base::DictionaryValue> keys_object_value( auto keys_object_value = std::make_unique<base::DictionaryValue>();
new base::DictionaryValue());
keys_object_value->SetInteger("integer", 5); keys_object_value->SetInteger("integer", 5);
keys_object_value->SetString("string", "string"); 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()); params_value->Append(keys_object_value->CreateDeepCopy());
std::unique_ptr<StorageArea::Get::Params> params( std::unique_ptr<functions_on_types::StorageArea::Get::Params> params(
StorageArea::Get::Params::Create(*params_value)); functions_on_types::StorageArea::Get::Params::Create(*params_value));
ASSERT_TRUE(params); ASSERT_TRUE(params);
ASSERT_TRUE(params->keys); ASSERT_TRUE(params->keys);
EXPECT_TRUE(keys_object_value->Equals( EXPECT_TRUE(keys_object_value->Equals(
...@@ -52,24 +51,23 @@ TEST(JsonSchemaCompilerFunctionsOnTypesTest, StorageAreaGetParamsCreate) { ...@@ -52,24 +51,23 @@ TEST(JsonSchemaCompilerFunctionsOnTypesTest, StorageAreaGetParamsCreate) {
} }
TEST(JsonSchemaCompilerFunctionsOnTypesTest, StorageAreaGetResultCreate) { 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.SetDouble("asdf", 0.1);
items.additional_properties.SetString("sdfg", "zxcv"); items.additional_properties.SetString("sdfg", "zxcv");
std::unique_ptr<base::ListValue> results = std::unique_ptr<base::ListValue> results =
StorageArea::Get::Results::Create(items); functions_on_types::StorageArea::Get::Results::Create(items);
base::DictionaryValue* item_result = NULL; base::DictionaryValue* item_result = NULL;
ASSERT_TRUE(results->GetDictionary(0, &item_result)); ASSERT_TRUE(results->GetDictionary(0, &item_result));
EXPECT_TRUE(item_result->Equals(&items.additional_properties)); EXPECT_TRUE(item_result->Equals(&items.additional_properties));
} }
TEST(JsonSchemaCompilerFunctionsOnTypesTest, ChromeSettingGetParamsCreate) { TEST(JsonSchemaCompilerFunctionsOnTypesTest, ChromeSettingGetParamsCreate) {
std::unique_ptr<base::DictionaryValue> details_value( auto details_value = std::make_unique<base::DictionaryValue>();
new base::DictionaryValue());
details_value->SetBoolean("incognito", true); 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)); params_value->Append(std::move(details_value));
std::unique_ptr<ChromeSetting::Get::Params> params( std::unique_ptr<functions_on_types::ChromeSetting::Get::Params> params(
ChromeSetting::Get::Params::Create(*params_value)); functions_on_types::ChromeSetting::Get::Params::Create(*params_value));
EXPECT_TRUE(params.get()); EXPECT_TRUE(params.get());
EXPECT_TRUE(*params->details.incognito); EXPECT_TRUE(*params->details.incognito);
} }
...@@ -15,9 +15,7 @@ ...@@ -15,9 +15,7 @@
#include "tools/json_schema_compiler/test/objects_movable.h" #include "tools/json_schema_compiler/test/objects_movable.h"
#include "tools/json_schema_compiler/test/objects_movable_json.h" #include "tools/json_schema_compiler/test/objects_movable_json.h"
using namespace test::api::objects; namespace objects_movable = test::api::objects_movable;
using namespace test::api::objects_movable;
using namespace test::api::objects_movable_json;
TEST(JsonSchemaCompilerObjectsTest, ObjectParamParamsCreate) { TEST(JsonSchemaCompilerObjectsTest, ObjectParamParamsCreate) {
{ {
...@@ -31,8 +29,8 @@ TEST(JsonSchemaCompilerObjectsTest, ObjectParamParamsCreate) { ...@@ -31,8 +29,8 @@ TEST(JsonSchemaCompilerObjectsTest, ObjectParamParamsCreate) {
auto params_value = std::make_unique<base::ListValue>(); auto params_value = std::make_unique<base::ListValue>();
params_value->Append(std::move(info_value)); params_value->Append(std::move(info_value));
std::unique_ptr<ObjectParam::Params> params( std::unique_ptr<test::api::objects::ObjectParam::Params> params(
ObjectParam::Params::Create(*params_value)); test::api::objects::ObjectParam::Params::Create(*params_value));
EXPECT_TRUE(params.get()); EXPECT_TRUE(params.get());
EXPECT_EQ((size_t) 2, params->info.strings.size()); EXPECT_EQ((size_t) 2, params->info.strings.size());
EXPECT_EQ("one", params->info.strings[0]); EXPECT_EQ("one", params->info.strings[0]);
...@@ -50,17 +48,17 @@ TEST(JsonSchemaCompilerObjectsTest, ObjectParamParamsCreate) { ...@@ -50,17 +48,17 @@ TEST(JsonSchemaCompilerObjectsTest, ObjectParamParamsCreate) {
auto params_value = std::make_unique<base::ListValue>(); auto params_value = std::make_unique<base::ListValue>();
params_value->Append(std::move(info_value)); params_value->Append(std::move(info_value));
std::unique_ptr<ObjectParam::Params> params( std::unique_ptr<test::api::objects::ObjectParam::Params> params(
ObjectParam::Params::Create(*params_value)); test::api::objects::ObjectParam::Params::Create(*params_value));
EXPECT_FALSE(params.get()); EXPECT_FALSE(params.get());
} }
} }
TEST(JsonSchemaCompilerObjectsTest, ReturnsObjectResultCreate) { TEST(JsonSchemaCompilerObjectsTest, ReturnsObjectResultCreate) {
ReturnsObject::Results::Info info; test::api::objects::ReturnsObject::Results::Info info;
info.state = FIRST_STATE_FOO; info.state = test::api::objects::FIRST_STATE_FOO;
std::unique_ptr<base::ListValue> results = std::unique_ptr<base::ListValue> results =
ReturnsObject::Results::Create(info); test::api::objects::ReturnsObject::Results::Create(info);
base::DictionaryValue expected; base::DictionaryValue expected;
expected.SetString("state", "foo"); expected.SetString("state", "foo");
...@@ -70,9 +68,10 @@ TEST(JsonSchemaCompilerObjectsTest, ReturnsObjectResultCreate) { ...@@ -70,9 +68,10 @@ TEST(JsonSchemaCompilerObjectsTest, ReturnsObjectResultCreate) {
} }
TEST(JsonSchemaCompilerObjectsTest, OnObjectFiredCreate) { TEST(JsonSchemaCompilerObjectsTest, OnObjectFiredCreate) {
OnObjectFired::SomeObject object; test::api::objects::OnObjectFired::SomeObject object;
object.state = FIRST_STATE_BAR; object.state = test::api::objects::FIRST_STATE_BAR;
std::unique_ptr<base::ListValue> results(OnObjectFired::Create(object)); std::unique_ptr<base::ListValue> results(
test::api::objects::OnObjectFired::Create(object));
base::DictionaryValue expected; base::DictionaryValue expected;
expected.SetString("state", "bar"); expected.SetString("state", "bar");
...@@ -81,36 +80,36 @@ TEST(JsonSchemaCompilerObjectsTest, OnObjectFiredCreate) { ...@@ -81,36 +80,36 @@ TEST(JsonSchemaCompilerObjectsTest, OnObjectFiredCreate) {
ASSERT_TRUE(result->Equals(&expected)); ASSERT_TRUE(result->Equals(&expected));
} }
TEST(JsonSchemaCompilerMovableObjectsTest, MovableObjectsTest) { TEST(JsonSchemaCompilerMovableObjectsTest, MovableObjectsTest) {
std::vector<MovablePod> pods; std::vector<objects_movable::MovablePod> pods;
{ {
MovablePod pod; objects_movable::MovablePod pod;
pod.foo = FOO_BAR; pod.foo = objects_movable::FOO_BAR;
pod.str = "str1"; pod.str = "str1";
pod.num = 42; pod.num = 42;
pod.b = true; pod.b = true;
pods.push_back(std::move(pod)); pods.push_back(std::move(pod));
} }
{ {
MovablePod pod; objects_movable::MovablePod pod;
pod.foo = FOO_BAZ; pod.foo = objects_movable::FOO_BAZ;
pod.str = "str2"; pod.str = "str2";
pod.num = 45; pod.num = 45;
pod.b = false; pod.b = false;
pods.push_back(std::move(pod)); pods.push_back(std::move(pod));
} }
MovableParent parent; objects_movable::MovableParent parent;
parent.pods = std::move(pods); parent.pods = std::move(pods);
parent.strs.push_back("pstr"); parent.strs.push_back("pstr");
parent.blob.additional_properties.SetString("key", "val"); 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()); 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("str1", parent2.pods[0].str);
EXPECT_EQ(42, parent2.pods[0].num); EXPECT_EQ(42, parent2.pods[0].num);
EXPECT_TRUE(parent2.pods[0].b); 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("str2", parent2.pods[1].str);
EXPECT_EQ(45, parent2.pods[1].num); EXPECT_EQ(45, parent2.pods[1].num);
EXPECT_FALSE(parent2.pods[1].b); EXPECT_FALSE(parent2.pods[1].b);
...@@ -125,14 +124,14 @@ TEST(JsonSchemaCompilerMovableObjectsTest, MovableObjectsTest) { ...@@ -125,14 +124,14 @@ TEST(JsonSchemaCompilerMovableObjectsTest, MovableObjectsTest) {
EXPECT_EQ("val", blob_string); EXPECT_EQ("val", blob_string);
{ {
MovableParent parent_with_pod_choice; objects_movable::MovableParent parent_with_pod_choice;
MovablePod pod; objects_movable::MovablePod pod;
pod.foo = FOO_BAZ; pod.foo = objects_movable::FOO_BAZ;
pod.str = "str"; pod.str = "str";
pod.num = 10; pod.num = 10;
pod.b = false; pod.b = false;
parent_with_pod_choice.choice.as_movable_pod.reset( parent_with_pod_choice.choice.as_movable_pod =
new MovablePod(std::move(pod))); std::make_unique<objects_movable::MovablePod>(std::move(pod));
parent2 = std::move(parent_with_pod_choice); parent2 = std::move(parent_with_pod_choice);
} }
EXPECT_TRUE(parent2.pods.empty()); EXPECT_TRUE(parent2.pods.empty());
...@@ -140,12 +139,12 @@ TEST(JsonSchemaCompilerMovableObjectsTest, MovableObjectsTest) { ...@@ -140,12 +139,12 @@ TEST(JsonSchemaCompilerMovableObjectsTest, MovableObjectsTest) {
EXPECT_TRUE(parent2.blob.additional_properties.empty()); EXPECT_TRUE(parent2.blob.additional_properties.empty());
EXPECT_FALSE(parent2.choice.as_string.get()); EXPECT_FALSE(parent2.choice.as_string.get());
ASSERT_TRUE(parent2.choice.as_movable_pod.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("str", parent2.choice.as_movable_pod->str);
EXPECT_EQ(10, parent2.choice.as_movable_pod->num); EXPECT_EQ(10, parent2.choice.as_movable_pod->num);
EXPECT_FALSE(parent2.choice.as_movable_pod->b); EXPECT_FALSE(parent2.choice.as_movable_pod->b);
MovableWithAdditional with_additional; test::api::objects_movable_json::MovableWithAdditional with_additional;
with_additional.str = "str"; with_additional.str = "str";
std::vector<std::string> vals1; std::vector<std::string> vals1;
vals1.push_back("vals1a"); vals1.push_back("vals1a");
...@@ -156,7 +155,8 @@ TEST(JsonSchemaCompilerMovableObjectsTest, MovableObjectsTest) { ...@@ -156,7 +155,8 @@ TEST(JsonSchemaCompilerMovableObjectsTest, MovableObjectsTest) {
vals2.push_back("vals2b"); vals2.push_back("vals2b");
with_additional.additional_properties["key2"] = vals2; 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("str", with_additional2.str);
EXPECT_EQ(2u, with_additional2.additional_properties.size()); EXPECT_EQ(2u, with_additional2.additional_properties.size());
EXPECT_EQ(vals1, with_additional2.additional_properties["key1"]); EXPECT_EQ(vals1, with_additional2.additional_properties["key1"]);
......
...@@ -9,12 +9,12 @@ ...@@ -9,12 +9,12 @@
#include "base/values.h" #include "base/values.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
using namespace test::api::simple_api; namespace simple_api = test::api::simple_api;
namespace { namespace {
static std::unique_ptr<base::DictionaryValue> CreateTestTypeDictionary() { 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("number", base::Value(1.1));
value->SetKey("integer", base::Value(4)); value->SetKey("integer", base::Value(4));
value->SetKey("string", base::Value("bling")); value->SetKey("string", base::Value("bling"));
...@@ -26,51 +26,51 @@ static std::unique_ptr<base::DictionaryValue> CreateTestTypeDictionary() { ...@@ -26,51 +26,51 @@ static std::unique_ptr<base::DictionaryValue> CreateTestTypeDictionary() {
TEST(JsonSchemaCompilerSimpleTest, IncrementIntegerResultCreate) { TEST(JsonSchemaCompilerSimpleTest, IncrementIntegerResultCreate) {
std::unique_ptr<base::ListValue> results = std::unique_ptr<base::ListValue> results =
IncrementInteger::Results::Create(5); simple_api::IncrementInteger::Results::Create(5);
base::ListValue expected; base::ListValue expected;
expected.AppendInteger(5); expected.AppendInteger(5);
EXPECT_TRUE(results->Equals(&expected)); EXPECT_TRUE(results->Equals(&expected));
} }
TEST(JsonSchemaCompilerSimpleTest, IncrementIntegerParamsCreate) { 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); params_value->AppendInteger(6);
std::unique_ptr<IncrementInteger::Params> params( std::unique_ptr<simple_api::IncrementInteger::Params> params(
IncrementInteger::Params::Create(*params_value)); simple_api::IncrementInteger::Params::Create(*params_value));
EXPECT_TRUE(params.get()); EXPECT_TRUE(params.get());
EXPECT_EQ(6, params->num); EXPECT_EQ(6, params->num);
} }
TEST(JsonSchemaCompilerSimpleTest, NumberOfParams) { 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");
params_value->AppendString("text"); params_value->AppendString("text");
std::unique_ptr<OptionalString::Params> params( std::unique_ptr<simple_api::OptionalString::Params> params(
OptionalString::Params::Create(*params_value)); simple_api::OptionalString::Params::Create(*params_value));
EXPECT_FALSE(params.get()); EXPECT_FALSE(params.get());
} }
{ {
std::unique_ptr<base::ListValue> params_value(new base::ListValue()); auto params_value = std::make_unique<base::ListValue>();
std::unique_ptr<IncrementInteger::Params> params( std::unique_ptr<simple_api::IncrementInteger::Params> params(
IncrementInteger::Params::Create(*params_value)); simple_api::IncrementInteger::Params::Create(*params_value));
EXPECT_FALSE(params.get()); EXPECT_FALSE(params.get());
} }
} }
TEST(JsonSchemaCompilerSimpleTest, OptionalStringParamsCreate) { TEST(JsonSchemaCompilerSimpleTest, OptionalStringParamsCreate) {
{ {
std::unique_ptr<base::ListValue> params_value(new base::ListValue()); auto params_value = std::make_unique<base::ListValue>();
std::unique_ptr<OptionalString::Params> params( std::unique_ptr<simple_api::OptionalString::Params> params(
OptionalString::Params::Create(*params_value)); simple_api::OptionalString::Params::Create(*params_value));
EXPECT_TRUE(params.get()); EXPECT_TRUE(params.get());
EXPECT_FALSE(params->str.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"); params_value->AppendString("asdf");
std::unique_ptr<OptionalString::Params> params( std::unique_ptr<simple_api::OptionalString::Params> params(
OptionalString::Params::Create(*params_value)); simple_api::OptionalString::Params::Create(*params_value));
EXPECT_TRUE(params.get()); EXPECT_TRUE(params.get());
EXPECT_TRUE(params->str.get()); EXPECT_TRUE(params->str.get());
EXPECT_EQ("asdf", *params->str); EXPECT_EQ("asdf", *params->str);
...@@ -79,10 +79,10 @@ TEST(JsonSchemaCompilerSimpleTest, OptionalStringParamsCreate) { ...@@ -79,10 +79,10 @@ TEST(JsonSchemaCompilerSimpleTest, OptionalStringParamsCreate) {
TEST(JsonSchemaCompilerSimpleTest, OptionalParamsTakingNull) { 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>()); params_value->Append(std::make_unique<base::Value>());
std::unique_ptr<OptionalString::Params> params( std::unique_ptr<simple_api::OptionalString::Params> params(
OptionalString::Params::Create(*params_value)); simple_api::OptionalString::Params::Create(*params_value));
EXPECT_TRUE(params.get()); EXPECT_TRUE(params.get());
EXPECT_FALSE(params->str.get()); EXPECT_FALSE(params->str.get());
} }
...@@ -90,21 +90,21 @@ TEST(JsonSchemaCompilerSimpleTest, OptionalParamsTakingNull) { ...@@ -90,21 +90,21 @@ TEST(JsonSchemaCompilerSimpleTest, OptionalParamsTakingNull) {
TEST(JsonSchemaCompilerSimpleTest, OptionalStringParamsWrongType) { 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); params_value->AppendInteger(5);
std::unique_ptr<OptionalString::Params> params( std::unique_ptr<simple_api::OptionalString::Params> params(
OptionalString::Params::Create(*params_value)); simple_api::OptionalString::Params::Create(*params_value));
EXPECT_FALSE(params.get()); EXPECT_FALSE(params.get());
} }
} }
TEST(JsonSchemaCompilerSimpleTest, OptionalBeforeRequired) { 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->Append(std::make_unique<base::Value>());
params_value->AppendString("asdf"); params_value->AppendString("asdf");
std::unique_ptr<OptionalBeforeRequired::Params> params( std::unique_ptr<simple_api::OptionalBeforeRequired::Params> params(
OptionalBeforeRequired::Params::Create(*params_value)); simple_api::OptionalBeforeRequired::Params::Create(*params_value));
EXPECT_TRUE(params.get()); EXPECT_TRUE(params.get());
EXPECT_FALSE(params->first.get()); EXPECT_FALSE(params->first.get());
EXPECT_EQ("asdf", params->second); EXPECT_EQ("asdf", params->second);
...@@ -112,16 +112,17 @@ TEST(JsonSchemaCompilerSimpleTest, OptionalBeforeRequired) { ...@@ -112,16 +112,17 @@ TEST(JsonSchemaCompilerSimpleTest, OptionalBeforeRequired) {
} }
TEST(JsonSchemaCompilerSimpleTest, NoParamsResultCreate) { 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; base::ListValue expected;
EXPECT_TRUE(results->Equals(&expected)); EXPECT_TRUE(results->Equals(&expected));
} }
TEST(JsonSchemaCompilerSimpleTest, TestTypePopulate) { 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(); 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("bling", test_type->string);
EXPECT_EQ(1.1, test_type->number); EXPECT_EQ(1.1, test_type->number);
EXPECT_EQ(4, test_type->integer); EXPECT_EQ(4, test_type->integer);
...@@ -129,20 +130,20 @@ TEST(JsonSchemaCompilerSimpleTest, TestTypePopulate) { ...@@ -129,20 +130,20 @@ TEST(JsonSchemaCompilerSimpleTest, TestTypePopulate) {
EXPECT_TRUE(value->Equals(test_type->ToValue().get())); 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(); std::unique_ptr<base::DictionaryValue> value = CreateTestTypeDictionary();
value->Remove("number", NULL); 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) { TEST(JsonSchemaCompilerSimpleTest, GetTestType) {
{ {
std::unique_ptr<base::DictionaryValue> value = CreateTestTypeDictionary(); std::unique_ptr<base::DictionaryValue> value = CreateTestTypeDictionary();
std::unique_ptr<TestType> test_type(new TestType()); auto test_type = std::make_unique<simple_api::TestType>();
EXPECT_TRUE(TestType::Populate(*value, test_type.get())); EXPECT_TRUE(simple_api::TestType::Populate(*value, test_type.get()));
std::unique_ptr<base::ListValue> results = std::unique_ptr<base::ListValue> results =
GetTestType::Results::Create(*test_type); simple_api::GetTestType::Results::Create(*test_type);
base::DictionaryValue* result = NULL; base::DictionaryValue* result = NULL;
results->GetDictionary(0, &result); results->GetDictionary(0, &result);
...@@ -152,7 +153,8 @@ TEST(JsonSchemaCompilerSimpleTest, GetTestType) { ...@@ -152,7 +153,8 @@ TEST(JsonSchemaCompilerSimpleTest, GetTestType) {
TEST(JsonSchemaCompilerSimpleTest, OnIntegerFiredCreate) { 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; base::ListValue expected;
expected.AppendInteger(5); expected.AppendInteger(5);
EXPECT_TRUE(results->Equals(&expected)); EXPECT_TRUE(results->Equals(&expected));
...@@ -161,7 +163,8 @@ TEST(JsonSchemaCompilerSimpleTest, OnIntegerFiredCreate) { ...@@ -161,7 +163,8 @@ TEST(JsonSchemaCompilerSimpleTest, OnIntegerFiredCreate) {
TEST(JsonSchemaCompilerSimpleTest, OnStringFiredCreate) { 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; base::ListValue expected;
expected.AppendString("yo dawg"); expected.AppendString("yo dawg");
EXPECT_TRUE(results->Equals(&expected)); EXPECT_TRUE(results->Equals(&expected));
...@@ -170,7 +173,7 @@ TEST(JsonSchemaCompilerSimpleTest, OnStringFiredCreate) { ...@@ -170,7 +173,7 @@ TEST(JsonSchemaCompilerSimpleTest, OnStringFiredCreate) {
TEST(JsonSchemaCompilerSimpleTest, OnTestTypeFiredCreate) { TEST(JsonSchemaCompilerSimpleTest, OnTestTypeFiredCreate) {
{ {
TestType some_test_type; simple_api::TestType some_test_type;
std::unique_ptr<base::DictionaryValue> expected = std::unique_ptr<base::DictionaryValue> expected =
CreateTestTypeDictionary(); CreateTestTypeDictionary();
ASSERT_TRUE(expected->GetDouble("number", &some_test_type.number)); ASSERT_TRUE(expected->GetDouble("number", &some_test_type.number));
...@@ -179,7 +182,7 @@ TEST(JsonSchemaCompilerSimpleTest, OnTestTypeFiredCreate) { ...@@ -179,7 +182,7 @@ TEST(JsonSchemaCompilerSimpleTest, OnTestTypeFiredCreate) {
ASSERT_TRUE(expected->GetBoolean("boolean", &some_test_type.boolean)); ASSERT_TRUE(expected->GetBoolean("boolean", &some_test_type.boolean));
std::unique_ptr<base::ListValue> results( std::unique_ptr<base::ListValue> results(
OnTestTypeFired::Create(some_test_type)); simple_api::OnTestTypeFired::Create(some_test_type));
base::DictionaryValue* result = NULL; base::DictionaryValue* result = NULL;
results->GetDictionary(0, &result); results->GetDictionary(0, &result);
EXPECT_TRUE(result->Equals(expected.get())); 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