functions_on_types_unittest.cc revision 5821806d5e7f356e8fa4b058a389a808ea183019
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/functions_on_types.h"
6
7#include "testing/gtest/include/gtest/gtest.h"
8
9using namespace test::api::functions_on_types;
10
11TEST(JsonSchemaCompilerFunctionsOnTypesTest, StorageAreaGetParamsCreate) {
12  {
13    scoped_ptr<ListValue> params_value(new ListValue());
14    scoped_ptr<StorageArea::Get::Params> params(
15        StorageArea::Get::Params::Create(*params_value));
16    EXPECT_TRUE(params.get());
17    EXPECT_EQ(StorageArea::Get::Params::KEYS_NONE, params->keys_type);
18  }
19  {
20    scoped_ptr<ListValue> params_value(new ListValue());
21    params_value->Append(Value::CreateIntegerValue(9));
22    scoped_ptr<StorageArea::Get::Params> params(
23        StorageArea::Get::Params::Create(*params_value));
24    EXPECT_FALSE(params.get());
25  }
26  {
27    scoped_ptr<ListValue> params_value(new ListValue());
28    params_value->Append(Value::CreateStringValue("test"));
29    scoped_ptr<StorageArea::Get::Params> params(
30        StorageArea::Get::Params::Create(*params_value));
31    EXPECT_TRUE(params.get());
32    EXPECT_EQ(StorageArea::Get::Params::KEYS_STRING, params->keys_type);
33    EXPECT_EQ("test", *params->keys_string);
34  }
35  {
36    scoped_ptr<DictionaryValue> keys_object_value(new DictionaryValue());
37    keys_object_value->SetInteger("integer", 5);
38    keys_object_value->SetString("string", "string");
39    scoped_ptr<ListValue> params_value(new ListValue());
40    params_value->Append(keys_object_value->DeepCopy());
41    scoped_ptr<StorageArea::Get::Params> params(
42        StorageArea::Get::Params::Create(*params_value));
43    EXPECT_TRUE(params.get());
44    EXPECT_EQ(StorageArea::Get::Params::KEYS_OBJECT, params->keys_type);
45    EXPECT_TRUE(
46        keys_object_value->Equals(&params->keys_object->additional_properties));
47  }
48}
49
50TEST(JsonSchemaCompilerFunctionsOnTypesTest, StorageAreaGetResultCreate) {
51  StorageArea::Get::Results::Items items;
52  items.additional_properties.SetDouble("asdf", 0.1);
53  items.additional_properties.SetString("sdfg", "zxcv");
54  scoped_ptr<ListValue> results = StorageArea::Get::Results::Create(items);
55  DictionaryValue* item_result = NULL;
56  results->GetDictionary(0, &item_result);
57  EXPECT_TRUE(item_result->Equals(&items.additional_properties));
58}
59
60TEST(JsonSchemaCompilerFunctionsOnTypesTest, ChromeSettingGetParamsCreate) {
61  scoped_ptr<DictionaryValue> details_value(new DictionaryValue());
62  details_value->SetBoolean("incognito", true);
63  scoped_ptr<ListValue> params_value(new ListValue());
64  params_value->Append(details_value.release());
65  scoped_ptr<ChromeSetting::Get::Params> params(
66      ChromeSetting::Get::Params::Create(*params_value));
67  EXPECT_TRUE(params.get());
68  EXPECT_TRUE(*params->details.incognito);
69}
70