Index: trunk/psModules/test/camera/tap_pmFPA.c
===================================================================
--- trunk/psModules/test/camera/tap_pmFPA.c	(revision 14881)
+++ trunk/psModules/test/camera/tap_pmFPA.c	(revision 15987)
@@ -1,25 +1,2 @@
-/** @file  tst_pmAstrometry.c
- *
- *  XXX: Untested: pmFPACheckParents()
- *
-    void pmCellFreeReadouts(pmCell *cell)
-    void pmCellFreeData(pmCell *cell)
-    void pmChipFreeCells(pmChip *chip)   
-    void pmChipFreeData(pmChip *chip)
-    void pmFPAFreeData(pmFPA *fpa)
-    void pmReadoutFreeData(pmReadout *readout)
-
-*    pmReadout *pmReadoutAlloc(pmCell *cell)
-*    pmCell *pmCellAlloc(pmChip *chip, const char *name)
-*    pmChip *pmChipAlloc(pmFPA *fpa, const char *name)
-*    pmFPA *pmFPAAlloc(const psMetadata *camera)
-
-    bool pmFPACheckParents(pmFPA *fpa)
- *
- *  @version $Revision: 1.1 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2007-09-18 18:57:18 $
- *
- *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
- */
 #include <stdio.h>
 #include <string.h>
@@ -28,4 +5,7 @@
 #include "tap.h"
 #include "pstap.h"
+/* STATUS:
+    All functions are tested.
+*/
 
 #define CHIP_ALLOC_NAME "ChipName"
@@ -89,5 +69,5 @@
     psArrayRealloc(cell->readouts, NUM_READOUTS);
     for (int i = 0 ; i < NUM_READOUTS ; i++) {
-        cell->readouts->data[i] = generateSimpleReadout(cell);
+        cell->readouts->data[i] = psMemDecrRefCounter((psPtr) generateSimpleReadout(cell));
     }
     return(cell);
@@ -108,5 +88,5 @@
     psArrayRealloc(chip->cells, NUM_CELLS);
     for (int i = 0 ; i < NUM_CELLS ; i++) {
-        chip->cells->data[i] = generateSimpleCell(chip);
+        chip->cells->data[i] = psMemDecrRefCounter((psPtr) generateSimpleCell(chip));
     }
     return(chip);
@@ -129,5 +109,5 @@
     psArrayRealloc(fpa->chips, NUM_CHIPS);
     for (int i = 0 ; i < NUM_CHIPS ; i++) {
-        fpa->chips->data[i] = generateSimpleChip(fpa);
+        fpa->chips->data[i] = psMemDecrRefCounter((psPtr) generateSimpleChip(fpa));
     }
 
@@ -135,28 +115,4 @@
 }
 
-// XXX: This should only be necessary until the psFree() functions for
-// FPA/chip/cell/readout correctly free all child chips/cells/readouts
-void myFreeCell(pmCell *cell)
-{
-    for (int k = 0 ; k < cell->readouts->n ; k++) {
-        psFree(cell->readouts->data[k]);
-    }
-    psFree(cell);
-}
-
-void myFreeChip(pmChip *chip) {
-    for (int j = 0 ; j < chip->cells->n ; j++) {
-        myFreeCell(chip->cells->data[j]);
-    }
-    psFree(chip);
-}
-
-void myFreeFPA(pmFPA *fpa)
-{
-    for (int i = 0 ; i < fpa->chips->n ; i++) {
-        myFreeChip(fpa->chips->data[i]);
-    }
-    psFree(fpa);
-}
 
 psS32 main(psS32 argc, char* argv[])
@@ -164,9 +120,18 @@
     psLogSetFormat("HLNM");
     psLogSetLevel(PS_LOG_INFO);
-    plan_tests(56);
+    plan_tests(92);
 
     // ------------------------------------------------------------------------
     // pmFPAAlloc() tests
