Changeset 1714 for trunk/psLib/test/sysUtils/tst_psString.c
- Timestamp:
- Sep 7, 2004, 2:09:36 PM (22 years ago)
- File:
-
- 1 edited
-
trunk/psLib/test/sysUtils/tst_psString.c (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/test/sysUtils/tst_psString.c
r1406 r1714 17 17 * @author Eric Van Alst, MHPCC 18 18 * 19 * @version $Revision: 1. 7$ $Name: not supported by cvs2svn $20 * @date $Date: 2004-0 8-06 22:34:06 $19 * @version $Revision: 1.8 $ $Name: not supported by cvs2svn $ 20 * @date $Date: 2004-09-08 00:09:36 $ 21 21 * 22 22 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 28 28 #include "psTest.h" 29 29 30 static int testStringCopy00(void); 31 static int testStringCopy01(void); 32 static int testStringCopy02(void); 33 static int testStringCopy03(void); 34 static int testStringCopy04(void); 35 static int testStringCopy05(void); 36 static int testStringCopy06(void); 37 38 testDescription tests[] = { 39 {testStringCopy00, 0, "Verify string copy", 0, false}, 40 {testStringCopy01, 1, "Verify empty string copy", 0, false}, 41 {testStringCopy02, 2, "Verify string copy with length", 0, false}, 42 {testStringCopy03, 3, "Verify empty string copy with length", 0, false}, 43 {testStringCopy04, 4, "Copy string to larger string", 0, false}, 44 {testStringCopy05, 5, "Copy string with negative size", 0, false}, 45 {testStringCopy06, 6, "Verify creation of string literal", 0, false}, 46 {NULL} 47 }; 48 49 int main( int argc, char* argv[] ) 50 { 51 psLogSetLevel( PS_LOG_INFO ); 52 53 return ( ! runTestSuite( stderr, "psString", tests, argc, argv ) ); 54 } 55 56 /* 30 57 int main( int argc, 31 58 char * argv[] ) … … 46 73 int memBlockAllocated = 0; 47 74 psMemBlock ***memBlockPtr = NULL; 75 76 */ 77 78 static int testStringCopy00(void) 79 { 80 char stringval[20] = "E R R O R"; 81 int result = 0; 82 int result1 = 0; 83 char *strResult; 48 84 49 85 // Test point #1 Verify string copy - psStringCopy 50 printPositiveTestHeader(stderr,"psStringCopy","Verify string copy");51 86 strResult = psStringCopy(stringval); 52 87 // Perform string compare … … 63 98 fprintf(stderr, " changed src = %s expected %s\n",strResult, 64 99 stringval); 65 tpResult = false; 66 tpFails++; 67 } else { 68 tpResult = true; 69 } 100 return 1; 101 } 102 70 103 // Free memory allocated 71 104 psFree(strResult); 72 printFooter(stderr, "psStringCopy","Verify string copy", tpResult); 105 106 return 0; 107 } 108 109 static int testStringCopy01(void) 110 { 111 char *emptyval = ""; 112 int result = 0; 113 char *strResult; 73 114 74 115 // Test point #2 Verify empty string copy - psStringCopy 75 printPositiveTestHeader(stderr,"psStringCopy","Verify empty string copy");76 116 strResult = psStringCopy(emptyval); 77 117 // Perform string compare … … 81 121 fprintf(stderr," src = %s expected %s\n", 82 122 strResult, emptyval); 83 tpResult = false; 84 tpFails++; 85 } else { 86 tpResult = true; 87 } 123 return 1; 124 } 125 88 126 // Free memory allocated 89 127 psFree(strResult); 90 printFooter(stderr, "psStringCopy","Verify empty string copy", tpResult); 128 129 return 0; 130 } 131 132 static int testStringCopy02(void) 133 { 134 int result = 0; 135 int result1 = 0; 136 char *strResult; 137 char stringval1[20] = "e r r o r"; 138 int substringlen = 6; 139 char *substringval = "e r r"; 91 140 92 141 // Test point #3 Verify string copy with length - psStringNCopy 93 printPositiveTestHeader(stderr,"psStringNCopy","Verify string copy with length");94 142 strResult = psStringNCopy(stringval1, substringlen); 95 143 // Perform string compare and get string length … … 105 153 fprintf(stderr," src = %s expected %s\n", 106 154 strResult, substringval); 107 tpResult = false; 108 tpFails++; 109 } else { 110 tpResult = true; 155 return 1; 111 156 } 112 157 // Free memory allocated 113 158 psFree(strResult); 114 printFooter(stderr, "psStringNCopy","Verify string copy with length", tpResult); 159 160 return 0; 161 } 162 163 static int testStringCopy03(void) 164 { 165 int result = 0; 166 int result1 = 0; 167 char *strResult; 168 char *stringvalnocopy = "F A I L"; 115 169 116 170 // Test point #4 Verify empty string copy with length - psStringNCopy 117 printPositiveTestHeader(stderr,"psStringNCopy", "Verify empty string copy with length");118 171 strResult = psStringNCopy(stringvalnocopy, 0); 119 172 // Perform string compare and get sting length … … 124 177 fprintf(stderr," src = %s didn't expected %s\n", 125 178 strResult, stringvalnocopy); 126 tpResult = false; 127 tpFails++; 128 } else { 129 tpResult = true; 179 return 1; 130 180 } 131 181 // Free memory 132 182 psFree(strResult); 133 printFooter(stderr, "psStringNCopy","Verify empty string copy with length", tpResult); 183 184 return 0; 185 } 186 187 static int testStringCopy04(void) 188 { 189 int result = 0; 190 int result1 = 0; 191 char *strResult; 192 char stringval[20] = "E R R O R"; 193 int increaseSize = 5; 134 194 135 195 // Test point #5 Copy string to larger string - psStringNCopy 136 printPositiveTestHeader(stderr,"psStringNCopy", "Copy string to larger string");137 196 strResult = psStringNCopy(stringval, (strlen(stringval) + increaseSize)); 138 197 // Perform string compare and get string length … … 147 206 fprintf(stderr," strlne result = %d expected %d\n",result1, 148 207 (int)strlen(stringval)); 149 tpResult = false; 150 tpFails++; 151 } else { 152 tpResult = true; 208 return 1; 153 209 } 154 210 // Free memory 155 211 psFree(strResult); 156 printFooter(stderr, "psStringNCopy", "Copy string to larger string", tpResult); 212 213 return 0; 214 } 215 216 static int testStringCopy05(void) 217 { 218 char *strResult; 219 char stringval[20] = "E R R O R"; 220 int negativeSize = -5; 157 221 158 222 // Test point #6 Copy string with negative size - psStringNCopy 159 printPositiveTestHeader(stderr,"psStringNCopy", "Copy string with negative size");160 223 strResult = psStringNCopy(stringval, negativeSize); 161 224 if ( strResult != NULL ) { 162 225 fprintf(stderr,"Failed test point #6 return value = %ld expected NULL\n", 163 226 (unsigned long)strResult); 164 tpResult = false; 165 tpFails++; 166 } else { 167 tpResult = true; 227 return 1; 168 228 } 169 229 // Memory should not have been allocated 170 printFooter(stderr, "psStringNCopy", "Copy string with negative size", tpResult); 230 231 return 0; 232 } 233 234 static int testStringCopy06(void) 235 { 236 char *strResult; 237 char stringval[20] = "E R R O R"; 238 int result = 0; 171 239 172 240 // Test point #7 Verify creation of string literal - PS_STRING 173 printPositiveTestHeader(stderr,"PS_STRING","Verify creation of string literal");174 241 strResult = PS_STRING(E R R O R); 175 242 result = strcmp(strResult, stringval); 176 243 if ( result != 0 ) { 177 244 fprintf(stderr,"Failed test point #7 strcmp result = %d expected %d",result,0); 178 tpResult = false; 179 tpFails++; 180 } else { 181 tpResult = true; 245 return 1; 182 246 } 183 247 // Memory should not have been allocated 184 printFooter(stderr, "PS_STRING", "Verify creation of string literal", tpResult); 185 186 // Check for memory leaks 187 memBlockAllocated = psMemCheckLeaks(0, memBlockPtr, stderr); 188 if ( memBlockAllocated != 0 ) { 189 fprintf(stderr,"Failed - Memory leaks detected - Blocks still allocated = %d\n", 190 memBlockAllocated); 191 tpFails++; 192 } 193 194 // Display test driver fail message if tpFail not zero 195 if ( tpFails != 0 ) { 196 fprintf(stderr,"Failed test driver testpoint fail = %d expected %d\n", 197 tpFails, 0); 198 } 199 200 // Return number of test points which failed 201 return tpFails; 202 } 203 248 249 return 0; 250 }
Note:
See TracChangeset
for help on using the changeset viewer.
