OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "tools/json_schema_compiler/test/choices.h" |
| 6 |
| 7 #include "testing/gtest/include/gtest/gtest.h" |
| 8 |
| 9 using namespace test::api::choices; |
| 10 |
| 11 TEST(JsonSchemaCompilerChoicesTest, TakesIntegersParamsCreate) { |
| 12 { |
| 13 scoped_ptr<ListValue> params_value(new ListValue()); |
| 14 params_value->Append(Value::CreateBooleanValue(true)); |
| 15 scoped_ptr<TakesIntegers::Params> params( |
| 16 TakesIntegers::Params::Create(*params_value)); |
| 17 EXPECT_FALSE(params.get()); |
| 18 } |
| 19 { |
| 20 scoped_ptr<ListValue> params_value(new ListValue()); |
| 21 params_value->Append(Value::CreateIntegerValue(6)); |
| 22 scoped_ptr<TakesIntegers::Params> params( |
| 23 TakesIntegers::Params::Create(*params_value)); |
| 24 EXPECT_TRUE(params.get()); |
| 25 EXPECT_EQ(TakesIntegers::Params::NUMS_INTEGER, params->nums_type); |
| 26 EXPECT_FALSE(params->nums_array.get()); |
| 27 EXPECT_EQ(6, *params->nums_integer); |
| 28 } |
| 29 { |
| 30 scoped_ptr<ListValue> params_value(new ListValue()); |
| 31 scoped_ptr<ListValue> integers(new ListValue()); |
| 32 integers->Append(Value::CreateIntegerValue(6)); |
| 33 integers->Append(Value::CreateIntegerValue(8)); |
| 34 params_value->Append(integers.release()); |
| 35 scoped_ptr<TakesIntegers::Params> params( |
| 36 TakesIntegers::Params::Create(*params_value)); |
| 37 EXPECT_TRUE(params.get()); |
| 38 EXPECT_EQ(TakesIntegers::Params::NUMS_ARRAY, params->nums_type); |
| 39 EXPECT_EQ(2UL, (*params->nums_array).size()); |
| 40 EXPECT_EQ(6, (*params->nums_array)[0]); |
| 41 EXPECT_EQ(8, (*params->nums_array)[1]); |
| 42 } |
| 43 } |
| 44 |
| 45 TEST(JsonSchemaCompilerChoicesTest, ObjectWithChoicesParamsCreate) { |
| 46 { |
| 47 scoped_ptr<DictionaryValue> object_param(new DictionaryValue()); |
| 48 object_param->SetWithoutPathExpansion("strings", |
| 49 Value::CreateStringValue("asdf")); |
| 50 scoped_ptr<ListValue> params_value(new ListValue()); |
| 51 params_value->Append(object_param.release()); |
| 52 scoped_ptr<ObjectWithChoices::Params> params( |
| 53 ObjectWithChoices::Params::Create(*params_value)); |
| 54 EXPECT_TRUE(params.get()); |
| 55 EXPECT_EQ(ObjectWithChoices::Params::StringInfo::STRINGS_STRING, |
| 56 params->string_info.strings_type); |
| 57 EXPECT_EQ("asdf", *params->string_info.strings_string); |
| 58 } |
| 59 { |
| 60 scoped_ptr<DictionaryValue> object_param(new DictionaryValue()); |
| 61 object_param->SetWithoutPathExpansion("strings", |
| 62 Value::CreateStringValue("asdf")); |
| 63 object_param->SetWithoutPathExpansion("integers", |
| 64 Value::CreateIntegerValue(6)); |
| 65 scoped_ptr<ListValue> params_value(new ListValue()); |
| 66 params_value->Append(object_param.release()); |
| 67 scoped_ptr<ObjectWithChoices::Params> params( |
| 68 ObjectWithChoices::Params::Create(*params_value)); |
| 69 EXPECT_TRUE(params.get()); |
| 70 EXPECT_EQ(ObjectWithChoices::Params::StringInfo::STRINGS_STRING, |
| 71 params->string_info.strings_type); |
| 72 EXPECT_EQ("asdf", *params->string_info.strings_string); |
| 73 EXPECT_EQ(ObjectWithChoices::Params::StringInfo::INTEGERS_INTEGER, |
| 74 params->string_info.integers_type); |
| 75 EXPECT_EQ(6, *params->string_info.integers_integer); |
| 76 } |
| 77 } |
| 78 |
| 79 TEST(JsonSchemaCompilerChoicesTest, ObjectWithChoicesParamsCreateFail) { |
| 80 { |
| 81 scoped_ptr<DictionaryValue> object_param(new DictionaryValue()); |
| 82 object_param->SetWithoutPathExpansion("strings", |
| 83 Value::CreateIntegerValue(5)); |
| 84 scoped_ptr<ListValue> params_value(new ListValue()); |
| 85 params_value->Append(object_param.release()); |
| 86 scoped_ptr<ObjectWithChoices::Params> params( |
| 87 ObjectWithChoices::Params::Create(*params_value)); |
| 88 EXPECT_FALSE(params.get()); |
| 89 } |
| 90 { |
| 91 scoped_ptr<DictionaryValue> object_param(new DictionaryValue()); |
| 92 object_param->SetWithoutPathExpansion("strings", |
| 93 Value::CreateStringValue("asdf")); |
| 94 object_param->SetWithoutPathExpansion("integers", |
| 95 Value::CreateStringValue("asdf")); |
| 96 scoped_ptr<ListValue> params_value(new ListValue()); |
| 97 params_value->Append(object_param.release()); |
| 98 scoped_ptr<ObjectWithChoices::Params> params( |
| 99 ObjectWithChoices::Params::Create(*params_value)); |
| 100 EXPECT_FALSE(params.get()); |
| 101 } |
| 102 { |
| 103 scoped_ptr<DictionaryValue> object_param(new DictionaryValue()); |
| 104 object_param->SetWithoutPathExpansion("integers", |
| 105 Value::CreateIntegerValue(6)); |
| 106 scoped_ptr<ListValue> params_value(new ListValue()); |
| 107 params_value->Append(object_param.release()); |
| 108 scoped_ptr<ObjectWithChoices::Params> params( |
| 109 ObjectWithChoices::Params::Create(*params_value)); |
| 110 EXPECT_FALSE(params.get()); |
| 111 } |
| 112 } |
| 113 |
| 114 TEST(JsonSchemaCompilerChoicesTest, ReturnChoices) { |
| 115 { |
| 116 std::vector<int> integers; |
| 117 integers.push_back(1); |
| 118 integers.push_back(2); |
| 119 scoped_ptr<Value> array_result(ReturnChoices::Result::Create(integers)); |
| 120 ListValue* list = NULL; |
| 121 EXPECT_TRUE(array_result->GetAsList(&list)); |
| 122 EXPECT_EQ(2UL, list->GetSize()); |
| 123 int temp; |
| 124 EXPECT_TRUE(list->GetInteger(0, &temp)); |
| 125 EXPECT_EQ(1, temp); |
| 126 EXPECT_TRUE(list->GetInteger(1, &temp)); |
| 127 EXPECT_EQ(2, temp); |
| 128 } |
| 129 { |
| 130 scoped_ptr<Value> single_result(ReturnChoices::Result::Create(5)); |
| 131 int temp; |
| 132 EXPECT_TRUE(single_result->GetAsInteger(&temp)); |
| 133 EXPECT_EQ(5, temp); |
| 134 } |
| 135 } |
OLD | NEW |