Index: trunk/psLib/test/math/tap_psPolyFit2D.c
===================================================================
--- trunk/psLib/test/math/tap_psPolyFit2D.c	(revision 13124)
+++ trunk/psLib/test/math/tap_psPolyFit2D.c	(revision 13337)
@@ -364,5 +364,275 @@
     psLogSetFormat("HLNM");
     psLogSetLevel(PS_LOG_INFO);
-    plan_tests(44);
+    plan_tests(88);
+
+
+    // psVectorFitPolynomial2D()
+    // Test various erroneous input paramater configurations
+    {
+        psMemId id = psMemGetId();
+        psPolynomial2D *myPoly = psPolynomial2DAlloc(PS_POLYNOMIAL_ORD, POLY_ORDER_X, POLY_ORDER_Y);
+        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 *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 psPolynomial2D to NULL, should cause error
+        {
+            psMemId id = psMemGetId();
+            bool rc = psVectorFitPolynomial2D(NULL, mask, MASK_VALUE, f, fErr, x, y);
+            ok(rc == false, "psVectorFitPolynomial2D() returned FALSE with NULL psPolynomial2D");
+            ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
+        }
+
+
+        // Set mask to incorrect type, should cause error
+        {
+            psMemId id = psMemGetId();
+            bool rc = psVectorFitPolynomial2D(myPoly, maskS8, MASK_VALUE, f, fErr, x, y);
+            ok(rc == false, "psVectorFitPolynomial2D() 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 = psVectorFitPolynomial2D(myPoly, mask, MASK_VALUE, fS32, fErr, x, y);
+            ok(rc == false, "psVectorFitPolynomial2D() 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 = psVectorFitPolynomial2D(myPoly, mask, MASK_VALUE, f, fErrS32, x, y);
+            ok(rc == false, "psVectorFitPolynomial2D() 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 = psVectorFitPolynomial2D(myPoly, mask, MASK_VALUE, f, fErr, xS32, y);
+            ok(rc == false, "psVectorFitPolynomial2D() 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 = psVectorFitPolynomial2D(myPoly, mask, MASK_VALUE, f, fErr, x, yS32);
+            ok(rc == false, "psVectorFitPolynomial2D() returned FALSE: Set y 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 = psVectorFitPolynomial2D(myPoly, mask, MASK_VALUE, f, fErr, x, y);
+            mask->n--;
+            ok(rc == false, "psVectorFitPolynomial2D() 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 = psVectorFitPolynomial2D(myPoly, mask, MASK_VALUE, f, fErr, x, y);
+            f->n--;
+            ok(rc == false, "psVectorFitPolynomial2D() 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 = psVectorFitPolynomial2D(myPoly, mask, MASK_VALUE, f, fErr, x, y);
+            fErr->n--;
+            ok(rc == false, "psVectorFitPolynomial2D() 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 = psVectorFitPolynomial2D(myPoly, mask, MASK_VALUE, f, fErr, x, y);
+            x->n--;
+            ok(rc == false, "psVectorFitPolynomial2D() 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(f);
+        psFree(fS32);
+        psFree(mask);
+        psFree(maskS8);
+        psFree(fErr);
+        psFree(fErrS32);
+        ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
+    }
+
+
+    // psVectorClipFitPolynomial2D()
+    // Test various erroneous input paramater configurations
+    {
+        psMemId id = psMemGetId();
+        psPolynomial2D *myPoly = psPolynomial2DAlloc(PS_POLYNOMIAL_ORD, POLY_ORDER_X, POLY_ORDER_Y);
+        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 *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 psPolynomial2D to NULL, should cause error
+        {
+            psMemId id = psMemGetId();
+            bool rc = psVectorClipFitPolynomial2D(NULL, stats, mask, MASK_VALUE, f, fErr, x, y);
+            ok(rc == false, "psVectorClipFitPolynomial2D() returned FALSE with NULL psPolynomial2D");
+            ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
+        }
+
+
+        // Set psStats to NULL, should cause error
+        {
+            psMemId id = psMemGetId();
+            bool rc = psVectorClipFitPolynomial2D(myPoly, NULL, mask, MASK_VALUE, f, fErr, x, y);
+            ok(rc == false, "psVectorClipFitPolynomial2D() 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 = psVectorClipFitPolynomial2D(myPoly, stats, maskS8, MASK_VALUE, f, fErr, x, y);
+            ok(rc == false, "psVectorClipFitPolynomial2D() 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 = psVectorClipFitPolynomial2D(myPoly, stats, mask, MASK_VALUE, fS32, fErr, x, y);
+            ok(rc == false, "psVectorClipFitPolynomial2D() 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 = psVectorClipFitPolynomial2D(myPoly, stats, mask, MASK_VALUE, f, fErrS32, x, y);
+            ok(rc == false, "psVectorClipFitPolynomial2D() 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 = psVectorClipFitPolynomial2D(myPoly, stats, mask, MASK_VALUE, f, fErr, xS32, y);
+            ok(rc == false, "psVectorClipFitPolynomial2D() 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 = psVectorClipFitPolynomial2D(myPoly, stats, mask, MASK_VALUE, f, fErr, x, yS32);
+            ok(rc == false, "psVectorClipFitPolynomial2D() returned FALSE: Set y 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 = psVectorClipFitPolynomial2D(myPoly, stats, mask, MASK_VALUE, f, fErr, x, y);
+            mask->n--;
+            ok(rc == false, "psVectorClipFitPolynomial2D() 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 = psVectorClipFitPolynomial2D(myPoly, stats, mask, MASK_VALUE, f, fErr, x, y);
+            f->n--;
+            ok(rc == false, "psVectorClipFitPolynomial2D() 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 = psVectorClipFitPolynomial2D(myPoly, stats, mask, MASK_VALUE, f, fErr, x, y);
+            fErr->n--;
+            ok(rc == false, "psVectorClipFitPolynomial2D() 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 = psVectorClipFitPolynomial2D(myPoly, stats, mask, MASK_VALUE, f, fErr, x, y);
+            x->n--;
+            ok(rc == false, "psVectorClipFitPolynomial2D() 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(f);
+        psFree(fS32);
+        psFree(mask);
+        psFree(maskS8);
+        psFree(fErr);
+        psFree(fErrS32);
+        psFree(stats);
+        ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
+    }
+
 
     //
