Index: /trunk/psLib/test/image/tst_psImage.c
===================================================================
--- /trunk/psLib/test/image/tst_psImage.c	(revision 843)
+++ /trunk/psLib/test/image/tst_psImage.c	(revision 844)
@@ -6,6 +6,6 @@
  *  @author Robert DeSonia, MHPCC
  *
- *  @version $Revision: 1.8 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2004-06-02 23:29:29 $
+ *  @version $Revision: 1.9 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2004-06-04 00:19:54 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -18,11 +18,14 @@
 #include "psTest.h"
 #include "pslib.h"
+#include "psType.h"
 
 static int testImageAlloc(void);
 static int testImageSubset(void);
+static int testImageCopy(void);
 
 testDescription tests[] = {
                               {testImageAlloc,"546/548-testImageAlloc/Free",0},
-                              {testImageSubset,"547/549-testImageSubset",0},
+                              {testImageSubset,"547/550-testImageSubset",0},
+                              {testImageCopy,"551-testImageCopy",0},
                               {NULL}
                           };
@@ -385,4 +388,5 @@
              "psImage structure is not modified.");
 
+    psLogMsg(__func__,PS_LOG_INFO,"An error should follow...");
     subset1 = psImageSubset(NULL,NULL,c/2,r/2,0,0);
     if (subset1 != NULL) {
@@ -396,4 +400,5 @@
 
     memcpy(&preSubsetStruct,original,sizeof(psImage));
+    psLogMsg(__func__,PS_LOG_INFO,"An error should follow...");
     subset1 = psImageSubset(NULL,original,c/2,0,0,0);
     if (subset1 != NULL) {
@@ -401,4 +406,5 @@
         return 15;
     }
+    psLogMsg(__func__,PS_LOG_INFO,"An error should follow...");
     subset1 = psImageSubset(NULL,original,0,r/2,0,0);
     if (subset1 != NULL) {
@@ -416,4 +422,5 @@
              "values of psImage structure image.");
 
+    psLogMsg(__func__,PS_LOG_INFO,"An error should follow...");
     subset1 = psImageSubset(NULL,original,c/2,r/2,c,0);
     if (subset1 != NULL) {
@@ -422,4 +429,5 @@
         return 18;
     }
+    psLogMsg(__func__,PS_LOG_INFO,"An error should follow...");
     subset1 = psImageSubset(NULL,original,c/2,r/2,0,r);
     if (subset1 != NULL) {
@@ -428,4 +436,5 @@
         return 19;
     }
+    psLogMsg(__func__,PS_LOG_INFO,"An error should follow...");
     subset1 = psImageSubset(NULL,original,c/2,r/2,-1,0);
     if (subset1 != NULL) {
@@ -434,4 +443,5 @@
         return 20;
     }
+    psLogMsg(__func__,PS_LOG_INFO,"An error should follow...");
     subset1 = psImageSubset(NULL,original,c/2,r/2,0,-1);
     if (subset1 != NULL) {
@@ -446,4 +456,5 @@
              "is not modified.");
 
+    psLogMsg(__func__,PS_LOG_INFO,"An error should follow...");
     subset1 = psImageSubset(NULL,original,c/2,r/2,c/2,0);
     if (subset1 != NULL) {
@@ -451,4 +462,5 @@
         return 22;
     }
+    psLogMsg(__func__,PS_LOG_INFO,"An error should follow...");
     subset1 = psImageSubset(NULL,original,c/2,r/2,0,r/2);
     if (subset1 != NULL) {
@@ -456,4 +468,5 @@
         return 23;
     }
+    psLogMsg(__func__,PS_LOG_INFO,"An error should follow...");
     subset1 = psImageSubset(NULL,original,c/2,r/2,c/2,r/2);
     if (subset1 != NULL) {
@@ -465,14 +478,35 @@
              "psImage structure");
 
+    memcpy(&preSubsetStruct,original,sizeof(psImage));
+
     psImageFreeChildren(original);
 
     // Verify the returned psImage structure member Nchildren is set to zero.
     if (original->nChildren != 0) {
-        psError(__func__,"psImageFreeChildren row+cols).");
+        psError(__func__,"psImageFreeChildren didn't set nChildren to zero.");
         return 25;
     }
 
+    // Verify the returned psImage structure member children pointer is set to null.
+    if (original->children != NULL) {
+        psError(__func__,"psImageFreeChildren didn't set children ptr to NULL.");
+        return 26;
+    }
+
+    //Verify the returned psImage structure members type, nrow, ncol, row0, col0, rows and parent are not
+    // modified.
+    if (preSubsetStruct.numRows != original->numRows ||
+            preSubsetStruct.numCols != original->numCols ||
+            preSubsetStruct.row0 != original->row0 ||
+            preSubsetStruct.col0 != original->col0) {
+
+        psError(__func__,"psImageFreeChildren modified parent's non-children elements.");
+        return 27;
+    }
 
     psImageFree(original);
+
+    // Verify no memory leaks or corruption are detected for a psImage structure
+    // Verify no memory leaks or corruption are detected for a psImage structure
     psMemCheckLeaks(currentId,NULL,NULL);
     psMemCheckCorruption(1);
@@ -480,2 +514,101 @@
     return 0;
 }
