Index: trunk/psLib/test/imageops/tap_psImageStructManip.c
===================================================================
--- trunk/psLib/test/imageops/tap_psImageStructManip.c	(revision 13123)
+++ trunk/psLib/test/imageops/tap_psImageStructManip.c	(revision 13614)
@@ -5,6 +5,11 @@
 *  @author Robert DeSonia, MHPCC
 *
-*  @version $Revision: 1.3 $ $Name: not supported by cvs2svn $
-*  @date $Date: 2007-05-02 04:14:33 $
+*  psLib functions tested:
+*     psImageSubset()
+*     psImageCopy()
+*     psImageTrim()
+*
+*  @version $Revision: 1.4 $ $Name: not supported by cvs2svn $
+*  @date $Date: 2007-06-04 20:25:32 $
 *
 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -16,11 +21,7 @@
 #include "pstap.h"
 
-psS32 main( psS32 argc, char* argv[] )
+
+void genericImageSubsetTest(int numRows, int numCols)
 {
-    psLogSetFormat("HLNM");
-    psLogSetLevel(PS_LOG_INFO);
-    plan_tests(185);
-
-
     // psImageSubset shall create child image of a specified size from a
     // parent psImage structure
@@ -29,21 +30,19 @@
         psMemId id = psMemGetId();
         psImage preSubsetStruct;
-        psS32 c = 128;
-        psS32 r = 256;
-        psRegion region1 = psRegionSet(0, c/2, 0, r/2);
-        psRegion region2 = psRegionSet(c/4, c/4+c/2, r/4, r/4+r/2);
-
-        psImage* original = psImageAlloc(c,r,PS_TYPE_U32);
-        for (psS32 row=0;row<r;row++) {
-            for (psS32 col=0;col<c;col++) {
+        psRegion region1 = psRegionSet(0, numCols/2, 0, numRows/2);
+        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);
+        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);
+        psImage* subset3 = psImageSubset(original, region1);
         ok(subset3, "psImageSubset() returned non-NULL (subset3)");
         skip_start(subset3 == NULL, 24, "Skipping tests because psImageSubset() returned NULL");
@@ -51,18 +50,17 @@
         // Verify the returned psImage structure members nrow and ncol are equal to
         // the input parameter nrow and ncol respectively
-        ok(subset2->numCols == c/2 && subset2->numRows == r/2,
+        ok(subset2->numCols == numCols/2 && subset2->numRows == numRows/2,
            "psImageSubset output size set properly");
-        ok(subset3->numCols == c/2 && subset3->numRows == r/2,
+        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<r/2;row++) {
-            for (psS32 col=0;col<c/2;col++) {
-                if (subset2->data.U32[row][col] != original->data.U32[row+r/4][col+c/4]) {
+        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+r/4][col+c/4]);
+                         row,col,subset2->data.U32[row][col], original->data.U32[row+numRows/4][col+numCols/4]);
                     errorFlag = true;
                 }
@@ -83,5 +81,5 @@
         // Verify the returned psImage structure members row0 and col0 are equal to
         // the input parameters row0 and col0 respectively
-        ok(subset2->col0 == c/4 && subset2->row0 == r/4,
+        ok(subset2->col0 == numCols/4 && subset2->row0 == numRows/4,
            "psImageSubset() set col0/row0 correctly (subset2)");
         ok(subset3->col0 == 0 && subset3->row0 == 0,
@@ -101,5 +99,4 @@
         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
@@ -111,5 +108,4 @@
         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.
@@ -117,13 +113,15 @@
         // An error should follow...
         // XXX: Verify error
-        memcpy(&preSubsetStruct,original,sizeof(psImage));
-        subset1 = psImageSubset(original, psRegionSet(0,c/2,r/2,r/2));
-        ok(subset1 == NULL, "psImageSubset returned NULL when numRows=0.");
-        // An error should follow...
-        // XXX: Verify error
-        subset1 = psImageSubset(original,psRegionSet(c/2,c/2,0,r/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.");
+        {
+            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
@@ -132,23 +130,24 @@
         // An error should follow...
         // XXX: Verify error
-        subset1 = psImageSubset(original, psRegionSet(0,c/2, 0,r*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,c*2,0,r/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,c/2,0,r/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,c/2,-1,r/2));
-        ok(subset1 == NULL,
-           "psImageSubset returned NULL when subset origin was outside of image (row0=-1)");
-
+        {
+            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
@@ -158,18 +157,19 @@
         // An error should follow...
         // XXX: Verify error
-        subset1 = psImageSubset(original,psRegionSet(0,c/2,0,r+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,c+1,0,r/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,c+1,0,r+1));
-        ok(subset1 == NULL,
-           "psImageSubset returned NULL when subset was outside of image (via row+cols)");
-
+        {
+            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
@@ -196,4 +196,15 @@
         ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
     }
+}
+
+psS32 main(psS32 argc, char* argv[])
+{
+    psLogSetFormat("HLNM");
+    psLogSetLevel(PS_LOG_INFO);
+    plan_tests(239);
+
+    genericImageSubsetTest(128, 256);
+    genericImageSubsetTest(256, 128);
+    genericImageSubsetTest(128, 128);
 
     // psImageCopy()
