Changeset 12781 for trunk/psLib/test/sys
- Timestamp:
- Apr 10, 2007, 11:09:31 AM (19 years ago)
- Location:
- trunk/psLib/test/sys
- Files:
-
- 7 edited
-
tap_psConfigure.c (modified) (2 diffs)
-
tap_psError.c (modified) (3 diffs)
-
tap_psLine.c (modified) (2 diffs)
-
tap_psMemory.c (modified) (5 diffs)
-
tap_psString.c (modified) (3 diffs)
-
tap_psStringSubstitute.c (modified) (2 diffs)
-
tap_psTrace.c (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/test/sys/tap_psConfigure.c
r11685 r12781 11 11 * @author Ross Harman, MHPCC 12 12 * 13 * @version $Revision: 1. 2$ $Name: not supported by cvs2svn $14 * @date $Date: 2007-0 2-07 22:50:18$13 * @version $Revision: 1.3 $ $Name: not supported by cvs2svn $ 14 * @date $Date: 2007-04-10 21:09:31 $ 15 15 * 16 16 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 24 24 25 25 26 static psS32 psLibVersion00(void);27 28 29 26 psS32 main(psS32 argc, char* argv[]) 30 27 { 31 plan_tests( 1);28 plan_tests(2); 32 29 33 psLibVersion00(); 30 // Simple test of psLibVersion() 31 // XX: Must somehow verify the output is correct. 32 { 33 psMemId id = psMemGetId(); 34 char *stringVal = NULL; 35 stringVal = psLibVersion(); 36 ok(stringVal != NULL && strlen(stringVal), "Version is cool"); 37 psFree(stringVal); 38 ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks"); 39 } 34 40 } 35 41 36 37 static psS32 psLibVersion00(void)38 {39 diag("psLibVersion00");40 41 char *stringVal = NULL;42 stringVal = psLibVersion();43 ok( stringVal != NULL && strlen(stringVal), "Version is cool");44 psFree(stringVal);45 46 return 0;47 }48 -
trunk/psLib/test/sys/tap_psError.c
r12513 r12781 3 3 * @brief Test driver for psError function 4 4 * 5 * This test driver contains the following test points for psError6 * testError00 - psError() (Testpoint #486)7 * testError01 - psErrorMsg(), psErrorStackPrint() (Testpoint #725)8 * testError02 - psErrorStackPrintV() (Testpoint #726)9 * testError03 - psErrorGet(), psErrorLast() (Testpoint #727)10 * testError04 - psErrorClear() (Testpoint #728)11 * testError05 - psErrorCodeString() (Testpoint #729)12 *13 5 * @author Eric Van Alst, MHPCC 14 6 * 15 * @version $Revision: 1. 3$ $Name: not supported by cvs2svn $16 * @date $Date: 2007-0 3-20 03:57:25$7 * @version $Revision: 1.4 $ $Name: not supported by cvs2svn $ 8 * @date $Date: 2007-04-10 21:09:31 $ 17 9 * 18 10 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 28 20 29 21 // Function used in testError02 to verify the psErrorStackPrintV function 30 static void myErrorStackPrint(FILE *fd, 31 const char *fmt, 32 ...) 22 static void myErrorStackPrint( 23 FILE *fd, 24 const char *fmt, 25 ...) 33 26 { 34 27 va_list ap; … … 41 34 42 35 43 static psS32 testError00(void)44 {45 // diag("testError00");46 47 psS32 intval=1;48 psS64 longval = 2;49 float floatval = 3.01;50 char charval = 'E';51 char *stringval = "E R R O R";52 53 // Test point #1 Multiple type values placed in the error string54 psError(PS_ERR_UNKNOWN, true,55 "ALL TYPES intval = %d longval = %lld floatval = %f charval = %c strval = %s",56 intval,longval,floatval,charval,stringval);57 58 // Test point #2 String values in error message59 psError(PS_ERR_UNKNOWN, true, "NO VALUES");60 61 // Test point #3 Empty strings in error message62 psError(PS_ERR_UNKNOWN, true, " ");63 64 return 0;65 }66 67 68 static psS32 testError01(void)69 {70 // diag("testError01");71 72 psErrorCode code=PS_ERR_BAD_PARAMETER_VALUE;73 74 // Verify the return value of psErrorMsg is the psErrorCode passed75 ok ( psError(code, true, "Error code = %d", code) == code,76 "Failed return value verify.");77 skip_start ( psError(code, true, "Error code = %d", code) != code,78 4, "Failed return value verify.");79 80 psErrorStackPrint(stderr,"ERROR STACK PRINT Test1A");81 82 // test1B empty string in for name argument83 ok ( psError(code+1, true, "Error code = %d", code+1) == code+1,84 "Failed return with empty string.");85 skip_start ( psError(code+1, true, "Error code = %d", code+1) != code+1,86 3, "Failed return with empty string.");87 88 psErrorStackPrint(stderr,"ERROR STACK PRINT Test1B");89 90 // test1D undefined code91 ok ( psError(-1, true, "Error code = %d", -1) == -1,92 "Failed return with undefined code.");93 skip_start ( psError(-1, true, "Error code = %d", -1) != -1,94 2, "Failed return with undefined code.");95 96 psErrorStackPrint(stderr,"ERROR STACK PRINT Test1D");97 98 // test1E set psErrorMsg argument to false99 ok( psError(code, false, "Error code = %d", code) == code,100 "Failed return with false new arg.");101 skip_start( psError(code, false, "Error code = %d", code) != code,102 1, "Failed return with false new arg.");103 104 psErrorStackPrint(stderr,"ERROR STACK PRINT Test1E");105 106 // test1F psErrorMsg with a error code less then PS_ERR_BASE(256)107 ok( psError(9, true, "Errno code = %d", 9) == 9, "Error Code" );108 109 psErrorStackPrint(stderr,"ERROR STACK PRINT Test1F");110 111 skip_end();112 skip_end();113 skip_end();114 skip_end();115 116 return 0;117 }118 119 120 static psS32 testError02(void)121 {122 // diag("testError02");123 124 psErrorCode code = PS_ERR_BAD_PARAMETER_VALUE;125 126 // Generate error message and verify return value127 ok (psError(code, true, "Error code = %d", code) == code,128 "Failed return value verify.");129 130 myErrorStackPrint(stderr,"ERROR STACK PRINT Test%dA",2);131 132 return 0;133 }134 135 136 static psS32 testError03(void)137 {138 // diag("testError03");139 140 psErrorCode code = PS_ERR_BAD_PARAMETER_VALUE;141 psErr *last = NULL;142 psErr *getErr = NULL;143 144 // Attempt to get last error message with an empty stack verify psErr with code PS_ERR_NONE145 last = psErrorLast();146 ok(last->code == PS_ERR_NONE,147 "psErrorLast did return PS_ERR_NONE for empty stack (%d)", last->code);148 skip_start(last->code == PS_ERR_NONE,149 9, "psErrorLast did return PS_ERR_NONE for empty stack");150 151 psFree(last);152 153 // HEY154 // Attempt to get specific error message with empty stack verify psErr with code PS_ERR_NONE155 getErr= psErrorGet(2);156 ok(getErr->code == PS_ERR_NONE,157 "psErrorGet did not return PS_ERR_NONE for empty stack (%d)", getErr->code);158 skip_start(getErr->code == PS_ERR_NONE,159 8, "psErrorGet did not return PS_ERR_NONE for empty stack");160 161 psFree(getErr);162 163 // Attempt to get error message with invalid index and an empty stack164 getErr= psErrorGet(-1);165 ok(getErr->code == PS_ERR_NONE,166 "psErrorGet with invalid index/empty stack");167 skip_start(getErr->code != PS_ERR_NONE,168 7, "psErrorGet with invalid index/empty stack");169 170 psFree(getErr);171 172 // Generate three error messages173 ok (psError(code, true, "Error code = %d", code) == code,174 "return value verify-1.");175 skip_start (psError(code, true, "Error code = %d", code != code),176 6, "return value verify-2.");177 178 ok (psError((code+1), false, "Error code = %d", (code+1)) == (code+1),179 "Failed return value verify-3.");180 skip_start (psError((code+1), false, "Error code = %d", (code+1))!=(code+1),181 5, "Failed return value verify-4.");182 183 ok (psError((code+2), false, "Error code = %d", (code+2)) == (code+2),184 "Failed return value verify-5.");185 skip_start (psError((code+2), false, "Error code = %d", (code+2))!=(code+2),186 4, "Failed return value verify-6.");187 188 last = psErrorLast();189 getErr= psErrorGet(0);190 191 // Check that last and get with 0 index are equal192 ok(last == getErr, "psErrorGet(0) equal to psErrorLast");193 skip_start(last != getErr, 3, "psErrorGet(0) equal to psErrorLast");194 195 psFree(last);196 197 // Verify the last error message was returned198 ok ( getErr->code == (code+2),199 "psErrorLast() did not retrieve last error");200 skip_start ( getErr->code != (code+2),201 2, "psErrorLast() did not retrieve last error");202 203 psFree(getErr);204 205 // Verify the middle error message can be retrieved206 getErr= psErrorGet(1);207 ok ( getErr->code == (code+1),208 "psErrorGet() did not retrieve proper error");209 skip_start ( getErr->code != (code+1),210 1, "psErrorGet() did not retrieve proper error");211 212 psFree(getErr);213 214 // Verify the psErrorGet returns NULL if an invalid index is given215 getErr= psErrorGet(-1);216 ok ( getErr->code == PS_ERR_NONE,217 "psErrorGet() did not return PS_ERR_NONE w/ invalid arg");218 219 skip_end();220 skip_end();221 skip_end();222 skip_end();223 skip_end();224 skip_end();225 skip_end();226 skip_end();227 skip_end();228 229 psFree(getErr);230 231 return 0;232 }233 234 235 static psS32 testError04(void)236 {237 //diag("testError04");238 239 psErrorCode code = PS_ERR_BAD_PARAMETER_VALUE;240 psErr *last = NULL;241 psErr *lastAfterClear = NULL;242 243 // With an attemp error stack call psErrorClear244 psErrorClear();245 246 // Get the last error message and verify PS_ERR_NONE (empty stack)247 lastAfterClear = psErrorLast();248 ok(lastAfterClear->code == PS_ERR_NONE, "psErrorLast return expected.");249 skip_start(lastAfterClear->code != PS_ERR_NONE,250 5, "psErrorLast return expected.");251 252 psFree(lastAfterClear);253 254 // Generate three error messages to have messages on error stack255 ok (psError(code, true, "Error code = %d", code) == code,256 "Failed return value verify.");257 skip_start (psError(code, true, "Error code = %d", code) != code,258 4, "Failed return value verify.");259 260 ok (psError((code+1), false, "Error code = %d", (code+1)) == (code+1),261 "Failed return value verify.");262 skip_start (psError((code+1), false, "Error code = %d", (code+1))!=(code+1),263 3, "Failed return value verify.");264 265 ok (psError((code+2), false, "Error code = %d", (code+2)) == (code+2),266 "Failed return value verify.");267 skip_start (psError((code+2), false, "Error code = %d", (code+2))!=(code+2),268 2, "Failed return value verify.");269 270 // Get the last error message and verify it has the expected code271 last = psErrorLast();272 ok(last->code == (code+2), "psErrorLast return expected.");273 skip_start(last->code != (code+2), 1, "psErrorLast return expected.");274 275 psFree(last);276 277 // Clear the error stack278 psErrorClear();279 280 // Get the last error message after clear and verify is has PS_ERR_NONE code281 lastAfterClear = psErrorLast();282 ok(lastAfterClear->code == PS_ERR_NONE, "psErrorLast return expected.");283 284 skip_end();285 skip_end();286 skip_end();287 skip_end();288 skip_end();289 290 psFree(lastAfterClear);291 292 return 0;293 }294 295 296 static psS32 testError05(void)297 {298 //diag("testError05");299 300 // Verify the return value of psErrorCodeString301 // psErrorCode code = PS_ERR_BAD_PARAMETER_VALUE;302 // psLogMsg("tst_psError05", PS_LOG_INFO, psErrorCodeString(code));303 304 // Verify the return value of psErrorCodeString if code is negative305 ok( psErrorCodeString(-1) == NULL, "error string with neg. code");306 307 return 0;308 }309 310 311 static psS32 testErrorRegister(void)312 {313 //diag("testErrorRegister");314 315 psS32 numErr = 4;316 psErrorDescription errDesc[] = { {PS_ERR_N_ERR_CLASSES+1,"first"},317 {PS_ERR_N_ERR_CLASSES+2,"second"},318 {PS_ERR_N_ERR_CLASSES+3,"third"},319 {PS_ERR_N_ERR_CLASSES+4,"fourth"} };320 /*321 1. invoke psErrorRegister with a n>1 array of psErrorDescriptions. Verify that:322 a. Each error description given is retrievable with psErrorCodeString.323 */324 psErrorRegister(errDesc,numErr);325 326 for (psS32 i = 0; i < numErr; i++) {327 const char* desc = psErrorCodeString(PS_ERR_N_ERR_CLASSES+1+i);328 ok (desc != NULL,329 "psErrorCode didn't find registered error code.");330 331 ok (strcmp(desc,errDesc[i].description) == 0,332 "psErrorCode didn't return the proper description. Got '%s', expected '%s'.", desc,errDesc[i].description);333 }334 335 /*336 2. invoke psErrorCodeString with a static/builtin psLib error code. Verify:337 a. the result is correct.338 */339 const char* desc = psErrorCodeString(PS_ERR_N_ERR_CLASSES);340 ok (desc != NULL, "psErrorCode didn't find static error code.");341 ok (strcmp(desc,"error classes end marker") == 0,342 "psErrorCode didn't return the proper description. Got '%s', expected '%s'.",343 desc,"error classes end marker");344 345 desc = psErrorCodeString(PS_ERR_NONE);346 ok (desc != NULL,347 "psErrorCode didn't find static error code.");348 ok (strcmp(desc,"not an error") == 0,349 "psErrorCode didn't return the proper description. Got '%s', expected '%s'.",350 desc,"not an error");351 352 /*353 3. invoke psErrorCodeString with an invalid code. Verify a NULL is returned.354 */355 desc = psErrorCodeString(PS_ERR_N_ERR_CLASSES+numErr+1);356 ok (desc == NULL,357 "psErrorCode didn't return a NULL with a bogus input code.");358 359 /*360 4. invoke psErrorRegister with a NULL psErrorDescription. Verify that:361 a. the execution does not cease.362 b. an appropriate error is generated.363 */364 psLogMsg(__func__,PS_LOG_INFO,"Following should be an error.");365 psErrorClear();366 psErrorRegister(NULL,1);367 psErr* err = psErrorLast();368 ok (err->code == PS_ERR_BAD_PARAMETER_NULL,369 "psErrorCode didn't generate proper error code for NULL input.");370 371 psFree(err);372 373 /*374 5. invoke psErrorRegister with nerror=0. Verify that no error occurs.375 */376 psErrorClear();377 psErrorRegister(errDesc,0);378 err = psErrorLast();379 ok (err->code == PS_ERR_NONE,380 "psErrorCode generated an error for nErrors = 0.");381 382 psFree(err);383 return 0;384 }385 386 387 36 psS32 main( psS32 argc, char* argv[] ) 388 37 { 389 38 psLogSetFormat("HLNM"); 390 plan_tests(38); 391 392 // XXX: testError03() fails if we put it in sequence with the others. 393 testError03(); 394 testError00(); 395 testError01(); 396 testError02(); 397 testError04(); 398 testError05(); 399 testErrorRegister(); 39 plan_tests(60); 40 41 42 //psError() tests 43 { 44 psS32 intval=1; 45 psS64 longval = 2; 46 float floatval = 3.01; 47 char charval = 'E'; 48 char *stringval = "E R R O R"; 49 50 // Multiple type values placed in the error string 51 // XX: The output is never verified 52 { 53 psMemId id = psMemGetId(); 54 psError(PS_ERR_UNKNOWN, true, 55 "ALL TYPES intval = %d longval = %lld floatval = %f charval = %c strval = %s", 56 intval,longval,floatval,charval,stringval); 57 ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks"); 58 } 59 60 61 // String values in error message 62 // XX: The output is never verified 63 { 64 psMemId id = psMemGetId(); 65 psError(PS_ERR_UNKNOWN, true, "NO VALUES"); 66 ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks"); 67 } 68 69 70 // Empty strings in error message 71 // XX: The output is never verified 72 { 73 psMemId id = psMemGetId(); 74 psError(PS_ERR_UNKNOWN, true, " "); 75 ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks"); 76 } 77 78 79 // Verify the return value of psErrorMsg is the psErrorCode passed 80 { 81 psMemId id = psMemGetId(); 82 psErrorCode code=PS_ERR_BAD_PARAMETER_VALUE; 83 ok(psError(code, true, "Error code = %d", code) == code, "Failed return value verify."); 84 psErrorStackPrint(stderr,"ERROR STACK PRINT Test1A"); 85 ok(!psMemCheckLeaks(id, NULL, NULL, false), "no memory leaks"); 86 } 87 88 89 // test1B empty string in for name argument 90 { 91 psMemId id = psMemGetId(); 92 psErrorCode code=PS_ERR_BAD_PARAMETER_VALUE; 93 ok(psError(code+1, true, "Error code = %d", code+1) == code+1, 94 "Failed return with empty string."); 95 psErrorStackPrint(stderr,"ERROR STACK PRINT Test1B"); 96 ok(!psMemCheckLeaks(id, NULL, NULL, false), "no memory leaks"); 97 } 98 99 100 // test1D undefined code 101 { 102 psMemId id = psMemGetId(); 103 ok(psError(-1, true, "Error code = %d", -1) == -1, 104 "Failed return with undefined code."); 105 psErrorStackPrint(stderr,"ERROR STACK PRINT Test1D"); 106 ok(!psMemCheckLeaks(id, NULL, NULL, false), "no memory leaks"); 107 } 108 109 110 // test1E set psErrorMsg argument to false 111 { 112 psMemId id = psMemGetId(); 113 psErrorCode code=PS_ERR_BAD_PARAMETER_VALUE; 114 ok(psError(code, false, "Error code = %d", code) == code, 115 "Failed return with false new arg."); 116 psErrorStackPrint(stderr,"ERROR STACK PRINT Test1E"); 117 ok(!psMemCheckLeaks(id, NULL, NULL, false), "no memory leaks"); 118 } 119 120 121 // test1F psErrorMsg with a error code less then PS_ERR_BASE(256) 122 { 123 psMemId id = psMemGetId(); 124 ok(psError(9, true, "Errno code = %d", 9) == 9, "Error Code" ); 125 psErrorStackPrint(stderr,"ERROR STACK PRINT Test1F"); 126 ok(!psMemCheckLeaks(id, NULL, NULL, false), "no memory leaks"); 127 } 128 } 129 130 131 //testError02() 132 { 133 // Generate error message and verify return value 134 { 135 psErrorCode code = PS_ERR_BAD_PARAMETER_VALUE; 136 psMemId id = psMemGetId(); 137 ok(psError(code, true, "Error code = %d", code) == code, 138 "Failed return value verify."); 139 myErrorStackPrint(stderr,"ERROR STACK PRINT Test%dA",2); 140 ok(!psMemCheckLeaks(id, NULL, NULL, false), "no memory leaks"); 141 } 142 } 143 144 145 //psErrorGet(), psErrorLast() 146 { 147 // Attempt to get last error message with an empty stack verify 148 // psErr with code PS_ERR_NONE 149 { 150 psMemId id = psMemGetId(); 151 psErrorClear(); 152 psErr *last = psErrorLast(); 153 ok(last != NULL, "psErrorLast() returned non-NULL"); 154 skip_start(last == NULL, 1, "Skipping tests because psErrorLast() returned NULL"); 155 ok(last->code == PS_ERR_NONE, 156 "psErrorLast did return PS_ERR_NONE for empty stack(%d)", last->code); 157 skip_end(); 158 psFree(last); 159 ok(!psMemCheckLeaks(id, NULL, NULL, false), "no memory leaks"); 160 } 161 162 // Attempt to get specific error message with empty stack verify 163 // psErr with code PS_ERR_NONE 164 { 165 psMemId id = psMemGetId(); 166 psErr *getErr= psErrorGet(2); 167 ok(getErr != NULL, "psErrorGet(2) returned non-NULL"); 168 skip_start(getErr == NULL, 1, "Skipping tests because psErrorGet() returned NULL"); 169 ok(getErr->code == PS_ERR_NONE, 170 "psErrorGet(2) did return PS_ERR_NONE for empty stack(%d)", getErr->code); 171 skip_end(); 172 psFree(getErr); 173 ok(!psMemCheckLeaks(id, NULL, NULL, false), "no memory leaks"); 174 } 175 176 177 // Attempt to get error message with invalid index and an empty stack 178 { 179 psMemId id = psMemGetId(); 180 psErr *getErr= psErrorGet(-1); 181 ok(getErr != NULL, "psErrorGet(-1) returned non-NULL"); 182 skip_start(getErr == NULL, 1, "Skipping tests because psErrorGet(-1) returned NULL"); 183 ok(getErr->code == PS_ERR_NONE, "psErrorGet with invalid index/empty stack"); 184 skip_end(); 185 psFree(getErr); 186 ok(!psMemCheckLeaks(id, NULL, NULL, false), "no memory leaks"); 187 } 188 189 190 // Generate three error messages, ensure they are correctly returned by psError() 191 { 192 psMemId id = psMemGetId(); 193 psErrorCode code = PS_ERR_BAD_PARAMETER_VALUE; 194 ok(psError(code, true, "Error code = %d", code) == code, 195 "psError() returned correct error code (example 1)"); 196 ok(psError((code+1), false, "Error code = %d", (code+1)) == (code+1), 197 "psError() returned correct error code (example 2)"); 198 ok(psError((code+2), false, "Error code = %d", (code+2)) == (code+2), 199 "psError() returned correct error code (example 3)"); 200 201 psErr *last = psErrorLast(); 202 psErr *getErr= psErrorGet(0); 203 204 // Check that last and get with 0 index are equal 205 ok(last == getErr, "psErrorGet(0) equal to psErrorLast()"); 206 psFree(last); 207 208 // Verify the last error message was returned 209 ok(getErr->code == (code+2), "psErrorLast() did retrieve last error"); 210 psFree(getErr); 211 psErrorClear(); 212 ok(!psMemCheckLeaks(id, NULL, NULL, false), "no memory leaks"); 213 } 214 215 216 // Verify the middle error message can be retrieved 217 { 218 psMemId id = psMemGetId(); 219 psErrorCode code = PS_ERR_BAD_PARAMETER_VALUE; 220 psError(code, true, "Error code = %d", code); 221 psError((code+1), false, "Error code = %d", (code+1)); 222 psError((code+2), false, "Error code = %d", (code+2)); 223 psErr *getErr= psErrorGet(1); 224 ok(getErr->code == (code+1), "psErrorGet() did not retrieve proper error"); 225 psFree(getErr); 226 psErrorClear(); 227 ok(!psMemCheckLeaks(id, NULL, NULL, false), "no memory leaks"); 228 } 229 230 // Verify the psErrorGet returns non-NULL PS_ERR_NONE if an invalid index 231 // is given with non-empty error stack 232 { 233 psMemId id = psMemGetId(); 234 psErrorCode code = PS_ERR_BAD_PARAMETER_VALUE; 235 psError(code, true, "Error code = %d", code); 236 psError((code+1), false, "Error code = %d", (code+1)); 237 psError((code+2), false, "Error code = %d", (code+2)); 238 psErr *getErr= psErrorGet(-1); 239 ok(getErr->code == PS_ERR_NONE, "psErrorGet() did not return PS_ERR_NONE w/ invalid arg"); 240 psFree(getErr); 241 psErrorClear(); 242 ok(!psMemCheckLeaks(id, NULL, NULL, false), "no memory leaks"); 243 } 244 } 245 246 247 // psErrorClear() 248 { 249 // With an attemp error stack call psErrorClear 250 { 251 psMemId id = psMemGetId(); 252 psErrorClear(); 253 // Get the last error message and verify PS_ERR_NONE (empty stack) 254 psErr *lastAfterClear = psErrorLast(); 255 ok(lastAfterClear->code == PS_ERR_NONE, "psErrorLast return expected."); 256 psFree(lastAfterClear); 257 ok(!psMemCheckLeaks(id, NULL, NULL, false), "no memory leaks"); 258 } 259 260 261 // Generate three error messages to have messages on error stack 262 { 263 psMemId id = psMemGetId(); 264 psErrorCode code = PS_ERR_BAD_PARAMETER_VALUE; 265 ok(psError(code, true, "Error code = %d", code) == code, 266 "Failed return value verify."); 267 ok(psError((code+1), false, "Error code = %d", (code+1)) == (code+1), 268 "Failed return value verify."); 269 ok(psError((code+2), false, "Error code = %d", (code+2)) == (code+2), 270 "Failed return value verify."); 271 ok(!psMemCheckLeaks(id, NULL, NULL, false), "no memory leaks"); 272 } 273 274 // Get the last error message and verify it has the expected code 275 { 276 psMemId id = psMemGetId(); 277 psErrorCode code = PS_ERR_BAD_PARAMETER_VALUE; 278 psErr *last = psErrorLast(); 279 ok(last->code == (code+2), "psErrorLast return expected."); 280 psFree(last); 281 ok(!psMemCheckLeaks(id, NULL, NULL, false), "no memory leaks"); 282 } 283 284 // Clear the error stack 285 { 286 psMemId id = psMemGetId(); 287 psErrorClear(); 288 // Get the last error message after clear and verify is has PS_ERR_NONE code 289 psErr *lastAfterClear = psErrorLast(); 290 ok(lastAfterClear->code == PS_ERR_NONE, "psErrorLast return expected."); 291 psFree(lastAfterClear); 292 ok(!psMemCheckLeaks(id, NULL, NULL, false), "no memory leaks"); 293 } 294 } 295 296 297 // psErrorCodeString() 298 { 299 // Verify the return value of psErrorCodeString 300 // psErrorCode code = PS_ERR_BAD_PARAMETER_VALUE; 301 // psLogMsg("tst_psError05", PS_LOG_INFO, psErrorCodeString(code)); 302 303 // Verify the return value of psErrorCodeString if code is negative 304 ok( psErrorCodeString(-1) == NULL, "error string with neg. code"); 305 } 306 307 308 //testErrorRegister() 309 { 310 psS32 numErr = 4; 311 psErrorDescription errDesc[] = { {PS_ERR_N_ERR_CLASSES+1,"first"}, 312 {PS_ERR_N_ERR_CLASSES+2,"second"}, 313 {PS_ERR_N_ERR_CLASSES+3,"third"}, 314 {PS_ERR_N_ERR_CLASSES+4,"fourth"} }; 315 /* 316 1. invoke psErrorRegister with a n>1 array of psErrorDescriptions. Verify that: 317 a. Each error description given is retrievable with psErrorCodeString. 318 */ 319 psErrorRegister(errDesc,numErr); 320 321 for (psS32 i = 0; i < numErr; i++) { 322 const char* desc = psErrorCodeString(PS_ERR_N_ERR_CLASSES+1+i); 323 ok(desc != NULL, 324 "psErrorCode didn't find registered error code."); 325 326 ok(strcmp(desc,errDesc[i].description) == 0, 327 "psErrorCode didn't return the proper description. Got '%s', expected '%s'.", desc,errDesc[i].description); 328 } 329 330 /* 331 2. invoke psErrorCodeString with a static/builtin psLib error code. Verify: 332 a. the result is correct. 333 */ 334 const char* desc = psErrorCodeString(PS_ERR_N_ERR_CLASSES); 335 ok(desc != NULL, "psErrorCode didn't find static error code."); 336 ok(strcmp(desc,"error classes end marker") == 0, 337 "psErrorCode didn't return the proper description. Got '%s', expected '%s'.", 338 desc,"error classes end marker"); 339 340 desc = psErrorCodeString(PS_ERR_NONE); 341 ok(desc != NULL, 342 "psErrorCode didn't find static error code."); 343 ok(strcmp(desc,"not an error") == 0, 344 "psErrorCode didn't return the proper description. Got '%s', expected '%s'.", 345 desc,"not an error"); 346 347 /* 348 3. invoke psErrorCodeString with an invalid code. Verify a NULL is returned. 349 */ 350 desc = psErrorCodeString(PS_ERR_N_ERR_CLASSES+numErr+1); 351 ok(desc == NULL, 352 "psErrorCode didn't return a NULL with a bogus input code."); 353 354 /* 355 4. invoke psErrorRegister with a NULL psErrorDescription. Verify that: 356 a. the execution does not cease. 357 b. an appropriate error is generated. 358 */ 359 psLogMsg(__func__,PS_LOG_INFO,"Following should be an error."); 360 psErrorClear(); 361 psErrorRegister(NULL,1); 362 psErr* err = psErrorLast(); 363 ok(err->code == PS_ERR_BAD_PARAMETER_NULL, 364 "psErrorCode didn't generate proper error code for NULL input."); 365 366 psFree(err); 367 368 /* 369 5. invoke psErrorRegister with nerror=0. Verify that no error occurs. 370 */ 371 psErrorClear(); 372 psErrorRegister(errDesc,0); 373 err = psErrorLast(); 374 ok(err->code == PS_ERR_NONE, 375 "psErrorCode generated an error for nErrors = 0."); 376 psFree(err); 377 } 400 378 } 401 402 379 //HERE -
trunk/psLib/test/sys/tap_psLine.c
r12550 r12781 5 5 * @author dRob, MHPCC 6 6 * 7 * @version $Revision: 1. 3$ $Name: not supported by cvs2svn $8 * @date $Date: 2007-0 3-22 22:47:07$7 * @version $Revision: 1.4 $ $Name: not supported by cvs2svn $ 8 * @date $Date: 2007-04-10 21:09:31 $ 9 9 * 10 10 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 17 17 #include "string.h" 18 18 19 static psS32 testLineAlloc(void); 20 static psS32 testLineInit(void); 21 static psS32 testLineAdd(void); 22 static psS32 testLineChk(void); 19 psS32 main( psS32 argc, char* argv[] ) 20 { 21 plan_tests(16); 22 psLogSetFormat("HLNM"); 23 psLogSetLevel(PS_LOG_INFO); 24 25 //testLineAlloc() 26 { 27 psMemId id = psMemGetId(); 28 psLine *lineline = NULL; 29 lineline = psLineAlloc(20); 30 ok(lineline->NLINE==20, "psLine set NLINE parameter during Allocation"); 31 ok(lineline->Nline == 0, "psLine set Nline parameter during Allocation"); 32 strncpy(lineline->line, "Hello World", 20); 33 ok(!strncmp(lineline->line, "Hello World", 20), 34 "psLine was stored a simple string!"); 35 psFree(lineline); 36 ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks"); 37 } 38 39 // testLineInit() 40 { 41 psMemId id = psMemGetId(); 42 psLine *line = NULL; 43 //Return false for NULL input 44 int okay = !psLineInit(line); 45 ok(okay, "psLineInit. Expected false for NULL psLine input"); 46 //Allocate a line and return true on Init 47 line = psLineAlloc(1); 48 okay = psLineInit(line); 49 ok(okay, "psLineInit. Expected true for valid psLine input"); 50 ok(line->NLINE == 1 && line->Nline == 0, "psLineInit returned line parameters."); 51 psFree(line); 52 ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks"); 53 } 23 54 24 55 25 psS32 main( psS32 argc, char* argv[] ) 26 { 27 plan_tests(12); 28 29 testLineAlloc(); 30 testLineInit(); 31 testLineAdd(); 32 testLineChk(); 33 } 34 35 psS32 testLineAlloc(void) 36 { 37 // diag("testLineAlloc"); 38 39 psLine *lineline = NULL; 40 lineline = psLineAlloc(20); 41 42 ok (lineline->NLINE==20, "psLine set NLINE parameter during Allocation"); 43 skip_start (lineline->NLINE != 20, 44 2, "psLine set NLINE parameter during Allocation"); 45 46 ok (lineline->Nline == 0, 47 "psLine set Nline parameter during Allocation\n"); 48 skip_start (lineline->Nline == 0, 49 1, "psLine set Nline parameter during Allocation\n"); 50 51 strncpy(lineline->line, "Hello World", 20); 52 ok (!strncmp(lineline->line, "Hello World", 20), 53 "psLine was stored a simple string!\n"); 54 55 skip_end(); 56 skip_end(); 57 58 psFree(lineline); 59 60 return 0; 61 } 62 63 psS32 testLineInit(void) 64 { 65 // diag("testLineInit"); 66 67 psLine *line = NULL; 68 //Return false for NULL input 69 int okay = !psLineInit(line); 70 ok (okay, "psLineInit. Expected false for NULL psLine input.\n"); 71 skip_start (!okay, 2, "psLineInit. Expected NULL psLine input.\n"); 72 73 //Allocate a line and return true on Init 74 line = psLineAlloc(1); 75 okay = psLineInit(line); 76 ok( okay, "psLineInit. Expected true for valid psLine input.\n"); 77 skip_start( !okay, 1, "psLineInit. Expected true for valid psLine input."); 78 79 ok (line->NLINE == 1 && line->Nline == 0, 80 "psLineInit returned line parameters."); 81 82 skip_end(); 83 skip_end(); 84 85 psFree(line); 86 87 return 0; 88 } 56 // testLineAdd() 57 { 58 psMemId id = psMemGetId(); 59 psLine *line = NULL; 60 //Return false for NULL input 61 ok(!psLineAdd(line, "Hello World"), 62 "psLineAdd. Expected false for NULL psLine input."); 63 //Allocate and return true for valid input. 64 line = psLineAlloc(20); 65 int okay = psLineAdd(line, "Hello %s", "World"); 66 ok( okay, "psLineAdd. Expected true for valid psLine input"); 67 ok(line->NLINE == 20 && line->Nline == 11, 68 "psLineAdd failed to return the correct line parameters"); 69 ok(!strncmp(line->line, "Hello World", 20), 70 "psLineAdd failed to store the correct line string."); 71 psFree(line); 72 ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks"); 73 } 89 74 90 75 91 psS32 testLineAdd(void) 92 { 93 // diag("testLineAdd"); 94 95 psLine *line = NULL; 96 //Return false for NULL input 97 ok (!psLineAdd(line, "Hello World"), 98 "psLineAdd. Expected false for NULL psLine input."); 99 skip_start(psLineAdd(line, "Hello World"), 100 3, "psLineAdd. Expected false for NULL psLine input."); 101 102 //Allocate and return true for valid input. 103 line = psLineAlloc(20); 104 int okay = psLineAdd(line, "Hello %s", "World"); 105 ok( okay, "psLineAdd. Expected true for valid psLine input.\n"); 106 skip_start( !okay, 2, "psLineAdd.Expected true for valid psLine input.\n"); 107 108 ok (line->NLINE == 20 && line->Nline == 11, 109 "psLineAdd failed to return the correct line parameters.\n"); 110 skip_start (line->NLINE != 20 || line->Nline != 11, 111 1,"psLineAdd failed to return the correct line parameters.\n"); 112 113 ok (!strncmp(line->line, "Hello World", 20), 114 "psLineAdd failed to store the correct line string."); 115 116 skip_end(); 117 skip_end(); 118 skip_end(); 119 120 psFree(line); 121 122 return 0; 76 // testLineChk() 77 { 78 psMemId id = psMemGetId(); 79 psLine *line = NULL; 80 //Return false for Null input line 81 ok(!psMemCheckLine(line), 82 "psMemCheckLine return false for NULL line input"); 83 line = psLineAlloc(1); 84 ok(psMemCheckLine(line), 85 "psMemCheckLine return true for valid line input"); 86 psFree(line); 87 ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks"); 88 } 123 89 } 124 125 psS32 testLineChk(void)126 {127 // diag("testLineChk");128 129 psLine *line = NULL;130 //Return false for Null input line131 ok (!psMemCheckLine(line),132 "psMemCheckLine return false for NULL line input.\n");133 skip_start (psMemCheckLine(line),134 1, "psMemCheckLine return false for NULL line input.\n");135 136 line = psLineAlloc(1);137 ok (psMemCheckLine(line),138 "psMemCheckLine return true for valid line input.\n");139 140 psFree(line);141 142 skip_end();143 144 return 0;145 } -
trunk/psLib/test/sys/tap_psMemory.c
r12513 r12781 3 3 * @brief Contains the tests for psMemory.[ch] 4 4 * 5 *6 5 * @author Robert DeSonia, MHPCC 7 6 * 8 * @version $Revision: 1. 6$ $Name: not supported by cvs2svn $9 * @date $Date: 2007-0 3-20 03:57:25$7 * @version $Revision: 1.7 $ $Name: not supported by cvs2svn $ 8 * @date $Date: 2007-04-10 21:09:31 $ 10 9 * 11 10 * XXXX: Several tests fail with an Abort and are commented out. … … 42 41 psLogSetFormat("HLNM"); 43 42 psLogSetLevel(PS_LOG_INFO); 44 plan_tests(10); 45 46 void TPFreeReferencedMemory( void ); 47 if (1) { 48 TPFreeReferencedMemory(); 49 } 50 51 void TPOutOfMemory( void ); 43 plan_tests(46); 44 45 // TPFreeReferencedMemory() 46 { 47 psMemId id = psMemGetId(); 48 psS32 *mem = ( psS32* ) psAlloc( 100 * sizeof( psS32 ) ); 49 psS32 ref = psMemGetRefCounter( mem ); 50 ok(ref == 1, "buffer reference count %d.", ref ); 51 skip_start ( ref != 1, 3, "buffer reference count %d.", ref ); 52 psMemIncrRefCounter(mem); 53 psMemIncrRefCounter(mem); 54 psMemIncrRefCounter(mem); 55 56 ref = psMemGetRefCounter( mem ); 57 ok(ref == 4, "buffer reference count was %d.", ref ); 58 skip_start ( ref != 4, 2, "buffer reference count was %d.", ref ); 59 60 psMemDecrRefCounter( mem ); 61 psMemDecrRefCounter( mem ); 62 63 ref = psMemGetRefCounter( mem ); 64 ok(ref == 2, "Found buffer reference count to be %d.", ref ); 65 skip_start ( ref != 2, 1, "Found buffer reference count to be %d.", ref ); 66 67 psMemDecrRefCounter( mem ); 68 ref = psMemGetRefCounter( mem ); 69 ok(ref == 1, "Found buffer reference count to be %d.", ref ); 70 skip_end(); 71 skip_end(); 72 skip_end(); 73 psFree(mem); 74 ok(!psMemCheckLeaks(id, NULL, NULL, false), "no memory leaks"); 75 } 76 77 78 // Upon requesting more memory than is available, psalloc shall call 79 // the psMemExhaustedCallback. 52 80 // XXXX: Skipping TPOutOfMemory() because of test abort failure 53 81 if (0) { 54 TPOutOfMemory(); 55 } 56 57 void TPReallocOutOfMemory( void ); 82 psMemId id = psMemGetId(); 83 psS32 *mem[ 100 ]; 84 psMemExhaustedCallback cb; 85 for ( psS32 lcv = 0; lcv < 100; lcv++ ) { 86 mem[ lcv ] = NULL; 87 } 88 exhaustedCallbackCalled = 0; 89 cb = psMemExhaustedCallbackSet( TPOutOfMemoryExhaustedCallback ); 90 #ifdef COMMENTED_OUT 91 // Don't include since intentionally aborts 92 for ( psS32 lcv = 0; lcv < 100; lcv++ ) { 93 mem[ lcv ] = ( psS32* ) psAlloc( SIZE_MAX/2 - 1000 ); 94 } 95 psMemExhaustedCallbackSet( cb ); 96 ok(exhaustedCallbackCalled != 0, 97 "Called psAlloc with HUGE memory requirement and survived!"); 98 for ( psS32 lcv = 0; lcv < 100; lcv++ ) { 99 psFree( mem[ lcv ] ); 100 } 101 #endif 102 ok(!psMemCheckLeaks(id, NULL, NULL, false), "no memory leaks"); 103 } 104 105 106 107 // Bug/Task #562 regression test. Upon requesting more memory than is available, 108 // psRealloc shall call the psMemExhaustedCallback. 58 109 // XXXX: Skipping TPReallocOutOfMemory() because of test abort failure 59 110 if (0) { 60 TPReallocOutOfMemory(); 61 } 62 63 void TPCheckBufferPositive( void ); 64 if (1) { 65 TPCheckBufferPositive(); 66 } 67 68 void TPrealloc( void ); 69 if (1) { 70 TPrealloc(); 71 } 72 73 void TPallocCallback( void ); 74 if (1) { 75 TPallocCallback(); 76 } 77 78 void TPcheckLeaks( void ); 111 psMemId id = psMemGetId(); 112 psS32 *mem[ 100 ]; 113 psMemExhaustedCallback cb; 114 for ( psS32 lcv = 0; lcv < 100; lcv++ ) { 115 mem[ lcv ] = NULL; 116 } 117 exhaustedCallbackCalled = 0; 118 cb = psMemExhaustedCallbackSet( TPOutOfMemoryExhaustedCallback ); 119 for ( psS32 lcv = 0; lcv < 100; lcv++ ) { 120 mem[ lcv ] = ( psS32* ) psAlloc( 10 ); 121 } 122 for ( psS32 lcv = 0; lcv < 100; lcv++ ) { 123 mem[ lcv ] = ( psS32* ) psRealloc( mem[ lcv ], SIZE_MAX/2 - 1000 ); 124 } 125 psMemExhaustedCallbackSet( cb ); 126 ok(exhaustedCallbackCalled != 0, 127 "Called psRealloc with HUGE memory requirement and survived in %s!", __func__ ); 128 for ( psS32 lcv = 0; lcv < 100; lcv++ ) { 129 psFree( mem[ lcv ] ); 130 } 131 ok(!psMemCheckLeaks(id, NULL, NULL, false), "no memory leaks"); 132 } 133 134 135 // psAlloc shall allocate memory blocks writeable by caller. 136 { 137 psMemId id = psMemGetId(); 138 const psS32 size = 100; 139 psS32 *mem = ( psS32* ) psAlloc( size * sizeof( psS32 ) ); 140 ok(mem != NULL, "psAlloc returned non-NULL value" ); 141 for ( psS32 index = 0;index < size;index++ ) { 142 mem[ index ] = index; 143 } 144 psS32 failed = 0; 145 for ( psS32 index = 0;index < size;index++ ) { 146 if ( mem[ index ] != index ) { 147 failed++; 148 } 149 } 150 ok(failed == 0, "mem legit" ); 151 psFree( mem ); 152 ok(!psMemCheckLeaks(id, NULL, NULL, false), "no memory leaks"); 153 } 154 155 156 // psRealloc shall increase/decrease memory buffer while preserving contents 157 { 158 psMemId id = psMemGetId(); 159 const psS32 initialSize = 100; 160 // allocate buffer with known values. 161 psS32 *mem1 = ( psS32* ) psAlloc( initialSize * sizeof( psS32 ) ); 162 psS32 *mem2 = ( psS32* ) psAlloc( initialSize * sizeof( psS32 ) ); 163 psS32 *mem3 = ( psS32* ) psAlloc( initialSize * sizeof( psS32 ) ); 164 for ( psS32 lcv = 0;lcv < initialSize;lcv++ ) { 165 mem1[lcv] = mem2[lcv] = mem3[lcv] = lcv; 166 } 167 psMemCheckCorruption(stderr, false); 168 // realloc to 2x 169 mem1 = ( psS32* ) psRealloc( mem1, 2 * initialSize * sizeof( psS32 ) ); 170 mem2 = ( psS32* ) psRealloc( mem2, 2 * initialSize * sizeof( psS32 ) ); 171 mem3 = ( psS32* ) psRealloc( mem3, 2 * initialSize * sizeof( psS32 ) ); 172 // check values of initial block 173 int error = 0; 174 for ( psS32 i = 0;i < initialSize;i++ ) { 175 if ( mem1[ i ] != i || mem2[ i ] != i || mem3[ i ] != i ) { 176 error = 1; 177 break; 178 } 179 } 180 ok(error==0, "Realloc preserve the contents with expanding buffer"); 181 psMemCheckCorruption(stderr, false); 182 // realloc to 1/2 initial value. 183 mem1 = ( psS32* ) psRealloc( mem1, ( initialSize / 2 ) * sizeof( psS32 ) ); 184 mem2 = ( psS32* ) psRealloc( mem2, ( initialSize / 2 ) * sizeof( psS32 ) ); 185 mem3 = ( psS32* ) psRealloc( mem3, ( initialSize / 2 ) * sizeof( psS32 ) ); 186 // check values of initial block 187 error = 0; 188 for ( psS32 i = 0;i < initialSize / 2;i++ ) { 189 if ( mem1[ i ] != i || mem2[ i ] != i || mem3[ i ] != i ) { 190 error = 1; 191 break; 192 } 193 } 194 ok(error==0, "Realloc preserved the contents with shrinking buffer"); 195 psFree( mem1 ); 196 psFree( mem2 ); 197 psFree( mem3 ); 198 ok(!psMemCheckLeaks(id, NULL, NULL, false), "no memory leaks"); 199 } 200 201 202 // TPallocCallback() 203 { 204 psMemId id = psMemGetId(); 205 psS32 currentId = psMemGetId(); 206 const psS32 initialSize = 100; 207 psS32 mark; 208 allocCallbackCalled = 0; 209 freeCallbackCalled = 0; 210 psMemAllocCallbackSet( memAllocCallback ); 211 psMemFreeCallbackSet( memFreeCallback ); 212 psMemAllocCallbackSetID( currentId + 1 ); 213 psMemFreeCallbackSetID( currentId + 1 ); 214 // allocate buffer with known values. 215 psS32 *mem1 = ( psS32* ) psAlloc( initialSize * sizeof( psS32 ) ); 216 psS32 *mem2 = ( psS32* ) psAlloc( initialSize * sizeof( psS32 ) ); 217 psS32 *mem3 = ( psS32* ) psAlloc( initialSize * sizeof( psS32 ) ); 218 psFree(mem1); 219 psFree(mem2); 220 psFree(mem3); 221 ok(allocCallbackCalled == 2 && freeCallbackCalled == 2, 222 "alloc/free callbacks called the proper number of times" ); 223 allocCallbackCalled = 0; 224 freeCallbackCalled = 0; 225 mark = psMemGetId(); 226 mem1 = ( psS32* ) psAlloc( initialSize * sizeof( psS32 ) ); 227 psMemAllocCallbackSetID( mark ); 228 mem1 = ( psS32* ) psRealloc( mem1, initialSize * 2 * sizeof( psS32 ) ); 229 psFree( mem1 ); 230 ok(allocCallbackCalled == 2, 231 "realloc callbacks were called the proper number of times" ); 232 ok(!psMemCheckLeaks(id, NULL, NULL, false), "no memory leaks"); 233 } 234 235 236 // TPcheckLeaks() 79 237 // XXXX: Skipping TPcheckLeaks() because of test abort failure 80 238 if (0) { 81 TPcheckLeaks(); 82 } 239 const psS32 numBuffers = 5; 240 psS32* buffers[ 5 ]; 241 psS32 lcv; 242 psS32 currentId = psMemGetId(); 243 psMemBlock** blks; 244 psS32 nLeaks = 0; 245 psS32 lineMark = 0; 246 247 for ( lcv = 0;lcv < numBuffers;lcv++ ) { 248 lineMark = __LINE__ + 1; 249 buffers[ lcv ] = psAlloc( sizeof( psS32 ) ); 250 } 251 for ( lcv = 1;lcv < numBuffers;lcv++ ) { 252 psFree( buffers[ lcv ] ); 253 } 254 nLeaks = psMemCheckLeaks( currentId, &blks, stderr, false ); 255 ok(nLeaks == 1, "psMemCheckLeaks found %d leaks", nLeaks ); 256 ok(blks[ 0 ] ->lineno == lineMark, 257 "psMemCheckLeaks found a leak other than the expected one (line %d vs %d)", lineMark, blks[ 0 ] ->lineno ); 258 psFree( buffers[ 0 ] ); 259 psFree( blks ); 260 psMemCheckLeaks(currentId,NULL,stderr, false); 261 for ( lcv = 0;lcv < numBuffers;lcv++ ) { 262 lineMark = __LINE__ + 1; 263 buffers[ lcv ] = psAlloc( sizeof( psS32 ) ); 264 } 265 for ( lcv = 0;lcv < numBuffers - 1;lcv++ ) { 266 psFree( buffers[ lcv ] ); 267 } 268 nLeaks = psMemCheckLeaks( currentId, &blks, stderr, false ); 269 ok(nLeaks == 1, "psMemCheckLeaks found %d leaks.", nLeaks ); 270 ok(blks[ 0 ] ->lineno == lineMark, "psMemCheckLeaks found leaks"); 271 psFree( buffers[ 4 ] ); 272 psFree( blks ); 273 for ( lcv = 0;lcv < numBuffers;lcv++ ) { 274 lineMark = __LINE__ + 1; 275 buffers[ lcv ] = psAlloc( sizeof( psS32 ) ); 276 } 277 for ( lcv = 0;lcv < numBuffers;lcv++ ) { 278 if ( lcv % 2 == 0 ) { 279 psFree( buffers[ lcv ] ); 280 } 281 } 282 nLeaks = psMemCheckLeaks( currentId, &blks, stderr, false ); 283 ok(nLeaks == 2, "psMemCheckLeaks found %d leaks.", nLeaks); 284 ok(blks[ 0 ] ->lineno == lineMark, 285 "psMemCheckLeaks found a leak other than the expected." ); 286 psFree(blks); 287 psFree(buffers[1]); 288 psFree(buffers[3]); 289 } 290 83 291 84 292 void TPmultipleFree( void ); … … 87 295 TPmultipleFree(); 88 296 } 89 } 90 91 // Testpoint #449, psAlloc shall allocate memory blocks writeable by caller. 92 void TPCheckBufferPositive( void ) 93 { 94 // diag("TPCheckBufferPositive"); 95 96 psS32 * mem; 97 const psS32 size = 100; 98 psS32 failed = 0; 99 100 mem = ( psS32* ) psAlloc( size * sizeof( psS32 ) ); 101 ok ( mem != NULL, "psAlloc returned non-NULL value" ); 102 103 for ( psS32 index = 0;index < size;index++ ) { 104 mem[ index ] = index; 105 } 106 107 for ( psS32 index = 0;index < size;index++ ) { 108 if ( mem[ index ] != index ) { 109 failed++; 110 } 111 } 112 ok( failed == 0, "mem legit" ); 113 114 psFree( mem ); 115 } 116 117 void TPFreeReferencedMemory( void ) 118 { 119 // diag("TPFreeReferencedMemory"); 120 121 // create memory 122 psS32 * mem; 123 psS32 ref = 0; 124 125 mem = ( psS32* ) psAlloc( 100 * sizeof( psS32 ) ); 126 127 ref = psMemGetRefCounter( mem ); 128 ok ( ref == 1, "buffer reference count %d.", ref ); 129 skip_start ( ref != 1, 3, "buffer reference count %d.", ref ); 130 131 psMemIncrRefCounter( mem ); 132 psMemIncrRefCounter( mem ); 133 psMemIncrRefCounter( mem ); 134 135 ref = psMemGetRefCounter( mem ); 136 ok ( ref == 4, "buffer reference count was %d.", ref ); 137 skip_start ( ref != 4, 2, "buffer reference count was %d.", ref ); 138 139 psMemDecrRefCounter( mem ); 140 psMemDecrRefCounter( mem ); 141 142 ref = psMemGetRefCounter( mem ); 143 ok ( ref == 2, "Found buffer reference count to be %d.", ref ); 144 skip_start ( ref != 2, 1, "Found buffer reference count to be %d.", ref ); 145 146 psMemDecrRefCounter( mem ); 147 148 ref = psMemGetRefCounter( mem ); 149 ok ( ref == 1, "Found buffer reference count to be %d.", ref ); 150 151 skip_end(); 152 skip_end(); 153 skip_end(); 154 155 psFree( mem ); 156 } 157 158 // Bug/Task #562 regression test. Upon requesting more memory than is available, psRealloc shall call 159 // the psMemExhaustedCallback. 160 void TPReallocOutOfMemory( void ) 161 { 162 // diag("TPReallocOutOfMemory"); 163 164 psS32 * mem[ 100 ]; 165 psMemExhaustedCallback cb; 166 167 for ( psS32 lcv = 0; lcv < 100; lcv++ ) { 168 mem[ lcv ] = NULL; 169 } 170 171 exhaustedCallbackCalled = 0; 172 173 cb = psMemExhaustedCallbackSet( TPOutOfMemoryExhaustedCallback ); 174 175 for ( psS32 lcv = 0; lcv < 100; lcv++ ) { 176 mem[ lcv ] = ( psS32* ) psAlloc( 10 ); 177 } 178 179 for ( psS32 lcv = 0; lcv < 100; lcv++ ) { 180 mem[ lcv ] = ( psS32* ) psRealloc( mem[ lcv ], SIZE_MAX/2 - 1000 ); 181 } 182 183 psMemExhaustedCallbackSet( cb ); 184 185 ok ( exhaustedCallbackCalled != 0, 186 "Called psRealloc with HUGE memory requirement and survived in %s!", __func__ ); 187 188 for ( psS32 lcv = 0; lcv < 100; lcv++ ) { 189 psFree( mem[ lcv ] ); 190 } 191 } 192 193 194 // Testpoint #450, Upon requesting more memory than is available, psalloc shall call 195 // the psMemExhaustedCallback. 196 void TPOutOfMemory( void ) 197 { 198 // diag("TPOutOfMemory"); 199 200 psS32 * mem[ 100 ]; 201 psMemExhaustedCallback cb; 202 203 for ( psS32 lcv = 0; lcv < 100; lcv++ ) { 204 mem[ lcv ] = NULL; 205 } 206 207 exhaustedCallbackCalled = 0; 208 cb = psMemExhaustedCallbackSet( TPOutOfMemoryExhaustedCallback ); 209 210 #ifdef COMMENTED_OUT 211 // Don't include since intentionally aborts 212 213 for ( psS32 lcv = 0; lcv < 100; lcv++ ) { 214 mem[ lcv ] = ( psS32* ) psAlloc( SIZE_MAX/2 - 1000 ); 215 } 216 217 psMemExhaustedCallbackSet( cb ); 218 219 ok ( exhaustedCallbackCalled != 0, 220 "Called psAlloc with HUGE memory requirement and survived!"); 221 222 for ( psS32 lcv = 0; lcv < 100; lcv++ ) { 223 psFree( mem[ lcv ] ); 224 } 225 #endif 226 } 227 228 229 // Testpoint #451, psRealloc shall increase/decrease memory buffer while preserving contents 230 void TPrealloc( void ) 231 { 232 // diag("TPrealloc"); 233 234 psS32 * mem1; 235 psS32* mem2; 236 psS32* mem3; 237 const psS32 initialSize = 100; 238 239 // allocate buffer with known values. 240 mem1 = ( psS32* ) psAlloc( initialSize * sizeof( psS32 ) ); 241 mem2 = ( psS32* ) psAlloc( initialSize * sizeof( psS32 ) ); 242 mem3 = ( psS32* ) psAlloc( initialSize * sizeof( psS32 ) ); 243 for ( psS32 lcv = 0;lcv < initialSize;lcv++ ) { 244 mem1[ lcv ] = mem2[ lcv ] = mem3[ lcv ] = lcv; 245 } 246 247 psMemCheckCorruption(stderr, false); 248 249 // realloc to 2x 250 mem1 = ( psS32* ) psRealloc( mem1, 2 * initialSize * sizeof( psS32 ) ); 251 mem2 = ( psS32* ) psRealloc( mem2, 2 * initialSize * sizeof( psS32 ) ); 252 mem3 = ( psS32* ) psRealloc( mem3, 2 * initialSize * sizeof( psS32 ) ); 253 254 // check values of initial block 255 int error = 0; 256 for ( psS32 i = 0;i < initialSize;i++ ) { 257 if ( mem1[ i ] != i || mem2[ i ] != i || mem3[ i ] != i ) { 258 error = 1; 259 break; 260 } 261 } 262 ok(error==0, "Realloc preserve the contents with expanding buffer"); 263 264 psMemCheckCorruption(stderr, false); 265 266 // realloc to 1/2 initial value. 267 mem1 = ( psS32* ) psRealloc( mem1, ( initialSize / 2 ) * sizeof( psS32 ) ); 268 mem2 = ( psS32* ) psRealloc( mem2, ( initialSize / 2 ) * sizeof( psS32 ) ); 269 mem3 = ( psS32* ) psRealloc( mem3, ( initialSize / 2 ) * sizeof( psS32 ) ); 270 271 // check values of initial block 272 error = 0; 273 for ( psS32 i = 0;i < initialSize / 2;i++ ) { 274 if ( mem1[ i ] != i || mem2[ i ] != i || mem3[ i ] != i ) { 275 error = 1; 276 break; 277 } 278 } 279 ok(error==0, "Realloc preserved the contents with shrinking buffer"); 280 281 psFree( mem1 ); 282 psFree( mem2 ); 283 psFree( mem3 ); 284 } 285 286 287 void TPallocCallback( void ) 288 { 289 // diag("TPallocCallback"); 290 291 psS32 * mem1; 292 psS32* mem2; 293 psS32* mem3; 294 psS32 currentId = psMemGetId(); 295 const psS32 initialSize = 100; 296 psS32 mark; 297 298 allocCallbackCalled = 0; 299 freeCallbackCalled = 0; 300 psMemAllocCallbackSet( memAllocCallback ); 301 psMemFreeCallbackSet( memFreeCallback ); 302 303 psMemAllocCallbackSetID( currentId + 1 ); 304 psMemFreeCallbackSetID( currentId + 1 ); 305 306 // allocate buffer with known values. 307 mem1 = ( psS32* ) psAlloc( initialSize * sizeof( psS32 ) ); 308 mem2 = ( psS32* ) psAlloc( initialSize * sizeof( psS32 ) ); 309 mem3 = ( psS32* ) psAlloc( initialSize * sizeof( psS32 ) ); 310 311 psFree( mem1 ); 312 psFree( mem2 ); 313 psFree( mem3 ); 314 315 ok( allocCallbackCalled == 2 && freeCallbackCalled == 2, 316 "alloc/free callbacks called the proper number of times" ); 317 skip_start( allocCallbackCalled != 2 || freeCallbackCalled != 2, 318 1, "alloc/free callbacks called the proper number of times" ); 319 320 allocCallbackCalled = 0; 321 freeCallbackCalled = 0; 322 323 mark = psMemGetId(); 324 325 mem1 = ( psS32* ) psAlloc( initialSize * sizeof( psS32 ) ); 326 327 psMemAllocCallbackSetID( mark ); 328 329 mem1 = ( psS32* ) psRealloc( mem1, initialSize * 2 * sizeof( psS32 ) ); 330 331 psFree( mem1 ); 332 333 ok ( allocCallbackCalled == 2, 334 "realloc callbacks were called the proper number of times" ); 335 336 skip_end(); 337 } 338 339 340 void TPcheckLeaks( void ) 341 { 342 const psS32 numBuffers = 5; 343 psS32* buffers[ 5 ]; 344 psS32 lcv; 345 psS32 currentId = psMemGetId(); 346 psMemBlock** blks; 347 psS32 nLeaks = 0; 348 psS32 lineMark = 0; 349 350 for ( lcv = 0;lcv < numBuffers;lcv++ ) { 351 lineMark = __LINE__ + 1; 352 buffers[ lcv ] = psAlloc( sizeof( psS32 ) ); 353 } 354 355 for ( lcv = 1;lcv < numBuffers;lcv++ ) { 356 psFree( buffers[ lcv ] ); 357 } 358 359 nLeaks = psMemCheckLeaks( currentId, &blks, stderr, false ); 360 361 ok ( nLeaks == 1, "psMemCheckLeaks found %d leaks", nLeaks ); 362 skip_start ( nLeaks != 1, 5, "psMemCheckLeaks found %d leaks", nLeaks ); 363 364 ok ( blks[ 0 ] ->lineno == lineMark, 365 "psMemCheckLeaks found a leak other than the expected one (line %d vs %d)", lineMark, blks[ 0 ] ->lineno ); 366 skip_start ( blks[ 0 ] ->lineno != lineMark, 367 4,"psMemCheckLeaks found a leak other than the expected one (line %d vs %d)", lineMark, blks[ 0 ] ->lineno ); 368 369 psFree( buffers[ 0 ] ); 370 psFree( blks ); 371 372 psMemCheckLeaks(currentId,NULL,stderr, false); 373 374 for ( lcv = 0;lcv < numBuffers;lcv++ ) { 375 lineMark = __LINE__ + 1; 376 buffers[ lcv ] = psAlloc( sizeof( psS32 ) ); 377 } 378 379 for ( lcv = 0;lcv < numBuffers - 1;lcv++ ) { 380 psFree( buffers[ lcv ] ); 381 } 382 383 nLeaks = psMemCheckLeaks( currentId, &blks, stderr, false ); 384 385 ok ( nLeaks == 1, "psMemCheckLeaks found %d leaks.", nLeaks ); 386 skip_start ( nLeaks != 1, 3, "psMemCheckLeaks found %d leaks.", nLeaks ); 387 388 ok ( blks[ 0 ] ->lineno == lineMark, "psMemCheckLeaks found leaks"); 389 skip_start ( blks[ 0 ] ->lineno==lineMark,2,"psMemCheckLeaks found leaks"); 390 391 psFree( buffers[ 4 ] ); 392 psFree( blks ); 393 394 for ( lcv = 0;lcv < numBuffers;lcv++ ) { 395 lineMark = __LINE__ + 1; 396 buffers[ lcv ] = psAlloc( sizeof( psS32 ) ); 397 } 398 399 for ( lcv = 0;lcv < numBuffers;lcv++ ) { 400 if ( lcv % 2 == 0 ) { 401 psFree( buffers[ lcv ] ); 402 } 403 } 404 405 nLeaks = psMemCheckLeaks( currentId, &blks, stderr, false ); 406 407 ok ( nLeaks == 2, "psMemCheckLeaks found %d leaks.", nLeaks); 408 skip_start ( nLeaks != 2, 1, "psMemCheckLeaks found %d leaks.", nLeaks); 409 410 ok ( blks[ 0 ] ->lineno == lineMark, 411 "psMemCheckLeaks found a leak other than the expected." ); 412 413 skip_end(); 414 skip_end(); 415 skip_end(); 416 skip_end(); 417 skip_end(); 418 419 psFree( blks ); 420 psFree( buffers[ 1 ] ); 421 psFree( buffers[ 3 ] ); 297 298 //HERE 299 // memCheckTypes() 300 if (1) { 301 psMemId id = psMemGetId(); 302 psArray *negative = psArrayAlloc(2); 303 psMetadata *neg = psMetadataAlloc(); 304 305 psArray *array = psArrayAlloc(100); 306 int okay = psMemCheckType(PS_DATA_ARRAY,array); 307 if (!okay) { 308 psFree(array); 309 } 310 ok(okay, "psMemCheckArray in memCheckType"); 311 312 ok(!psMemCheckType(PS_DATA_ARRAY, neg), "psMemCheckType with metadata input"); 313 psFree(array); 314 315 psBitSet *bits; 316 bits = psBitSetAlloc(100); 317 okay = psMemCheckType(PS_DATA_BITSET, bits); 318 if (!okay ) 319 psFree(bits); 320 ok(okay, "psMemCheckBitSet in memCheckType"); 321 ok(!psMemCheckType(PS_DATA_BITSET, negative), "psMemCheckType on psArray"); 322 psFree(bits); 323 324 psCube *cube; 325 cube = psCubeAlloc(); 326 okay = psMemCheckType(PS_DATA_CUBE, cube); 327 if (!okay ) 328 psFree(cube); 329 ok(okay, "psMemCheckCube in memCheckType"); 330 psFree(cube); 331 332 psFits *fits; 333 fits = psFitsOpen("test.fits","w"); 334 psImage* img = psImageAlloc(16,16,PS_TYPE_F32); 335 psFitsWriteImage(fits,NULL,img,1,NULL); 336 psFree(img); 337 okay = psMemCheckType(PS_DATA_FITS, fits); 338 if (!okay ) 339 psFree(fits); 340 ok(okay, "psMemCheckFits in memCheckType"); 341 psFitsClose(fits); 342 343 psHash *hash; 344 hash = psHashAlloc(100); 345 okay = psMemCheckType(PS_DATA_HASH, hash); 346 if (!okay ) 347 psFree(hash); 348 ok(okay, "psMemCheckHash in memCheckType"); 349 psFree(hash); 350 351 psHistogram *histogram; 352 histogram = psHistogramAlloc(1.1, 2.2, 2); 353 okay = psMemCheckType(PS_DATA_HISTOGRAM, histogram); 354 if (!okay ) 355 psFree(histogram); 356 ok(okay, "psMemCheckHistogram in memCheckType"); 357 psFree(histogram); 358 359 psImage *image; 360 image = psImageAlloc(5, 5, PS_TYPE_F32); 361 okay = psMemCheckType(PS_DATA_IMAGE, image); 362 if (!okay ) 363 psFree(image); 364 ok(okay, "psMemCheckImage in memCheckType"); 365 psFree(image); 366 367 psKernel *kernel; 368 kernel = psKernelAlloc(0, 1, 0, 1); 369 okay = psMemCheckType(PS_DATA_KERNEL, kernel); 370 if (!okay ) 371 psFree(kernel); 372 ok(okay, "psMemCheckKernel in memCheckType"); 373 psFree(kernel); 374 375 psList *list; 376 list = psListAlloc(NULL); 377 okay = psMemCheckType(PS_DATA_LIST, list); 378 if (!okay ) 379 psFree(list); 380 ok(okay, "psMemCheckList in memCheckType"); 381 psFree(list); 382 383 psLookupTable *lookup; 384 char *file = "tableF32.dat"; 385 char *format = "\%f \%lf \%d \%ld"; 386 lookup = psLookupTableAlloc(file, format, 10); 387 okay = psMemCheckType(PS_DATA_LOOKUPTABLE, lookup); 388 if (!okay ) 389 psFree(lookup); 390 ok(okay, "psMemCheckLookupTable in memCheckType"); 391 psFree(lookup); 392 393 psMetadata *metadata; 394 metadata = psMetadataAlloc(); 395 okay = psMemCheckType(PS_DATA_METADATA, metadata); 396 if (!okay ) 397 psFree(metadata); 398 ok(okay, "psMemCheckMetadata in memCheckType"); 399 psFree(metadata); 400 401 psMetadataItem *metaItem; 402 metaItem = psMetadataItemAlloc("name", PS_DATA_S32, "COMMENT", 1); 403 okay = psMemCheckType(PS_DATA_METADATAITEM, metaItem); 404 if (!okay ) 405 psFree(metaItem); 406 ok(okay, "psMemCheckMetadataItem in memCheckType"); 407 psFree(metaItem); 408 409 psMinimization *min; 410 min = psMinimizationAlloc(3, 0.1); 411 okay = psMemCheckType(PS_DATA_MINIMIZATION, min); 412 if (!okay ) 413 psFree(min); 414 ok(okay, "psMemCheckMinimization in memCheckType"); 415 psFree(min); 416 417 psPixels *pixels; 418 pixels = psPixelsAlloc(100); 419 okay = psMemCheckType(PS_DATA_PIXELS, pixels); 420 if (!okay ) 421 psFree(pixels); 422 ok(okay, "psMemCheckPixels in memCheckType"); 423 psFree(pixels); 424 425 psPlane *plane; 426 plane = psPlaneAlloc(); 427 okay = psMemCheckType(PS_DATA_PLANE, plane); 428 if (!okay ) 429 psFree(plane); 430 ok(okay, "psMemCheckPlane in memCheckType."); 431 psFree(plane); 432 433 psPlaneDistort *planeDistort; 434 planeDistort = psPlaneDistortAlloc(1, 1, 1, 1); 435 okay = psMemCheckType(PS_DATA_PLANEDISTORT, planeDistort); 436 if (!okay ) 437 psFree(planeDistort); 438 ok(okay, "psMemCheckPlaneDistort in memCheckType."); 439 psFree(planeDistort); 440 441 psPlaneTransform *planeTransform; 442 planeTransform = psPlaneTransformAlloc(1, 1); 443 okay = psMemCheckType(PS_DATA_PLANETRANSFORM, planeTransform); 444 if (!okay ) 445 psFree(planeTransform); 446 ok(okay, "psMemCheckPlaneTransform in memCheckType"); 447 psFree(planeTransform); 448 449 psPolynomial1D *poly1; 450 poly1 = psPolynomial1DAlloc(PS_POLYNOMIAL_ORD, 2); 451 okay = psMemCheckType(PS_DATA_POLYNOMIAL1D, poly1); 452 if (!okay ) 453 psFree(poly1); 454 ok(okay, "psMemCheckPolynomial1D in memCheckType"); 455 psFree(poly1); 456 457 psPolynomial2D *poly2; 458 poly2 = psPolynomial2DAlloc(PS_POLYNOMIAL_ORD, 2, 1); 459 okay = psMemCheckType(PS_DATA_POLYNOMIAL2D, poly2); 460 if (!okay ) 461 psFree(poly2); 462 ok(okay, "psMemCheckPolynomial2D in memCheckType"); 463 psFree(poly2); 464 465 psPolynomial3D *poly3; 466 poly3 = psPolynomial3DAlloc(PS_POLYNOMIAL_ORD, 2, 1, 1); 467 okay = psMemCheckType(PS_DATA_POLYNOMIAL3D, poly3); 468 if (!okay ) 469 psFree(poly3); 470 ok(okay, "psMemCheckPolynomial3D in memCheckType"); 471 psFree(poly3); 472 473 psPolynomial4D *poly4; 474 poly4 = psPolynomial4DAlloc(PS_POLYNOMIAL_ORD, 2, 1, 2, 1); 475 okay = psMemCheckType(PS_DATA_POLYNOMIAL4D, poly4); 476 if (!okay ) 477 psFree(poly4); 478 ok(okay, "psMemCheckPolynomial4D in memCheckType"); 479 psFree(poly4); 480 481 psProjection *proj; 482 proj = psProjectionAlloc(1, 1, 2.1, 2.1, PS_PROJ_TAN); 483 okay = psMemCheckType(PS_DATA_PROJECTION, proj); 484 if (!okay ) 485 psFree(proj); 486 ok(okay, "psMemCheckProjection in memCheckType."); 487 psFree(proj); 488 489 psScalar *scalar; 490 psF64 f64 = 1.1; 491 scalar = psScalarAlloc(f64, PS_TYPE_F64); 492 okay = psMemCheckType(PS_DATA_SCALAR, scalar); 493 if (!okay ) 494 psFree(scalar); 495 ok(okay, "psMemCheckScalar in memCheckType"); 496 psFree(scalar); 497 498 psSphere *sphere; 499 sphere = psSphereAlloc(); 500 okay = psMemCheckType(PS_DATA_SPHERE, sphere); 501 if (!okay ) 502 psFree(sphere); 503 ok(okay, "psMemCheckSphere in memCheckType"); 504 psFree(sphere); 505 506 psSphereRot *sphereRot; 507 sphereRot = psSphereRotAlloc(0, 0, 20); 508 okay = psMemCheckType(PS_DATA_SPHEREROT, sphereRot); 509 if (!okay ) 510 psFree(sphereRot); 511 ok(okay, "psMemCheckSphereRot in memCheckType"); 512 psFree(sphereRot); 513 514 psSpline1D *spline; 515 spline = psSpline1DAlloc(2, 1, 0, 2); 516 okay = psMemCheckType(PS_DATA_SPLINE1D, spline); 517 if (!okay ) 518 psFree(spline); 519 ok(okay, "psMemCheckSpline1D in memCheckType"); 520 psFree(spline); 521 522 psStats *stats; 523 stats = psStatsAlloc(PS_STAT_MAX); 524 okay = psMemCheckType(PS_DATA_STATS, stats); 525 if (!okay ) 526 psFree(stats); 527 ok(okay, "psMemCheckStats in memCheckType"); 528 psFree(stats); 529 530 psTime *time; 531 time = psTimeAlloc(PS_TIME_UT1); 532 okay = psMemCheckType(PS_DATA_TIME, time); 533 if (!okay ) 534 psFree(time); 535 ok(okay, "psMemCheckTime in memCheckType"); 536 psFree(time); 537 538 psVector *vector; 539 vector = psVectorAlloc(100, PS_TYPE_F32); 540 okay = psMemCheckType(PS_DATA_VECTOR, vector); 541 ok(okay, "psMemCheckVector in memCheckType"); 542 psFree(vector); 543 psFree(negative); 544 psFree(neg); 545 ok(!psMemCheckLeaks(id, NULL, NULL, false), "no memory leaks"); 546 } 422 547 } 423 548 … … 455 580 psFree( buffer ); 456 581 457 ok (corruptions == 1,582 ok(corruptions == 1, 458 583 "Expected one memory corruption but found %d", corruptions ); 459 skip_start ( corruptions != 1, 460 1, "Expected one memory corruption but found %d", corruptions ); 461 462 ok ( problemCallbackCalled == 1, "The memProblemCallback was invoked" ); 463 464 skip_end(); 584 ok(problemCallbackCalled == 1, "The memProblemCallback was invoked" ); 465 585 } 466 586 #endif … … 500 620 } 501 621 502 psS32 memCheckTypes( void ) 503 { 504 psArray *negative; 505 negative = psArrayAlloc(2); 506 psMetadata *neg; 507 neg = psMetadataAlloc(); 508 509 psArray *array; 510 array = psArrayAlloc(100); 511 int okay = psMemCheckType(PS_DATA_ARRAY,array); 512 if ( ! okay ) 513 psFree(array); 514 ok ( okay, "psMemCheckArray in memCheckType"); 515 skip_start( ! okay, 28, "psMemCheckArray in memCheckType"); 516 517 ok ( psMemCheckType(PS_DATA_ARRAY, neg), "psMemCheckArray in memCheckType"); 518 psFree(array); 519 520 psBitSet *bits; 521 bits = psBitSetAlloc(100); 522 okay = psMemCheckType(PS_DATA_BITSET, bits); 523 if ( ! okay ) 524 psFree(bits); 525 ok ( okay, "psMemCheckBitSet in memCheckType"); 526 skip_start ( !okay, 27, "psMemCheckBitSet in memCheckType"); 527 528 ok ( psMemCheckType(PS_DATA_BITSET, negative), 529 "psMemCheckBitSet in memCheckType"); 530 psFree(bits); 531 532 psCube *cube; 533 cube = psCubeAlloc(); 534 okay = psMemCheckType(PS_DATA_CUBE, cube); 535 if ( ! okay ) 536 psFree(cube); 537 ok ( okay, "psMemCheckCube in memCheckType"); 538 skip_start ( !okay, 26, "psMemCheckCube in memCheckType"); 539 psFree(cube); 540 541 psFits *fits; 542 fits = psFitsOpen("test.fits","w"); 543 psImage* img = psImageAlloc(16,16,PS_TYPE_F32); 544 psFitsWriteImage(fits,NULL,img,1,NULL); 545 psFree(img); 546 okay = psMemCheckType(PS_DATA_FITS, fits); 547 if ( ! okay ) 548 psFree(fits); 549 ok ( okay, "psMemCheckFits in memCheckType"); 550 skip_start ( !okay, 25,"psMemCheckFits in memCheckType"); 551 psFitsClose(fits); 552 553 psHash *hash; 554 hash = psHashAlloc(100); 555 okay = psMemCheckType(PS_DATA_HASH, hash); 556 if ( ! okay ) 557 psFree(hash); 558 ok ( okay, "psMemCheckHash in memCheckType"); 559 skip_start ( !okay, 24, "psMemCheckHash in memCheckType"); 560 psFree(hash); 561 562 psHistogram *histogram; 563 histogram = psHistogramAlloc(1.1, 2.2, 2); 564 okay = psMemCheckType(PS_DATA_HISTOGRAM, histogram); 565 if ( ! okay ) 566 psFree(histogram); 567 ok ( okay, "psMemCheckHistogram in memCheckType"); 568 skip_start ( !okay, 23, "psMemCheckHistogram in memCheckType"); 569 psFree(histogram); 570 571 psImage *image; 572 image = psImageAlloc(5, 5, PS_TYPE_F32); 573 okay = psMemCheckType(PS_DATA_IMAGE, image); 574 if ( ! okay ) 575 psFree(image); 576 ok ( okay, "psMemCheckImage in memCheckType"); 577 skip_start ( !okay, 22, "psMemCheckImage in memCheckType"); 578 psFree(image); 579 580 psKernel *kernel; 581 kernel = psKernelAlloc(0, 1, 0, 1); 582 okay = psMemCheckType(PS_DATA_KERNEL, kernel); 583 if ( ! okay ) 584 psFree(kernel); 585 ok ( okay, "psMemCheckKernel in memCheckType"); 586 skip_start ( !okay, 21, "psMemCheckKernel in memCheckType"); 587 psFree(kernel); 588 589 psList *list; 590 list = psListAlloc(NULL); 591 okay = psMemCheckType(PS_DATA_LIST, list); 592 if ( ! okay ) 593 psFree(list); 594 ok ( okay, "psMemCheckList in memCheckType"); 595 skip_start ( !okay, 20, "psMemCheckList in memCheckType"); 596 psFree(list); 597 598 psLookupTable *lookup; 599 char *file = "tableF32.dat"; 600 char *format = "\%f \%lf \%d \%ld"; 601 lookup = psLookupTableAlloc(file, format, 10); 602 okay = psMemCheckType(PS_DATA_LOOKUPTABLE, lookup); 603 if ( ! okay ) 604 psFree(lookup); 605 ok ( okay, "psMemCheckLookupTable in memCheckType"); 606 skip_start ( !okay, 19, "psMemCheckLookupTable in memCheckType"); 607 psFree(lookup); 608 609 psMetadata *metadata; 610 metadata = psMetadataAlloc(); 611 okay = psMemCheckType(PS_DATA_METADATA, metadata); 612 if ( ! okay ) 613 psFree(metadata); 614 ok ( okay, "psMemCheckMetadata in memCheckType"); 615 skip_start ( !okay, 18, "psMemCheckMetadata in memCheckType"); 616 psFree(metadata); 617 618 psMetadataItem *metaItem; 619 metaItem = psMetadataItemAlloc("name", PS_DATA_S32, "COMMENT", 1); 620 okay = psMemCheckType(PS_DATA_METADATAITEM, metaItem); 621 if ( ! okay ) 622 psFree(metaItem); 623 ok ( okay, "psMemCheckMetadataItem in memCheckType"); 624 skip_start ( !okay, 17, "psMemCheckMetadataItem in memCheckType"); 625 psFree(metaItem); 626 627 psMinimization *min; 628 min = psMinimizationAlloc(3, 0.1); 629 okay = psMemCheckType(PS_DATA_MINIMIZATION, min); 630 if ( ! okay ) 631 psFree(min); 632 ok ( okay, "psMemCheckMinimization in memCheckType"); 633 skip_start ( !okay, 16, "psMemCheckMinimization in memCheckType"); 634 psFree(min); 635 636 psPixels *pixels; 637 pixels = psPixelsAlloc(100); 638 okay = psMemCheckType(PS_DATA_PIXELS, pixels); 639 if ( ! okay ) 640 psFree(pixels); 641 ok ( okay, "psMemCheckPixels in memCheckType"); 642 skip_start ( !okay, 15, "psMemCheckPixels in memCheckType"); 643 psFree(pixels); 644 645 psPlane *plane; 646 plane = psPlaneAlloc(); 647 okay = psMemCheckType(PS_DATA_PLANE, plane); 648 if ( ! okay ) 649 psFree(plane); 650 ok ( okay, "psMemCheckPlane in memCheckType."); 651 skip_start ( !okay, 14, "psMemCheckPlane in memCheckType."); 652 psFree(plane); 653 654 psPlaneDistort *planeDistort; 655 planeDistort = psPlaneDistortAlloc(1, 1, 1, 1); 656 okay = psMemCheckType(PS_DATA_PLANEDISTORT, planeDistort); 657 if ( ! okay ) 658 psFree(planeDistort); 659 ok ( okay, "psMemCheckPlaneDistort in memCheckType."); 660 skip_start ( !okay, 13, "psMemCheckPlaneDistort in memCheckType."); 661 psFree(planeDistort); 662 663 psPlaneTransform *planeTransform; 664 planeTransform = psPlaneTransformAlloc(1, 1); 665 okay = psMemCheckType(PS_DATA_PLANETRANSFORM, planeTransform); 666 if ( ! okay ) 667 psFree(planeTransform); 668 ok ( okay, "psMemCheckPlaneTransform in memCheckType"); 669 skip_start ( !okay, 12, "psMemCheckPlaneTransform in memCheckType"); 670 psFree(planeTransform); 671 672 psPolynomial1D *poly1; 673 poly1 = psPolynomial1DAlloc(PS_POLYNOMIAL_ORD, 2); 674 okay = psMemCheckType(PS_DATA_POLYNOMIAL1D, poly1); 675 if ( ! okay ) 676 psFree(poly1); 677 ok ( okay, "psMemCheckPolynomial1D in memCheckType"); 678 skip_start ( !okay, 11, "psMemCheckPolynomial1D in memCheckType"); 679 psFree(poly1); 680 681 psPolynomial2D *poly2; 682 poly2 = psPolynomial2DAlloc(PS_POLYNOMIAL_ORD, 2, 1); 683 okay = psMemCheckType(PS_DATA_POLYNOMIAL2D, poly2); 684 if ( ! okay ) 685 psFree(poly2); 686 ok ( okay, "psMemCheckPolynomial2D in memCheckType"); 687 skip_start ( !okay, 10, "psMemCheckPolynomial2D in memCheckType"); 688 psFree(poly2); 689 690 psPolynomial3D *poly3; 691 poly3 = psPolynomial3DAlloc(PS_POLYNOMIAL_ORD, 2, 1, 1); 692 okay = psMemCheckType(PS_DATA_POLYNOMIAL3D, poly3); 693 if ( ! okay ) 694 psFree(poly3); 695 ok ( okay, "psMemCheckPolynomial3D in memCheckType"); 696 skip_start ( !okay, 9, "psMemCheckPolynomial3D in memCheckType"); 697 psFree(poly3); 698 699 psPolynomial4D *poly4; 700 poly4 = psPolynomial4DAlloc(PS_POLYNOMIAL_ORD, 2, 1, 2, 1); 701 okay = psMemCheckType(PS_DATA_POLYNOMIAL4D, poly4); 702 if ( ! okay ) 703 psFree(poly4); 704 ok ( okay, "psMemCheckPolynomial4D in memCheckType"); 705 skip_start ( !okay, 8, "psMemCheckPolynomial4D in memCheckType"); 706 psFree(poly4); 707 708 psProjection *proj; 709 proj = psProjectionAlloc(1, 1, 2.1, 2.1, PS_PROJ_TAN); 710 okay = psMemCheckType(PS_DATA_PROJECTION, proj); 711 if ( ! okay ) 712 psFree(proj); 713 ok ( okay, "psMemCheckProjection in memCheckType."); 714 skip_start ( !okay, 7, "psMemCheckProjection in memCheckType."); 715 psFree(proj); 716 717 psScalar *scalar; 718 psF64 f64 = 1.1; 719 scalar = psScalarAlloc(f64, PS_TYPE_F64); 720 okay = psMemCheckType(PS_DATA_SCALAR, scalar); 721 if ( ! okay ) 722 psFree(scalar); 723 ok ( okay, "psMemCheckScalar in memCheckType"); 724 skip_start ( !okay, 6, "psMemCheckScalar in memCheckType"); 725 psFree(scalar); 726 727 psSphere *sphere; 728 sphere = psSphereAlloc(); 729 okay = psMemCheckType(PS_DATA_SPHERE, sphere); 730 if ( ! okay ) 731 psFree(sphere); 732 ok ( okay, "psMemCheckSphere in memCheckType"); 733 skip_start ( !okay, 5, "psMemCheckSphere in memCheckType"); 734 psFree(sphere); 735 736 psSphereRot *sphereRot; 737 sphereRot = psSphereRotAlloc(0, 0, 20); 738 okay = psMemCheckType(PS_DATA_SPHEREROT, sphereRot); 739 if ( ! okay ) 740 psFree(sphereRot); 741 ok( okay, "psMemCheckSphereRot in memCheckType"); 742 skip_start( !okay, 4, "psMemCheckSphereRot in memCheckType"); 743 psFree(sphereRot); 744 745 psSpline1D *spline; 746 spline = psSpline1DAlloc(2, 1, 0, 2); 747 okay = psMemCheckType(PS_DATA_SPLINE1D, spline); 748 if ( ! okay ) 749 psFree(spline); 750 ok( okay, "psMemCheckSpline1D in memCheckType"); 751 skip_start( !okay, 3, "psMemCheckSpline1D in memCheckType"); 752 psFree(spline); 753 754 psStats *stats; 755 stats = psStatsAlloc(PS_STAT_MAX); 756 okay = psMemCheckType(PS_DATA_STATS, stats); 757 if ( ! okay ) 758 psFree(stats); 759 ok( okay, "psMemCheckStats in memCheckType"); 760 skip_start( !okay, 2, "psMemCheckStats in memCheckType"); 761 psFree(stats); 762 763 psTime *time; 764 time = psTimeAlloc(PS_TIME_UT1); 765 okay = psMemCheckType(PS_DATA_TIME, time); 766 if ( ! okay ) 767 psFree(time); 768 ok( okay, "psMemCheckTime in memCheckType"); 769 skip_start( !okay, 1, "psMemCheckTime in memCheckType"); 770 psFree(time); 771 772 psVector *vector; 773 vector = psVectorAlloc(100, PS_TYPE_F32); 774 okay = psMemCheckType(PS_DATA_VECTOR, vector); 775 ok( okay, "psMemCheckVector in memCheckType"); 776 psFree(vector); 777 778 skip_end(); 779 skip_end(); 780 skip_end(); 781 skip_end(); 782 skip_end(); 783 skip_end(); 784 skip_end(); 785 skip_end(); 786 skip_end(); 787 skip_end(); 788 skip_end(); 789 skip_end(); 790 skip_end(); 791 skip_end(); 792 skip_end(); 793 skip_end(); 794 skip_end(); 795 skip_end(); 796 skip_end(); 797 skip_end(); 798 skip_end(); 799 skip_end(); 800 skip_end(); 801 skip_end(); 802 skip_end(); 803 skip_end(); 804 skip_end(); 805 skip_end(); 806 807 psFree(negative); 808 psFree(neg); 809 810 return 0; 811 } 622 -
trunk/psLib/test/sys/tap_psString.c
r12607 r12781 20 20 * @author Eric Van Alst, MHPCC 21 21 * 22 * @version $Revision: 1. 7$ $Name: not supported by cvs2svn $23 * @date $Date: 2007-0 3-27 22:52:03$22 * @version $Revision: 1.8 $ $Name: not supported by cvs2svn $ 23 * @date $Date: 2007-04-10 21:09:31 $ 24 24 * 25 25 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 35 35 #define STR_0 "binky had a leeeetle lamb" 36 36 37 psS32 testStringCopy00(void);38 psS32 testStringCopy01(void);39 psS32 testStringCopy02(void);40 psS32 testStringCopy03(void);41 psS32 testStringCopy04(void);42 //psS32 testStringCopy05(void);43 psS32 testStringCopy06(void);44 45 psS32 testStrAppend00(void);46 psS32 testStrAppend01(void);47 psS32 testStrAppend02(void);48 psS32 testStrAppend03(void);49 50 psS32 testStrPrepend00(void);51 psS32 testStrPrepend01(void);52 psS32 testStrPrepend02(void);53 psS32 testStrPrepend03(void);54 55 psS32 testStrSplit00(void);56 psS32 testNULLStrings(void);57 psS32 testStrCheck(void);58 59 37 60 38 psS32 main( psS32 argc, char* argv[] ) 61 39 { 62 plan_tests(55); 63 64 testStringCopy00(); 65 testStringCopy01(); 66 testStringCopy02(); 67 testStringCopy03(); 68 testStringCopy04(); 69 testStringCopy06(); 70 71 testStrAppend00(); 72 testStrAppend01(); 73 testStrAppend02(); 74 testStrAppend03(); 75 76 testStrPrepend00(); 77 testStrPrepend01(); 78 testStrPrepend02(); 79 testStrPrepend03(); 80 81 testStrSplit00(); 82 testNULLStrings(); 83 testStrCheck(); 84 } 85 86 87 psS32 testStringCopy00(void) 88 { 89 // diag("testStringCopy00"); 90 91 char stringval[20] = "E R R O R"; 92 psS32 result = 0; 93 psS32 result1 = 0; 94 char *strResult; 95 96 // Test point #1 Verify string copy - psStringCopy 97 strResult = psStringCopy(stringval); 98 // Perform string compare 99 result = strcmp(strResult, stringval); 100 // Modify original string 101 stringval[0]='G'; 102 result1 = strcmp(strResult, stringval); 103 stringval[0]='E'; 104 ok ( ( result == 0 ) && ( result1 != 0), 105 "Failed test point #1 strcmp result = %d expected 0\n",result); 106 107 // Free memory allocated 108 psFree(strResult); 109 110 return 0; 111 } 112 113 114 psS32 testStringCopy01(void) 115 { 116 // diag("testStringCopy01"); 117 118 char *emptyval = ""; 119 psS32 result = 0; 120 char *strResult; 121 122 // Test point #2 Verify empty string copy - psStringCopy 123 strResult = psStringCopy(emptyval); 124 // Perform string compare 125 result = strcmp(strResult, emptyval); 126 ok ( result == 0, 127 "test point #2 strcmp result = %d expected 0\n",result); 128 129 // Free memory allocated 130 psFree(strResult); 131 132 return 0; 133 } 134 135 136 psS32 testStringCopy02(void) 137 { 138 // diag("testStringCopy02"); 139 140 psS32 result = 0; 141 psS32 result1 = 0; 142 char *strResult; 143 char stringval1[20] = "e r r o r"; 144 psS32 substringlen = 5; 145 char *substringval = "e r r"; 146 147 // Test point #3 Verify string copy with length - psStringNCopy 148 strResult = psStringNCopy(stringval1, substringlen); 149 // Perform string compare and get string length 150 result = strncmp(strResult, substringval, substringlen); 151 // Change original string 152 stringval1[0] = 'g'; 153 result1 = strncmp(strResult, substringval, substringlen); 154 ok ( ( result == 0 ) && ( result1 == 0 ), 155 "Failed test point #3 strcmp result = %d expected 0\n",result); 156 157 // Free memory allocated 158 psFree(strResult); 159 160 return 0; 161 } 162 163 psS32 testStringCopy03(void) 164 { 165 // diag("testStringCopy03"); 166 167 psS32 result = 0; 168 psS32 result1 = 0; 169 char *strResult; 170 char *stringvalnocopy = "F A I L"; 171 172 // Test point #4 Verify empty string copy with length - psStringNCopy 173 strResult = psStringNCopy(stringvalnocopy, 0); 174 // Perform string compare and get sting length 175 result = strcmp(strResult, stringvalnocopy); 176 result1 = strlen(strResult); 177 ok ( result != 0, 178 "test point #4 strcmp result = %d didn't expected %d\n",result,0); 179 180 // Free memory 181 psFree(strResult); 182 183 return 0; 184 } 185 186 psS32 testStringCopy04(void) 187 { 188 // diag("testStringCopy04"); 189 190 psS32 result = 0; 191 psS32 result1 = 0; 192 char *strResult; 193 char stringval[20] = "E R R O R"; 194 psS32 increaseSize = 5; 195 196 // Test point #5 Copy string to larger string - psStringNCopy 197 strResult = psStringNCopy(stringval, (strlen(stringval) + increaseSize)); 198 // Perform string compare and get string length 199 result = strcmp(strResult, stringval); 200 result1 = strlen(strResult); 201 // The strings should still compare 202 ok ( result == 0 && result1 == strlen(stringval), 203 "test point #5 strcmp result = %d expected %d\n",result,0); 204 205 // Free memory 206 psFree(strResult); 207 208 return 0; 209 } 40 psLogSetFormat("HLNM"); 41 psLogSetLevel(PS_LOG_INFO); 42 plan_tests(72); 43 44 45 //testStringCopy00() 46 { 47 psMemId id = psMemGetId(); 48 char stringval[20] = "E R R O R"; 49 psS32 result = 0; 50 psS32 result1 = 0; 51 char *strResult; 52 53 // Test point #1 Verify string copy - psStringCopy 54 strResult = psStringCopy(stringval); 55 // Perform string compare 56 result = strcmp(strResult, stringval); 57 // Modify original string 58 stringval[0]='G'; 59 result1 = strcmp(strResult, stringval); 60 stringval[0]='E'; 61 ok(( result == 0 ) && ( result1 != 0), 62 "Failed test point #1 strcmp result = %d expected 0",result); 63 // Free memory allocated 64 psFree(strResult); 65 ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks"); 66 } 67 68 69 // testStringCopy01() 70 { 71 psMemId id = psMemGetId(); 72 char *emptyval = ""; 73 psS32 result = 0; 74 char *strResult; 75 76 // Test point #2 Verify empty string copy - psStringCopy 77 strResult = psStringCopy(emptyval); 78 // Perform string compare 79 result = strcmp(strResult, emptyval); 80 ok(result == 0, 81 "test point #2 strcmp result = %d expected 0",result); 82 // Free memory allocated 83 psFree(strResult); 84 ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks"); 85 } 86 87 88 // testStringCopy02() 89 { 90 psMemId id = psMemGetId(); 91 psS32 result = 0; 92 psS32 result1 = 0; 93 char *strResult; 94 char stringval1[20] = "e r r o r"; 95 psS32 substringlen = 5; 96 char *substringval = "e r r"; 97 98 // Test point #3 Verify string copy with length - psStringNCopy 99 strResult = psStringNCopy(stringval1, substringlen); 100 // Perform string compare and get string length 101 result = strncmp(strResult, substringval, substringlen); 102 // Change original string 103 stringval1[0] = 'g'; 104 result1 = strncmp(strResult, substringval, substringlen); 105 ok(( result == 0 ) && ( result1 == 0 ), 106 "Failed test point #3 strcmp result = %d expected 0",result); 107 psFree(strResult); 108 ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks"); 109 } 110 111 112 // testStringCopy03() 113 { 114 psMemId id = psMemGetId(); 115 psS32 result = 0; 116 psS32 result1 = 0; 117 char *strResult; 118 char *stringvalnocopy = "F A I L"; 119 120 // Test point #4 Verify empty string copy with length - psStringNCopy 121 strResult = psStringNCopy(stringvalnocopy, 0); 122 // Perform string compare and get sting length 123 result = strcmp(strResult, stringvalnocopy); 124 result1 = strlen(strResult); 125 ok(result != 0, 126 "test point #4 strcmp result = %d didn't expected %d",result,0); 127 psFree(strResult); 128 ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks"); 129 } 130 131 132 // testStringCopy04() 133 { 134 psMemId id = psMemGetId(); 135 psS32 result = 0; 136 psS32 result1 = 0; 137 char *strResult; 138 char stringval[20] = "E R R O R"; 139 psS32 increaseSize = 5; 140 141 // Test point #5 Copy string to larger string - psStringNCopy 142 strResult = psStringNCopy(stringval, (strlen(stringval) + increaseSize)); 143 // Perform string compare and get string length 144 result = strcmp(strResult, stringval); 145 result1 = strlen(strResult); 146 // The strings should still compare 147 ok(result == 0 && result1 == strlen(stringval), 148 "test point #5 strcmp result = %d expected %d",result,0); 149 psFree(strResult); 150 ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks"); 151 } 210 152 211 153 // XXX This test needs to be modified to check for maximum size 212 154 // This will require a mod to psStringNCopy source to check for maximum size 213 155 // 214 //psS32 testStringCopy05( void)156 //psS32 testStringCopy05() 215 157 //{ 216 158 // char *strResult; … … 231 173 232 174 233 psS32 testStringCopy06(void) 234 { 235 // diag("testStringCopy06"); 236 237 char *strResult; 238 char stringval[20] = "E R R O R"; 239 psS32 result = 0; 240 241 // Test point #7 Verify creation of string literal - PS_STRING 242 strResult = PS_STRING(E R R O R); 243 result = strcmp(strResult, stringval); 244 ok ( result == 0, 245 "test point #7 strcmp result = %d expected %d",result,0); 246 247 // Memory should not have been allocated 248 return 0; 175 // testStringCopy06() 176 { 177 psMemId id = psMemGetId(); 178 char *strResult; 179 char stringval[20] = "E R R O R"; 180 psS32 result = 0; 181 182 // Test point #7 Verify creation of string literal - PS_STRING 183 strResult = PS_STRING(E R R O R); 184 result = strcmp(strResult, stringval); 185 ok(result == 0, 186 "test point #7 strcmp result = %d expected %d",result,0); 187 // Memory should not have been allocated 188 ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks"); 189 } 190 191 192 // testStrAppend00() 193 { 194 psMemId id = psMemGetId(); 195 char *str = psStringCopy("3.14159"); 196 psStringAppend(&str, "%d%s", 2653589, "79323846"); 197 // Test point: Verify string append 198 int result = strcmp(str, "3.14159265358979323846"); 199 ok(result == 0, "Failed test point"); 200 psFree(str); 201 ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks"); 202 } 203 204 205 // testStrAppend01() 206 { 207 psMemId id = psMemGetId(); 208 char *str=NULL; 209 // test nonsensical invocations ... 210 ssize_t sz = psStringAppend(NULL, NULL); 211 ok(sz == 0, "Failed test point"); 212 sz = psStringAppend(&str, NULL); 213 ok(sz == 0, "Failed test point"); 214 ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks"); 215 } 216 217 218 // testStrAppend02() 219 { 220 psMemId id = psMemGetId(); 221 char *str=NULL; 222 // test string creation 223 psStringAppend(&str, "%s", "fubar"); 224 int result = strcmp(str, "fubar"); 225 ok(result == 0, "Failed test point"); 226 psFree(str); 227 ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks"); 228 } 229 230 231 // testStrAppend03() 232 { 233 psMemId id = psMemGetId(); 234 char *str =psStringCopy(STR_0); 235 // test null-op 236 psStringAppend(&str, "%s", ""); 237 is_str(str, STR_0, "Failed test point"); 238 psFree(str); 239 ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks"); 240 } 241 242 243 // testStrPrepend00() 244 { 245 psMemId id = psMemGetId(); 246 char *str = psStringCopy("79323846"); 247 psStringPrepend(&str, "%s%d","3.14159", 2653589 ); 248 // Test point: Verify string append 249 int result = strcmp(str, "3.14159265358979323846"); 250 ok(result == 0, "Failed test point"); 251 psFree(str); 252 ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks"); 253 } 254 255 256 // testStrPrepend01() 257 { 258 psMemId id = psMemGetId(); 259 char *str=NULL; 260 // test nonsensical invocations ... 261 ssize_t sz = psStringPrepend(NULL, NULL); 262 ok(sz == 0, "Failed test point"); 263 sz = psStringPrepend(&str, NULL); 264 ok(sz == 0, "Failed test point"); 265 ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks"); 266 } 267 268 269 // testStrPrepend02() 270 { 271 psMemId id = psMemGetId(); 272 char *str=NULL; 273 // test string creation 274 psStringPrepend(&str, "%s", "fubar"); 275 int result = strcmp(str, "fubar"); 276 ok(result == 0, "Failed test point"); 277 psFree(str); 278 ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks"); 279 } 280 281 282 // testStrPrepend03() 283 { 284 // test null-op 285 psMemId id = psMemGetId(); 286 char *str = psStringCopy(STR_0); 287 psStringPrepend(&str, "%s", ""); 288 int result = strcmp(str, STR_0); 289 ok(result == 0, "test point str=[%s]", str); 290 psFree(str); 291 ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks"); 292 } 293 294 295 // testStrSplit00() 296 { 297 psMemId id = psMemGetId(); 298 psList *strList = NULL; 299 char str[35]; 300 char split[5]; 301 strncpy(str, "This is, a, test case, to check", 35); 302 strncpy(split, ",", 2); 303 psString psStr; 304 psString psSplit; 305 psStr = psStringCopy(str); 306 psSplit = psStringCopy(split); 307 308 //Return NULL for NULL inputs 309 strList = psStringSplit(NULL, NULL, true); 310 ok(!strList, "psStringSplit" ); 311 psFree(strList); 312 313 strList = NULL; 314 //Return empty list for NULL string input 315 strList = psStringSplit(NULL, split, true); 316 ok(!psListLength(strList), "psListLength()" ); 317 psFree(strList); 318 319 strList = NULL; 320 //Return NULL for NULL splitter input 321 strList = psStringSplit(str, NULL, true); 322 ok(!strList, "psStringSplit" ); 323 psFree(strList); 324 325 strList = NULL; 326 //Return a psList* of psStrings 327 strList = psStringSplit(str, split, true); 328 ok(strList->n == 4, 329 "psStringSplit to return the correct number of strings"); 330 ok(!strncmp((psString)(strList->head->data), "This is", 10), 331 "psStringSplit to return expected strings"); 332 ok(!strncmp((psString)(strList->head->next->data), " a", 10), 333 "psStringSplit to return expected strings"); 334 ok(!strncmp((psString)(strList->head->next->next->data), " test case",10), 335 "psStringSplit to return expected strings"); 336 ok(!strncmp((psString)(strList->head->next->next->next->data), " to check", 10), 337 "psStringSplit failed to return expected strings"); 338 339 psFree(strList); 340 //Return correct psList when using (psString, char*) 341 strList = psStringSplit(psStr, split, true); 342 ok(strList->n == 4, 343 "psStringSplit to return the correct number of strings"); 344 ok(!strncmp((psString)(strList->head->data), "This is", 10), 345 "psStringSplit to return expected strings"); 346 ok(!strncmp((psString)(strList->head->next->data), " a", 10), 347 "psStringSplit failed to return expected strings"); 348 ok(!strncmp((psString)(strList->head->next->next->data), " test case",10), 349 "psStringSplit failed to return expected strings"); 350 ok(!strncmp((psString)(strList->head->next->next->next->data), " to check", 10), 351 "psStringSplit to return expected strings"); 352 353 psFree(strList); 354 //Return correct psList when using (char*, psString) 355 strList = psStringSplit(str, psSplit, true); 356 ok(strList->n == 4, 357 "psStringSplit to return the correct number of strings"); 358 ok(!strncmp((psString)(strList->head->data), "This is", 10), 359 "psStringSplit to return expected strings"); 360 ok(!strncmp((psString)(strList->head->next->data), " a", 10), 361 "psStringSplit to return expected strings"); 362 ok(!strncmp((psString)(strList->head->next->next->data), " test case",10), 363 "psStringSplit to return expected strings"); 364 ok(!strncmp((psString)(strList->head->next->next->next->data), " to check", 10), 365 "psStringSplit to return expected strings"); 366 367 psFree(strList); 368 //Return correct psList when using (psString, psString) 369 strList = psStringSplit(psStr, psSplit, true); 370 ok(strList->n == 4, 371 "psStringSplit to return the correct number of strings"); 372 ok(!strncmp((psString)(strList->head->data), "This is", 10), 373 "psStringSplit to return expected strings"); 374 ok(!strncmp((psString)(strList->head->next->data), " a", 10), 375 "psStringSplit to return expected strings"); 376 ok(!strncmp((psString)(strList->head->next->next->data), " test case",10), 377 "psStringSplit to return expected strings"); 378 ok(!strncmp((psString)(strList->head->next->next->next->data), " to check", 10), 379 "psStringSplit to return expected strings"); 380 381 psFree(strList); 382 //Return correct psList output for string of zero length case 383 strncpy(str, "This is,, a,, test case,, to check", 35); 384 strList = psStringSplit(str, split, false); 385 ok(strList->n == 4, 386 "psStringSplit to return the correct number of strings"); 387 ok(!strncmp((psString)(strList->head->data), "This is", 10), 388 "psStringSplit to return expected strings"); 389 ok(!strncmp((psString)(strList->head->next->data), " a", 10), 390 "psStringSplit to return expected strings"); 391 ok(!strncmp((psString)(strList->head->next->next->data), " test case",10), 392 "psStringSplit to return expected strings"); 393 ok(!strncmp((psString)(strList->head->next->next->next->data), " to check", 10), 394 "psStringSplit to return expected strings"); 395 psFree(strList); 396 psFree(psStr); 397 psFree(psSplit); 398 ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks"); 399 } 400 401 402 // testNULLStrings() 403 { 404 psMemId id = psMemGetId(); 405 psString nullTest = NULL; 406 psString output = NULL; 407 ssize_t outSize = 0; 408 char** nullDest = NULL; 409 char** test = NULL; 410 //psStringCopy should return NULL for NULL input string 411 // psLogMsg(__func__,PS_LOG_INFO,"Following should generate error message"); 412 output = psStringCopy(nullTest); 413 ok(output == NULL, "psStringCopy to return NULL for NULL input string"); 414 415 //psStringNCopy should return NULL for NULL input string 416 output = psStringNCopy(nullTest, 100); 417 ok(output == NULL, "psStringNCopy to return NULL for NULL input string"); 418 419 //psStringAppend should return 0 for NULL input destination 420 outSize = psStringAppend(nullDest, "%s", ""); 421 ok(outSize == 0, "psStringAppend to return 0 for NULL input destination"); 422 423 //psStringAppend should return 0 for NULL input format 424 outSize = psStringAppend(test, nullTest); 425 ok(outSize == 0, "psStringAppend to return 0 for NULL input format"); 426 427 //psStringPrepend should return 0 for NULL input destination 428 outSize = psStringPrepend(nullDest, " "); 429 ok(outSize == 0, "psStringPrepend to return 0 for NULL input destination"); 430 431 //psStringPrepend should return 0 for NULL input format 432 outSize = psStringPrepend(test, nullTest); 433 ok(outSize == 0, "psStringPrepend to return 0 for NULL input format"); 434 435 //psStringSplit should return empty list for NULL input string 436 psList *nullList = NULL; 437 nullList = psStringSplit(nullTest, ",", true); 438 ok(!psListLength(nullList), "psStringSplit to return NULL for NULL input string"); 439 psFree(nullList); 440 441 nullList = NULL; 442 //psStringSplit should return NULL for NULL input splitter 443 nullList = psStringSplit("Hello World", nullTest, true); 444 ok(!nullList, "psStringSplit to return NULL for NULL input splitter"); 445 psFree(nullList); 446 ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks"); 447 } 448 449 450 // testStrCheck() 451 { 452 psMemId id = psMemGetId(); 453 psString str = psStringAlloc(10); 454 strcpy(str, "Hello"); 455 ok(psMemCheckString(str), "psString allocated!"); 456 ok(psMemCheckType(PS_DATA_STRING, str), "psString allocated"); 457 psFree(str); 458 459 char charStr[10]; 460 ok(!psMemCheckType(PS_DATA_STRING, charStr), 461 "Input string is a psDataType"); 462 ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks"); 463 } 249 464 } 250 251 252 psS32 testStrAppend00(void) 253 { 254 // diag("testStrAppend00"); 255 256 char *str=NULL; 257 int result = 0; 258 259 str = psStringCopy("3.14159"); 260 261 psStringAppend(&str, "%d%s", 2653589, "79323846"); 262 263 // Test point: Verify string append 264 result = strcmp(str, "3.14159265358979323846"); 265 ok ( result == 0, "Failed test point\n"); 266 267 psFree(str); 268 269 return 0; 270 } 271 272 psS32 testStrAppend01(void) 273 { 274 // diag("testStrAppend01"); 275 276 ssize_t sz; 277 char *str=NULL; 278 279 // test nonsensical invocations ... 280 sz = psStringAppend(NULL, NULL); 281 ok ( sz == 0, "Failed test point\n"); 282 283 sz = psStringAppend(&str, NULL); 284 ok ( sz == 0, "Failed test point\n"); 285 286 return 0; 287 } 288 289 290 psS32 testStrAppend02(void) 291 { 292 // diag("testStrAppend02"); 293 294 char *str=NULL; 295 int result; 296 297 // test string creation 298 psStringAppend(&str, "%s", "fubar"); 299 result = strcmp(str, "fubar"); 300 ok ( result == 0, "Failed test point\n"); 301 302 psFree(str); 303 304 return 0; 305 } 306 307 psS32 testStrAppend03(void) 308 { 309 // diag("testStrAppend03"); 310 311 char *str =psStringCopy(STR_0); 312 313 // test null-op 314 psStringAppend(&str, "%s", ""); 315 is_str(str, STR_0, "Failed test point"); 316 psFree(str); 317 318 return 0; 319 } 320 321 322 psS32 testStrPrepend00(void) 323 { 324 // diag("testStrPrepend00"); 325 326 char *str=NULL; 327 int result = 0; 328 329 str = psStringCopy("79323846"); 330 331 psStringPrepend(&str, "%s%d","3.14159", 2653589 ); 332 333 // Test point: Verify string append 334 result = strcmp(str, "3.14159265358979323846"); 335 ok ( result == 0, "Failed test point\n"); 336 337 psFree(str); 338 339 return 0; 340 } 341 342 343 psS32 testStrPrepend01(void) 344 { 345 // diag("testStrPrepend01"); 346 347 ssize_t sz; 348 char *str=NULL; 349 350 // test nonsensical invocations ... 351 sz = psStringPrepend(NULL, NULL); 352 ok ( sz == 0, "Failed test point\n"); 353 354 sz = psStringPrepend(&str, NULL); 355 ok ( sz == 0, "Failed test point\n"); 356 357 return 0; 358 } 359 360 psS32 testStrPrepend02(void) 361 { 362 // diag("testStrPrepend02"); 363 364 char *str=NULL; 365 int result; 366 367 // test string creation 368 psStringPrepend(&str, "%s", "fubar"); 369 result = strcmp(str, "fubar"); 370 ok ( result == 0, "Failed test point\n"); 371 372 psFree(str); 373 374 return 0; 375 } 376 377 psS32 testStrPrepend03(void) 378 { 379 // diag("testStrPrepend03"); 380 381 char *str=NULL; 382 int result; 383 384 str = psStringCopy(STR_0); 385 386 // test null-op 387 psStringPrepend(&str, "%s", ""); 388 result = strcmp(str, STR_0); 389 ok ( result == 0, "test point str=[%s]\n", str); 390 391 psFree(str); 392 393 return 0; 394 } 395 396 397 psS32 testStrSplit00(void) 398 { 399 // diag("testStrSplit00"); 400 401 psList *strList = NULL; 402 char str[35]; 403 char split[5]; 404 strncpy(str, "This is, a, test case, to check.", 35); 405 strncpy(split, ",", 2); 406 psString psStr; 407 psString psSplit; 408 psStr = psStringCopy(str); 409 psSplit = psStringCopy(split); 410 411 //Return NULL for NULL inputs 412 strList = psStringSplit(NULL, NULL, true); 413 ok (!strList, "psStringSplit" ); 414 psFree(strList); 415 416 strList = NULL; 417 //Return empty list for NULL string input 418 strList = psStringSplit(NULL, split, true); 419 ok ( !psListLength(strList), "psListLength()" ); 420 psFree(strList); 421 422 strList = NULL; 423 //Return NULL for NULL splitter input 424 strList = psStringSplit(str, NULL, true); 425 ok ( !strList, "psStringSplit" ); 426 psFree(strList); 427 428 strList = NULL; 429 //Return a psList* of psStrings 430 strList = psStringSplit(str, split, true); 431 ok (strList->n == 4, 432 "psStringSplit to return the correct number of strings.\n"); 433 434 ok ( !strncmp((psString)(strList->head->data), "This is", 10), 435 "psStringSplit to return expected strings."); 436 437 ok ( !strncmp((psString)(strList->head->next->data), " a", 10), 438 "psStringSplit to return expected strings."); 439 440 ok ( !strncmp((psString)(strList->head->next->next->data), " test case",10), 441 "psStringSplit to return expected strings."); 442 443 ok ( !strncmp((psString)(strList->head->next->next->next->data), " to check.", 10), 444 "psStringSplit failed to return expected strings."); 445 446 psFree(strList); 447 //Return correct psList when using (psString, char*) 448 strList = psStringSplit(psStr, split, true); 449 ok (strList->n == 4, 450 "psStringSplit to return the correct number of strings.\n"); 451 452 ok ( !strncmp((psString)(strList->head->data), "This is", 10), 453 "psStringSplit to return expected strings."); 454 455 ok ( !strncmp((psString)(strList->head->next->data), " a", 10), 456 "psStringSplit failed to return expected strings."); 457 458 ok ( !strncmp((psString)(strList->head->next->next->data), " test case",10), 459 "psStringSplit failed to return expected strings."); 460 461 ok ( !strncmp((psString)(strList->head->next->next->next->data), " to check.", 10), 462 "psStringSplit to return expected strings."); 463 464 psFree(strList); 465 //Return correct psList when using (char*, psString) 466 strList = psStringSplit(str, psSplit, true); 467 ok (strList->n == 4, 468 "psStringSplit to return the correct number of strings.\n"); 469 470 ok ( !strncmp((psString)(strList->head->data), "This is", 10), 471 "psStringSplit to return expected strings."); 472 473 ok ( !strncmp((psString)(strList->head->next->data), " a", 10), 474 "psStringSplit to return expected strings."); 475 476 ok ( !strncmp((psString)(strList->head->next->next->data), " test case",10), 477 "psStringSplit to return expected strings."); 478 479 ok ( !strncmp((psString)(strList->head->next->next->next->data), " to check.", 10), 480 "psStringSplit to return expected strings."); 481 482 psFree(strList); 483 //Return correct psList when using (psString, psString) 484 strList = psStringSplit(psStr, psSplit, true); 485 ok (strList->n == 4, 486 "psStringSplit to return the correct number of strings.\n"); 487 488 ok ( !strncmp((psString)(strList->head->data), "This is", 10), 489 "psStringSplit to return expected strings."); 490 491 ok ( !strncmp((psString)(strList->head->next->data), " a", 10), 492 "psStringSplit to return expected strings."); 493 494 ok ( !strncmp((psString)(strList->head->next->next->data), " test case",10), 495 "psStringSplit to return expected strings."); 496 497 ok ( !strncmp((psString)(strList->head->next->next->next->data), " to check.", 10), 498 "psStringSplit to return expected strings."); 499 500 psFree(strList); 501 //Return correct psList output for string of zero length case 502 strncpy(str, "This is,, a,, test case,, to check.", 35); 503 strList = psStringSplit(str, split, false); 504 ok (strList->n == 4, 505 "psStringSplit to return the correct number of strings.\n"); 506 507 ok ( !strncmp((psString)(strList->head->data), "This is", 10), 508 "psStringSplit to return expected strings."); 509 510 ok ( !strncmp((psString)(strList->head->next->data), " a", 10), 511 "psStringSplit to return expected strings."); 512 513 ok ( !strncmp((psString)(strList->head->next->next->data), " test case",10), 514 "psStringSplit to return expected strings."); 515 516 ok ( !strncmp((psString)(strList->head->next->next->next->data), " to check.", 10), 517 "psStringSplit to return expected strings."); 518 519 psFree(strList); 520 psFree(psStr); 521 psFree(psSplit); 522 return 0; 523 } 524 525 psS32 testNULLStrings(void) 526 { 527 // diag("test""s"); 528 529 psString nullTest = NULL; 530 psString output = NULL; 531 ssize_t outSize = 0; 532 char** nullDest = NULL; 533 char** test = NULL; 534 //psStringCopy should return NULL for NULL input string 535 // psLogMsg(__func__,PS_LOG_INFO,"Following should generate error message"); 536 output = psStringCopy(nullTest); 537 ok (output == NULL, 538 "psStringCopy to return NULL for NULL input string.\n"); 539 540 //psStringNCopy should return NULL for NULL input string 541 output = psStringNCopy(nullTest, 100); 542 ok (output == NULL, 543 "psStringNCopy to return NULL for NULL input string.\n"); 544 545 //psStringAppend should return 0 for NULL input destination 546 outSize = psStringAppend(nullDest, "%s", ""); 547 ok (outSize == 0, 548 "psStringAppend to return 0 for NULL input destination.\n"); 549 550 //psStringAppend should return 0 for NULL input format 551 outSize = psStringAppend(test, nullTest); 552 ok (outSize == 0, 553 "psStringAppend to return 0 for NULL input format.\n"); 554 555 //psStringPrepend should return 0 for NULL input destination 556 outSize = psStringPrepend(nullDest, " "); 557 ok (outSize == 0, 558 "psStringPrepend to return 0 for NULL input destination.\n"); 559 560 //psStringPrepend should return 0 for NULL input format 561 outSize = psStringPrepend(test, nullTest); 562 ok (outSize == 0, 563 "psStringPrepend to return 0 for NULL input format.\n"); 564 565 //psStringSplit should return empty list for NULL input string 566 psList *nullList = NULL; 567 nullList = psStringSplit(nullTest, ",", true); 568 ok ( !psListLength(nullList), 569 "psStringSplit to return NULL for NULL input string.\n"); 570 psFree(nullList); 571 572 nullList = NULL; 573 //psStringSplit should return NULL for NULL input splitter 574 nullList = psStringSplit("Hello World", nullTest, true); 575 ok ( !nullList, 576 "psStringSplit to return NULL for NULL input splitter.\n"); 577 psFree(nullList); 578 579 return 0; 580 } 581 582 psS32 testStrCheck(void) 583 { 584 // diag("testStrCheck"); 585 586 psString str = NULL; 587 str = psStringAlloc(10); 588 strcpy(str, "Hello"); 589 ok (psMemCheckString(str), "psString allocated!\n"); 590 591 ok (psMemCheckType(PS_DATA_STRING, str), "psString allocated!\n"); 592 psFree(str); 593 594 char charStr[10]; 595 ok (!psMemCheckType(PS_DATA_STRING, charStr), 596 "Input string is a psDataType"); 597 598 return 0; 599 } 465 // HERE -
trunk/psLib/test/sys/tap_psStringSubstitute.c
r10446 r12781 11 11 int main (void) 12 12 { 13 psLogSetFormat("HLNM"); 14 psLogSetLevel(PS_LOG_INFO); 13 15 plan_tests(16); 14 16 15 diag("psStringSubstitute() tests");16 17 17 18 // Return input for NULL key 18 19 { 20 psMemId id = psMemGetId(); 19 21 psString input = psStringCopy(ORIGINAL); 20 22 psStringSubstitute(&input, ",", NULL); 21 23 ok(input && strcmp(input, ORIGINAL) == 0, "output = %s", input); 22 24 psFree(input); 23 // ok(psMemCheckLeaks(0, NULL, stdout, false) == 0, "Memory Leaks"); 24 mem(); 25 ok(!psMemCheckLeaks(id, NULL, NULL, false), "no memory leaks"); 25 26 } 27 26 28 27 29 // Return input for empty key 28 30 { 31 psMemId id = psMemGetId(); 29 32 psString input = psStringCopy(ORIGINAL); 30 33 psStringSubstitute(&input, "XXX", ""); 31 34 ok(input && strcmp(input, ORIGINAL) == 0, "output = %s", input); 32 35 psFree(input); 33 // ok(psMemCheckLeaks(0, NULL, stdout, false) == 0, "Memory Leaks"); 34 mem(); 36 ok(!psMemCheckLeaks(id, NULL, NULL, false), "no memory leaks"); 35 37 } 38 36 39 37 40 // Return corrected version for NULL replace 38 41 { 42 psMemId id = psMemGetId(); 39 43 psString input = psStringCopy(ORIGINAL); 40 44 psStringSubstitute(&input, NULL, ","); 41 45 ok(input && strcmp(input, CORRECTED) == 0, "output = %s", input); 42 46 psFree(input); 43 mem();47 ok(!psMemCheckLeaks(id, NULL, NULL, false), "no memory leaks"); 44 48 } 49 45 50 46 51 // Return corrected version for empty replace 47 52 { 53 psMemId id = psMemGetId(); 48 54 psString input = psStringCopy(ORIGINAL); 49 55 psStringSubstitute(&input, "", ","); 50 56 ok(input && strcmp(input, CORRECTED) == 0, "output = %s", input); 51 57 psFree(input); 52 mem();58 ok(!psMemCheckLeaks(id, NULL, NULL, false), "no memory leaks"); 53 59 } 60 54 61 55 62 // Return NULL for NULL input 56 63 { 64 psMemId id = psMemGetId(); 57 65 int status = psStringSubstitute(NULL, "XXX", ","); 58 66 ok(status == 0, "status = %d", status); 59 mem();67 ok(!psMemCheckLeaks(id, NULL, NULL, false), "no memory leaks"); 60 68 } 69 61 70 62 71 // Return emptry string for empty input 63 72 { 73 psMemId id = psMemGetId(); 64 74 psString input = psStringCopy(""); 65 75 psStringSubstitute(&input, "XXX", ","); 66 76 ok(input && strcmp(input, "") == 0, "output = %s", input); 67 77 psFree(input); 68 mem();78 ok(!psMemCheckLeaks(id, NULL, NULL, false), "no memory leaks"); 69 79 } 80 70 81 71 82 // Change commas to bangs 72 83 { 84 psMemId id = psMemGetId(); 73 85 psString input = psStringCopy(ORIGINAL); 74 86 psStringSubstitute(&input, "!", ","); 75 87 ok(input && strcmp(input, "This is! a! test case! to check.") == 0, "output = %s", input); 76 88 psFree(input); 77 mem();89 ok(!psMemCheckLeaks(id, NULL, NULL, false), "no memory leaks"); 78 90 } 91 79 92 80 93 // Long replacement text --- should allocate new space 81 94 { 95 psMemId id = psMemGetId(); 82 96 psString input = psStringCopy(ORIGINAL); 83 97 psStringSubstitute(&input, "; This string is too long to fit in input(35 chars)", "."); … … 86 100 "output = %s", input); 87 101 psFree(input); 88 mem();102 ok(!psMemCheckLeaks(id, NULL, NULL, false), "no memory leaks"); 89 103 } 90 91 92 return exit_status();93 104 } -
trunk/psLib/test/sys/tap_psTrace.c
r12513 r12781 8 8 #include <fcntl.h> 9 9 #include <unistd.h> 10 11 10 #include "pslib.h" 12 11 #include "tap.h" … … 14 13 15 14 16 static psS32 testTrace00(void);17 static psS32 testTrace01(void);18 static psS32 testTrace02(void);19 static psS32 testTrace03(void);20 static psS32 testTrace04(void);21 static psS32 testTrace05(void);22 static psS32 testTrace05a(void);23 static psS32 testTrace06(void);24 static psS32 testTrace08(void);25 26 27 15 psS32 main( psS32 argc, char* argv[] ) 28 16 { 29 plan_tests(45); 30 31 testTrace00(); 32 testTrace01(); 33 testTrace02(); 34 testTrace03(); 35 testTrace04(); 36 testTrace05(); 37 testTrace05a(); 38 testTrace06(); 39 testTrace08(); 40 } 41 42 43 static psS32 testTrace00(void) 44 { 45 // diag("testTrace00"); 46 47 psS32 i; 48 psS32 lev = 0; 49 50 // psTraceSetDestination(stderr); 51 (void)psTraceSetDestination(2); 52 53 for (i=0;i<10;i++) { 54 (void)psTraceSetLevel(".", i); 55 lev = psTraceGetLevel("."); 56 ok(lev == i, "trace level was %d, actual was %d\n", i, lev); 57 } 58 59 (void)psTraceSetLevel(".", 3); 60 61 for (i=5;i<10;i++) { 62 (void)psTraceSetLevel(".NODE00", i); 63 lev = psTraceGetLevel(".NODE00"); 64 ok (lev == i,"(.NODE00) expected trace level was %d, actual was %d\n", 65 i, lev); 66 67 lev = psTraceGetLevel("."); 68 ok (lev == 3, 69 "expected trace level was %d, actual was %d\n", i, 3); 70 } 71 72 73 (void)psTraceSetLevel(".NODE00.NODE01", 4); 74 for (i=0;i<10;i++) { 75 (void)psTraceSetLevel(".NODE00.NODE01", i); 76 lev = psTraceGetLevel(".NODE00.NODE01"); 77 ok (lev == i, 78 "(.NODE00.NODE01) expected trace level was %d, actual was %d\n", 79 i, lev); 80 } 81 82 return 0; 83 } 84 85 86 static psS32 testTrace01(void) 87 { 88 // diag("testTrace01"); 89 90 // psTraceSetDestination(stderr); 91 (void)psTraceSetDestination(2); 92 (void)psTraceSetLevel(".A.B.C.D.E", 5); 93 94 psTrace(".A.C.D.C",1,"You should not see this.\n"); 95 psTrace(".A.B.C.D.E",2,"You should see this.\n"); 96 psTrace(".A.B.C.D.E.F",3,"You should see this too.\n"); 97 98 psTracePrintLevels(); 99 100 return 0; 101 } 102 103 static psS32 testTrace02(void) 104 { 105 // diag("testTrace02"); 106 107 psTraceReset(); 108 // psTraceSetDestination(stderr); 109 (void)psTraceSetDestination(2); 110 (void)psTraceSetLevel(".A.B", 2); 111 (void)psTraceSetLevel(".A.B.C.D.E", 5); 112 psTracePrintLevels(); 113 (void)psTraceSetLevel(".A.B", 10); 114 psTracePrintLevels(); 115 116 ok (10 == psTraceGetLevel(".A.B.C"), 117 ".A.B.C did not dynamically inherit a trace level (%d)\n", 118 psTraceGetLevel(".A.B.C")); 119 120 ok (10 == psTraceGetLevel(".A.B.C.D"), 121 ".A.B.C.D did not dynamically inherit a trace level (%d)\n", 122 psTraceGetLevel(".A.B.C.D")); 123 124 ok (5 == psTraceGetLevel(".A.B.C.D.E"), 125 ".A.B.C.D.E did dynamically inherit a trace level (%d)\n", 126 psTraceGetLevel(".A.B.C.D.E")); 127 128 return 0; 129 } 130 131 static psS32 testTrace03(void) 132 { 133 // diag("testTrace03"); 134 135 psS32 i = 0; 136 psS32 lev = 0; 137 138 // psTraceSetDestination(stderr); 139 (void)psTraceSetDestination(2); 140 141 for (i=0;i<10;i++) { 142 (void)psTraceSetLevel(".", i); 143 psTraceReset(); 144 145 lev = psTraceGetLevel("."); 146 ok (lev == PS_UNKNOWN_TRACE_LEVEL, 147 "expected trace level was %d, actual was %d\n", 148 PS_UNKNOWN_TRACE_LEVEL, lev); 149 } 150 151 (void)psTraceSetLevel(".", 5); 152 (void)psTraceSetLevel(".a", 4); 153 (void)psTraceSetLevel(".a.b", 3); 154 (void)psTraceSetLevel(".a.b.c", 2); 155 ok (!((5 != psTraceGetLevel(".")) || 156 (4 != psTraceGetLevel(".a")) || 157 (3 != psTraceGetLevel(".a.b")) || 158 (2 != psTraceGetLevel(".a.b.c"))), 159 "trace successFlag = false;levels were not settable?\n"); 160 161 psTraceReset(); 162 ok (!((PS_UNKNOWN_TRACE_LEVEL != psTraceGetLevel(".")) || 163 (PS_UNKNOWN_TRACE_LEVEL != psTraceGetLevel(".a")) || 164 (PS_UNKNOWN_TRACE_LEVEL != psTraceGetLevel(".a.b")) || 165 (PS_UNKNOWN_TRACE_LEVEL != psTraceGetLevel(".a.b.c"))), 166 "trace levels were not reset properly\n"); 167 168 return 0; 169 } 170 171 172 static psS32 testTrace04(void) 173 { 174 // diag("testTrace04"); 175 176 int FD; 177 psS32 nb = 0; 178 FD = creat("tst_psTrace02_OUT", 0666); 179 // printf("\nFD = %d\n", FD); 180 // fp = fopen("tst_psTrace02_OUT", "w"); 181 for (nb = 0 ; nb<4;nb++) { 182 if (nb == 0) 183 // psTraceSetDestination(stdout); 184 (void)psTraceSetDestination(1); 185 if (nb == 1) 186 // psTraceSetDestination(stderr); 187 (void)psTraceSetDestination(2); 188 if (nb == 2) 189 (void)psTraceSetDestination(0); //NULL 190 if (nb == 3) 191 (void)psTraceSetDestination(FD); 192 193 (void)psTraceSetLevel(".", 4); 194 psTrace(".", 5, "(0) This message should not be displayed (%x)\n", 195 0xbeefface); 196 (void)psTraceSetLevel(".", 7); 197 psTrace(".", 5, "(0) This message should be displayed (%x)\n", 198 0xbeefface); 199 17 psLogSetFormat("HLNM"); 18 psLogSetLevel(PS_LOG_INFO); 19 plan_tests(54); 20 21 // testTrace00() 22 { 23 psMemId id = psMemGetId(); 24 psS32 lev = 0; 25 (void)psTraceSetDestination(2); 26 for (int i=0;i<10;i++) { 27 (void)psTraceSetLevel(".", i); 28 lev = psTraceGetLevel("."); 29 ok(lev == i, "trace level was %d, actual was %d", i, lev); 30 } 31 32 (void)psTraceSetLevel(".", 3); 33 for (int i=5;i<10;i++) { 34 (void)psTraceSetLevel(".NODE00", i); 35 lev = psTraceGetLevel(".NODE00"); 36 ok (lev == i,"(.NODE00) expected trace level was %d, actual was %d", 37 i, lev); 38 39 lev = psTraceGetLevel("."); 40 ok (lev == 3, 41 "expected trace level was %d, actual was %d", i, 3); 42 } 43 44 (void)psTraceSetLevel(".NODE00.NODE01", 4); 45 for (int i=0;i<10;i++) { 46 (void)psTraceSetLevel(".NODE00.NODE01", i); 47 lev = psTraceGetLevel(".NODE00.NODE01"); 48 ok (lev == i, 49 "(.NODE00.NODE01) expected trace level was %d, actual was %d", 50 i, lev); 51 } 52 53 ok(!psMemCheckLeaks(id, NULL, NULL, false), "no memory leaks"); 54 } 55 56 57 // testTrace01() 58 { 59 psMemId id = psMemGetId(); 60 (void)psTraceSetDestination(2); 61 (void)psTraceSetLevel(".A.B.C.D.E", 5); 62 psTrace(".A.C.D.C",1,"You should not see this"); 63 psTrace(".A.B.C.D.E",2,"You should see this"); 64 psTrace(".A.B.C.D.E.F",3,"You should see this too"); 65 psTracePrintLevels(); 66 ok(!psMemCheckLeaks(id, NULL, NULL, false), "no memory leaks"); 67 } 68 69 70 // testTrace02() 71 { 72 psMemId id = psMemGetId(); 73 psTraceReset(); 74 (void)psTraceSetDestination(2); 75 (void)psTraceSetLevel(".A.B", 2); 76 (void)psTraceSetLevel(".A.B.C.D.E", 5); 77 psTracePrintLevels(); 78 (void)psTraceSetLevel(".A.B", 10); 79 psTracePrintLevels(); 80 81 ok (10 == psTraceGetLevel(".A.B.C"), 82 ".A.B.C did not dynamically inherit a trace level (%d)", 83 psTraceGetLevel(".A.B.C")); 84 85 ok (10 == psTraceGetLevel(".A.B.C.D"), 86 ".A.B.C.D did not dynamically inherit a trace level (%d)", 87 psTraceGetLevel(".A.B.C.D")); 88 89 ok (5 == psTraceGetLevel(".A.B.C.D.E"), 90 ".A.B.C.D.E did dynamically inherit a trace level (%d)", 91 psTraceGetLevel(".A.B.C.D.E")); 92 ok(!psMemCheckLeaks(id, NULL, NULL, false), "no memory leaks"); 93 } 94 95 96 // testTrace03() 97 { 98 psMemId id = psMemGetId(); 99 (void)psTraceSetDestination(2); 100 101 for (int i=0;i<10;i++) { 102 (void)psTraceSetLevel(".", i); 103 psTraceReset(); 104 int lev = psTraceGetLevel("."); 105 ok (lev == PS_UNKNOWN_TRACE_LEVEL, 106 "expected trace level was %d, actual was %d", 107 PS_UNKNOWN_TRACE_LEVEL, lev); 108 } 109 110 (void)psTraceSetLevel(".", 5); 200 111 (void)psTraceSetLevel(".a", 4); 201 psTrace(".a", 5, "(1) This message should not be displayed (%x)\n", 202 0xbeefface); 203 (void)psTraceSetLevel(".a", 7); 204 psTrace(".a", 5, "(1) This message should be displayed (%x)\n", 205 0xbeefface); 206 207 208 (void)psTraceSetLevel(".a.b", 4); 209 psTrace(".a.b", 5, "(2) This message should not be displayed (%x)\n", 210 0xbeefface); 211 (void)psTraceSetLevel(".a.b", 7); 212 psTrace(".a.b", 5, "(2) This message should be displayed (%x)\n", 213 0xbeefface); 214 (void)psTraceSetLevel(".a.b.c", 12); 215 psTrace(".a.b.c", 11, "(3) This message should be displayed (%x)\n", 216 0xbeefface); 217 218 } 219 220 close(FD); 221 222 return(0); 223 } 224 225 static psS32 testTrace05(void) 226 { 227 // psTraceSetDestination(stderr); 228 (void)psTraceSetDestination(2); 229 230 (void)psTraceSetLevel(".", 9); 231 232 (void)psTraceSetLevel(".a", 8); 233 (void)psTraceSetLevel(".b", 7); 234 (void)psTraceSetLevel(".c", 5); 235 236 (void)psTraceSetLevel(".a.a", 4); 237 (void)psTraceSetLevel(".a.b", 3); 238 239 (void)psTraceSetLevel(".b.a", 2); 240 (void)psTraceSetLevel(".b.b", 1); 241 242 (void)psTraceSetLevel(".c.a", 0); 243 (void)psTraceSetLevel(".c.b", 3); 244 (void)psTraceSetLevel(".c.c", 5); 245 246 psTracePrintLevels(); 247 248 return 0; 249 250 } 251 252 static psS32 testTrace05a(void) 253 { 254 (void)psTraceSetLevel(".", 9); 255 256 (void)psTraceSetLevel("a", 8); 257 (void)psTraceSetLevel("b", 7); 258 (void)psTraceSetLevel("c", 5); 259 260 (void)psTraceSetLevel("a.a", 4); 261 (void)psTraceSetLevel("a.b", 3); 262 263 (void)psTraceSetLevel("b.a", 2); 264 (void)psTraceSetLevel("b.b", 1); 265 266 (void)psTraceSetLevel("c.a", 0); 267 (void)psTraceSetLevel("c.b", 3); 268 (void)psTraceSetLevel("c.c", 5); 269 270 psTracePrintLevels(); 271 272 return 0; 273 274 } 275 276 static psS32 testTrace06(void) 277 { 278 // psTraceSetDestination(stderr); 279 (void)psTraceSetDestination(2); 280 281 (void)psTraceSetLevel(".", 9); 282 283 (void)psTraceSetLevel(".a", 8); 284 (void)psTraceSetLevel(".b", 7); 285 (void)psTraceSetLevel(".c", 5); 286 287 (void)psTraceSetLevel(".a.a", 4); 288 (void)psTraceSetLevel(".a.b", 3); 289 290 (void)psTraceSetLevel(".b.a", 2); 291 (void)psTraceSetLevel(".b.b", 1); 292 293 (void)psTraceSetLevel(".c.a", 0); 294 (void)psTraceSetLevel(".c.b", 3); 295 (void)psTraceSetLevel(".c.c", 5); 296 297 psTraceReset(); 298 299 if ((psTraceGetLevel(".")!=PS_UNKNOWN_TRACE_LEVEL) || 112 (void)psTraceSetLevel(".a.b", 3); 113 (void)psTraceSetLevel(".a.b.c", 2); 114 ok (!((5 != psTraceGetLevel(".")) || 115 (4 != psTraceGetLevel(".a")) || 116 (3 != psTraceGetLevel(".a.b")) || 117 (2 != psTraceGetLevel(".a.b.c"))), 118 "trace successFlag = false;levels were not settable?"); 119 120 psTraceReset(); 121 ok (!((PS_UNKNOWN_TRACE_LEVEL != psTraceGetLevel(".")) || 122 (PS_UNKNOWN_TRACE_LEVEL != psTraceGetLevel(".a")) || 123 (PS_UNKNOWN_TRACE_LEVEL != psTraceGetLevel(".a.b")) || 124 (PS_UNKNOWN_TRACE_LEVEL != psTraceGetLevel(".a.b.c"))), 125 "trace levels were not reset properly"); 126 ok(!psMemCheckLeaks(id, NULL, NULL, false), "no memory leaks"); 127 } 128 129 130 // testTrace04() 131 { 132 psMemId id = psMemGetId(); 133 int FD = creat("tst_psTrace02_OUT", 0666); 134 for (int nb = 0 ; nb<4;nb++) { 135 if (nb == 0) 136 (void)psTraceSetDestination(1); 137 if (nb == 1) 138 (void)psTraceSetDestination(2); 139 if (nb == 2) 140 (void)psTraceSetDestination(0); 141 if (nb == 3) 142 (void)psTraceSetDestination(FD); 143 144 (void)psTraceSetLevel(".", 4); 145 psTrace(".", 5, "(0) This message should not be displayed (%x)", 146 0xbeefface); 147 (void)psTraceSetLevel(".", 7); 148 psTrace(".", 5, "(0) This message should be displayed (%x)", 149 0xbeefface); 150 151 (void)psTraceSetLevel(".a", 4); 152 psTrace(".a", 5, "(1) This message should not be displayed (%x)", 153 0xbeefface); 154 (void)psTraceSetLevel(".a", 7); 155 psTrace(".a", 5, "(1) This message should be displayed (%x)", 156 0xbeefface); 157 158 (void)psTraceSetLevel(".a.b", 4); 159 psTrace(".a.b", 5, "(2) This message should not be displayed (%x)", 160 0xbeefface); 161 (void)psTraceSetLevel(".a.b", 7); 162 psTrace(".a.b", 5, "(2) This message should be displayed (%x)", 163 0xbeefface); 164 (void)psTraceSetLevel(".a.b.c", 12); 165 psTrace(".a.b.c", 11, "(3) This message should be displayed (%x)", 166 0xbeefface); 167 } 168 close(FD); 169 ok(!psMemCheckLeaks(id, NULL, NULL, false), "no memory leaks"); 170 } 171 172 173 // testTrace05() 174 { 175 psMemId id = psMemGetId(); 176 (void)psTraceSetDestination(2); 177 (void)psTraceSetLevel(".", 9); 178 (void)psTraceSetLevel(".a", 8); 179 (void)psTraceSetLevel(".b", 7); 180 (void)psTraceSetLevel(".c", 5); 181 (void)psTraceSetLevel(".a.a", 4); 182 (void)psTraceSetLevel(".a.b", 3); 183 (void)psTraceSetLevel(".b.a", 2); 184 (void)psTraceSetLevel(".b.b", 1); 185 (void)psTraceSetLevel(".c.a", 0); 186 (void)psTraceSetLevel(".c.b", 3); 187 (void)psTraceSetLevel(".c.c", 5); 188 psTracePrintLevels(); 189 ok(!psMemCheckLeaks(id, NULL, NULL, false), "no memory leaks"); 190 } 191 192 193 // testTrace05a() 194 { 195 psMemId id = psMemGetId(); 196 (void)psTraceSetLevel(".", 9); 197 (void)psTraceSetLevel("a", 8); 198 (void)psTraceSetLevel("b", 7); 199 (void)psTraceSetLevel("c", 5); 200 (void)psTraceSetLevel("a.a", 4); 201 (void)psTraceSetLevel("a.b", 3); 202 (void)psTraceSetLevel("b.a", 2); 203 (void)psTraceSetLevel("b.b", 1); 204 (void)psTraceSetLevel("c.a", 0); 205 (void)psTraceSetLevel("c.b", 3); 206 (void)psTraceSetLevel("c.c", 5); 207 psTracePrintLevels(); 208 ok(!psMemCheckLeaks(id, NULL, NULL, false), "no memory leaks"); 209 } 210 211 212 // testTrace06() 213 { 214 psMemId id = psMemGetId(); 215 (void)psTraceSetDestination(2); 216 (void)psTraceSetLevel(".", 9); 217 (void)psTraceSetLevel(".a", 8); 218 (void)psTraceSetLevel(".b", 7); 219 (void)psTraceSetLevel(".c", 5); 220 (void)psTraceSetLevel(".a.a", 4); 221 (void)psTraceSetLevel(".a.b", 3); 222 (void)psTraceSetLevel(".b.a", 2); 223 (void)psTraceSetLevel(".b.b", 1); 224 (void)psTraceSetLevel(".c.a", 0); 225 (void)psTraceSetLevel(".c.b", 3); 226 (void)psTraceSetLevel(".c.c", 5); 227 psTraceReset(); 228 229 if ((psTraceGetLevel(".")!=PS_UNKNOWN_TRACE_LEVEL) || 300 230 (psTraceGetLevel(".a")!=PS_UNKNOWN_TRACE_LEVEL) || 301 231 (psTraceGetLevel(".b")!=PS_UNKNOWN_TRACE_LEVEL) || … … 308 238 (psTraceGetLevel(".c.b")!=PS_UNKNOWN_TRACE_LEVEL) || 309 239 (psTraceGetLevel(".c.c")!=PS_UNKNOWN_TRACE_LEVEL)) { 310 return 1; 311 } 312 313 return 0; 314 } 315 316 // Ensure that the leading dot in the component names are optional. 317 static psS32 testTrace08(void) 318 { 319 psTraceReset(); 320 (void)psTraceSetLevel(".", 9); 321 322 (void)psTraceSetLevel(".a", 8); 323 (void)psTraceSetLevel(".b", 7); 324 (void)psTraceSetLevel(".c", 5); 325 326 (void)psTraceSetLevel(".a.a", 4); 327 (void)psTraceSetLevel(".a.b", 3); 328 329 (void)psTraceSetLevel(".b.a", 2); 330 (void)psTraceSetLevel(".b.b", 1); 331 332 (void)psTraceSetLevel(".c.a", 0); 333 (void)psTraceSetLevel(".c.b", 3); 334 (void)psTraceSetLevel(".c.c", 5); 335 336 psTracePrintLevels(); 337 338 if ((psTraceGetLevel(".")!=9) || 240 return 1; 241 } 242 ok(!psMemCheckLeaks(id, NULL, NULL, false), "no memory leaks"); 243 } 244 245 246 // Ensure that the leading dot in the component names are optional. 247 // testTrace08() 248 { 249 psMemId id = psMemGetId(); 250 psTraceReset(); 251 (void)psTraceSetLevel(".", 9); 252 (void)psTraceSetLevel(".a", 8); 253 (void)psTraceSetLevel(".b", 7); 254 (void)psTraceSetLevel(".c", 5); 255 (void)psTraceSetLevel(".a.a", 4); 256 (void)psTraceSetLevel(".a.b", 3); 257 (void)psTraceSetLevel(".b.a", 2); 258 (void)psTraceSetLevel(".b.b", 1); 259 (void)psTraceSetLevel(".c.a", 0); 260 (void)psTraceSetLevel(".c.b", 3); 261 (void)psTraceSetLevel(".c.c", 5); 262 psTracePrintLevels(); 263 if ((psTraceGetLevel(".")!=9) || 339 264 (psTraceGetLevel("a")!=8) || 340 265 (psTraceGetLevel("b")!=7) || … … 347 272 (psTraceGetLevel("c.b")!=3) || 348 273 (psTraceGetLevel("c.c")!=5)) { 349 printf("psTraceGetLevel(.) is %d\n", psTraceGetLevel(".")); 350 printf("psTraceGetLevel(a) is %d\n", psTraceGetLevel("a")); 351 printf("psTraceGetLevel(b) is %d\n", psTraceGetLevel("b")); 352 printf("psTraceGetLevel(c) is %d\n", psTraceGetLevel("c")); 353 printf("psTraceGetLevel(a.a) is %d\n", psTraceGetLevel("a.a")); 354 printf("psTraceGetLevel(a.b) is %d\n", psTraceGetLevel("a.b")); 355 printf("psTraceGetLevel(b.a) is %d\n", psTraceGetLevel("b.a")); 356 printf("psTraceGetLevel(b.b) is %d\n", psTraceGetLevel("b.b")); 357 printf("psTraceGetLevel(c.a) is %d\n", psTraceGetLevel("c.a")); 358 printf("psTraceGetLevel(c.b) is %d\n", psTraceGetLevel("c.b")); 359 printf("psTraceGetLevel(c.c) is %d\n", psTraceGetLevel("c.c")); 360 361 return 1; 362 } 363 364 return 0; 274 printf("psTraceGetLevel(.) is %d", psTraceGetLevel(".")); 275 printf("psTraceGetLevel(a) is %d", psTraceGetLevel("a")); 276 printf("psTraceGetLevel(b) is %d", psTraceGetLevel("b")); 277 printf("psTraceGetLevel(c) is %d", psTraceGetLevel("c")); 278 printf("psTraceGetLevel(a.a) is %d", psTraceGetLevel("a.a")); 279 printf("psTraceGetLevel(a.b) is %d", psTraceGetLevel("a.b")); 280 printf("psTraceGetLevel(b.a) is %d", psTraceGetLevel("b.a")); 281 printf("psTraceGetLevel(b.b) is %d", psTraceGetLevel("b.b")); 282 printf("psTraceGetLevel(c.a) is %d", psTraceGetLevel("c.a")); 283 printf("psTraceGetLevel(c.b) is %d", psTraceGetLevel("c.b")); 284 printf("psTraceGetLevel(c.c) is %d", psTraceGetLevel("c.c")); 285 return 1; 286 } 287 ok(!psMemCheckLeaks(id, NULL, NULL, false), "no memory leaks"); 288 } 365 289 }
Note:
See TracChangeset
for help on using the changeset viewer.
