Sophie

Sophie

distrib > Fedora > 13 > i386 > by-pkgid > 2dc7ae7102ce788eb8a15dec0caf7708 > files > 350

xapian-core-devel-1.0.21-1.fc13.i686.rpm

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE>Xapian: Tests</TITLE>
</HEAD>
<BODY BGCOLOR="white" TEXT="black">

<H1>Tests</H1>

<H2>Contents</H2>

<ol>
<li> <A HREF="#running">A Brief Guide to Running Tests</A>
<li> <A HREF="#writing">A Brief Guide to Writing Tests</A>
<li> <A HREF="#quartz">Quartz Backend Tests</A>
</ol>

<H2><A NAME="running">A Brief Guide to Running Tests</A></H2>

<P>After a successful "<code>make</code>", try "<code>make check</code>".

<P>It's possible to run test cases individually, and get verbose output
when one fails, etc.  For more information, see the "Running test programs"
section of HACKING.

<H2><A NAME="writing">A Brief Guide to Writing Tests</A></H2>

<P>Test programs live in <code>tests/</code>.  They mostly use a standard test harness,
in <code>tests/harness/</code>, which wraps each test,
reports results, and generally packages things up nicely.  The test harness
counts how many testcases pass/fail/skip, catches signals and unhandled exceptions,
and so
forth.  It can also also check for memory leaks and accesses to
uninitialised values by making use of valgrind, for platforms which valgrind
supports (configure automatically enables use of valgrind if a suitably
recent version is detected).

<P>A typical test program has three parts: the tests themselves (at the top),
a table of tests (at the bottom), and a tiny main which sets the test harness
in motion.  It uses the table to figure out what the tests are called, and
what function to call to run them.

<P>The most important test system for most people will be <code>apitest</code>. This also
uses the test harness, but has several tables of tests to be run depending what
facilities each backend supports.  A lot of the work is done by macros and
helper functions, which may make it hard to work out quite what is going on,
but make life easier once you've grasped what's going on.  The <code>main()</code>
function and other
bits are in <code>apitest.cc</code>, and tests themselves are in various other C++ files
starting api_. Each one of these has its own tables for various different
groups of tests (eg: <code>api_db.cc</code>, which performs tests on the API that require a
database backend, has basic tests, a few specialised groups that only contain
one or two tests, tests that require a writable database, tests that require a
local database, and finally tests that require a remote database).

<P>To add a new api test, figure out what the test will be dependent on
and put it in the appropriate place (eg: if adding a test for a bug
that occurs while writing to a database, you want a writable
database, so you add a test to <code>api_db.cc</code> and reference it in the
<code>writabledb_tests</code> table).

<P>Currently, there's <code>api_nodb.cc</code> (no db required, largely testing query
construction and boundary conditions), <code>api_posdb.cc</code> (db with
positional information required) and <code>api_db.cc</code> (everything else, with
lots of subgroups of tests). It's easiest to base a test on an
existing one.

<P>You'll notice in <code>apitest.cc</code> that it runs all appropriate test groups against
each backend that is being built. The backends are inmemory,
quartz, flint, remote and remotetcp. If you need to create a new test group
with different
requirements to any current ones, put it in the appropriate api_ file (or
create a new one, and add it into Makefile.am) and remember to add the group to
all pertinent backends in <code>apitest.cc</code>.

<P>Incidentally, when fixing bugs, it's often better to write the test
before fixing the bug. Firstly, it's easier to assure yourself that
the bug is (a) genuine, and (b) fixed, because you see the test go
from fail to pass (though sometimes you don't get the testcase quite right,
so this isn't doesn't always work as well as it should).
Secondly you're more likely to write the test
carefully, because once you've fixed something there's often a feeling
that you should commit it for the good of the world, which tends to
distract you.

<H2><A NAME="quartz">Quartz Backend Tests</A></H2>

<P>Tests of the btree's functionality go in <code>tests/btreetest.cc</code>;
tests of quartz itself in <code>tests/quartztest.cc</code>.

<P>The framework is done for you, so you don't need to worry about that much.
You are responsible for doing two things:

<ol>
<li> writing a minimal test or tests for the feature
<li> adding that test to the list of tests to be run
</ol>

Adding the test is simple. There's a test_desc array in each file that comprises a
set of tests (I'll come to that in a minute), and you just add another
entry. The entry is an array consisting of a name for the test and a
pointer to the function that is the test. Easy.

<P>Look at the bottom of <code>tests/btreetest.cc</code> for the test_desc array. Now look up about
20 lines to where the test functions are defined.
You need to write a function like these which will return true or false
depending on whether it failed or not.

<P>In addition, there are a bunch of macros to help you perform standards testing
tasks. Things like
TEST_EQUAL are all in <code>tests/harness/testsuite.h</code>. They're pretty simple to
use.

<!-- FOOTER $Author: olly $ $Date: 2007-04-09 15:09:11 +0100 (Mon, 09 Apr 2007) $ $Id: tests.html 8160 2007-04-09 14:09:11Z olly $ -->
</BODY>
</HTML>