-    // XXX: Add tests for NULL inputs.
+    // Call pmFPAAlloc() with NULL pmCamera input.
+    {
+        psMemId id = psMemGetId();
+        pmFPA* fpa = pmFPAAlloc(NULL);
+        ok(fpa != NULL && psMemCheckFPA(fpa), "pmFPAAlloc() returned a non-NULL pmFPA with a NULL pmCamera input");
+        psFree(fpa);
+        ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
+    }
+
+    // Call pmFPAAlloc() with acceptable input parameters.
     {
         psMemId id = psMemGetId();
@@ -186,5 +151,4 @@
            psMemCheckArray(fpa->chips), "pmFPAAlloc() set ->chips correctly");
         ok(fpa->hdu == NULL, "pmFPAAlloc() set ->hdu to NULL");
-//        ok(fpa->wrote_phu == false, "pmFPAAlloc() set ->wrote_phu to FALSE");
         psFree(fpa);
         psFree(camera);
@@ -192,76 +156,62 @@
     }
 
+
     // Populate the pmFPA struct with real data to ensure they were psFree()'ed correctly.
     {
         psMemId id = psMemGetId();
         pmFPA* fpa = generateSimpleFPA(NULL);
-
-        myFreeFPA(fpa);
-/*
-        if (1) {
-            for (int i = 0 ; i < fpa->chips->n ; i++) {
-                pmChip *chip = fpa->chips->data[i];
-                for (int j = 0 ; j < chip->cells->n ; j++) {
-                    pmCell *cell = chip->cells->data[j];
-                    for (int k = 0 ; k < cell->readouts->n ; k++) {
-                        pmReadout *readout = cell->readouts->data[k];
-                        psFree(readout);
-		    }
-                    psFree(cell);
-    		}
-                psFree(chip);
-	    }
-            psFree(fpa);
-	} else {
-            for (int i = 0 ; i < fpa->chips->n ; i++) {
-                pmChip *chip = fpa->chips->data[i];
-                pmChipFreeCells(chip);
-                pmChipFreeData(chip);
-                psFree(chip);
-	    }
-            psFree(fpa);
-	}
-*/
-        ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
-    }
+        psFree(fpa);
+        ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks (Populate the pmFPA struct with real data)");
+    }
+
 
     // ------------------------------------------------------------------------
     // pmFPAFreeData() tests
