Index: /trunk/psLib/test/collections/tst_psDlist.c
===================================================================
--- /trunk/psLib/test/collections/tst_psDlist.c	(revision 902)
+++ /trunk/psLib/test/collections/tst_psDlist.c	(revision 903)
@@ -6,6 +6,6 @@
  *  @author Robert DeSonia, MHPCC
  *
- *  @version $Revision: 1.2 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2004-06-07 23:20:21 $
+ *  @version $Revision: 1.3 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2004-06-08 00:58:39 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -21,4 +21,5 @@
 static int testDlistAdd(void);
 static int testDlistGet(void);
+static int testDlistRemove(void);
 
 testDescription tests[] = {
@@ -26,4 +27,5 @@
                               {testDlistAdd,"488-testDlistAdd",0},
                               {testDlistGet,"489-testDlistGet",0},
+                              {testDlistRemove,"490-testDlistRemove",0},
                               {NULL}
                           };
@@ -294,7 +296,4 @@
     */
 
-    psLogMsg(__func__,PS_LOG_INFO,"psDlistGet(list,which) shall be tested with "
-             "the following instances");
-
     //  1. list is NULL.
     psLogMsg(__func__,PS_LOG_INFO,"Following should be an error");
@@ -380,2 +379,239 @@
     return 0;
 }
