Index: /trunk/psLib/test/collections/tst_psVectorSort_02.c
===================================================================
--- /trunk/psLib/test/collections/tst_psVectorSort_02.c	(revision 2676)
+++ /trunk/psLib/test/collections/tst_psVectorSort_02.c	(revision 2677)
@@ -6,10 +6,14 @@
  *     A)  Create vectors
  *     B)  Sort integer vector of indices based on pre-sort order of floating point vector
- *     C)  Free vectors
+ *     C)  Attempt to sort with null input vector
+ *     D)  Sort with output vector which needs to be resized
+ *     E)  Sort input vector with zero elements
+ *     F)  Attempt to sort input vector with invalid type
+ *     G)  Free vectors
  *
  *  @author  Ross Harman, MHPCC
  *
- *  @version $Revision: 1.5 $  $Name: not supported by cvs2svn $
- *  @date  $Date: 2004-11-22 21:07:42 $
+ *  @version $Revision: 1.6 $  $Name: not supported by cvs2svn $
+ *  @date  $Date: 2004-12-09 21:33:04 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -20,4 +24,39 @@
 #include "psTest.h"
 
+#define tstVectorSortIndexByType(datatype,value) \
+in = psVectorAlloc( 5, PS_TYPE_##datatype ); \
+in->n = 5; \
+in->data.datatype[0] = 7+value; \
+in->data.datatype[1] = 9+value; \
+in->data.datatype[2] = 5+value; \
+in->data.datatype[3] = 1+value; \
+in->data.datatype[4] = 5+value; \
+out = psVectorSortIndex(out,in); \
+if(out->type.type != PS_TYPE_U32) { \
+    psError(PS_ERR_UNKNOWN,true,"Output vector is not of type PS_TYPE_U32"); \
+    return 10; \
+} \
+if(out->data.U32[0] != 3 ) { \
+    psError(PS_ERR_UNKNOWN,true,"Improper index sort out[0] = %ld",out->data.U32[0]); \
+    return 20; \
+} \
+if(out->data.U32[1] != 2 ) { \
+    psError(PS_ERR_UNKNOWN,true,"Improper index sort out[1] = %ld",out->data.U32[1]); \
+    return 30; \
+} \
+if(out->data.U32[2] != 4 ) { \
+    psError(PS_ERR_UNKNOWN,true,"Improper index sort out[2] = %ld",out->data.U32[2]); \
+    return 40; \
+} \
+if(out->data.U32[3] != 0 ) { \
+    psError(PS_ERR_UNKNOWN,true,"Improper index sort out[3] = %ld",out->data.U32[3]); \
+    return 50; \
+} \
+if(out->data.U32[4] != 1 ) { \
+    psError(PS_ERR_UNKNOWN,true,"Improper index sort out[4] = %ld",out->data.U32[4]); \
+    return 60; \
+} \
+psFree(in);
+
 psS32 main(psS32 argc,
            char* argv[])
@@ -25,47 +64,115 @@
     psVector *in = NULL;
     psVector *out = NULL;
+    psVector *tempVect = NULL;
 
+    // Test A - Sort vectors by index for all types
+    printPositiveTestHeader(stdout,"psVectorSortIndex","Sort by index for all types");
+    tstVectorSortIndexByType(S8,0)
+    tstVectorSortIndexByType(U8,1)
+    tstVectorSortIndexByType(S16,2)
+    tstVectorSortIndexByType(U16,3)
+    tstVectorSortIndexByType(S32,4)
+    tstVectorSortIndexByType(U32,5)
+    tstVectorSortIndexByType(S64,6)
+    tstVectorSortIndexByType(U64,7)
+    tstVectorSortIndexByType(F32,8)
+    tstVectorSortIndexByType(F64,9)
+    psFree(out);
+    printFooter(stdout,"psVectorSortIndex","Sort by index for all types",true);
 
-    // Test A - Create float vectors
-    printPositiveTestHeader(stdout,"psVectorSortIndex", "Create vectors");
-    in = psVectorAlloc(5, PS_TYPE_F32);
-    in->n = 5;
-    in->data.F32[0] = 7.0f;
-    in->data.F32[1] = 9.0f;
-    in->data.F32[2] = 3.0f;
-    in->data.F32[3] = 1.0f;
-    in->data.F32[4] = 5.0f;
-    for(psS32 i=0; i<5; i++) {
-        printf("arr[%d] = %f\n", i, in->data.F32[i]);
+    // Test  C  Attempt to sort with null input vector
+    printPositiveTestHeader(stdout,"psVectorSortIndex","Attempt to sort with NULL input");
+    psLogMsg(__func__,PS_LOG_INFO,"Following should generate an error message");
+    in = NULL;
+    out = psVectorAlloc(5,PS_TYPE_U32);
+    out = psVectorSortIndex(out,in);
+    if(out != NULL) {
+        psError(PS_ERR_UNKNOWN,true,"Did not return NULL with NULL input specified");
+        return 111;
     }
-    printFooter(stdout, "psVectorSortIndex", "Create vectors", true);
+    printFooter(stdout,"psVectorSortIndex","Attempt to sort with NULL input",true);
 
-
-    // Test B - Sort integer vector of indices based on pre-sort order of floating point vector
-    printPositiveTestHeader(stdout,"psVectorSortIndex", "Create sorted index vector");
-    out = psVectorSortIndex(out, in);
-    for(psS32 i=0; i<5; i++) {
-        printf("arr[%d] = %d\n", i, out->data.U32[i]);
+    // Test  D  Sort with output vector which needs to be resized
+    printPositiveTestHeader(stdout,"psVectorSortIndex","Sort with resize output vector");
+    in = psVectorAlloc(5,PS_TYPE_U8);
+    for(psS32 m=0; m<5; m++) {
+        in->data.U8[m]= 20-m;
     }
-    printFooter(stdout, "psVectorSortIndex", "Create sorted index vector", true);
-
-    // Test D - Verify the output vector is of type psU32
-    printPositiveTestHeader(stdout,"psVectorSortIndex", "Verify output vector type");
-    if(out->type.type != PS_TYPE_U32) {
-        printf("ERROR: output vector is of type %d\n", out->type.type);
+    out = psVectorAlloc(3,PS_TYPE_U32);
+    out = psVectorSortIndex(out,in);
+    if(out->n != 5) {
+        psError(PS_ERR_UNKNOWN,true,"Did not properly resize output vector");
+        return 112;
     }
-    printFooter(stdout, "psVectorSortIndex", "Verify output vector type", true);
-
-    // Test C - Free vectors
-    printPositiveTestHeader(stdout,"psVectorSortIndex", "Free vectors");
+    if(out->data.U32[0] != 4) {
+        psError(PS_ERR_UNKNOWN,true,"Did not properly sort index out[0] = %d",out->data.U32[0]);
+        return 113;
+    }
+    if(out->data.U32[1] != 3) {
+        psError(PS_ERR_UNKNOWN,true,"Did not properly sort index out[1] = %d",out->data.U32[1]);
+        return 114;
+    }
+    if(out->data.U32[2] != 2) {
+        psError(PS_ERR_UNKNOWN,true,"Did not properly sort index out[2] = %d",out->data.U32[2]);
+        return 115;
+    }
+    if(out->data.U32[3] != 1) {
+        psError(PS_ERR_UNKNOWN,true,"Did not properly sort index out[3] = %d",out->data.U32[3]);
+        return 116;
+    }
+    if(out->data.U32[4] != 0) {
+        psError(PS_ERR_UNKNOWN,true,"Did not properly sort index out[4] = %d",out->data.U32[4]);
+        return 117;
+    }
     psFree(in);
     psFree(out);
+    printFooter(stdout,"psVectorSortIndex","Sort with resize output vector",true);
+
+    // Test E - Sort input vector with zero elements
+    printPositiveTestHeader(stdout,"psVectorSortIndex","Sort with input vector with zero elements");
+    in = psVectorAlloc(5,PS_TYPE_U8);
+    out = psVectorAlloc(5,PS_TYPE_U32);
+    in->n = 0;
+    out->n = 0;
+    tempVect = out;
+    out = psVectorSortIndex(out,in);
+    if ( out != tempVect ) {
+        psError(PS_ERR_UNKNOWN,true,"Did not return the same output vector");
+        return 118;
+    }
+    in->n=5;
+    out->n=5;
+    psFree(out);
+    psFree(in);
+    printFooter(stdout,"psVectorSortIndex","Sort with input vector with zero elements",true);
+
+    // Test F - Attempt to sort input vector with invalid type
+    printPositiveTestHeader(stdout,"psVectorSortIndex","Attempt to sort with invalid type");
+    in = psVectorAlloc(5,PS_TYPE_U8);
+    out = psVectorAlloc(5,PS_TYPE_U32);
+    tempVect = out;
+    in->type.type = PS_TYPE_BOOL;
+    psLogMsg(__func__,PS_LOG_INFO,"Following should generate two error messages(psVectorSort,psVectorSortIndex)");
+    out = psVectorSortIndex(out,in);
+    if( out != tempVect) {
+        psError(PS_ERR_UNKNOWN,true,"Did not return the same output vector");
+        return 119;
+    }
+    in->type.type = PS_TYPE_U8;
+    psFree(in);
+    psFree(out);
+    printFooter(stdout,"psVectorSortIndex","Attempt to sort with invalid type",true);
+
+    // Test G - Free vectors
+    printPositiveTestHeader(stdout,"psVectorSortIndex", "Free vectors");
     psS32 nLeaks = psMemCheckLeaks(0, NULL, stdout, false);
     if(nLeaks) {
         printf("ERROR: Found %d memory leaks\n", nLeaks);
+        return 222;
     }
     psS32 nBad = psMemCheckCorruption(0);
     if(nBad) {
         printf("ERROR: Found %d bad memory blocks\n", nBad);
+        return 333;
     }
     printFooter(stdout, "psVectorSort", "Free vectors", true);
Index: /trunk/psLib/test/collections/verified/tst_psVectorSort_02.stderr
===================================================================
--- /trunk/psLib/test/collections/verified/tst_psVectorSort_02.stderr	(revision 2676)
+++ /trunk/psLib/test/collections/verified/tst_psVectorSort_02.stderr	(revision 2677)
@@ -1,2 +1,10 @@
+<DATE><TIME>|<HOST>|I|main
+    Following should generate an error message
 <DATE><TIME>|<HOST>|E|psVectorSortIndex (psVector.c:<LINENO>)
-    Input psVector is an unsupported type (0).
+    psVectorSort can not sort a NULL psVector.
+<DATE><TIME>|<HOST>|I|main
+    Following should generate two error messages(psVectorSort,psVectorSortIndex)
+<DATE><TIME>|<HOST>|E|psVectorSort (psVector.c:<LINENO>)
+    Input psVector is an unsupported type (4865).
+<DATE><TIME>|<HOST>|E|psVectorSortIndex (psVector.c:<LINENO>)
+    Input psVector is an unsupported type (4865).
Index: /trunk/psLib/test/collections/verified/tst_psVectorSort_02.stdout
===================================================================
--- /trunk/psLib/test/collections/verified/tst_psVectorSort_02.stdout	(revision 2676)
+++ /trunk/psLib/test/collections/verified/tst_psVectorSort_02.stdout	(revision 2677)
@@ -1,38 +1,46 @@
 /***************************** TESTPOINT ******************************************\
 *             TestFile: tst_psVectorSort_02.c                                      *
-*            TestPoint: psVectorSortIndex{Create vectors}                          *
-*             TestType: Positive                                                   *
-\**********************************************************************************/
-
-arr[0] = 7.000000
-arr[1] = 9.000000
-arr[2] = 3.000000
-arr[3] = 1.000000
-arr[4] = 5.000000
-
----> TESTPOINT PASSED (psVectorSortIndex{Create vectors} | tst_psVectorSort_02.c)
-
-/***************************** TESTPOINT ******************************************\
-*             TestFile: tst_psVectorSort_02.c                                      *
-*            TestPoint: psVectorSortIndex{Create sorted index vector}              *
-*             TestType: Positive                                                   *
-\**********************************************************************************/
-
-arr[0] = 0
-arr[1] = 0
-arr[2] = 0
-arr[3] = 0
-arr[4] = 0
-
----> TESTPOINT PASSED (psVectorSortIndex{Create sorted index vector} | tst_psVectorSort_02.c)
-
-/***************************** TESTPOINT ******************************************\
-*             TestFile: tst_psVectorSort_02.c                                      *
-*            TestPoint: psVectorSortIndex{Verify output vector type}               *
+*            TestPoint: psVectorSortIndex{Sort by index for all types}             *
 *             TestType: Positive                                                   *
 \**********************************************************************************/
 
 
----> TESTPOINT PASSED (psVectorSortIndex{Verify output vector type} | tst_psVectorSort_02.c)
+---> TESTPOINT PASSED (psVectorSortIndex{Sort by index for all types} | tst_psVectorSort_02.c)
+
+/***************************** TESTPOINT ******************************************\
+*             TestFile: tst_psVectorSort_02.c                                      *
+*            TestPoint: psVectorSortIndex{Attempt to sort with NULL input}         *
+*             TestType: Positive                                                   *
+\**********************************************************************************/
+
+
+---> TESTPOINT PASSED (psVectorSortIndex{Attempt to sort with NULL input} | tst_psVectorSort_02.c)
+
+/***************************** TESTPOINT ******************************************\
+*             TestFile: tst_psVectorSort_02.c                                      *
+*            TestPoint: psVectorSortIndex{Sort with resize output vector}          *
+*             TestType: Positive                                                   *
+\**********************************************************************************/
+
+
+---> TESTPOINT PASSED (psVectorSortIndex{Sort with resize output vector} | tst_psVectorSort_02.c)
+
+/***************************** TESTPOINT ******************************************\
+*             TestFile: tst_psVectorSort_02.c                                      *
+*            TestPoint: psVectorSortIndex{Sort with input vector with zero elements} *
+*             TestType: Positive                                                   *
+\**********************************************************************************/
+
+
+---> TESTPOINT PASSED (psVectorSortIndex{Sort with input vector with zero elements} | tst_psVectorSort_02.c)
+
+/***************************** TESTPOINT ******************************************\
+*             TestFile: tst_psVectorSort_02.c                                      *
+*            TestPoint: psVectorSortIndex{Attempt to sort with invalid type}       *
+*             TestType: Positive                                                   *
+\**********************************************************************************/
+
+
+---> TESTPOINT PASSED (psVectorSortIndex{Attempt to sort with invalid type} | tst_psVectorSort_02.c)
 
 /***************************** TESTPOINT ******************************************\
