Index: trunk/psLib/test/imageops/tap_psImageStructManip.c
===================================================================
--- trunk/psLib/test/imageops/tap_psImageStructManip.c	(revision 13614)
+++ trunk/psLib/test/imageops/tap_psImageStructManip.c	(revision 14926)
@@ -10,6 +10,6 @@
 *     psImageTrim()
 *
-*  @version $Revision: 1.4 $ $Name: not supported by cvs2svn $
-*  @date $Date: 2007-06-04 20:25:32 $
+*  @version $Revision: 1.5 $ $Name: not supported by cvs2svn $
+*  @date $Date: 2007-09-20 23:56:10 $
 *
 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -33,166 +33,188 @@
         psRegion region2 = psRegionSet(numCols/4, numCols/4+numCols/2, numRows/4, numRows/4+numRows/2);
 
-        psImage* original = psImageAlloc(numCols,numRows,PS_TYPE_U32);
-        for (psS32 row=0;row<numRows;row++) {
-            for (psS32 col=0;col<numCols;col++) {
-                original->data.F32[row][col] = row*1000+col;
-            }
-        }
-
-        memcpy(&preSubsetStruct, original, sizeof(psImage));
-        psImage* subset2 = psImageSubset(original, region2);
-        ok(subset2, "psImageSubset() returned non-NULL (subset2)");
-        skip_start(subset2 == NULL, 25, "Skipping tests because psImageSubset() returned NULL");
-        psImage* subset3 = psImageSubset(original, region1);
-        ok(subset3, "psImageSubset() returned non-NULL (subset3)");
-        skip_start(subset3 == NULL, 24, "Skipping tests because psImageSubset() returned NULL");
-
-        // Verify the returned psImage structure members nrow and ncol are equal to
-        // the input parameter nrow and ncol respectively
-        ok(subset2->numCols == numCols/2 && subset2->numRows == numRows/2,
-           "psImageSubset output size set properly");
-        ok(subset3->numCols == numCols/2 && subset3->numRows == numRows/2,
-           "psImageSubset output size set properly");
-
-        // Verify the returned psImage structure contains expected values in the
-        // row member, if the input psImage structure image contains known values
-        bool errorFlag = false;
-        for (psS32 row=0;row<numRows/2;row++) {
-            for (psS32 col=0;col<numCols/2;col++) {
-                if (subset2->data.U32[row][col] != original->data.U32[row+numRows/4][col+numCols/4]) {
-                    diag("psImageSubset output #1 was wrong at %dx%d (%d vs %d).",
-                         row,col,subset2->data.U32[row][col], original->data.U32[row+numRows/4][col+numCols/4]);
-                    errorFlag = true;
-                }
-                if (subset3->data.U32[row][col] != original->data.U32[row][col]) {
-                    diag("psImageSubset output #1 was wrong at %dx%d (%d vs %d).",
-                         row,col,subset2->data.U32[row][col], original->data.U32[row][col]);
-                    errorFlag = true;
-                }
-            }
-        }
-        ok(!errorFlag, "psImageSubset() produced the expected values");
-
-        // Verify the returned psImage structure member type is equal to the input
-        // psImage structure member type
-        ok(subset2->type.type == PS_TYPE_U32, "psImageSubset() type was correct (subset2)");
-        ok(subset3->type.type == PS_TYPE_U32, "psImageSubset() type was correct (subset3)");
-
-        // Verify the returned psImage structure members row0 and col0 are equal to
-        // the input parameters row0 and col0 respectively
-        ok(subset2->col0 == numCols/4 && subset2->row0 == numRows/4,
-           "psImageSubset() set col0/row0 correctly (subset2)");
-        ok(subset3->col0 == 0 && subset3->row0 == 0,
-           "psImageSubset() set col0/row0 correctly (subset3)");
-
-        // Verify the returned psImage structure member parent is equal to the
-        // input psImage structure pointer image
-        ok(subset2->parent == original && subset3->parent == original, "psImageSubset() set ->parent correctly");
-
-        // Verify the returned psImage structure member children is null
-        ok(subset2->children == NULL && subset3->children == NULL, "psImageSubset() set ->children correctly");
-
-        // Verify the input psImage structure image only has the following members
-        // changed: 1) Nchildren is increased by one. 2) parent contains pointer psImage structure
-        // out at parent[Nchildren-1]
-        ok(original->children != NULL && original->children->n == 2, "psImageSubset did increment number of children by one per subset.");
-        ok(original->children->data[0] == subset2 && original->children->data[1] == subset3,
-           "psImageSubset did properly store the children pointers.");
-
-        // Verify the returned psImage structure pointer is null and program
-        // execution doesn't stop, if the input parameter image is null.
-        // Also verified the input psImage structure is not modified
-        // An error should follow...
-        // XXX: Verify error
-        psImage* subset1 = psImageSubset(NULL,region1);
-        ok(subset1 == NULL, "psImageSubset returned NULL when input image was NULL.");
-
-        // Verify the returned psImage structure pointer is null and program
-        // execution doesn't stop, if the input parameters nrow and/or ncol are zero.
-        // Also verify input psImage structure is not modified
-        // An error should follow...
-        // XXX: Verify error
-        {
-            memcpy(&preSubsetStruct,original,sizeof(psImage));
-            subset1 = psImageSubset(original, psRegionSet(0,numCols/2,numRows/2,numRows/2));
-            ok(subset1 == NULL, "psImageSubset returned NULL when numRows=0.");
-            // An error should follow...
-            // XXX: Verify error
-            subset1 = psImageSubset(original,psRegionSet(numCols/2,numCols/2,0,numRows/2));
-            ok(subset1 == NULL, "psImageSubset returned NULL when numCols=0.");
-            ok(memcmp(original,&preSubsetStruct,sizeof(psImage)) == 0,
-               "psImageSubset didn't change the original struct though it failed to subset.");
-        }
-
-        // Verify the returned psImage structure pointer is null and program
-        // execution doesn't stop, if the input parameters row0 and col0 are not within
-        // the range of values of psImage structure image
-        // An error should follow...
-        // XXX: Verify error
-        {
-            subset1 = psImageSubset(original, psRegionSet(0,numCols/2, 0,numRows*2));
-            ok(subset1 == NULL,
-               "psImageSubset returned NULL when subset origin was outside of image (via cols)");
-            // An error should follow...
-            // XXX: Verify error
-            subset1 = psImageSubset(original,psRegionSet(0,numCols*2,0,numRows/2));
-            ok(subset1 == NULL,
-               "psImageSubset returned NULL when subset origin was outside of image (via rows)");
-            // An error should follow...
-            // XXX: Verify error
-            subset1 = psImageSubset(original, psRegionSet(-1,numCols/2,0,numRows/2));
-            ok(subset1 == NULL,
-               "psImageSubset returned NULL when subset origin was outside of image (col0=-1)");
-            // An error should follow...
-            // XXX: Verify error
-            subset1 = psImageSubset(original, psRegionSet(0,numCols/2,-1,numRows/2));
-            ok(subset1 == NULL,
-               "psImageSubset returned NULL when subset origin was outside of image (row0=-1)");
-        }    
-
-        // Verify the returned psImage structure pointer is null and program
-        // execution doesn't stop if the input parameters nrow, ncol, row0 and col0
-        // specify a range of data not within the input psImage structure image.  Also
-        // verify the input psImage structure is not modified
-        // An error should follow...
-        // XXX: Verify error
-        {
-            subset1 = psImageSubset(original,psRegionSet(0,numCols/2,0,numRows+1));
-            ok(subset1 == NULL,
-               "psImageSubset returned NULL when subset was outside of image (via rows)");
-            // An error should follow...
-            // XXX: Verify error
-            subset1 = psImageSubset(original, psRegionSet(0,numCols+1,0,numRows/2));
-            ok(subset1 == NULL,
-               "psImageSubset returned NULL when subset was outside of image (via cols)");
-            // An error should follow...
-            // XXX: Verify error
-            subset1 = psImageSubset(original,psRegionSet(0,numCols+1,0,numRows+1));
-            ok(subset1 == NULL,
-               "psImageSubset returned NULL when subset was outside of image (via row+cols)");
-        }
-
-        // psImageFreeChildren shall deallocate any children images of a
-        // psImage structure
-        memcpy(&preSubsetStruct,original,sizeof(psImage));
-        psImageFreeChildren(original);
-
-        // Verify the returned psImage structure member Nchildren is set to zero.
-        // XXX: This doesn't make sense.
-        ok(original->children == NULL || original->children->n == 0,
-           "psImageFreeChildren didn't set children to NULL");
-
-        //Verify the returned psImage structure members type, nrow, ncol, row0, col0, rows
-        // and parent are not modified.
-        ok(preSubsetStruct.numRows == original->numRows &&
-           preSubsetStruct.numCols == original->numCols &&
-           preSubsetStruct.row0 == original->row0 &&
-           preSubsetStruct.col0 == original->col0,
-           "psImageFreeChildren modified parent's non-children elements");
-
-        skip_end();
-        skip_end();
-        psFree(original);
-        ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
+	// test basic subset creation 
+	{ 
+	    psImage* original = psImageAlloc(numCols,numRows,PS_TYPE_U32);
+	    for (psS32 row=0;row<numRows;row++) {
+		for (psS32 col=0;col<numCols;col++) {
+		    original->data.F32[row][col] = row*1000+col;
+		}
+	    }
+
+	    // XXX this is not being used in this section
+	    memcpy(&preSubsetStruct, original, sizeof(psImage));
+	    psImage* subset1 = psImageSubset(original, region2);
+	    ok(subset1, "psImageSubset() returned non-NULL (subset1)");
+	    skip_start(subset1 == NULL, 25, "Skipping tests because psImageSubset() returned NULL");
+	    psImage* subset2 = psImageSubset(original, region1);
+	    ok(subset2, "psImageSubset() returned non-NULL (subset2)");
+	    skip_start(subset2 == NULL, 24, "Skipping tests because psImageSubset() returned NULL");
+
+	    // Verify the returned psImage structure members nrow and ncol are equal to
+	    // the input parameter nrow and ncol respectively
+	    ok(subset1->numCols == numCols/2 && subset1->numRows == numRows/2,
+	       "psImageSubset output size set properly");
+	    ok(subset2->numCols == numCols/2 && subset2->numRows == numRows/2,
+	       "psImageSubset output size set properly");
+
+	    // Verify the returned psImage structure contains expected values in the
+	    // row member, if the input psImage structure image contains known values
+	    bool errorFlag = false;
+	    for (psS32 row=0;row<numRows/2;row++) {
+		for (psS32 col=0;col<numCols/2;col++) {
+		    if (subset1->data.U32[row][col] != original->data.U32[row+numRows/4][col+numCols/4]) {
+			diag("psImageSubset output #1 was wrong at %dx%d (%d vs %d).",
+			     row,col,subset1->data.U32[row][col], original->data.U32[row+numRows/4][col+numCols/4]);
+			errorFlag = true;
+		    }
+		    if (subset2->data.U32[row][col] != original->data.U32[row][col]) {
+			diag("psImageSubset output #1 was wrong at %dx%d (%d vs %d).",
+			     row,col,subset1->data.U32[row][col], original->data.U32[row][col]);
+			errorFlag = true;
+		    }
+		}
+	    }
+	    ok(!errorFlag, "psImageSubset() produced the expected values");
+
+	    // Verify the returned psImage structure member type is equal to the input
+	    // psImage structure member type
+	    ok(subset1->type.type == PS_TYPE_U32, "psImageSubset() type was correct (subset1)");
+	    ok(subset2->type.type == PS_TYPE_U32, "psImageSubset() type was correct (subset2)");
+
+	    // Verify the returned psImage structure members row0 and col0 are equal to
+	    // the input parameters row0 and col0 respectively
+	    ok(subset1->col0 == numCols/4 && subset1->row0 == numRows/4,
+	       "psImageSubset() set col0/row0 correctly (subset1)");
+	    ok(subset2->col0 == 0 && subset2->row0 == 0,
+	       "psImageSubset() set col0/row0 correctly (subset2)");
+
+	    // Verify the returned psImage structure member parent is equal to the
+	    // input psImage structure pointer image
+	    ok(subset1->parent == original && subset2->parent == original, "psImageSubset() set ->parent correctly");
+
+	    // Verify the returned psImage structure member children is null
+	    ok(subset1->children == NULL && subset2->children == NULL, "psImageSubset() set ->children correctly");
+
+	    // Verify the input psImage structure image only has the following members
+	    // changed: 1) Nchildren is increased by one. 2) parent contains pointer psImage structure
+	    // out at parent[Nchildren-1]
+	    ok(original->children != NULL && original->children->n == 2, "psImageSubset did increment number of children by one per subset.");
+	    ok(original->children->data[0] == subset1 && original->children->data[1] == subset2,
+	       "psImageSubset did properly store the children pointers.");
+
+	    psFree (subset1);
+	    psFree (subset2);
+	    skip_end();
+	    skip_end();
+	    psFree (original);
+	}
+
+	// test free in reverse order from above
+	{ 
+	    psImage* original = psImageAlloc(numCols,numRows,PS_TYPE_U32);
+	    for (psS32 row=0;row<numRows;row++) {
+		for (psS32 col=0;col<numCols;col++) {
+		    original->data.F32[row][col] = row*1000+col;
+		}
+	    }
+
+	    // XXX this is not being used in this section
+	    memcpy(&preSubsetStruct, original, sizeof(psImage));
+	    psImage* subset1 = psImageSubset(original, region2);
+	    ok(subset1, "psImageSubset() returned non-NULL (subset1)");
+	    psImage* subset2 = psImageSubset(original, region1);
+	    ok(subset2, "psImageSubset() returned non-NULL (subset2)");
+
+	    psFree (original);
+	    psFree (subset1);
+	    psFree (subset2);
+	}
+
+	{
+	    psImage* original = psImageAlloc(numCols,numRows,PS_TYPE_U32);
+	    for (psS32 row=0;row<numRows;row++) {
+		for (psS32 col=0;col<numCols;col++) {
+		    original->data.F32[row][col] = row*1000+col;
+		}
+	    }
+
+	    // XXX this is not being used in this section
+	    memcpy(&preSubsetStruct, original, sizeof(psImage));
+
+	    // Verify the returned psImage structure pointer is null and program
+	    // execution doesn't stop, if the input parameter image is null.
+	    // Also verified the input psImage structure is not modified
+	    // An error should follow...
+	    // XXX: Verify error
+	    psImage* subset1 = psImageSubset(NULL,region1);
+	    ok(subset1 == NULL, "psImageSubset returned NULL when input image was NULL.");
+
+	    // Verify the returned psImage structure pointer is null and program
+	    // execution doesn't stop, if the input parameters nrow and/or ncol are zero.
+	    // Also verify input psImage structure is not modified
+	    // An error should follow...
+	    // XXX: Verify error
+	    {
+		memcpy(&preSubsetStruct,original,sizeof(psImage));
+		subset1 = psImageSubset(original, psRegionSet(0,numCols/2,numRows/2,numRows/2));
+		ok(subset1 == NULL, "psImageSubset returned NULL when numRows=0.");
+		// An error should follow...
+		// XXX: Verify error
+		subset1 = psImageSubset(original,psRegionSet(numCols/2,numCols/2,0,numRows/2));
+		ok(subset1 == NULL, "psImageSubset returned NULL when numCols=0.");
+		ok(memcmp(original,&preSubsetStruct,sizeof(psImage)) == 0,
+		   "psImageSubset didn't change the original struct though it failed to subset.");
+	    }
+
+	    // Verify the returned psImage structure pointer is null and program
+	    // execution doesn't stop, if the input parameters row0 and col0 are not within
+	    // the range of values of psImage structure image
+	    // An error should follow...
+	    // XXX: Verify error
+	    {
+		subset1 = psImageSubset(original, psRegionSet(0,numCols/2, 0,numRows*2));
+		ok(subset1 == NULL,
+		   "psImageSubset returned NULL when subset origin was outside of image (via cols)");
+		// An error should follow...
+		// XXX: Verify error
+		subset1 = psImageSubset(original,psRegionSet(0,numCols*2,0,numRows/2));
+		ok(subset1 == NULL,
+		   "psImageSubset returned NULL when subset origin was outside of image (via rows)");
+		// An error should follow...
+		// XXX: Verify error
+		subset1 = psImageSubset(original, psRegionSet(-1,numCols/2,0,numRows/2));
+		ok(subset1 == NULL,
+		   "psImageSubset returned NULL when subset origin was outside of image (col0=-1)");
+		// An error should follow...
+		// XXX: Verify error
+		subset1 = psImageSubset(original, psRegionSet(0,numCols/2,-1,numRows/2));
+		ok(subset1 == NULL,
+		   "psImageSubset returned NULL when subset origin was outside of image (row0=-1)");
+	    }    
+
+	    // Verify the returned psImage structure pointer is null and program
+	    // execution doesn't stop if the input parameters nrow, ncol, row0 and col0
+	    // specify a range of data not within the input psImage structure image.  Also
+	    // verify the input psImage structure is not modified
+	    // An error should follow...
+	    // XXX: Verify error
+	    {
+		subset1 = psImageSubset(original,psRegionSet(0,numCols/2,0,numRows+1));
+		ok(subset1 == NULL,
+		   "psImageSubset returned NULL when subset was outside of image (via rows)");
+		// An error should follow...
+		// XXX: Verify error
+		subset1 = psImageSubset(original, psRegionSet(0,numCols+1,0,numRows/2));
+		ok(subset1 == NULL,
+		   "psImageSubset returned NULL when subset was outside of image (via cols)");
+		// An error should follow...
+		// XXX: Verify error
+		subset1 = psImageSubset(original,psRegionSet(0,numCols+1,0,numRows+1));
+		ok(subset1 == NULL,
+		   "psImageSubset returned NULL when subset was outside of image (via row+cols)");
+	    }
+	    psFree(original);
+	}
+        ok(!psMemCheckLeaks (id, NULL, stderr, false), "no memory leaks");
     }
 }
