/** @file  psTest.h
 *
 *  Testing infrastructure functions.
 *
 *  @author Robert DeSonia, MHPCC
 *
 *  @version $Revision: 1.4 $ $Name: not supported by cvs2svn $
 *  @date $Date: 2005-06-17 00:10:55 $
 *
 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
 *
 */


#ifndef PSTEST_H
#define PSTEST_H

#include <stdio.h>

#include "psType.h"

#define printPositiveTestHeader(filePtr, packageName, testPointName) \
p_printPositiveTestHeader(filePtr, __FILE__, packageName, testPointName)

#define printNegativeTestHeader(filePtr, packageName, testPointName, expectedError, exitValue) \
p_printNegativeTestHeader(filePtr, __FILE__, packageName, testPointName, expectedError, exitValue)

#define printFooter(filePtr, packageName, testPointName, success) \
p_printFooter(filePtr, __FILE__, packageName, testPointName, success)

/** Specifies the format of a user-defined function for use with psTest functions. */
typedef psS32 (*testFcn)(void);

/** Defines a data structure containing test description information. */
typedef struct
{
    testFcn     fcn;                   ///< Specified test function
    psS32       testPointNumber;       ///< Test Point Number
    const char* testPointName;         ///< Test Point Name
    psS32       expectedReturn;        ///< Expected return value
    psBool      isDuplicateEntry;      ///< Is the entry a duplicate?
}
testDescription;

#define runTest(filePtr, packageName, testPointName, fcn, expectedReturn, useFork) \
p_runTest(filePtr, __FILE__, packageName, testPointName, fcn, expectedReturn, useFork)

#define runTestSuite(filePtr, packageName, tests, argc, argv) \
p_runTestSuite(filePtr, __FILE__, packageName, tests, argc, argv)


/////////////////////////// PRIVATE FUNCTIONS //////////////////////////////

///XXX: Comments correct?

/** Procedure used to run a test.
 *  
 *  @return psBool:    True if successful.
 */
psBool p_runTest(
    FILE *fp,                          ///< File to test
    const char* testPointFile,         ///< Test point in file
    const char* packageName,           ///< Package name
    const char* testPointName,         ///< Test point name
    testFcn fcn,                       ///< Function tested
    psS32 expectedReturn,              ///< Expected return
    psBool useFork                     ///< Fork to use
);

/** Procedure used to run the test suite.
 *  
 *  @return psBool:    True if successful. 
 */
psBool p_runTestSuite(
    FILE *fp,                          ///< File to test
    const char* testPointFile,         ///< Test point in file
    const char* packageName,           ///< Package name
    testDescription tests[],           ///< Description of tests
    psS32 argc,                        ///< Number of test arguments
    char * const argv[]                ///< Test arguments
);

/** Prints a positive test header to file */
void p_printPositiveTestHeader(
    FILE *fp,                          ///< File to which to print
    const char* testPointFile,         ///< Test point in file
    const char* packageName,           ///< Package name
    const char* testPointName          ///< Test point name
);

/** Prints a negative test header to file */
void p_printNegativeTestHeader(
    FILE *fp,                          ///< File to which to print
    const char* testPointFile,         ///< Test point in file
    const char* packageName,           ///< Package name
    const char* testPointName,         ///< Test point name
    const char* expectedError,         ///< Expected error
    psS32 exitValue                    ///< Exit value
);

/** Prints a footer to file */
void p_printFooter(
    FILE *fp,                          ///< File to which to print
    const char* testPointFile,         ///< Test point in file
    const char* packageName,           ///< Package name
    const char* testPointName,         ///< Test point name
    psBool success                     ///< True if successful
);

#endif // #ifndef PSTEST_H
