IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 538


Ignore:
Timestamp:
Apr 27, 2004, 4:31:54 PM (22 years ago)
Author:
desonia
Message:

added runTest and runTestSuite to the mix.

Location:
trunk/psLib/test
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/psLib/test/psTest.c

    r526 r538  
    1111//
    1212
     13
     14#include <stdlib.h>
     15#include <unistd.h>
     16#include <sys/wait.h>
     17
    1318#include "psTest.h"
     19#include "psAbort.h"
    1420
    1521#define HEADER_TOP    "/----------------------------- TESTPOINT --------------------------------\\\n"
     
    1824#define HEADER_BOTTOM "\\------------------------------------------------------------------------/\n\n"
    1925
    20 void p_printPositiveTestHeader(FILE *fp, const char* testPointFile, const char* packageName, const char* testPointName)
     26bool p_runTestSuite(FILE *fp, const char* testPointFile, const char* packageName, testDescription tests[])
     27{
     28    bool failed = false;
     29
     30    for (int index=0; tests[index].fcn != NULL; index++) {
     31        failed = failed || p_runTest(fp,testPointFile,packageName,tests[index].testPointName,
     32                                     tests[index].fcn,tests[index].expectedReturn);
     33    }
     34    return failed;
     35}
     36
     37bool p_runTest(FILE *fp, const char* testPointFile, const char* packageName, const char* testPointName,
     38               testFcn fcn, int expectedReturn)
     39{
     40    int childReturn = 0;
     41    pid_t child;
     42
     43    p_printPositiveTestHeader(fp,testPointFile,packageName,testPointName);
     44
     45    child = fork();
     46    if (child == 0) {                   // I am the child process, run the test
     47        exit(fcn());
     48    } else if (child < 0) {
     49        psAbort(testPointFile,"Couldn't fork a process to run a negative test (%s|%s)", packageName,
     50                testPointName);
     51    }
     52
     53    wait(&childReturn);
     54
     55    p_printFooter(fp,testPointFile,packageName,testPointName, (childReturn==expectedReturn));
     56
     57    return (childReturn==expectedReturn);
     58}
     59
     60void p_printPositiveTestHeader(FILE *fp, const char* testPointFile, const char* packageName, const char*
     61                               testPointName)
    2162{
    2263    char TP[80];
  • trunk/psLib/test/psTest.h

    r526 r538  
    1515p_printFooter(filePtr, __FILE__, packageName, testPointName, success)
    1616
     17typedef int (*testFcn)(void);
     18
     19typedef struct
     20{
     21    testFcn     fcn;
     22    const char* testPointName;
     23    int         expectedReturn;
     24}
     25testDescription;
     26
     27#define runTest(filePtr, packageName, testPointName, fcn, expectedReturn) \
     28p_runTest(filePtr, __FILE__, packageName, testPointName, fcn, expectedReturn)
     29
     30#define runTestSuite(filePtr, packageName, tests) \
     31p_runTestSuite(filePtr, __FILE__, packageName, tests)
     32
    1733
    1834/////////////////////////// PRIVATE FUNCTIONS //////////////////////////////
    1935
    20 void p_printPositiveTestHeader(FILE *fp, const char* testPointFile, const char* packageName, const char* testPointName);
     36bool p_runTest(FILE *fp, const char* testPointFile, const char* packageName, const char* testPointName,
     37               testFcn fcn, int expectedReturn);
     38
     39bool p_runTestSuite(FILE *fp, const char* testPointFile, const char* packageName, testDescription tests[]);
     40
     41void p_printPositiveTestHeader(FILE *fp, const char* testPointFile, const char* packageName,
     42                               const char* testPointName);
    2143
    2244void p_printNegativeTestHeader(FILE *fp, const char* testPointFile, const char* packageName,
    2345                               const char* testPointName,const char* expectedError, int exitValue);
    2446
    25 void p_printFooter(FILE *fp, const char* testPointFile, const char* packageName, const char* testPointName, bool
    26                    success);
     47void p_printFooter(FILE *fp, const char* testPointFile, const char* packageName, const char* testPointName,
     48                   bool success);
     49
    2750#endif
Note: See TracChangeset for help on using the changeset viewer.