Changeset 13123 for trunk/psLib/test/types
- Timestamp:
- May 1, 2007, 6:14:33 PM (19 years ago)
- File:
-
- 1 edited
-
trunk/psLib/test/types/tap_psPixels_all.c (modified) (22 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/test/types/tap_psPixels_all.c
r12781 r13123 23 23 plan_tests(36); 24 24 25 note("Tests for psPixels Functions"); 26 25 //Tests for psPixels Functions 27 26 testPixelsCreate(); 28 27 testPixelsManip(); … … 33 32 void testPixelsCreate(void) 34 33 { 35 note(" >>>Test 1: psPixels Creation Fxns"); 36 34 //Test 1: psPixels Creation Fxns 37 35 //Return allocated psPixels of length 0 with NULL data. 38 36 psPixels* p0 = psPixelsAlloc(0); … … 49 47 //Make sure psMemCheckPixels works correctly - return true 50 48 { 51 ok( psMemCheckPixels(p1),49 ok(psMemCheckPixels(p1), 52 50 "psMemCheckPixels: return true for psPixels input."); 53 51 } … … 55 53 { 56 54 int j = 2; 57 ok( !psMemCheckPixels(&j),55 ok(!psMemCheckPixels(&j), 58 56 "psMemCheckPixels: return false for non-psPixels input."); 59 57 } … … 62 60 psPixels *noPix = psPixelsAlloc(1); 63 61 noPix = psPixelsRealloc(noPix, 0); 64 ok( noPix->n == 0 && noPix->nalloc == 0,62 ok(noPix->n == 0 && noPix->nalloc == 0, 65 63 "psPixelsRealloc: return re-allocated psPixels of 0 length."); 66 64 psFree(noPix); … … 75 73 "Skipping 1 tests because psPixels input is of wrong size! =%ld", p0->n); 76 74 p0 = psPixelsRealloc(p0, 2); 77 ok( p0->n == 2 && fabs(p0->data[0].x - 1.1) < FLT_EPSILON && p0->nalloc == 2,75 ok(p0->n == 2 && fabs(p0->data[0].x - 1.1) < FLT_EPSILON && p0->nalloc == 2, 78 76 "psPixelsRealloc: return properly down-sized psPixels."); 79 77 skip_end(); … … 83 81 psPixels *noPix = NULL; 84 82 noPix = psPixelsCopy(noPix, p0); 85 ok( noPix->n == 2 && fabs(noPix->data[0].x - 1.1) < FLT_EPSILON && noPix->nalloc == 2,83 ok(noPix->n == 2 && fabs(noPix->data[0].x - 1.1) < FLT_EPSILON && noPix->nalloc == 2, 86 84 "psPixelsCopy: return properly copied psPixels."); 87 85 psFree(noPix); … … 91 89 psPixels *noPix = NULL; 92 90 noPix = psPixelsCopy(noPix, NULL); 93 ok( noPix == NULL,91 ok(noPix == NULL, 94 92 "psPixelsCopy: return NULL for NULL psPixels input."); 95 93 } … … 105 103 void testPixelsManip(void) 106 104 { 107 note(" >>>Test 2: psPixels Manipulation Fxns"); 108 105 //psPixels Manipulation Fxns 109 106 //Tests for psPixelsSet 110 107 psPixels *p0 = psPixelsAlloc(1); … … 114 111 //Return false for NULL pixels input 115 112 { 116 ok( !psPixelsSet(NULL, 0, in),113 ok(!psPixelsSet(NULL, 0, in), 117 114 "psPixelsSet: return false for NULL pixels input."); 118 115 } 119 116 //Return true for valid inputs 120 117 { 121 ok( psPixelsSet(p0, 0, in),118 ok(psPixelsSet(p0, 0, in), 122 119 "psPixelsSet: return true for valid inputs."); 123 120 } 124 121 //Return false for position == nalloc 125 122 { 126 ok( !psPixelsSet(p0, 1, in),123 ok(!psPixelsSet(p0, 1, in), 127 124 "psPixelsSet: return false for position == nalloc."); 128 125 } 129 126 //Return false for out-of-range position 130 127 { 131 ok( !psPixelsSet(p0, 2, in),128 ok(!psPixelsSet(p0, 2, in), 132 129 "psPixelsSet: return false for out-of-range position."); 133 130 } 134 131 //Return false for negative out-of-range position 135 132 { 136 ok( !psPixelsSet(p0, -2, in),133 ok(!psPixelsSet(p0, -2, in), 137 134 "psPixelsSet: return false for negative out-of-range position."); 138 135 } 139 136 //Return true for valid negative position 140 137 { 141 ok( psPixelsSet(p0, -1, in),138 ok(psPixelsSet(p0, -1, in), 142 139 "psPixelsSet: return true for valid negative position."); 143 140 } … … 148 145 { 149 146 out = psPixelsGet(NULL, 1); 150 ok( isnan(out.x) && isnan(out.y),147 ok(isnan(out.x) && isnan(out.y), 151 148 "psPixelsGet: return NANs for NULL pixels input."); 152 149 } … … 154 151 { 155 152 out = psPixelsGet(p0, 2); 156 ok( isnan(out.x) && isnan(out.y),153 ok(isnan(out.x) && isnan(out.y), 157 154 "psPixelsGet: return NANs for out-of-range position."); 158 155 } … … 160 157 { 161 158 out = psPixelsGet(p0, -2); 162 ok( isnan(out.x) && isnan(out.y),159 ok(isnan(out.x) && isnan(out.y), 163 160 "psPixelsGet: return NANs for out-of-range negative position."); 164 161 } … … 166 163 { 167 164 out = psPixelsGet(p0, 0); 168 ok( fabs(out.x - 1.1) < FLT_EPSILON && fabs(out.y - 1.2) < FLT_EPSILON,165 ok(fabs(out.x - 1.1) < FLT_EPSILON && fabs(out.y - 1.2) < FLT_EPSILON, 169 166 "psPixelsGet: return correct values for valid inputs."); 170 167 } … … 172 169 { 173 170 out = psPixelsGet(p0, -1); 174 ok( fabs(out.x - 1.1) < FLT_EPSILON && fabs(out.y - 1.2) < FLT_EPSILON,171 ok(fabs(out.x - 1.1) < FLT_EPSILON && fabs(out.y - 1.2) < FLT_EPSILON, 175 172 "psPixelsGet: return correct values for valid negative position."); 176 173 } … … 180 177 { 181 178 FILE *newFD = fopen("psPixels.out", "w+"); 182 ok (p_psPixelsPrint(newFD, p0, "PS-PIXELS"),179 ok(p_psPixelsPrint(newFD, p0, "PS-PIXELS"), 183 180 "p_psPixelsPrint: return true for valid input."); 184 181 fflush(NULL); … … 188 185 { 189 186 FILE *dummy = fopen("psPixels.out", "r"); 190 ok (!p_psPixelsPrint(dummy, p0, "failed test"),187 ok(!p_psPixelsPrint(dummy, p0, "failed test"), 191 188 "p_psPixelsPrint: return false for invalid file input."); 192 189 fclose(dummy); … … 196 193 //Return false for NULL pixels and name inputs 197 194 { 198 ok (!p_psPixelsPrint(stdout, NULL, NULL),195 ok(!p_psPixelsPrint(stdout, NULL, NULL), 199 196 "p_psPixelsPrint: return false for NULL pixels and name inputs."); 200 197 } … … 202 199 psPixels *p1 = psPixelsAlloc(0); 203 200 { 204 ok (p_psPixelsPrint(NULL, p1, "noPix"),201 ok(p_psPixelsPrint(NULL, p1, "noPix"), 205 202 "p_psPixelsPrint: return true for NULL file and empty pixel data inputs."); 206 203 } 207 204 205 206 //---------------------------------------------------------------------- 208 207 //psPixelsToMask Tests 209 208 psImage *outImage = NULL; … … 214 213 region.y1 = 5.0; 215 214 psMaskType maskVal = 1; 216 217 215 //Return NULL for NULL pixels input 218 216 { 217 psMemId id = psMemGetId(); 219 218 outImage = psPixelsToMask(outImage, NULL, region, maskVal); 220 ok ( outImage == NULL, 221 "psPixelsToMask: return NULL for NULL pixels input."); 222 } 219 ok(outImage == NULL, "psPixelsToMask: return NULL for NULL pixels input."); 220 ok(!psMemCheckLeaks(id, NULL, NULL, false), "no memory leaks"); 221 } 222 223 223 224 //Return NULL for empty pixel data 224 225 { 226 psMemId id = psMemGetId(); 225 227 outImage = psPixelsToMask(outImage, p1, region, maskVal); 226 ok ( outImage == NULL, 227 "psPixelsToMask: return NULL for NULL pixels data input."); 228 } 228 ok(outImage == NULL, "psPixelsToMask: return NULL for NULL pixels data input."); 229 ok(!psMemCheckLeaks(id, NULL, NULL, false), "no memory leaks"); 230 } 231 232 229 233 //Return NULL for bad region input - negative value 230 234 { 235 psMemId id = psMemGetId(); 231 236 outImage = psPixelsToMask(outImage, p0, region, maskVal); 232 ok ( outImage == NULL, 233 "psPixelsToMask: return NULL for negative value in region."); 234 } 237 ok(outImage == NULL, "psPixelsToMask: return NULL for negative value in region."); 238 ok(!psMemCheckLeaks(id, NULL, NULL, false), "no memory leaks"); 239 } 240 241 235 242 //Return NULL for bad region input - upper bound less than lower bound 236 243 region.x0 = 3.0; 237 244 region.x1 = 1.0; 238 245 { 246 psMemId id = psMemGetId(); 239 247 outImage = psPixelsToMask(outImage, p0, region, maskVal); 240 ok ( outImage == NULL, 241 "psPixelsToMask: return NULL for bad region input."); 242 } 248 ok(outImage == NULL, "psPixelsToMask: return NULL for bad region input."); 249 ok(!psMemCheckLeaks(id, NULL, NULL, false), "no memory leaks"); 250 } 251 252 253 //Return NULL for un-recyclable image - out->type.dimen != PS_DIMEN_IMAGE 243 254 region.x0 = 1.0; 244 255 region.x1 = 3.0; 245 //Return NULL for un-recyclable image - out->type.dimen != PS_DIMEN_IMAGE246 256 outImage = psImageAlloc(1, 1, PS_TYPE_S32); 247 257 *(psDimen*)&(outImage->type.dimen) = PS_DIMEN_OTHER; 248 258 { 259 psMemId id = psMemGetId(); 249 260 outImage = psPixelsToMask(outImage, p0, region, maskVal); 250 ok ( outImage == NULL, 251 "psPixelsToMask: return NULL for bad image input."); 252 } 261 ok(outImage == NULL, "psPixelsToMask: return NULL for bad image input."); 262 ok(!psMemCheckLeaks(id, NULL, NULL, false), "no memory leaks"); 263 } 264 265 253 266 //Return valid image for valid inputs 267 //XXX: Musr check pixel values 254 268 p0 = psPixelsAdd(p0, 1, 2.1, 2.2); 255 269 p0 = psPixelsAdd(p0, 1, 3.1, 3.2); 256 270 p0 = psPixelsAdd(p0, 1, 1.0, 1.0); 257 271 { 272 psMemId id = psMemGetId(); 258 273 outImage = psPixelsToMask(outImage, p0, region, maskVal); 259 ok ( outImage != NULL, 260 "psPixelsToMask: return valid image for valid input."); 261 } 262 274 ok(outImage != NULL, "psPixelsToMask: return valid image for valid input."); 275 ok(!psMemCheckLeaks(id, NULL, NULL, false), "no memory leaks"); 276 } 277 psFree(outImage); 278 279 280 //---------------------------------------------------------------------- 263 281 //psPixelsFromMask Tests 264 //Return valid psPixels for valid inputs265 psFree(outImage);266 282 outImage = psImageAlloc(31, 99, PS_TYPE_MASK); 267 283 for (int i = 0; i < outImage->numCols; i++) { … … 270 286 } 271 287 } 272 273 { 288 //Return valid psPixels for valid inputs 289 //XXX: We never check output psPixels 290 { 291 psMemId id = psMemGetId(); 274 292 psPixels *outPixels = NULL; 275 293 outPixels = psPixelsFromMask(outPixels, outImage, maskVal); 276 ok ( outPixels != NULL, 277 "psPixelsFromMask: return valid pixels for valid input."); 294 ok(outPixels != NULL, "psPixelsFromMask: return valid pixels for valid input."); 278 295 psFree(outPixels); 279 } 296 ok(!psMemCheckLeaks(id, NULL, NULL, false), "no memory leaks"); 297 } 298 280 299 281 300 // Return NULL for NULL image input 282 301 { 302 psMemId id = psMemGetId(); 283 303 psPixels *outPixels = NULL; 284 304 outPixels = psPixelsFromMask(outPixels, NULL, maskVal); 285 ok ( outPixels == NULL, 286 "psPixelsFromMask: return NULL for NULL image input."); 287 } 305 ok(outPixels == NULL, "psPixelsFromMask: return NULL for NULL image input."); 306 ok(!psMemCheckLeaks(id, NULL, NULL, false), "no memory leaks"); 307 } 308 288 309 289 310 // Return NULL for image with wrong maskType 290 *(psElemType*)&(outImage->type.type) = PS_TYPE_U32; 291 { 311 { 312 *(psElemType*)&(outImage->type.type) = PS_TYPE_U32; 313 psMemId id = psMemGetId(); 292 314 psPixels *outPixels = NULL; 293 315 outPixels = psPixelsFromMask(outPixels, outImage, maskVal); 294 ok ( outPixels == NULL, 295 "psPixelsFromMask: return NULL for image with wrong maskType."); 296 } 297 316 ok(outPixels == NULL, "psPixelsFromMask: return NULL for image with wrong maskType."); 317 ok(!psMemCheckLeaks(id, NULL, NULL, false), "no memory leaks"); 318 *(psElemType*)&(outImage->type.type) = PS_TYPE_U8; 319 } 320 321 322 323 //---------------------------------------------------------------------- 298 324 // psPixelsConcatenate Tests 299 325 // Return NULL for NULL pixels input 300 326 { 327 psMemId id = psMemGetId(); 301 328 psPixels *outPixels = NULL; 302 329 outPixels = psPixelsConcatenate(outPixels, NULL); 303 ok ( outPixels == NULL,304 "psPixelsConcatenate: return NULL for NULL pixels input.");330 ok(outPixels == NULL, "psPixelsConcatenate: return NULL for NULL pixels input."); 331 ok(!psMemCheckLeaks(id, NULL, NULL, false), "no memory leaks"); 305 332 } 306 333 … … 308 335 //Return copy of input pixels for NULL out pixels 309 336 { 337 psMemId id = psMemGetId(); 310 338 psPixels *outPixels = NULL; 311 339 outPixels = psPixelsFromMask(outPixels, outImage, maskVal); 312 340 outPixels = psPixelsConcatenate(outPixels, p0); 313 ok (outPixels->n == 4 && fabs(outPixels->data[0].x - 1.1) < FLT_EPSILON &&341 ok(outPixels->n == 4 && fabs(outPixels->data[0].x - 1.1) < FLT_EPSILON && 314 342 fabs(outPixels->data[0].y - 1.2) < FLT_EPSILON , 315 343 "psPixelsConcatenate: return copy of input pixels for NULL out input."); 316 344 psFree(outPixels); 317 } 318 345 ok(!psMemCheckLeaks(id, NULL, NULL, false), "no memory leaks"); 346 } 347 348 349 //test psPixelsConcatenate() 319 350 //Return properly concatenated psPixels list 320 //Set all the compare cases to cover 'comparePixelCoord' as well. 321 psPixels *outPixels = psPixelsAlloc(5); 322 in.x = 1.0; 323 in.y = 1.0; 324 psPixelsSet(outPixels, 0, in); //1, 1 325 psPixelsSet(outPixels, 1, in); //1, 1 326 in.y = 2.0; 327 psPixelsSet(outPixels, 2, in); //1, 2 328 in.y = 1.0; 329 psPixelsSet(outPixels, 3, in); //1, 1 330 in.x = 2.0; 331 psPixelsSet(outPixels, 4, in); //2, 1 332 333 psPixels *testPixels = psPixelsAlloc(6); 334 in.x = 1.0; 335 in.y = 1.0; 336 psPixelsSet(testPixels, 0, in); //1, 1 337 in.y = 2.0; 338 psPixelsSet(testPixels, 1, in); //1, 2 339 in.y = 1.0; 340 psPixelsSet(testPixels, 2, in); //1, 1 341 in.x = 2.0; 342 psPixelsSet(testPixels, 3, in); //2, 1 343 in.x = 1.0; 344 psPixelsSet(testPixels, 4, in); //1, 1 345 in.x = 5.0; 346 in.y = 3.0; 347 psPixelsSet(testPixels, 5, in); //5, 3 348 //Return properly concatenate pixel list 349 { 351 { 352 psMemId id = psMemGetId(); 353 psPixels *outPixels = psPixelsAlloc(5); 354 in.x = 1.0; 355 in.y = 1.0; 356 psPixelsSet(outPixels, 0, in); //1, 1 357 psPixelsSet(outPixels, 1, in); //1, 1 358 in.y = 2.0; 359 psPixelsSet(outPixels, 2, in); //1, 2 360 in.y = 1.0; 361 psPixelsSet(outPixels, 3, in); //1, 1 362 in.x = 2.0; 363 psPixelsSet(outPixels, 4, in); //2, 1 364 psPixels *testPixels = psPixelsAlloc(6); 365 in.x = 1.0; 366 in.y = 1.0; 367 psPixelsSet(testPixels, 0, in); //1, 1 368 in.y = 2.0; 369 psPixelsSet(testPixels, 1, in); //1, 2 370 in.y = 1.0; 371 psPixelsSet(testPixels, 2, in); //1, 1 372 in.x = 2.0; 373 psPixelsSet(testPixels, 3, in); //2, 1 374 in.x = 1.0; 375 psPixelsSet(testPixels, 4, in); //1, 1 376 in.x = 5.0; 377 in.y = 3.0; 378 psPixelsSet(testPixels, 5, in); //5, 3 350 379 outPixels = psPixelsConcatenate(outPixels, testPixels); 351 ok ( outPixels->n == 6, 352 "psPixelsConcatenate: return properly concatenate pixel list for valid inputs."); 353 } 354 355 356 //Check for Memory leaks 357 { 380 ok(outPixels->n == 6, "psPixelsConcatenate: return properly concatenate pixel list for valid inputs."); 358 381 psFree(testPixels); 359 382 psFree(outPixels); 383 ok(!psMemCheckLeaks(id, NULL, NULL, false), "no memory leaks"); 384 } 385 386 387 //Check for Memory leaks 388 //XXX: Remove this, add memory checks to individual blocks 389 { 360 390 psFree(outImage); 361 391 psFree(p1);
Note:
See TracChangeset
for help on using the changeset viewer.
