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

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

Issue 9415001: Add tests to tools/json_schema_compiler (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: 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
Index: tools/json_schema_compiler/test/array_test.cc
diff --git a/tools/json_schema_compiler/test/array_test.cc b/tools/json_schema_compiler/test/array_test.cc
new file mode 100644
index 0000000000000000000000000000000000000000..a4f40008ae1a6607e225783cb0623e2f1b032fda
--- /dev/null
+++ b/tools/json_schema_compiler/test/array_test.cc
@@ -0,0 +1,93 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
not at google - send to devlin 2012/02/19 23:19:59 These files should all be _unittest.cc not _test.c
calamity 2012/02/20 05:03:37 Done.
+// 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/array.h"
+
+#include "testing/gtest/include/gtest/gtest.h"
+
+using namespace test::api::array;
+
+namespace {
+
+DictionaryValue* CreateBasicArrayTypeDictionary() {
+ DictionaryValue* value = new DictionaryValue();
+ ListValue* strings_value = new ListValue();
+ strings_value->Append(Value::CreateStringValue("a"));
+ strings_value->Append(Value::CreateStringValue("b"));
+ strings_value->Append(Value::CreateStringValue("c"));
not at google - send to devlin 2012/02/18 03:29:02 You're calling things like this a lot, and presuma
not at google - send to devlin 2012/02/19 23:19:59 Don't worry about this, I'm going to add it to bas
calamity 2012/02/20 05:03:37 Added a TODO for when your patch goes through.
+ strings_value->Append(Value::CreateStringValue("it's easy as"));
+ ListValue* integers_value = new ListValue();
+ integers_value->Append(Value::CreateIntegerValue(1));
+ integers_value->Append(Value::CreateIntegerValue(2));
+ integers_value->Append(Value::CreateIntegerValue(3));
+ ListValue* booleans_value = new ListValue();
+ booleans_value->Append(Value::CreateBooleanValue(false));
+ booleans_value->Append(Value::CreateBooleanValue(true));
+ ListValue* numbers_value = new ListValue();
+ numbers_value->Append(Value::CreateDoubleValue(6.1));
+ value->SetWithoutPathExpansion("numbers", numbers_value);
+ value->SetWithoutPathExpansion("booleans", booleans_value);
+ value->SetWithoutPathExpansion("strings", strings_value);
+ value->SetWithoutPathExpansion("integers", integers_value);
+ return value;
not at google - send to devlin 2012/02/18 03:29:02 Should return a scoped ptr
calamity 2012/02/20 05:03:37 Done.
+}
+
+Value* CreateItemValue(int val) {
+ scoped_ptr<DictionaryValue> value(new DictionaryValue());
not at google - send to devlin 2012/02/18 03:29:02 Heh, scoped_ptr here but not above? Do one or the
calamity 2012/02/20 05:03:37 Done.
+ value->SetWithoutPathExpansion("val", Value::CreateIntegerValue(val));
not at google - send to devlin 2012/02/18 03:29:02 Can definitely do just value->SetString("val", val
calamity 2012/02/20 05:03:37 Done.
+ return value.release();
+}
+
+} // namespace
+
+TEST(JsonSchemaCompilerArrayTest, BasicArrayType) {
+ {
+ scoped_ptr<DictionaryValue> value(CreateBasicArrayTypeDictionary());
+ scoped_ptr<BasicArrayType> basic_array_type(new BasicArrayType());
+ EXPECT_TRUE(BasicArrayType::Populate(*value, basic_array_type.get()));
+ EXPECT_TRUE(value->Equals(basic_array_type->ToValue().get()));
+ }
+}
+
+TEST(JsonSchemaCompilerArrayTest, RefArrayType) {
+ {
+ scoped_ptr<DictionaryValue> value(new DictionaryValue());
+ scoped_ptr<ListValue> ref_array(new ListValue());
+ ref_array->Append(CreateItemValue(1));
+ ref_array->Append(CreateItemValue(2));
+ ref_array->Append(CreateItemValue(3));
+ value->SetWithoutPathExpansion("refs", ref_array.release());
+ scoped_ptr<RefArrayType> ref_array_type(new RefArrayType());
+ EXPECT_TRUE(RefArrayType::Populate(*value, ref_array_type.get()));
+ EXPECT_EQ(1, ref_array_type->refs[0]->val);
not at google - send to devlin 2012/02/19 23:19:59 Should test size == 3 too (same elsewhere where ap
calamity 2012/02/20 05:03:37 Done.
+ EXPECT_EQ(2, ref_array_type->refs[1]->val);
+ EXPECT_EQ(3, ref_array_type->refs[2]->val);
+ }
+ {
+ scoped_ptr<DictionaryValue> value(new DictionaryValue());
+ scoped_ptr<ListValue> not_ref_array(new ListValue());
+ not_ref_array->Append(CreateItemValue(1));
+ not_ref_array->Append(Value::CreateIntegerValue(3));
+ value->SetWithoutPathExpansion("refs", not_ref_array.release());
+ scoped_ptr<RefArrayType> ref_array_type(new RefArrayType());
+ EXPECT_FALSE(RefArrayType::Populate(*value, ref_array_type.get()));
+ }
+}
+
+TEST(JsonSchemaCompilerArrayTest, IntegerArrayParamsCreate) {
+ {
not at google - send to devlin 2012/02/18 03:29:02 If you're only testing 1 atomic unit, probably no
calamity 2012/02/20 05:03:37 Done.
+ scoped_ptr<ListValue> params_value(new ListValue());
+ scoped_ptr<ListValue> integer_array(new ListValue());
+ integer_array->Append(Value::CreateIntegerValue(2));
+ integer_array->Append(Value::CreateIntegerValue(4));
+ integer_array->Append(Value::CreateIntegerValue(8));
+ params_value->Append(integer_array.release());
+ scoped_ptr<IntegerArray::Params> params(
+ IntegerArray::Params::Create(*params_value));
+ EXPECT_TRUE(params.get());
+ EXPECT_EQ(2, params->nums[0]);
+ EXPECT_EQ(4, params->nums[1]);
+ EXPECT_EQ(8, params->nums[2]);
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698