Index: trunk/psModules/test/tst_pmNonLinear.c
===================================================================
--- trunk/psModules/test/tst_pmNonLinear.c	(revision 2857)
+++ trunk/psModules/test/tst_pmNonLinear.c	(revision 2915)
@@ -11,8 +11,11 @@
  * N), (N, 1), (N, N)].  
  *
+ * test02, test03: This code tests the functions with various unallowable
+ * input parameters (NULLS) and incorrect vector sizes.
+ *
  *  @author GLG, MHPCC
  *
- *  @version $Revision: 1.9 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2004-12-30 22:22:00 $
+ *  @version $Revision: 1.10 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2005-01-05 23:25:25 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -24,7 +27,11 @@
 static int test00(void);
 static int test01(void);
+static int test02(void);
+static int test03(void);
 testDescription tests[] = {
-                              {test00, 000, "pmNonLinearityPolynomial", 0, false},
-                              {test01, 000, "pmNonLinearityLookup", 0, false},
+                              {test00, 000, "pmNonLinearityPolynomial", true, false},
+                              {test01, 000, "pmNonLinearityLookup", true, false},
+                              {test02, 000, "pmNonLinearityPolynomial(): error/warning conditions", true, false},
+                              {test03, 000, "pmNonLinearityLookup(): error/warning conditions", true, false},
                               {NULL}
                           };
@@ -44,7 +51,6 @@
     float actual;
     float expect;
-    int testStatus = 0;
+    int testStatus = true;
     psImage *myImage = psImageAlloc(numCols, numRows, PS_TYPE_F32);
-    //    psReadout *myReadout = psReadoutAlloc(numCols, numRows, myImage);
     psReadout *myReadout = psReadoutAlloc();
     myReadout->image = myImage;
@@ -64,6 +70,6 @@
             actual = myReadout->image->data.F32[i][j];
             if (FLT_EPSILON < fabs(expect - actual)) {
-                printf("ERROR: image[%d][%d] is %f, should be %f\n", i, j, actual, expect);
-                testStatus = 1;
+                printf("TEST ERROR: image[%d][%d] is %f, should be %f\n", i, j, actual, expect);
+                testStatus = false;
             }
         }
@@ -94,8 +100,7 @@
     float actual;
     float expect;
-    int testStatus = 0;
+    int testStatus = true;
     int tableSize = PS_MAX(numCols, numRows)*2;
     psImage *myImage = psImageAlloc(numCols, numRows, PS_TYPE_F32);
-    //    psReadout *myReadout = psReadoutAlloc(numCols, numRows, myImage);
     psReadout *myReadout = psReadoutAlloc();
     myReadout->image = myImage;
@@ -120,6 +125,6 @@
             actual = myReadout->image->data.F32[i][j];
             if (FLT_EPSILON < fabs(expect - actual)) {
-                printf("ERROR: image[%d][%d] is %f, should be %f\n", i, j, actual, expect);
-                testStatus = 1;
+                printf("TEST ERROR: image[%d][%d] is %f, should be %f\n", i, j, actual, expect);
+                testStatus = false;
             }
         }
@@ -144,2 +149,231 @@
     return(testStatus);
 }
