Changeset 1867 for trunk/psLib/test/sysUtils/tst_psError.c
- Timestamp:
- Sep 23, 2004, 11:59:16 AM (22 years ago)
- File:
-
- 1 edited
-
trunk/psLib/test/sysUtils/tst_psError.c (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/test/sysUtils/tst_psError.c
r1851 r1867 4 4 * 5 5 * This test driver contains the following test points for psError 6 * 1) Multiple type values in error message 7 * 2) String values in error message 8 * 3) Empty strings in error message 6 * testError00 - psError() 7 * testError01 - psErrorMsg(), psErrorStackPrint() 8 * testError02 - psErrorStackPrintV() 9 * testError03 - psErrorGet(), psErrorLast() 10 * testError04 - psErrorClear() 9 11 * 10 12 * @author Eric Van Alst, MHPCC 11 13 * 12 * @version $Revision: 1. 6$ $Name: not supported by cvs2svn $13 * @date $Date: 2004-09-2 2 23:47:09$14 * @version $Revision: 1.7 $ $Name: not supported by cvs2svn $ 15 * @date $Date: 2004-09-23 21:59:16 $ 14 16 * 15 17 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 23 25 24 26 static int testError00(void); 27 static int testError01(void); 28 static int testError02(void); 29 static int testError03(void); 30 static int testError04(void); 31 32 // Function used in testError02 to verify the psErrorStackPrintV function 33 static void myErrorStackPrint(FILE *fd, 34 const char *fmt, 35 ...) 36 { 37 va_list ap; 38 39 // Test whether psErrorStackPrintV() accept a va_list for output variables 40 va_start(ap, fmt); 41 psErrorStackPrintV(fd, fmt, ap); 42 va_end(ap); 43 } 25 44 26 45 testDescription tests[] = { 27 46 {testError00, 0, "psError()", 0, false}, 47 {testError01, 0, "psErrorMsg(),psErrorStackPrint()", 0, false}, 48 {testError02, 0, "psErrorStackPrintV()", 0, false}, 49 {testError03, 0, "psErrorGet(),psErrorLast()", 0, false}, 50 {testError04, 0, "psErrorClear()", 0, false}, 28 51 {NULL} 29 52 }; … … 34 57 35 58 return ( !runTestSuite(stderr, "psError", tests, argc, argv) ); 59 } 60 61 static int testError04(void) 62 { 63 psErrorCode code = PS_ERR_BAD_PARAMETER_VALUE; 64 psErr *last = NULL; 65 psErr *lastAfterClear = NULL; 66 67 // Generate three error messages 68 if (psErrorMsg("test3A", code, true, "Error code = %d", code) != code) { 69 psLogMsg("tst_psError03", PS_LOG_ERROR, "Failed return value verify."); 70 return 30; 71 } 72 if (psErrorMsg("test3A", (code+1), false, "Error code = %d", (code+1)) != (code+1)) { 73 psLogMsg("tst_psError03", PS_LOG_ERROR, "Failed return value verify."); 74 return 31; 75 } 76 if (psErrorMsg("test3A", (code+2), false, "Error code = %d", (code+2)) != (code+2)) { 77 psLogMsg("tst_psError03", PS_LOG_ERROR, "Failed return value verify."); 78 return 32; 79 } 80 81 // Get the last error message and verify it has the expected code 82 last = psErrorLast(); 83 if(last->code != (code+2)) { 84 psLogMsg("tst_psError04", PS_LOG_ERROR, "psErrorLast did not return expected."); 85 return 33; 86 } 87 psFree(last); 88 89 // Clear the error stack 90 psErrorClear(); 91 92 // Get the last error message after clear and verify is has PS_ERR_NONE code 93 lastAfterClear = psErrorLast(); 94 if(last->code != PS_ERR_NONE) { 95 psLogMsg("tst_psError05", PS_LOG_ERROR, "psErrorLaster did not return expected."); 96 return 34; 97 } 98 psFree(lastAfterClear); 99 100 return 0; 101 } 102 103 static int testError03(void) 104 { 105 psErrorCode code = PS_ERR_BAD_PARAMETER_VALUE; 106 psErr *last = NULL; 107 psErr *get 108 = NULL; 109 110 // Attempt to get last error message with an empty stack verify psErr with code PS_ERR_NONE 111 last = psErrorLast(); 112 if(last->code != PS_ERR_NONE) { 113 psLogMsg("tst_psError03", PS_LOG_ERROR, "psErrorLast did return PS_ERR_NONE for empty stack"); 114 return 20; 115 } 116 psFree(last); 117 118 // Attempt to get specific error message with empty stack verify psErr with code PS_ERR_NONE 119 get 120 = psErrorGet(2); 121 if(get 122 ->code != PS_ERR_NONE) { 123 psLogMsg("tst_psError03", PS_LOG_ERROR, "psErrorGet did not return PS_ERR_NONE for empty stack"); 124 return 21; 125 } 126 psFree(get 127 ); 128 129 // Attempt to get error message with invalid index and an empty stack 130 get 131 = psErrorGet(-1); 132 if(get 133 ->code != PS_ERR_NONE) { 134 psLogMsg("tst_psError03", PS_LOG_ERROR, "psErrorGet with invalid index/empty stack"); 135 return 22; 136 } 137 psFree(get 138 ); 139 140 // Generate three error messages 141 if (psErrorMsg("test3A", code, true, "Error code = %d", code) != code) { 142 psLogMsg("tst_psError03", PS_LOG_ERROR, "Failed return value verify."); 143 return 23; 144 } 145 if (psErrorMsg("test3A", (code+1), false, "Error code = %d", (code+1)) != (code+1)) { 146 psLogMsg("tst_psError03", PS_LOG_ERROR, "Failed return value verify."); 147 return 24; 148 } 149 if (psErrorMsg("test3A", (code+2), false, "Error code = %d", (code+2)) != (code+2)) { 150 psLogMsg("tst_psError03", PS_LOG_ERROR, "Failed return value verify."); 151 return 25; 152 } 153 154 last = psErrorLast(); 155 get 156 = psErrorGet(0); 157 158 // Check that last and get with 0 index are equal 159 if(last != get 160 ) { 161 psLogMsg("tst_psError03", PS_LOG_ERROR, "psErrorGet(0) not equal to psErrorLast"); 162 return 26; 163 } 164 psFree(last); 165 166 // Verify the last error message was returned 167 if ( last->code != (code+2) ) { 168 psLogMsg("tst_psError03", PS_LOG_ERROR, "psErrorLast() did not retrieve last error"); 169 return 27; 170 } 171 psFree(get 172 ); 173 174 // Verify the middle error message can be retrieved 175 get 176 = psErrorGet(1); 177 if ( get 178 ->code != (code+1)) { 179 psLogMsg("tst_psError03", PS_LOG_ERROR, "psErrorGet() did not retrieve proper error"); 180 return 28; 181 } 182 psFree(get 183 ); 184 185 // Verify the psErrorGet returns NULL if an invalid index is given 186 get 187 = psErrorGet(-1); 188 if ( get 189 ->code != PS_ERR_NONE ) { 190 psLogMsg("tst_psError03", PS_LOG_ERROR, "psErrorGet() did not return PS_ERR_NONE w/ invalid arg"); 191 return 29; 192 } 193 psFree(get 194 ); 195 196 return 0; 197 } 198 199 static int testError02(void) 200 { 201 psErrorCode code = PS_ERR_BAD_PARAMETER_VALUE; 202 203 // Generate error message and verify return value 204 if (psErrorMsg("test2A", code, true, "Error code = %d", code) != code ) { 205 psLogMsg("tst_psError02", PS_LOG_ERROR, "Failed return value verify."); 206 return 10; 207 } 208 myErrorStackPrint(stderr,"ERROR STACK PRINT Test%dA",2); 209 210 return 0; 211 } 212 213 static int testError01(void) 214 { 215 psErrorCode code=PS_ERR_BAD_PARAMETER_VALUE; 216 217 // Verify the return value of psErrorMsg is the psErrorCode passed 218 if ( psErrorMsg("test1A", code, true, "Error code = %d", code) != code) { 219 psLogMsg("tst_psError01", PS_LOG_ERROR, "Failed return value verify."); 220 return 1; 221 } 222 psErrorStackPrint(stderr,"ERROR STACK PRINT Test1A"); 223 224 // test1B empty string in for name argument 225 if ( psErrorMsg("", code+1, true, "Error code = %d", code+1) != code+1) { 226 psLogMsg("tst_psError01", PS_LOG_ERROR, "Failed return with empty string."); 227 return 2; 228 } 229 psErrorStackPrint(stderr,"ERROR STACK PRINT Test1B"); 230 231 // test1C null pointer in for name argument 232 if ( psErrorMsg(NULL, code+2, true, "Error code = %d", code+2) != code+2) { 233 psLogMsg("tst_psError01", PS_LOG_ERROR, "Failed return with null name arg."); 234 return 3; 235 } 236 psErrorStackPrint(stderr,"ERROR STACK PRINT Test1C"); 237 238 // test1D undefined code 239 if ( psErrorMsg("test1D", -1, true, "Error code = %d", -1) != -1) { 240 psLogMsg("test_psError01", PS_LOG_ERROR, "Failed return with undefined code."); 241 return 4; 242 } 243 psErrorStackPrint(stderr,"ERROR STACK PRINT Test1D"); 244 245 // test1E set psErrorMsg argument to false 246 if( psErrorMsg("test1E", code, false, "Error code = %d", code) != code) { 247 psLogMsg("test_psError01", PS_LOG_ERROR, "Failed return with false new arg."); 248 return 5; 249 } 250 psErrorStackPrint(stderr,"ERROR STACK PRINT Test1E"); 251 252 // Call psErrorMsg with 253 return 0; 36 254 } 37 255 … … 46 264 47 265 // Test point #1 Multiple type values placed in the error string 48 printPositiveTestHeader(stderr,"psError","Multiple type values in error message");49 266 psError(__func__, 50 267 "ALL TYPES intval = %d longval = %ld floatval = %f charval = %c strval = %s", 51 268 intval,longval,floatval,charval,stringval); 52 printFooter(stderr, "psError","Multiple type values in error message",true);53 269 54 270 // Test point #2 String values in error message 55 printPositiveTestHeader(stderr, "psError","String values in error message");56 271 psError(PS_STRING(__LINE__),"NO VALUES"); 57 printFooter(stderr, "psError","String values in error message",true);58 272 59 273 // Test point #3 Empty strings in error message 60 printPositiveTestHeader(stderr, "psError","Empty strings in error message");61 274 psError("",""); 62 printFooter(stderr, "psError","Empty strings in error message",true); 63 64 return 0; 65 } 66 275 276 return 0; 277 } 278
Note:
See TracChangeset
for help on using the changeset viewer.
