IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 2129


Ignore:
Timestamp:
Oct 14, 2004, 11:14:58 AM (22 years ago)
Author:
desonia
Message:

fixed/tested psErrorRegister and psErrorCodeString.

Location:
trunk/psLib
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/psLib/psLib.kdevses

    r2110 r2129  
    22<!DOCTYPE KDevPrjSession>
    33<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" />
    88   </View0>
    99  </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>
    4010 </DocsAndViews>
    4111 <pluginList>
  • trunk/psLib/src/pslib.h

    r1974 r2129  
    99*  @author Eric Van Alst, MHPCC
    1010*
    11 *  @version $Revision: 1.25 $ $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 $
    1313*
    1414*  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    161161#include "psAstrometry.h"
    162162
     163#include "psConstants.h"
    163164/// @}
    164165
  • trunk/psLib/src/sys/psErrorCodes.c

    r1905 r2129  
    77 *  @author Robert DeSonia, MHPCC
    88 *
    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 $
    1111 *
    1212 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
    1313 */
     14
     15#include <string.h>
    1416
    1517#include "psError.h"
     
    7577        desc = (psErrorDescription*)psListGet(dynamicErrorCodes,PS_LIST_HEAD);
    7678        while (desc != NULL) {
    77             desc = (psErrorDescription*)psListGetNext(dynamicErrorCodes);
    78             if (desc != NULL && desc->code == code) {
     79            if (desc->code == code) {
    7980                return desc;
    8081            }
     82            desc = (psErrorDescription*)psListGetNext(dynamicErrorCodes);
    8183        }
    8284    }
    8385    return NULL;
    8486}
     87
     88static void freeErrorDescription(psErrorDescription* err)
     89{
     90    psFree((void*)err->description);
     91}
     92
     93psErrorDescription* 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
    85109
    86110const char *psErrorCodeString(psErrorCode code)
     
    114138    }
    115139
     140    if (dynamicErrorCodes == NULL) {
     141        dynamicErrorCodes = psListAlloc(NULL);
     142        p_psMemSetPersistent(dynamicErrorCodes,true);
     143    }
     144
    116145    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);
    117150        if (! psListAdd(dynamicErrorCodes,
    118151                        PS_LIST_HEAD,
    119                         (void*)&errors[i]) ) {
     152                        err) ) {
    120153
    121154            psErrorMsg(PS_ERRORNAME_DOMAIN "psErrorRegister",
     
    124157                       i);
    125158        }
     159        p_psMemSetPersistent(dynamicErrorCodes->head,true);
     160        psFree(err);
    126161    }
    127162}
    128163
     164bool 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  
    77 *  @author Robert DeSonia, MHPCC
    88 *
    9  *  @version $Revision: 1.10 $ $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 $
    1111 *
    1212 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    6464psErrorDescription;
    6565
     66/** Allocates a new psErrorDescription
     67 *
     68 *  @return psErrorDescription*        new psErrorDescription struct.
     69 */
     70psErrorDescription* psErrorDescriptionAlloc(
     71    psErrorCode code,                  ///< An error code
     72    const char *description            ///< the associated description
     73);
     74
    6675/** Retrieves the description of an error code.
    6776 *
     
    8796);
    8897
     98/** Clears error codes registered via psErrorRegister.
     99 *
     100 *  @return bool    TRUE if given errorcode was removed, otherwise FALSE.
     101 */
     102bool p_psErrorUnregister(
     103    psErrorCode code                   ///< the error code to find and remove
     104);
     105
    89106/// @}
    90107
  • trunk/psLib/src/sysUtils/psErrorCodes.c

    r1905 r2129  
    77 *  @author Robert DeSonia, MHPCC
    88 *
    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 $
    1111 *
    1212 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
    1313 */
     14
     15#include <string.h>
    1416
    1517#include "psError.h"
     
    7577        desc = (psErrorDescription*)psListGet(dynamicErrorCodes,PS_LIST_HEAD);
    7678        while (desc != NULL) {
    77             desc = (psErrorDescription*)psListGetNext(dynamicErrorCodes);
    78             if (desc != NULL && desc->code == code) {
     79            if (desc->code == code) {
    7980                return desc;
    8081            }
     82            desc = (psErrorDescription*)psListGetNext(dynamicErrorCodes);
    8183        }
    8284    }
    8385    return NULL;
    8486}
     87
     88static void freeErrorDescription(psErrorDescription* err)
     89{
     90    psFree((void*)err->description);
     91}
     92
     93psErrorDescription* 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
    85109
    86110const char *psErrorCodeString(psErrorCode code)
     
    114138    }
    115139
     140    if (dynamicErrorCodes == NULL) {
     141        dynamicErrorCodes = psListAlloc(NULL);
     142        p_psMemSetPersistent(dynamicErrorCodes,true);
     143    }
     144
    116145    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);
    117150        if (! psListAdd(dynamicErrorCodes,
    118151                        PS_LIST_HEAD,
    119                         (void*)&errors[i]) ) {
     152                        err) ) {
    120153
    121154            psErrorMsg(PS_ERRORNAME_DOMAIN "psErrorRegister",
     
    124157                       i);
    125158        }
     159        p_psMemSetPersistent(dynamicErrorCodes->head,true);
     160        psFree(err);
    126161    }
    127162}
    128163
     164bool 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  
    77 *  @author Robert DeSonia, MHPCC
    88 *
    9  *  @version $Revision: 1.10 $ $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 $
    1111 *
    1212 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    6464psErrorDescription;
    6565
     66/** Allocates a new psErrorDescription
     67 *
     68 *  @return psErrorDescription*        new psErrorDescription struct.
     69 */
     70psErrorDescription* psErrorDescriptionAlloc(
     71    psErrorCode code,                  ///< An error code
     72    const char *description            ///< the associated description
     73);
     74
    6675/** Retrieves the description of an error code.
    6776 *
     
    8796);
    8897
     98/** Clears error codes registered via psErrorRegister.
     99 *
     100 *  @return bool    TRUE if given errorcode was removed, otherwise FALSE.
     101 */
     102bool p_psErrorUnregister(
     103    psErrorCode code                   ///< the error code to find and remove
     104);
     105
    89106/// @}
    90107
  • trunk/psLib/test/sysUtils/tst_psError.c

    r1884 r2129  
    1313 *  @author  Eric Van Alst, MHPCC
    1414 *
    15  *  @version $Revision: 1.12 $  $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 $
    1717 *
    1818 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    3232static int testError04(void);
    3333static int testError05(void);
     34static int testErrorRegister(void);
    3435
    3536// Function used in testError02 to verify the psErrorStackPrintV function
     
    5354                              {testError04, 728, "psErrorClear()", 0, false},
    5455                              {testError05, 729, "psErrorCodeString()", 0, false},
     56                              {testErrorRegister, 751, "psErrorRegister()", 0, false},
    5557                              {NULL}
    5658                          };
     
    298300}
    299301
     302static 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  
    102102---> TESTPOINT PASSED (psError{psErrorCodeString()} | tst_psError.c)
    103103
     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.