-    // XXX: pmFPAAlloc(), pmChipAlloc(), etc, allocate much of the members of
-    // those data structures.  We don't really check that those members were
-    // actually psFree()'ed; we merely ensure that they were set to NULL.
-    {
-        psMemId id = psMemGetId();
-        psMetadata *camera = psMetadataAlloc();
-        pmFPA* fpa = generateSimpleFPA(camera);
-//        pmChip *chip = pmChipAlloc(fpa, CHIP_ALLOC_NAME);
-//        pmCell *cell = pmCellAlloc(chip, CELL_ALLOC_NAME);
-//        pmReadout *readout = pmReadoutAlloc(cell);
+    // Call pmFPAFreeData() with NULL pmFPA input parameter
+    {
+        psMemId id = psMemGetId();
+        pmFPAFreeData(NULL);
+        ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks (Call pmFPAFreeData() with NULL pmFPA input parameter)");
+    }
+
+
+    // Call pmFPAFreeData() with acceptable input parameters
+    {
+        psMemId id = psMemGetId();
+        pmFPA* fpa = generateSimpleFPA(NULL);
+        fpa->hdu->images = psArrayAlloc(10);
+        fpa->hdu->weights = psArrayAlloc(10);
+        fpa->hdu->masks = psArrayAlloc(10);
         pmFPAFreeData(fpa);
         ok(fpa->hdu->images == NULL, "pmFPAFreeData() correctly set fpa->hdu->images to NULL");
         ok(fpa->hdu->weights == NULL, "pmFPAFreeData() correctly set fpa->hdu->weights to NULL");
         ok(fpa->hdu->masks == NULL, "pmFPAFreeData() correctly set fpa->hdu->masks to NULL");
-     
-//        ok(chip->hdu->images == NULL, "pmFPAFreeData() correctly set chip->hdu->images to NULL");
-//        ok(chip->hdu->weights == NULL, "pmFPAFreeData() correctly set chip->hdu->weights to NULL");
-//        ok(chip->hdu->masks == NULL, "pmFPAFreeData() correctly set chip->hdu->masks to NULL");
-//        ok(cell->hdu->images == NULL, "pmFPAFreeData() correctly set cell->hdu->images to NULL");
-//        ok(cell->hdu->weights == NULL, "pmFPAFreeData() correctly set cell->hdu->weights to NULL");
-//        ok(cell->hdu->masks == NULL, "pmFPAFreeData() correctly set cell->hdu->masks to NULL");
-        psFree(camera);
-        psFree(fpa);
-//        psFree(chip);
-//        psFree(cell);
-//        psFree(readout);
-        ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
-    }
-
-    // ------------------------------------------------------------------------
+        psFree(fpa);
+        ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
+    }
+
+
+    // ------------------------------------------------------------------------
+    // pmChipAlloc() tests
+    // Call pmChipAlloc() with NULL input parameters
+    {
+        psMemId id = psMemGetId();
+        pmChip *chip = pmChipAlloc(NULL, CHIP_ALLOC_NAME);
+        ok(chip != NULL, "pmChipAlloc() returned non-NULL with NULL pmFPA input parameter");
+        psFree(chip);
+        pmFPA* fpa = generateSimpleFPA(NULL);
+        chip = pmChipAlloc(fpa, NULL);
+        ok(chip != NULL, "pmChipAlloc() returned non-NULL with NULL chip name input parameter");
+        psFree(fpa);
+        psFree(chip);
+        ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
+    }
+
+
     // pmChipAlloc() tests
     // XXX: Add tests for NULL inputs.
     {
         psMemId id = psMemGetId();
-        psMetadata *camera = psMetadataAlloc();
-        pmFPA* fpa = generateSimpleFPA(camera);
+        pmFPA* fpa = generateSimpleFPA(NULL);
         pmChip *chip = pmChipAlloc(fpa, CHIP_ALLOC_NAME);
         ok(chip != NULL, "pmChipAlloc() returned non-NULL");
@@ -280,10 +230,9 @@
         ok(chip->data_exists == false, "pmChipAlloc() set ->data_exists correctly");
         ok(chip->hdu == NULL, "pmChipAlloc() set ->hdu to NULL");
-//        ok(chip->wrote_phu == false, "pmChipAlloc() set ->wrote_phu correctly");
-        psFree(camera);
-        psFree(fpa);
-        psFree(chip);
-        ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
-    }
+        psFree(fpa);
+        psFree(chip);
+        ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
+    }
+
 
     // Populate the pmChip struct with real data to ensure they were free'ed correctly.
@@ -292,4 +241,51 @@
         pmChip *chip = generateSimpleChip(NULL);
         psFree(chip);
