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 "testing/gtest/include/gtest/gtest.h" 6 #include "tools/json_schema_compiler/test/any.h" 7 8 using namespace test::api::any; 9 10 TEST(JsonSchemaCompilerAnyTest, AnyTypePopulate) { 11 { 12 AnyType any_type; 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())); 19 } 20 { 21 AnyType any_type; 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())); 28 } 29 } 30 31 TEST(JsonSchemaCompilerAnyTest, OptionalAnyParamsCreate) { 32 { 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()); 38 } 39 { 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)); 45 ASSERT_TRUE(params); 46 ASSERT_TRUE(params->any_name); 47 EXPECT_TRUE(params->any_name->Equals(param.get())); 48 } 49 { 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)); 55 ASSERT_TRUE(params); 56 ASSERT_TRUE(params->any_name); 57 EXPECT_TRUE(params->any_name->Equals(param.get())); 58 } 59 } 60