summaryrefslogtreecommitdiffstats
path: root/chrome/common/json_schema_validator_unittest.cc
blob: ca4b38803c177b4a836475d5d04e8ce61c25b50f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "base/values.h"
#include "chrome/common/json_schema_validator.h"
#include "chrome/common/json_schema_validator_unittest_base.h"
#include "testing/gtest/include/gtest/gtest.h"

class JSONSchemaValidatorCPPTest : public JSONSchemaValidatorTestBase {
 public:
  JSONSchemaValidatorCPPTest()
      : JSONSchemaValidatorTestBase(JSONSchemaValidatorTestBase::CPP) {
  }

 protected:
  virtual void ExpectValid(const std::string& test_source,
                           Value* instance, DictionaryValue* schema,
                           ListValue* types) {
    JSONSchemaValidator validator(schema, types);
    if (validator.Validate(instance))
      return;

    for (size_t i = 0; i < validator.errors().size(); ++i) {
      ADD_FAILURE() << test_source << ": "
                    << validator.errors()[i].path << ": "
                    << validator.errors()[i].message;
    }
  }

  virtual void ExpectNotValid(const std::string& test_source,
                              Value* instance, DictionaryValue* schema,
                              ListValue* types,
                              const std::string& expected_error_path,
                              const std::string& expected_error_message) {
    JSONSchemaValidator validator(schema, types);
    if (validator.Validate(instance)) {
      ADD_FAILURE() << test_source;
      return;
    }

    ASSERT_EQ(1u, validator.errors().size()) << test_source;
    EXPECT_EQ(expected_error_path, validator.errors()[0].path) << test_source;
    EXPECT_EQ(expected_error_message, validator.errors()[0].message)
        << test_source;
  }
};

TEST_F(JSONSchemaValidatorCPPTest, Test) {
  RunTests();
}