+        ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks (Populate the pmChip struct with real data)");
+    }
+
+
+    // ------------------------------------------------------------------------
+    // pmChipFreeData() tests
+    // Call pmChipFreeData() with NULL pmFPA input parameter
+    {
+        psMemId id = psMemGetId();
+        pmChipFreeData(NULL);
+        ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks (Call pmChipFreeData() with NULL pmFPA input parameter)");
+    }
+
+
+    // Call pmChipFreeData() with acceptable input parameters
+    {
+        psMemId id = psMemGetId();
+        pmChip* chip = generateSimpleChip(NULL);
+        chip->hdu->images = psArrayAlloc(10);
+        chip->hdu->weights = psArrayAlloc(10);
+        chip->hdu->masks = psArrayAlloc(10);
+        pmChipFreeData(chip);
+        ok(chip->hdu->images == NULL, "pmChipFreeData() correctly set chip->hdu->images to NULL");
+        ok(chip->hdu->weights == NULL, "pmChipFreeData() correctly set chip->hdu->weights to NULL");
+        ok(chip->hdu->masks == NULL, "pmChipFreeData() correctly set chip->hdu->masks to NULL");
+        psFree(chip);
+        ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
+    }
+
+
+    // ------------------------------------------------------------------------
+    // pmChipFreeCells() tests
+    // Call pmChipFreeCells() with NULL pmFPA input parameter
+    {
+        psMemId id = psMemGetId();
+        pmChipFreeCells(NULL);
+        ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks (Call pmChipFreeCells() with NULL pmFPA input parameter)");
+    }
+
+
+    // Call pmChipFreeCells() with acceptable input parameters
+    {
+        psMemId id = psMemGetId();
+        pmChip* chip = generateSimpleChip(NULL);
+        pmChipFreeCells(chip);
+        ok(chip->cells->n == 0, "pmChipFreeCells() free'ed chip->cells correctly");
+        psFree(chip);
         ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
     }
@@ -298,5 +294,22 @@
     // ------------------------------------------------------------------------
     // pmCellAlloc() tests
-    // XXX: Add tests for NULL inputs.
+    // Call pmCellAlloc() with NULL input parameters
+    {
+        psMemId id = psMemGetId();
+        pmCell *cell = pmCellAlloc(NULL, CELL_ALLOC_NAME);
+        ok(cell != NULL, "pmCellAlloc returned non-NULL with NULL pmChip input parameter");
+        psFree(cell);
+
+        pmChip *chip = pmChipAlloc(NULL, NULL);
+        cell = pmCellAlloc(chip, NULL);
+        ok(cell != NULL, "pmCellAlloc returned non-NULL with NULL cell name input parameter");
+        psFree(chip);
+        psFree(cell);
+        ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
+    }
+
+
+    // pmCellAlloc() tests
+    // Call pmCellAlloc() with acceptable input parameters
     {
         psMemId id = psMemGetId();
@@ -319,5 +332,4 @@
         ok(cell->data_exists == false, "pmCellAlloc() set ->data_exists correctly");
         ok(cell->hdu == NULL, "pmCellAlloc() set ->hdu to NULL");
-//        ok(cell->wrote_phu == false, "pmCellAlloc() set ->wrote_phu correctly");
         psFree(camera);
         psFree(fpa);
@@ -326,4 +338,5 @@
         ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
     }
+
 
     // Populate the pmCell struct with real data to ensure they were
@@ -333,8 +346,35 @@
         pmCell *cell = generateSimpleCell(NULL);
         psFree(cell);
-        ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
-    }
-
-
+        ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks (Populate the pmCell struct with real data)");
+    }
+
+
+    // ------------------------------------------------------------------------
+    // pmCellFreeData() tests
+    // Call pmCellFreeData() with NULL pmFPA input parameter
+    {
+        psMemId id = psMemGetId();
+        pmCellFreeData(NULL);
+        ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks (Call pmCellFreeData() with NULL pmFPA input parameter)");
+    }
+
+
+    // Call pmCellFreeData() with acceptable input parameters
+    {
+        psMemId id = psMemGetId();
+        pmCell *cell = generateSimpleCell(NULL);
+        cell->hdu->images = psArrayAlloc(10);
+        cell->hdu->weights = psArrayAlloc(10);
+        cell->hdu->masks = psArrayAlloc(10);
+        pmCellFreeData(cell);
+        ok(cell->hdu->images == NULL, "pmCellFreeData() correctly set cell->hdu->images to NULL");
+        ok(cell->hdu->weights == NULL, "pmCellFreeData() correctly set cell->hdu->weights to NULL");
+        ok(cell->hdu->masks == NULL, "pmCellFreeData() correctly set cell->hdu->masks to NULL");
+        psFree(cell);
+        ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
+    }
+
+
+    // ------------------------------------------------------------------------
     // test pmCellFreeReadouts()
     {
@@ -350,5 +390,15 @@
     // ------------------------------------------------------------------------
     // pmReadoutAlloc() tests
-    // XXX: Add tests for NULL inputs.
+    // Call pmReadoutAlloc() with NULL input parameters
+    {
+        psMemId id = psMemGetId();
+        pmReadout *readout = pmReadoutAlloc(NULL);
+        ok(readout != NULL, "pmReadoutAlloc() returned non-NULL with NULL pmCell input parameter");
+        psFree(readout);
+        ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
+    }
+
+
+    // Call pmReadoutAlloc() with acceptable parameters
     {
         psMemId id = psMemGetId();
@@ -380,4 +430,5 @@
     }
 
+
     // Populate the pmReadout struct with real data to ensure they were
     // psFree()'ed correctly.
@@ -390,20 +441,50 @@
     }
 
