Index: trunk/psLib/test/dataIO/tst_psDB.c
===================================================================
--- trunk/psLib/test/dataIO/tst_psDB.c	(revision 4383)
+++ trunk/psLib/test/dataIO/tst_psDB.c	(revision 4390)
@@ -9,6 +9,6 @@
  *  @author Aaron Culliney, MHPCC
  *
- *  @version $Revision: 1.27 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2005-06-24 21:31:13 $
+ *  @version $Revision: 1.28 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2005-06-25 01:17:24 $
  *
  *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -109,5 +109,5 @@
                               {TPDBDumpCols,       851,  "dbDumpCols",        0, false},
                               {TPDBUpdateRows,     852,  "dbUpdateRows",      0, false},
-                              {TPDBDeleteRows,      -13, "dbDeleteRows",      0, false},
+                              {TPDBDeleteRows,     853,  "dbDeleteRows",      0, false},
                               //{TPDBCreate,        -14, "dbCreate",          0, false},
                               //{TPDBDrop,          -15, "dbDrop",            0, false},
@@ -1992,66 +1992,173 @@
 }
 
-// Testpoint #XXX, TPDBDeleteRows shall update rows in a test table ...
+// Testpoint #853, TPDBDeleteRows shall update rows in a test table ...
 psS32 TPDBDeleteRows( void )
 {
-    psS32 failed = 0;
-    psDB *dbh = NULL;
-    const char* table = "table11";
-    psArray *ary=NULL, *rowSet=NULL;
-    psMetadata *where=NULL, *row=NULL, *md = _get_CreateTableMetadata();
-
+    psDB*         dbh       = NULL;
+    const char*   table     = "table11";
+    psArray*      ary       = NULL;
+    psArray*      rowSet    = NULL;
+    psMetadata*   where     = NULL;
+    psMetadata*   row       = NULL;
+    psMetadata*   md        = NULL;
+    int           chgRows   = 0;
+
+    // Create database table definition
+    md = _get_CreateTableMetadata();
+
+    // Initialize database connection
     dbh = _init_psDB();
     if (dbh == NULL) {
+        psError(PS_ERR_UNKNOWN,true,"Did not expect return NULL for initialize database");
         return 1;
     }
 
-    psLogMsg( __func__, PS_LOG_INFO, "psDBDeleteRows shall delete rows from a test table.\n" );
-
-    failed = ! psDBCreateTable(dbh, table, md);
-    if (!failed) {
-        rowSet = psArrayAlloc(3);
-        rowSet->n = 0;
-
-        row = _get_const_row1();
-        psArrayAdd(rowSet, 0, row);
-        psFree(row);
-
-        row = _get_const_row2();
-        psArrayAdd(rowSet, 0, row);
-        psFree(row);
-
-        row = _get_row();
-        psArrayAdd(rowSet, 0, row);
-        psFree(row);
-
-        failed = ! psDBInsertRows(dbh, table, rowSet);
-        if (!failed) {
-            where = _get_where();
-            failed = (psDBDeleteRows(dbh, table, where) < 0);
-
-            ary = psDBDumpRows(dbh, table);
-            if (ary == NULL) {
-                failed = 1;
-            } else {
-                if (ary->n != 2) {
-                    psLogMsg( __func__, PS_LOG_INFO, "oops, did not delete stuff!\n" );
-                    failed = 1;
-                } else {
-                    psLogMsg( __func__, PS_LOG_INFO, "found expected two-row table.\n" );
-                }
-
-                psFree(ary);
-            }
-
-            psFree(where);
-        }
-        psFree(rowSet);
-        psDBDropTable(dbh, table);
-    }
+    // Create test table
+    if(!psDBCreateTable(dbh, table, md)) {
+        psError(PS_ERR_UNKNOWN,true,"Did not expect return false for creating test table");
+        psDBCleanup(dbh);
+        return 2;
+    }
+
+    // Create known data rows to put into test table
+    rowSet = psArrayAlloc(3);
+    rowSet->n = 0;
+    row = _get_const_row1();
+    psArrayAdd(rowSet, 0, row);
+    psFree(row);
+    row = _get_const_row2();
+    psArrayAdd(rowSet, 0, row);
+    psFree(row);
+    row = _get_row();
+    psArrayAdd(rowSet, 0, row);
+    psFree(row);
+    if(!psDBInsertRows(dbh, table, rowSet)) {
+        psError(PS_ERR_UNKNOWN,true,"Did not expect return false for inserting data into table");
+        psDBDropTable(dbh,table);
+        psDBCleanup(dbh);
+        return 3;
+    }
+
+    // Create where clause to specify the row to remove
+    where = _get_where();
+
+    // Delete row with valid arguments
+    chgRows = psDBDeleteRows(dbh,table,where);
+    if(chgRows != 1) {
+        psError(PS_ERR_UNKNOWN,true,"Deleted rows %ld not as expected %ld",
+                chgRows,1);
+        psDBDropTable(dbh,table);
+        psDBCleanup(dbh);
+        return 4;
+    }
+    // Verify table contents
+    ary = psDBDumpRows(dbh, table);
+    if (ary == NULL) {
+        psError(PS_ERR_UNKNOWN,true,"Did not expect return NULL for dump rows");
+        psDBDropTable(dbh,table);
+        psDBCleanup(dbh);
+        return 5;
+    }
+    if (ary->n != 2) {
+        psError(PS_ERR_UNKNOWN,true,"Remaining rows %d not as expected %d",
+                ary->n,2);
+        psDBDropTable(dbh,table);
+        psDBCleanup(dbh);
+        return 6;
+    }
+    psFree(ary);
+
+    // Attempt to delete row just deleted again
+    chgRows = psDBDeleteRows(dbh,table,where);
+    if(chgRows != 0) {
+        psError(PS_ERR_UNKNOWN,true,"Deleted rows %ld not as expected %ld",
+                chgRows,0);
+        psDBDropTable(dbh,table);
+        psDBCleanup(dbh);
+        return 7;
+    }
+    // Verify table contents
+    ary = psDBDumpRows(dbh, table);
+    if (ary == NULL) {
+        psError(PS_ERR_UNKNOWN,true,"Did not expect return NULL for dump rows");
+        psDBDropTable(dbh,table);
+        psDBCleanup(dbh);
+        return 8;
+    }
+    if (ary->n != 2) {
+        psError(PS_ERR_UNKNOWN,true,"Remaining rows %d not as expected %d",
+                ary->n,2);
+        psDBDropTable(dbh,table);
+        psDBCleanup(dbh);
+        return 9;
+    }
+    psFree(ary);
+
+    // Attempt to delete row with NULL database
+    psLogMsg(__func__,PS_LOG_INFO,"Following should generate error message for NULL database");
+    chgRows = psDBDeleteRows(NULL,table,where);
+    if(chgRows > 0) {
+        psError(PS_ERR_UNKNOWN,true,"Deleted rows %ld not as expected %ld",
+                chgRows, -1);
+        psDBDropTable(dbh,table);
+        psDBCleanup(dbh);
+        return 10;
+    }
+
+    // Attempt to delete row with invalid table
+    psLogMsg(__func__,PS_LOG_INFO,"Following should generate error message for invalid table");
+    chgRows = psDBDeleteRows(dbh,"table999",where);
+    if(chgRows > 0) {
+        psError(PS_ERR_UNKNOWN,true,"Deleted rows %ld not as expected %ld",
+                chgRows, -1);
+        psDBDropTable(dbh,table);
+        psDBCleanup(dbh);
+        return 11;
+    }
+
+    // Attempt to delete row with NULL where - deletes all rows
+    chgRows = psDBDeleteRows(dbh,table,NULL);
+    if(chgRows != 2) {
+        psError(PS_ERR_UNKNOWN,true,"Deleted rows %ld not as expected %ld",
+                chgRows, 2);
+        psDBDropTable(dbh,table);
+        psDBCleanup(dbh);
+        return 12;
+    }
+    // Verify table contents
+    ary = psDBDumpRows(dbh, table);
+    if (ary == NULL) {
+        psError(PS_ERR_UNKNOWN,true,"Did not expect return NULL for dump rows");
+        psDBDropTable(dbh,table);
+        psDBCleanup(dbh);
+        return 13;
+    }
+    if (ary->n != 0) {
+        psError(PS_ERR_UNKNOWN,true,"Remaining rows %d not as expected %d",
+                ary->n,0);
+        psDBDropTable(dbh,table);
+        psDBCleanup(dbh);
+        return 14;
+    }
+    psFree(ary);
+
+    // Attempt to delete row with NULL where - deletes all rows from an empty table
+    chgRows = psDBDeleteRows(dbh,table,NULL);
+    if(chgRows != 0) {
+        psError(PS_ERR_UNKNOWN,true,"Deleted rows %ld not as expected %ld",
+                chgRows, 0);
+        psDBDropTable(dbh,table);
+        psDBCleanup(dbh);
+        return 15;
+    }
+
+    psFree(where);
+    psFree(rowSet);
+    psDBDropTable(dbh, table);
 
     psFree(md);
     psDBCleanup(dbh);
 
-    return failed;
+    return 0;
 }
 
