Changeset 605 for trunk/psLib/test/sysUtils/tst_psString.c
- Timestamp:
- May 7, 2004, 12:06:17 PM (22 years ago)
- File:
-
- 1 edited
-
trunk/psLib/test/sysUtils/tst_psString.c (modified) (13 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/test/sysUtils/tst_psString.c
r543 r605 11 11 * 5) Copy string to larger string - psStringNCopy 12 12 * 6) Copy string with negative size - psStringNCopy 13 * 7) Verifiy creation of string literal - PS_STRING 13 14 * 14 15 * Return: Number of test points which failed … … 16 17 * @author Eric Van Alst, MHPCC 17 18 * 18 * @version $Revision: 1. 2$ $Name: not supported by cvs2svn $19 * @date $Date: 2004-0 4-28 22:00:02$19 * @version $Revision: 1.3 $ $Name: not supported by cvs2svn $ 20 * @date $Date: 2004-05-07 22:06:17 $ 20 21 * 21 22 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 32 33 bool tpResult = false; 33 34 char *stringval = "E R R O R"; 34 char *substringval = "E R R "; 35 char *stringval1 = "e r r o r"; 36 char *stringvalnocopy = "F A I L"; 37 char *substringval = "e r r "; 35 38 int substringlen = 6; 36 39 char *emptyval = ""; … … 41 44 int result = 0; 42 45 int result1 = 0; 46 int memBlockAllocated = 0; 47 psMemBlock ***memBlockPtr = NULL; 43 48 44 49 // Test point #1 Verify string copy - psStringCopy … … 49 54 if ( result != 0 ) { 50 55 fprintf(stderr, "Failed test point #1 strcmp result = %d expected 0\n",result); 56 fprintf(stderr, " src = %s expected %s\n", 57 strResult, stringval); 51 58 tpResult = false; 52 59 tpFails++; … … 54 61 tpResult = true; 55 62 } 63 // Free memory allocated 64 psFree(strResult); 56 65 printFooter(stderr, "psStringCopy","Verify string copy", tpResult); 57 66 … … 63 72 if ( result != 0 ) { 64 73 fprintf(stderr,"Failed test point #2 strcmp result = %d expected 0\n",result); 74 fprintf(stderr," src = %s expected %s\n", 75 strResult, emptyval); 65 76 tpResult = false; 66 77 tpFails++; … … 68 79 tpResult = true; 69 80 } 81 // Free memory allocated 82 psFree(strResult); 70 83 printFooter(stderr, "psStringCopy","Verify empty string copy", tpResult); 71 84 72 85 // Test point #3 Verify string copy with length - psStringNCopy 73 86 printPositiveTestHeader(stderr,"psStringNCopy","Verify string copy with length"); 74 strResult = psStringNCopy(stringval , substringlen);87 strResult = psStringNCopy(stringval1, substringlen); 75 88 // Perform string compare and get string length 76 result = strcmp(strResult, substringval); 77 result1 = strlen(strResult); 78 if ( ( result != 0 ) || 79 ( result1 != substringlen ) ) { 89 result = strncmp(strResult, substringval, substringlen); 90 if ( result != 0 ) { 80 91 fprintf(stderr,"Failed test point #3 strcmp result = %d expected 0\n",result); 81 fprintf(stderr," strlen result = %d expected %d\n",82 result1, substringlen);92 fprintf(stderr," src = %s expected %s\n", 93 strResult, substringval); 83 94 tpResult = false; 84 95 tpFails++; … … 86 97 tpResult = true; 87 98 } 99 // Free memory allocated 100 psFree(strResult); 88 101 printFooter(stderr, "psStringNCopy","Verify string copy with length", tpResult); 89 102 90 103 // Test point #4 Verify empty string copy with length - psStringNCopy 91 104 printPositiveTestHeader(stderr,"psStringNCopy", "Verify empty string copy with length"); 92 strResult = psStringNCopy(stringval , 0);105 strResult = psStringNCopy(stringvalnocopy, 0); 93 106 // Perform string compare and get sting length 94 result = strcmp(strResult, emptyval);107 result = strcmp(strResult, stringvalnocopy); 95 108 result1 = strlen(strResult); 96 if ( ( result != 0 ) || 97 ( result1 != strlen(emptyval) ) ) { 98 fprintf(stderr,"Failed test point #4 strcmp result = %d expected %d\n",result,0); 99 fprintf(stderr," strlen result = %d expected %d\n",result1, 100 (int)strlen(emptyval)); 109 if ( result == 0 ) { 110 fprintf(stderr,"Failed test point #4 strcmp result = %d didn't expected %d\n",result,0); 111 fprintf(stderr," src = %s didn't expected %s\n", 112 strResult, stringvalnocopy); 101 113 tpResult = false; 102 114 tpFails++; … … 104 116 tpResult = true; 105 117 } 118 // Free memory 119 psFree(strResult); 106 120 printFooter(stderr, "psStringNCopy","Verify empty string copy with length", tpResult); 107 121 … … 116 130 ( result1 != strlen(stringval) ) ) { 117 131 fprintf(stderr,"Failed test point #5 strcmp result = %d expected %d\n",result,0); 132 fprintf(stderr," src = %s expected %s\n", 133 strResult, stringval); 118 134 fprintf(stderr," strlne result = %d expected %d\n",result1, 119 135 (int)strlen(stringval)); … … 123 139 tpResult = true; 124 140 } 141 // Free memory 142 psFree(strResult); 125 143 printFooter(stderr, "psStringNCopy", "Copy string to larger string", tpResult); 126 144 … … 136 154 tpResult = true; 137 155 } 156 // Memory should not have been allocated 138 157 printFooter(stderr, "psStringNCopy", "Copy string with negative size", tpResult); 158 159 // Test point #7 Verify creation of string literal - PS_STRING 160 printPositiveTestHeader(stderr,"PS_STRING","Verify creation of string literal"); 161 strResult = PS_STRING(E R R O R); 162 result = strcmp(strResult, stringval); 163 if ( result != 0 ) { 164 fprintf(stderr,"Failed test point #7 strcmp result = %d expected %d",result,0); 165 tpResult = false; 166 tpFails++; 167 } else { 168 tpResult = true; 169 } 170 // Memory should not have been allocated 171 printFooter(stderr, "PS_STRING", "Verify creation of string literal", tpResult); 172 173 // Check for memory leaks 174 memBlockAllocated = psMemCheckLeaks(0, memBlockPtr, stderr); 175 if ( memBlockAllocated != 0 ) { 176 fprintf(stderr,"Failed - Memory leaks detected - Blocks still allocated = %d\n", 177 memBlockAllocated); 178 tpFails++; 179 } 139 180 140 181 // Display test driver fail message if tpFail not zero
Note:
See TracChangeset
for help on using the changeset viewer.
