Index: trunk/psModules/test/camera/tap_pmFPAUtils.c
===================================================================
--- trunk/psModules/test/camera/tap_pmFPAUtils.c	(revision 14882)
+++ trunk/psModules/test/camera/tap_pmFPAUtils.c	(revision 15987)
@@ -5,12 +5,7 @@
 #include "tap.h"
 #include "pstap.h"
-// XXX: Use better name for the temporary FITS file
-// XXX: The code to generate and free the FPA hierarchy was copied from
-// tap-pmFPA.c.  EIther include it directly, or library, or something.
-// Also, get rid of the manual free functions and use psFree() once
-// it correctly frees child members
-// XXX: For the genSimpleFPA() code, add IDs to each function so that
-// the values set in each chip-?cell-?hdu-?image are unique
-// XXX: For the genSimpleFPA() code, write masks and weights as well
+/* STATUS:
+    All functions are tested.
+*/
 
 #define CHIP_ALLOC_NAME        "ChipName"
@@ -81,10 +76,14 @@
     cell->hdu = pmHDUAlloc("cellExtName");
     for (int i = 0 ; i < NUM_READOUTS ; i++) {
-        cell->readouts->data[i] = generateSimpleReadout(cell);
-    }
-
-    bool rc = pmConfigFileRead(&cell->hdu->format, "data/camera0/format0.config", "Camera format 0");
+        cell->readouts->data[i] = psMemDecrRefCounter((psPtr) generateSimpleReadout(cell));
+    }
+
+    // First try to read data from ../dataFiles, then try dataFiles.
+    bool rc = pmConfigFileRead(&cell->hdu->format, "dataFiles/camera0/format0.config", "Camera format 0");
     if (!rc) {
-        diag("pmConfigFileRead() was unsuccessful (from generateSimpleCell())");
+        rc = pmConfigFileRead(&cell->hdu->format, "../dataFiles/camera0/format0.config", "Camera format 0");
+        if (!rc) {
+            diag("pmConfigFileRead() was unsuccessful (from generateSimpleCell())");
+	}
     }
 
@@ -102,7 +101,6 @@
 
     //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.
+    // You shouldn't have to remove the key from the metadata.
     psMetadataRemoveKey(cell->concepts, "CELL.TRIMSEC");
     psMetadataAddPtr(cell->concepts, PS_LIST_TAIL|PS_META_REPLACE, "CELL.TRIMSEC", PS_DATA_REGION, "I am a region", region);
@@ -122,19 +120,9 @@
     psMetadataAddS32(chip->analysis, PS_LIST_HEAD, MISC_NAME, 0, NULL, MISC_NUM);
     psMetadataAddS32(chip->concepts, PS_LIST_HEAD, MISC_NAME, 0, NULL, MISC_NUM);
-//    chip->hdu = pmHDUAlloc("chipExtName");
-//
-//    bool rc = pmConfigFileRead(&chip->hdu->format, "data/camera0/format0.config", "Camera format 0");
-//    if (!rc) {
-//        diag("pmConfigFileRead() was unsuccessful (from generateSimpleChip())");
-//    }
-//
+
     psArrayRealloc(chip->cells, NUM_CELLS);
     for (int i = 0 ; i < NUM_CELLS ; i++) {
-        chip->cells->data[i] = generateSimpleCell(chip);
-    }
-
-    // XXX: Add code to initialize chip pmConcepts
-
-
+        chip->cells->data[i] = psMemDecrRefCounter((psPtr) generateSimpleCell(chip));
+    }
     return(chip);
 }
@@ -153,50 +141,11 @@
     psMetadataAddS32((psMetadata *) fpa->camera, PS_LIST_HEAD, MISC_NAME, 0, NULL, MISC_NUM);
     psMetadataAddS32(fpa->concepts, PS_LIST_HEAD, MISC_NAME, 0, NULL, MISC_NUM);
-//    fpa->hdu = pmHDUAlloc("fpaExtName");
-//
-//    bool rc = pmConfigFileRead(&fpa->hdu->format, "data/camera0/format0.config", "Camera format 0");
-//    if (!rc) {
-//        diag("pmConfigFileRead() was unsuccessful (from generateSimpleFPA())");
-//    }
 
     psArrayRealloc(fpa->chips, NUM_CHIPS);
     for (int i = 0 ; i < NUM_CHIPS ; i++) {
-        fpa->chips->data[i] = generateSimpleChip(fpa);
-    }
-
-    // XXX: Eventually, when you finish the pmConcepts tests, add full concept
-    // reading code from wherever.
+        fpa->chips->data[i] = psMemDecrRefCounter((psPtr) generateSimpleChip(fpa));
+    }
     pmConceptsBlankFPA(fpa);
-//    bool mdok;
-//    psMetadata *fileData = psMetadataLookupMetadata(&mdok, fpa->hdu->format, "FILE");
-//    char *fpaNameHdr = psMetadataLookupStr(&mdok, fileData, "FPA.NAME");
-//    psMetadataAddStr(fpa->concepts, PS_LIST_TAIL, "FPA.NAME", PS_META_REPLACE, NULL, fpaNameHdr);
-
     return(fpa);
-}
-
-// 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);
 }
 
@@ -207,48 +156,48 @@
     psLogSetLevel(PS_LOG_INFO);
     psTraceSetLevel("err", ERR_TRACE_LEVEL);
-    plan_tests(72);
+    plan_tests(40);
+
 
     // ----------------------------------------------------------------------