+
+int testDlistRemove(void)
+{
+    int currentId = psMemGetId();
+    psDlist* list = NULL;
+    int* data;
+
+    /*
+        psDlistRemove(list,data,which) should be tested under the following conditions:
+
+        1. list is NULL
+        2. which is PS_DLIST_HEAD (remove first element of list)
+        3. which is PS_DLIST_TAIL (remove last element of list)
+        4. which is PS_DLIST_NEXT (element right of cursor [which should be head,tail, and neither])
+        5. which is PS_DLIST_PREV (element left of cursor [which should be head,tail, and neither])
+        6. which is PS_DLIST_UNKNOWN and data=NULL (error)
+        7. which is PS_DLIST_UNKNOWN and data=[head,tail,other list items]
+        8. which is PS_DLIST_UNKNOWN and data!=NULL and data!=any element in list
+
+        In all conditions that are not an error, list.n shall be decremented and only the specified element
+        shall be removed. After each step, list.n should be checked to verify that it is the true
+        number of elements in list.
+    */
+
+    //  1. list is NULL.
+    psLogMsg(__func__,PS_LOG_INFO,"Following should be an error");
+    if (psDlistRemove(list,NULL,PS_DLIST_HEAD) != NULL) {
+        psError(__func__,"psDlistGet didn't return NULL given a NULL list.");
+        return 1;
+    };
+
+    // create a list
+    list = psDlistAlloc(NULL);
+
+    for (int lcv=0;lcv<15;lcv++) {
+        data = psAlloc(sizeof(int));
+        *data = lcv;
+        list = psDlistAdd(list,data,PS_DLIST_TAIL);
+    }
+
+
+    // 2. which is PS_DLIST_HEAD (remove first element of list)
+    data = psDlistRemove(list,NULL,PS_DLIST_HEAD);
+    if (data == NULL || *data != 0) {
+        printListInt(list);
+        psError(__func__,"Failed to remove PS_DLIST_HEAD");
+        return 1;
+    }
+    psFree(data);
+    if (list->size != 14) {
+        printListInt(list);
+        psError(__func__,"Didn't decrement size properly to 14.");
+        return 1;
+    }
+
+    // 3. which is PS_DLIST_TAIL (remove last element of list)
+    data = psDlistRemove(list,NULL,PS_DLIST_TAIL);
+    if (data == NULL || *data != 14) {
+        printListInt(list);
+        psError(__func__,"Failed to remove PS_DLIST_TAIL");
+        return 1;
+    }
+    psFree(data);
+    if (list->size != 13) {
+        printListInt(list);
+        psError(__func__,"Didn't decrement size properly to 13.");
+        return 1;
+    }
+
+    // 4. which is PS_DLIST_NEXT (element right of cursor [which should be head,tail, and neither])
+    psDlistSetIterator(list,PS_DLIST_HEAD);
+    data = psDlistRemove(list,NULL,PS_DLIST_NEXT);
+    if (data == NULL || *data != 2) {
+        printListInt(list);
+        psError(__func__,"Failed to remove PS_DLIST_NEXT @ PS_DLIST_HEAD");
+        return 1;
+    }
+    psFree(data);
+    if (list->size != 12) {
+        printListInt(list);
+        psError(__func__,"Didn't decrement size properly to 12.");
+        return 1;
+    }
+
+    psDlistSetIterator(list,PS_DLIST_TAIL);
+    psLogMsg(__func__,PS_LOG_INFO,"Next message should be an error");
+    data = psDlistRemove(list,NULL,PS_DLIST_NEXT);
+    if (data != NULL) {
+        printListInt(list);
+        psError(__func__,"Removed something with PS_DLIST_NEXT @ PS_DLIST_TAIL");
+        return 1;
+    }
+
+    psDlistSetIterator(list,2);
+    data = psDlistRemove(list,NULL,PS_DLIST_NEXT);
+    if (data == NULL || *data != 5) {
+        printListInt(list);
+        psError(__func__,"Failed to remove PS_DLIST_NEXT @ which=2");
+        return 1;
+    }
+    psFree(data);
+    if (list->size != 11) {
+        printListInt(list);
+        psError(__func__,"Didn't decrement size properly to 11.");
+        return 1;
+    }
+
+    // 5. which is PS_DLIST_PREV (element left of cursor [which should be head,tail, and neither])
+    psDlistSetIterator(list,PS_DLIST_HEAD);
+    psLogMsg(__func__,PS_LOG_INFO,"Next message should be an error");
+    data = psDlistRemove(list,NULL,PS_DLIST_PREVIOUS);
+    if (data != NULL) {
+        printListInt(list);
+        psError(__func__,"removed something for PS_DLIST_PREVIOUS @ PS_DLIST_HEAD");
+        return 1;
+    }
+
+    psDlistSetIterator(list,PS_DLIST_TAIL);
+    data = psDlistRemove(list,NULL,PS_DLIST_PREVIOUS);
+    if (data == NULL || *data != 12) {
+        printListInt(list);
+        psError(__func__,"Failed to remove PS_DLIST_PREVIOUS @ PS_DLIST_TAIL");
+        return 1;
+    }
+    psFree(data);
+    if (list->size != 10) {
+        printListInt(list);
+        psError(__func__,"Didn't decrement size properly to 10.");
+        return 1;
+    }
+
+    psDlistSetIterator(list,2);
+    data = psDlistRemove(list,NULL,PS_DLIST_PREVIOUS);
+    if (data == NULL || *data != 3) {
+        printListInt(list);
+        psError(__func__,"Failed to remove PS_DLIST_PREVIOUS @ which=2");
+        return 1;
+    }
+    psFree(data);
+    if (list->size != 9) {
+        printListInt(list);
+        psError(__func__,"Didn't decrement size properly to 9.");
+        return 1;
+    }
+
+    // 6. which is PS_DLIST_UNKNOWN and data=NULL (error)
+    psLogMsg(__func__,PS_LOG_INFO,"Next message should be an error");
+    data = psDlistRemove(list,NULL,PS_DLIST_UNKNOWN);
+    if (data != NULL) {
+        printListInt(list);
+        psError(__func__,"removed something for PS_DLIST_UNKNOWN with data=NULL");
+        return 1;
+    }
+
+    // 7. which is PS_DLIST_UNKNOWN and data=[head,tail,other list items]
+    data = psDlistGet(list,PS_DLIST_HEAD);
+    data = psDlistRemove(list,data,PS_DLIST_UNKNOWN);
+    if (data == NULL || *data != 1) {
+        printListInt(list);
+        psError(__func__,"Failed to remove PS_DLIST_UNKNOWN @ PS_DLIST_HEAD");
+        return 1;
+    }
+    psFree(data);
+    if (list->size != 8) {
+        printListInt(list);
+        psError(__func__,"Didn't decrement size properly to 8.");
+        return 1;
+    }
+
+    data = psDlistGet(list,PS_DLIST_TAIL);
+    data = psDlistRemove(list,data,PS_DLIST_UNKNOWN);
+    if (data == NULL || *data != 13) {
+        printListInt(list);
+        psError(__func__,"Failed to remove PS_DLIST_UNKNOWN @ PS_DLIST_TAIL");
+        return 1;
+    }
+    psFree(data);
+    if (list->size != 7) {
+        printListInt(list);
+        psError(__func__,"Didn't decrement size properly to 7.");
+        return 1;
+    }
+
+    psDlistSetIterator(list,PS_DLIST_HEAD);
+    data = psDlistGet(list,PS_DLIST_NEXT);
+
+    data = psDlistRemove(list,data,PS_DLIST_UNKNOWN);
+    if (data == NULL || *data != 6) {
+        printListInt(list);
+        psError(__func__,"Failed to remove PS_DLIST_UNKNOWN @ which=1");
+        return 1;
+    }
+    psFree(data);
+    if (list->size != 6) {
+        printListInt(list);
+        psError(__func__,"Didn't decrement size properly to 6.");
+        return 1;
+    }
+
+    // 8. which is PS_DLIST_UNKNOWN and data!=NULL and data!=any element in list
+    psLogMsg(__func__,PS_LOG_INFO,"Next message should be an error");
+    data = psDlistRemove(list,data,PS_DLIST_UNKNOWN);
+    if (data != NULL) {
+        printListInt(list);
+        psError(__func__,"removed something for PS_DLIST_UNKNOWN with previously removed item");
+        return 1;
+    }
+
+    // clear out the list
+    psFree(psDlistRemove(list,NULL,PS_DLIST_HEAD));
+    psFree(psDlistRemove(list,NULL,PS_DLIST_HEAD));
+    psFree(psDlistRemove(list,NULL,PS_DLIST_HEAD));
+    psFree(psDlistRemove(list,NULL,PS_DLIST_HEAD));
+    psFree(psDlistRemove(list,NULL,PS_DLIST_HEAD));
+
+    data = psDlistRemove(list,data,PS_DLIST_HEAD);
+    if (data == NULL || *data != 11) {
+        printListInt(list);
+        psError(__func__,"Failed to remove last element");
+        return 1;
+    }
+    psFree(data);
+
+    if (list->size != 0) {
+        printListInt(list);
+        psError(__func__,"Didn't remove all the elements.");
+        return 1;
+    }
+
+    psDlistFree(list,PS_FREE);
+
+    psMemCheckLeaks(currentId,NULL,NULL);
+    psMemCheckCorruption(1);
+
+    return 0;
+
+}
