Home | History | Annotate | Download | only in common
      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 #ifndef CHROME_COMMON_JSON_SCHEMA_VALIDATOR_UNITTEST_BASE_H_
      6 #define CHROME_COMMON_JSON_SCHEMA_VALIDATOR_UNITTEST_BASE_H_
      7 
      8 #include "testing/gtest/include/gtest/gtest.h"
      9 
     10 class DictionaryValue;
     11 class ListValue;
     12 class Value;
     13 
     14 // Base class for unit tests for JSONSchemaValidator. There is currently only
     15 // one implementation, JSONSchemaValidatorCPPTest.
     16 //
     17 // TODO(aa): Refactor chrome/test/data/json_schema_test.js into
     18 // JSONSchemaValidatorJSTest that inherits from this.
     19 class JSONSchemaValidatorTestBase : public testing::Test {
     20  public:
     21   enum ValidatorType {
     22     CPP = 1,
     23     JS = 2
     24   };
     25 
     26   explicit JSONSchemaValidatorTestBase(ValidatorType type);
     27 
     28   void RunTests();
     29 
     30  protected:
     31   virtual void ExpectValid(const std::string& test_source,
     32                            Value* instance, DictionaryValue* schema,
     33                            ListValue* types) = 0;
     34 
     35   virtual void ExpectNotValid(const std::string& test_source,
     36                               Value* instance, DictionaryValue* schema,
     37                               ListValue* types,
     38                               const std::string& expected_error_path,
     39                               const std::string& expected_error_message) = 0;
     40 
     41  private:
     42   void TestComplex();
     43   void TestStringPattern();
     44   void TestEnum();
     45   void TestChoices();
     46   void TestExtends();
     47   void TestObject();
     48   void TestTypeReference();
     49   void TestArrayTuple();
     50   void TestArrayNonTuple();
     51   void TestString();
     52   void TestNumber();
     53   void TestTypeClassifier();
     54   void TestTypes();
     55 
     56   ValidatorType type_;
     57 };
     58 
     59 #endif  // CHROME_COMMON_JSON_SCHEMA_VALIDATOR_UNITTEST_BASE_H_
     60