Index: trunk/psModules/test/objects/tap_pmSourceUtils.c
===================================================================
--- trunk/psModules/test/objects/tap_pmSourceUtils.c	(revision 15726)
+++ trunk/psModules/test/objects/tap_pmSourceUtils.c	(revision 15985)
@@ -5,5 +5,9 @@
 #include "tap.h"
 #include "pstap.h"
-// XXX: We only test with unallowable input parameters so far.
+/* STATUS
+    All functions are tested.
+       pmSourceFromModel(): Must verify the pmSourceDefinePixels() set the
+           values correctly.
+*/
 
 #define MISC_NUM                32
@@ -14,5 +18,5 @@
 #define VERBOSE                 0
 #define ERR_TRACE_LEVEL         0
-#define TEST_FLOATS_EQUAL(X, Y) (abs(X - Y) < 0.0001)
+#define TEST_FLOATS_EQUAL(X, Y) (abs((X) - (Y)) < 0.0001)
 #define NUM_SOURCES		100
 
@@ -83,6 +87,4 @@
     }
 
-    //XXX: Should the region be set some other way?  Like through the various config files?
-//    psRegion *region = psRegionAlloc(0.0, TEST_NUM_COLS-1, 0.0, TEST_NUM_ROWS-1);
     psRegion *region = psRegionAlloc(0.0, 0.0, 0.0, 0.0);
     // You shouldn't have to remove the key from the metadata.  Find out how to simply change the key value.
@@ -108,12 +110,11 @@
     psTraceSetLevel("err", ERR_TRACE_LEVEL);
     psTraceSetLevel("psModules.objects", 0);
-    plan_tests(14);
+    plan_tests(23);
 
 
     // ----------------------------------------------------------------------
     // pmSourceModelGuess() tests
-    // pmModel *pmSourceModelGuess(pmSource *source, pmModelType modelType)
     // Call pmSourceModelGuess() with NULL pmSource input parameter
