IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 7901


Ignore:
Timestamp:
Jul 13, 2006, 4:26:25 PM (20 years ago)
Author:
drobbin
Message:

Added str check test for error handling of psString fxns, namely stringSubstitute. Edited memory and type to include MemCheck's for string, line, and region. Added is_psType function to check for NULLs and native types first. <-will have to update all fxns next wrt to this change. Added psStringAlloc, stringFree, regionFree. Added doxygen comments.

Location:
trunk/psLib
Files:
1 added
13 edited

Legend:

Unmodified
Added
Removed
  • trunk/psLib/src/math/psRegion.c

    r7563 r7901  
    66#include "psRegion.h"
    77
     8static void regionFree(psRegion *region)
     9{
     10    // There are non dynamic allocated items
     11}
     12
    813psRegion *psRegionAlloc(float x0,
    914                        float x1,
     
    1217{
    1318    psRegion *region = psAlloc(sizeof(psRegion)); // New region, to be returned
     19    psMemSetDeallocator(region, (psFreeFunc)regionFree);
    1420    // No complex structures, so no special deallocator
    1521    *region = psRegionSet(x0, x1, y0, y1);
     
    101107}
    102108
     109bool psMemCheckRegion(psPtr ptr)
     110{
     111    if (!is_psType(ptr)) {
     112        return false;
     113    }
     114    return ( psMemGetDeallocator(ptr) == (psFreeFunc)regionFree );
     115}
     116
     117
  • trunk/psLib/src/math/psRegion.h

    r7563 r7901  
    2727                        float y1        ///< the last row of the region + 1.
    2828                       );
     29
     30/** Checks the type of a particular pointer.
     31 *
     32 *  Uses the appropriate deallocation function in psMemBlock to check the ptr datatype.
     33 *
     34 *  @return bool:       True if the pointer matches a psRegion structure, false otherwise.
     35 */
     36bool psMemCheckRegion(
     37    psPtr ptr                          ///< the pointer whose type to check
     38);
    2939
    3040/** Create a psRegion with the specified attributes.
     
    7080);
    7181
    72 // Test if any element of the region is NaN
    73 bool psRegionIsNaN(psRegion region// Region to check
    74                   );
     82/** Test if any element of the region is NaN
     83 *
     84 * @return bool:        True if an element is NaN, otherwise false.
     85 */
     86bool psRegionIsNaN(
     87    psRegion region                    ///< Region to check
     88);
    7589
    7690#endif
  • trunk/psLib/src/sys/psLine.c

    r7380 r7901  
    3939}
    4040
    41 bool psLineAdd(psLine *line, const char *format, ...)
     41bool psLineAdd(psLine *line,
     42               const char *format,
     43               ...)
    4244{
    4345    if (!line) {
     
    5860    return true;
    5961}
     62
     63bool psMemCheckLine(psPtr ptr)
     64{
     65    if (!is_psType(ptr)) {
     66        return false;
     67    }
     68    return ( psMemGetDeallocator(ptr) == (psFreeFunc)lineFree );
     69}
     70
  • trunk/psLib/src/sys/psLine.h

    r7847 r7901  
    11/** @file  psLine.h
    22 *
    3  * the psLine functions allow manipulation of fixed-length lines
     3 *
     4 *  @brief Contains the declarations of line utility functions
     5 *
     6 *  @ingroup SysUtils
     7 *
     8 *  The psLine functions allow manipulation of fixed-length lines.
     9 *
     10 *  @author Paul Price, IFA
     11 *  @author David Robbins, MHPCC
     12 *
     13 *  @version $Revision: 1.3 $ $Name: not supported by cvs2svn $
     14 *  @date $Date: 2006-07-14 02:26:25 $
     15 *
     16 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
    417 */
    518
    619#ifndef PS_LINE_H
    720#define PS_LINE_H
     21
     22/** @addtogroup SysUtils
     23 *  @{
     24 */
    825
    926/** Structure to carry a dynamic string */
     
    1633psLine;
    1734
    18 /** Allocates a line object of length Nline
     35/** Allocates a line object of length Nline.
    1936 *
    2037 *  @return psLine*:        the newly allocated line object.
    2138*/
    2239psLine *psLineAlloc(
    23     long Nline                         ///<
     40    long Nline                         ///< length of line object to allocate
     41);
     42
     43/** Checks the type of a particular pointer.
     44 *
     45 *  Uses the appropriate deallocation function in psMemBlock to check the ptr datatype.
     46 *
     47 *  @return bool:       True if the pointer matches a psLine structure, false otherwise.
     48 */
     49bool psMemCheckLine(
     50    psPtr ptr                          ///< the pointer whose type to check
    2451);
    2552
     
    3259*/
    3360bool psLineInit(
    34     psLine *line                       ///<
     61    psLine *line                       ///< line to (re-)initialize
    3562);
    3663
  • trunk/psLib/src/sys/psMemory.c

    r7617 r7901  
    88*  @author Robert Lupton, Princeton University
    99*
    10 *  @version $Revision: 1.73 $ $Name: not supported by cvs2svn $
    11 *  @date $Date: 2006-06-21 21:40:12 $
     10*  @version $Revision: 1.74 $ $Name: not supported by cvs2svn $
     11*  @date $Date: 2006-07-14 02:26:25 $
    1212*
    1313*  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    2424#include "psAbort.h"
    2525#include "psLogMsg.h"
    26 
    2726#include "psBitSet.h"
    28 //#include "psArray.h"
    29 //#include "psImage.h"
    30 //#include "psList.h"
    31 //#include "psLookupTable.h"
    32 //#include "psHash.h"
    33 
    34 //#include "psMetadata.h"
    3527#include "psFits.h"
    3628#include "psPixels.h"
    37 //#include "psScalar.h"
    38 //#include "psVector.h"
    39 //#include "psTime.h"
    40 //#include "psCoord.h"
    4129#include "psSphereOps.h"
    42 //#include "psStats.h"
    4330#include "psMinimizeLMM.h"
    4431#include "psImageConvolve.h"
    4532#include "psTime.h"
    46 
     33#include "psLine.h"
     34#include "psRegion.h"
    4735#include "psErrorText.h"
    4836
     
    837825}
    838826
     827bool is_psType(psPtr ptr)
     828{
     829    if (ptr == NULL) {
     830        return false;
     831    }
     832    psMemBlock* m = ((psMemBlock* ) ptr) - 1;
     833    if (m->startblock != P_PS_MEMMAGIC || m->endblock != P_PS_MEMMAGIC) {
     834        return false; //Probably not a psAllocated-Type
     835    } else {
     836        return true;
     837    }
     838}
     839
    839840bool psMemCheckType(psDataType type,
    840841                    psPtr ptr)
    841842{
     843    if (!is_psType(ptr)) {
     844        return false;
     845    }
     846
    842847    switch(type) {
    843848    case PS_DATA_ARRAY:
     
    905910            break;
    906911        }
     912    case PS_DATA_LINE:
     913        if ( psMemCheckLine(ptr) )
     914            return true;
     915        else {
     916            psError(PS_ERR_BAD_PARAMETER_VALUE, false,
     917                    "Incorrect pointer.  Datatypes do not match.\n");
     918            break;
     919        }
    907920    case PS_DATA_LIST:
    908921        if ( psMemCheckList(ptr) )
     
    10171030            break;
    10181031        }
     1032    case PS_DATA_REGION:
     1033        if ( psMemCheckRegion(ptr) )
     1034            return true;
     1035        else {
     1036            psError(PS_ERR_BAD_PARAMETER_VALUE, false,
     1037                    "Incorrect pointer.  Datatypes do not match.\n");
     1038            break;
     1039        }
    10191040    case PS_DATA_SCALAR:
    10201041        if ( psMemCheckScalar(ptr) )
     
    10511072    case PS_DATA_STATS:
    10521073        if ( psMemCheckStats(ptr) )
     1074            return true;
     1075        else {
     1076            psError(PS_ERR_BAD_PARAMETER_VALUE, false,
     1077                    "Incorrect pointer.  Datatypes do not match.\n");
     1078            break;
     1079        }
     1080    case PS_DATA_STRING:
     1081        if ( psMemCheckString(ptr) )
    10531082            return true;
    10541083        else {
  • trunk/psLib/src/sys/psMemory.h

    r7617 r7901  
    1212 *  @ingroup MemoryManagement
    1313 *
    14  *  @version $Revision: 1.56 $ $Name: not supported by cvs2svn $
    15  *  @date $Date: 2006-06-21 21:40:12 $
     14 *  @version $Revision: 1.57 $ $Name: not supported by cvs2svn $
     15 *  @date $Date: 2006-07-14 02:26:25 $
    1616 *
    1717 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    172172);
    173173
     174bool is_psType(
     175    psPtr ptr
     176);
     177
    174178/** Checks the deallocator to see if the pointer matches the desired datatype.
    175179 *
  • trunk/psLib/src/sys/psString.c

    r7879 r7901  
    1313 *  @author David Robbins, MHPCC
    1414 *
    15  *  @version $Revision: 1.36 $ $Name: not supported by cvs2svn $
    16  *  @date $Date: 2006-07-12 21:17:51 $
     15 *  @version $Revision: 1.37 $ $Name: not supported by cvs2svn $
     16 *  @date $Date: 2006-07-14 02:26:25 $
    1717 *
    1818 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    3030#include "psErrorText.h"
    3131
     32static void stringFree(psString string)
     33{
     34    // There is non dynamic allocated item
     35}
     36
     37psString psStringAlloc(long nChar)
     38{
     39    if (nChar < 1) {
     40        return NULL;
     41    }
     42    psString string = psAlloc(nChar + 1);
     43    psMemSetDeallocator(string, (psFreeFunc)stringFree);
     44    return string;
     45}
     46
     47bool psMemCheckString(psPtr ptr)
     48{
     49    if (!is_psType(ptr)) {
     50        return false;
     51    }
     52    return ( psMemGetDeallocator(ptr) == (psFreeFunc)stringFree );
     53}
     54
    3255psString psStringCopy(const char *string)
    3356{
     
    231254        return input;
    232255    }
     256    if (!psMemCheckString(input)) {
     257        return input;
     258    }
     259
    233260
    234261    // replace == NULL is valid: it just means that we strip out the key
  • trunk/psLib/src/sys/psString.h

    r7853 r7901  
    1414 *  @author David Robbins, MHPCC
    1515 *
    16  *  @version $Revision: 1.25 $ $Name: not supported by cvs2svn $
    17  *  @date $Date: 2006-07-10 20:15:43 $
     16 *  @version $Revision: 1.26 $ $Name: not supported by cvs2svn $
     17 *  @date $Date: 2006-07-14 02:26:25 $
    1818 *
    1919 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    3939 *  @{
    4040 */
     41
     42/** Allocates a new psString.
     43 *
     44 *  @return psString:       Newly allocated string of length n.
     45 */
     46psString psStringAlloc(
     47    long nChar                         ///< Size of psString to allocate.
     48);
     49
     50/** Checks the type of a particular pointer.
     51 *
     52 *  Uses the appropriate deallocation function in psMemBlock to check the ptr datatype.
     53 *
     54 *  @return bool:       True if the pointer matches a psString structure, false otherwise.
     55 */
     56bool psMemCheckString(
     57    psPtr ptr                          ///< the pointer whose type to check
     58);
    4159
    4260/** Copies the input string
     
    145163);
    146164
    147 
    148165/** @} */// Doxygen - End of SystemGroup Functions
    149166
  • trunk/psLib/src/sys/psType.h

    r7472 r7901  
    1010*  @author Ross Harman, MHPCC
    1111*
    12 *  @version $Revision: 1.50 $ $Name: not supported by cvs2svn $
    13 *  @date $Date: 2006-06-10 02:28:17 $
     12*  @version $Revision: 1.51 $ $Name: not supported by cvs2svn $
     13*  @date $Date: 2006-07-14 02:26:25 $
    1414*
    1515*  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    118118    PS_DATA_IMAGE,                     ///< psImage
    119119    PS_DATA_KERNEL,                    ///< psKernel
     120    PS_DATA_LINE,                      ///< psLine
    120121    PS_DATA_LIST,                      ///< psList
    121122    PS_DATA_LOOKUPTABLE,               ///< psLookupTable
  • trunk/psLib/test/sys/Makefile.am

    r7884 r7901  
    1212        tst_psString \
    1313        tst_psTrace \
    14         tap_psStringSubstitute
     14        tap_psStringSubstitute \
     15        tst_psLine
    1516
    1617tst_psAbort_SOURCES =  tst_psAbort.c
     
    2122tst_psString_SOURCES =  tst_psString.c
    2223tst_psTrace_SOURCES =  tst_psTrace.c
     24tst_psLine_SOURCES =  tst_psLine.c
    2325
    2426tap_psStringSubstitute_CPPFLAGS = $(AM_CPPFLAGS) -I$(top_srcdir)/test/tap/src
  • trunk/psLib/test/sys/tst_psString.c

    r7880 r7901  
    2020 *  @author  Eric Van Alst, MHPCC
    2121 *
    22  *  @version $Revision: 1.10 $  $Name: not supported by cvs2svn $
    23  *  @date  $Date: 2006-07-12 21:25:39 $
     22 *  @version $Revision: 1.11 $  $Name: not supported by cvs2svn $
     23 *  @date  $Date: 2006-07-14 02:26:25 $
    2424 *
    2525 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    5353static psS32 testStrSplit00(void);
    5454static psS32 testNULLStrings(void);
     55static psS32 testStrCheck(void);
    5556
    5657testDescription tests[] = {
     
    7475                              {testStrSplit00,15, "Test String Splitting", 0, false},
    7576                              {testNULLStrings,666, "Test NULL String Error Handling", 0, false},
     77                              {testStrCheck,16, "Test String Allocation and MemCheck", 0, false},
    7678                              {NULL}
    7779                          };
     
    709711    return 0;
    710712}
     713
     714psS32 testStrCheck(void)
     715{
     716    psString str = NULL;
     717    str = psStringAlloc(10);
     718    strcpy(str, "Hello");
     719    if (!psMemCheckString(str)) {
     720        psError(PS_ERR_BAD_PARAMETER_VALUE, true,
     721                "psString wasn't properly allocated!\n");
     722        return 1;
     723    }
     724    if (!psMemCheckType(PS_DATA_STRING, str)) {
     725        psError(PS_ERR_BAD_PARAMETER_VALUE, true,
     726                "psString wasn't properly allocated!\n");
     727        return 2;
     728    }
     729    psFree(str);
     730
     731    char charStr[10];
     732    if (psMemCheckType(PS_DATA_STRING, charStr)) {
     733        psError(PS_ERR_BAD_PARAMETER_VALUE, true,
     734                "Input string is not a psDataType!!!  (Should have returned false)\n");
     735        return 3;
     736    }
     737
     738    return 0;
     739}
     740
  • trunk/psLib/test/sys/verified/tst_psString.stderr

    r7880 r7901  
    175175---> TESTPOINT PASSED (psString{Test NULL String Error Handling} | tst_psString.c)
    176176
     177/***************************** TESTPOINT ******************************************\
     178*             TestFile: tst_psString.c                                             *
     179*            TestPoint: psString{Test String Allocation and MemCheck}              *
     180*             TestType: Positive                                                   *
     181\**********************************************************************************/
     182
     183
     184---> TESTPOINT PASSED (psString{Test String Allocation and MemCheck} | tst_psString.c)
     185
  • trunk/psLib/test/types/verified/tst_psMetadata_06.stdout

    r5454 r7901  
    99Key Name:  myItem1  Key mdType: 0x00000104  Key Value:             222  Key Comment: I am a signed integer
    1010Key Name:  myItem2  Key mdType: 0x00000104  Key Value:             333  Key Comment: I am a signed integer
    11 Key Name:  myItem2  Key mdType: 0x00010009  Key Value:          psList  Key Comment: I am a list
     11Key Name:  myItem2  Key mdType: 0x0001000a  Key Value:          psList  Key Comment: I am a list
    1212
    1313---> TESTPOINT PASSED (psMetadata{Test A - Allocate metadata and items} | tst_psMetadata_06.c)
Note: See TracChangeset for help on using the changeset viewer.