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()));
......
......@@ -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 =
......
......@@ -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