Index: /trunk/psLib/test/astronomy/tst_psAstrometry.c
===================================================================
--- /trunk/psLib/test/astronomy/tst_psAstrometry.c	(revision 2053)
+++ /trunk/psLib/test/astronomy/tst_psAstrometry.c	(revision 2054)
@@ -5,6 +5,6 @@
  *  @author Robert DeSonia, MHPCC
  *
- *  @version $Revision: 1.4 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2004-10-12 19:10:00 $
+ *  @version $Revision: 1.5 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2004-10-12 19:28:40 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -21,4 +21,5 @@
 static int testFPAAlloc(void);
 static int testChipAlloc(void);
+static int testCellAlloc(void);
 
 testDescription tests[] = {
@@ -27,4 +28,5 @@
                               {testFPAAlloc,739,"psFPAAlloc",0,false},
                               {testChipAlloc,740,"psChipAlloc",0,false},
+                              {testCellAlloc,741,"psCellAlloc",0,false},
                               {NULL}
                           };
@@ -468,2 +470,160 @@
     return 0;
 }
+
+static int testCellAlloc(void)
+{
+    char* name = "The Kaiser Royal Observatory";
+
+    psTime* now = psTimeGetTime(PS_TIME_UTC);
+
+    psObservatory* obs = psObservatoryAlloc(name,
+                                            20.7*M_PI/180.0, 156.3*M_PI/180.0, 3055.0, 0.0065f);
+
+    psExposure* exp = psExposureAlloc(1.0, 2.0, 3.0, 4.0, 5.0,
+                                      now, 6.0f, 260.0f, 1013.0f, 0.7f, 10.0f, 0.650f, obs);
+
+    psFPA* fpa = psFPAAlloc(8, exp);
+
+    psChip* chip = psChipAlloc(8, fpa);
+
+    // N.B. psChipAlloc made a reference to any of these that it is
+    // referencing, so these are not actually freed here.  Just
+    // these references to the buffers are freed.
+    psFree(fpa);
+    psFree(exp);
+    psFree(obs);
+    psFree(now);
+
+    /*
+        1. invoke psCellAlloc with nReadouts > 0 and parentChip non-NULL. Verify that:
+        a. the readouts array is of the size nReadouts and all elements are NULL.
+        b. parent attribute is set to parentChip parameter and the ref. count 
+           was incremented.
+        c. all other attributes are initialized to NULL or 0.
+    */
+
+    psCell* cell1 = psCellAlloc(8,chip);
+
+    if (cell1 == NULL) {
+        psLogMsg(__func__,PS_LOG_ERROR,"psCellAlloc returned NULL.");
+        return 1;
+    }
+
+    if (cell1->readouts->n != 8) {
+        psLogMsg(__func__,PS_LOG_ERROR,
+                 "psCellAlloc did not set the number of readouts properly.");
+        return 2;
+    }
+
+    for (int lcv=0; lcv < 8; lcv++) {
+        if (cell1->readouts->data[lcv] != NULL) {
+            psLogMsg(__func__,PS_LOG_ERROR,
+                     "psCellAlloc did not set readout %d to NULL.", lcv);
+            return 3;
+        }
+    }
+
+    if (cell1->parent != chip) {
+        psLogMsg(__func__,PS_LOG_ERROR,
+                 "psCellAlloc did not set the parent properly.");
+        return 4;
+    }
+
+    if (psMemGetRefCounter(chip) != 2) {
+        psLogMsg(__func__,PS_LOG_ERROR,
+                 "psCellAlloc did not increment reference counter for parent.");
+        return 5;
+    }
+
+    if (cell1->metadata != NULL) {
+        psLogMsg(__func__,PS_LOG_ERROR,
+                 "psCellAlloc did not set metadata to NULL.");
+        return 6;
+    }
+
+    if (cell1->toChip != NULL) {
+        psLogMsg(__func__,PS_LOG_ERROR,
+                 "psCellAlloc did not set toChip to NULL.");
+        return 7;
+    }
+
+    if (cell1->fromChip != NULL) {
+        psLogMsg(__func__,PS_LOG_ERROR,
+                 "psCellAlloc did not set fromChip to NULL.");
+        return 8;
+    }
+
+    if (cell1->toFPA != NULL) {
+        psLogMsg(__func__,PS_LOG_ERROR,
+                 "psCellAlloc did not set toFPA to NULL.");
+        return 9;
+    }
+
+    if (cell1->toTP != NULL) {
+        psLogMsg(__func__,PS_LOG_ERROR,
+                 "psCellAlloc did not set toTP to NULL.");
+        return 10;
+    }
+
+    /*
+        2. invoke psChipAlloc with nCells = 0. Verify that:
+        a. execution does not halt
+        b. the cells array is of the size of zero.    
+    */
+
+    psCell* cell2 = psCellAlloc(0,chip);
+
+    if (cell2 == NULL) {
+        psLogMsg(__func__,PS_LOG_ERROR,"psCellAlloc returned NULL.");
+        return 11;
+    }
+
+    if (cell2->readouts->n != 0) {
+        psLogMsg(__func__,PS_LOG_ERROR,
+                 "psCellAlloc did not set the number of readouts properly.");
+        return 12;
+    }
+
+    if (cell2->parent != chip) {
+        psLogMsg(__func__,PS_LOG_ERROR,
+                 "psCellAlloc did not set the parent properly.");
+        return 14;
+    }
+
+    if (psMemGetRefCounter(chip) != 3) {
+        psLogMsg(__func__,PS_LOG_ERROR,
+                 "psCellAlloc did not increment reference counter for parent FPA.");
+        return 15;
+    }
+
+    /*
+        3. invoke psChipAlloc with parentFPA = NULL. Verify that parent 
+           attribute is NULL and no error is generated.
+    */
+
+    psCell* cell3 = psCellAlloc(8,NULL);
+
+    if (cell3 == NULL) {
+        psLogMsg(__func__,PS_LOG_ERROR,"psCellAlloc returned NULL.");
+        return 21;
+    }
+
+    if (cell3->readouts->n != 8) {
+        psLogMsg(__func__,PS_LOG_ERROR,
+                 "psCellAlloc did not set the number of cells properly.");
+        return 22;
+    }
+
+    if (cell3->parent != NULL) {
+        psLogMsg(__func__,PS_LOG_ERROR,
+                 "psCellAlloc did not set the parent to NULL.");
+        return 24;
+    }
+
+    psFree(chip);
+    psFree(cell1);
+    psFree(cell2);
+    psFree(cell3);
+
+    return 0;
+}
