IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

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

added runTest and runTestSuite to the mix.

File:
1 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];
Note: See TracChangeset for help on using the changeset viewer.