Changeset 14909
- Timestamp:
- Sep 20, 2007, 9:17:57 AM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branch_20070830/psLib/test/imageops/tap_psImageStructManip.c
r13614 r14909 10 10 * psImageTrim() 11 11 * 12 * @version $Revision: 1.4 $ $Name: not supported by cvs2svn $13 * @date $Date: 2007-0 6-04 20:25:32$12 * @version $Revision: 1.4.6.1 $ $Name: not supported by cvs2svn $ 13 * @date $Date: 2007-09-20 19:17:57 $ 14 14 * 15 15 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 33 33 psRegion region2 = psRegionSet(numCols/4, numCols/4+numCols/2, numRows/4, numRows/4+numRows/2); 34 34 35 psImage* original = psImageAlloc(numCols,numRows,PS_TYPE_U32); 36 for (psS32 row=0;row<numRows;row++) { 37 for (psS32 col=0;col<numCols;col++) { 38 original->data.F32[row][col] = row*1000+col; 39 } 40 } 41 42 memcpy(&preSubsetStruct, original, sizeof(psImage)); 43 psImage* subset2 = psImageSubset(original, region2); 44 ok(subset2, "psImageSubset() returned non-NULL (subset2)"); 45 skip_start(subset2 == NULL, 25, "Skipping tests because psImageSubset() returned NULL"); 46 psImage* subset3 = psImageSubset(original, region1); 47 ok(subset3, "psImageSubset() returned non-NULL (subset3)"); 48 skip_start(subset3 == NULL, 24, "Skipping tests because psImageSubset() returned NULL"); 49 50 // Verify the returned psImage structure members nrow and ncol are equal to 51 // the input parameter nrow and ncol respectively 52 ok(subset2->numCols == numCols/2 && subset2->numRows == numRows/2, 53 "psImageSubset output size set properly"); 54 ok(subset3->numCols == numCols/2 && subset3->numRows == numRows/2, 55 "psImageSubset output size set properly"); 56 57 // Verify the returned psImage structure contains expected values in the 58 // row member, if the input psImage structure image contains known values 59 bool errorFlag = false; 60 for (psS32 row=0;row<numRows/2;row++) { 61 for (psS32 col=0;col<numCols/2;col++) { 62 if (subset2->data.U32[row][col] != original->data.U32[row+numRows/4][col+numCols/4]) { 63 diag("psImageSubset output #1 was wrong at %dx%d (%d vs %d).", 64 row,col,subset2->data.U32[row][col], original->data.U32[row+numRows/4][col+numCols/4]); 65 errorFlag = true; 66 } 67 if (subset3->data.U32[row][col] != original->data.U32[row][col]) { 68 diag("psImageSubset output #1 was wrong at %dx%d (%d vs %d).", 69 row,col,subset2->data.U32[row][col], original->data.U32[row][col]); 70 errorFlag = true; 71 } 72 } 73 } 74 ok(!errorFlag, "psImageSubset() produced the expected values"); 75 76 // Verify the returned psImage structure member type is equal to the input 77 // psImage structure member type 78 ok(subset2->type.type == PS_TYPE_U32, "psImageSubset() type was correct (subset2)"); 79 ok(subset3->type.type == PS_TYPE_U32, "psImageSubset() type was correct (subset3)"); 80 81 // Verify the returned psImage structure members row0 and col0 are equal to 82 // the input parameters row0 and col0 respectively 83 ok(subset2->col0 == numCols/4 && subset2->row0 == numRows/4, 84 "psImageSubset() set col0/row0 correctly (subset2)"); 85 ok(subset3->col0 == 0 && subset3->row0 == 0, 86 "psImageSubset() set col0/row0 correctly (subset3)"); 87 88 // Verify the returned psImage structure member parent is equal to the 89 // input psImage structure pointer image 90 ok(subset2->parent == original && subset3->parent == original, "psImageSubset() set ->parent correctly"); 91 92 // Verify the returned psImage structure member children is null 93 ok(subset2->children == NULL && subset3->children == NULL, "psImageSubset() set ->children correctly"); 94 95 // Verify the input psImage structure image only has the following members 96 // changed: 1) Nchildren is increased by one. 2) parent contains pointer psImage structure 97 // out at parent[Nchildren-1] 98 ok(original->children != NULL && original->children->n == 2, "psImageSubset did increment number of children by one per subset."); 99 ok(original->children->data[0] == subset2 && original->children->data[1] == subset3, 100 "psImageSubset did properly store the children pointers."); 101 102 // Verify the returned psImage structure pointer is null and program 103 // execution doesn't stop, if the input parameter image is null. 104 // Also verified the input psImage structure is not modified 105 // An error should follow... 106 // XXX: Verify error 107 psImage* subset1 = psImageSubset(NULL,region1); 108 ok(subset1 == NULL, "psImageSubset returned NULL when input image was NULL."); 109 110 // Verify the returned psImage structure pointer is null and program 111 // execution doesn't stop, if the input parameters nrow and/or ncol are zero. 112 // Also verify input psImage structure is not modified 113 // An error should follow... 114 // XXX: Verify error 115 { 116 memcpy(&preSubsetStruct,original,sizeof(psImage)); 117 subset1 = psImageSubset(original, psRegionSet(0,numCols/2,numRows/2,numRows/2)); 118 ok(subset1 == NULL, "psImageSubset returned NULL when numRows=0."); 119 // An error should follow... 120 // XXX: Verify error 121 subset1 = psImageSubset(original,psRegionSet(numCols/2,numCols/2,0,numRows/2)); 122 ok(subset1 == NULL, "psImageSubset returned NULL when numCols=0."); 123 ok(memcmp(original,&preSubsetStruct,sizeof(psImage)) == 0, 124 "psImageSubset didn't change the original struct though it failed to subset."); 125 } 126 127 // Verify the returned psImage structure pointer is null and program 128 // execution doesn't stop, if the input parameters row0 and col0 are not within 129 // the range of values of psImage structure image 130 // An error should follow... 131 // XXX: Verify error 132 { 133 subset1 = psImageSubset(original, psRegionSet(0,numCols/2, 0,numRows*2)); 134 ok(subset1 == NULL, 135 "psImageSubset returned NULL when subset origin was outside of image (via cols)"); 136 // An error should follow... 137 // XXX: Verify error 138 subset1 = psImageSubset(original,psRegionSet(0,numCols*2,0,numRows/2)); 139 ok(subset1 == NULL, 140 "psImageSubset returned NULL when subset origin was outside of image (via rows)"); 141 // An error should follow... 142 // XXX: Verify error 143 subset1 = psImageSubset(original, psRegionSet(-1,numCols/2,0,numRows/2)); 144 ok(subset1 == NULL, 145 "psImageSubset returned NULL when subset origin was outside of image (col0=-1)"); 146 // An error should follow... 147 // XXX: Verify error 148 subset1 = psImageSubset(original, psRegionSet(0,numCols/2,-1,numRows/2)); 149 ok(subset1 == NULL, 150 "psImageSubset returned NULL when subset origin was outside of image (row0=-1)"); 151 } 152 153 // Verify the returned psImage structure pointer is null and program 154 // execution doesn't stop if the input parameters nrow, ncol, row0 and col0 155 // specify a range of data not within the input psImage structure image. Also 156 // verify the input psImage structure is not modified 157 // An error should follow... 158 // XXX: Verify error 159 { 160 subset1 = psImageSubset(original,psRegionSet(0,numCols/2,0,numRows+1)); 161 ok(subset1 == NULL, 162 "psImageSubset returned NULL when subset was outside of image (via rows)"); 163 // An error should follow... 164 // XXX: Verify error 165 subset1 = psImageSubset(original, psRegionSet(0,numCols+1,0,numRows/2)); 166 ok(subset1 == NULL, 167 "psImageSubset returned NULL when subset was outside of image (via cols)"); 168 // An error should follow... 169 // XXX: Verify error 170 subset1 = psImageSubset(original,psRegionSet(0,numCols+1,0,numRows+1)); 171 ok(subset1 == NULL, 172 "psImageSubset returned NULL when subset was outside of image (via row+cols)"); 173 } 174 175 // psImageFreeChildren shall deallocate any children images of a 176 // psImage structure 177 memcpy(&preSubsetStruct,original,sizeof(psImage)); 178 psImageFreeChildren(original); 179 180 // Verify the returned psImage structure member Nchildren is set to zero. 181 // XXX: This doesn't make sense. 182 ok(original->children == NULL || original->children->n == 0, 183 "psImageFreeChildren didn't set children to NULL"); 184 185 //Verify the returned psImage structure members type, nrow, ncol, row0, col0, rows 186 // and parent are not modified. 187 ok(preSubsetStruct.numRows == original->numRows && 188 preSubsetStruct.numCols == original->numCols && 189 preSubsetStruct.row0 == original->row0 && 190 preSubsetStruct.col0 == original->col0, 191 "psImageFreeChildren modified parent's non-children elements"); 192 193 skip_end(); 194 skip_end(); 195 psFree(original); 196 ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks"); 35 // test basic subset creation 36 { 37 psImage* original = psImageAlloc(numCols,numRows,PS_TYPE_U32); 38 for (psS32 row=0;row<numRows;row++) { 39 for (psS32 col=0;col<numCols;col++) { 40 original->data.F32[row][col] = row*1000+col; 41 } 42 } 43 44 // XXX this is not being used in this section 45 memcpy(&preSubsetStruct, original, sizeof(psImage)); 46 psImage* subset1 = psImageSubset(original, region2); 47 ok(subset1, "psImageSubset() returned non-NULL (subset1)"); 48 skip_start(subset1 == NULL, 25, "Skipping tests because psImageSubset() returned NULL"); 49 psImage* subset2 = psImageSubset(original, region1); 50 ok(subset2, "psImageSubset() returned non-NULL (subset2)"); 51 skip_start(subset2 == NULL, 24, "Skipping tests because psImageSubset() returned NULL"); 52 53 // Verify the returned psImage structure members nrow and ncol are equal to 54 // the input parameter nrow and ncol respectively 55 ok(subset1->numCols == numCols/2 && subset1->numRows == numRows/2, 56 "psImageSubset output size set properly"); 57 ok(subset2->numCols == numCols/2 && subset2->numRows == numRows/2, 58 "psImageSubset output size set properly"); 59 60 // Verify the returned psImage structure contains expected values in the 61 // row member, if the input psImage structure image contains known values 62 bool errorFlag = false; 63 for (psS32 row=0;row<numRows/2;row++) { 64 for (psS32 col=0;col<numCols/2;col++) { 65 if (subset1->data.U32[row][col] != original->data.U32[row+numRows/4][col+numCols/4]) { 66 diag("psImageSubset output #1 was wrong at %dx%d (%d vs %d).", 67 row,col,subset1->data.U32[row][col], original->data.U32[row+numRows/4][col+numCols/4]); 68 errorFlag = true; 69 } 70 if (subset2->data.U32[row][col] != original->data.U32[row][col]) { 71 diag("psImageSubset output #1 was wrong at %dx%d (%d vs %d).", 72 row,col,subset1->data.U32[row][col], original->data.U32[row][col]); 73 errorFlag = true; 74 } 75 } 76 } 77 ok(!errorFlag, "psImageSubset() produced the expected values"); 78 79 // Verify the returned psImage structure member type is equal to the input 80 // psImage structure member type 81 ok(subset1->type.type == PS_TYPE_U32, "psImageSubset() type was correct (subset1)"); 82 ok(subset2->type.type == PS_TYPE_U32, "psImageSubset() type was correct (subset2)"); 83 84 // Verify the returned psImage structure members row0 and col0 are equal to 85 // the input parameters row0 and col0 respectively 86 ok(subset1->col0 == numCols/4 && subset1->row0 == numRows/4, 87 "psImageSubset() set col0/row0 correctly (subset1)"); 88 ok(subset2->col0 == 0 && subset2->row0 == 0, 89 "psImageSubset() set col0/row0 correctly (subset2)"); 90 91 // Verify the returned psImage structure member parent is equal to the 92 // input psImage structure pointer image 93 ok(subset1->parent == original && subset2->parent == original, "psImageSubset() set ->parent correctly"); 94 95 // Verify the returned psImage structure member children is null 96 ok(subset1->children == NULL && subset2->children == NULL, "psImageSubset() set ->children correctly"); 97 98 // Verify the input psImage structure image only has the following members 99 // changed: 1) Nchildren is increased by one. 2) parent contains pointer psImage structure 100 // out at parent[Nchildren-1] 101 ok(original->children != NULL && original->children->n == 2, "psImageSubset did increment number of children by one per subset."); 102 ok(original->children->data[0] == subset1 && original->children->data[1] == subset2, 103 "psImageSubset did properly store the children pointers."); 104 105 psFree (subset1); 106 psFree (subset2); 107 skip_end(); 108 skip_end(); 109 psFree (original); 110 } 111 112 // test free in reverse order from above 113 { 114 psImage* original = psImageAlloc(numCols,numRows,PS_TYPE_U32); 115 for (psS32 row=0;row<numRows;row++) { 116 for (psS32 col=0;col<numCols;col++) { 117 original->data.F32[row][col] = row*1000+col; 118 } 119 } 120 121 // XXX this is not being used in this section 122 memcpy(&preSubsetStruct, original, sizeof(psImage)); 123 psImage* subset1 = psImageSubset(original, region2); 124 ok(subset1, "psImageSubset() returned non-NULL (subset1)"); 125 psImage* subset2 = psImageSubset(original, region1); 126 ok(subset2, "psImageSubset() returned non-NULL (subset2)"); 127 128 psFree (original); 129 psFree (subset1); 130 psFree (subset2); 131 } 132 133 { 134 psImage* original = psImageAlloc(numCols,numRows,PS_TYPE_U32); 135 for (psS32 row=0;row<numRows;row++) { 136 for (psS32 col=0;col<numCols;col++) { 137 original->data.F32[row][col] = row*1000+col; 138 } 139 } 140 141 // XXX this is not being used in this section 142 memcpy(&preSubsetStruct, original, sizeof(psImage)); 143 144 // Verify the returned psImage structure pointer is null and program 145 // execution doesn't stop, if the input parameter image is null. 146 // Also verified the input psImage structure is not modified 147 // An error should follow... 148 // XXX: Verify error 149 psImage* subset1 = psImageSubset(NULL,region1); 150 ok(subset1 == NULL, "psImageSubset returned NULL when input image was NULL."); 151 152 // Verify the returned psImage structure pointer is null and program 153 // execution doesn't stop, if the input parameters nrow and/or ncol are zero. 154 // Also verify input psImage structure is not modified 155 // An error should follow... 156 // XXX: Verify error 157 { 158 memcpy(&preSubsetStruct,original,sizeof(psImage)); 159 subset1 = psImageSubset(original, psRegionSet(0,numCols/2,numRows/2,numRows/2)); 160 ok(subset1 == NULL, "psImageSubset returned NULL when numRows=0."); 161 // An error should follow... 162 // XXX: Verify error 163 subset1 = psImageSubset(original,psRegionSet(numCols/2,numCols/2,0,numRows/2)); 164 ok(subset1 == NULL, "psImageSubset returned NULL when numCols=0."); 165 ok(memcmp(original,&preSubsetStruct,sizeof(psImage)) == 0, 166 "psImageSubset didn't change the original struct though it failed to subset."); 167 } 168 169 // Verify the returned psImage structure pointer is null and program 170 // execution doesn't stop, if the input parameters row0 and col0 are not within 171 // the range of values of psImage structure image 172 // An error should follow... 173 // XXX: Verify error 174 { 175 subset1 = psImageSubset(original, psRegionSet(0,numCols/2, 0,numRows*2)); 176 ok(subset1 == NULL, 177 "psImageSubset returned NULL when subset origin was outside of image (via cols)"); 178 // An error should follow... 179 // XXX: Verify error 180 subset1 = psImageSubset(original,psRegionSet(0,numCols*2,0,numRows/2)); 181 ok(subset1 == NULL, 182 "psImageSubset returned NULL when subset origin was outside of image (via rows)"); 183 // An error should follow... 184 // XXX: Verify error 185 subset1 = psImageSubset(original, psRegionSet(-1,numCols/2,0,numRows/2)); 186 ok(subset1 == NULL, 187 "psImageSubset returned NULL when subset origin was outside of image (col0=-1)"); 188 // An error should follow... 189 // XXX: Verify error 190 subset1 = psImageSubset(original, psRegionSet(0,numCols/2,-1,numRows/2)); 191 ok(subset1 == NULL, 192 "psImageSubset returned NULL when subset origin was outside of image (row0=-1)"); 193 } 194 195 // Verify the returned psImage structure pointer is null and program 196 // execution doesn't stop if the input parameters nrow, ncol, row0 and col0 197 // specify a range of data not within the input psImage structure image. Also 198 // verify the input psImage structure is not modified 199 // An error should follow... 200 // XXX: Verify error 201 { 202 subset1 = psImageSubset(original,psRegionSet(0,numCols/2,0,numRows+1)); 203 ok(subset1 == NULL, 204 "psImageSubset returned NULL when subset was outside of image (via rows)"); 205 // An error should follow... 206 // XXX: Verify error 207 subset1 = psImageSubset(original, psRegionSet(0,numCols+1,0,numRows/2)); 208 ok(subset1 == NULL, 209 "psImageSubset returned NULL when subset was outside of image (via cols)"); 210 // An error should follow... 211 // XXX: Verify error 212 subset1 = psImageSubset(original,psRegionSet(0,numCols+1,0,numRows+1)); 213 ok(subset1 == NULL, 214 "psImageSubset returned NULL when subset was outside of image (via row+cols)"); 215 } 216 psFree(original); 217 } 218 ok(!psMemCheckLeaks (id, NULL, stderr, false), "no memory leaks"); 197 219 } 198 220 }
Note:
See TracChangeset
for help on using the changeset viewer.
