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.
5 #include "testing/gtest/include/gtest/gtest.h"
6 #include "tools/json_schema_compiler/test/any.h"
8 using namespace test::api::any
;
10 TEST(JsonSchemaCompilerAnyTest
, AnyTypePopulate
) {
13 scoped_ptr
<base::DictionaryValue
> any_type_value(
14 new base::DictionaryValue());
15 any_type_value
->SetString("any", "value");
16 EXPECT_TRUE(AnyType::Populate(*any_type_value
, &any_type
));
17 scoped_ptr
<base::Value
> any_type_to_value(any_type
.ToValue());
18 EXPECT_TRUE(any_type_value
->Equals(any_type_to_value
.get()));
22 scoped_ptr
<base::DictionaryValue
> any_type_value(
23 new base::DictionaryValue());
24 any_type_value
->SetInteger("any", 5);
25 EXPECT_TRUE(AnyType::Populate(*any_type_value
, &any_type
));
26 scoped_ptr
<base::Value
> any_type_to_value(any_type
.ToValue());
27 EXPECT_TRUE(any_type_value
->Equals(any_type_to_value
.get()));
31 TEST(JsonSchemaCompilerAnyTest
, OptionalAnyParamsCreate
) {
33 scoped_ptr
<base::ListValue
> params_value(new base::ListValue());
34 scoped_ptr
<OptionalAny::Params
> params(
35 OptionalAny::Params::Create(*params_value
));
36 EXPECT_TRUE(params
.get());
37 EXPECT_FALSE(params
->any_name
.get());
40 scoped_ptr
<base::ListValue
> params_value(new base::ListValue());
41 scoped_ptr
<base::Value
> param(new base::StringValue("asdf"));
42 params_value
->Append(param
->DeepCopy());
43 scoped_ptr
<OptionalAny::Params
> params(
44 OptionalAny::Params::Create(*params_value
));
46 ASSERT_TRUE(params
->any_name
);
47 EXPECT_TRUE(params
->any_name
->Equals(param
.get()));
50 scoped_ptr
<base::ListValue
> params_value(new base::ListValue());
51 scoped_ptr
<base::Value
> param(new base::FundamentalValue(true));
52 params_value
->Append(param
->DeepCopy());
53 scoped_ptr
<OptionalAny::Params
> params(
54 OptionalAny::Params::Create(*params_value
));
56 ASSERT_TRUE(params
->any_name
);
57 EXPECT_TRUE(params
->any_name
->Equals(param
.get()));