Index: /trunk/psLib/test/collections/tst_psList.c
===================================================================
--- /trunk/psLib/test/collections/tst_psList.c	(revision 3062)
+++ /trunk/psLib/test/collections/tst_psList.c	(revision 3063)
@@ -6,6 +6,6 @@
  *  @author Robert DeSonia, MHPCC
  *
- *  @version $Revision: 1.21 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2004-12-11 01:24:15 $
+ *  @version $Revision: 1.22 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2005-01-20 00:30:05 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -26,4 +26,6 @@
 static psS32 testListFree(void);
 static psS32 testListSort(void);
+static psS32 testListAddAfter(void);
+static psS32 testListAddBefore(void);
 
 testDescription tests[] = {
@@ -36,4 +38,6 @@
                               {testListFree,627,"psListFree",0,false},
                               {testListSort,624,"psListSort",0,false},
+                              {testListAddAfter,811,"psListAddAfter",0,false},
+                              {testListAddBefore,811,"psListAddBefore",0,false},
                               {NULL}
                           };
@@ -63,5 +67,5 @@
     // empty psList struct with head=tail=NULL and n=0. Otherwise, it shall
     // return a psList of one element (head=tail=data, n=1).
-
+    // Test requirement SDR-167
     list = psListAlloc(NULL);
     if (list == NULL) {
@@ -69,10 +73,8 @@
         return 1;
     }
-
     if (list->head != NULL || list->tail != NULL) {
         psError(PS_ERR_UNKNOWN, true,"head and/or tail was not NULL for empty list.");
         return 2;
     }
-
     if (list->size != 0) {
         psError(PS_ERR_UNKNOWN, true,"size of list wasn't zero for empty list.");
@@ -82,4 +84,5 @@
     psFree(list);
 
+    // Test requirement SDR-165
     list = psListAlloc(data);
     if (list == NULL) {
@@ -109,8 +112,151 @@
     }
 
-
-    psFree(list);
-
-    psFree(data);
+    psFree(list);
+
+    psFree(data);
+
+    return 0;
+}
+
+psS32 testListAddAfter(void)
+{
+    psList* list = NULL;
+    psS32*  data = NULL;
+    psS32*  data1 = NULL;
+    psS32*  data2 = NULL;
+    psListIterator *currentIterator = NULL;
+
+    data = psAlloc(sizeof(psS32));
+    *data = 1;
+    data1 = psAlloc(sizeof(psS32));
+    *data1 = 2;
+    data2 = psAlloc(sizeof(psS32));
+    *data2 = 3;
+
+    list = psListAlloc(data);
+    currentIterator = psListIteratorAlloc(list,PS_LIST_HEAD);
+
+    // Add data after HEAD and verify data
+    // Test requirement SDR-755
+    if(!psListAddAfter(currentIterator,data1)) {
+        psError(PS_ERR_UNKNOWN,true,"psListAddAfter failed to add item");
+        return 1;
+    }
+    if(*(psS32*)list->head->next->data != 2) {
+        psError(PS_ERR_UNKNOWN,true,"psListAddAfter did not add the item properly");
+        return 2;
+    }
+    // Test requirement SDR-175
+    if (psMemGetRefCounter(data1) != 2) {
+        psError(PS_ERR_UNKNOWN, true,"psListAddAfter didn't increment the data reference count.");
+        return 20;
+    }
+    psFree(currentIterator);
+
+    currentIterator = psListIteratorAlloc(list,PS_LIST_TAIL);
+
+    // Add data after TAIL and verify data
+    if(!psListAddAfter(currentIterator,data2)) {
+        psError(PS_ERR_UNKNOWN,true,"psListAddAfter failed to add item");
+        return 3;
+    }
+    if(*(psS32*)list->tail->data != 3) {
+        psError(PS_ERR_UNKNOWN,true,"psListAddAfter did not add the item properly");
+        return 4;
+    }
+    // Test requirement SDR-175
+    if (psMemGetRefCounter(data2) != 2) {
+        psError(PS_ERR_UNKNOWN, true,"psListAddAfter didn't increment the data reference count.");
+        return 40;
+    }
+
+    // Verify error message generated with data pointer is NULL
+    psLogMsg(__func__,PS_LOG_INFO,"NULL data pointer should generate error message");
+    if(psListAddAfter(currentIterator,NULL)) {
+        psError(PS_ERR_UNKNOWN,true,"psListAddAfter should have generated error.");
+        return 5;
+    }
+
+    // Verify error message generated with iterator NULL
+    psLogMsg(__func__,PS_LOG_INFO,"NULL iterator should generate error message");
+    if(psListAddAfter(NULL,data2)) {
+        psError(PS_ERR_UNKNOWN,true,"psListAddAfter should have generated error.");
+        return 6;
+    }
+
+    psFree(data);
+    psFree(data1);
+    psFree(data2);
+    psFree(list);
+
+    return 0;
+}
+
+psS32 testListAddBefore(void)
+{
+    psList* list = NULL;
+    psS32*  data1 = NULL;
+    psS32*  data2 = NULL;
+    psListIterator *currentIterator = NULL;
+
+    data1 = psAlloc(sizeof(psS32));
+    *data1 = 2;
+    data2 = psAlloc(sizeof(psS32));
+    *data2 = 3;
+
+    list = psListAlloc(NULL);
+    currentIterator = psListIteratorAlloc(list,PS_LIST_HEAD);
+
+    // Add data before HEAD and verify data
+    // Test requirement SDR-756
+    if(!psListAddBefore(currentIterator,data1)) {
+        psError(PS_ERR_UNKNOWN,true,"psListAddBefore failed to add item");
+        return 1;
+    }
+    if(*(psS32*)list->head->data != 2) {
+        psError(PS_ERR_UNKNOWN,true,"psListAddBefore did not add the item properly");
+        return 2;
+    }
+    // Test requirement SDR-175
+    if (psMemGetRefCounter(data1) != 2) {
+        psError(PS_ERR_UNKNOWN, true,"psListAddBefore didn't increment the data reference count.");
+        return 20;
+    }
+    psFree(currentIterator);
+
+    currentIterator = psListIteratorAlloc(list,PS_LIST_TAIL);
+
+    // Add data after TAIL and verify data
+    if(!psListAddBefore(currentIterator,data2)) {
+        psError(PS_ERR_UNKNOWN,true,"psListAddBefore failed to add item");
+        return 3;
+    }
+    if(*(psS32*)list->tail->prev->data != 3) {
+        psError(PS_ERR_UNKNOWN,true,"psListAddBefore did not add the item properly");
+        return 4;
+    }
+    // Test requirement SDR-175
+    if (psMemGetRefCounter(data2) != 2) {
+        psError(PS_ERR_UNKNOWN, true,"psListAddBefore didn't increment the data reference count.");
+        return 40;
+    }
+
+    // Verify error message generated with data pointer is NULL
+    psLogMsg(__func__,PS_LOG_INFO,"NULL data pointer should generate error message");
+    if(psListAddBefore(currentIterator,NULL)) {
+        psError(PS_ERR_UNKNOWN,true,"psListAddBefore should have generated error.");
+        return 5;
+    }
+
+    // Verify error message generated with iterator NULL
+    psLogMsg(__func__,PS_LOG_INFO,"NULL iterator should generate error message");
+    if(psListAddBefore(NULL,data2)) {
+        psError(PS_ERR_UNKNOWN,true,"psListAddBefore should have generated error.");
+        return 6;
+    }
+
+    psFree(data1);
+    psFree(data2);
+    psFree(list);
 
     return 0;
@@ -167,5 +313,5 @@
         return 21;
     }
