Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(608)

Unified Diff: tools/json_schema_compiler/test/simple_api_unittest.cc

Issue 9309044: Supporting more APIs with json_schema_compiler (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: rework, add a couple of tests Created 8 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « tools/json_schema_compiler/test/simple_api.json ('k') | tools/json_schema_compiler/util_cc_helper.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/json_schema_compiler/test/simple_api_unittest.cc
diff --git a/tools/json_schema_compiler/test/simple_api_unittest.cc b/tools/json_schema_compiler/test/simple_api_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..dc959a31041fc512c8a5fc33d119fa1ad61ee0dd
--- /dev/null
+++ b/tools/json_schema_compiler/test/simple_api_unittest.cc
@@ -0,0 +1,111 @@
+// 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/simple_api.h"
+
+#include "testing/gtest/include/gtest/gtest.h"
+
+using namespace test::api::simple_api;
+
+namespace {
+
+static scoped_ptr<DictionaryValue> CreateTestTypeDictionary() {
+ scoped_ptr<DictionaryValue> value(new DictionaryValue());
+ value->SetWithoutPathExpansion("number", Value::CreateDoubleValue(1.1));
+ value->SetWithoutPathExpansion("integer", Value::CreateIntegerValue(4));
+ value->SetWithoutPathExpansion("string", Value::CreateStringValue("bling"));
+ value->SetWithoutPathExpansion("boolean", Value::CreateBooleanValue(true));
+ return value.Pass();
+}
+
+} // namespace
+
+TEST(JsonSchemaCompilerSimpleTest, IncrementIntegerResultCreate) {
+ scoped_ptr<Value> result(IncrementInteger::Result::Create(5));
+ int temp = 0;
+ EXPECT_TRUE(result->GetAsInteger(&temp));
+ EXPECT_EQ(5, temp);
+}
+
+TEST(JsonSchemaCompilerSimpleTest, IncrementIntegerParamsCreate) {
+ scoped_ptr<ListValue> params_value(new ListValue());
+ params_value->Append(Value::CreateIntegerValue(6));
+ scoped_ptr<IncrementInteger::Params> params(
+ IncrementInteger::Params::Create(*params_value));
+ EXPECT_TRUE(params.get());
+ EXPECT_EQ(6, params->num);
+}
+
+TEST(JsonSchemaCompilerSimpleTest, OptionalStringParamsCreate) {
+ {
+ scoped_ptr<ListValue> params_value(new ListValue());
+ scoped_ptr<OptionalString::Params> params(
+ OptionalString::Params::Create(*params_value));
+ EXPECT_TRUE(params.get());
+ EXPECT_FALSE(params->str.get());
+ }
+ {
+ scoped_ptr<ListValue> params_value(new ListValue());
+ params_value->Append(Value::CreateStringValue("asdf"));
+ scoped_ptr<OptionalString::Params> params(
+ OptionalString::Params::Create(*params_value));
+ EXPECT_TRUE(params.get());
+ EXPECT_TRUE(params->str.get());
+ EXPECT_EQ("asdf", *params->str);
+ }
+}
+
+TEST(JsonSchemaCompilerSimpleTest, OptionalParamsTakingNull) {
+ {
+ scoped_ptr<ListValue> params_value(new ListValue());
+ params_value->Append(Value::CreateNullValue());
+ scoped_ptr<OptionalString::Params> params(
+ OptionalString::Params::Create(*params_value));
+ EXPECT_TRUE(params.get());
+ EXPECT_FALSE(params->str.get());
+ }
+}
+
+TEST(JsonSchemaCompilerSimpleTest, OptionalStringParamsWrongType) {
+ {
+ scoped_ptr<ListValue> params_value(new ListValue());
+ params_value->Append(Value::CreateIntegerValue(5));
+ scoped_ptr<OptionalString::Params> params(
+ OptionalString::Params::Create(*params_value));
+ EXPECT_FALSE(params.get());
+ }
+}
+
+TEST(JsonSchemaCompilerSimpleTest, NoParamsResultCreate) {
+ EXPECT_TRUE(Value::Equals(OptionalString::Result::Create(),
+ Value::CreateNullValue()));
+}
+
+TEST(JsonSchemaCompilerSimpleTest, TestTypePopulate) {
+ {
+ scoped_ptr<TestType> test_type(new TestType());
+ scoped_ptr<DictionaryValue> value = CreateTestTypeDictionary();
+ EXPECT_TRUE(TestType::Populate(*value, test_type.get()));
+ EXPECT_EQ("bling", test_type->string);
+ EXPECT_EQ(1.1, test_type->number);
+ EXPECT_EQ(4, test_type->integer);
+ EXPECT_EQ(true, test_type->boolean);
+ EXPECT_TRUE(value->Equals(test_type->ToValue().get()));
+ }
+ {
+ scoped_ptr<TestType> test_type(new TestType());
+ scoped_ptr<DictionaryValue> value = CreateTestTypeDictionary();
+ value->RemoveWithoutPathExpansion("number", NULL);
+ EXPECT_FALSE(TestType::Populate(*value, test_type.get()));
+ }
+}
+
+TEST(JsonSchemaCompilerSimpleTest, GetTestType) {
+ scoped_ptr<DictionaryValue> value = CreateTestTypeDictionary();
+ scoped_ptr<TestType> test_type(new TestType());
+ EXPECT_TRUE(TestType::Populate(*value, test_type.get()));
+ scoped_ptr<Value> result(GetTestType::Result::Create(*test_type));
+ EXPECT_TRUE(value->Equals(result.get()));
+}
+
« no previous file with comments | « tools/json_schema_compiler/test/simple_api.json ('k') | tools/json_schema_compiler/util_cc_helper.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698