-/*
-    {
-        psMemId id = psMemGetId();
-        pmReadout *readout = pmReadoutAlloc(NULL);
-        readout->image = psImageAlloc(TEST_NUM_COLS, TEST_NUM_ROWS, PS_TYPE_F32);
-        readout->mask = psImageAlloc(TEST_NUM_COLS, TEST_NUM_ROWS, PS_TYPE_U8);
-        readout->weight = psImageAlloc(TEST_NUM_COLS, TEST_NUM_ROWS, PS_TYPE_F32);
-        for (psS32 i = 0 ; i < NUM_BIAS_DATA ; i++) {
-            psImage *tmpImage = psImageAlloc(TEST_NUM_COLS, TEST_NUM_ROWS, PS_TYPE_F32);
-            psListAdd(readout->bias, PS_LIST_HEAD, tmpImage);
-        }
-        psMetadataAddS32(readout->analysis, PS_LIST_HEAD, MISC_NAME, 0, NULL, MISC_NUM);
-        return(readout);
-    }
-*/
-
-
-}
+
+    // ------------------------------------------------------------------------
+    // pmReadoutFreeData() tests
+    // Call pmReadoutFreeData() with NULL pmFPA input parameter
+    {
+        psMemId id = psMemGetId();
+        pmReadoutFreeData(NULL);
+        ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks (Call pmReadoutFreeData() with NULL pmFPA input parameter)");
+    }
+
+
+    // Call pmReadoutFreeData() with acceptable input parameters
+    {
+        psMemId id = psMemGetId();
+        pmReadout *readout = generateSimpleReadout(NULL);
+        pmReadoutFreeData(readout);
+        ok(readout->image == NULL, "pmReadoutFreeData() correctly set readout->image to NULL");
+        ok(readout->weight == NULL, "pmReadoutFreeData() correctly set readout->weight to NULL");
+        ok(readout->mask == NULL, "pmReadoutFreeData() correctly set readout->mask to NULL");
+        psFree(readout);
+        ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
+    }
+
+
+    // ------------------------------------------------------------------------
+    // pmFPACheckParents() tests
+    // psBool pmFPACheckParents(pmFPA *fpa)
+    // Call pmFPACheckParents() with NULL pmFPA input parameter
+    {
+        psMemId id = psMemGetId();
+        bool rc = pmFPACheckParents(NULL);
+        ok(rc == false, "pmFPACheckParents() returned FALSE with NULL pmFPA input parameter");
+        ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
+    }
+
+
+    // pmFPACheckParents() tests
+    // Call pmFPACheckParents() with acceptable input parameters
+    {
+        psMemId id = psMemGetId();
+        pmFPA* fpa = generateSimpleFPA(NULL);
+        bool rc = pmFPACheckParents(fpa);
+        ok(rc == true, "pmFPACheckParents() returned FALSE with acceptable input parameters");
+        psFree(fpa);
+        ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
+    }
+
+}
