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
3 // found in the LICENSE file.
5 #ifndef COMPONENTS_AUTOFILL_CORE_BROWSER_DATA_DRIVEN_TEST_H_
6 #define COMPONENTS_AUTOFILL_CORE_BROWSER_DATA_DRIVEN_TEST_H_
10 #include "base/files/file_path.h"
11 #include "base/strings/string16.h"
15 // A convenience class for implementing data-driven tests. Subclassers need only
16 // implement the conversion of serialized input data to serialized output data
17 // and provide a set of input files. For each input file, on the first run, a
18 // gold output file is generated; for subsequent runs, the test ouptut is
19 // compared to this gold output.
20 class DataDrivenTest
{
22 // For each file in |input_directory| whose filename matches
23 // |file_name_pattern|, slurps in the file contents and calls into
24 // |GenerateResults()|. If the corresponding output file already exists in
25 // the |output_directory|, verifies that the results match the file contents;
26 // otherwise, writes a gold result file to the |output_directory|.
27 void RunDataDrivenTest(const base::FilePath
& input_directory
,
28 const base::FilePath
& output_directory
,
29 const base::FilePath::StringType
& file_name_pattern
);
31 // Given the |input| data, generates the |output| results. The output results
32 // must be stable across runs.
33 // Note: The return type is |void| so that googletest |ASSERT_*| macros will
35 virtual void GenerateResults(const std::string
& input
,
36 std::string
* output
) = 0;
38 // Return |base::FilePath|s to the test input and output subdirectories
39 // ../autofill/|test_name|/input and ../autofill/|test_name|/output.
40 base::FilePath
GetInputDirectory(const base::FilePath::StringType
& test_name
);
41 base::FilePath
GetOutputDirectory(
42 const base::FilePath::StringType
& test_name
);
45 DataDrivenTest(const base::FilePath
& test_data_directory
);
46 virtual ~DataDrivenTest();
49 base::FilePath test_data_directory_
;
51 DISALLOW_COPY_AND_ASSIGN(DataDrivenTest
);
54 } // namespace autofill
56 #endif // COMPONENTS_AUTOFILL_CORE_BROWSER_DATA_DRIVEN_TEST_H_