test_driver Class Reference

The test driver. This class takes care of running the tests. More...

#include <testsuite.h>

Collaboration diagram for test_driver:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 XAPIAN_NORETURN (static void usage())
 test_driver (const test_desc *tests_)
 The constructor, which sets up the test driver.
result run_tests ()
 Run all the tests supplied and return the results.
result run_tests (std::vector< std::string >::const_iterator b, std::vector< std::string >::const_iterator e)
 Run the tests in the list and return the results.

Static Public Member Functions

static void add_command_line_option (const std::string &l, char s, std::string *arg)
 Add a test-specific command line option.
static void parse_command_line (int argc, char **argv)
 Parse the command line arguments.
static int run (const test_desc *tests)
static std::string get_srcdir ()
 Read srcdir from environment and if not present, make a valiant attempt to guess a value.
static void report (const test_driver::result &r, const std::string &desc)
 Print summary of tests passed, failed, and skipped.

Static Public Attributes

static result subtotal
static result total

Private Types

enum  test_result { PASS = 1, FAIL = 0, SKIP = -1 }

Private Member Functions

 test_driver (const test_driver &)
 Prevent copying.
test_driveroperator= (const test_driver &)
test_result runtest (const test_desc *test)
 Runs the test function and returns its result.
result do_run_tests (std::vector< std::string >::const_iterator b, std::vector< std::string >::const_iterator e)
 The implementation used by run_tests.

Private Attributes

std::ostream out
const test_desctests

Static Private Attributes

static std::map< int, std::string * > short_opts
static std::string opt_help
static std::vector< std::string > test_names
static bool abort_on_error = false
static int runs = 0
static std::string argv0
static std::string col_red
static std::string col_green
static std::string col_yellow
static std::string col_reset
static bool use_cr = false

Classes

struct  result
 A structure used to report the summary of tests passed and failed. More...

Detailed Description

The test driver. This class takes care of running the tests.

Definition at line 94 of file testsuite.h.


Member Enumeration Documentation

enum test_driver::test_result [private]

Enumerator:
PASS 
FAIL 
SKIP 

Definition at line 181 of file testsuite.h.


Constructor & Destructor Documentation

test_driver::test_driver ( const test_desc tests_  ) 

The constructor, which sets up the test driver.

Parameters:
tests The zero-terminated array of tests to run.

Definition at line 150 of file testsuite.cc.

test_driver::test_driver ( const test_driver  )  [private]

Prevent copying.


Member Function Documentation

static void test_driver::add_command_line_option ( const std::string &  l,
char  s,
std::string *  arg 
) [static]

Add a test-specific command line option.

The recognised option will be described as:

-<s>=<l>

And any value set will be put into arg.

Referenced by main().

void test_driver::parse_command_line ( int  argc,
char **  argv 
) [static]

Parse the command line arguments.

Parameters:
argc The argument count passed into main()
argv The argument list passed into main()

Definition at line 616 of file testsuite.cc.

References abort_on_error, argv0, col_green, col_red, col_reset, col_yellow, DEBUGLINE, gnu_getopt_long(), long_opts, no_argument, Xapian::Remote::open(), optarg, optind, opts, short_opts, test_names, unlink(), use_cr, and verbose.

Referenced by main().

test_driver::XAPIAN_NORETURN ( static void   usage()  ) 

int test_driver::run ( const test_desc tests  )  [static]

Definition at line 706 of file testsuite.cc.

References test_driver::result::failed, run_tests(), subtotal, test_names, and tests.

Referenced by if(), and main().

test_driver::result test_driver::run_tests (  ) 

Run all the tests supplied and return the results.

Definition at line 498 of file testsuite.cc.

References do_run_tests().

Referenced by run().

result test_driver::run_tests ( std::vector< std::string >::const_iterator  b,
std::vector< std::string >::const_iterator  e 
)

Run the tests in the list and return the results.

string test_driver::get_srcdir (  )  [static]

Read srcdir from environment and if not present, make a valiant attempt to guess a value.

Definition at line 103 of file testsuite.cc.

References argv0, endswith(), file_exists(), srcdir, and startswith().

Referenced by DEFINE_TESTCASE(), and main().

static void test_driver::report ( const test_driver::result r,
const std::string &  desc 
) [static]

Print summary of tests passed, failed, and skipped.

Referenced by report_totals().

test_driver& test_driver::operator= ( const test_driver  )  [private]

test_driver::test_result test_driver::runtest ( const test_desc test  )  [private]

Runs the test function and returns its result.

It will also trap exceptions and some memory leaks and force a failure in those cases.

Parameters:
test A description of the test to run.

Definition at line 218 of file testsuite.cc.

References SignalRedirector::activate(), col_red, col_reset, col_yellow, dummy, expected_exception, FAIL, Xapian::Error::get_description(), Xapian::Error::get_type(), jb, out, PASS, test_desc::run, signum, SKIP, tout, and verbose.

result test_driver::do_run_tests ( std::vector< std::string >::const_iterator  b,
std::vector< std::string >::const_iterator  e 
) [private]

The implementation used by run_tests.

it runs test(s) (with runtest()), prints out messages for the user, and tracks the successes and failures.

Parameters:
b,e If b != e, a vector of the test(s) to run. If b == e, all tests will be run.

Referenced by run_tests().


Member Data Documentation

test_driver::result test_driver::subtotal [static]

Definition at line 168 of file testsuite.h.

Referenced by run().

test_driver::result test_driver::total [static]

Definition at line 171 of file testsuite.h.

Referenced by report_totals().

map< int, string * > test_driver::short_opts [static, private]

Definition at line 183 of file testsuite.h.

Referenced by parse_command_line().

string test_driver::opt_help [static, private]

Definition at line 185 of file testsuite.h.

vector< string > test_driver::test_names [static, private]

Definition at line 187 of file testsuite.h.

Referenced by parse_command_line(), and run().

bool test_driver::abort_on_error = false [static, private]

Definition at line 208 of file testsuite.h.

Referenced by parse_command_line().

std::ostream test_driver::out [private]

Definition at line 211 of file testsuite.h.

Referenced by runtest().

const test_desc* test_driver::tests [private]

Definition at line 214 of file testsuite.h.

Referenced by run().

int test_driver::runs = 0 [static, private]

Definition at line 217 of file testsuite.h.

string test_driver::argv0 [static, private]

Definition at line 220 of file testsuite.h.

Referenced by get_srcdir(), and parse_command_line().

string test_driver::col_red [static, private]

Definition at line 223 of file testsuite.h.

Referenced by parse_command_line(), and runtest().

string test_driver::col_green [static, private]

Definition at line 223 of file testsuite.h.

Referenced by parse_command_line().

string test_driver::col_yellow [static, private]

Definition at line 223 of file testsuite.h.

Referenced by parse_command_line(), and runtest().

string test_driver::col_reset [static, private]

Definition at line 223 of file testsuite.h.

Referenced by parse_command_line(), and runtest().

bool test_driver::use_cr = false [static, private]

Definition at line 227 of file testsuite.h.

Referenced by parse_command_line().


The documentation for this class was generated from the following files:
Documentation for Xapian (version 1.0.10).
Generated on 24 Dec 2008 by Doxygen 1.5.2.