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

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

Issue 276603003: Support converting referenced enum array into string. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix win compile error Created 6 years, 7 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/arrays.json ('k') | tools/json_schema_compiler/util.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/json_schema_compiler/test/arrays_unittest.cc
diff --git a/tools/json_schema_compiler/test/arrays_unittest.cc b/tools/json_schema_compiler/test/arrays_unittest.cc
index 9aca730db38835fc5596b49b56cfdfc36f7113b9..817e51c27e64243e9ba5a426dc17db248af7772a 100644
--- a/tools/json_schema_compiler/test/arrays_unittest.cc
+++ b/tools/json_schema_compiler/test/arrays_unittest.cc
@@ -5,6 +5,7 @@
#include "tools/json_schema_compiler/test/arrays.h"
#include "testing/gtest/include/gtest/gtest.h"
+#include "tools/json_schema_compiler/test/enums.h"
using namespace test::api::arrays;
@@ -80,6 +81,87 @@ TEST(JsonSchemaCompilerArrayTest, EnumArrayType) {
EXPECT_TRUE(value.Equals(as_value.get())) << value << " != " << *as_value;
}
+TEST(JsonSchemaCompilerArrayTest, EnumArrayReference) {
+ // { "types": ["one", "two", "three"] }
+ base::ListValue* types = new base::ListValue();
+ types->AppendString("one");
+ types->AppendString("two");
+ types->AppendString("three");
+ base::DictionaryValue value;
+ value.Set("types", types);
+
+ EnumArrayReference enum_array_reference;
+
+ // Test Populate.
+ ASSERT_TRUE(EnumArrayReference::Populate(value, &enum_array_reference));
+
+ Enumeration expected_types[] = {ENUMERATION_ONE, ENUMERATION_TWO,
+ ENUMERATION_THREE};
+ EXPECT_EQ(std::vector<Enumeration>(
+ expected_types, expected_types + arraysize(expected_types)),
+ enum_array_reference.types);
+
+ // Test ToValue.
+ scoped_ptr<base::Value> as_value(enum_array_reference.ToValue());
+ EXPECT_TRUE(value.Equals(as_value.get())) << value << " != " << *as_value;
+}
+
+TEST(JsonSchemaCompilerArrayTest, EnumArrayMixed) {
+ // { "types": ["one", "two", "three"] }
+ base::ListValue* inline_enums = new base::ListValue();
+ inline_enums->AppendString("one");
+ inline_enums->AppendString("two");
+ inline_enums->AppendString("three");
+
+ base::ListValue* infile_enums = new base::ListValue();
+ infile_enums->AppendString("one");
+ infile_enums->AppendString("two");
+ infile_enums->AppendString("three");
+
+ base::ListValue* external_enums = new base::ListValue();
+ external_enums->AppendString("one");
+ external_enums->AppendString("two");
+ external_enums->AppendString("three");
+
+ base::DictionaryValue value;
+ value.Set("inline_enums", inline_enums);
+ value.Set("infile_enums", infile_enums);
+ value.Set("external_enums", external_enums);
+
+ EnumArrayMixed enum_array_mixed;
+
+ // Test Populate.
+ ASSERT_TRUE(EnumArrayMixed::Populate(value, &enum_array_mixed));
+
+ EnumArrayMixed::Inline_enumsType expected_inline_types[] = {
+ EnumArrayMixed::INLINE_ENUMS_TYPE_ONE,
+ EnumArrayMixed::INLINE_ENUMS_TYPE_TWO,
+ EnumArrayMixed::INLINE_ENUMS_TYPE_THREE};
+ EXPECT_EQ(std::vector<EnumArrayMixed::Inline_enumsType>(
+ expected_inline_types,
+ expected_inline_types + arraysize(expected_inline_types)),
+ enum_array_mixed.inline_enums);
+
+ Enumeration expected_infile_types[] = {ENUMERATION_ONE, ENUMERATION_TWO,
+ ENUMERATION_THREE};
+ EXPECT_EQ(std::vector<Enumeration>(
+ expected_infile_types,
+ expected_infile_types + arraysize(expected_infile_types)),
+ enum_array_mixed.infile_enums);
+
+ test::api::enums::Enumeration expected_external_types[] = {
+ test::api::enums::ENUMERATION_ONE, test::api::enums::ENUMERATION_TWO,
+ test::api::enums::ENUMERATION_THREE};
+ EXPECT_EQ(std::vector<test::api::enums::Enumeration>(
+ expected_external_types,
+ expected_external_types + arraysize(expected_external_types)),
+ enum_array_mixed.external_enums);
+
+ // Test ToValue.
+ scoped_ptr<base::Value> as_value(enum_array_mixed.ToValue());
+ EXPECT_TRUE(value.Equals(as_value.get())) << value << " != " << *as_value;
+}
+
TEST(JsonSchemaCompilerArrayTest, OptionalEnumArrayType) {
{
std::vector<OptionalEnumArrayType::TypesType> enums;
« no previous file with comments | « tools/json_schema_compiler/test/arrays.json ('k') | tools/json_schema_compiler/util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698