FileTestContext Class Reference

#include <FileTestContext.h>

Inheritance diagram for FileTestContext:

SipDbTestContext RegistrationDbTestContext

List of all members.


Detailed Description

Utilities for redirecting file resources during unit tests.

This class and its subclasses abstract the locations of files that would normally be hardcoded so that tests can use locations in the build tree and provide different input sets for each test.

A typical test that reads and writes files can declare a FileTestContext so that the input files are copied from the source tree to the build tree, possibly modified along the way by a TemplateConverter supplied by the test or some subclass of FileTestContext. Typically the paths to the source and build tree will be provided from the build environment.

Note:
The working directory will be deleted and recreated, so it must not be in the source tree.

Public Member Functions

 FileTestContext (const char *testInputDir, const char *testWorkingDir)
 Define a context for a test or set of tests.
virtual void inputFile (const char *filename)
 Get a file from the testInputDir, copy into testWorkingDir.
typedef void TemplateConverter (OsFile *templateFile, OsFile *workingFile)
 Helper function provided by a test for converting a template to a working file.
virtual void workingFileFromTemplate (const char *templateName, TemplateConverter *converter, const char *filename=NULL)
 The template in the testInputDir and the filename in testWorkingDir are opened, and then both files are passed to the converter.
virtual void removeWorkingFile (const char *filename)
 Delete any existing copy of the file in the testWorkingDir.
void inputFilePath (const char *filename, UtlString &path)
 Convert a file name to a full path name in the input directory.
void workingFilePath (const char *filename, UtlString &path)
 Convert a file name to a full path name in the working directory.
void setSipxDir (DirectoryType dirType, const char *subDir=NULL)
 Set the environment so that the SipXecsService paths are resolved to the context.
virtual ~FileTestContext ()
 Destructor.

Protected Member Functions

virtual void makeCleanWorkingDir ()

Protected Attributes

UtlString mTestInputDir
UtlString mTestWorkingDir

Private Member Functions

 FileTestContext (const FileTestContext &)
 There is no copy constructor.
FileTestContextoperator= (const FileTestContext &)
 There is no assignment operator.

Constructor & Destructor Documentation

FileTestContext ( const char *  testInputDir,
const char *  testWorkingDir 
)

Define a context for a test or set of tests.

Deletes all files and directories in the testWorkingDir.

The directories are:

  • testInputDir holds all the input files for the test. Each input file is copied to the working directory using inputFile or inputFileFromTemplate. Normally a path to somewhere in the src tree. In the autotools build, most tests provided this from the cpp command line as TEST_DATA_DIR.

  • testWorkingDir holds the files for a single FileTestContext. Normally set to a directory in the build tree or some tmp location unique to the test. This is set to be the directory where sipdb expects to find database .xml files and the sipdb working files. In the autotools build, most tests provided this from the cpp command line as TEST_WORK_DIR.
Parameters:
testInputDir  directory for test input & template files
testWorkingDir  directory for test working files.

virtual ~FileTestContext (  )  [virtual]

Destructor.

FileTestContext ( const FileTestContext  )  [private]

There is no copy constructor.


Member Function Documentation

virtual void inputFile ( const char *  filename  )  [virtual]

Get a file from the testInputDir, copy into testWorkingDir.

Reimplemented in RegistrationDbTestContext.

typedef void TemplateConverter ( OsFile *  templateFile,
OsFile *  workingFile 
)

Helper function provided by a test for converting a template to a working file.

This is provided by a test and called by workingFileFromTemplate. When called, the templateFile is already opened for reading, and the workingFile is already opened for writing.

Parameters:
templateFile  input
workingFile  output

virtual void workingFileFromTemplate ( const char *  templateName,
TemplateConverter *  converter,
const char *  filename = NULL 
) [virtual]

The template in the testInputDir and the filename in testWorkingDir are opened, and then both files are passed to the converter.

The converter is responsible for reading the template and writing the filename.

If no filename is supplied, its name is the same as the templateName.

Parameters:
templateName  testInputDir file
converter  conversion function
filename  testWorkingDir file

virtual void removeWorkingFile ( const char *  filename  )  [virtual]

Delete any existing copy of the file in the testWorkingDir.

void inputFilePath ( const char *  filename,
UtlString path 
)

Convert a file name to a full path name in the input directory.

void workingFilePath ( const char *  filename,
UtlString path 
)

Convert a file name to a full path name in the working directory.

void setSipxDir ( DirectoryType  dirType,
const char *  subDir = NULL 
)

Set the environment so that the SipXecsService paths are resolved to the context.

Parameters:
subDir  a subdirectory of the working directory.

virtual void makeCleanWorkingDir (  )  [protected, virtual]

FileTestContext& operator= ( const FileTestContext  )  [private]

There is no assignment operator.


Member Data Documentation

UtlString mTestInputDir [protected]


Online Library Docs

sipXecs home page

Version 4.2.1-018930 2010-07-31T01:13:23 build16 abuild