OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "tools/json_schema_compiler/test/simple_api.h" | 5 #include "tools/json_schema_compiler/test/simple_api.h" |
6 | 6 |
7 #include "testing/gtest/include/gtest/gtest.h" | 7 #include "testing/gtest/include/gtest/gtest.h" |
8 | 8 |
9 using namespace test::api::simple_api; | 9 using namespace test::api::simple_api; |
10 | 10 |
11 namespace { | 11 namespace { |
12 | 12 |
13 static scoped_ptr<base::DictionaryValue> CreateTestTypeDictionary() { | 13 static scoped_ptr<base::DictionaryValue> CreateTestTypeDictionary() { |
14 scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue()); | 14 scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue()); |
15 value->SetWithoutPathExpansion("number", | 15 value->SetWithoutPathExpansion("number", |
16 base::Value::CreateDoubleValue(1.1)); | 16 base::Value::CreateDoubleValue(1.1)); |
17 value->SetWithoutPathExpansion("integer", new base::FundamentalValue(4)); | 17 value->SetWithoutPathExpansion("integer", new base::FundamentalValue(4)); |
18 value->SetWithoutPathExpansion("string", | 18 value->SetWithoutPathExpansion("string", new base::StringValue("bling")); |
19 base::Value::CreateStringValue("bling")); | |
20 value->SetWithoutPathExpansion("boolean", new base::FundamentalValue(true)); | 19 value->SetWithoutPathExpansion("boolean", new base::FundamentalValue(true)); |
21 return value.Pass(); | 20 return value.Pass(); |
22 } | 21 } |
23 | 22 |
24 } // namespace | 23 } // namespace |
25 | 24 |
26 TEST(JsonSchemaCompilerSimpleTest, IncrementIntegerResultCreate) { | 25 TEST(JsonSchemaCompilerSimpleTest, IncrementIntegerResultCreate) { |
27 scoped_ptr<base::ListValue> results = IncrementInteger::Results::Create(5); | 26 scoped_ptr<base::ListValue> results = IncrementInteger::Results::Create(5); |
28 base::ListValue expected; | 27 base::ListValue expected; |
29 expected.Append(new base::FundamentalValue(5)); | 28 expected.Append(new base::FundamentalValue(5)); |
30 EXPECT_TRUE(results->Equals(&expected)); | 29 EXPECT_TRUE(results->Equals(&expected)); |
31 } | 30 } |
32 | 31 |
33 TEST(JsonSchemaCompilerSimpleTest, IncrementIntegerParamsCreate) { | 32 TEST(JsonSchemaCompilerSimpleTest, IncrementIntegerParamsCreate) { |
34 scoped_ptr<base::ListValue> params_value(new base::ListValue()); | 33 scoped_ptr<base::ListValue> params_value(new base::ListValue()); |
35 params_value->Append(new base::FundamentalValue(6)); | 34 params_value->Append(new base::FundamentalValue(6)); |
36 scoped_ptr<IncrementInteger::Params> params( | 35 scoped_ptr<IncrementInteger::Params> params( |
37 IncrementInteger::Params::Create(*params_value)); | 36 IncrementInteger::Params::Create(*params_value)); |
38 EXPECT_TRUE(params.get()); | 37 EXPECT_TRUE(params.get()); |
39 EXPECT_EQ(6, params->num); | 38 EXPECT_EQ(6, params->num); |
40 } | 39 } |
41 | 40 |
42 TEST(JsonSchemaCompilerSimpleTest, NumberOfParams) { | 41 TEST(JsonSchemaCompilerSimpleTest, NumberOfParams) { |
43 { | 42 { |
44 scoped_ptr<base::ListValue> params_value(new base::ListValue()); | 43 scoped_ptr<base::ListValue> params_value(new base::ListValue()); |
45 params_value->Append(base::Value::CreateStringValue("text")); | 44 params_value->Append(new base::StringValue("text")); |
46 params_value->Append(base::Value::CreateStringValue("text")); | 45 params_value->Append(new base::StringValue("text")); |
47 scoped_ptr<OptionalString::Params> params( | 46 scoped_ptr<OptionalString::Params> params( |
48 OptionalString::Params::Create(*params_value)); | 47 OptionalString::Params::Create(*params_value)); |
49 EXPECT_FALSE(params.get()); | 48 EXPECT_FALSE(params.get()); |
50 } | 49 } |
51 { | 50 { |
52 scoped_ptr<base::ListValue> params_value(new base::ListValue()); | 51 scoped_ptr<base::ListValue> params_value(new base::ListValue()); |
53 scoped_ptr<IncrementInteger::Params> params( | 52 scoped_ptr<IncrementInteger::Params> params( |
54 IncrementInteger::Params::Create(*params_value)); | 53 IncrementInteger::Params::Create(*params_value)); |
55 EXPECT_FALSE(params.get()); | 54 EXPECT_FALSE(params.get()); |
56 } | 55 } |
57 } | 56 } |
58 | 57 |
59 TEST(JsonSchemaCompilerSimpleTest, OptionalStringParamsCreate) { | 58 TEST(JsonSchemaCompilerSimpleTest, OptionalStringParamsCreate) { |
60 { | 59 { |
61 scoped_ptr<base::ListValue> params_value(new base::ListValue()); | 60 scoped_ptr<base::ListValue> params_value(new base::ListValue()); |
62 scoped_ptr<OptionalString::Params> params( | 61 scoped_ptr<OptionalString::Params> params( |
63 OptionalString::Params::Create(*params_value)); | 62 OptionalString::Params::Create(*params_value)); |
64 EXPECT_TRUE(params.get()); | 63 EXPECT_TRUE(params.get()); |
65 EXPECT_FALSE(params->str.get()); | 64 EXPECT_FALSE(params->str.get()); |
66 } | 65 } |
67 { | 66 { |
68 scoped_ptr<base::ListValue> params_value(new base::ListValue()); | 67 scoped_ptr<base::ListValue> params_value(new base::ListValue()); |
69 params_value->Append(base::Value::CreateStringValue("asdf")); | 68 params_value->Append(new base::StringValue("asdf")); |
70 scoped_ptr<OptionalString::Params> params( | 69 scoped_ptr<OptionalString::Params> params( |
71 OptionalString::Params::Create(*params_value)); | 70 OptionalString::Params::Create(*params_value)); |
72 EXPECT_TRUE(params.get()); | 71 EXPECT_TRUE(params.get()); |
73 EXPECT_TRUE(params->str.get()); | 72 EXPECT_TRUE(params->str.get()); |
74 EXPECT_EQ("asdf", *params->str); | 73 EXPECT_EQ("asdf", *params->str); |
75 } | 74 } |
76 } | 75 } |
77 | 76 |
78 TEST(JsonSchemaCompilerSimpleTest, OptionalParamsTakingNull) { | 77 TEST(JsonSchemaCompilerSimpleTest, OptionalParamsTakingNull) { |
79 { | 78 { |
(...skipping 13 matching lines...) Expand all Loading... |
93 scoped_ptr<OptionalString::Params> params( | 92 scoped_ptr<OptionalString::Params> params( |
94 OptionalString::Params::Create(*params_value)); | 93 OptionalString::Params::Create(*params_value)); |
95 EXPECT_FALSE(params.get()); | 94 EXPECT_FALSE(params.get()); |
96 } | 95 } |
97 } | 96 } |
98 | 97 |
99 TEST(JsonSchemaCompilerSimpleTest, OptionalBeforeRequired) { | 98 TEST(JsonSchemaCompilerSimpleTest, OptionalBeforeRequired) { |
100 { | 99 { |
101 scoped_ptr<base::ListValue> params_value(new base::ListValue()); | 100 scoped_ptr<base::ListValue> params_value(new base::ListValue()); |
102 params_value->Append(base::Value::CreateNullValue()); | 101 params_value->Append(base::Value::CreateNullValue()); |
103 params_value->Append(base::Value::CreateStringValue("asdf")); | 102 params_value->Append(new base::StringValue("asdf")); |
104 scoped_ptr<OptionalBeforeRequired::Params> params( | 103 scoped_ptr<OptionalBeforeRequired::Params> params( |
105 OptionalBeforeRequired::Params::Create(*params_value)); | 104 OptionalBeforeRequired::Params::Create(*params_value)); |
106 EXPECT_TRUE(params.get()); | 105 EXPECT_TRUE(params.get()); |
107 EXPECT_FALSE(params->first.get()); | 106 EXPECT_FALSE(params->first.get()); |
108 EXPECT_EQ("asdf", params->second); | 107 EXPECT_EQ("asdf", params->second); |
109 } | 108 } |
110 } | 109 } |
111 | 110 |
112 TEST(JsonSchemaCompilerSimpleTest, NoParamsResultCreate) { | 111 TEST(JsonSchemaCompilerSimpleTest, NoParamsResultCreate) { |
113 scoped_ptr<base::ListValue> results = OptionalString::Results::Create(); | 112 scoped_ptr<base::ListValue> results = OptionalString::Results::Create(); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
154 base::ListValue expected; | 153 base::ListValue expected; |
155 expected.Append(new base::FundamentalValue(5)); | 154 expected.Append(new base::FundamentalValue(5)); |
156 EXPECT_TRUE(results->Equals(&expected)); | 155 EXPECT_TRUE(results->Equals(&expected)); |
157 } | 156 } |
158 } | 157 } |
159 | 158 |
160 TEST(JsonSchemaCompilerSimpleTest, OnStringFiredCreate) { | 159 TEST(JsonSchemaCompilerSimpleTest, OnStringFiredCreate) { |
161 { | 160 { |
162 scoped_ptr<base::ListValue> results(OnStringFired::Create("yo dawg")); | 161 scoped_ptr<base::ListValue> results(OnStringFired::Create("yo dawg")); |
163 base::ListValue expected; | 162 base::ListValue expected; |
164 expected.Append(base::Value::CreateStringValue("yo dawg")); | 163 expected.Append(new base::StringValue("yo dawg")); |
165 EXPECT_TRUE(results->Equals(&expected)); | 164 EXPECT_TRUE(results->Equals(&expected)); |
166 } | 165 } |
167 } | 166 } |
168 | 167 |
169 TEST(JsonSchemaCompilerSimpleTest, OnTestTypeFiredCreate) { | 168 TEST(JsonSchemaCompilerSimpleTest, OnTestTypeFiredCreate) { |
170 { | 169 { |
171 TestType some_test_type; | 170 TestType some_test_type; |
172 scoped_ptr<base::DictionaryValue> expected = CreateTestTypeDictionary(); | 171 scoped_ptr<base::DictionaryValue> expected = CreateTestTypeDictionary(); |
173 ASSERT_TRUE(expected->GetDouble("number", &some_test_type.number)); | 172 ASSERT_TRUE(expected->GetDouble("number", &some_test_type.number)); |
174 ASSERT_TRUE(expected->GetString("string", &some_test_type.string)); | 173 ASSERT_TRUE(expected->GetString("string", &some_test_type.string)); |
175 ASSERT_TRUE(expected->GetInteger("integer", &some_test_type.integer)); | 174 ASSERT_TRUE(expected->GetInteger("integer", &some_test_type.integer)); |
176 ASSERT_TRUE(expected->GetBoolean("boolean", &some_test_type.boolean)); | 175 ASSERT_TRUE(expected->GetBoolean("boolean", &some_test_type.boolean)); |
177 | 176 |
178 scoped_ptr<base::ListValue> results( | 177 scoped_ptr<base::ListValue> results( |
179 OnTestTypeFired::Create(some_test_type)); | 178 OnTestTypeFired::Create(some_test_type)); |
180 base::DictionaryValue* result = NULL; | 179 base::DictionaryValue* result = NULL; |
181 results->GetDictionary(0, &result); | 180 results->GetDictionary(0, &result); |
182 EXPECT_TRUE(result->Equals(expected.get())); | 181 EXPECT_TRUE(result->Equals(expected.get())); |
183 } | 182 } |
184 } | 183 } |
OLD | NEW |