Index: trunk/psLib/test/math/tap_psPolyFit4D.c
===================================================================
--- trunk/psLib/test/math/tap_psPolyFit4D.c	(revision 13124)
+++ trunk/psLib/test/math/tap_psPolyFit4D.c	(revision 13337)
@@ -472,6 +472,328 @@
     psLogSetFormat("HLNM");
     psLogSetLevel(PS_LOG_INFO);
-    plan_tests(60);
-
+    plan_tests(112);
+
+
+    // psVectorFitPolynomial4D()
+    // Test various erroneous input paramater configurations
+    {
+        psMemId id = psMemGetId();
+        psPolynomial4D *myPoly = psPolynomial4DAlloc(PS_POLYNOMIAL_ORD, POLY_ORDER_X, POLY_ORDER_Y, POLY_ORDER_Z, POLY_ORDER_T);
+        psVector *x = psVectorAlloc(NUM_DATA, PS_TYPE_F32);
+        psVector *xS32 = psVectorAlloc(NUM_DATA, PS_TYPE_S32);
+        psVector *y = psVectorAlloc(NUM_DATA, PS_TYPE_F32);
+        psVector *yS32 = psVectorAlloc(NUM_DATA, PS_TYPE_S32);
+        psVector *z = psVectorAlloc(NUM_DATA, PS_TYPE_F32);
+        psVector *zS32 = psVectorAlloc(NUM_DATA, PS_TYPE_S32);
+        psVector *t = psVectorAlloc(NUM_DATA, PS_TYPE_F32);
+        psVector *tS32 = psVectorAlloc(NUM_DATA, PS_TYPE_S32);
+        psVector *f = psVectorAlloc(NUM_DATA, PS_TYPE_F32);
+        psVector *fS32 = psVectorAlloc(NUM_DATA, PS_TYPE_S32);
+        psVector *mask = psVectorAlloc(NUM_DATA, PS_TYPE_U8);
+        psVector *maskS8 = psVectorAlloc(NUM_DATA, PS_TYPE_S8);
+        psVector *fErr = psVectorAlloc(NUM_DATA, PS_TYPE_F32);
+        psVector *fErrS32 = psVectorAlloc(NUM_DATA, PS_TYPE_S32);
+
+
+        // Set psPolynomial4D to NULL, should cause error
+        {
+            psMemId id = psMemGetId();
+            bool rc = psVectorFitPolynomial4D(NULL, mask, MASK_VALUE, f, fErr, x, y, z, t);
+            ok(rc == false, "psVectorFitPolynomial4D() returned FALSE with NULL psPolynomial4D");
+            ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
+        }
+
+
+        // Set mask to incorrect type, should cause error
+        {
+            psMemId id = psMemGetId();
+            bool rc = psVectorFitPolynomial4D(myPoly, maskS8, MASK_VALUE, f, fErr, x, y, z, t);
+            ok(rc == false, "psVectorFitPolynomial4D() returned FALSE with mask set to incorrect type");
+            ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
+        }
+
+
+        // Set f psVector to incorrect type, should cause error
+        {
+            psMemId id = psMemGetId();
+            bool rc = psVectorFitPolynomial4D(myPoly, mask, MASK_VALUE, fS32, fErr, x, y, z, t);
+            ok(rc == false, "psVectorFitPolynomial4D() returned FALSE: Set f psVector to incorrect type");
+            ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
+        }
+
+
+        // Set fError vector to incorrect type, should cause error
+        {
+            psMemId id = psMemGetId();
+            bool rc = psVectorFitPolynomial4D(myPoly, mask, MASK_VALUE, f, fErrS32, x, y, z, t);
+            ok(rc == false, "psVectorFitPolynomial4D() returned FALSE: Set fError vector to incorrect type");
+            ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
+        }
+
+
+        // Set x vector to incorrect type, should cause error
+        {
+            psMemId id = psMemGetId();
+            bool rc = psVectorFitPolynomial4D(myPoly, mask, MASK_VALUE, f, fErr, xS32, y, z, t);
+            ok(rc == false, "psVectorFitPolynomial4D() returned FALSE: Set x vector to incorrect type");
+            ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
+        }
+
+
+        // Set y vector to incorrect type, should cause error
+        {
+            psMemId id = psMemGetId();
+            bool rc = psVectorFitPolynomial4D(myPoly, mask, MASK_VALUE, f, fErr, x, yS32, z, t);
+            ok(rc == false, "psVectorFitPolynomial4D() returned FALSE: Set y vector to incorrect type");
+            ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
+        }
+
+
+        // Set z vector to incorrect type, should cause error
+        {
+            psMemId id = psMemGetId();
+            bool rc = psVectorFitPolynomial4D(myPoly, mask, MASK_VALUE, f, fErr, x, y, zS32, t);
+            ok(rc == false, "psVectorFitPolynomial4D() returned FALSE: Set z vector to incorrect type");
+            ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
+        }
+
+
+        // Set t vector to incorrect type, should cause error
+        {
+            psMemId id = psMemGetId();
+            bool rc = psVectorFitPolynomial4D(myPoly, mask, MASK_VALUE, f, fErr, x, y, z, tS32);
+            ok(rc == false, "psVectorFitPolynomial4D() returned FALSE: Set t vector to incorrect type");
+            ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
+        }
+
+
+        // Incorrect mask psVector size, should cause error
+        {
+            psMemId id = psMemGetId();
+            mask->n++;
+            bool rc = psVectorFitPolynomial4D(myPoly, mask, MASK_VALUE, f, fErr, x, y, z, t);
+            mask->n--;
+            ok(rc == false, "psVectorFitPolynomial4D() returned FALSE: Incorrect mask psVector size");
+            ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
+        }
+
+
+        // Incorrect f psVector size, should cause error
+        {
+            psMemId id = psMemGetId();
+            f->n++;
+            bool rc = psVectorFitPolynomial4D(myPoly, mask, MASK_VALUE, f, fErr, x, y, z, t);
+            f->n--;
+            ok(rc == false, "psVectorFitPolynomial4D() returned FALSE: Incorrect f psVector size");
+            ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
+        }
+
+
+        // Incorrect fErr psVector size, should cause error
+        {
+            psMemId id = psMemGetId();
+            fErr->n++;
+            bool rc = psVectorFitPolynomial4D(myPoly, mask, MASK_VALUE, f, fErr, x, y, z, t);
+            fErr->n--;
+            ok(rc == false, "psVectorFitPolynomial4D() returned FALSE: Incorrect fErr psVector size");
+            ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
+        }
+
+
+        // Incorrect x psVector size, should cause error
+        {
+            psMemId id = psMemGetId();
+            x->n++;
+            bool rc = psVectorFitPolynomial4D(myPoly, mask, MASK_VALUE, f, fErr, x, y, z, t);
+            x->n--;
+            ok(rc == false, "psVectorFitPolynomial4D() returned FALSE: Incorrect x psVector size");
+            ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
+        }
+
+        psFree(myPoly);
+        psFree(x);
+        psFree(xS32);
+        psFree(y);
+        psFree(yS32);
+        psFree(z);
+        psFree(zS32);
+        psFree(t);
+        psFree(tS32);
+        psFree(f);
+        psFree(fS32);
+        psFree(mask);
+        psFree(maskS8);
+        psFree(fErr);
+        psFree(fErrS32);
+        ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
+    }
+
+
+    // psVectorClipFitPolynomial4D()
+    // Test various erroneous input paramater configurations
+    {
+        psMemId id = psMemGetId();
+        psPolynomial4D *myPoly = psPolynomial4DAlloc(PS_POLYNOMIAL_ORD, POLY_ORDER_X, POLY_ORDER_Y, POLY_ORDER_Z, POLY_ORDER_T);
+        psVector *x = psVectorAlloc(NUM_DATA, PS_TYPE_F32);
+        psVector *xS32 = psVectorAlloc(NUM_DATA, PS_TYPE_S32);
+        psVector *y = psVectorAlloc(NUM_DATA, PS_TYPE_F32);
+        psVector *yS32 = psVectorAlloc(NUM_DATA, PS_TYPE_S32);
+        psVector *z = psVectorAlloc(NUM_DATA, PS_TYPE_F32);
+        psVector *zS32 = psVectorAlloc(NUM_DATA, PS_TYPE_S32);
+        psVector *t = psVectorAlloc(NUM_DATA, PS_TYPE_F32);
+        psVector *tS32 = psVectorAlloc(NUM_DATA, PS_TYPE_S32);
+        psVector *f = psVectorAlloc(NUM_DATA, PS_TYPE_F32);
+        psVector *fS32 = psVectorAlloc(NUM_DATA, PS_TYPE_S32);
+        psVector *mask = psVectorAlloc(NUM_DATA, PS_TYPE_U8);
+        psVector *maskS8 = psVectorAlloc(NUM_DATA, PS_TYPE_S8);
+        psVector *fErr = psVectorAlloc(NUM_DATA, PS_TYPE_F32);
+        psVector *fErrS32 = psVectorAlloc(NUM_DATA, PS_TYPE_S32);
+        psStats *stats = psStatsAlloc(PS_STAT_SAMPLE_MEAN);
+
+
+        // Set psPolynomial4D to NULL, should cause error
+        {
+            psMemId id = psMemGetId();
+            bool rc = psVectorClipFitPolynomial4D(NULL, stats, mask, MASK_VALUE, f, fErr, x, y, z, t);
+            ok(rc == false, "psVectorClipFitPolynomial4D() returned FALSE with NULL psPolynomial4D");
+            ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
+        }
+
+
+        // Set psStats to NULL, should cause error
+        {
+            psMemId id = psMemGetId();
+            bool rc = psVectorClipFitPolynomial4D(myPoly, stats, mask, MASK_VALUE, f, fErr, x, y, z, t);
+            ok(rc == false, "psVectorClipFitPolynomial4D() returned FALSE with NULL psStats");
+            ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
+        }
+
+
+        // Set mask to incorrect type, should cause error
+        {
+            psMemId id = psMemGetId();
+            bool rc = psVectorClipFitPolynomial4D(myPoly, stats, maskS8, MASK_VALUE, f, fErr, x, y, z, t);
+            ok(rc == false, "psVectorClipFitPolynomial4D() returned FALSE with mask set to incorrect type");
+            ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
+        }
+
+
+        // Set f psVector to incorrect type, should cause error
+        {
+            psMemId id = psMemGetId();
+            bool rc = psVectorClipFitPolynomial4D(myPoly, stats, mask, MASK_VALUE, fS32, fErr, x, y, z, t);
+            ok(rc == false, "psVectorClipFitPolynomial4D() returned FALSE: Set f psVector to incorrect type");
+            ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
+        }
+
+
+        // Set fError vector to incorrect type, should cause error
+        {
+            psMemId id = psMemGetId();
+            bool rc = psVectorClipFitPolynomial4D(myPoly, stats, mask, MASK_VALUE, f, fErrS32, x, y, z, t);
+            ok(rc == false, "psVectorClipFitPolynomial4D() returned FALSE: Set fError vector to incorrect type");
+            ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
+        }
+
+
+        // Set x vector to incorrect type, should cause error
+        {
+            psMemId id = psMemGetId();
+            bool rc = psVectorClipFitPolynomial4D(myPoly, stats, mask, MASK_VALUE, f, fErr, xS32, y, z, t);
+            ok(rc == false, "psVectorClipFitPolynomial4D() returned FALSE: Set x vector to incorrect type");
+            ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
+        }
+
+
+        // Set y vector to incorrect type, should cause error
+        {
+            psMemId id = psMemGetId();
+            bool rc = psVectorClipFitPolynomial4D(myPoly, stats, mask, MASK_VALUE, f, fErr, x, yS32, z, t);
+            ok(rc == false, "psVectorClipFitPolynomial4D() returned FALSE: Set y vector to incorrect type");
+            ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
+        }
+
+
+        // Set z vector to incorrect type, should cause error
+        {
+            psMemId id = psMemGetId();
+            bool rc = psVectorClipFitPolynomial4D(myPoly, stats, mask, MASK_VALUE, f, fErr, x, y, zS32, t);
+            ok(rc == false, "psVectorClipFitPolynomial4D() returned FALSE: Set z vector to incorrect type");
+            ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
+        }
+
+
+        // Set t vector to incorrect type, should cause error
+        {
+            psMemId id = psMemGetId();
+            bool rc = psVectorClipFitPolynomial4D(myPoly, stats, mask, MASK_VALUE, f, fErr, x, y, z, tS32);
+            ok(rc == false, "psVectorClipFitPolynomial4D() returned FALSE: Set t vector to incorrect type");
+            ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
+        }
+
+
+        // Incorrect mask psVector size, should cause error
+        {
+            psMemId id = psMemGetId();
+            mask->n++;
+            bool rc = psVectorClipFitPolynomial4D(myPoly, stats, mask, MASK_VALUE, f, fErr, x, y, z, t);
+            mask->n--;
+            ok(rc == false, "psVectorClipFitPolynomial4D() returned FALSE: Incorrect mask psVector size");
+            ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
+        }
+
+
+        // Incorrect f psVector size, should cause error
+        {
+            psMemId id = psMemGetId();
+            f->n++;
+            bool rc = psVectorClipFitPolynomial4D(myPoly, stats, mask, MASK_VALUE, f, fErr, x, y, z, t);
+            f->n--;
+            ok(rc == false, "psVectorClipFitPolynomial4D() returned FALSE: Incorrect f psVector size");
+            ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
+        }
+
+
+        // Incorrect fErr psVector size, should cause error
+        {
+            psMemId id = psMemGetId();
+            fErr->n++;
+            bool rc = psVectorClipFitPolynomial4D(myPoly, stats, mask, MASK_VALUE, f, fErr, x, y, z, t);
+            fErr->n--;
+            ok(rc == false, "psVectorClipFitPolynomial4D() returned FALSE: Incorrect fErr psVector size");
+            ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
+        }
+
+
+        // Incorrect x psVector size, should cause error
+        {
+            psMemId id = psMemGetId();
+            x->n++;
+            bool rc = psVectorClipFitPolynomial4D(myPoly, stats, mask, MASK_VALUE, f, fErr, x, y, z, t);
+            x->n--;
+            ok(rc == false, "psVectorClipFitPolynomial4D() returned FALSE: Incorrect x psVector size");
+            ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
+        }
+
+        psFree(myPoly);
+        psFree(x);
+        psFree(xS32);
+        psFree(y);
+        psFree(yS32);
+        psFree(z);
+        psFree(zS32);
+        psFree(t);
+        psFree(tS32);
+        psFree(f);
+        psFree(fS32);
+        psFree(mask);
+        psFree(maskS8);
+        psFree(fErr);
+        psFree(fErrS32);
+        psFree(stats);
+        ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
+    }
+
+    
     //
     // F32 tests: Ordinary polys, non-clip fit
@@ -696,2 +1018,3 @@
 }
 
+