+
+int test02( void )
+{
+    int i;
+    int j;
+    int testStatus = true;
+    psImage *myImage = psImageAlloc(NUM_COLS, NUM_ROWS, PS_TYPE_F32);
+    psReadout *myReadout = psReadoutAlloc();
+    psReadout *rc = NULL;
+    myReadout->image = myImage;
+    psPolynomial1D *myPoly = psPolynomial1DAlloc(2, PS_POLYNOMIAL_ORD);
+    myPoly->coeff[1] = 1.0;
+
+    for (i=0;i<NUM_ROWS;i++) {
+        for (j=0;j<NUM_COLS;j++) {
+            myReadout->image->data.F32[i][j] = (float) (i + j);
+        }
+    }
+
+    printf("------------------------------------------------------------\n");
+    printf("Calling pmNonLinearityPolynomial() with NULL input readout.  Should generate error, return NULL.\n");
+    rc = pmNonLinearityPolynomial(NULL, myPoly);
+    if (rc != NULL) {
+        printf("TEST ERROR: pmNonLinearityPolynomial() returned a non-NULL psReadout\n");
+        testStatus = false;
+    }
+
+    printf("------------------------------------------------------------\n");
+    printf("Calling pmNonLinearityPolynomial() with NULL input readout->image.  Should generate error, return NULL.\n");
+    psImage *tmpImage = myReadout->image;
+    myReadout->image = NULL;
+    rc = pmNonLinearityPolynomial(myReadout, myPoly);
+    if (rc != NULL) {
+        printf("TEST ERROR: pmNonLinearityPolynomial() returned a non-NULL psReadout\n");
+        testStatus = false;
+    }
+    myReadout->image = tmpImage;
+
+    printf("------------------------------------------------------------\n");
+    printf("Calling pmNonLinearityPolynomial() with NULL polynomial.  Should generate error, return NULL.\n");
+    rc = pmNonLinearityPolynomial(myReadout, NULL);
+    if (rc != NULL) {
+        printf("TEST ERROR: pmNonLinearityPolynomial() returned a non-NULL psReadout\n");
+        testStatus = false;
+    }
+
+    psFree(myReadout);
+    psFree(myPoly);
+    return(testStatus);
+}
+
+
+int test03Init(psReadout *myReadout)
+{
+    for (psS32 i=0;i<NUM_ROWS;i++) {
+        for (psS32 j=0;j<NUM_COLS;j++) {
+            myReadout->image->data.F32[i][j] = (float) (i + j);
+        }
+    }
+    return(0);
+}
+
+int test03()
+{
+    int i;
+    int j;
+    int testStatus = true;
+    int tableSize = PS_MAX(NUM_COLS, NUM_ROWS)*3;
+    psImage *myImage = psImageAlloc(NUM_COLS, NUM_ROWS, PS_TYPE_F32);
+    psReadout *myReadout = psReadoutAlloc();
+    psReadout *rc = NULL;
+    myReadout->image = myImage;
+    psVector *in = psVectorAlloc(tableSize, PS_TYPE_F32);
+    psVector *inOne = psVectorAlloc(1, PS_TYPE_F32);
+    psVector *inSmall = psVectorAlloc(tableSize-1, PS_TYPE_F32);
+    psVector *inBig = psVectorAlloc(tableSize+1, PS_TYPE_F32);
+    psVector *out = psVectorAlloc(tableSize, PS_TYPE_F32);
+    psVector *outOne = psVectorAlloc(1, PS_TYPE_F32);
+    psVector *outSmall = psVectorAlloc(tableSize-1, PS_TYPE_F32);
+    psVector *outBig = psVectorAlloc(tableSize+1, PS_TYPE_F32);
+
+    test03Init(myReadout);
+    for (i=0;i<tableSize;i++) {
+        in->data.F32[i] = (float) i;
+        out->data.F32[i] = (float) (2 * i);
+        inBig->data.F32[i] = (float) i;
+        outBig->data.F32[i] = (float) (2 * i);
+        if (i < tableSize-1) {
+            inSmall->data.F32[i] = (float) (2 * i);
+            outSmall->data.F32[i] = (float) (2 * i);
+        }
+    }
+    inBig->data.F32[tableSize] = (float) tableSize;
+    outBig->data.F32[tableSize] = (float) (2 * tableSize);
+    inOne->data.F32[0] = 0.0;
+    outOne->data.F32[0] = 0.0;
+
+    printf("------------------------------------------------------------\n");
+    printf("Calling pmNonLinearityLookup() with NULL input psReadout.  Should generate error, return NULL.\n");
+    rc = pmNonLinearityLookup(NULL, in, out);
+    if (rc != NULL) {
+        printf("TEST ERROR: pmNonLinearityPolynomial() returned a non-NULL psReadout\n");
+        testStatus = false;
+    }
+
+    printf("------------------------------------------------------------\n");
+    printf("Calling pmNonLinearityLookup() with NULL input psReadout->image.  Should generate error, return NULL.\n");
+    psImage *tmpImage = myReadout->image;
+    myReadout->image = NULL;
+    rc = pmNonLinearityLookup(myReadout, in, out);
+    if (rc != NULL) {
+        printf("TEST ERROR: pmNonLinearityPolynomial() returned a non-NULL psReadout\n");
+        testStatus = false;
+    }
+    myReadout->image = tmpImage;
+
+    printf("------------------------------------------------------------\n");
+    printf("Calling pmNonLinearityLookup() with NULL inFlux psVector.  Should generate error, return NULL.\n");
+    rc = pmNonLinearityLookup(myReadout, NULL, out);
+    if (rc != NULL) {
+        printf("TEST ERROR: pmNonLinearityPolynomial() returned a non-NULL psReadout\n");
+        testStatus = false;
+    }
+
+    printf("------------------------------------------------------------\n");
+    printf("Calling pmNonLinearityLookup() with NULL outFlux psVector.  Should generate error, return NULL.\n");
+    rc = pmNonLinearityLookup(myReadout, in, NULL);
+    if (rc != NULL) {
+        printf("TEST ERROR: pmNonLinearityPolynomial() returned a non-NULL psReadout\n");
+        testStatus = false;
+    }
+
+    test03Init(myReadout);
+    printf("------------------------------------------------------------\n");
+    printf("Calling pmNonLinearityLookup() with size difference in inFlux/outFLux psVectors.  Should generate warning.\n");
+    rc = pmNonLinearityLookup(myReadout, in, outBig);
+    if (rc == NULL) {
+        printf("TEST ERROR: pmNonLinearityPolynomial() returned a NULL psReadout\n");
+        testStatus = false;
+    }
+    for (i=0;i<NUM_ROWS;i++) {
+        for (j=0;j<NUM_COLS;j++) {
+            psF32 expect = (float) (2 * (i + j));
+            psF32 actual = rc->image->data.F32[i][j];
+            if (FLT_EPSILON < fabs(expect - actual)) {
+                printf("TEST ERROR: image[%d][%d] is %f, should be %f\n", i, j, actual, expect);
+                testStatus = false;
+            }
+        }
+    }
+
+
+    test03Init(myReadout);
+    printf("------------------------------------------------------------\n");
+    printf("Calling pmNonLinearityLookup() with size difference in inFlux/outFLux psVectors.  Should generate warning.\n");
+    rc = pmNonLinearityLookup(myReadout, in, outSmall);
+    if (rc == NULL) {
+        printf("TEST ERROR: pmNonLinearityPolynomial() returned a NULL psReadout\n");
+        testStatus = false;
+    }
+
+    test03Init(myReadout);
+    printf("------------------------------------------------------------\n");
+    printf("Calling pmNonLinearityLookup() with size difference in inFlux/outFLux psVectors.  Should generate warning.\n");
+    rc = pmNonLinearityLookup(myReadout, inSmall, out);
+    if (rc == NULL) {
+        printf("TEST ERROR: pmNonLinearityPolynomial() returned a NULL psReadout\n");
+        testStatus = false;
+    }
+
+    test03Init(myReadout);
+    printf("------------------------------------------------------------\n");
+    printf("Calling pmNonLinearityLookup() with size difference in inFlux/outFLux psVectors.  Should generate warning.\n");
+    rc = pmNonLinearityLookup(myReadout, inBig, out);
+    if (rc == NULL) {
+        printf("TEST ERROR: pmNonLinearityPolynomial() returned a NULL psReadout\n");
+        testStatus = false;
+    }
+
+    test03Init(myReadout);
+    printf("------------------------------------------------------------\n");
+    printf("Calling pmNonLinearityLookup() with size difference in inFlux/outFLux psVectors.  Should generate warning.\n");
+    rc = pmNonLinearityLookup(myReadout, inSmall, outBig);
+    if (rc == NULL) {
+        printf("TEST ERROR: pmNonLinearityPolynomial() returned a NULL psReadout\n");
+        testStatus = false;
+    }
+
+    test03Init(myReadout);
+    printf("------------------------------------------------------------\n");
+    printf("Calling pmNonLinearityLookup() with size difference in inFlux/outFLux psVectors.  Should generate warning.\n");
+    rc = pmNonLinearityLookup(myReadout, inBig, outSmall);
+    if (rc == NULL) {
+        printf("TEST ERROR: pmNonLinearityPolynomial() returned a NULL psReadout\n");
+        testStatus = false;
+    }
+
+    test03Init(myReadout);
+    printf("------------------------------------------------------------\n");
+    printf("Calling pmNonLinearityLookup() with inFlux psVector size 1.  Should generate error, return original psReadout.\n");
+    rc = pmNonLinearityLookup(myReadout, inOne, out);
+    if (rc != myReadout) {
+        printf("TEST ERROR: pmNonLinearityPolynomial() did not return the original psReadout\n");
+        testStatus = false;
+    }
+
+    printf("------------------------------------------------------------\n");
+    printf("Calling pmNonLinearityLookup() with one pixels outside inFlux range.  Should generate warnings.\n");
+    test03Init(myReadout);
+    myReadout->image->data.F32[0][0] = -1;
+    rc = pmNonLinearityLookup(myReadout, in, out);
+    if (rc == NULL) {
+        printf("TEST ERROR: pmNonLinearityPolynomial() returned a NULL psReadout\n");
+        testStatus = false;
+    }
+
+
+    psFree(myReadout);
+    psFree(in);
+    psFree(inOne);
+    psFree(inSmall);
+    psFree(inBig);
+    psFree(out);
+    psFree(outOne);
+    psFree(outSmall);
+    psFree(outBig);
+
+    return(testStatus);
+}
