Home | History | Annotate | Download | only in test
      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<DictionaryValue> any_type_value(new DictionaryValue());
     14     any_type_value->SetString("any", "value");
     15     EXPECT_TRUE(AnyType::Populate(*any_type_value, &any_type));
     16     scoped_ptr<Value> any_type_to_value(any_type.ToValue());
     17     EXPECT_TRUE(any_type_value->Equals(any_type_to_value.get()));
     18   }
     19   {
     20     AnyType any_type;
     21     scoped_ptr<DictionaryValue> any_type_value(new DictionaryValue());
     22     any_type_value->SetInteger("any", 5);
     23     EXPECT_TRUE(AnyType::Populate(*any_type_value, &any_type));
     24     scoped_ptr<Value> any_type_to_value(any_type.ToValue());
     25     EXPECT_TRUE(any_type_value->Equals(any_type_to_value.get()));
     26   }
     27 }
     28 
     29 TEST(JsonSchemaCompilerAnyTest, OptionalAnyParamsCreate) {
     30   {
     31     scoped_ptr<ListValue> params_value(new ListValue());
     32     scoped_ptr<OptionalAny::Params> params(
     33         OptionalAny::Params::Create(*params_value));
     34     EXPECT_TRUE(params.get());
     35     EXPECT_FALSE(params->any_name.get());
     36   }
     37   {
     38     scoped_ptr<ListValue> params_value(new ListValue());
     39     scoped_ptr<Value> param(Value::CreateStringValue("asdf"));
     40     params_value->Append(param->DeepCopy());
     41     scoped_ptr<OptionalAny::Params> params(
     42         OptionalAny::Params::Create(*params_value));
     43     ASSERT_TRUE(params);
     44     ASSERT_TRUE(params->any_name);
     45     EXPECT_TRUE(params->any_name->Equals(param.get()));
     46   }
     47   {
     48     scoped_ptr<ListValue> params_value(new ListValue());
     49     scoped_ptr<Value> param(Value::CreateBooleanValue(true));
     50     params_value->Append(param->DeepCopy());
     51     scoped_ptr<OptionalAny::Params> params(
     52         OptionalAny::Params::Create(*params_value));
     53     ASSERT_TRUE(params);
     54     ASSERT_TRUE(params->any_name);
     55     EXPECT_TRUE(params->any_name->Equals(param.get()));
     56   }
     57 }
     58