Changeset 1946 for trunk/psLib/test/dataManip/tst_psFunc02.c
- Timestamp:
- Oct 3, 2004, 2:39:58 PM (22 years ago)
- File:
-
- 1 edited
-
trunk/psLib/test/dataManip/tst_psFunc02.c (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/test/dataManip/tst_psFunc02.c
r1811 r1946 1 1 /***************************************************************************** 2 2 This routine must ensure that the psSpline1DAlloc() function properly 3 allocates the spline data structure. 4 5 XXX: figure out the memory deallocator 3 allocates the spline data structure. It allocates both linear and cubic 4 splines with a variety of min/max ranges. 6 5 *****************************************************************************/ 7 6 #include <stdio.h> … … 11 10 #include "psFunctions.h" 12 11 13 #define N 10 12 #define N 4 13 #define LINEAR 1 14 #define CUBIC 3 14 15 15 16 int main() … … 18 19 int memLeaks=0; 19 20 int i; 20 //int currentId = psMemGetId();21 int currentId = psMemGetId(); 21 22 psSpline1D *tmpSpline; 22 23 … … 26 27 printPositiveTestHeader(stdout, 27 28 "psFunction functions", 28 "psSpline1DAlloc() ");29 30 tmpSpline = psSpline1DAlloc(N, 1, 1.0, 10.0);31 if (tmpSpline == NULL) { 32 printf("ERROR: Could not allocate psSpline1D data structure\n"); 33 testStatus = false; 34 } 35 if (tmpSpline->spline == NULL) { 36 printf("ERROR: Could not allocate psSpline1D->spline data structure\n"); 37 testStatus = false; 38 } 39 40 if (tmpSpline->n != N) { 41 printf("ERROR: spline->n set incorrectly (%d)\n", tmpSpline->n); 42 testStatus = false; 43 } 44 45 for (i=0;i<N;i++) { 46 if (tmpSpline->spline[i] == NULL) { 47 printf("ERROR: Could not allocate spline %d\n", i); 48 testStatus = false; 49 } 50 if ((tmpSpline->spline[i])->n != 2) {51 printf("ERROR: Spline created with order %d\n", (tmpSpline->spline[i])->n); 52 testStatus = false; 53 } 54 } 55 56 if (tmpSpline->domains == NULL) { 57 printf("ERROR: Could not allocate psSpline1D->domains data structure\n"); 58 testStatus = false; 59 } 60 61 for (i=0;i<N+1;i++) { 62 printf("psSpline1D->domains[%d] is %f\n", i, tmpSpline->domains[i]); 63 } 64 65 p sFree(tmpSpline);66 psMemCheckCorruption(1); 67 //memLeaks = psMemCheckLeaks(currentId,NULL,stderr);68 if (0 != memLeaks) { 69 psAbort(__func__,"Memory Leaks! (%d leaks)", memLeaks); 70 } 71 72 printFooter(stdout, 73 "psFunctions functions", 74 "psSpline1DAlloc() ",75 testStatus); 76 77 /****************************************************************************/ 78 /****************************************************************************/ 79 testStatus = true; 80 printPositiveTestHeader(stdout, 81 "psFunction functions", 82 "psSpline1DAlloc() ");83 84 tmpSpline = psSpline1DAlloc(N, 1, 1.0, 1.0);29 "psSpline1DAlloc(): linear, normal"); 30 31 tmpSpline = psSpline1DAlloc(N, LINEAR, 1.0, 10.0); 32 if (tmpSpline == NULL) { 33 printf("ERROR: Could not allocate psSpline1D data structure\n"); 34 testStatus = false; 35 } 36 if (tmpSpline->spline == NULL) { 37 printf("ERROR: Could not allocate psSpline1D->spline data structure\n"); 38 testStatus = false; 39 } 40 41 if (tmpSpline->n != N) { 42 printf("ERROR: spline->n set incorrectly (%d)\n", tmpSpline->n); 43 testStatus = false; 44 } 45 46 for (i=0;i<N;i++) { 47 if (tmpSpline->spline[i] == NULL) { 48 printf("ERROR: Could not allocate spline %d\n", i); 49 testStatus = false; 50 } 51 if ((tmpSpline->spline[i])->n != LINEAR+1) { 52 printf("ERROR: Spline created with order %d\n", (tmpSpline->spline[i])->n); 53 testStatus = false; 54 } 55 } 56 57 if (tmpSpline->domains == NULL) { 58 printf("ERROR: Could not allocate psSpline1D->domains data structure\n"); 59 testStatus = false; 60 } 61 62 for (i=0;i<N+1;i++) { 63 printf("psSpline1D->domains[%d] is %f\n", i, tmpSpline->domains[i]); 64 } 65 66 p_psSpline1DFree(tmpSpline); 67 psMemCheckCorruption(1); 68 memLeaks = psMemCheckLeaks(currentId,NULL,stderr); 69 if (0 != memLeaks) { 70 psAbort(__func__,"Memory Leaks! (%d leaks)", memLeaks); 71 } 72 73 printFooter(stdout, 74 "psFunctions functions", 75 "psSpline1DAlloc(): linear, normal", 76 testStatus); 77 78 /****************************************************************************/ 79 /****************************************************************************/ 80 testStatus = true; 81 printPositiveTestHeader(stdout, 82 "psFunction functions", 83 "psSpline1DAlloc(): linear, min/max are equal"); 84 85 tmpSpline = psSpline1DAlloc(N, LINEAR, 1.0, 1.0); 85 86 86 87 if (tmpSpline != NULL) { … … 89 90 } 90 91 91 p sFree(tmpSpline);92 psMemCheckCorruption(1); 93 //memLeaks = psMemCheckLeaks(currentId,NULL,stderr);94 if (0 != memLeaks) { 95 psAbort(__func__,"Memory Leaks! (%d leaks)", memLeaks); 96 } 97 98 printFooter(stdout, 99 "psFunctions functions", 100 "psSpline1DAlloc() ",101 testStatus); 102 103 /****************************************************************************/ 104 /****************************************************************************/ 105 testStatus = true; 106 printPositiveTestHeader(stdout, 107 "psFunction functions", 108 "psSpline1DAlloc() ");109 110 tmpSpline = psSpline1DAlloc(N, 1, 1.0, -1.0);111 if (tmpSpline == NULL) { 112 printf("ERROR: Could not allocate psSpline1D data structure\n"); 113 testStatus = false; 114 } 115 if (tmpSpline->spline == NULL) { 116 printf("ERROR: Could not allocate psSpline1D->spline data structure\n"); 117 testStatus = false; 118 } 119 120 if (tmpSpline->n != N) { 121 printf("ERROR: spline->n set incorrectly (%d)\n", tmpSpline->n); 122 testStatus = false; 123 } 124 125 for (i=0;i<N;i++) { 126 if (tmpSpline->spline[i] == NULL) { 127 printf("ERROR: Could not allocate spline %d\n", i); 128 testStatus = false; 129 } 130 if ((tmpSpline->spline[i])->n != 2) {131 printf("ERROR: Spline created with order %d\n", (tmpSpline->spline[i])->n); 132 testStatus = false; 133 } 134 } 135 136 if (tmpSpline->domains == NULL) { 137 printf("ERROR: Could not allocate psSpline1D->domains data structure\n"); 138 testStatus = false; 139 } 140 141 for (i=0;i<N+1;i++) { 142 printf("psSpline1D->domains[%d] is %f\n", i, tmpSpline->domains[i]); 143 } 144 145 p sFree(tmpSpline);146 psMemCheckCorruption(1); 147 //memLeaks = psMemCheckLeaks(currentId,NULL,stderr);148 if (0 != memLeaks) { 149 psAbort(__func__,"Memory Leaks! (%d leaks)", memLeaks); 150 } 151 152 printFooter(stdout, 153 "psFunctions functions", 154 "psSpline1DAlloc() ",155 testStatus); 156 157 /****************************************************************************/ 158 /****************************************************************************/ 159 testStatus = true; 160 printPositiveTestHeader(stdout, 161 "psFunction functions", 162 "psSpline1DAlloc() ");163 164 tmpSpline = psSpline1DAlloc(N, 3, 1.0, 10.0);165 if (tmpSpline == NULL) { 166 printf("ERROR: Could not allocate psSpline1D data structure\n"); 167 testStatus = false; 168 } 169 if (tmpSpline->spline == NULL) { 170 printf("ERROR: Could not allocate psSpline1D->spline data structure\n"); 171 testStatus = false; 172 } 173 174 if (tmpSpline->n != N) { 175 printf("ERROR: spline->n set incorrectly (%d)\n", tmpSpline->n); 176 testStatus = false; 177 } 178 179 for (i=0;i<N;i++) { 180 if (tmpSpline->spline[i] == NULL) { 181 printf("ERROR: Could not allocate spline %d\n", i); 182 testStatus = false; 183 } 184 if ((tmpSpline->spline[i])->n != 4) {185 printf("ERROR: Spline created with order %d\n", (tmpSpline->spline[i])->n); 186 testStatus = false; 187 } 188 } 189 190 if (tmpSpline->domains == NULL) { 191 printf("ERROR: Could not allocate psSpline1D->domains data structure\n"); 192 testStatus = false; 193 } 194 195 for (i=0;i<N+1;i++) { 196 printf("psSpline1D->domains[%d] is %f\n", i, tmpSpline->domains[i]); 197 } 198 199 p sFree(tmpSpline);200 psMemCheckCorruption(1); 201 //memLeaks = psMemCheckLeaks(currentId,NULL,stderr);202 if (0 != memLeaks) { 203 psAbort(__func__,"Memory Leaks! (%d leaks)", memLeaks); 204 } 205 206 printFooter(stdout, 207 "psFunctions functions", 208 "psSpline1DAlloc() ",209 testStatus); 210 211 /****************************************************************************/ 212 /****************************************************************************/ 213 testStatus = true; 214 printPositiveTestHeader(stdout, 215 "psFunction functions", 216 "psSpline1DAlloc() ");217 218 tmpSpline = psSpline1DAlloc(N, 3, 1.0, 1.0);92 p_psSpline1DFree(tmpSpline); 93 psMemCheckCorruption(1); 94 memLeaks = psMemCheckLeaks(currentId,NULL,stderr); 95 if (0 != memLeaks) { 96 psAbort(__func__,"Memory Leaks! (%d leaks)", memLeaks); 97 } 98 99 printFooter(stdout, 100 "psFunctions functions", 101 "psSpline1DAlloc(): linear, min/max are equal", 102 testStatus); 103 104 /****************************************************************************/ 105 /****************************************************************************/ 106 testStatus = true; 107 printPositiveTestHeader(stdout, 108 "psFunction functions", 109 "psSpline1DAlloc(): linear, min > max."); 110 111 tmpSpline = psSpline1DAlloc(N, LINEAR, 1.0, -1.0); 112 if (tmpSpline == NULL) { 113 printf("ERROR: Could not allocate psSpline1D data structure\n"); 114 testStatus = false; 115 } 116 if (tmpSpline->spline == NULL) { 117 printf("ERROR: Could not allocate psSpline1D->spline data structure\n"); 118 testStatus = false; 119 } 120 121 if (tmpSpline->n != N) { 122 printf("ERROR: spline->n set incorrectly (%d)\n", tmpSpline->n); 123 testStatus = false; 124 } 125 126 for (i=0;i<N;i++) { 127 if (tmpSpline->spline[i] == NULL) { 128 printf("ERROR: Could not allocate spline %d\n", i); 129 testStatus = false; 130 } 131 if ((tmpSpline->spline[i])->n != LINEAR+1) { 132 printf("ERROR: Spline created with order %d\n", (tmpSpline->spline[i])->n); 133 testStatus = false; 134 } 135 } 136 137 if (tmpSpline->domains == NULL) { 138 printf("ERROR: Could not allocate psSpline1D->domains data structure\n"); 139 testStatus = false; 140 } 141 142 for (i=0;i<N+1;i++) { 143 printf("psSpline1D->domains[%d] is %f\n", i, tmpSpline->domains[i]); 144 } 145 146 p_psSpline1DFree(tmpSpline); 147 psMemCheckCorruption(1); 148 memLeaks = psMemCheckLeaks(currentId,NULL,stderr); 149 if (0 != memLeaks) { 150 psAbort(__func__,"Memory Leaks! (%d leaks)", memLeaks); 151 } 152 153 printFooter(stdout, 154 "psFunctions functions", 155 "psSpline1DAlloc(): linear, min > max.", 156 testStatus); 157 158 /****************************************************************************/ 159 /****************************************************************************/ 160 testStatus = true; 161 printPositiveTestHeader(stdout, 162 "psFunction functions", 163 "psSpline1DAlloc(), cubic, normal"); 164 165 tmpSpline = psSpline1DAlloc(N, CUBIC, 1.0, 10.0); 166 if (tmpSpline == NULL) { 167 printf("ERROR: Could not allocate psSpline1D data structure\n"); 168 testStatus = false; 169 } 170 if (tmpSpline->spline == NULL) { 171 printf("ERROR: Could not allocate psSpline1D->spline data structure\n"); 172 testStatus = false; 173 } 174 175 if (tmpSpline->n != N) { 176 printf("ERROR: spline->n set incorrectly (%d)\n", tmpSpline->n); 177 testStatus = false; 178 } 179 180 for (i=0;i<N;i++) { 181 if (tmpSpline->spline[i] == NULL) { 182 printf("ERROR: Could not allocate spline %d\n", i); 183 testStatus = false; 184 } 185 if ((tmpSpline->spline[i])->n != CUBIC+1) { 186 printf("ERROR: Spline created with order %d\n", (tmpSpline->spline[i])->n); 187 testStatus = false; 188 } 189 } 190 191 if (tmpSpline->domains == NULL) { 192 printf("ERROR: Could not allocate psSpline1D->domains data structure\n"); 193 testStatus = false; 194 } 195 196 for (i=0;i<N+1;i++) { 197 printf("psSpline1D->domains[%d] is %f\n", i, tmpSpline->domains[i]); 198 } 199 200 p_psSpline1DFree(tmpSpline); 201 psMemCheckCorruption(1); 202 memLeaks = psMemCheckLeaks(currentId,NULL,stderr); 203 if (0 != memLeaks) { 204 psAbort(__func__,"Memory Leaks! (%d leaks)", memLeaks); 205 } 206 207 printFooter(stdout, 208 "psFunctions functions", 209 "psSpline1DAlloc(): cubic, normal", 210 testStatus); 211 212 /****************************************************************************/ 213 /****************************************************************************/ 214 testStatus = true; 215 printPositiveTestHeader(stdout, 216 "psFunction functions", 217 "psSpline1DAlloc(): cubic, min/max are equal"); 218 219 tmpSpline = psSpline1DAlloc(N, CUBIC, 1.0, 1.0); 219 220 220 221 if (tmpSpline != NULL) { … … 223 224 } 224 225 225 p sFree(tmpSpline);226 psMemCheckCorruption(1); 227 //memLeaks = psMemCheckLeaks(currentId,NULL,stderr);228 if (0 != memLeaks) { 229 psAbort(__func__,"Memory Leaks! (%d leaks)", memLeaks); 230 } 231 232 printFooter(stdout, 233 "psFunctions functions", 234 "psSpline1DAlloc() ",235 testStatus); 236 237 /****************************************************************************/ 238 /****************************************************************************/ 239 testStatus = true; 240 printPositiveTestHeader(stdout, 241 "psFunction functions", 242 "psSpline1DAlloc() ");243 244 tmpSpline = psSpline1DAlloc(N, 3, 1.0, -1.0);245 if (tmpSpline == NULL) { 246 printf("ERROR: Could not allocate psSpline1D data structure\n"); 247 testStatus = false; 248 } 249 if (tmpSpline->spline == NULL) { 250 printf("ERROR: Could not allocate psSpline1D->spline data structure\n"); 251 testStatus = false; 252 } 253 254 if (tmpSpline->n != N) { 255 printf("ERROR: spline->n set incorrectly (%d)\n", tmpSpline->n); 256 testStatus = false; 257 } 258 259 for (i=0;i<N;i++) { 260 if (tmpSpline->spline[i] == NULL) { 261 printf("ERROR: Could not allocate spline %d\n", i); 262 testStatus = false; 263 } 264 if ((tmpSpline->spline[i])->n != 4) {265 printf("ERROR: Spline created with order %d\n", (tmpSpline->spline[i])->n); 266 testStatus = false; 267 } 268 } 269 270 if (tmpSpline->domains == NULL) { 271 printf("ERROR: Could not allocate psSpline1D->domains data structure\n"); 272 testStatus = false; 273 } 274 275 for (i=0;i<N+1;i++) { 276 printf("psSpline1D->domains[%d] is %f\n", i, tmpSpline->domains[i]); 277 } 278 279 p sFree(tmpSpline);280 psMemCheckCorruption(1); 281 //memLeaks = psMemCheckLeaks(currentId,NULL,stderr);282 if (0 != memLeaks) { 283 psAbort(__func__,"Memory Leaks! (%d leaks)", memLeaks); 284 } 285 286 printFooter(stdout, 287 "psFunctions functions", 288 "psSpline1DAlloc() ",226 p_psSpline1DFree(tmpSpline); 227 psMemCheckCorruption(1); 228 memLeaks = psMemCheckLeaks(currentId,NULL,stderr); 229 if (0 != memLeaks) { 230 psAbort(__func__,"Memory Leaks! (%d leaks)", memLeaks); 231 } 232 233 printFooter(stdout, 234 "psFunctions functions", 235 "psSpline1DAlloc(): cubic, min/max are equal", 236 testStatus); 237 238 /****************************************************************************/ 239 /****************************************************************************/ 240 testStatus = true; 241 printPositiveTestHeader(stdout, 242 "psFunction functions", 243 "psSpline1DAlloc(): cubic, min > max."); 244 245 tmpSpline = psSpline1DAlloc(N, CUBIC, 1.0, -1.0); 246 if (tmpSpline == NULL) { 247 printf("ERROR: Could not allocate psSpline1D data structure\n"); 248 testStatus = false; 249 } 250 if (tmpSpline->spline == NULL) { 251 printf("ERROR: Could not allocate psSpline1D->spline data structure\n"); 252 testStatus = false; 253 } 254 255 if (tmpSpline->n != N) { 256 printf("ERROR: spline->n set incorrectly (%d)\n", tmpSpline->n); 257 testStatus = false; 258 } 259 260 for (i=0;i<N;i++) { 261 if (tmpSpline->spline[i] == NULL) { 262 printf("ERROR: Could not allocate spline %d\n", i); 263 testStatus = false; 264 } 265 if ((tmpSpline->spline[i])->n != CUBIC+1) { 266 printf("ERROR: Spline created with order %d\n", (tmpSpline->spline[i])->n); 267 testStatus = false; 268 } 269 } 270 271 if (tmpSpline->domains == NULL) { 272 printf("ERROR: Could not allocate psSpline1D->domains data structure\n"); 273 testStatus = false; 274 } 275 276 for (i=0;i<N+1;i++) { 277 printf("psSpline1D->domains[%d] is %f\n", i, tmpSpline->domains[i]); 278 } 279 280 p_psSpline1DFree(tmpSpline); 281 psMemCheckCorruption(1); 282 memLeaks = psMemCheckLeaks(currentId,NULL,stderr); 283 if (0 != memLeaks) { 284 psAbort(__func__,"Memory Leaks! (%d leaks)", memLeaks); 285 } 286 287 printFooter(stdout, 288 "psFunctions functions", 289 "psSpline1DAlloc(): cubic, min > max.", 289 290 testStatus); 290 291
Note:
See TracChangeset
for help on using the changeset viewer.
