| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "components/policy/core/common/schema.h" | 5 #include "components/policy/core/common/schema.h" |
| 6 | 6 |
| 7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
| 8 #include "base/strings/stringprintf.h" | 8 #include "base/strings/stringprintf.h" |
| 9 #include "components/policy/core/common/schema_internal.h" | 9 #include "components/policy/core/common/schema_internal.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
| (...skipping 392 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 403 { "Number", base::Value::TYPE_DOUBLE }, | 403 { "Number", base::Value::TYPE_DOUBLE }, |
| 404 { "Object", base::Value::TYPE_DICTIONARY }, | 404 { "Object", base::Value::TYPE_DICTIONARY }, |
| 405 { "ObjectOfArray", base::Value::TYPE_DICTIONARY }, | 405 { "ObjectOfArray", base::Value::TYPE_DICTIONARY }, |
| 406 { "ObjectOfObject", base::Value::TYPE_DICTIONARY }, | 406 { "ObjectOfObject", base::Value::TYPE_DICTIONARY }, |
| 407 { "ObjectWithPatternProperties", base::Value::TYPE_DICTIONARY }, | 407 { "ObjectWithPatternProperties", base::Value::TYPE_DICTIONARY }, |
| 408 { "String", base::Value::TYPE_STRING }, | 408 { "String", base::Value::TYPE_STRING }, |
| 409 { "StringWithEnums", base::Value::TYPE_STRING }, | 409 { "StringWithEnums", base::Value::TYPE_STRING }, |
| 410 { "StringWithPattern", base::Value::TYPE_STRING }, | 410 { "StringWithPattern", base::Value::TYPE_STRING }, |
| 411 }; | 411 }; |
| 412 Schema::Iterator it = schema.GetPropertiesIterator(); | 412 Schema::Iterator it = schema.GetPropertiesIterator(); |
| 413 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kExpectedProperties); ++i) { | 413 for (size_t i = 0; i < arraysize(kExpectedProperties); ++i) { |
| 414 ASSERT_FALSE(it.IsAtEnd()); | 414 ASSERT_FALSE(it.IsAtEnd()); |
| 415 EXPECT_STREQ(kExpectedProperties[i].expected_key, it.key()); | 415 EXPECT_STREQ(kExpectedProperties[i].expected_key, it.key()); |
| 416 ASSERT_TRUE(it.schema().valid()); | 416 ASSERT_TRUE(it.schema().valid()); |
| 417 EXPECT_EQ(kExpectedProperties[i].expected_type, it.schema().type()); | 417 EXPECT_EQ(kExpectedProperties[i].expected_type, it.schema().type()); |
| 418 it.Advance(); | 418 it.Advance(); |
| 419 } | 419 } |
| 420 EXPECT_TRUE(it.IsAtEnd()); | 420 EXPECT_TRUE(it.IsAtEnd()); |
| 421 } | 421 } |
| 422 | 422 |
| 423 TEST(SchemaTest, Lookups) { | 423 TEST(SchemaTest, Lookups) { |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 466 struct { | 466 struct { |
| 467 const char* expected_key; | 467 const char* expected_key; |
| 468 base::Value::Type expected_type; | 468 base::Value::Type expected_type; |
| 469 } kExpectedKeys[] = { | 469 } kExpectedKeys[] = { |
| 470 { "aa", base::Value::TYPE_BOOLEAN }, | 470 { "aa", base::Value::TYPE_BOOLEAN }, |
| 471 { "ab", base::Value::TYPE_DOUBLE }, | 471 { "ab", base::Value::TYPE_DOUBLE }, |
| 472 { "aba", base::Value::TYPE_INTEGER }, | 472 { "aba", base::Value::TYPE_INTEGER }, |
| 473 { "abab", base::Value::TYPE_STRING }, | 473 { "abab", base::Value::TYPE_STRING }, |
| 474 { "bb", base::Value::TYPE_NULL }, | 474 { "bb", base::Value::TYPE_NULL }, |
| 475 }; | 475 }; |
| 476 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kExpectedKeys); ++i) { | 476 for (size_t i = 0; i < arraysize(kExpectedKeys); ++i) { |
| 477 Schema sub = schema.GetKnownProperty(kExpectedKeys[i].expected_key); | 477 Schema sub = schema.GetKnownProperty(kExpectedKeys[i].expected_key); |
| 478 ASSERT_TRUE(sub.valid()); | 478 ASSERT_TRUE(sub.valid()); |
| 479 EXPECT_EQ(kExpectedKeys[i].expected_type, sub.type()); | 479 EXPECT_EQ(kExpectedKeys[i].expected_type, sub.type()); |
| 480 } | 480 } |
| 481 } | 481 } |
| 482 | 482 |
| 483 TEST(SchemaTest, Wrap) { | 483 TEST(SchemaTest, Wrap) { |
| 484 const internal::SchemaNode kSchemas[] = { | 484 const internal::SchemaNode kSchemas[] = { |
| 485 { base::Value::TYPE_DICTIONARY, 0 }, // 0: root node | 485 { base::Value::TYPE_DICTIONARY, 0 }, // 0: root node |
| 486 { base::Value::TYPE_BOOLEAN, -1 }, // 1 | 486 { base::Value::TYPE_BOOLEAN, -1 }, // 1 |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 552 { "Number", base::Value::TYPE_DOUBLE }, | 552 { "Number", base::Value::TYPE_DOUBLE }, |
| 553 { "String", base::Value::TYPE_STRING }, | 553 { "String", base::Value::TYPE_STRING }, |
| 554 { "List", base::Value::TYPE_LIST }, | 554 { "List", base::Value::TYPE_LIST }, |
| 555 { "IntEnum", base::Value::TYPE_INTEGER }, | 555 { "IntEnum", base::Value::TYPE_INTEGER }, |
| 556 { "RangedInt", base::Value::TYPE_INTEGER }, | 556 { "RangedInt", base::Value::TYPE_INTEGER }, |
| 557 { "StrEnum", base::Value::TYPE_STRING }, | 557 { "StrEnum", base::Value::TYPE_STRING }, |
| 558 { "StrPat", base::Value::TYPE_STRING }, | 558 { "StrPat", base::Value::TYPE_STRING }, |
| 559 }; | 559 }; |
| 560 | 560 |
| 561 Schema::Iterator it = schema.GetPropertiesIterator(); | 561 Schema::Iterator it = schema.GetPropertiesIterator(); |
| 562 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kExpectedProperties); ++i) { | 562 for (size_t i = 0; i < arraysize(kExpectedProperties); ++i) { |
| 563 ASSERT_FALSE(it.IsAtEnd()); | 563 ASSERT_FALSE(it.IsAtEnd()); |
| 564 EXPECT_STREQ(kExpectedProperties[i].key, it.key()); | 564 EXPECT_STREQ(kExpectedProperties[i].key, it.key()); |
| 565 Schema sub = it.schema(); | 565 Schema sub = it.schema(); |
| 566 ASSERT_TRUE(sub.valid()); | 566 ASSERT_TRUE(sub.valid()); |
| 567 EXPECT_EQ(kExpectedProperties[i].type, sub.type()); | 567 EXPECT_EQ(kExpectedProperties[i].type, sub.type()); |
| 568 | 568 |
| 569 if (sub.type() == base::Value::TYPE_LIST) { | 569 if (sub.type() == base::Value::TYPE_LIST) { |
| 570 Schema items = sub.GetItems(); | 570 Schema items = sub.GetItems(); |
| 571 ASSERT_TRUE(items.valid()); | 571 ASSERT_TRUE(items.valid()); |
| 572 EXPECT_EQ(base::Value::TYPE_STRING, items.type()); | 572 EXPECT_EQ(base::Value::TYPE_STRING, items.type()); |
| (...skipping 597 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1170 | 1170 |
| 1171 EXPECT_FALSE(ParseFails(SchemaObjectWrapper( | 1171 EXPECT_FALSE(ParseFails(SchemaObjectWrapper( |
| 1172 "{" | 1172 "{" |
| 1173 " \"type\": \"integer\"," | 1173 " \"type\": \"integer\"," |
| 1174 " \"minimum\": 10," | 1174 " \"minimum\": 10," |
| 1175 " \"maximum\": 20" | 1175 " \"maximum\": 20" |
| 1176 "}"))); | 1176 "}"))); |
| 1177 } | 1177 } |
| 1178 | 1178 |
| 1179 } // namespace policy | 1179 } // namespace policy |
| OLD | NEW |