Home | History | Annotate | Download | only in autofill
      1 // Copyright (c) 2011 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_BROWSER_AUTOFILL_DATA_DRIVEN_TEST_H_
      6 #define CHROME_BROWSER_AUTOFILL_DATA_DRIVEN_TEST_H_
      7 #pragma once
      8 
      9 #include <string>
     10 
     11 #include "base/file_path.h"
     12 #include "base/string16.h"
     13 
     14 // A convenience class for implementing data-driven tests. Subclassers need only
     15 // implement the conversion of serialized input data to serialized output data
     16 // and provide a set of input files. For each input file, on the first run, a
     17 // gold output file is generated; for subsequent runs, the test ouptut is
     18 // compared to this gold output.
     19 class DataDrivenTest {
     20  public:
     21   // For each file in |input_directory| whose filename matches
     22   // |file_name_pattern|, slurps in the file contents and calls into
     23   // |GenerateResults()|. If the corresponding output file already exists in
     24   // the |output_directory|, verifies that the results match the file contents;
     25   // otherwise, writes a gold result file to the |output_directory|.
     26   void RunDataDrivenTest(const FilePath& input_directory,
     27                          const FilePath& output_directory,
     28                          const FilePath::StringType& file_name_pattern);
     29 
     30   // Given the |input| data, generates the |output| results. The output results
     31   // must be stable across runs.
     32   // Note: The return type is |void| so that googletest |ASSERT_*| macros will
     33   // compile.
     34   virtual void GenerateResults(const std::string& input,
     35                                std::string* output) = 0;
     36 
     37   // Return |FilePath|s to the test input and output subdirectories
     38   // ../autofill/|test_name|/input and ../autofill/|test_name|/output.
     39   FilePath GetInputDirectory(const FilePath::StringType& test_name);
     40   FilePath GetOutputDirectory(const FilePath::StringType& test_name);
     41 
     42  protected:
     43   DataDrivenTest();
     44   virtual ~DataDrivenTest();
     45 
     46  private:
     47   DISALLOW_COPY_AND_ASSIGN(DataDrivenTest);
     48 };
     49 
     50 #endif  // CHROME_BROWSER_AUTOFILL_DATA_DRIVEN_TEST_H_
     51