Changeset 2129
- Timestamp:
- Oct 14, 2004, 11:14:58 AM (22 years ago)
- Location:
- trunk/psLib
- Files:
-
- 9 edited
-
psLib.kdevelop.pcs (modified) ( previous)
-
psLib.kdevses (modified) (1 diff)
-
src/pslib.h (modified) (2 diffs)
-
src/sys/psErrorCodes.c (modified) (4 diffs)
-
src/sys/psErrorCodes.h (modified) (3 diffs)
-
src/sysUtils/psErrorCodes.c (modified) (4 diffs)
-
src/sysUtils/psErrorCodes.h (modified) (3 diffs)
-
test/sysUtils/tst_psError.c (modified) (4 diffs)
-
test/sysUtils/verified/tst_psError.stderr (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/psLib.kdevses
r2110 r2129 2 2 <!DOCTYPE KDevPrjSession> 3 3 <KDevPrjSession> 4 <DocsAndViews NumberOfDocuments=" 7" >5 <Doc0 NumberOfViews="1" URL="file:/home/desonia/psLib/ test/astronomy/tst_psAstrometry01.c" >6 <View0 line=" 462" Type="???" >7 <AdditionalSettings Top="2" Width=" 1181" Attach="1" Height="732" Left="2" MinMaxMode="0" />4 <DocsAndViews NumberOfDocuments="1" > 5 <Doc0 NumberOfViews="1" URL="file:/home/desonia/psLib/src/dataManip/psConstants.h" > 6 <View0 line="109" Type="???" > 7 <AdditionalSettings Top="2" Width="878" Attach="1" Height="750" Left="2" MinMaxMode="0" /> 8 8 </View0> 9 9 </Doc0> 10 <Doc1 context="" NumberOfViews="1" URL="man:/printf" >11 <View0 Type="???" >12 <AdditionalSettings Top="2" Width="1181" Attach="1" Height="732" Left="2" MinMaxMode="0" />13 </View0>14 </Doc1>15 <Doc2 context="" NumberOfViews="1" URL="man:/usr/share/man/man3/printf.3.gz" >16 <View0 Type="???" >17 <AdditionalSettings Top="2" Width="1181" Attach="1" Height="732" Left="2" MinMaxMode="0" />18 </View0>19 </Doc2>20 <Doc3 NumberOfViews="1" URL="file:/home/desonia/psLib/test/astronomy/Makefile" >21 <View0 line="31" Type="???" >22 <AdditionalSettings Top="2" Width="1181" Attach="1" Height="732" Left="2" MinMaxMode="0" />23 </View0>24 </Doc3>25 <Doc4 NumberOfViews="1" URL="file:/home/desonia/psLib/src/sysUtils/psTrace.c" >26 <View0 line="201" Type="???" >27 <AdditionalSettings Top="2" Width="1181" Attach="1" Height="508" Left="2" MinMaxMode="0" />28 </View0>29 </Doc4>30 <Doc5 NumberOfViews="1" URL="file:/home/desonia/psLib/src/sysUtils/psTrace.h" >31 <View0 line="19" Type="???" >32 <AdditionalSettings Top="2" Width="1181" Attach="1" Height="732" Left="2" MinMaxMode="0" />33 </View0>34 </Doc5>35 <Doc6 NumberOfViews="1" URL="file:/home/desonia/psLib/test/astronomy/tst_psTime_01.c" >36 <View0 line="0" Type="???" >37 <AdditionalSettings Top="2" Width="1181" Attach="1" Height="508" Left="2" MinMaxMode="0" />38 </View0>39 </Doc6>40 10 </DocsAndViews> 41 11 <pluginList> -
trunk/psLib/src/pslib.h
r1974 r2129 9 9 * @author Eric Van Alst, MHPCC 10 10 * 11 * @version $Revision: 1.2 5$ $Name: not supported by cvs2svn $12 * @date $Date: 2004-10- 06 01:21:34$11 * @version $Revision: 1.26 $ $Name: not supported by cvs2svn $ 12 * @date $Date: 2004-10-14 21:14:57 $ 13 13 * 14 14 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 161 161 #include "psAstrometry.h" 162 162 163 #include "psConstants.h" 163 164 /// @} 164 165 -
trunk/psLib/src/sys/psErrorCodes.c
r1905 r2129 7 7 * @author Robert DeSonia, MHPCC 8 8 * 9 * @version $Revision: 1. 9$ $Name: not supported by cvs2svn $10 * @date $Date: 2004- 09-27 20:38:02$9 * @version $Revision: 1.10 $ $Name: not supported by cvs2svn $ 10 * @date $Date: 2004-10-14 21:14:58 $ 11 11 * 12 12 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii 13 13 */ 14 15 #include <string.h> 14 16 15 17 #include "psError.h" … … 75 77 desc = (psErrorDescription*)psListGet(dynamicErrorCodes,PS_LIST_HEAD); 76 78 while (desc != NULL) { 77 desc = (psErrorDescription*)psListGetNext(dynamicErrorCodes); 78 if (desc != NULL && desc->code == code) { 79 if (desc->code == code) { 79 80 return desc; 80 81 } 82 desc = (psErrorDescription*)psListGetNext(dynamicErrorCodes); 81 83 } 82 84 } 83 85 return NULL; 84 86 } 87 88 static void freeErrorDescription(psErrorDescription* err) 89 { 90 psFree((void*)err->description); 91 } 92 93 psErrorDescription* psErrorDescriptionAlloc(psErrorCode code, 94 const char *description) 95 { 96 psErrorDescription* err = psAlloc(sizeof(psErrorDescription)); 97 err->code = code; 98 if (description == NULL) { 99 err->description = NULL; 100 } else { 101 err->description = psAlloc(sizeof(char)*strlen(description)+1); 102 strcpy((char*)err->description,description); 103 } 104 105 p_psMemSetDeallocator(err,(psFreeFcn)freeErrorDescription); 106 return err; 107 } 108 85 109 86 110 const char *psErrorCodeString(psErrorCode code) … … 114 138 } 115 139 140 if (dynamicErrorCodes == NULL) { 141 dynamicErrorCodes = psListAlloc(NULL); 142 p_psMemSetPersistent(dynamicErrorCodes,true); 143 } 144 116 145 for (int i=0;i<nerror;i++) { 146 psErrorDescription* err = psErrorDescriptionAlloc( 147 errors[i].code, errors[i].description); 148 p_psMemSetPersistent(err,true); 149 p_psMemSetPersistent((void*)err->description,true); 117 150 if (! psListAdd(dynamicErrorCodes, 118 151 PS_LIST_HEAD, 119 (void*)&errors[i]) ) {152 err) ) { 120 153 121 154 psErrorMsg(PS_ERRORNAME_DOMAIN "psErrorRegister", … … 124 157 i); 125 158 } 159 p_psMemSetPersistent(dynamicErrorCodes->head,true); 160 psFree(err); 126 161 } 127 162 } 128 163 164 bool p_psErrorUnregister(psErrorCode code) 165 { 166 // Check input argument is non-negative 167 if ( code < 0 ) { 168 return false; 169 } 170 171 const psErrorDescription* desc = getErrorDescription(code); 172 173 if (desc == NULL) { 174 return false; 175 } 176 177 if (dynamicErrorCodes == NULL) { 178 return false; 179 } 180 181 return psListRemove(dynamicErrorCodes,PS_LIST_UNKNOWN,(void*)desc); 182 } -
trunk/psLib/src/sys/psErrorCodes.h
r1905 r2129 7 7 * @author Robert DeSonia, MHPCC 8 8 * 9 * @version $Revision: 1.1 0$ $Name: not supported by cvs2svn $10 * @date $Date: 2004- 09-27 20:38:02$9 * @version $Revision: 1.11 $ $Name: not supported by cvs2svn $ 10 * @date $Date: 2004-10-14 21:14:58 $ 11 11 * 12 12 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 64 64 psErrorDescription; 65 65 66 /** Allocates a new psErrorDescription 67 * 68 * @return psErrorDescription* new psErrorDescription struct. 69 */ 70 psErrorDescription* psErrorDescriptionAlloc( 71 psErrorCode code, ///< An error code 72 const char *description ///< the associated description 73 ); 74 66 75 /** Retrieves the description of an error code. 67 76 * … … 87 96 ); 88 97 98 /** Clears error codes registered via psErrorRegister. 99 * 100 * @return bool TRUE if given errorcode was removed, otherwise FALSE. 101 */ 102 bool p_psErrorUnregister( 103 psErrorCode code ///< the error code to find and remove 104 ); 105 89 106 /// @} 90 107 -
trunk/psLib/src/sysUtils/psErrorCodes.c
r1905 r2129 7 7 * @author Robert DeSonia, MHPCC 8 8 * 9 * @version $Revision: 1. 9$ $Name: not supported by cvs2svn $10 * @date $Date: 2004- 09-27 20:38:02$9 * @version $Revision: 1.10 $ $Name: not supported by cvs2svn $ 10 * @date $Date: 2004-10-14 21:14:58 $ 11 11 * 12 12 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii 13 13 */ 14 15 #include <string.h> 14 16 15 17 #include "psError.h" … … 75 77 desc = (psErrorDescription*)psListGet(dynamicErrorCodes,PS_LIST_HEAD); 76 78 while (desc != NULL) { 77 desc = (psErrorDescription*)psListGetNext(dynamicErrorCodes); 78 if (desc != NULL && desc->code == code) { 79 if (desc->code == code) { 79 80 return desc; 80 81 } 82 desc = (psErrorDescription*)psListGetNext(dynamicErrorCodes); 81 83 } 82 84 } 83 85 return NULL; 84 86 } 87 88 static void freeErrorDescription(psErrorDescription* err) 89 { 90 psFree((void*)err->description); 91 } 92 93 psErrorDescription* psErrorDescriptionAlloc(psErrorCode code, 94 const char *description) 95 { 96 psErrorDescription* err = psAlloc(sizeof(psErrorDescription)); 97 err->code = code; 98 if (description == NULL) { 99 err->description = NULL; 100 } else { 101 err->description = psAlloc(sizeof(char)*strlen(description)+1); 102 strcpy((char*)err->description,description); 103 } 104 105 p_psMemSetDeallocator(err,(psFreeFcn)freeErrorDescription); 106 return err; 107 } 108 85 109 86 110 const char *psErrorCodeString(psErrorCode code) … … 114 138 } 115 139 140 if (dynamicErrorCodes == NULL) { 141 dynamicErrorCodes = psListAlloc(NULL); 142 p_psMemSetPersistent(dynamicErrorCodes,true); 143 } 144 116 145 for (int i=0;i<nerror;i++) { 146 psErrorDescription* err = psErrorDescriptionAlloc( 147 errors[i].code, errors[i].description); 148 p_psMemSetPersistent(err,true); 149 p_psMemSetPersistent((void*)err->description,true); 117 150 if (! psListAdd(dynamicErrorCodes, 118 151 PS_LIST_HEAD, 119 (void*)&errors[i]) ) {152 err) ) { 120 153 121 154 psErrorMsg(PS_ERRORNAME_DOMAIN "psErrorRegister", … … 124 157 i); 125 158 } 159 p_psMemSetPersistent(dynamicErrorCodes->head,true); 160 psFree(err); 126 161 } 127 162 } 128 163 164 bool p_psErrorUnregister(psErrorCode code) 165 { 166 // Check input argument is non-negative 167 if ( code < 0 ) { 168 return false; 169 } 170 171 const psErrorDescription* desc = getErrorDescription(code); 172 173 if (desc == NULL) { 174 return false; 175 } 176 177 if (dynamicErrorCodes == NULL) { 178 return false; 179 } 180 181 return psListRemove(dynamicErrorCodes,PS_LIST_UNKNOWN,(void*)desc); 182 } -
trunk/psLib/src/sysUtils/psErrorCodes.h
r1905 r2129 7 7 * @author Robert DeSonia, MHPCC 8 8 * 9 * @version $Revision: 1.1 0$ $Name: not supported by cvs2svn $10 * @date $Date: 2004- 09-27 20:38:02$9 * @version $Revision: 1.11 $ $Name: not supported by cvs2svn $ 10 * @date $Date: 2004-10-14 21:14:58 $ 11 11 * 12 12 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 64 64 psErrorDescription; 65 65 66 /** Allocates a new psErrorDescription 67 * 68 * @return psErrorDescription* new psErrorDescription struct. 69 */ 70 psErrorDescription* psErrorDescriptionAlloc( 71 psErrorCode code, ///< An error code 72 const char *description ///< the associated description 73 ); 74 66 75 /** Retrieves the description of an error code. 67 76 * … … 87 96 ); 88 97 98 /** Clears error codes registered via psErrorRegister. 99 * 100 * @return bool TRUE if given errorcode was removed, otherwise FALSE. 101 */ 102 bool p_psErrorUnregister( 103 psErrorCode code ///< the error code to find and remove 104 ); 105 89 106 /// @} 90 107 -
trunk/psLib/test/sysUtils/tst_psError.c
r1884 r2129 13 13 * @author Eric Van Alst, MHPCC 14 14 * 15 * @version $Revision: 1.1 2$ $Name: not supported by cvs2svn $16 * @date $Date: 2004- 09-24 22:48:59$15 * @version $Revision: 1.13 $ $Name: not supported by cvs2svn $ 16 * @date $Date: 2004-10-14 21:14:58 $ 17 17 * 18 18 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 32 32 static int testError04(void); 33 33 static int testError05(void); 34 static int testErrorRegister(void); 34 35 35 36 // Function used in testError02 to verify the psErrorStackPrintV function … … 53 54 {testError04, 728, "psErrorClear()", 0, false}, 54 55 {testError05, 729, "psErrorCodeString()", 0, false}, 56 {testErrorRegister, 751, "psErrorRegister()", 0, false}, 55 57 {NULL} 56 58 }; … … 298 300 } 299 301 302 static int testErrorRegister(void) 303 { 304 305 int numErr = 4; 306 psErrorDescription errDesc[] = { {PS_ERR_N_ERR_CLASSES+1,"first"}, 307 {PS_ERR_N_ERR_CLASSES+2,"second"}, 308 {PS_ERR_N_ERR_CLASSES+3,"third"}, 309 {PS_ERR_N_ERR_CLASSES+4,"fourth"} }; 310 /* 311 1. invoke psErrorRegister with a n>1 array of psErrorDescriptions. Verify that: 312 a. Each error description given is retrievable with psErrorCodeString. 313 */ 314 psErrorRegister(errDesc,numErr); 315 316 for (int i = 0; i < numErr; i++) { 317 const char* desc = psErrorCodeString(PS_ERR_N_ERR_CLASSES+1+i); 318 if (desc == NULL) { 319 psLogMsg(__func__,PS_LOG_ERROR, 320 "psErrorCode didn't find registered error code."); 321 return 1+i*10; 322 } 323 if (strcmp(desc,errDesc[i].description) != 0) { 324 psLogMsg(__func__,PS_LOG_ERROR, 325 "psErrorCode didn't return the proper description. Got '%s', expected '%s'.", 326 desc,errDesc[i].description); 327 return 2+i*10; 328 } 329 } 330 331 /* 332 2. invoke psErrorCodeString with a static/builtin psLib error code. Verify: 333 a. the result is correct. 334 */ 335 const char* desc = psErrorCodeString(PS_ERR_N_ERR_CLASSES); 336 if (desc == NULL) { 337 psLogMsg(__func__,PS_LOG_ERROR, 338 "psErrorCode didn't find static error code."); 339 return 40; 340 } 341 if (strcmp(desc,"error classes end marker") != 0) { 342 psLogMsg(__func__,PS_LOG_ERROR, 343 "psErrorCode didn't return the proper description. Got '%s', expected '%s'.", 344 desc,"error classes end marker"); 345 return 41; 346 } 347 348 desc = psErrorCodeString(PS_ERR_NONE); 349 if (desc == NULL) { 350 psLogMsg(__func__,PS_LOG_ERROR, 351 "psErrorCode didn't find static error code."); 352 return 42; 353 } 354 if (strcmp(desc,"not an error") != 0) { 355 psLogMsg(__func__,PS_LOG_ERROR, 356 "psErrorCode didn't return the proper description. Got '%s', expected '%s'.", 357 desc,"not an error"); 358 return 43; 359 } 360 361 /* 362 3. invoke psErrorCodeString with an invalid code. Verify a NULL is returned. 363 */ 364 desc = psErrorCodeString(PS_ERR_N_ERR_CLASSES+numErr+1); 365 if (desc != NULL) { 366 psLogMsg(__func__,PS_LOG_ERROR, 367 "psErrorCode didn't return a NULL with a bogus input code."); 368 return 44; 369 } 370 371 /* 372 4. invoke psErrorRegister with a NULL psErrorDescription. Verify that: 373 a. the execution does not cease. 374 b. an appropriate error is generated. 375 */ 376 psLogMsg(__func__,PS_LOG_INFO,"Following should be an error."); 377 psErrorClear(); 378 psErrorRegister(NULL,1); 379 psErr* err = psErrorLast(); 380 if (err->code != PS_ERR_BAD_PARAMETER_NULL) { 381 psLogMsg(__func__,PS_LOG_ERROR, 382 "psErrorCode didn't generate proper error code for NULL input."); 383 return 45; 384 } 385 psFree(err); 386 387 /* 388 5. invoke psErrorRegister with nerror=0. Verify that no error occurs. 389 */ 390 psErrorClear(); 391 psErrorRegister(errDesc,0); 392 err = psErrorLast(); 393 if (err->code != PS_ERR_NONE) { 394 psLogMsg(__func__,PS_LOG_ERROR, 395 "psErrorCode generated an error for nErrors = 0."); 396 return 46; 397 } 398 psFree(err); 399 return 0; 400 } -
trunk/psLib/test/sysUtils/verified/tst_psError.stderr
r1882 r2129 102 102 ---> TESTPOINT PASSED (psError{psErrorCodeString()} | tst_psError.c) 103 103 104 /***************************** TESTPOINT ******************************************\ 105 * TestFile: tst_psError.c * 106 * TestPoint: psError{psErrorRegister()} * 107 * TestType: Positive * 108 \**********************************************************************************/ 109 110 <DATE><TIME>|<HOST>|I|testErrorRegister 111 Following should be an error. 112 <DATE><TIME>|<HOST>|E|psLib.sysUtils.psErrorRegister 113 Specified psErrorDescription pointer can not be NULL. 114 115 ---> TESTPOINT PASSED (psError{psErrorRegister()} | tst_psError.c) 116
Note:
See TracChangeset
for help on using the changeset viewer.