-    if (1) {
+    {
         psMemId id = psMemGetId();
         pmSource *src = pmSourceAlloc();
@@ -130,5 +131,5 @@
 
     // Call pmSourceModelGuess() with NULL pmSource->peak input parameter
-    if (1) {
+    {
         psMemId id = psMemGetId();
         pmSource *src = pmSourceAlloc();
@@ -144,5 +145,5 @@
 
     // Call pmSourceModelGuess() with NULL pmSource->moments input parameter
-    if (1) {
+    {
         psMemId id = psMemGetId();
         pmSource *src = pmSourceAlloc();
@@ -159,6 +160,7 @@
     // pmModel *pmSourceModelGuess(pmSource *source, pmModelType modelType)
     // Call pmSourceModelGuess() with acceptable input parameters
-    // XXX: Must verify that the values of the new pmModel are set correctly.
-    if (1) {
+    // We only test a single model (PS_MODEL_GAUSS), but since this function is mostly
+    // a wrapper to the model functions, that will suffice.
+    {
         psMemId id = psMemGetId();
         pmSource *src = pmSourceAlloc();
@@ -174,10 +176,24 @@
         src->moments->y = 7.0;
 
-        pmModelType type = pmModelClassGetType ("PS_MODEL_GAUSS");
+        pmModelType type = pmModelClassGetType("PS_MODEL_GAUSS");
         pmModel *testModel = pmModelAlloc(type);
         testModel->modelGuess(testModel, src);
         pmModel *model = pmSourceModelGuess(src, type);
         ok(model != NULL, "pmSourceModelGuess() returned non-NULL with acceptable input parameters");
-
+        psF32 *PAR  = model->params->data.F32;
+        psEllipseMoments emoments;
+        emoments.x2 = src->moments->Sx;
+        emoments.y2 = src->moments->Sy;
+        emoments.xy = src->moments->Sxy;
+        // force the axis ratio to be < 20.0
+        psEllipseAxes axes = psEllipseMomentsToAxes (emoments, 20.0);
+        psEllipseShape shape = psEllipseAxesToShape (axes);
+        ok(TEST_FLOATS_EQUAL(PAR[PM_PAR_SKY], src->moments->Sky), "pmSourceModelGuess() returned set model->params[PM_PAR_SKY] correctly");
+        ok(TEST_FLOATS_EQUAL(PAR[PM_PAR_I0], src->moments->Peak - src->moments->Sky), "pmSourceModelGuess() returned set model->params[PM_PAR_IO] correctly");
+        ok(TEST_FLOATS_EQUAL(PAR[PM_PAR_XPOS], src->moments->x), "pmSourceModelGuess() returned set model->params[PM_PAR_XPOS] correctly");
+        ok(TEST_FLOATS_EQUAL(PAR[PM_PAR_YPOS], src->moments->y), "pmSourceModelGuess() returned set model->params[PM_PAR_YPOS] correctly");
+        ok(TEST_FLOATS_EQUAL(PAR[PM_PAR_SXX], PS_MAX(0.5, M_SQRT2*shape.sx)), "pmSourceModelGuess() returned set model->params[PM_PAR_SXX] correctly");
+        ok(TEST_FLOATS_EQUAL(PAR[PM_PAR_SYY], PS_MAX(0.5, M_SQRT2*shape.sy)), "pmSourceModelGuess() returned set model->params[PM_PAR_SYY] correctly");
+        ok(TEST_FLOATS_EQUAL(PAR[PM_PAR_SXY], shape.sxy), "pmSourceModelGuess() returned set model->params[PM_PAR_SXY] correctly");
         psFree(src);
         psFree(testModel);
@@ -190,8 +206,6 @@
     // ----------------------------------------------------------------------
     // pmSourceModelGuess() tests
-    // pmSource *pmSourceFromModel (pmModel *model, pmReadout *readout, 
-    //                              float radius, pmSourceType type)
     // Call pmSourceFromModel() with NULL pmModel input parameter
-    if (1) {
+    {
         psMemId id = psMemGetId();
         pmModelType type = pmModelClassGetType ("PS_MODEL_GAUSS");
@@ -210,5 +224,5 @@
 
     // Call pmSourceFromModel() with NULL pmReadout input parameter
-    if (1) {
+    {
         psMemId id = psMemGetId();
 
@@ -227,26 +241,32 @@
 
     // Call pmSourceFromModel() with acceptable input parameters
-    // XXX: Must verify that the values of the new pmSource are set correctly.
-    if (1) {
-        psMemId id = psMemGetId();
-
-        pmModelType type = pmModelClassGetType ("PS_MODEL_GAUSS");
-        pmModel *model = pmModelAlloc(type);
+    // XXX: Must verify the pmSourceDefinePixels() set the values correctly.
+    {
+        psMemId id = psMemGetId();
+
+        pmModel *model = pmModelAlloc(pmModelClassGetType("PS_MODEL_GAUSS"));
+        float Io    = model->params->data.F32[PM_PAR_I0] = 2.0;
+        float xChip = model->params->data.F32[PM_PAR_XPOS] = 3.0;
+        float yChip = model->params->data.F32[PM_PAR_YPOS] = 5.0;
         pmCell *cell = generateSimpleCell(NULL);
         pmReadout *readout = cell->readouts->data[0];
         pmSource *src = pmSourceFromModel(model, readout, 10.0, PM_SOURCE_TYPE_STAR);
         ok(src != NULL, "pmSourceFromModel() returned non-NULL with acceptable input parameters");
+        ok(src->modelPSF == model, "pmSourceFromModel() set pmSource->modelPSF correctly");
+
+        pmPeak *tmpPeak = pmPeakAlloc (xChip, yChip, Io, PM_PEAK_LONE);
+        ok(src->peak->x == xChip, "pmSourceFromModel() set pmSource->peak->x correctly (%.2f %.2f)", src->peak->x, xChip);
+
         psFree(model);
         // XXX: We get psMemory aborts if the following is not done.
         // There is probably an issue with psMemIncrRefCounter() in pmSourceUtils.c
+
         src->modelPSF = NULL;
         src->modelEXT = NULL;
         psFree(src);
+        psFree(tmpPeak);
         myFreeCell(cell);
         pmModelClassCleanup();
         ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
     }
-
-
-}
-
+}
