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

Side by Side Diff: chrome/common/json_schema_validator_unittest.cc

Issue 4673001: Implements a C++ version of JSONSchemaValidator. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: more tests Created 10 years, 1 month 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 | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2010 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 "base/logging.h"
6 #include "base/values.h"
7 #include "chrome/common/json_schema_validator.h"
8 #include "chrome/common/json_schema_validator_unittest_base.h"
9 #include "testing/gtest/include/gtest/gtest.h"
10
11 class JSONSchemaValidatorCPPTest : public JSONSchemaValidatorTestBase {
12 public:
13 JSONSchemaValidatorCPPTest()
14 : JSONSchemaValidatorTestBase(JSONSchemaValidatorTestBase::CPP) {
15 }
16
17 protected:
18 virtual void ExpectValid(const std::string& test_source,
19 Value* instance, DictionaryValue* schema,
20 ListValue* types) {
21 JSONSchemaValidator validator(schema, types);
22 if (validator.Validate(instance))
23 return;
24
25 for (size_t i = 0; i < validator.errors().size(); ++i) {
26 ADD_FAILURE() << test_source << ": "
27 << validator.errors()[i].path << ": "
28 << validator.errors()[i].message;
29 }
30 }
31
32 virtual void ExpectNotValid(const std::string& test_source,
33 Value* instance, DictionaryValue* schema,
34 ListValue* types,
35 const std::string& expected_error_path,
36 const std::string& expected_error_message) {
37 JSONSchemaValidator validator(schema, types);
38 if (validator.Validate(instance)) {
39 ADD_FAILURE() << test_source;
40 return;
41 }
42
43 // TODO(aa): Remove this.
44 if (validator.errors().size() > 1u) {
45 for (size_t i = 0; i < validator.errors().size(); ++i) {
46 LOG(ERROR) << validator.errors()[i].message;
47 }
48 }
49
50 ASSERT_EQ(1u, validator.errors().size()) << test_source;
51 EXPECT_EQ(expected_error_path, validator.errors()[0].path) << test_source;
52 EXPECT_EQ(expected_error_message, validator.errors()[0].message) << test_sou rce;
53
54 // TODO(aa): Remove this.
55 LOG(ERROR) << validator.errors()[0].message;
56 }
57 };
58
59 TEST_F(JSONSchemaValidatorCPPTest, Test) {
60 RunTests();
61 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698