Index: /trunk/psLib/test/image/tst_psImage.c
===================================================================
--- /trunk/psLib/test/image/tst_psImage.c	(revision 694)
+++ /trunk/psLib/test/image/tst_psImage.c	(revision 694)
@@ -0,0 +1,222 @@
+/** @file  tst_psImage.c
+ *
+ *  @brief Contains the tests for psImage.[ch]
+ *
+ *
+ *  @author Robert DeSonia, MHPCC
+ *
+ *  @version $Revision: 1.1 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2004-05-15 00:16:31 $
+ *
+ *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
+ */
+
+
+
+#include "psTest.h"
+#include "psLib.h"
+
+#include <math.h>
+#include <float.h>
+
+static int testImageAlloc(void);
+
+testDescription tests[] = {
+                              {testImageAlloc,"546-testImageAlloc",0},
+                              {NULL}
+                          };
+
+int main()
+{
+    psSetLogLevel(PS_LOG_INFO);
+
+    testImageAlloc();
+
+    if (! runTestSuite(stderr,"psImage",tests)) {
+        psAbort(__FILE__,"One or more tests failed");
+    }
+    return 0;
+}
+
+int testImageAlloc(void)
+{
+
+    psImage* image = NULL;
+    unsigned int sizes = 6;
+    unsigned int numCols[] = {0,1,1,100,100,150};
+    unsigned int numRows[] = {0,1,100,1,150,100};
+    unsigned int types = 12;
+    psElemType type[] = { PS_TYPE_INT8, PS_TYPE_INT16, PS_TYPE_INT32, PS_TYPE_INT64,
+                          PS_TYPE_UINT8, PS_TYPE_UINT16, PS_TYPE_UINT32, PS_TYPE_UINT64,
+                          PS_TYPE_FLOAT, PS_TYPE_DOUBLE, PS_TYPE_COMPLEX_FLOAT, PS_TYPE_COMPLEX_DOUBLE };
+
+    psLogMsg(__func__,PS_LOG_INFO,"#546 - psImageAlloc shall allocate memory for a psImage structure");
+
+    for (unsigned int t=0;t<types;t++) {
+        psLogMsg(__func__,PS_LOG_INFO,"Testing psImage with type %xh",type[t]);
+
+        for (unsigned int i=0;i<sizes;i++) {
+
+            image = psImageAlloc(numCols[i],numRows[i],type[t]);
+
+            if (image == NULL) {
+                if (numRows[i] == 0 || numCols[i] == 0) {
+                    continue;
+                }
+                psError(__func__,"psImageAlloc returned NULL for type %x, size %dx%d.",
+                        type[t], numCols[i], numRows[i]);
+                psImageFree(image);
+                return 1;
+            }
+
+            if (image->type.dimen != PS_DIMEN_IMAGE || image->type.type != type[t]) {
+                psError(__func__,"psImageAlloc allocated wrong dimen/type (%d/%d), should be "
+                        "PS_IMAGE_DIMEN/%d", image->type.dimen, image->type.type, type[t]);
+                psImageFree(image);
+                return 2;
+            }
+
+            if (image->numCols != numCols[i] || image->numRows != numRows[i]) {
+                psError(__func__,"psImageAlloc allocated wrong size %dx%d, should be %dx%d (type = %d)",
+                        image->numCols, image->numRows, numCols[i], numRows[i],type[t]);
+                psImageFree(image);
+                return 3;
+            }
+
+            if (image->col0 != 0 || image->row0 != 0) {
+                psError(__func__,"psImageAlloc returned row0/col0 of %d/%d.  Should be 0/0.",
+                        image->row0, image->row0);
+                psImageFree(image);
+                return 4;
+            }
+
+            if (image->parent != NULL) {
+                psError(__func__,"psImageAlloc returned non-NULL parent");
+                psImageFree(image);
+                return 5;
+            }
+
+            if (image->nChildren != 0) {
+                psError(__func__,"psImageAlloc returned non-zero number of children");
+                psImageFree(image);
+                return 6;
+            }
+
+            if (image->children != NULL) {
+                psError(__func__,"psImageAlloc returned non-NULL children vector");
+                psImageFree(image);
+                return 7;
+            }
+
+            switch (type[t]) {
+            case PS_TYPE_UINT16: {
+                    unsigned int rows = numRows[i];
+                    unsigned int cols = numCols[i];
+
+                    for (int r=0;r<rows;r++) {
+                        for (int c=0;c<cols;c++) {
+                            image->data.ui16[r][c] = 2*c+r;
+                        }
+                    }
+                    for (int r=0;r<rows;r++) {
+                        for (int c=0;c<cols;c++) {
+                            if (image->data.ui16[r][c] != 2*c+r) {
+                                psError(__func__,"Could not set all pixels in uint16 image at (%d,%d)",c,r);
+                                psImageFree(image);
+                                return 8;
+                            }
+                        }
+                    }
+                }
+                break;
+            case PS_TYPE_FLOAT: {
+                    unsigned int rows = numRows[i];
+                    unsigned int cols = numCols[i];
+
+                    for (int r=0;r<rows;r++) {
+                        for (int c=0;c<cols;c++) {
+                            image->data.f32[r][c] = 2.0f*c+r;
+                        }
+                    }
+                    for (int r=0;r<rows;r++) {
+                        for (int c=0;c<cols;c++) {
+                            if (fabsf(image->data.f32[r][c] - (2.0f*c+r)) > FLT_EPSILON) {
+                                psError(__func__,"Could not set all pixels in float image at (%d,%d)",c,r);
+                                psImageFree(image);
+                                return 8;
+                            }
+                        }
+                    }
+                }
+                break;
+            case PS_TYPE_DOUBLE: {
+                    unsigned int rows = numRows[i];
+                    unsigned int cols = numCols[i];
+
+                    for (int r=0;r<rows;r++) {
+                        for (int c=0;c<cols;c++) {
+                            image->data.f64[r][c] = 2.0f*c+r;
+                        }
+                    }
+                    for (int r=0;r<rows;r++) {
+                        for (int c=0;c<cols;c++) {
+                            if (fabs(image->data.f64[r][c] - (2.0f*c+r)) > DBL_EPSILON) {
+                                psError(__func__,"Could not set all pixels in double image at (%d,%d)",c,r);
+                                psImageFree(image);
+                                return 8;
+                            }
+                        }
+                    }
+                }
+                break;
+            case PS_TYPE_COMPLEX_FLOAT: {
+                    unsigned int rows = numRows[i];
+                    unsigned int cols = numCols[i];
+
+                    for (int r=0;r<rows;r++) {
+                        for (int c=0;c<cols;c++) {
+                            image->data.c32[r][c] = r + I * c;
+                        }
+                    }
+                    for (int r=0;r<rows;r++) {
+                        for (int c=0;c<cols;c++) {
+                            if (fabsf(crealf(image->data.c32[r][c]) - r) > FLT_EPSILON ||
+                                    fabsf(cimagf(image->data.c32[r][c]) - c) > FLT_EPSILON ) {
+                                psError(__func__,"Could not set all pixels in complex image at (%d,%d)",c,r);
+                                psImageFree(image);
+                                return 8;
+                            }
+                        }
+                    }
+                }
+                break;
+            default: {
+                    // ignore type and just use as byte bucket.
+                    unsigned int rows = numRows[i];
+                    unsigned int cols = numCols[i]*PSELEMTYPE_SIZEOF(type[t]);
+
+                    for (int r=0;r<rows;r++) {
+                        for (int c=0;c<cols;c++) {
+                            image->data.ui8[r][c] = (uint8_t)(r + c);
+                        }
+                    }
+                    for (int r=0;r<rows;r++) {
+                        for (int c=0;c<cols;c++) {
+                            if (image->data.ui8[r][c] != (uint8_t)(r + c)) {
+                                psError(__func__,"Could not set all pixels in image (type=%d) at (%d,%d)",
+                                        type[t],c,r);
+                                psImageFree(image);
+                                return 8;
+                            }
+                        }
+                    }
+                }
+            }
+
+            psImageFree(image);
+        }
+    }
+
+    return 0;
+}
+
