Changeset 12781 for trunk/psLib/test/mathtypes
- Timestamp:
- Apr 10, 2007, 11:09:31 AM (19 years ago)
- Location:
- trunk/psLib/test/mathtypes
- Files:
-
- 8 edited
-
tap_psImage.c (modified) (3 diffs)
-
tap_psImageInterpolate.c (modified) (1 diff)
-
tap_psScalar.c (modified) (2 diffs)
-
tap_psVector.c (modified) (29 diffs)
-
tap_psVectorSort_01.c (modified) (4 diffs)
-
tap_psVectorSort_02.c (modified) (4 diffs)
-
tap_psVectorSort_03.c (modified) (2 diffs)
-
tap_psVectorSort_04.c (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/test/mathtypes/tap_psImage.c
r12513 r12781 6 6 * @author Robert DeSonia, MHPCC 7 7 * 8 * @version $Revision: 1. 5$ $Name: not supported by cvs2svn $9 * @date $Date: 2007-0 3-20 03:57:25$8 * @version $Revision: 1.6 $ $Name: not supported by cvs2svn $ 9 * @date $Date: 2007-04-10 21:09:30 $ 10 10 * 11 11 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 16 16 #include <string.h> 17 17 #include <stdlib.h> 18 19 18 #include "pslib.h" 20 19 #include "psType.h" 21 22 20 #include "tap.h" 23 21 #include "pstap.h" 24 22 25 26 //static int Okay = 1;27 //static int setOkay( int okay )28 //{29 // Okay = okay;30 // return okay;31 //}32 23 33 24 #define OK(exp) \ … … 40 31 } 41 32 42 43 44 33 int main(int argc, char* argv[]) 45 34 { 46 plan_tests(383); 47 48 void testImageAlloc(void); 49 testImageAlloc(); 50 51 void testRegion(void); 52 testRegion(); 53 54 void testRegion2(void); 55 testRegion2(); 56 57 void testRegion3(void); 58 testRegion3(); 59 60 void testImageInit(void); 61 testImageInit(); 62 63 void testImageSet(void); 64 testImageSet(); 35 psLogSetFormat("HLNM"); 36 psLogSetLevel(PS_LOG_INFO); 37 plan_tests(402); 38 39 // testImageAlloc() 40 { 41 psMemId id = psMemGetId(); 42 psImage* image = NULL; 43 psU32 sizes = 6; 44 psU32 numCols[] = {0,1,1,100,100,150}; 45 psU32 numRows[] = {0,1,100,1,150,100}; 46 psU32 types = 12; 47 psElemType type[] = { PS_TYPE_S8, PS_TYPE_S16, PS_TYPE_S32, PS_TYPE_S64, 48 PS_TYPE_U8, PS_TYPE_U16, PS_TYPE_U32, PS_TYPE_U64, 49 PS_TYPE_F32, PS_TYPE_F64 }; 50 for (psU32 t=0;t<types;t++) { 51 for (psU32 i=0;i<sizes;i++) { 52 // Following should be an error if numRows[i] == 0 || numCols[i]==0 53 image = psImageAlloc(numCols[i],numRows[i],type[t]); 54 if (image == NULL) { 55 if (numRows[i] == 0 || numCols[i] == 0) { 56 continue; 57 } 58 ok(0, "psImageAlloc returned NULL for type %x, size %dx%d.", 59 type[t], numCols[i], numRows[i]); 60 psFree(image); 61 } 62 63 ok(image->type.dimen==PS_DIMEN_IMAGE && image->type.type==type[t], 64 "psImageAlloc allocated dimen/type (%d/%d), expecting " 65 "PS_IMAGE_DIMEN/%d", image->type.dimen, 66 image->type.type, type[t]); 67 ok(image->numCols == numCols[i] && image->numRows == numRows[i], 68 "psImageAlloc allocated size %dx%d, expecting be %dx%d " 69 "(type = %d)", image->numCols, image->numRows, numCols[i], 70 numRows[i],type[t]); 71 ok(image->col0 == 0 && image->row0 == 0, 72 "psImageAlloc returned row0/col0 of %d/%d. Expected 0/0.", 73 image->row0, image->row0); 74 ok(image->parent == NULL, "psImageAlloc returned NULL parent"); 75 ok(image->children == NULL, 76 "psImageAlloc returned NULL children array"); 77 78 79 if (image->children != NULL) { 80 psFree(image); 81 } 82 83 switch (type[t]) { 84 case PS_TYPE_U16: { 85 psU32 rows = numRows[i]; 86 psU32 cols = numCols[i]; 87 88 for (psS32 r=0;r<rows;r++) { 89 for (psS32 c=0;c<cols;c++) { 90 image->data.U16[r][c] = 2*c+r; 91 } 92 } 93 bool errorFlag = false; 94 for (psS32 r=0;r<rows;r++) { 95 for (psS32 c=0;c<cols;c++) { 96 if (image->data.U16[r][c] != 2*c+r) { 97 errorFlag = true; 98 } 99 } 100 } 101 ok(!errorFlag, "psImageAlloc() set data correctly (U16)"); 102 } 103 break; 104 case PS_TYPE_F32: { 105 psU32 rows = numRows[i]; 106 psU32 cols = numCols[i]; 107 108 for (psS32 r=0;r<rows;r++) { 109 for (psS32 c=0;c<cols;c++) { 110 image->data.F32[r][c] = 2.0f*c+r; 111 } 112 } 113 bool errorFlag = false; 114 for (psS32 r=0;r<rows;r++) { 115 for (psS32 c=0;c<cols;c++) { 116 if (fabsf(image->data.F32[r][c] - (2.0f*c+r)) > FLT_EPSILON) { 117 errorFlag = true; 118 } 119 } 120 } 121 ok(!errorFlag, "psImageAlloc() set data correctly (F32)"); 122 } 123 break; 124 case PS_TYPE_F64: { 125 psU32 rows = numRows[i]; 126 psU32 cols = numCols[i]; 127 128 for (psS32 r=0;r<rows;r++) { 129 for (psS32 c=0;c<cols;c++) { 130 image->data.F64[r][c] = 2.0f*c+r; 131 } 132 } 133 bool errorFlag = false; 134 for (psS32 r=0;r<rows;r++) { 135 for (psS32 c=0;c<cols;c++) { 136 if (fabs(image->data.F64[r][c] - (2.0f*c+r)) > DBL_EPSILON) { 137 errorFlag = true; 138 } 139 } 140 } 141 ok(!errorFlag, "psImageAlloc() set data correctly (F64)"); 142 } 143 break; 144 default: { 145 // ignore type and just use as byte bucket. 146 psU32 rows = numRows[i]; 147 psU32 cols = numCols[i]*PSELEMTYPE_SIZEOF(type[t]); 148 149 for (psS32 r=0;r<rows;r++) { 150 for (psS32 c=0;c<cols;c++) { 151 image->data.U8[r][c] = (uint8_t)(r + c); 152 } 153 } 154 bool errorFlag = false; 155 for (psS32 r=0;r<rows;r++) { 156 for (psS32 c=0;c<cols;c++) { 157 if (image->data.U8[r][c] != (uint8_t)(r + c)) { 158 errorFlag = true; 159 } 160 } 161 } 162 ok(!errorFlag, "psImageAlloc() set data correctly (default)"); 163 } 164 } 165 psFree(image); 166 } 167 } 168 169 // #548: Verify no memory leaks or corruption are detected after a valid psImage structure with multiple 170 // children is freed. 171 image = psImageAlloc(100,100,PS_TYPE_F32); 172 psImageSubset(image,(psRegion) {50,0,70,20}); 173 psImageSubset(image,(psRegion) {70,20,90,40}); 174 psFree(image); 175 ok(!psMemCheckLeaks(id, NULL, NULL, false), "no memory leaks"); 176 } 177 178 179 // testRegion() 180 { 181 psMemId id = psMemGetId(); 182 psRegion region = psRegionSet(1,2,3,4); 183 char *tmpStr = psRegionToString(region); 184 ok(!(region.x0 != 1 || region.x1 != 2 || region.y0 != 3 || region.y1 != 4), 185 "The region attributes are set to (%s)", tmpStr); 186 psFree(tmpStr); 187 region = psRegionFromString("[1:2,3:4]"); 188 tmpStr = psRegionToString(region); 189 ok(!(region.x0 != 0 || region.x1 != 2 || region.y0 != 2 || region.y1 != 4), 190 "The region attributes are set to (%s)", tmpStr); 191 psFree(tmpStr); 192 region = psRegionFromString("[1:2,3:]"); 193 ok(isnan(region.x0), 194 "psRegionFromString returned a NULL pointer given a malformed string."); 195 ok(!psMemCheckLeaks(id, NULL, NULL, false), "no memory leaks"); 196 } 197 198 199 //psRegionForImage 200 { 201 psMemId id = psMemGetId(); 202 psImage *in; 203 psRegion inReg; 204 psRegion out; 205 in = psImageAlloc(1, 1, PS_TYPE_S32); 206 inReg = psRegionSet(1, 2, 1, 2); 207 out = psRegionForImage(in,inReg); 208 psRegion inReg2; 209 psRegion out2; 210 inReg2 = psRegionSet(-1, 0, -2, -1); 211 out2 = psRegionForImage(in, inReg2); 212 213 ok(!( out.x0 != 1 || out.x1 != 1 || out.y0 != 1 || out.y1 != 1 ), 214 "Region For Image returned correct values"); 215 216 ok(!( out2.x0 != 0 || out2.x1 != 1 || out2.y0 != 0 || out2.y1 != 0 ), 217 "Region For Image returned correct values"); 218 psFree(in); 219 ok(!psMemCheckLeaks(id, NULL, NULL, false), "no memory leaks"); 220 } 221 222 223 //psRegionForSquare// 224 { 225 psMemId id = psMemGetId(); 226 float X = 1; 227 float Y = 1; 228 float RAD = 1; 229 psRegion out; 230 out = psRegionForSquare(X, Y, RAD); 231 ok(!(out.x0 != 0 || out.x1 != 3 || out.y0 != 0 || out.y1!= 3), 232 "Region For Square returned correct values"); 233 ok(!psMemCheckLeaks(id, NULL, NULL, false), "no memory leaks"); 234 } 235 236 237 //Initialize an image with a given value.// 238 { 239 psMemId id = psMemGetId(); 240 psImage *in1 = NULL; 241 psImage *in2 = NULL; 242 psImage *in3 = NULL; 243 psImage *in4 = NULL; 244 int nRow = 1; 245 int nCol = 1; 246 in1 = psImageAlloc(nRow, nCol, PS_TYPE_U8); 247 ok(psImageInit(in1, 5 ), 248 "ImageAlloc. U8 Case - 1x1"); 249 nRow = 5; 250 in2 = psImageAlloc(nRow, nCol, PS_TYPE_F32); 251 ok(psImageInit(in2, 3), 252 "ImageAlloc. F32 Case - 5x1"); 253 254 nCol = 5; 255 in3 = psImageAlloc(nRow, nCol, PS_TYPE_F64); 256 ok(psImageInit(in3, 3.14), 257 "ImageAlloc. F64 Case - 5x5"); 258 259 in4 = psImageAlloc(nRow, nCol, PS_TYPE_S32); 260 ok(psImageInit(in4, 3), 261 "ImageAlloc. S32 Case - 5x5"); 262 psFree(in1); 263 psFree(in2); 264 psFree(in3); 265 psFree(in4); 266 ok(!psMemCheckLeaks(id, NULL, NULL, false), "no memory leaks"); 267 } 268 269 270 // testImageSet() 271 { 272 psMemId id = psMemGetId(); 273 psImage *image = NULL; 274 image = psImageAlloc(5, 4, PS_TYPE_S32); 275 276 //Set the position of the subimage relative to the parent. 277 image->col0 = 10; 278 image->row0 = 10; 279 for (int i = 0; i < 4; i++) { 280 for (int j = 0; j < 5; j++) { 281 image->data.S32[i][j] = i+j; 282 } 283 } 284 285 //Attempt to set a position in a NULL psImage* 286 psImage *none = NULL; 287 ok(! psImageSet(none, 1, 1, 1), 288 "psImageSet returned non-null"); 289 290 //Attempt to set a position in a psImage* with negative numCols, numRows 291 none = psImageAlloc(2, 2, PS_TYPE_S32); 292 *(int*)&none->numCols = -1; 293 ok(! psImageSet(none, 1, 1, 1), 294 "psImageSet return false when passed an image with negative numCols"); 295 296 *(int*)&none->numCols = 2; 297 *(int*)&none->numRows = -1; 298 ok(!psImageSet(none, 1, 1, 1), 299 "psImageSet failed to return false when passed an image with negative numRows"); 300 301 //Attempt to set a position in a psImage* with negative col0, row0 302 *(int*)&none->numRows = 2; 303 none->row0 = -1; 304 ok(!psImageSet(none, 1, 1, 1), 305 "psImageSet failed to return false when passed an image with negative col0"); 306 307 none->row0 = 0; 308 none->col0 = -1; 309 ok(!psImageSet(none, 1, 1, 1), 310 "psImageSet failed to return false when passed an image with negative col0"); 311 psFree(none); 312 313 //Try to set a position inside of the subimage. 314 ok(psImageSet(image, 14, 12, 666), 315 "psImageSet failed to return true when passed valid parameters"); 316 317 ok(image->data.S32[2][4] == 666, 318 "psImageSet set the data value. value=%d", image->data.S32[2][4]); 319 320 //Try to set a position inside of the subimage from the tail. 321 ok(psImageSet(image, -1, -1, 666), 322 "psImageSet return true when passed valid parameters"); 323 324 ok(image->data.S32[3][4] == 666, 325 "psImageSet set (from the tail) the data values correctly"); 326 327 //Try to set a position outside of the subimage but inside of the parent image. 328 ok(!psImageSet(image, 0, 0, 666), 329 "psImageSet return false when passed an invalid location"); 330 331 ok(!psImageSet(image, 9, 10, 666), 332 "psImageSet return false when passed an invalid location"); 333 334 //Try to set a position outside of the subimage. 335 ok(!psImageSet(image, 15, 14, 666), 336 "psImageSet return false when passed an invalid location"); 337 338 //Try to set a position outside of the subimage, indexing from the tail. 339 ok(!psImageSet(image, -6, -1, 666), 340 "psImageSet return false when passed an invalid location"); 341 psFree(image); 342 ok(!psMemCheckLeaks(id, NULL, NULL, false), "no memory leaks"); 343 } 344 345 346 // testImageGet() 347 { 348 psMemId id = psMemGetId(); 349 psImage *image = NULL; 350 image = psImageAlloc(5, 3, PS_TYPE_S32); 351 352 //Set the position of the subimage relative to the parent. 353 image->col0 = 10; 354 image->row0 = 10; 355 for (int i = 0; i < 3; i++) { 356 for (int j = 0; j < 5; j++) { 357 image->data.S32[i][j] = i+j; 358 } 359 } 360 361 //Attempt to get a position in a NULL psImage* 362 psImage *none = NULL; 363 ok(isnan( psImageGet(none, 1, 1) ), 364 "psImageGet return false when passed a NULL image"); 365 366 //Attempt to get a position in a psImage* with negative numCols, numRows 367 none = psImageAlloc(2, 2, PS_TYPE_S32); 368 *(int*)&none->numCols = -1; 369 ok(isnan( psImageGet(none, 1, 1) ), 370 "psImageGet return false when passed an image with negative numCols"); 371 372 *(int*)&none->numCols = 2; 373 *(int*)&none->numRows = -1; 374 ok(isnan( psImageGet(none, 1, 1) ), 375 "psImageGet return false when passed an image with negative numRows"); 376 377 //Attempt to get a position in a psImage* with negative col0, row0 378 *(int*)&none->numRows = 2; 379 none->row0 = -1; 380 ok(isnan( psImageGet(none, 1, 1) ), 381 "psImageGet return false when passed an image with negative col0"); 382 383 none->row0 = 0; 384 none->col0 = -1; 385 ok(isnan( psImageGet(none, 1, 1) ), 386 "psImageGet return false when passed an image with negative col0"); 387 388 psFree(none); 389 390 391 //Try to get a position inside of the subimage. 392 ok(psImageGet(image, 14, 12) == 6, 393 "psImageGet return the correct value"); 394 395 //Try to get a position inside of the subimage from the tail. 396 ok(psImageGet(image, -1, -1) == 6, 397 "psImageGet return the correct value"); 398 399 //Try to get a position outside of the subimage but inside of the parent image. 400 ok(isnan( psImageGet(image, 1, 1) ), 401 "psImageGet return NAN when passed an invalid location"); 402 403 ok(isnan( psImageGet(image, 9, 10) ), 404 "psImageGet return NAN when passed an invalid location"); 405 406 //Try to set a position outside of the subimage. 407 ok(isnan( psImageGet(image, 15, 14) ), 408 "psImageGet return NAN when passed an invalid location"); 409 410 //Try to set a position outside of the subimage, indexing from the tail. 411 ok(isnan( psImageGet(image, -6, -1) ), 412 "psImageGet failed to return NAN when passed an invalid location"); 413 psFree(image); 414 ok(!psMemCheckLeaks(id, NULL, NULL, false), "no memory leaks"); 415 ok(!psMemCheckLeaks(id, NULL, NULL, false), "no memory leaks"); 416 } 65 417 } 66 67 68 void testImageAlloc()69 {70 // diag("testImageAlloc");71 72 psImage* image = NULL;73 psU32 sizes = 6;74 psU32 numCols[] = {75 0,1,1,100,100,15076 };77 psU32 numRows[] = {78 0,1,100,1,150,10079 };80 psU32 types = 12;81 psElemType type[] = { PS_TYPE_S8, PS_TYPE_S16, PS_TYPE_S32, PS_TYPE_S64,82 PS_TYPE_U8, PS_TYPE_U16, PS_TYPE_U32, PS_TYPE_U64,83 PS_TYPE_F32, PS_TYPE_F64 };84 85 for (psU32 t=0;t<types;t++) {86 87 for (psU32 i=0;i<sizes;i++) {88 89 // Following should be an error if numRows[i] == 0 || numCols[i]==090 91 image = psImageAlloc(numCols[i],numRows[i],type[t]);92 93 if (image == NULL) {94 if (numRows[i] == 0 || numCols[i] == 0) {95 continue;96 }97 ok(0, "psImageAlloc returned NULL for type %x, size %dx%d.",98 type[t], numCols[i], numRows[i]);99 psFree(image);100 return;101 }102 103 ok (image->type.dimen==PS_DIMEN_IMAGE && image->type.type==type[t],104 "psImageAlloc allocated dimen/type (%d/%d), expecting "105 "PS_IMAGE_DIMEN/%d", image->type.dimen,106 image->type.type, type[t]);107 skip_start (!(image->type.dimen==PS_DIMEN_IMAGE && image->type.type==type[t]),108 4, "psImageAlloc allocated wrong dimen/type");109 110 ok (image->numCols == numCols[i] && image->numRows == numRows[i],111 "psImageAlloc allocated size %dx%d, expecting be %dx%d "112 "(type = %d)", image->numCols, image->numRows, numCols[i],113 numRows[i],type[t]);114 skip_start (!(image->numCols == numCols[i] && image->numRows == numRows[i]),115 3, "psImageAlloc allocated wrong size");116 117 ok (image->col0 == 0 && image->row0 == 0,118 "psImageAlloc returned row0/col0 of %d/%d. Expected 0/0.",119 image->row0, image->row0);120 skip_start (!(image->col0 == 0 && image->row0 == 0),121 2, "psImageAlloc returned wrong row0/col0");122 123 ok (image->parent == NULL, "psImageAlloc returned NULL parent");124 skip_start (image->parent != NULL,125 1, "psImageAlloc returned NULL parent");126 127 ok (image->children == NULL,128 "psImageAlloc returned NULL children array");129 130 skip_end();131 skip_end();132 skip_end();133 skip_end();134 135 if (image->children != NULL) {136 psFree(image);137 return;138 }139 140 switch (type[t]) {141 case PS_TYPE_U16: {142 psU32 rows = numRows[i];143 psU32 cols = numCols[i];144 145 for (psS32 r=0;r<rows;r++) {146 for (psS32 c=0;c<cols;c++) {147 image->data.U16[r][c] = 2*c+r;148 }149 }150 bool errorFlag = false;151 for (psS32 r=0;r<rows;r++) {152 for (psS32 c=0;c<cols;c++) {153 if (image->data.U16[r][c] != 2*c+r) {154 // diag("ERROR: Could not set all pixels in uint16 image at (%d,%d)",c,r);155 errorFlag = true;156 }157 }158 }159 ok(!errorFlag, "psImageAlloc() set data correctly (U16)");160 }161 break;162 case PS_TYPE_F32: {163 psU32 rows = numRows[i];164 psU32 cols = numCols[i];165 166 for (psS32 r=0;r<rows;r++) {167 for (psS32 c=0;c<cols;c++) {168 image->data.F32[r][c] = 2.0f*c+r;169 }170 }171 bool errorFlag = false;172 for (psS32 r=0;r<rows;r++) {173 for (psS32 c=0;c<cols;c++) {174 if (fabsf(image->data.F32[r][c] - (2.0f*c+r)) > FLT_EPSILON) {175 // diag("Could not set all pixels in float image at (%d,%d)",c,r);176 errorFlag = true;177 }178 }179 }180 ok(!errorFlag, "psImageAlloc() set data correctly (F32)");181 }182 break;183 case PS_TYPE_F64: {184 psU32 rows = numRows[i];185 psU32 cols = numCols[i];186 187 for (psS32 r=0;r<rows;r++) {188 for (psS32 c=0;c<cols;c++) {189 image->data.F64[r][c] = 2.0f*c+r;190 }191 }192 bool errorFlag = false;193 for (psS32 r=0;r<rows;r++) {194 for (psS32 c=0;c<cols;c++) {195 if (fabs(image->data.F64[r][c] - (2.0f*c+r)) > DBL_EPSILON) {196 // diag("Set all pixels in double image at (%d,%d)",c,r);197 errorFlag = true;198 }199 }200 }201 ok(!errorFlag, "psImageAlloc() set data correctly (F64)");202 }203 break;204 default: {205 // ignore type and just use as byte bucket.206 psU32 rows = numRows[i];207 psU32 cols = numCols[i]*PSELEMTYPE_SIZEOF(type[t]);208 209 for (psS32 r=0;r<rows;r++) {210 for (psS32 c=0;c<cols;c++) {211 image->data.U8[r][c] = (uint8_t)(r + c);212 }213 }214 bool errorFlag = false;215 for (psS32 r=0;r<rows;r++) {216 for (psS32 c=0;c<cols;c++) {217 if (image->data.U8[r][c] != (uint8_t)(r + c)) {218 // diag("Set all pixels in image (type=%d) at (%d,%d)", type[t],c,r);219 errorFlag = true;220 }221 }222 }223 ok(!errorFlag, "psImageAlloc() set data correctly (default)");224 }225 }226 psFree(image);227 }228 }229 230 // #548: Verify no memory leaks or corruption are detected after a valid psImage structure with multiple231 // children is freed.232 image = psImageAlloc(100,100,PS_TYPE_F32);233 psImageSubset(image,(psRegion) {234 50,0,70,20235 }236 );237 psImageSubset(image,(psRegion) {238 70,20,90,40239 }240 );241 242 psFree(image);243 }244 245 246 247 void testRegion()248 {249 // Testpoint #790250 251 // diag("testRegion");252 253 psRegion region = psRegionSet(1,2,3,4);254 ok (!(region.x0 != 1 || region.x1 != 2 || region.y0 != 3 || region.y1 != 4),255 "The region attributes are set to (%s)", psRegionToString(region));256 257 // Testpoint #791258 259 region = psRegionFromString("[1:2,3:4]");260 ok (!(region.x0 != 0 || region.x1 != 2 || region.y0 != 2 || region.y1 != 4),261 "The region attributes are set to (%s)", psRegionToString(region));262 263 region = psRegionFromString("[1:2,3:]");264 ok (isnan(region.x0),265 "psRegionFromString returned a NULL pointer given a malformed string.");266 }267 268 269 //psRegionForImage//270 void testRegion2()271 {272 // diag("testRegion2");273 274 psImage *in;275 psRegion inReg;276 psRegion out;277 in = psImageAlloc(1, 1, PS_TYPE_S32);278 inReg = psRegionSet(1, 2, 1, 2);279 out = psRegionForImage(in,inReg);280 psRegion inReg2;281 psRegion out2;282 inReg2 = psRegionSet(-1, 0, -2, -1);283 out2 = psRegionForImage(in, inReg2);284 285 ok(!( out.x0 != 1 || out.x1 != 1 || out.y0 != 1 || out.y1 != 1 ),286 "Region For Image returned correct values.\n");287 288 ok(!( out2.x0 != 0 || out2.x1 != 1 || out2.y0 != 0 || out2.y1 != 0 ),289 "Region For Image returned correct values.\n");290 291 psFree(in);292 }293 294 295 //psRegionForSquare//296 void testRegion3()297 {298 // diag("testRegion3");299 300 float X = 1;301 float Y = 1;302 float RAD = 1;303 psRegion out;304 out = psRegionForSquare(X, Y, RAD);305 ok (!(out.x0 != 0 || out.x1 != 3 || out.y0 != 0 || out.y1!= 3),306 "Region For Square returned correct values.\n");307 }308 309 310 //Initialize an image with a given value.//311 void testImageInit()312 {313 // diag("testImageInit");314 315 psImage *in1 = NULL;316 psImage *in2 = NULL;317 psImage *in3 = NULL;318 psImage *in4 = NULL;319 int nRow = 1;320 int nCol = 1;321 in1 = psImageAlloc(nRow, nCol, PS_TYPE_U8);322 ok ( psImageInit(in1, 5 ),323 "ImageAlloc. U8 Case - 1x1\n");324 nRow = 5;325 in2 = psImageAlloc(nRow, nCol, PS_TYPE_F32);326 ok ( psImageInit(in2, 3),327 "ImageAlloc. F32 Case - 5x1\n");328 329 nCol = 5;330 in3 = psImageAlloc(nRow, nCol, PS_TYPE_F64);331 ok ( psImageInit(in3, 3.14),332 "ImageAlloc. F64 Case - 5x5\n");333 334 in4 = psImageAlloc(nRow, nCol, PS_TYPE_S32);335 ok ( psImageInit(in4, 3),336 "ImageAlloc. S32 Case - 5x5\n");337 338 psFree(in1);339 psFree(in2);340 psFree(in3);341 psFree(in4);342 }343 344 345 void testImageSet()346 {347 // diag("testImageSet");348 349 psImage *image = NULL;350 image = psImageAlloc(5, 4, PS_TYPE_S32);351 352 //Set the position of the subimage relative to the parent.353 image->col0 = 10;354 image->row0 = 10;355 for (int i = 0; i < 4; i++) {356 for (int j = 0; j < 5; j++) {357 image->data.S32[i][j] = i+j;358 }359 }360 361 //Attempt to set a position in a NULL psImage*362 psImage *none = NULL;363 ok (! psImageSet(none, 1, 1, 1),364 "psImageSet returned non-null.\n");365 skip_start ( psImageSet(none, 1, 1, 1),366 12, "psImageSet failed");367 368 //Attempt to set a position in a psImage* with negative numCols, numRows369 none = psImageAlloc(2, 2, PS_TYPE_S32);370 *(int*)&none->numCols = -1;371 ok (! psImageSet(none, 1, 1, 1),372 "psImageSet return false when passed an image with negative numCols");373 skip_start ( psImageSet(none, 1, 1, 1),374 11,"psImageSet return true when passed an image with negative numCols");375 376 *(int*)&none->numCols = 2;377 *(int*)&none->numRows = -1;378 ok ( !psImageSet(none, 1, 1, 1),379 "psImageSet failed to return false when passed an image with negative numRows.\n");380 skip_start ( psImageSet(none, 1, 1, 1),381 10,"psImageSet return true when passed an image with negative numRows.");382 383 //Attempt to set a position in a psImage* with negative col0, row0384 *(int*)&none->numRows = 2;385 none->row0 = -1;386 ok ( !psImageSet(none, 1, 1, 1),387 "psImageSet failed to return false when passed an image with negative col0.\n");388 skip_start ( psImageSet(none, 1, 1, 1),389 9,"psImageSet return true when passed an image with negative col0.\n");390 391 none->row0 = 0;392 none->col0 = -1;393 ok ( !psImageSet(none, 1, 1, 1),394 "psImageSet failed to return false when passed an image with negative col0.\n");395 skip_start ( psImageSet(none, 1, 1, 1),396 8,"psImageSet return true when passed an image with negative col0.\n");397 398 psFree(none);399 400 //Try to set a position inside of the subimage.401 ok ( psImageSet(image, 14, 12, 666),402 "psImageSet failed to return true when passed valid parameters.\n");403 skip_start ( !psImageSet(image, 14, 12, 666),404 7,"psImageSet failed to return true when passed valid parameters.\n");405 406 ok (image->data.S32[2][4] == 666,407 "psImageSet set the data value. value=%d\n", image->data.S32[2][4]);408 skip_start (image->data.S32[2][4] != 666,409 6,"psImageSet set the data value. value=%d\n", image->data.S32[2][4]);410 411 //Try to set a position inside of the subimage from the tail.412 ok ( psImageSet(image, -1, -1, 666),413 "psImageSet return true when passed valid parameters.\n");414 skip_start ( !psImageSet(image, -1, -1, 666),415 5,"psImageSet failed to return true when passed valid parameters.\n");416 417 ok (image->data.S32[3][4] == 666,418 "psImageSet set (from the tail) the data values correctly.\n");419 skip_start (image->data.S32[3][4] != 666,420 4,"psImageSet set (from the tail) the data values incorrectly.\n");421 422 423 //Try to set a position outside of the subimage but inside of the parent image.424 ok ( !psImageSet(image, 0, 0, 666),425 "psImageSet return false when passed an invalid location.\n");426 skip_start ( psImageSet(image, 0, 0, 666),427 3,"psImageSet failed to return false when passed an invalid location");428 429 ok ( !psImageSet(image, 9, 10, 666),430 "psImageSet return false when passed an invalid location.\n");431 skip_start ( psImageSet(image, 9, 10, 666),432 2,"psImageSet return false when passed an invalid location.\n");433 434 //Try to set a position outside of the subimage.435 ok ( !psImageSet(image, 15, 14, 666),436 "psImageSet return false when passed an invalid location.\n");437 skip_start ( psImageSet(image, 15, 14, 666),438 1,"psImageSet failed to return false when passed an invalid location");439 440 //Try to set a position outside of the subimage, indexing from the tail.441 ok ( !psImageSet(image, -6, -1, 666),442 "psImageSet return false when passed an invalid location.\n");443 444 skip_end();445 skip_end();446 skip_end();447 skip_end();448 skip_end();449 skip_end();450 skip_end();451 skip_end();452 skip_end();453 skip_end();454 skip_end();455 skip_end();456 457 psFree(image);458 }459 460 461 void testImageGet()462 {463 // diag("testImageGet");464 465 psImage *image = NULL;466 image = psImageAlloc(5, 3, PS_TYPE_S32);467 468 //Set the position of the subimage relative to the parent.469 image->col0 = 10;470 image->row0 = 10;471 for (int i = 0; i < 3; i++) {472 for (int j = 0; j < 5; j++) {473 image->data.S32[i][j] = i+j;474 }475 }476 477 //Attempt to get a position in a NULL psImage*478 psImage *none = NULL;479 ok ( isnan( psImageGet(none, 1, 1) ),480 "psImageGet return false when passed a NULL image.\n");481 skip_start ( !isnan( psImageGet(none, 1, 1) ),482 10,"psImageGet failed to return false when passed a NULL image.\n");483 484 //Attempt to get a position in a psImage* with negative numCols, numRows485 none = psImageAlloc(2, 2, PS_TYPE_S32);486 *(int*)&none->numCols = -1;487 ok ( isnan( psImageGet(none, 1, 1) ),488 "psImageGet return false when passed an image with negative numCols");489 skip_start ( !isnan( psImageGet(none, 1, 1) ),490 9,"psImageGet return true when passed an image with negative numCols");491 492 *(int*)&none->numCols = 2;493 *(int*)&none->numRows = -1;494 ok ( isnan( psImageGet(none, 1, 1) ),495 "psImageGet return false when passed an image with negative numRows");496 skip_start ( !isnan( psImageGet(none, 1, 1) ),497 8,"psImageGet failed to return false when passed an image with negative numRows.\n");498 499 //Attempt to get a position in a psImage* with negative col0, row0500 *(int*)&none->numRows = 2;501 none->row0 = -1;502 ok ( isnan( psImageGet(none, 1, 1) ),503 "psImageGet return false when passed an image with negative col0.\n");504 skip_start ( !isnan( psImageGet(none, 1, 1) ),505 7,"psImageGet return false when passed an image with negative col0.\n");506 507 none->row0 = 0;508 none->col0 = -1;509 ok ( isnan( psImageGet(none, 1, 1) ),510 "psImageGet return false when passed an image with negative col0.\n");511 skip_start ( !isnan( psImageGet(none, 1, 1) ),512 6,"psImageGet failed to return false when passed an image with negative col0.\n");513 514 psFree(none);515 516 517 //Try to get a position inside of the subimage.518 ok ( psImageGet(image, 14, 12) == 6,519 "psImageGet return the correct value.\n");520 skip_start ( psImageGet(image, 14, 12) != 6,521 5,"psImageGet failed to return the correct value.\n");522 523 //Try to get a position inside of the subimage from the tail.524 ok ( psImageGet(image, -1, -1) == 6,525 "psImageGet return the correct value.\n");526 skip_start ( psImageGet(image, -1, -1) == 6,527 4, "psImageGet failed to return the correct value.\n");528 529 //Try to get a position outside of the subimage but inside of the parent image.530 ok ( isnan( psImageGet(image, 1, 1) ),531 "psImageGet return NAN when passed an invalid location.\n");532 skip_start ( !isnan( psImageGet(image, 1, 1) ),533 3, "psImageGet didn't return NAN when passed an invalid location.\n");534 535 ok ( isnan( psImageGet(image, 9, 10) ),536 "psImageGet return NAN when passed an invalid location.\n");537 skip_start ( ! isnan( psImageGet(image, 9, 10) ),538 2,"psImageGet failed to return NAN when passed an invalid location.\n");539 540 //Try to set a position outside of the subimage.541 ok ( isnan( psImageGet(image, 15, 14) ),542 "psImageGet return NAN when passed an invalid location.\n");543 skip_start ( !isnan( psImageGet(image, 15, 14) ),544 1, "psImageGet didn't return NAN when passed an invalid location.\n");545 546 //Try to set a position outside of the subimage, indexing from the tail.547 ok ( isnan( psImageGet(image, -6, -1) ),548 "psImageGet failed to return NAN when passed an invalid location.\n");549 550 skip_end();551 skip_end();552 skip_end();553 skip_end();554 skip_end();555 skip_end();556 skip_end();557 skip_end();558 skip_end();559 skip_end();560 561 562 psFree(image);563 } -
trunk/psLib/test/mathtypes/tap_psImageInterpolate.c
r12741 r12781 8 8 int main (void) 9 9 { 10 p lan_tests(88);11 12 // diag("psImageInterpolate() tests");10 psLogSetFormat("HLNM"); 11 psLogSetLevel(PS_LOG_INFO); 12 plan_tests(47); 13 13 14 14 // very simple tests: no mask, bilinear mode, xramp image only 15 15 { 16 16 psMemId id = psMemGetId(); 17 18 // diag ("interpolate a delta function"); 19 20 // generate simple image (x ramp) 21 psImage *image = psImageAlloc(32, 32, PS_TYPE_F64); 22 ok(image != NULL, "psImage successfully allocated"); 23 skip_start(image == NULL, 5, "Skipping tests because psImageAlloc() failed"); 24 25 psImageInit(image, 0.0); 26 image->data.F64[10][10] = 1; 27 28 // center of pixels is 0.5, 0.5 29 double value; 30 31 psImageInterpolateOptions *interp = psImageInterpolateOptionsAlloc(PS_INTERPOLATE_BILINEAR, 32 image, NULL, NULL, 0, 0.0, 0.0, 33 0, 0, 0.0); 34 ok(interp, "Interpolation options set"); 35 36 ok(psImageInterpolate(&value, NULL, NULL, 10.5, 10.5, interp), "Interpolation"); 37 is_double (value, 1.0, "pixel center value - %f", value); 38 39 // diag ("why do I need to have tolerances of 4epsilon or so??"); 40 41 ok(psImageInterpolate(&value, NULL, NULL, 10.9, 10.5, interp), "Interpolation"); 42 is_double_tol (value, 0.6, 4.0*FLT_EPSILON, "pixel value - %.20f", value); 43 44 ok(psImageInterpolate(&value, NULL, NULL, 10.5, 10.9, interp), "Interpolation"); 45 is_double_tol (value, 0.6, 4.0*FLT_EPSILON, "pixel value - %.20f", value); 46 47 ok(psImageInterpolate(&value, NULL, NULL, 10.1, 10.5, interp), "Interpolation"); 48 is_double_tol (value, 0.6, 4.0*FLT_EPSILON, "pixel value - %.20f", value); 49 50 psFree(interp); 51 52 skip_end(); 53 54 psFree(image); 55 ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks"); 56 } 17 // generate simple image (x ramp) 18 psImage *image = psImageAlloc(32, 32, PS_TYPE_F32); 19 ok(image != NULL, "psImage successfully allocated"); 20 skip_start(image == NULL, 5, "Skipping tests because psImageAlloc() failed"); 21 22 image->data.F32[10][10] = 1; 23 24 // center of pixels is 0.5, 0.5 25 float value; 26 27 value = psImagePixelInterpolate (image, 10.5, 10.5, NULL, 0, 0.0, PS_INTERPOLATE_BILINEAR); 28 is_float (value, 1.0, "pixel center value - %f", value); 29 30 value = psImagePixelInterpolate (image, 10.9, 10.5, NULL, 0, 0.0, PS_INTERPOLATE_BILINEAR); 31 is_float_tol (value, 0.6, 4.0*FLT_EPSILON, "pixel value - %.20f", value); 32 33 value = psImagePixelInterpolate (image, 10.5, 10.9, NULL, 0, 0.0, PS_INTERPOLATE_BILINEAR); 34 is_float_tol (value, 0.6, 4.0*FLT_EPSILON, "pixel value - %.20f", value); 35 36 value = psImagePixelInterpolate (image, 10.1, 10.5, NULL, 0, 0.0, PS_INTERPOLATE_BILINEAR); 37 is_float_tol (value, 0.6, 4.0*FLT_EPSILON, "pixel value - %.20f", value); 38 39 skip_end(); 40 41 psFree(image); 42 ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks"); 43 } 44 57 45 58 46 // very simple tests: no mask, bilinear mode, xramp image only 59 47 { 60 48 psMemId id = psMemGetId(); 61 62 // diag ("interpolate an x-ramp"); 63 64 // generate simple image (x ramp) 65 psImage *image = psImageAlloc(32, 32, PS_TYPE_F64); 66 ok(image != NULL, "psImage successfully allocated"); 67 skip_start(image == NULL, 5, "Skipping tests because psImageAlloc() failed"); 68 69 for (int j = 0; j < image->numRows; j++) { 70 for (int i = 0; i < image->numCols; i++) { 71 image->data.F64[j][i] = i + 0.5; 72 } 73 } 74 75 // center of pixels is 0.5, 0.5 76 double value; 77 78 psImageInterpolateOptions *interp = psImageInterpolateOptionsAlloc(PS_INTERPOLATE_BILINEAR, 79 image, NULL, NULL, 0, 0.0, 0.0, 80 0, 0, 0.0); 81 ok(interp, "Interpolation options set"); 82 83 ok(psImageInterpolate(&value, NULL, NULL, 2.5, 2.5, interp), "Interpolation"); 84 is_double_tol (value, 2.5, 5.0e-8, "pixel center value - %f", value); 85 86 ok(psImageInterpolate(&value, NULL, NULL, 2.2, 2.5, interp), "Interpolation"); 87 is_double_tol (value, 2.2, 5.0e-8, "coord: 2.2, 2.5, value: %f", value); 88 89 ok(psImageInterpolate(&value, NULL, NULL, 2.8, 2.5, interp), "Interpolation"); 90 is_double_tol (value, 2.8, 5.0e-8, "coord: 2.8, value: %f", value); 91 92 ok(psImageInterpolate(&value, NULL, NULL, 2.8, 2.2, interp), "Interpolation"); 93 is_double_tol (value, 2.8, 5.0e-8, "coord: 2.8, value: %f", value); 94 95 ok(psImageInterpolate(&value, NULL, NULL, 2.8, 2.8, interp), "Interpolation"); 96 is_double_tol (value, 2.8, 5.0e-8, "coord: 2.8, value: %f", value); 97 98 ok(psImageInterpolate(&value, NULL, NULL, 0.8, 2.8, interp), "Interpolation"); 99 is_double_tol (value, 0.8, 5.0e-8, "coord: 0.8, value: %f", value); 49 // generate simple image (x ramp) 50 psImage *image = psImageAlloc(32, 32, PS_TYPE_F32); 51 ok(image != NULL, "psImage successfully allocated"); 52 skip_start(image == NULL, 5, "Skipping tests because psImageAlloc() failed"); 53 54 for (int j = 0; j < image->numRows; j++) 55 { 56 for (int i = 0; i < image->numCols; i++) { 57 image->data.F32[j][i] = i + 0.5; 58 } 59 } 60 61 // center of pixels is 0.5, 0.5 62 float value; 63 64 value = psImagePixelInterpolate (image, 2.5, 2.5, NULL, 0, 0.0, PS_INTERPOLATE_BILINEAR); 65 is_float (value, 2.5, "pixel center value - %f", value); 66 67 value = psImagePixelInterpolate (image, 2.2, 2.5, NULL, 0, 0.0, PS_INTERPOLATE_BILINEAR); 68 is_float (value, 2.2, "coord: 2.2, 2.5, value: %f", value); 69 70 value = psImagePixelInterpolate (image, 2.8, 2.5, NULL, 0, 0.0, PS_INTERPOLATE_BILINEAR); 71 is_float (value, 2.8, "coord: 2.8, value: %f", value); 72 73 value = psImagePixelInterpolate (image, 2.8, 2.2, NULL, 0, 0.0, PS_INTERPOLATE_BILINEAR); 74 is_float (value, 2.8, "coord: 2.8, value: %f", value); 75 76 value = psImagePixelInterpolate (image, 2.8, 2.8, NULL, 0, 0.0, PS_INTERPOLATE_BILINEAR); 77 is_float (value, 2.8, "coord: 2.8, value: %f", value); 78 79 value = psImagePixelInterpolate (image, 0.8, 2.8, NULL, 0, 0.0, PS_INTERPOLATE_BILINEAR); 80 is_float (value, 0.8, "coord: 0.8, value: %f", value); 100 81 101 82 // no extrapolation 102 ok(psImageInterpolate(&value, NULL, NULL, 0.3, 2.8, interp), "Interpolation"); 103 is_double (value, 0.0, "coord: 0.3, value: %f", value); 104 105 ok(psImageInterpolate(&value, NULL, NULL, -0.2, 2.8, interp), "Interpolation"); 106 is_double (value, 0.0, "coord: -0.2, value: %f", value); 107 108 psFree(interp); 109 110 skip_end(); 111 112 psFree(image); 113 ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks"); 114 } 83 value = psImagePixelInterpolate (image, 0.3, 2.8, NULL, 0, 0.0, PS_INTERPOLATE_BILINEAR); 84 is_float (value, 0.5, "coord: 0.3, value: %f", value); 85 86 value = psImagePixelInterpolate (image, -0.2, 2.8, NULL, 0, 0.0, PS_INTERPOLATE_BILINEAR); 87 is_float (value, 0.5, "coord: -0.2, value: %f", value); 88 89 skip_end(); 90 91 psFree(image); 92 ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks"); 93 } 94 115 95 116 96 // very simple tests: no mask, bilinear mode, yramp image only 117 97 { 118 98 psMemId id = psMemGetId(); 119 120 // diag ("interpolate a y-ramp: ");121 122 99 // generate simple image (y ramp) 123 psImage *image = psImageAlloc(32, 32, PS_TYPE_F64); 124 ok(image != NULL, "psImage successfully allocated"); 125 skip_start(image == NULL, 5, "Skipping tests because psImageAlloc() failed"); 126 127 for (int j = 0; j < image->numRows; j++) 128 { 129 for (int i = 0; i < image->numCols; i++) { 130 image->data.F64[j][i] = j + 0.5; 131 } 132 } 133 134 // center of pixels is 0.5, 0.5 135 double value; 136 137 psImageInterpolateOptions *interp = psImageInterpolateOptionsAlloc(PS_INTERPOLATE_BILINEAR, 138 image, NULL, NULL, 0, 0.0, 0.0, 139 0, 0, 0.0); 140 ok(interp, "Interpolation options set"); 141 142 ok(psImageInterpolate(&value, NULL, NULL, 2.5, 2.5, interp), "Interpolation"); 143 is_double_tol (value, 2.5, 5.0e-8, "pixel center value - %f", value); 144 145 ok(psImageInterpolate(&value, NULL, NULL, 2.2, 2.2, interp), "Interpolation"); 146 is_double_tol (value, 2.2, 5.0e-8, "coord: 2.2, 2.2, value: %f", value); 147 148 ok(psImageInterpolate(&value, NULL, NULL, 2.5, 2.8, interp), "Interpolation"); 149 is_double_tol (value, 2.8, 5.0e-8, "coord: 2.8, value: %f", value); 150 151 ok(psImageInterpolate(&value, NULL, NULL, 2.2, 2.8, interp), "Interpolation"); 152 is_double_tol (value, 2.8, 5.0e-8, "coord: 2.8, value: %f", value); 153 154 ok(psImageInterpolate(&value, NULL, NULL, 2.8, 2.8, interp), "Interpolation"); 155 is_double_tol (value, 2.8, 5.0e-8, "coord: 2.8, value: %f", value); 156 157 psFree(interp); 158 159 skip_end(); 160 161 psFree(image); 162 ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks"); 163 } 100 psImage *image = psImageAlloc(32, 32, PS_TYPE_F32); 101 ok(image != NULL, "psImage successfully allocated"); 102 skip_start(image == NULL, 5, "Skipping tests because psImageAlloc() failed"); 103 104 for (int j = 0; j < image->numRows; j++) 105 { 106 for (int i = 0; i < image->numCols; i++) { 107 image->data.F32[j][i] = j + 0.5; 108 } 109 } 110 111 // center of pixels is 0.5, 0.5 112 float value; 113 114 value = psImagePixelInterpolate (image, 2.5, 2.5, NULL, 0, 0.0, PS_INTERPOLATE_BILINEAR); 115 is_float (value, 2.5, "pixel center value - %f", value); 116 117 value = psImagePixelInterpolate (image, 2.2, 2.2, NULL, 0, 0.0, PS_INTERPOLATE_BILINEAR); 118 is_float (value, 2.2, "coord: 2.2, 2.5, value: %f", value); 119 120 value = psImagePixelInterpolate (image, 2.5, 2.8, NULL, 0, 0.0, PS_INTERPOLATE_BILINEAR); 121 is_float (value, 2.8, "coord: 2.8, value: %f", value); 122 123 value = psImagePixelInterpolate (image, 2.2, 2.8, NULL, 0, 0.0, PS_INTERPOLATE_BILINEAR); 124 is_float (value, 2.8, "coord: 2.8, value: %f", value); 125 126 value = psImagePixelInterpolate (image, 2.8, 2.8, NULL, 0, 0.0, PS_INTERPOLATE_BILINEAR); 127 is_float (value, 2.8, "coord: 2.8, value: %f", value); 128 129 skip_end(); 130 131 psFree(image); 132 ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks"); 133 } 134 164 135 165 136 // very simple tests: no mask, bicube mode, xramp image only 166 137 { 167 138 psMemId id = psMemGetId(); 168 169 // diag ("interpolate an x-ramp (bicube)"); 170 171 // generate simple image (x ramp) 172 psImage *image = psImageAlloc(32, 32, PS_TYPE_F64); 173 ok(image != NULL, "psImage successfully allocated"); 174 skip_start(image == NULL, 5, "Skipping tests because psImageAlloc() failed"); 175 176 for (int j = 0; j < image->numRows; j++) 177 { 178 for (int i = 0; i < image->numCols; i++) { 179 image->data.F64[j][i] = i + 0.5; 180 } 181 } 182 183 // center of pixels is 0.5, 0.5 184 double value; 185 186 psImageInterpolateOptions *interp = psImageInterpolateOptionsAlloc(PS_INTERPOLATE_BICUBE, 187 image, NULL, NULL, 0, 0.0, 0.0, 188 0, 0, 0.0); 189 ok(interp, "Interpolation options set"); 190 191 ok(psImageInterpolate(&value, NULL, NULL, 2.5, 2.5, interp), "Interpolation"); 192 is_double_tol (value, 2.5, 5.0e-8, "coord; 2.5, 2.5, value - %f", value); 193 194 ok(psImageInterpolate(&value, NULL, NULL, 2.2, 2.5, interp), "Interpolation"); 195 is_double_tol (value, 2.2, 5.0e-8, "coord: 2.2, 2.5, value: %f", value); 196 197 ok(psImageInterpolate(&value, NULL, NULL, 2.8, 2.5, interp), "Interpolation"); 198 is_double_tol (value, 2.8, 5.0e-8, "coord: 2.8, 2.5, value: %f", value); 199 200 ok(psImageInterpolate(&value, NULL, NULL, 2.8, 2.2, interp), "Interpolation"); 201 is_double_tol (value, 2.8, 5.0e-8, "coord: 2.8, 2.2, value: %f", value); 202 203 ok(psImageInterpolate(&value, NULL, NULL, 2.8, 2.8, interp), "Interpolation"); 204 is_double_tol (value, 2.8, 5.0e-8, "coord: 2.8, 2.8, value: %f", value); 205 206 // diag ("coords outside of nominal range (1 < x < Nx - 2) return 'uncover'"); 139 // generate simple image (x ramp) 140 psImage *image = psImageAlloc(32, 32, PS_TYPE_F32); 141 ok(image != NULL, "psImage successfully allocated"); 142 skip_start(image == NULL, 5, "Skipping tests because psImageAlloc() failed"); 143 144 for (int j = 0; j < image->numRows; j++) 145 { 146 for (int i = 0; i < image->numCols; i++) { 147 image->data.F32[j][i] = i + 0.5; 148 } 149 } 150 151 // center of pixels is 0.5, 0.5 152 float value; 153 154 value = psImagePixelInterpolate (image, 2.5, 2.5, NULL, 0, 0.0, PS_INTERPOLATE_BICUBE); 155 is_float (value, 2.5, "coord; 2.5, 2.5, value - %f", value); 156 157 value = psImagePixelInterpolate (image, 2.2, 2.5, NULL, 0, 0.0, PS_INTERPOLATE_BICUBE); 158 is_float (value, 2.2, "coord: 2.2, 2.5, value: %f", value); 159 160 value = psImagePixelInterpolate (image, 2.8, 2.5, NULL, 0, 0.0, PS_INTERPOLATE_BICUBE); 161 is_float (value, 2.8, "coord: 2.8, 2.5, value: %f", value); 162 163 value = psImagePixelInterpolate (image, 2.8, 2.2, NULL, 0, 0.0, PS_INTERPOLATE_BICUBE); 164 is_float (value, 2.8, "coord: 2.8, 2.2, value: %f", value); 165 166 value = psImagePixelInterpolate (image, 2.8, 2.8, NULL, 0, 0.0, PS_INTERPOLATE_BICUBE); 167 is_float (value, 2.8, "coord: 2.8, 2.8, value: %f", value); 207 168 208 169 // no extrapolation: these return the 'uncover' value 209 ok(psImageInterpolate(&value, NULL, NULL, 0.8, 2.8, interp), "Interpolation"); 210 is_double (value, 0.0, "coord: 0.8, 2.8, value: %f", value); 211 212 ok(psImageInterpolate(&value, NULL, NULL, 0.3, 2.8, interp), "Interpolation"); 213 is_double (value, 0.0, "coord: 0.3, 2.8, value: %f", value); 214 215 ok(psImageInterpolate(&value, NULL, NULL, -0.2, 2.8, interp), "Interpolation"); 216 is_double (value, 0.0, "coord: -0.2, 2.8, value: %f", value); 217 218 psFree(interp); 219 220 skip_end(); 221 222 psFree(image); 223 ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks"); 224 } 170 value = psImagePixelInterpolate (image, 0.8, 2.8, NULL, 0, 0.0, PS_INTERPOLATE_BICUBE); 171 is_float (value, 0.0, "coord: 0.8, 2.8, value: %f", value); 172 173 value = psImagePixelInterpolate (image, 0.3, 2.8, NULL, 0, 0.0, PS_INTERPOLATE_BICUBE); 174 is_float (value, 0.0, "coord: 0.3, 2.8, value: %f", value); 175 176 value = psImagePixelInterpolate (image, -0.2, 2.8, NULL, 0, 0.0, PS_INTERPOLATE_BICUBE); 177 is_float (value, 0.0, "coord: -0.2, 2.8, value: %f", value); 178 179 skip_end(); 180 181 psFree(image); 182 ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks"); 183 } 184 225 185 226 186 // very simple tests: no mask, bilinear mode, yramp image only 227 187 { 228 188 psMemId id = psMemGetId(); 229 230 // diag ("interpolate a y-ramp (bicube)");231 232 189 // generate simple image (y ramp) 233 psImage *image = psImageAlloc(32, 32, PS_TYPE_F64); 234 ok(image != NULL, "psImage successfully allocated"); 235 skip_start(image == NULL, 5, "Skipping tests because psImageAlloc() failed"); 236 237 for (int j = 0; j < image->numRows; j++) 238 { 239 for (int i = 0; i < image->numCols; i++) { 240 image->data.F64[j][i] = j + 0.5; 241 } 242 } 243 244 // center of pixels is 0.5, 0.5 245 double value; 246 247 psImageInterpolateOptions *interp = psImageInterpolateOptionsAlloc(PS_INTERPOLATE_BICUBE, 248 image, NULL, NULL, 0, 0.0, 0.0, 249 0, 0, 0.0); 250 ok(interp, "Interpolation options set"); 251 252 ok(psImageInterpolate(&value, NULL, NULL, 2.5, 2.5, interp), "Interpolation"); 253 is_double_tol (value, 2.5, 5.0e-8, "pixel center value - %f", value); 254 255 ok(psImageInterpolate(&value, NULL, NULL, 2.2, 2.2, interp), "Interpolation"); 256 is_double_tol (value, 2.2, 5.0e-8, "coord: 2.2, 2.5, value: %f", value); 257 258 ok(psImageInterpolate(&value, NULL, NULL, 2.5, 2.8, interp), "Interpolation"); 259 is_double_tol (value, 2.8, 5.0e-8, "coord: 2.8, value: %f", value); 260 261 ok(psImageInterpolate(&value, NULL, NULL, 2.2, 2.8, interp), "Interpolation"); 262 is_double_tol (value, 2.8, 5.0e-8, "coord: 2.8, value: %f", value); 263 264 ok(psImageInterpolate(&value, NULL, NULL, 2.8, 2.8, interp), "Interpolation"); 265 is_double_tol (value, 2.8, 5.0e-8, "coord: 2.8, value: %f", value); 266 267 psFree(interp); 268 269 skip_end(); 270 271 psFree(image); 272 ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks"); 273 } 190 psImage *image = psImageAlloc(32, 32, PS_TYPE_F32); 191 ok(image != NULL, "psImage successfully allocated"); 192 skip_start(image == NULL, 5, "Skipping tests because psImageAlloc() failed"); 193 194 for (int j = 0; j < image->numRows; j++) 195 { 196 for (int i = 0; i < image->numCols; i++) { 197 image->data.F32[j][i] = j + 0.5; 198 } 199 } 200 201 // center of pixels is 0.5, 0.5 202 float value; 203 204 value = psImagePixelInterpolate (image, 2.5, 2.5, NULL, 0, 0.0, PS_INTERPOLATE_BICUBE); 205 is_float (value, 2.5, "pixel center value - %f", value); 206 207 value = psImagePixelInterpolate (image, 2.2, 2.2, NULL, 0, 0.0, PS_INTERPOLATE_BICUBE); 208 is_float (value, 2.2, "coord: 2.2, 2.5, value: %f", value); 209 210 value = psImagePixelInterpolate (image, 2.5, 2.8, NULL, 0, 0.0, PS_INTERPOLATE_BICUBE); 211 is_float (value, 2.8, "coord: 2.8, value: %f", value); 212 213 value = psImagePixelInterpolate (image, 2.2, 2.8, NULL, 0, 0.0, PS_INTERPOLATE_BICUBE); 214 is_float (value, 2.8, "coord: 2.8, value: %f", value); 215 216 value = psImagePixelInterpolate (image, 2.8, 2.8, NULL, 0, 0.0, PS_INTERPOLATE_BICUBE); 217 is_float (value, 2.8, "coord: 2.8, value: %f", value); 218 219 skip_end(); 220 221 psFree(image); 222 ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks"); 223 } 224 274 225 275 226 // very simple tests: no mask, bilinear mode, x,y 2nd order shape 276 227 { 277 228 psMemId id = psMemGetId(); 278 279 // diag ("interpolate a quadratic shape (bicube)"); 280 281 // generate simple image (x ramp) 282 psImage *image = psImageAlloc(32, 32, PS_TYPE_F64); 283 ok(image != NULL, "psImage successfully allocated"); 284 skip_start(image == NULL, 5, "Skipping tests because psImageAlloc() failed"); 285 286 for (int j = 0; j < image->numRows; j++) 287 { 288 for (int i = 0; i < image->numCols; i++) { 289 image->data.F64[j][i] = 0.25*PS_SQR(i + 0.5) + j + 0.5; 290 } 291 } 292 293 // center of pixels is 0.5, 0.5 294 double value; 295 296 psImageInterpolateOptions *interp = psImageInterpolateOptionsAlloc(PS_INTERPOLATE_BICUBE, 297 image, NULL, NULL, 0, 0.0, 0.0, 298 0, 0, 0.0); 299 ok(interp, "Interpolation options set"); 300 301 ok(psImageInterpolate(&value, NULL, NULL, 2.5, 2.5, interp), "Interpolation"); 302 is_double_tol (value, 4.0625, 2.0e-7, "pixel center value - %f", value); 303 304 ok(psImageInterpolate(&value, NULL, NULL, 2.2, 2.2, interp), "Interpolation"); 305 is_double_tol (value, 3.41, 2.0e-7, "coord: 2.2, 2.5, value: %f", value); 306 307 ok(psImageInterpolate(&value, NULL, NULL, 2.5, 2.8, interp), "Interpolation"); 308 is_double_tol (value, 4.3625, 2.0e-7, "coord: 2.5, 2.8, value: %f", value); 309 310 ok(psImageInterpolate(&value, NULL, NULL, 2.2, 2.8, interp), "Interpolation"); 311 is_double_tol (value, 4.01, 2.0e-7, "coord: 2.2, 2.8, value: %f", value); 312 313 ok(psImageInterpolate(&value, NULL, NULL, 2.8, 2.8, interp), "Interpolation"); 314 is_double_tol (value, 4.76, 2.0e-7, "coord: 2.8, 2.8, value: %f", value); 315 316 psFree(interp); 317 318 skip_end(); 319 320 psFree(image); 321 ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks"); 322 } 323 324 return exit_status(); 229 // generate simple image (x ramp) 230 psImage *image = psImageAlloc(32, 32, PS_TYPE_F32); 231 ok(image != NULL, "psImage successfully allocated"); 232 skip_start(image == NULL, 5, "Skipping tests because psImageAlloc() failed"); 233 234 for (int j = 0; j < image->numRows; j++) 235 { 236 for (int i = 0; i < image->numCols; i++) { 237 image->data.F32[j][i] = 0.25*PS_SQR(i + 0.5) + j + 0.5; 238 } 239 } 240 241 // center of pixels is 0.5, 0.5 242 float value; 243 244 value = psImagePixelInterpolate (image, 2.5, 2.5, NULL, 0, 0.0, PS_INTERPOLATE_BICUBE); 245 is_float (value, 4.0625, "pixel center value - %f", value); 246 247 value = psImagePixelInterpolate (image, 2.2, 2.2, NULL, 0, 0.0, PS_INTERPOLATE_BICUBE); 248 is_float (value, 3.41, "coord: 2.2, 2.5, value: %f", value); 249 250 value = psImagePixelInterpolate (image, 2.5, 2.8, NULL, 0, 0.0, PS_INTERPOLATE_BICUBE); 251 is_float (value, 4.3625002, "coord: 2.5, 2.8, value: %f", value); 252 253 value = psImagePixelInterpolate (image, 2.2, 2.8, NULL, 0, 0.0, PS_INTERPOLATE_BICUBE); 254 is_float (value, 4.010000229, "coord: 2.2, 2.8, value: %f", value); 255 256 value = psImagePixelInterpolate (image, 2.8, 2.8, NULL, 0, 0.0, PS_INTERPOLATE_BICUBE); 257 is_float (value, 4.75999975, "coord: 2.8, 2.8, value: %f", value); 258 259 skip_end(); 260 261 psFree(image); 262 ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks"); 263 } 325 264 } -
trunk/psLib/test/mathtypes/tap_psScalar.c
r12513 r12781 5 5 * @author Eric Van Alst, MHPCC 6 6 * 7 * @version $Revision: 1. 4$7 * @version $Revision: 1.5 $ 8 8 * $Name: not supported by cvs2svn $ 9 * @date $Date: 2007-0 3-20 03:57:25$9 * @date $Date: 2007-04-10 21:09:30 $ 10 10 * 11 11 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii 12 12 */ 13 14 13 #include <pslib.h> 15 16 14 #include "tap.h" 17 15 #include "pstap.h" … … 49 47 int main(void) 50 48 { 51 plan_tests(43); 49 psLogSetFormat("HLNM"); 50 psLogSetLevel(PS_LOG_INFO); 51 plan_tests(47); 52 52 53 void testScalarAlloc();54 testScalarAlloc();55 void testBadScalarAlloc();56 testBadScalarAlloc();57 53 58 void testScalarCopy(); 59 testScalarCopy(); 60 void testBadScalarCopy(); 61 testBadScalarCopy(); 62 } 54 // Verify return is null for invalid scalar type 55 { 56 psMemId id = psMemGetId(); 57 psScalar* scalar = psScalarAlloc(true,PS_TYPE_BOOL); 58 ok(scalar == NULL, "psScalarAlloc returns null for invalid type"); 59 ok(!psMemCheckLeaks(id, NULL, NULL, false), "no memory leaks"); 60 } 63 61 64 void testScalarAlloc(void)65 {66 // diag("psTestScalarAlloc");67 62 68 63 //Verify the proper allocation/deallocation of scalar objects of valid types 69 tstScalarAllocByType(S8,10); 70 tstScalarAllocByType(U8,12); 71 tstScalarAllocByType(S16,14); 72 tstScalarAllocByType(U16,16); 73 tstScalarAllocByType(S32,18); 74 tstScalarAllocByType(U32,20); 75 tstScalarAllocByType(S64,22); 76 tstScalarAllocByType(U64,24); 77 tstScalarAllocByType(F32,26); 78 tstScalarAllocByType(F64,28); 79 } 64 { 65 psMemId id = psMemGetId(); 66 tstScalarAllocByType(S8,10); 67 tstScalarAllocByType(U8,12); 68 tstScalarAllocByType(S16,14); 69 tstScalarAllocByType(U16,16); 70 tstScalarAllocByType(S32,18); 71 tstScalarAllocByType(U32,20); 72 tstScalarAllocByType(S64,22); 73 tstScalarAllocByType(U64,24); 74 tstScalarAllocByType(F32,26); 75 tstScalarAllocByType(F64,28); 76 ok(!psMemCheckLeaks(id, NULL, NULL, false), "no memory leaks"); 77 } 80 78 81 79 82 void testBadScalarAlloc(void) 83 { 84 // diag("psTestBadScalarAlloc"); 85 86 // Verify return is null for invalid scalar type 87 psScalar* scalar = psScalarAlloc(true,PS_TYPE_BOOL); 88 ok(scalar == NULL, "psScalarAlloc returns null for invalid type"); 89 } 80 // Verify the return is null for invalid scalar type in the original 81 { 82 psMemId id = psMemGetId(); 83 psScalar* scalarOrig = psScalarAlloc(0,PS_TYPE_S8); 84 scalarOrig->type.type = PS_TYPE_BOOL; 85 psScalar* scalarCopy = psScalarCopy(scalarOrig); 86 ok(scalarCopy == NULL, "psScalarCopy returns NULL for invalid type"); 87 scalarCopy = psScalarCopy(NULL); 88 ok(scalarCopy == NULL, "psScalarCopy returns NULL for NULL argument"); 89 psFree(scalarOrig); 90 psFree(scalarCopy); 91 ok(!psMemCheckLeaks(id, NULL, NULL, false), "no memory leaks"); 92 } 90 93 91 94 92 void testScalarCopy(void)93 {94 // diag("psTestScalarCopy");95 96 95 // Verify the proper copying of scalar objects for all valid types 97 tstScalarCopyByType(S8,100); 98 tstScalarCopyByType(U8,110); 99 tstScalarCopyByType(S16,120); 100 tstScalarCopyByType(U16,130); 101 tstScalarCopyByType(S32,140); 102 tstScalarCopyByType(U32,150); 103 tstScalarCopyByType(S64,160); 104 tstScalarCopyByType(U64,170); 105 tstScalarCopyByType(F32,180); 106 tstScalarCopyByType(F64,190); 96 { 97 psMemId id = psMemGetId(); 98 tstScalarCopyByType(S8,100); 99 tstScalarCopyByType(U8,110); 100 tstScalarCopyByType(S16,120); 101 tstScalarCopyByType(U16,130); 102 tstScalarCopyByType(S32,140); 103 tstScalarCopyByType(U32,150); 104 tstScalarCopyByType(S64,160); 105 tstScalarCopyByType(U64,170); 106 tstScalarCopyByType(F32,180); 107 tstScalarCopyByType(F64,190); 108 ok(!psMemCheckLeaks(id, NULL, NULL, false), "no memory leaks"); 109 } 107 110 } 108 109 110 void testBadScalarCopy(void)111 {112 // diag("psTestBadScalarCopy");113 114 // Verify the return is null for invalid scalar type in the original115 psScalar* scalarOrig = psScalarAlloc(0,PS_TYPE_S8);116 scalarOrig->type.type = PS_TYPE_BOOL;117 psScalar* scalarCopy = psScalarCopy(scalarOrig);118 ok(scalarCopy == NULL, "psScalarCopy returns NULL for invalid type");119 120 scalarCopy = psScalarCopy(NULL);121 ok(scalarCopy == NULL, "psScalarCopy returns NULL for NULL argument");122 } -
trunk/psLib/test/mathtypes/tap_psVector.c
r12513 r12781 8 8 int main (void) 9 9 { 10 plan_tests(209); 11 12 // diag("psVectorAlloc() tests"); 10 plan_tests(285); 11 13 12 14 13 { 15 14 psMemId id = psMemGetId(); 16 15 psVector *psVec = psVectorAlloc(5, PS_TYPE_S32); 17 18 16 ok(psVec != NULL, "psVector successfully allocated"); 19 17 skip_start(psVec == NULL, 4, "Skipping 4 tests because psVectorAlloc() failed"); … … 23 21 ok(psVec->type.dimen == PS_DIMEN_VECTOR, "Vector dimen = %d", psVec->type.dimen); 24 22 skip_end(); 25 26 23 psFree(psVec); 27 24 ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks"); 28 25 } 29 26 30 { 27 28 { 29 psMemId id = psMemGetId(); 31 30 psVector* vecZero = psVectorAlloc(0, PS_TYPE_S32); 32 33 31 ok(vecZero != NULL, "zero-length vector allocated"); 34 32 skip_start(vecZero == NULL, 2, "Skipping 2 tests because psVectorAlloc() failed"); … … 36 34 ok(vecZero->n == 0, "Vector population = %ld", vecZero->n); 37 35 skip_end(); 38 39 36 psFree(vecZero); 40 } 41 42 { 37 ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks"); 38 } 39 40 41 { 42 psMemId id = psMemGetId(); 43 43 psVector* vecBogus = psVectorAlloc(10, 0); 44 45 44 ok(vecBogus == NULL, "psVectorAlloc() doesn't not accept bogus type"); 46 45 psErr *err = psErrorLast(); 47 48 46 skip_start(err == NULL, 2, "Skipping 2 tests because psVectorAlloc() didn't fail as expect"); 49 47 ok(strstr(err->name, "vectorAlloc"), "alloc failure - got error name %s", err->name); 50 48 ok(err->code == PS_ERR_BAD_PARAMETER_TYPE, "alloc failure - got error code %d", err->code); 51 49 skip_end(); 52 53 50 psFree(vecBogus); 54 }55 56 57 // diag("psVectorRealloc() tests"); 58 59 { 60 // create new psVector51 ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks"); 52 } 53 54 55 // psVectorRealloc() tests 56 { 57 psMemId id = psMemGetId(); 61 58 psVector *psVec = psVectorAlloc(5, PS_TYPE_S32); 62 59 ok(psVec->n == 5, "Vector population = %ld", psVec->n); 63 // for(psS32 i = 0; i < 5; i++) {64 // printf ("Elem %d = %d\n", i, psVec->data.S32[i]);65 // }66 60 67 61 // generate first part of vector … … 93 87 } 94 88 skip_end(); 95 96 89 psFree(psVec); 97 } 98 99 { 100 // Test D - Reallocate S32 vector smaller 90 ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks"); 91 } 92 93 94 // Test D - Reallocate S32 vector smaller 95 { 96 psMemId id = psMemGetId(); 101 97 psVector *psVec = psVectorAlloc(5, PS_TYPE_S32); 102 psVec->n = 5;103 104 98 // generate test data values 105 99 for(psS32 i = 0; i < 5; i++) { … … 107 101 psVec->n++; 108 102 } 109 110 103 psVec = psVectorRealloc(psVec, 3); 111 112 104 ok(psVec != NULL, "test vector reallocated to smaller size"); 113 105 skip_start(psVec == NULL, 5, "Skipping 6 tests because psVectorRealloc() failed"); … … 120 112 } 121 113 skip_end(); 122 } 123 124 { 125 // reallocate to 0 length 114 psFree(psVec); 115 ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks"); 116 } 117 118 119 // reallocate to 0 length 120 { 121 psMemId id = psMemGetId(); 126 122 psVector *psVec = psVectorAlloc(5, PS_TYPE_S32); 127 123 psVec = psVectorRealloc(psVec,0); … … 136 132 // XXX not really a test... 137 133 psFree(psVec); 138 } 139 140 { 141 psVector *vecBogus = psVectorAlloc(5, PS_TYPE_S32); 142 vecBogus = psVectorRealloc(NULL, 6); 143 134 ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks"); 135 } 136 137 138 { 139 psMemId id = psMemGetId(); 140 psVector *vecBogus = psVectorRealloc(NULL, 6); 144 141 ok(vecBogus == NULL, "psVectorRealloc() doesn't not accept bogus type"); 145 142 psErr *err = psErrorLast(); 146 147 143 skip_start(err == NULL, 2, "Skipping 2 tests because psVectorRealloc() didn't fail as expect"); 148 144 ok(strstr(err->name, "psVectorRealloc"), "alloc failure - got error name %s", err->name); 149 145 ok(err->code == PS_ERR_BAD_PARAMETER_NULL, "alloc failure - got error code %d", err->code); 150 146 skip_end(); 151 152 147 psFree(vecBogus); 153 } 154 155 // diag("psVectorExtend() tests"); 156 { 157 // create new psVector 148 psFree(err); 149 ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks"); 150 } 151 152 153 // psVectorExtend() tests 154 { 155 psMemId id = psMemGetId(); 158 156 psVector *psVec = psVectorAlloc(5, PS_TYPE_S32); 159 157 psVec = psVectorExtend(psVec, 0, 2); … … 164 162 ok(psVec->n == 7, "Vector population = %ld", psVec->n); 165 163 skip_end(); 166 167 164 psFree(psVec); 168 } 169 170 { 165 ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks"); 166 } 167 168 169 { 170 psMemId id = psMemGetId(); 171 171 psVector *psVec = psVectorAlloc(5, PS_TYPE_S32); 172 172 psVec = psVectorExtend(psVec, 0, 2); 173 173 psVec = psVectorExtend(psVec, 0, 2); 174 175 174 ok(psVec != NULL, "test vector extended"); 176 175 skip_start(psVec == NULL, 2, "Skipping 2 tests because psVectorExtend() failed"); … … 179 178 ok(psVec->n == 9,"Vector population = %ld", psVec->n); 180 179 skip_end(); 181 182 180 psFree(psVec); 183 } 184 185 { 181 ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks"); 182 } 183 184 185 { 186 psMemId id = psMemGetId(); 186 187 psVector *psVec = psVectorAlloc(5, PS_TYPE_S32); 187 188 psVec = psVectorExtend(psVec, 0, 2); 188 189 psVec = psVectorExtend(psVec, 0, 2); 189 190 psVec = psVectorExtend(psVec, 0, -2); 190 191 191 ok(psVec != NULL, "test vector extended"); 192 192 skip_start(psVec == NULL, 2, "Skipping 2 tests because psVectorExtend() failed"); … … 195 195 ok(psVec->n == 7, "Vector population = %ld", psVec->n); 196 196 skip_end(); 197 198 197 psFree(psVec); 199 } 200 201 { 198 ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks"); 199 } 200 201 202 { 203 psMemId id = psMemGetId(); 202 204 psVector *psVec = psVectorAlloc(5, PS_TYPE_S32); 203 205 psVec = psVectorExtend(psVec, 0, 2); … … 205 207 psVec = psVectorExtend(psVec, 0, -2); 206 208 psVec = psVectorExtend(psVec, 0, -20); 207 208 209 ok(psVec != NULL, "test vector extended"); 209 210 skip_start(psVec == NULL, 2, "Skipping 2 tests because psVectorExtend() failed"); … … 212 213 ok(psVec->n == 0, "Vector population = %ld", psVec->n); 213 214 skip_end(); 214 215 215 psFree(psVec); 216 } 217 218 219 // diag("psVectorInit() tests"); 220 221 { 216 ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks"); 217 } 218 219 220 // psVectorInit() tests 221 { 222 psMemId id = psMemGetId(); 222 223 psVector *vec = psVectorAlloc(1, PS_TYPE_U8); 223 224 ok(psVectorInit(vec, 1 ), "U8 Case"); 224 225 psFree(vec); 225 } 226 227 { 226 ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks"); 227 } 228 229 230 { 231 psMemId id = psMemGetId(); 228 232 psVector *vec = psVectorAlloc(1, PS_TYPE_U16); 229 233 ok(!psVectorInit(vec, PS_MAX_U64), "VectorInit failed. U16 Case"); 230 234 psFree(vec); 231 } 232 233 { 235 ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks"); 236 } 237 238 239 { 240 psMemId id = psMemGetId(); 234 241 psVector *vec = psVectorAlloc(1, PS_TYPE_U32); 235 242 ok(psVectorInit(vec, 10), "U32 Case"); 236 243 psFree(vec); 237 } 238 239 { 244 ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks"); 245 } 246 247 248 { 249 psMemId id = psMemGetId(); 240 250 psVector *vec = psVectorAlloc(1, PS_TYPE_U64); 241 251 ok(psVectorInit(vec, PS_MIN_U64), "U64 Case"); 242 252 psFree(vec); 243 } 244 245 { 253 ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks"); 254 } 255 256 257 { 258 psMemId id = psMemGetId(); 246 259 psVector *vec = psVectorAlloc(1, PS_TYPE_S8); 247 260 ok(!psVectorInit(vec, PS_MAX_S16), "VectorInit failed. S8 Case"); 248 261 psFree(vec); 249 } 250 251 { 262 ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks"); 263 } 264 265 266 { 267 psMemId id = psMemGetId(); 252 268 psVector *vec = psVectorAlloc(1, PS_TYPE_S16); 253 269 ok(psVectorInit(vec, -100), "S16 Case"); 254 270 psFree(vec); 255 } 256 257 { 271 ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks"); 272 } 273 274 275 { 276 psMemId id = psMemGetId(); 258 277 psVector *vec = psVectorAlloc(1, PS_TYPE_S32); 259 278 ok(psVectorInit(vec, 1), "S32 Case"); 260 279 psFree(vec); 261 } 262 263 { 264 // XXX is this test ok? 280 ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks"); 281 } 282 283 284 // XXX is this test ok? 285 { 286 psMemId id = psMemGetId(); 265 287 psVector *vec = psVectorAlloc(1, PS_TYPE_S64); 266 288 ok(psVectorInit(vec, PS_MAX_S64), "S64 Case"); 267 289 psFree(vec); 268 } 269 270 { 290 ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks"); 291 } 292 293 294 { 295 psMemId id = psMemGetId(); 271 296 psVector *vec = psVectorAlloc(1, PS_TYPE_F32); 272 297 ok(psVectorInit(vec, 1.1), "F32 Case"); 273 298 psFree(vec); 274 } 275 276 { 299 ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks"); 300 } 301 302 303 { 304 psMemId id = psMemGetId(); 277 305 psVector *vec = psVectorAlloc(1, PS_TYPE_F64); 278 306 ok(psVectorInit(vec, 1.4 ), "F64 Case"); 279 307 psFree(vec); 280 } 281 282 283 // diag("psVectorCreate() tests"); 284 285 { 308 ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks"); 309 } 310 311 312 // psVectorCreate() tests 313 { 314 psMemId id = psMemGetId(); 286 315 psVector *test = psVectorCreate(NULL, 0.0, 10.0, 1.0, PS_TYPE_S8); 287 316 for (int i = 0; i < 10; i++) { … … 290 319 } 291 320 psFree(test); 292 } 293 294 { 321 ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks"); 322 } 323 324 325 { 326 psMemId id = psMemGetId(); 295 327 psVector *test = psVectorCreate(NULL, 0.0, 10.0, 1.0, PS_TYPE_U8); 296 328 for (int i = 0; i < 10; i++) { … … 299 331 } 300 332 psFree(test); 301 } 302 303 304 { 333 ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks"); 334 } 335 336 337 { 338 psMemId id = psMemGetId(); 305 339 psVector *test = psVectorCreate(NULL, 0.0, 10.0, 1.0, PS_TYPE_U32); 306 340 for (int i = 0; i < 10; i++) { … … 309 343 } 310 344 psFree(test); 311 } 312 313 314 { 345 ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks"); 346 } 347 348 349 { 350 psMemId id = psMemGetId(); 315 351 psVector *test = psVectorCreate(NULL, 0.0, 10.0, 1.0, PS_TYPE_S32); 316 352 for (int i = 0; i < 10; i++) { … … 319 355 } 320 356 psFree(test); 321 } 322 323 324 { 357 ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks"); 358 } 359 360 361 { 362 psMemId id = psMemGetId(); 325 363 psVector *input = psVectorAlloc(5, PS_TYPE_F32); 326 364 psVector *test = psVectorCreate(input, 0.0, 5.0, 0.5, PS_TYPE_F32); … … 330 368 "Vector data matches. i = %d, data=%f", i, test->data.F32[i]); 331 369 } 332 333 370 psFree(input); 334 } 371 ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks"); 372 } 373 335 374 336 375 // Test PS_TYPE_F64 337 376 // PS_TYPE_S64 338 377 // PS_TYPE_U64 339 340 {378 { 379 psMemId id = psMemGetId(); 341 380 psVector *test = psVectorCreate(NULL, 0.0, 10.0, 1.0, PS_TYPE_S64); 342 381 for (int i = 0; i < 10; i++) … … 347 386 } 348 387 psFree(test); 349 } 350 351 { 388 ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks"); 389 } 390 391 392 { 393 psMemId id = psMemGetId(); 352 394 psVector *test = psVectorCreate(NULL, 0.0, 10.0, 1.0, PS_TYPE_U64); 353 395 for (int i = 0; i < 10; i++) … … 358 400 } 359 401 psFree(test); 360 } 361 362 { 402 ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks"); 403 } 404 405 406 { 407 psMemId id = psMemGetId(); 363 408 psVector *input = psVectorAlloc(5, PS_TYPE_F64); 364 409 psVector *test = psVectorCreate(input, 0.0, 5.0, 0.5, PS_TYPE_F64); 365 366 410 for (int i = 0; i < 10; i++) 367 411 { … … 371 415 } 372 416 psFree(input); 373 } 417 ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks"); 418 } 419 374 420 375 421 // Test PS_TYPE_U16 376 422 // PS_TYPE_S16 377 423 { 424 psMemId id = psMemGetId(); 378 425 psVector *test = psVectorCreate(NULL, 0.0, 10.0, 1.0, PS_TYPE_S16); 379 426 for (int i = 0; i < 10; i++) … … 383 430 } 384 431 psFree(test); 385 } 386 387 { 432 ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks"); 433 } 434 435 436 { 437 psMemId id = psMemGetId(); 388 438 psVector *input = psVectorAlloc(5, PS_TYPE_U16); 389 439 psVector *test = psVectorCreate(input, 0.0, 20.0, 2.0, PS_TYPE_U16); 390 391 440 for (int i = 0; i < 10; i++) 392 441 { … … 395 444 } 396 445 psFree(input); 397 } 398 399 400 401 // diag("psVectorToString() tests"); 446 ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks"); 447 } 448 449 402 450 403 451 #define TEST_VECTOR_TO_STRING(TYPE, SIZE, START, INC, EXPECTED) \ 404 452 { \ 453 psMemId id = psMemGetId(); \ 405 454 const int asize = SIZE; /* alloc size */ \ 406 455 const int osize = 100; /* output size (max) */ \ … … 416 465 \ 417 466 psFree(input); \ 418 } 419 420 467 psFree(result); \ 468 ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks"); \ 469 } 470 //HERE 471 // psVectorToString() tests 421 472 TEST_VECTOR_TO_STRING(PS_TYPE_U8, 5, 1, 1, "[1,2,3,4,5]"); 422 423 473 TEST_VECTOR_TO_STRING(PS_TYPE_U16, 5, 1, 1, "[1,2,3,4,5]"); 424 425 474 TEST_VECTOR_TO_STRING(PS_TYPE_U32, 5, 1, 1, "[1,2,3,4,5]"); 426 427 475 TEST_VECTOR_TO_STRING(PS_TYPE_U64, 5, 1, 1, "[1,2,3,4,5]"); 428 429 476 TEST_VECTOR_TO_STRING(PS_TYPE_S8, 5, -100, 10,"[-100,-90,-80,-70,-60]"); 430 431 477 TEST_VECTOR_TO_STRING(PS_TYPE_S16, 5, 0, -100, "[0,-100,-200,-300,-400]"); 432 433 478 TEST_VECTOR_TO_STRING(PS_TYPE_S32, 5, 0, -100, "[0,-100,-200,-300,-400]"); 434 435 479 TEST_VECTOR_TO_STRING(PS_TYPE_S64, 5, 0, -100, "[0,-100,-200,-300,-400]"); 436 437 480 TEST_VECTOR_TO_STRING(PS_TYPE_F32,5,.123,1,"[0.123,1.123,2.123,3.123,4.123]"); 438 481 TEST_VECTOR_TO_STRING(PS_TYPE_F64,5,.123,1,"[0.123,1.123,2.123,3.123,4.123]"); 439 482 440 441 // diag("p_psVectorGetElementF64() tests");442 483 443 484 #define TEST_VECTOR_GET_ELEMENT_F64(ELEM_TYPE, SIZE, VALUE_TYPE, \ 444 485 INIT_VALUE ) \ 445 486 { \ 487 psMemId id = psMemGetId(); \ 446 488 psVector *vec = psVectorAlloc(SIZE, ELEM_TYPE); \ 447 489 vec->n = SIZE; \ … … 454 496 \ 455 497 psFree(vec); \ 456 } 457 498 ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks"); \ 499 } 500 // p_psVectorGetElementF64() tests 458 501 TEST_VECTOR_GET_ELEMENT_F64(PS_TYPE_U8, 1, psU8, 1); 459 460 502 TEST_VECTOR_GET_ELEMENT_F64(PS_TYPE_U16, 2, psU16, 2); 461 462 503 TEST_VECTOR_GET_ELEMENT_F64(PS_TYPE_U32, 3, psU32, 3); 463 464 504 TEST_VECTOR_GET_ELEMENT_F64(PS_TYPE_U64, 100, psU64, 999999); 465 466 505 TEST_VECTOR_GET_ELEMENT_F64(PS_TYPE_S8, 1, psS8, -1); 467 468 506 TEST_VECTOR_GET_ELEMENT_F64(PS_TYPE_S16, 2, psS16, -2); 469 470 507 TEST_VECTOR_GET_ELEMENT_F64(PS_TYPE_S32, 3, psS32, -3); 471 472 508 TEST_VECTOR_GET_ELEMENT_F64(PS_TYPE_S64, 100, psS64, -999999); 473 474 509 TEST_VECTOR_GET_ELEMENT_F64(PS_TYPE_F32,1, psF32, .123); 475 476 510 TEST_VECTOR_GET_ELEMENT_F64(PS_TYPE_F64,2, psF64, -123.123); 477 511 478 512 479 // diag("p_psVectorPrint() tests");480 513 // XXX: Why are we testing private functions? 481 514 #define TEST_VECTOR_PRINT(ELEM_TYPE, SIZE, VALUE_TYPE, INIT_VALUE, FD, \ 482 515 OUT_NAME, EXPECTED_RC ) \ 483 516 { \ 517 psMemId id = psMemGetId(); \ 484 518 psVector *vec = psVectorAlloc(SIZE, ELEM_TYPE); \ 485 519 vec->n = SIZE; \ … … 491 525 \ 492 526 psFree(vec); \ 493 } 494 527 ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks"); \ 528 } 529 // p_psVectorPrint() tests 495 530 TEST_VECTOR_PRINT(PS_TYPE_U8, 1, psU8, 1, 1, "PS_TYPE_U8", TRUE); 496 497 531 TEST_VECTOR_PRINT(PS_TYPE_U16, 2, psU16, 2, 1, "PS_TYPE_U16", TRUE); 498 499 532 TEST_VECTOR_PRINT(PS_TYPE_U32, 3, psU32, 3, 1, "PS_TYPE_U32", TRUE); 500 501 533 TEST_VECTOR_PRINT(PS_TYPE_U64, 4, psU64, 999999, 1, "PS_TYPE_U64", TRUE); 502 503 534 TEST_VECTOR_PRINT(PS_TYPE_S8, 1, psS8, -1, 1, "PS_TYPE_S8", TRUE); 504 505 535 TEST_VECTOR_PRINT(PS_TYPE_S16, 2, psS16, -2, 1, "PS_TYPE_S16", TRUE); 506 507 536 TEST_VECTOR_PRINT(PS_TYPE_S32, 3, psS32, -3, 1, "PS_TYPE_S32", TRUE); 508 509 537 TEST_VECTOR_PRINT(PS_TYPE_S64, 4, psS64, -999999, 1, "PS_TYPE_S64", TRUE); 510 511 538 TEST_VECTOR_PRINT(PS_TYPE_F32,1, psF32, .123, 1, "PS_TYPE_F32", TRUE); 512 513 539 TEST_VECTOR_PRINT(PS_TYPE_F64,2, psF64, -123.123, 1, "PS_TYPE_F64", TRUE); 514 540 515 // diag("psVectorSet() tests"); 516 517 {541 // psVectorSet() tests 542 { 543 psMemId id = psMemGetId(); 518 544 psVector *vec = psVectorAlloc(5, PS_TYPE_S32); 519 520 545 ok(psVectorSet(vec, 0, 10), 521 546 "VectorSet set S32 at position 0"); 522 523 psFree(vec); 524 } 525 526 { 547 psFree(vec); 548 ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks"); 549 } 550 551 552 { 553 psMemId id = psMemGetId(); 527 554 psVector *vec = psVectorAlloc(5, PS_TYPE_S32); 528 529 555 ok(!psVectorSet(vec, 10, 10), 530 556 "VectorSet failes to set S32 at out of range position"); 531 532 psFree(vec); 533 } 534 535 { 557 psFree(vec); 558 ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks"); 559 } 560 561 562 { 563 psMemId id = psMemGetId(); 536 564 psVector *vec = psVectorAlloc(5, PS_TYPE_S32); 537 538 565 ok(psVectorSet(vec, 1, 4) == true, 539 566 "VectorSet set S32 at position 1"); 540 541 psFree(vec);542 } 543 544 545 // diag("psVectorGet() tests"); 546 547 {567 psFree(vec); 568 ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks"); 569 } 570 571 572 // psVectorGet() tests 573 { 574 psMemId id = psMemGetId(); 548 575 psVector *vec = psVectorAlloc(10, PS_TYPE_S32); 549 576 psVectorSet(vec, 0, 10); 550 551 577 ok((psS32)psVectorGet(vec, 0) == 10, 552 578 "VectorGet returned the correct S32 from position 0"); 553 554 psFree(vec); 555 } 556 557 { 579 psFree(vec); 580 ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks"); 581 } 582 583 584 { 585 psMemId id = psMemGetId(); 558 586 psVector *vec = psVectorAlloc(5, PS_TYPE_S32); 559 587 psVectorSet(vec, -1, 4); 560 561 588 ok((psS32)psVectorGet(vec, -1) == 4, 562 589 "VectorGet returned the correct S32 from tail using -1"); 563 564 psFree(vec);565 } 566 567 568 // diag("psVectorCountPixelMask() tests"); 569 570 {590 psFree(vec); 591 ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks"); 592 } 593 594 595 // psVectorCountPixelMask() tests 596 { 597 psMemId id = psMemGetId(); 571 598 ok(psVectorCountPixelMask(NULL, 1) == -1, 572 599 "psVectorCountPixelMask returned -1 for NULL Vector input"); 573 } 574 575 { 600 ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks"); 601 } 602 603 604 { 605 psMemId id = psMemGetId(); 576 606 psVector *vec = psVectorAlloc(5, PS_TYPE_S32); 577 607 vec->data.S32[0] = 0; … … 580 610 vec->data.S32[3] = 1; 581 611 vec->data.S32[4] = 0; 582 vec->n = 5;583 584 612 ok(psVectorCountPixelMask(vec, 1) == -1, 585 613 "returned -1 for wrong type of Vector input"); 586 587 psFree(vec); 588 } 589 590 { 614 psFree(vec); 615 ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks"); 616 } 617 618 619 { 620 psMemId id = psMemGetId(); 591 621 psVector *vec = psVectorAlloc(5, PS_TYPE_U8); 592 622 vec->data.U8[0] = 0; … … 595 625 vec->data.U8[3] = 1; 596 626 vec->data.U8[4] = 0; 597 vec->n = 5;598 627 long numPix = psVectorCountPixelMask(vec, 1); 599 600 628 ok(numPix != -1, "returned -1 for correct Vector input"); 601 629 ok(numPix == 2, "returned pixel count %d", numPix); 602 603 psFree(vec); 604 } 605 606 607 // diag("psVectorLength() tests"); 608 { 630 psFree(vec); 631 ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks"); 632 } 633 634 635 // psVectorLength() tests 636 { 637 psMemId id = psMemGetId(); 609 638 psVector *vector = psVectorAlloc(5, PS_TYPE_F32); 610 639 ok(psVectorLength(vector) == 5, 611 640 "returned the correct length of vector (was %d, should be 5)", psVectorLength(vector)); 612 641 psFree(vector); 613 } 614 615 { 642 ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks"); 643 } 644 645 646 { 647 psMemId id = psMemGetId(); 616 648 psVector *vector = psVectorAlloc(5, PS_TYPE_F32); 617 vector->n = 5;618 619 649 ok(psVectorLength(vector) == 5, 620 650 "returned the correct length of vector"); 621 622 651 psFree(vector); 623 } 624 625 { 652 ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks"); 653 } 654 655 656 { 657 psMemId id = psMemGetId(); 626 658 psVector *vector = psVectorAlloc(6, PS_TYPE_F32); 627 vector->n = 6;628 629 659 ok(psVectorLength(vector) == 6, 630 660 "returned the correct length of vector"); 631 632 661 psFree(vector); 633 } 634 635 { 662 ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks"); 663 } 664 665 666 { 667 psMemId id = psMemGetId(); 636 668 ok(psVectorLength(NULL) == -1, "returned -1 for a NULL input vector"); 637 } 638 639 { 669 ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks"); 670 } 671 672 673 { 674 psMemId id = psMemGetId(); 640 675 psArray *array = psArrayAlloc(5); 641 642 676 ok(psVectorLength((psVector*)array) == -1, 643 677 "returned -1 for an invalid input vector"); 644 645 678 psFree(array); 646 }647 648 649 // diag("psVectorCopy() tests"); 650 651 { 652 679 ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks"); 680 } 681 682 683 // psVectorCopy() tests 684 { 685 psMemId id = psMemGetId(); 653 686 ok(psVectorCopy(NULL, NULL, PS_TYPE_F32) == NULL, 654 687 "returned a NULL vector for NULL input"); 655 } 656 657 { 688 ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks"); 689 } 690 691 692 { 693 psMemId id = psMemGetId(); 658 694 psVector *in = psVectorAlloc(5, PS_TYPE_F32); 659 in->n = 5;660 661 695 for (int i = 0; i < 5; i++) { 662 696 in->data.F32[i] = i; 663 697 } 664 665 698 //Try copy of different type 666 699 psVector *copy = psVectorCopy(NULL, in, PS_TYPE_F64); … … 671 704 copy->data.F64[2], in->data.F32[2]); 672 705 skip_end(); 673 674 706 psFree(in); 675 707 psFree(copy); 676 } 708 ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks"); 709 } 710 677 711 678 712 // XXX psVectorRecycle needs it's own tests 679 713 // copy = psVectorRecycle(copy, in->n + 2, PS_TYPE_F64); 680 681 {714 { 715 psMemId id = psMemGetId(); 682 716 // Try copy of same type and non-NULL outVector of different type and 683 717 // size. … … 700 734 psFree(in); 701 735 psFree(copy); 702 } 703 704 return exit_status(); 736 ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks"); 737 } 705 738 } -
trunk/psLib/test/mathtypes/tap_psVectorSort_01.c
r12513 r12781 12 12 * @author Ross Harman, MHPCC 13 13 * 14 * @version $Revision: 1. 3$ $Name: not supported by cvs2svn $15 * @date $Date: 2007-0 3-20 03:57:25$14 * @version $Revision: 1.4 $ $Name: not supported by cvs2svn $ 15 * @date $Date: 2007-04-10 21:09:31 $ 16 16 * 17 17 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii 18 18 * 19 19 */ 20 21 20 #include <pslib.h> 22 23 21 #include "tap.h" 24 22 #include "pstap.h" 25 23 26 27 24 #define tstVectorSortByType(datatype,value) \ 28 25 in = psVectorAlloc(7,PS_TYPE_##datatype); \ 29 in->n = 7; \30 26 out = psVectorAlloc(7,PS_TYPE_##datatype); \ 31 out->n = 7; \32 27 in->data.datatype[0] = 7+value; \ 33 28 in->data.datatype[1] = 9+value; \ … … 45 40 ok(out->data.datatype[0] == in->data.datatype[6], \ 46 41 "sort out[0] type %s",#datatype); \ 47 skip_start(out->data.datatype[0] != in->data.datatype[6], \48 6,"sort out[0] type %s",#datatype); \49 42 ok(out->data.datatype[1] == in->data.datatype[3], \ 50 43 "sort out[1] type %s",#datatype); \ 51 skip_start(out->data.datatype[1] != in->data.datatype[3], \52 5,"Improper sort out[1] type %s",#datatype); \53 44 ok(out->data.datatype[2] == in->data.datatype[2], \ 54 45 "sort out[2] type %s",#datatype); \ 55 skip_start(out->data.datatype[2] != in->data.datatype[2], \56 4,"Improper sort out[2] type %s",#datatype); \57 46 ok(out->data.datatype[3] == in->data.datatype[4], \ 58 47 "sort out[3] type %s",#datatype); \ 59 skip_start(out->data.datatype[3] != in->data.datatype[4], \60 3,"Improper sort out[3] type %s",#datatype); \61 48 ok(out->data.datatype[4] == in->data.datatype[5], \ 62 49 "sort out[4] %s",#datatype); \ 63 skip_start(out->data.datatype[4] != in->data.datatype[5], \64 2,"Improper sort out[4] %s",#datatype); \65 50 ok(out->data.datatype[5] == in->data.datatype[0], \ 66 51 "sort out[5] %s",#datatype); \ 67 skip_start(out->data.datatype[5] != in->data.datatype[0], \68 1,"Improper sort out[5] %s",#datatype); \69 52 ok(out->data.datatype[6] == in->data.datatype[1], \ 70 53 "sort out[6] %s",#datatype); \ 71 skip_end(); \72 skip_end(); \73 skip_end(); \74 skip_end(); \75 skip_end(); \76 skip_end(); \77 54 skip_end(); \ 78 55 psFree(in); \ … … 84 61 char* argv[]) 85 62 { 86 plan_tests(92); 63 psLogSetFormat("HLNM"); 64 psLogSetLevel(PS_LOG_INFO); 65 plan_tests(97); 87 66 88 67 psVector *in = NULL; … … 91 70 92 71 // Test A - Verify the sort for all supported types 93 94 tstVectorSortByType(S8,0); 95 tstVectorSortByType(S16,1); 96 tstVectorSortByType(S32,2); 97 tstVectorSortByType(S64,3); 98 tstVectorSortByType(U8,4); 99 tstVectorSortByType(U16,5); 100 tstVectorSortByType(U32,6); 101 tstVectorSortByType(U64,7); 102 tstVectorSortByType(F32,8); 103 tstVectorSortByType(F64,9); 72 { 73 psMemId id = psMemGetId(); 74 tstVectorSortByType(S8,0); 75 tstVectorSortByType(S16,1); 76 tstVectorSortByType(S32,2); 77 tstVectorSortByType(S64,3); 78 tstVectorSortByType(U8,4); 79 tstVectorSortByType(U16,5); 80 tstVectorSortByType(U32,6); 81 tstVectorSortByType(U64,7); 82 tstVectorSortByType(F32,8); 83 tstVectorSortByType(F64,9); 84 ok(!psMemCheckLeaks(id, NULL, NULL, false), "no memory leaks"); 85 } 104 86 105 87 106 88 // Test B - Sort input vector into itself 89 { 90 psMemId id = psMemGetId(); 91 psVector *in = psVectorAlloc(7, PS_TYPE_F32); 92 in->data.F32[0] = 0.7f; 93 in->data.F32[1] = 0.9f; 94 in->data.F32[2] = 0.3f; 95 in->data.F32[3] = 0.1f; 96 in->data.F32[4] = 0.5f; 97 in->data.F32[5] = 0.5f; 98 in->data.F32[6] = -2.0f; 99 in = psVectorSort(in, in); 100 ok(in->data.F32[0] == -2.0f,"self sort in[0]"); 101 ok(in->data.F32[1] == 0.1f,"self sort in[1]"); 102 ok(in->data.F32[2] == 0.3f, "self sort in[2]"); 103 ok(in->data.F32[3] == 0.5f, "self sort in[3]"); 104 ok(in->data.F32[4] == 0.5f, "self sort in[4]"); 105 ok(in->data.F32[5] == 0.7f, "self sort in[5]"); 106 ok(in->data.F32[6] == 0.9f, "self sort in[6]"); 107 psFree(in); 108 ok(!psMemCheckLeaks(id, NULL, NULL, false), "no memory leaks"); 109 } 107 110 108 in = psVectorAlloc(7, PS_TYPE_F32);109 in->n = 7;110 in->data.F32[0] = 0.7f;111 in->data.F32[1] = 0.9f;112 in->data.F32[2] = 0.3f;113 in->data.F32[3] = 0.1f;114 in->data.F32[4] = 0.5f;115 in->data.F32[5] = 0.5f;116 in->data.F32[6] = -2.0f;117 in = psVectorSort(in, in);118 ok(in->data.F32[0] == -2.0f,"self sort in[0]");119 ok(in->data.F32[1] == 0.1f,"self sort in[1]");120 ok(in->data.F32[2] == 0.3f, "self sort in[2]");121 ok(in->data.F32[3] == 0.5f, "self sort in[3]");122 ok(in->data.F32[4] == 0.5f, "self sort in[4]");123 ok(in->data.F32[5] == 0.7f, "self sort in[5]");124 ok(in->data.F32[6] == 0.9f, "self sort in[6]");125 111 126 112 // Test C - Attempt to sort vector with invalid type 127 in->type.type = PS_TYPE_BOOL; 128 out = psVectorAlloc(7,PS_TYPE_F32); 129 tempVec = psVectorSort(out,in); 130 ok(tempVec == NULL, "Did return NULL on error"); 113 { 114 psMemId id = psMemGetId(); 115 psVector *in = psVectorAlloc(7, PS_TYPE_F32); 116 in->type.type = PS_TYPE_BOOL; 117 out = psVectorAlloc(7,PS_TYPE_F32); 118 tempVec = psVectorSort(out,in); 119 ok(tempVec == NULL, "Did return NULL on error"); 120 psFree(out); 121 psFree(in); 122 ok(!psMemCheckLeaks(id, NULL, NULL, false), "no memory leaks"); 123 } 124 131 125 132 126 // Test D - Sort vector with zero elements 133 out = psVectorAlloc(7,PS_TYPE_F32); 134 in->n = 0; 135 out = psVectorSort(out,in); 136 ok (out != NULL, "psVectorSort returned a non-NULL vector" ); 137 skip_start (out == NULL, 1, "psVectorSort returned a NULL vector" ); 138 ok (out->n == 0, "psVectorSort correctly return a 0-length vector.\n"); 139 skip_end(); 140 141 psFree(out); 127 { 128 psMemId id = psMemGetId(); 129 out = psVectorAlloc(7,PS_TYPE_F32); 130 in->n = 0; 131 out = psVectorSort(out,in); 132 ok(out != NULL, "psVectorSort returned a non-NULL vector" ); 133 skip_start (out == NULL, 1, "psVectorSort returned a NULL vector" ); 134 ok(out->n == 0, "psVectorSort correctly return a 0-length vector"); 135 skip_end(); 136 psFree(out); 137 ok(!psMemCheckLeaks(id, NULL, NULL, false), "no memory leaks"); 138 } 142 139 143 140 144 141 // Test D - Free float vectors 145 psFree(in); 146 ok ( ! psMemCheckLeaks(0, NULL, stdout, false),"Memory leaks not detected"); 147 148 psS32 nBad = psMemCheckCorruption(stderr, false); 149 ok(!nBad, "Found %d bad memory blocks\n", nBad); 142 { 143 psMemId id = psMemGetId(); 144 psVector *in = psVectorAlloc(7, PS_TYPE_F32); 145 psFree(in); 146 ok( ! psMemCheckLeaks(0, NULL, stdout, false),"Memory leaks not detected"); 147 psS32 nBad = psMemCheckCorruption(stderr, false); 148 ok(!nBad, "Found %d bad memory blocks", nBad); 149 ok(!psMemCheckLeaks(id, NULL, NULL, false), "no memory leaks"); 150 } 150 151 } -
trunk/psLib/test/mathtypes/tap_psVectorSort_02.c
r12513 r12781 14 14 * @author Ross Harman, MHPCC 15 15 * 16 * @version $Revision: 1. 3$ $Name: not supported by cvs2svn $17 * @date $Date: 2007-0 3-20 03:57:25$16 * @version $Revision: 1.4 $ $Name: not supported by cvs2svn $ 17 * @date $Date: 2007-04-10 21:09:31 $ 18 18 * 19 19 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 28 28 #define tstVectorSortIndexByType(datatype,value) \ 29 29 in = psVectorAlloc( 5, PS_TYPE_##datatype ); \ 30 in->n = 5; \31 30 in->data.datatype[0] = 7+value; \ 32 31 in->data.datatype[1] = 9+value; \ … … 52 51 psS32 main(psS32 argc, char* argv[]) 53 52 { 54 plan_tests(71); 53 psLogSetFormat("HLNM"); 54 psLogSetLevel(PS_LOG_INFO); 55 plan_tests(77); 55 56 56 57 psVector *in = NULL; … … 59 60 60 61 // Test A - Sort vectors by index for all types 61 tstVectorSortIndexByType(S8,0) 62 tstVectorSortIndexByType(U8,1) 63 tstVectorSortIndexByType(S16,2) 64 tstVectorSortIndexByType(U16,3) 65 tstVectorSortIndexByType(S32,4) 66 tstVectorSortIndexByType(U32,5) 67 tstVectorSortIndexByType(S64,6) 68 tstVectorSortIndexByType(U64,7) 69 tstVectorSortIndexByType(F32,8) 70 tstVectorSortIndexByType(F64,9) 71 psFree(out); 62 { 63 psMemId id = psMemGetId(); 64 tstVectorSortIndexByType(S8,0) 65 tstVectorSortIndexByType(U8,1) 66 tstVectorSortIndexByType(S16,2) 67 tstVectorSortIndexByType(U16,3) 68 tstVectorSortIndexByType(S32,4) 69 tstVectorSortIndexByType(U32,5) 70 tstVectorSortIndexByType(S64,6) 71 tstVectorSortIndexByType(U64,7) 72 tstVectorSortIndexByType(F32,8) 73 tstVectorSortIndexByType(F64,9) 74 psFree(out); 75 ok(!psMemCheckLeaks(id, NULL, NULL, false), "no memory leaks"); 76 } 77 72 78 73 79 // Test C Attempt to sort with null input vector 74 in = NULL; 75 out = psVectorAlloc(5,PS_TYPE_U32); 76 out = psVectorSortIndex(out,in); 77 ok(out == NULL, "Did return NULL with NULL input specified"); 80 { 81 psMemId id = psMemGetId(); 82 in = NULL; 83 out = psVectorAlloc(5,PS_TYPE_U32); 84 out = psVectorSortIndex(out,in); 85 ok(out == NULL, "Did return NULL with NULL input specified"); 86 ok(!psMemCheckLeaks(id, NULL, NULL, false), "no memory leaks"); 87 } 88 78 89 79 90 // Test D Sort with output vector which needs to be resized 80 in = psVectorAlloc(5,PS_TYPE_U8); 81 in->n=5; 82 for(psS32 m=0; m<5; m++) { 83 in->data.U8[m]= 20-m; 91 { 92 psMemId id = psMemGetId(); 93 in = psVectorAlloc(5,PS_TYPE_U8); 94 in->n=5; 95 for(psS32 m=0; m<5; m++) { 96 in->data.U8[m]= 20-m; 97 } 98 out = psVectorAlloc(5,PS_TYPE_U32); 99 out->n = 5; 100 out = psVectorSortIndex(out,in); 101 ok(out->n == 5, "Did properly resize output vector...out->n=%d, in->n=%d", out->n, in->n); 102 ok(out->data.U32[0] == 4, 103 "Did properly sort index out[0] = %d",out->data.U32[0]); 104 ok(out->data.U32[1] == 3, 105 "Did properly sort index out[1] = %d",out->data.U32[1]); 106 ok(out->data.U32[2] == 2, 107 "Did properly sort index out[2] = %d",out->data.U32[2]); 108 ok(out->data.U32[3] == 1, 109 "Did properly sort index out[3] = %d",out->data.U32[3]); 110 ok(out->data.U32[4] == 0, 111 "Did properly sort index out[4] = %d",out->data.U32[4]); 112 psFree(in); 113 psFree(out); 114 ok(!psMemCheckLeaks(id, NULL, NULL, false), "no memory leaks"); 84 115 } 85 out = psVectorAlloc(5,PS_TYPE_U32);86 out->n = 5;87 out = psVectorSortIndex(out,in);88 ok(out->n == 5, "Did properly resize output vector...out->n=%d, in->n=%d", out->n, in->n);89 ok(out->data.U32[0] == 4,90 "Did properly sort index out[0] = %d",out->data.U32[0]);91 ok(out->data.U32[1] == 3,92 "Did properly sort index out[1] = %d",out->data.U32[1]);93 ok(out->data.U32[2] == 2,94 "Did properly sort index out[2] = %d",out->data.U32[2]);95 ok(out->data.U32[3] == 1,96 "Did properly sort index out[3] = %d",out->data.U32[3]);97 ok(out->data.U32[4] == 0,98 "Did properly sort index out[4] = %d",out->data.U32[4]);99 116 100 psFree(in);101 psFree(out);102 117 103 118 // Test E - Sort input vector with zero elements 104 in = psVectorAlloc(5,PS_TYPE_U8); 105 out = psVectorAlloc(5,PS_TYPE_U32); 106 in->n = 0; 107 out->n = 0; 108 tempVect = out; 109 out = psVectorSortIndex(out,in); 110 ok ( out == tempVect, "Did not return the same output vector"); 111 in->n=5; 112 out->n=5; 113 psFree(out); 114 psFree(in); 119 { 120 psMemId id = psMemGetId(); 121 in = psVectorAlloc(5,PS_TYPE_U8); 122 out = psVectorAlloc(5,PS_TYPE_U32); 123 in->n = 0; 124 out->n = 0; 125 tempVect = out; 126 out = psVectorSortIndex(out,in); 127 ok ( out == tempVect, "Did not return the same output vector"); 128 in->n=5; 129 out->n=5; 130 psFree(out); 131 psFree(in); 132 ok(!psMemCheckLeaks(id, NULL, NULL, false), "no memory leaks"); 133 } 134 115 135 116 136 // Test F - Attempt to sort input vector with invalid type 117 in = psVectorAlloc(5,PS_TYPE_U8); 118 out = psVectorAlloc(5,PS_TYPE_U32); 119 in->n = 5; 120 out->n = 5; 121 tempVect = out; 122 in->type.type = PS_TYPE_BOOL; 123 out = psVectorSortIndex(out,in); 124 ok( out == NULL, "Did return NULL"); 125 in->type.type = PS_TYPE_U8; 126 psFree(in); 137 { 138 psMemId id = psMemGetId(); 139 in = psVectorAlloc(5,PS_TYPE_U8); 140 out = psVectorAlloc(5,PS_TYPE_U32); 141 in->n = 5; 142 out->n = 5; 143 tempVect = out; 144 in->type.type = PS_TYPE_BOOL; 145 out = psVectorSortIndex(out,in); 146 ok( out == NULL, "Did return NULL"); 147 in->type.type = PS_TYPE_U8; 148 psFree(in); 149 ok(!psMemCheckLeaks(id, NULL, NULL, false), "no memory leaks"); 150 } 151 127 152 128 153 // Test G - Free vectors 129 psS32 nLeaks = psMemCheckLeaks(0, NULL, stdout, false); 130 ok(!nLeaks, "Found %d memory leaks\n", nLeaks); 131 psS32 nBad = psMemCheckCorruption(stderr, false); 132 ok(!nBad, "Found %d bad memory blocks\n", nBad); 154 { 155 psMemId id = psMemGetId(); 156 psS32 nLeaks = psMemCheckLeaks(0, NULL, stdout, false); 157 ok(!nLeaks, "Found %d memory leaks", nLeaks); 158 psS32 nBad = psMemCheckCorruption(stderr, false); 159 ok(!nBad, "Found %d bad memory blocks", nBad); 160 ok(!psMemCheckLeaks(id, NULL, NULL, false), "no memory leaks"); 161 } 133 162 } -
trunk/psLib/test/mathtypes/tap_psVectorSort_03.c
r11265 r12781 3 3 * @brief Test driver for psVectorSort functions 4 4 * 5 * This test driver contains the following tests for psVectorSort test point 3:6 * A) Create float vectors of different sizes7 * B) Attempt to sort vectors...should get errors8 * C) Create float vector and double vector9 * D) Attempt to sort vectors...should get errors10 * E) Free float, double vectors11 *12 5 * @author Ross Harman, MHPCC 13 6 * 14 * @version $Revision: 1.2 $ $Name: not supported by cvs2svn $ 15 * @date $Date: 2007-01-24 22:14:48 $ 7 * @version $Revision: 1.3 $ $Name: not supported by cvs2svn $ 8 * @date $Date: 2007-04-10 21:09:31 $ 9 * 10 * XXX: These tests are obsolete. psVectorSOrt no longer returns error 11 * with incorrect input vector types or sizes 16 12 * 17 13 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 28 24 char* argv[]) 29 25 { 30 plan_tests(2); 26 psLogSetFormat("HLNM"); 27 psLogSetLevel(PS_LOG_INFO); 28 plan_tests(1); 29 ok(true, "cake"); 31 30 32 psVector *in = NULL; 33 psVector *out = NULL; 34 psVector *in2 = NULL; 35 psVector *out2 = NULL; 36 37 // Test A - Create float vectors 38 in = psVectorAlloc(5, PS_TYPE_F32); 39 in->n = 5; 40 out = psVectorAlloc(6, PS_TYPE_F32); 41 out->n = 6; 42 in->n = 5; 43 for(psS32 i=0; i<5; i++) { 44 //printf("arr[%d] = %f\n", i, in->data.F32[i]); 31 // Create float vectors with incorrect sizes 32 if (0) { 33 psMemId id = psMemGetId(); 34 psVector *in = psVectorAlloc(5, PS_TYPE_F32); 35 psVector *out = psVectorAlloc(6, PS_TYPE_F32); 36 psVector *out2 = psVectorSort(out, in); 37 ok(out2 == NULL, "psVectorSort() returned() NULL with non-uniform verctor input sizes"); 38 psFree(in); 39 psFree(out); 40 ok(!psMemCheckLeaks(id, NULL, NULL, false), "no memory leaks"); 45 41 } 46 42 47 43 48 // Test B - Sort input float vector and put results into output floatvector49 out = psVectorSort(out, in);50 51 // Test C - Create float vector and double vector52 in2 = psVectorAlloc(5, PS_TYPE_F32);53 in2->n = 5;54 out2 = psVectorAlloc(5, PS_TYPE_F64);55 out2->n = 5;56 for(psS32 j=0; j<5; j++) {57 //printf("vec[%d] = %f\n", j, in2->data.F32[j]);44 // Create float vector and double vector 45 if (0) { 46 psMemId id = psMemGetId(); 47 psVector *in2 = psVectorAlloc(5, PS_TYPE_F32); 48 psVector *out2 = psVectorAlloc(5, PS_TYPE_F64); 49 psVector *out3 = psVectorSort(out2, in2); 50 ok(out3 == NULL, "psVectorSort() returned() NULL with non-uniform verctor input types"); 51 psFree(in2); 52 psFree(out2); 53 ok(!psMemCheckLeaks(id, NULL, NULL, false), "no memory leaks"); 58 54 } 59 60 // Test D - Attempt to sort vectors with output of different type should create error61 out2 = psVectorSort(out2, in2);62 63 // Test C - Free float vectors64 psFree(in);65 psFree(in2);66 psFree(out);67 psFree(out2);68 psS32 nLeaks = psMemCheckLeaks(0, NULL, stdout, false);69 ok(!nLeaks, "Found %d memory leaks\n", nLeaks);70 psS32 nBad = psMemCheckCorruption(stderr, false);71 ok(!nBad, "Found %d bad memory blocks\n", nBad);72 55 } -
trunk/psLib/test/mathtypes/tap_psVectorSort_04.c
r11265 r12781 3 3 * @brief Test driver for psVectorSort functions 4 4 * 5 * This test driver contains the following tests for psVectorSort test point 4:6 * A) Attempt to sort with null input vector7 * B) Free vectors8 *9 5 * @author Ross Harman, MHPCC 10 6 * 11 * @version $Revision: 1. 2$ $Name: not supported by cvs2svn $12 * @date $Date: 2007-0 1-24 22:14:48$7 * @version $Revision: 1.3 $ $Name: not supported by cvs2svn $ 8 * @date $Date: 2007-04-10 21:09:31 $ 13 9 * 14 10 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii 15 11 * 16 12 */ 17 18 13 #include <pslib.h> 19 20 14 #include "tap.h" 21 15 #include "pstap.h" … … 25 19 char* argv[]) 26 20 { 21 psLogSetFormat("HLNM"); 22 psLogSetLevel(PS_LOG_INFO); 27 23 plan_tests(2); 28 24 29 psVector *badIn = NULL;30 psVector *goodOut = psVectorAlloc(5, PS_TYPE_F32);31 25 32 // Test A - Attempt to sort with null input vector 33 goodOut = psVectorSort(goodOut, badIn); 34 35 // Test B - Free vectors 36 psFree(goodOut); 37 psS32 nLeaks = psMemCheckLeaks(0, NULL, stdout, false); 38 ok(!nLeaks, "Found %d memory blocks\n", nLeaks); 39 psS32 nBad = psMemCheckCorruption(stderr, false); 40 ok(!nBad, "Found %d bad memory blocks\n", nBad); 26 // Attempt to sort with null input vector 27 { 28 psMemId id = psMemGetId(); 29 psVector *goodOut = psVectorAlloc(5, PS_TYPE_F32); 30 goodOut = psVectorSort(goodOut, NULL); 31 ok(goodOut == NULL, "psVectorSort() returned NULL with NULL input vector"); 32 ok(!psMemCheckLeaks(id, NULL, NULL, false), "no memory leaks"); 33 } 41 34 }
Note:
See TracChangeset
for help on using the changeset viewer.
