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

Side by Side 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 unified diff | Download patch
OLDNEW
(Empty)
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 "tools/json_schema_compiler/test/simple_api.h"
6
7 #include "testing/gtest/include/gtest/gtest.h"
8
9 using namespace test::api::simple_api;
10
11 namespace {
12
13 static scoped_ptr<DictionaryValue> CreateTestTypeDictionary() {
14 scoped_ptr<DictionaryValue> value(new DictionaryValue());
15 value->SetWithoutPathExpansion("number", Value::CreateDoubleValue(1.1));
16 value->SetWithoutPathExpansion("integer", Value::CreateIntegerValue(4));
17 value->SetWithoutPathExpansion("string", Value::CreateStringValue("bling"));
18 value->SetWithoutPathExpansion("boolean", Value::CreateBooleanValue(true));
19 return value.Pass();
20 }
21
22 } // namespace
23
24 TEST(JsonSchemaCompilerSimpleTest, IncrementIntegerResultCreate) {
25 scoped_ptr<Value> result(IncrementInteger::Result::Create(5));
26 int temp = 0;
27 EXPECT_TRUE(result->GetAsInteger(&temp));
28 EXPECT_EQ(5, temp);
29 }
30
31 TEST(JsonSchemaCompilerSimpleTest, IncrementIntegerParamsCreate) {
32 scoped_ptr<ListValue> params_value(new ListValue());
33 params_value->Append(Value::CreateIntegerValue(6));
34 scoped_ptr<IncrementInteger::Params> params(
35 IncrementInteger::Params::Create(*params_value));
36 EXPECT_TRUE(params.get());
37 EXPECT_EQ(6, params->num);
38 }
39
40 TEST(JsonSchemaCompilerSimpleTest, OptionalStringParamsCreate) {
41 {
42 scoped_ptr<ListValue> params_value(new ListValue());
43 scoped_ptr<OptionalString::Params> params(
44 OptionalString::Params::Create(*params_value));
45 EXPECT_TRUE(params.get());
46 EXPECT_FALSE(params->str.get());
47 }
48 {
49 scoped_ptr<ListValue> params_value(new ListValue());
50 params_value->Append(Value::CreateStringValue("asdf"));
51 scoped_ptr<OptionalString::Params> params(
52 OptionalString::Params::Create(*params_value));
53 EXPECT_TRUE(params.get());
54 EXPECT_TRUE(params->str.get());
55 EXPECT_EQ("asdf", *params->str);
56 }
57 }
58
59 TEST(JsonSchemaCompilerSimpleTest, OptionalParamsTakingNull) {
60 {
61 scoped_ptr<ListValue> params_value(new ListValue());
62 params_value->Append(Value::CreateNullValue());
63 scoped_ptr<OptionalString::Params> params(
64 OptionalString::Params::Create(*params_value));
65 EXPECT_TRUE(params.get());
66 EXPECT_FALSE(params->str.get());
67 }
68 }
69
70 TEST(JsonSchemaCompilerSimpleTest, OptionalStringParamsWrongType) {
71 {
72 scoped_ptr<ListValue> params_value(new ListValue());
73 params_value->Append(Value::CreateIntegerValue(5));
74 scoped_ptr<OptionalString::Params> params(
75 OptionalString::Params::Create(*params_value));
76 EXPECT_FALSE(params.get());
77 }
78 }
79
80 TEST(JsonSchemaCompilerSimpleTest, NoParamsResultCreate) {
81 EXPECT_TRUE(Value::Equals(OptionalString::Result::Create(),
82 Value::CreateNullValue()));
83 }
84
85 TEST(JsonSchemaCompilerSimpleTest, TestTypePopulate) {
86 {
87 scoped_ptr<TestType> test_type(new TestType());
88 scoped_ptr<DictionaryValue> value = CreateTestTypeDictionary();
89 EXPECT_TRUE(TestType::Populate(*value, test_type.get()));
90 EXPECT_EQ("bling", test_type->string);
91 EXPECT_EQ(1.1, test_type->number);
92 EXPECT_EQ(4, test_type->integer);
93 EXPECT_EQ(true, test_type->boolean);
94 EXPECT_TRUE(value->Equals(test_type->ToValue().get()));
95 }
96 {
97 scoped_ptr<TestType> test_type(new TestType());
98 scoped_ptr<DictionaryValue> value = CreateTestTypeDictionary();
99 value->RemoveWithoutPathExpansion("number", NULL);
100 EXPECT_FALSE(TestType::Populate(*value, test_type.get()));
101 }
102 }
103
104 TEST(JsonSchemaCompilerSimpleTest, GetTestType) {
105 scoped_ptr<DictionaryValue> value = CreateTestTypeDictionary();
106 scoped_ptr<TestType> test_type(new TestType());
107 EXPECT_TRUE(TestType::Populate(*value, test_type.get()));
108 scoped_ptr<Value> result(GetTestType::Result::Create(*test_type));
109 EXPECT_TRUE(value->Equals(result.get()));
110 }
111
OLDNEW
« 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