+
+int testImageCopy(void)
+{
+    psImage* img = NULL;
+    psImage* img2 = NULL;
+    psImage* img3 = NULL;
+    unsigned int c = 128;
+    unsigned int r = 256;
+    int currentId = psMemGetId();
+
+    img = psImageAlloc(c,r,PS_TYPE_F32);
+    for (unsigned row=0;row<r;row++) {
+        psF32* imgRow = img->data.F32[row];
+        for (unsigned col=0;col<c;col++) {
+            imgRow[col] = (psF32)(row+col);
+        }
+    }
+    img2 = psImageAlloc(c,r,PS_TYPE_F32);
+    for (unsigned row=0;row<r;row++) {
+        psF32* img2Row = img2->data.F32[row];
+        for (unsigned col=0;col<c;col++) {
+            img2Row[col] = 0.0f;
+        }
+    }
+
+    img3 = psImageCopy(img2,img,PS_TYPE_F32);
+
+    // Verify the returned psImage structure pointer is equal to the input parameter output.
+    if (img2 != img3) {
+        psError(__func__,"the image given for recycled wasn't");
+        return 1;
+    }
+
+    // Verify the returned psImage structure member are equal to the values in
+    // the input psImage structure input.
+    for (unsigned row=0;row<r;row++) {
+        psF32* imgRow = img->data.F32[row];
+        psF32* img2Row = img2->data.F32[row];
+        for (unsigned col=0;col<c;col++) {
+            if (imgRow[col] - (row+col) > FLT_EPSILON) {
+                psError(__func__,"Input image was changed at %d,%d (%f)!",
+                        col,row,imgRow[col]);
+                return 2;
+            }
+
+            if (imgRow[col] != img2Row[col]) {
+                psError(__func__,"returned psImage values after copy don't match!");
+                return 2;
+            }
+        }
+    }
+
+    // Verify the returned psImage structure pointer is null and program
+    // execution doesn't stop, if the input parameter input is null.
+    psLogMsg(__func__,PS_LOG_INFO,"An error should follow...");
+    img3 = psImageCopy(NULL,NULL,PS_TYPE_F32);
+    if (img3 != NULL) {
+        psError(__func__,"psImageCopy didn't return NULL when input image was NULL.");
+        return 3;
+    }
+
+    img2 = psImageCopy(img2,img,PS_TYPE_U8);
+    for (unsigned row=0;row<r;row++) {
+        psF32* imgRow = img->data.F32[row];
+        psU8* img2Row = img2->data.U8[row];
+        for (unsigned col=0;col<c;col++) {
+            if (imgRow[col] - (row+col) > FLT_EPSILON) {
+                psError(__func__,"Input image was changed at %d,%d (%f)!",
+                        col,row,imgRow[col]);
+                return 2;
+            }
+
+            if (row+col != img2Row[col]) {
+                psError(__func__,"returned psImage values after copy don't match at %d,%d (%d vs %d)",
+                        col,row,img2Row[col], row+col);
+                return 2;
+            }
+        }
+    }
+
+    img2 = psImageCopy(img2,img,PS_TYPE_U16);
+    img2 = psImageCopy(img2,img,PS_TYPE_U32);
+    img2 = psImageCopy(img2,img,PS_TYPE_S8);
+    img2 = psImageCopy(img2,img,PS_TYPE_S16);
+    img2 = psImageCopy(img2,img,PS_TYPE_S32);
+    img2 = psImageCopy(img2,img,PS_TYPE_F64);
+    img2 = psImageCopy(img2,img,PS_TYPE_C32);
+    img2 = psImageCopy(img2,img,PS_TYPE_C64);
+
+    psImageFree(img);
+    psImageFree(img2);
+
+    if (psMemCheckLeaks(currentId,NULL,NULL) != 0) {
+        psAbort(__func__,"Memory Leaks!");
+    }
+    psMemCheckCorruption(1);
+
+    return 0;
+}