-
+    // Test requirement SDR-175
     if (psMemGetRefCounter(data) != 2) {
         psError(PS_ERR_UNKNOWN, true,"psListAdd didn't increment the data reference count.");
@@ -192,5 +338,5 @@
         return 21;
     }
-
+    // Test requirement SDR-175
     if (psMemGetRefCounter(data) != 2) {
         psError(PS_ERR_UNKNOWN, true,"psListAdd didn't increment the data reference count.");
@@ -226,4 +372,5 @@
         return 30;
     }
+    // Test requirement SDR-175
     if (psMemGetRefCounter(data) != 1) {
         psError(PS_ERR_UNKNOWN, true,"psListAdd incremented the data reference count.");
@@ -246,5 +393,5 @@
         return 30;
     }
-
+    // Test requirement SDR-175
     if (psMemGetRefCounter(data) != 2) {
         psError(PS_ERR_UNKNOWN, true,"psListAdd didn't increment the data reference count.");
@@ -265,4 +412,5 @@
         return 31;
     }
+    // Test requirment SDR-175
     if (psMemGetRefCounter(data) != 2) {
         psError(PS_ERR_UNKNOWN, true,"psListAdd didn't increment the data reference count.");
@@ -279,8 +427,10 @@
     data = psAlloc(sizeof(psS32));
     *data = 7;
+    // Test requirment SDR-169
     if ( ! psListAdd(list,2,data) ) {
         psError(PS_ERR_UNKNOWN, true,"psListAdd failed to add data to 2 position.");
         return 32;
     }
+    // Test requirment SDR-175
     if (psMemGetRefCounter(data) != 2) {
         psError(PS_ERR_UNKNOWN, true,"psListAdd didn't increment the data reference count.");
@@ -295,6 +445,7 @@
     }
 
-    data = psAlloc(sizeof(psS32));
-    *data = 7;
+    // Test requirement SDR-757
+    data = psAlloc(sizeof(psS32));
+    *data = 8;
     psLogMsg(__func__,PS_LOG_INFO,"Following should be a warning.");
 
@@ -303,18 +454,16 @@
         return 30;
     }
-
+    // Test requirment SDR-175
     if (psMemGetRefCounter(data) != 2) {
         psError(PS_ERR_UNKNOWN, true,"psListAdd didn't increment the data reference count.");
         return 29;
     }
-
-    psFree(data);
-
-    // verify that the size incremented
-    if (list->size != 7) {
-        printListInt(list);
-        psError(PS_ERR_UNKNOWN, true,"psListAdd didn't insert to position #9.");
+    if(list->size != 7 || *(psS32 *)list->tail->data != 8) {
+        printListInt(list);
+        psError(PS_ERR_UNKNOWN,true,"psListAdd didn't place added item at tail.");
         return 12;
     }
+
+    psFree(data);
 
     psFree(list);
