Index: /trunk/psLib/test/collections/tst_psDlist.c
===================================================================
--- /trunk/psLib/test/collections/tst_psDlist.c	(revision 901)
+++ /trunk/psLib/test/collections/tst_psDlist.c	(revision 902)
@@ -6,6 +6,6 @@
  *  @author Robert DeSonia, MHPCC
  *
- *  @version $Revision: 1.1 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2004-06-04 23:50:23 $
+ *  @version $Revision: 1.2 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2004-06-07 23:20:21 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -15,8 +15,15 @@
 #include "pslib.h"
 
+void printListInt(psDlist* list);
+
+
 static int testDlistAlloc(void);
+static int testDlistAdd(void);
+static int testDlistGet(void);
 
 testDescription tests[] = {
                               {testDlistAlloc,"487-testDlistAlloc",0},
+                              {testDlistAdd,"488-testDlistAdd",0},
+                              {testDlistGet,"489-testDlistGet",0},
                               {NULL}
                           };
@@ -25,6 +32,4 @@
 {
     psSetLogLevel(PS_LOG_INFO);
-
-    testDlistAlloc();
 
     if (! runTestSuite(stderr,"psDlist",tests)) {
@@ -103,11 +108,274 @@
 }
 
-int testpsDlistAdd(void)
-{
+int testDlistAdd(void)
+{
+    int currentId = psMemGetId();
+    psDlist* list = NULL;
+    int* data;
 
     psLogMsg(__func__,PS_LOG_INFO,"psDlistAdd shall add an element to list");
 
-
+    /*
+        psDlistAdd(list,data,where) should be tested in the instance where:
+
+        1. list is NULL (error)
+        2. data is NULL (error, list should not grow)
+        3. where is PS_DLIST_HEAD or PS_DLIST_TAIL
+        4. where is not PS_DLIST_* but <0
+        5. where is >0
+    */
+
+    //  1. list is NULL (error)
+    list = psDlistAdd(NULL,data,PS_DLIST_HEAD);
+
+    if (list != NULL) {
+        psError(__func__,"psDlistAdd was given a NULL list, but returned a non-NULL list.");
+        return 1;
+    }
+
+    //  2. data is NULL (error, list should not grow)
+    data = psAlloc(sizeof(int));
+    *data = 1;
+    list = psDlistAlloc(data);
+    if (list->size != 1) {
+        psError(__func__,"psDlistAlloc didn't create a list properly.");
+        return 2;
+    }
+
+    list = psDlistAdd(list, NULL,PS_DLIST_HEAD);
+
+    if (list->size != 1) {
+        psError(__func__,"psDlistAdd with a NULL data element changed the list size.");
+        return 3;
+    }
+
+    //  3. where is PS_DLIST_HEAD or PS_DLIST_TAIL
+    data = psAlloc(sizeof(int));
+    *data = 2;
+    list = psDlistAdd(list,data,PS_DLIST_HEAD);
+
+    // verify that the size incremented
+    if (list->size != 2) {
+        psError(__func__,"psDlistAdd didn't increment the size by one");
+        return 4;
+    }
+
+    // verify that the head is the inserted data item
+    if (*(int*)list->head->data != 2) {
+        psError(__func__,"psDlistAdd with PS_DLIST_HEAD didn't insert at the head.");
+        return 5;
+    }
+
+    data = psAlloc(sizeof(int));
+    *data = 3;
+    list = psDlistAdd(list,data,PS_DLIST_TAIL);
+
+    // verify that the size incremented
+    if (list->size != 3) {
+        psError(__func__,"psDlistAdd didn't increment the size by 1");
+        return 6;
+    }
+
+    // verify that the head is still the same
+    if (*(int*)list->head->data != 2) {
+        psError(__func__,"psDlistAdd with PS_DLIST_TAIL modified the head.");
+        return 7;
+    }
+
+    // verify that the tail is the data item inserted
+    if (*(int*)list->tail->data != 3) {
+        psError(__func__,"psDlistAdd with PS_DLIST_TAIL didn't insert at the tail.");
+        return 8;
+    }
+
+    // 4. where is not PS_DLIST_* but <0
+
+    data = psAlloc(sizeof(int));
+    *data = 4;
+
+    psLogMsg(__func__,PS_LOG_INFO,"Following should warn with invalid insert location");
+    list = psDlistAdd(list,data,-10);
+    // verify that the size incremented
+    if (list->size != 4 || *(int*)list->head->data != 4) {
+        printListInt(list);
+        psError(__func__,"psDlistAdd didn't insert to head when where was invalid.");
+        return 9;
+    }
+
+    // 5. where is >0
+    data = psAlloc(sizeof(int));
+    *data = 5;
+    list = psDlistAdd(list,data,1);
+    // verify that the size incremented
+    if (list->size != 5 || *(int*)list->head->next->data != 5) {
+        printListInt(list);
+        psError(__func__,"psDlistAdd didn't insert to position #1.");
+        return 9;
+    }
+
+    data = psAlloc(sizeof(int));
+    *data = 6;
+    list = psDlistAdd(list,data,4);
+    // verify that the size incremented
+    if (list->size != 6  || *(int *)list->head->next->next->next->next->data != 6) {
+        printListInt(list);
+        psError(__func__,"psDlistAdd didn't insert to position #4.");
+        return 9;
+    }
+
+    data = psAlloc(sizeof(int));
+    *data = 7;
+    list = psDlistAdd(list,data,2);
+    // verify that the size incremented
+    if (list->size != 7  || *(int *)list->head->next->next->data != 7) {
+        printListInt(list);
+        psError(__func__,"psDlistAdd didn't insert to position #2.");
+        return 9;
+    }
+
+    data = psAlloc(sizeof(int));
+    *data = 7;
+    psLogMsg(__func__,PS_LOG_INFO,"Following should be a warning.");
+    list = psDlistAdd(list,data,9);
+    // verify that the size incremented
+    if (list->size != 8) {
+        printListInt(list);
+        psError(__func__,"psDlistAdd didn't insert to position #9.");
+        return 9;
+    }
+
+    psDlistFree(list, PS_FREE);
+
+    psMemCheckLeaks(currentId,NULL,NULL);
+    psMemCheckCorruption(1);
 
     return 0;
 }
+
+void printListInt(psDlist* list)
+{
+    int* data = NULL;
+    bool first = true;
+
+    psDlistSetIterator(list,PS_DLIST_HEAD);
+    data = psDlistGetCurrent(list);
+
+    while ( data != NULL ) {
+        if (!first) {
+            printf(", %d",*(int*)data);
+        } else {
+            printf("%d",*(int*)data);
+            first = false;
+        }
+        data = psDlistGetNext(list);
+    }
+
+    printf(".\n");
+}
+
+
+int testDlistGet(void)
+{
+    int currentId = psMemGetId();
+    psDlist* list = NULL;
+    int* data;
+
+    /*
+     psDlistGet(list,which) shall be tested with the following instances
+
+        1. list is NULL.
+        2. which>0 and which<list.n.
+        3. which>list.n.
+        4. which=PS_DLIST_HEAD
+        5. which=PS_DLIST_NEXT
+        6. which=PS_DLIST_TAIL
+        7. which=PS_DLIST_PREV
+        8. which<0 and not any PS_DLIST_* values
+    */
+
+    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");
+    if (psDlistGet(list,PS_DLIST_HEAD) != NULL) {
+        psError(__func__,"psDlistGet didn't return NULL given a NULL list.");
+        return 1;
+    };
+
+    // create a list
+    data = psAlloc(sizeof(int));
+    *data = 0;
+    list = psDlistAlloc(data);
+
+    data = psAlloc(sizeof(int));
+    *data = 1;
+    list = psDlistAdd(list,data,PS_DLIST_TAIL);
+
+    data = psAlloc(sizeof(int));
+    *data = 2;
+    list = psDlistAdd(list,data,PS_DLIST_TAIL);
+
+    data = psAlloc(sizeof(int));
+    *data = 3;
+    list = psDlistAdd(list,data,PS_DLIST_TAIL);
+
+    //  2. which>0 and which<list.n.
+    data = (int*)psDlistGet(list,3);
+    if (data == NULL || *data != 3) {
+        psError(__func__,"psDlistGet failed with which=3");
+        return 2;
+    }
+    data = (int*)psDlistGet(list,1);
+    if (data == NULL || *data != 1) {
+        psError(__func__,"psDlistGet failed with which=1");
+        return 3;
+    }
+
+    //  3. which>=list.n.
+    data = (int*)psDlistGet(list,5);
+    if (data != NULL) {
+        psError(__func__,"psDlistGet failed with which=5");
+        return 4;
+    }
+    data = (int*)psDlistGet(list,4);
+    if (data != NULL) {
+        psError(__func__,"psDlistGet failed with which=4");
+        return 5;
+    }
+
+    //  4. which=PS_DLIST_HEAD
+    data = (int*)psDlistGet(list,PS_DLIST_HEAD);
+    if (data == NULL || *data != 0) {
+        psError(__func__,"psDlistGet failed with which=PS_DLIST_HEAD");
+        return 6;
+    }
+
+    //  5. which=PS_DLIST_NEXT
+    data = (int*)psDlistGet(list,PS_DLIST_NEXT);
+    if (data == NULL || *data != 1) {
+        psError(__func__,"psDlistGet failed with which=PS_DLIST_NEXT");
+        return 7;
+    }
+
+    //  6. which=PS_DLIST_TAIL
+    data = (int*)psDlistGet(list,PS_DLIST_TAIL);
+    if (data == NULL || *data != 3) {
+        psError(__func__,"psDlistGet failed with which=PS_DLIST_TAIL");
+        return 8;
+    }
+
+    //  7. which=PS_DLIST_PREV
+    data = (int*)psDlistGet(list,PS_DLIST_PREVIOUS);
+    if (data == NULL || *data != 2) {
+        psError(__func__,"psDlistGet failed with which=PS_DLIST_PREV");
+        return 9;
+    }
+
+    psDlistFree(list,PS_FREE);
+
+    psMemCheckLeaks(currentId,NULL,NULL);
+    psMemCheckCorruption(1);
+
+    return 0;
+}