-    // int pmFPAFindChip(const pmFPA *fpa, const char *name)
-    {
-        psMemId id = psMemGetId();
-        int rc = pmFPAFindChip(NULL, "bogus");
-        ok(-1 == rc, "pmFPAFindChip() returns -1 with NULL pmFPA input param");
-        ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
-    }
-
-
-    // ----------------------------------------------------------------------
-    // int pmFPAFindChip(const pmFPA *fpa, const char *name)
+    // pmFPAFindChip() tests
+    // Call pmFPAFindChip() with NULL pmFPA input parameter
+    {
+        psMemId id = psMemGetId();
+        int rc = pmFPAFindChip(NULL, "chip-0");
+        ok(-1 == rc, "pmFPAFindChip() returns -1 with NULL pmFPA input parameter");
+        ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
+    }
+
+
+    // Call pmFPAFindChip() with bogus chip name
+    {
+        psMemId id = psMemGetId();
+        pmFPA* fpa = generateSimpleFPA(NULL);
+        int rc = pmFPAFindChip(fpa, "bogus");
+        ok(-1 == rc, "pmFPAFindChip() returns -1 with bogus chip name");
+        psFree(fpa);
+        ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
+    }
+
+
+    // Call pmFPAFindChip() with NULL chip name
     {
         psMemId id = psMemGetId();
         // Generate the pmFPA heirarchy
-        psMetadata *camera = psMetadataAlloc();
-        pmFPA* fpa = generateSimpleFPA(camera);
-        pmChip *chip = fpa->chips->data[0];
-        pmCell *cell = chip->cells->data[0];
-        ok(fpa != NULL, "Allocated a pmFPA successfully");
-        ok(chip != NULL, "Allocated a pmChip successfully");
-        ok(cell != NULL, "Allocated a pmCell successfully");
+        pmFPA* fpa = generateSimpleFPA(NULL);
+        ok(fpa != NULL, "Allocated a pmFPA successfully");
         int rc = pmFPAFindChip(fpa, NULL);
         ok(-1 == rc, "pmFPAFindChip() returns -1 with NULL name input param");
-        myFreeFPA(fpa);
-        psFree(camera);
-        ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
-    }
-
-
-    // ----------------------------------------------------------------------
-    // int pmFPAFindChip(const pmFPA *fpa, const char *name)
+        psFree(fpa);
+        ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
+    }
+
+
+    // Call pmFPAFindChip() with acceptable input parameters
     {
         psMemId id = psMemGetId();
         // Generate the pmFPA heirarchy
-        psMetadata *camera = psMetadataAlloc();
-        pmFPA* fpa = generateSimpleFPA(camera);
-        pmChip *chip = fpa->chips->data[0];
-        pmCell *cell = chip->cells->data[0];
-        ok(fpa != NULL, "Allocated a pmFPA successfully");
-        ok(chip != NULL, "Allocated a pmChip successfully");
-        ok(cell != NULL, "Allocated a pmCell successfully");
+        pmFPA* fpa = generateSimpleFPA(NULL);
+        ok(fpa != NULL, "Allocated a pmFPA successfully");
         // Set unique chip names
         for (int chipID = 0 ; chipID < fpa->chips->n ; chipID++) {
@@ -267,6 +216,5 @@
 	}
 
-        myFreeFPA(fpa);
-        psFree(camera);
+        psFree(fpa);
         ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
     }
@@ -275,20 +223,30 @@
 
     // ----------------------------------------------------------------------
-    // int pmChipFindCell(const pmChip *chip, const char *name)
-    {
-        psMemId id = psMemGetId();
-        int rc = pmChipFindCell(NULL, "bogus");
+    // pmChipFindCell() tests
+    // Call pmChipFindCell() with bogus cell name
+    {
+        psMemId id = psMemGetId();
+        int rc = pmChipFindCell(NULL, "cell-0");
         ok(-1 == rc, "pmChipFindCell() returns -1 with NULL pmChip input param");
         ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
     }
 
-
-    // ----------------------------------------------------------------------
-    // int pmChipFindCell(const pmChip *chip, const char *name)
+    // Call pmChipFindCell() with bogus cell name
+    {
+        psMemId id = psMemGetId();
+        pmFPA* fpa = generateSimpleFPA(NULL);
+        pmChip *chip = fpa->chips->data[0];
+        int rc = pmChipFindCell(chip, "bogus");
+        ok(-1 == rc, "pmChipFindCell() returns -1 with bogus cell name");
+        psFree(fpa);
+        ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
+    }
+
+
+    // Call pmChipFindCell() with NULL cell name
     {
         psMemId id = psMemGetId();
         // Generate the pmChip heirarchy
-        psMetadata *camera = psMetadataAlloc();
-        pmFPA* fpa = generateSimpleFPA(camera);
+        pmFPA* fpa = generateSimpleFPA(NULL);
         pmChip *chip = fpa->chips->data[0];
         pmCell *cell = chip->cells->data[0];
@@ -298,17 +256,14 @@
         int rc = pmChipFindCell(chip, NULL);
         ok(-1 == rc, "pmChipFindCell() returns -1 with NULL name input param");
-        myFreeFPA(fpa);
-        psFree(camera);
-        ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
-    }
-
-
-    // ----------------------------------------------------------------------
-    // int pmChipFindCell(const pmChip *chip, const char *name)
+        psFree(fpa);
+        ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
+    }
+
+
+    // Call pmChipFindCell() with acceptable input parameters
     {
         psMemId id = psMemGetId();
         // Generate the pmChip heirarchy
-        psMetadata *camera = psMetadataAlloc();
-        pmFPA* fpa = generateSimpleFPA(camera);
+        pmFPA* fpa = generateSimpleFPA(NULL);
         pmChip *chip = fpa->chips->data[0];
         pmCell *cell = chip->cells->data[0];
@@ -332,8 +287,7 @@
 	}
 
-        myFreeFPA(fpa);
-        psFree(camera);
-        ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
-    }
-
-}
+        psFree(fpa);
+        ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
+    }
+
+}
