Changeset 9750
- Timestamp:
- Oct 25, 2006, 6:44:09 PM (20 years ago)
- Location:
- trunk/psLib
- Files:
-
- 3 edited
-
src/types/psMetadataConfig.c (modified) (7 diffs)
-
test/types/tap_psMetadataConfig_input.c (modified) (6 diffs)
-
test/types/tap_psMetadataConfig_output.c (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/types/psMetadataConfig.c
r9736 r9750 10 10 * @author Eric Van Alst, MHPCC 11 11 * 12 * @version $Revision: 1.9 7$ $Name: not supported by cvs2svn $13 * @date $Date: 2006-10-2 5 00:16:33$12 * @version $Revision: 1.98 $ $Name: not supported by cvs2svn $ 13 * @date $Date: 2006-10-26 04:44:09 $ 14 14 * 15 15 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 1166 1166 // Attempt to open specified file 1167 1167 int fd = 0; 1168 if (!(fd = open(filename, O_RDONLY))) { 1168 fd = open(filename, O_RDONLY); 1169 struct stat buf; // Results of stat() for file 1170 if (fd < 0 || fstat(fd, &buf) != 0) { 1169 1171 // XXX really should return strerror() here 1170 1172 psError(PS_ERR_IO, true, 1171 1173 _("Failed to open file '%s'. Check if it exists and it has the proper " 1172 1174 "permissions."), filename); 1175 close(fd); 1173 1176 return NULL; 1174 1177 } 1175 1176 struct stat buf; // Results of stat() for file 1178 /* This appears to be unreachable, but moving to check above just to be sure. 1177 1179 if (fstat(fd, &buf) != 0) { 1178 1180 psError(PS_ERR_IO, true, _("Unable to stat file '%s'.\n"), filename); … … 1180 1182 return NULL; 1181 1183 } 1182 1184 */ 1183 1185 // psMetadataConfigParse() is going to read the entire file into memory so 1184 1186 // we're trying to be nice by allowing the VM to flush the file out of … … 1188 1190 if (file == MAP_FAILED) { 1189 1191 psError(PS_ERR_IO, true, _("failed to mmap() file %s"), filename); 1190 if (close(fd) != 0) { 1191 // XXX really should return strerror() here 1192 psError(PS_ERR_IO, true, _("Failed to close file '%s'."), filename); 1193 return NULL; 1194 } 1192 /* if (close(fd) != 0) { 1193 // XXX really should return strerror() here 1194 psError(PS_ERR_IO, true, _("Failed to close file '%s'."), filename); 1195 return NULL; 1196 } 1197 */ 1198 close(fd); 1195 1199 return NULL; 1196 1200 } … … 1199 1203 1200 1204 munmap(file, (size_t)buf.st_size); 1201 1205 /* 1202 1206 if (close(fd) != 0) { 1203 1207 // XXX really should return strerror() here … … 1205 1209 return NULL; 1206 1210 } 1207 1211 */ 1212 close(fd); 1208 1213 return md; 1209 1214 } … … 1241 1246 1242 1247 psList *doc = psStringSplit(str, "\n", false); 1243 if (!doc) { 1248 if (!doc || doc->n == 0) { 1249 if (doc != NULL) 1250 psFree(doc); 1244 1251 psFree(parseLevelInfoArray); 1245 1252 psFree(md); -
trunk/psLib/test/types/tap_psMetadataConfig_input.c
r9739 r9750 12 12 #include <pslib.h> 13 13 #include <string.h> 14 #include <fcntl.h> 15 #include <unistd.h> 16 14 17 15 18 #include "tap.h" … … 22 25 int main(void) 23 26 { 24 plan_tests( 4);27 plan_tests(10); 25 28 26 29 diag("Tests for psMetadataConfig Input Functions"); … … 39 42 unsigned int nfail = 0; 40 43 md = psMetadataAlloc(); 41 psMetadataAddS32(md, PS_LIST_HEAD, "new S32", 0, "", 666);44 psMetadataAddS32(md, PS_LIST_HEAD, "new_S32", 0, "", 666); 42 45 43 46 //Return NULL for NULL filename input … … 47 50 "psMetadataConfigRead: return NULL for NULL filename input."); 48 51 } 49 //Return falsefor invalid filename input52 //Return NULL for invalid filename input 50 53 { 51 54 out = psMetadataConfigRead(out, &nfail, ".", false); … … 53 56 "psMetadataConfigRead: return NULL for invalid filename input."); 54 57 } 58 //Return NULL for missing file input 59 { 60 out = psMetadataConfigRead(out, &nfail, "table4.dat", false); 61 ok( out == NULL, 62 "psMetadataConfigRead: return NULL for missing file input."); 63 } 64 //Return empty metadata for read-only file with invalid syntax 65 { 66 out = psMetadataConfigRead(out, &nfail, "table3.dat", false); 67 ok( out != NULL && out->list->n == 0, 68 "psMetadataConfigRead: return empty metadata for file" 69 " with invalid syntax."); 70 psFree(out); 71 out = NULL; 72 } 55 73 //Return true for valid inputs 56 74 { 57 skip_start( !psMetadataConfigWrite(md, "mdcfg.wrt"), 1,58 "Skipping 1tests because psMetadataConfigWrite failed");75 skip_start( !psMetadataConfigWrite(md, "mdcfg.wrt"), 2, 76 "Skipping 2 tests because psMetadataConfigWrite failed"); 59 77 out = psMetadataConfigRead(out, &nfail, "mdcfg.wrt", false); 60 ok( out != NULL, 78 psMetadataItem *tempItem = psMetadataGet(out, PS_LIST_HEAD); 79 ok( out != NULL && nfail == 0, 61 80 "psMetadataConfigRead: return correct metadata for valid inputs."); 81 skip_start( tempItem == NULL, 1, 82 "Skipping 1 tests because metadata container is empty!"); 83 ok_str( tempItem->name, "new_S32", 84 "psMetadataConfigRead: return correct metadataItem from " 85 "returned metadata."); 86 skip_end(); 62 87 skip_end(); 63 88 } … … 76 101 { 77 102 diag(" >>>Test 2: psMetadataConfigParse"); 103 psMetadata *out = NULL; 104 unsigned int nfail = 0; 105 char str1[30]; 106 strcpy(str1, "-10.05 2 4"); 107 char str2[30]; 108 strcpy(str2, "\nnew S32 666\n"); 109 110 //Return NULL for NULL string input 111 { 112 out = psMetadataConfigParse(out, &nfail, NULL, false); 113 ok( out == NULL, 114 "psMetadataConfigParse: return NULL for NULL string input."); 115 } 116 //Return correct metadata for correct string input 117 { 118 psFree(out); 119 out = NULL; 120 out = psMetadataConfigParse(out, NULL, str2, false); 121 psMetadataItem *tempItem = psMetadataGet(out, PS_LIST_HEAD); 122 ok( out != NULL && tempItem != NULL, 123 "psMetadataConfigParse: return correct metadata for valid " 124 "string input."); 125 } 126 //Return empty metadata for incorrect string input 127 { 128 psFree(out); 129 out = NULL; 130 out = psMetadataConfigParse(out, NULL, str1, false); 131 psMetadataItem *tempItem = psMetadataGet(out, PS_LIST_HEAD); 132 ok( out != NULL && tempItem == NULL, 133 "psMetadataConfigParse: return correct metadata for valid " 134 "string input."); 135 if (tempItem != NULL) 136 printf("\n\n name=%s\n", tempItem->name); 137 } 138 139 78 140 /* FILE *openfile; 79 openfile = fopen("mdcfg.prt", "w+"); 80 FILE *nofile = NULL; 81 psMetadata *md = NULL; 82 md = psMetadataAlloc(); 83 84 //psMetadataConfigParse(psMetadata* md,unsigned int *nFail,const char *str,bool overwrite) 85 86 //Return false for NULL metadata input 87 { 88 ok( !psMetadataConfigPrint(openfile, NULL), 89 "psMetadataConfigPrint: return false for NULL metadata input."); 90 } 91 //Return false for empty metadata input 92 { 93 ok( !psMetadataConfigPrint(openfile, md), 94 "psMetadataConfigPrint: return false for empty metadata input."); 95 } 96 //Return false for NULL file input 97 psMetadataAddS32(md, PS_LIST_HEAD, "new S32", 0, "", 666); 98 { 99 ok( !psMetadataConfigPrint(nofile, md), 100 "psMetadataConfigPrint: return false for NULL FILE* input."); 101 } 102 //Return false for read-only file input 103 nofile = fopen("mdcfg.prt", "r"); 104 { 105 ok( !psMetadataConfigPrint(nofile, md), 106 "psMetadataConfigPrint: return false for read-only FILE* input."); 107 } 108 //Return true for valid inputs 109 { 110 ok( psMetadataConfigPrint(openfile, md), 111 "psMetadataConfigPrint: return true for valid inputs."); 112 } 113 114 115 //Check for Memory leaks 116 { 117 fclose(nofile); 118 fclose(openfile); 119 psFree(md); 120 remove("mdcfg.prt"); 121 checkMem(); 122 } 123 */ 141 openfile = fopen("mdcfg.prt", "w+"); 142 FILE *nofile = NULL; 143 psMetadata *md = NULL; 144 md = psMetadataAlloc(); 145 146 //psMetadataConfigParse(psMetadata* md,unsigned int *nFail,const char *str,bool overwrite) 147 148 //Return false for NULL metadata input 149 { 150 ok( !psMetadataConfigPrint(openfile, NULL), 151 "psMetadataConfigPrint: return false for NULL metadata input."); 152 } 153 //Return false for empty metadata input 154 { 155 ok( !psMetadataConfigPrint(openfile, md), 156 "psMetadataConfigPrint: return false for empty metadata input."); 157 } 158 //Return false for NULL file input 159 psMetadataAddS32(md, PS_LIST_HEAD, "new S32", 0, "", 666); 160 { 161 ok( !psMetadataConfigPrint(nofile, md), 162 "psMetadataConfigPrint: return false for NULL FILE* input."); 163 } 164 //Return false for read-only file input 165 nofile = fopen("mdcfg.prt", "r"); 166 { 167 ok( !psMetadataConfigPrint(nofile, md), 168 "psMetadataConfigPrint: return false for read-only FILE* input."); 169 } 170 //Return true for valid inputs 171 { 172 ok( psMetadataConfigPrint(openfile, md), 173 "psMetadataConfigPrint: return true for valid inputs."); 174 } 175 176 */ 177 //Check for Memory leaks 178 { 179 psFree(out); 180 checkMem(); 181 } 182 124 183 } 125 184 -
trunk/psLib/test/types/tap_psMetadataConfig_output.c
r9739 r9750 124 124 } 125 125 126 127 /*128 void testLookupTableAlloc(void)129 {130 diag(" >>>Test 1: psLookupTableAlloc & psMemCheckLookupTable Fxns");131 132 psLookupTable *lt = NULL;133 134 //Tests for psLookupTableAlloc135 //Return NULL for NULL filename input136 {137 lt = psLookupTableAlloc(NULL, "\%f \%lf \%d \%ld", 10);138 ok( lt == NULL,139 "psLookupTableAlloc: return NULL for NULL filename input.");140 }141 //Return correct vector output for valid inputs142 {143 vec = psLookupTableInterpolateAll(table2, 1);144 skip_start( vec == NULL, 1,145 "Skipping 1 tests because psLookupTableInterpolateAll failed");146 ok_double(vec->data.F64[0], 1.0,147 "psLookupTableInterpolateAll: return correct output vector for valid inputs.");148 skip_end();149 }150 //Check for Memory leaks151 {152 psFree(lt);153 checkMem();154 }155 }156 */157
Note:
See TracChangeset
for help on using the changeset viewer.
