Index: tools/json_schema_compiler/test/any_unittest.cc |
diff --git a/tools/json_schema_compiler/test/any_unittest.cc b/tools/json_schema_compiler/test/any_unittest.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..7ce8d604168bfb782c0b44dfb8c229ea78388a10 |
--- /dev/null |
+++ b/tools/json_schema_compiler/test/any_unittest.cc |
@@ -0,0 +1,66 @@ |
+// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "tools/json_schema_compiler/test/any.h" |
+ |
+#include "testing/gtest/include/gtest/gtest.h" |
+ |
+using namespace test::api::any; |
+ |
+TEST(JsonSchemaCompilerAnyTest, AnyTypePopulate) { |
+ { |
+ scoped_ptr<AnyType> any_type(new AnyType()); |
not at google - send to devlin
2012/02/29 03:06:30
just have any_type on the stack
calamity
2012/03/01 04:47:09
Done.
|
+ scoped_ptr<DictionaryValue> any_type_value(new DictionaryValue()); |
+ any_type_value->SetString("any", "value"); |
+ EXPECT_TRUE(AnyType::Populate(*any_type_value, any_type.get())); |
+ EXPECT_TRUE(any_type->any.value().IsType(Value::TYPE_STRING)); |
not at google - send to devlin
2012/02/29 03:06:30
again, try to use Equals rather than all this manu
calamity
2012/03/01 04:47:09
Done.
|
+ std::string temp; |
+ EXPECT_TRUE(any_type->any.value().GetAsString(&temp)); |
+ EXPECT_EQ("value", temp); |
+ } |
+ { |
+ scoped_ptr<AnyType> any_type(new AnyType()); |
+ scoped_ptr<DictionaryValue> any_type_value(new DictionaryValue()); |
+ any_type_value->SetInteger("any", 5); |
+ EXPECT_TRUE(AnyType::Populate(*any_type_value, any_type.get())); |
+ EXPECT_TRUE(any_type->any.value().IsType(Value::TYPE_INTEGER)); |
+ int temp = 0; |
+ EXPECT_TRUE(any_type->any.value().GetAsInteger(&temp)); |
+ EXPECT_EQ(5, temp); |
+ } |
+} |
+ |
+TEST(JsonSchemaCompilerAnyTest, OptionalAnyParamsCreate) { |
+ { |
+ scoped_ptr<ListValue> params_value(new ListValue()); |
+ scoped_ptr<OptionalAny::Params> params( |
+ OptionalAny::Params::Create(*params_value)); |
+ EXPECT_TRUE(params.get()); |
+ EXPECT_FALSE(params->any.get()); |
+ } |
+ { |
+ scoped_ptr<ListValue> params_value(new ListValue()); |
+ params_value->Append(Value::CreateStringValue("asdf")); |
+ scoped_ptr<OptionalAny::Params> params( |
+ OptionalAny::Params::Create(*params_value)); |
+ EXPECT_TRUE(params.get()); |
+ EXPECT_TRUE(params->any.get()); |
+ EXPECT_TRUE(params->any->value().IsType(Value::TYPE_STRING)); |
+ std::string temp; |
+ EXPECT_TRUE(params->any->value().GetAsString(&temp)); |
+ EXPECT_EQ("asdf", temp); |
+ } |
+ { |
+ scoped_ptr<ListValue> params_value(new ListValue()); |
+ params_value->Append(Value::CreateBooleanValue(true)); |
+ scoped_ptr<OptionalAny::Params> params( |
+ OptionalAny::Params::Create(*params_value)); |
+ EXPECT_TRUE(params.get()); |
+ EXPECT_TRUE(params->any.get()); |
+ EXPECT_TRUE(params->any->value().IsType(Value::TYPE_BOOLEAN)); |
+ bool temp; |
+ EXPECT_TRUE(params->any->value().GetAsBoolean(&temp)); |
+ EXPECT_TRUE(temp); |
+ } |
+} |