Changeset 538
- Timestamp:
- Apr 27, 2004, 4:31:54 PM (22 years ago)
- Location:
- trunk/psLib/test
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/test/psTest.c
r526 r538 11 11 // 12 12 13 14 #include <stdlib.h> 15 #include <unistd.h> 16 #include <sys/wait.h> 17 13 18 #include "psTest.h" 19 #include "psAbort.h" 14 20 15 21 #define HEADER_TOP "/----------------------------- TESTPOINT --------------------------------\\\n" … … 18 24 #define HEADER_BOTTOM "\\------------------------------------------------------------------------/\n\n" 19 25 20 void p_printPositiveTestHeader(FILE *fp, const char* testPointFile, const char* packageName, const char* testPointName) 26 bool 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 37 bool 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 60 void p_printPositiveTestHeader(FILE *fp, const char* testPointFile, const char* packageName, const char* 61 testPointName) 21 62 { 22 63 char TP[80]; -
trunk/psLib/test/psTest.h
r526 r538 15 15 p_printFooter(filePtr, __FILE__, packageName, testPointName, success) 16 16 17 typedef int (*testFcn)(void); 18 19 typedef struct 20 { 21 testFcn fcn; 22 const char* testPointName; 23 int expectedReturn; 24 } 25 testDescription; 26 27 #define runTest(filePtr, packageName, testPointName, fcn, expectedReturn) \ 28 p_runTest(filePtr, __FILE__, packageName, testPointName, fcn, expectedReturn) 29 30 #define runTestSuite(filePtr, packageName, tests) \ 31 p_runTestSuite(filePtr, __FILE__, packageName, tests) 32 17 33 18 34 /////////////////////////// PRIVATE FUNCTIONS ////////////////////////////// 19 35 20 void p_printPositiveTestHeader(FILE *fp, const char* testPointFile, const char* packageName, const char* testPointName); 36 bool p_runTest(FILE *fp, const char* testPointFile, const char* packageName, const char* testPointName, 37 testFcn fcn, int expectedReturn); 38 39 bool p_runTestSuite(FILE *fp, const char* testPointFile, const char* packageName, testDescription tests[]); 40 41 void p_printPositiveTestHeader(FILE *fp, const char* testPointFile, const char* packageName, 42 const char* testPointName); 21 43 22 44 void p_printNegativeTestHeader(FILE *fp, const char* testPointFile, const char* packageName, 23 45 const char* testPointName,const char* expectedError, int exitValue); 24 46 25 void p_printFooter(FILE *fp, const char* testPointFile, const char* packageName, const char* testPointName, bool 26 success); 47 void p_printFooter(FILE *fp, const char* testPointFile, const char* packageName, const char* testPointName, 48 bool success); 49 27 50 #endif
Note:
See TracChangeset
for help on using the changeset viewer.
