IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
May 7, 2004, 12:06:17 PM (22 years ago)
Author:
evanalst
Message:

Added memory leak checks.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psLib/test/sysUtils/tst_psString.c

    r543 r605  
    1111 *    5) Copy string to larger string - psStringNCopy
    1212 *    6) Copy string with negative size - psStringNCopy
     13 *    7) Verifiy creation of string literal - PS_STRING
    1314 *
    1415 *  Return:   Number of test points which failed
     
    1617 *  @author  Eric Van Alst, MHPCC
    1718 *
    18  *  @version $Revision: 1.2 $  $Name: not supported by cvs2svn $
    19  *  @date  $Date: 2004-04-28 22:00:02 $
     19 *  @version $Revision: 1.3 $  $Name: not supported by cvs2svn $
     20 *  @date  $Date: 2004-05-07 22:06:17 $
    2021 *
    2122 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    3233    bool  tpResult = false;
    3334    char  *stringval = "E R R O R";
    34     char  *substringval = "E R R ";
     35    char  *stringval1 = "e r r o r";
     36    char  *stringvalnocopy = "F A I L";
     37    char  *substringval = "e r r ";
    3538    int   substringlen = 6;
    3639    char  *emptyval = "";
     
    4144    int   result = 0;
    4245    int   result1 = 0;
     46    int   memBlockAllocated = 0;
     47    psMemBlock ***memBlockPtr = NULL;
    4348
    4449    // Test point #1 Verify string copy - psStringCopy
     
    4954    if ( result != 0 ) {
    5055        fprintf(stderr, "Failed test point #1 strcmp result = %d expected 0\n",result);
     56        fprintf(stderr, "                               src = %s expected %s\n",
     57                strResult, stringval);
    5158        tpResult = false;
    5259        tpFails++;
     
    5461        tpResult = true;
    5562    }
     63    // Free memory allocated
     64    psFree(strResult);
    5665    printFooter(stderr, "psStringCopy","Verify string copy", tpResult);
    5766
     
    6372    if ( result != 0 ) {
    6473        fprintf(stderr,"Failed test point #2 strcmp result = %d expected 0\n",result);
     74        fprintf(stderr,"                               src = %s expected %s\n",
     75                strResult, emptyval);
    6576        tpResult = false;
    6677        tpFails++;
     
    6879        tpResult = true;
    6980    }
     81    // Free memory allocated
     82    psFree(strResult);
    7083    printFooter(stderr, "psStringCopy","Verify empty string copy", tpResult);
    7184
    7285    // Test point #3 Verify string copy with length - psStringNCopy
    7386    printPositiveTestHeader(stderr,"psStringNCopy","Verify string copy with length");
    74     strResult = psStringNCopy(stringval, substringlen);
     87    strResult = psStringNCopy(stringval1, substringlen);
    7588    // Perform string compare and get string length
    76     result = strcmp(strResult, substringval);
    77     result1 = strlen(strResult);
    78     if ( ( result != 0 ) ||
    79             ( result1 != substringlen ) ) {
     89    result = strncmp(strResult, substringval, substringlen);
     90    if ( result != 0 )  {
    8091        fprintf(stderr,"Failed test point #3 strcmp result = %d expected 0\n",result);
    81         fprintf(stderr,"                     strlen result = %d expected %d\n",
    82                 result1, substringlen);
     92        fprintf(stderr,"                               src = %s expected %s\n",
     93                strResult, substringval);
    8394        tpResult = false;
    8495        tpFails++;
     
    8697        tpResult = true;
    8798    }
     99    // Free memory allocated
     100    psFree(strResult);
    88101    printFooter(stderr, "psStringNCopy","Verify string copy with length", tpResult);
    89102
    90103    // Test point #4 Verify empty string copy with length - psStringNCopy
    91104    printPositiveTestHeader(stderr,"psStringNCopy", "Verify empty string copy with length");
    92     strResult = psStringNCopy(stringval, 0);
     105    strResult = psStringNCopy(stringvalnocopy, 0);
    93106    // Perform string compare and get sting length
    94     result = strcmp(strResult, emptyval);
     107    result = strcmp(strResult, stringvalnocopy);
    95108    result1 = strlen(strResult);
    96     if ( ( result != 0 ) ||
    97             ( result1 != strlen(emptyval) ) ) {
    98         fprintf(stderr,"Failed test point #4 strcmp result = %d expected %d\n",result,0);
    99         fprintf(stderr,"                     strlen result = %d expected %d\n",result1,
    100                 (int)strlen(emptyval));
     109    if ( result == 0 ) {
     110        fprintf(stderr,"Failed test point #4 strcmp result = %d didn't expected %d\n",result,0);
     111        fprintf(stderr,"                               src = %s didn't expected %s\n",
     112                strResult, stringvalnocopy);
    101113        tpResult = false;
    102114        tpFails++;
     
    104116        tpResult = true;
    105117    }
     118    // Free memory
     119    psFree(strResult);
    106120    printFooter(stderr, "psStringNCopy","Verify empty string copy with length", tpResult);
    107121
     
    116130            ( result1 != strlen(stringval) ) ) {
    117131        fprintf(stderr,"Failed test point #5 strcmp result = %d expected %d\n",result,0);
     132        fprintf(stderr,"                               src = %s expected %s\n",
     133                strResult, stringval);
    118134        fprintf(stderr,"                     strlne result = %d expected %d\n",result1,
    119135                (int)strlen(stringval));
     
    123139        tpResult = true;
    124140    }
     141    // Free memory
     142    psFree(strResult);
    125143    printFooter(stderr, "psStringNCopy", "Copy string to larger string", tpResult);
    126144
     
    136154        tpResult = true;
    137155    }
     156    // Memory should not have been allocated
    138157    printFooter(stderr, "psStringNCopy", "Copy string with negative size", tpResult);
     158
     159    // Test point #7 Verify creation of string literal - PS_STRING
     160    printPositiveTestHeader(stderr,"PS_STRING","Verify creation of string literal");
     161    strResult = PS_STRING(E R R O R);
     162    result = strcmp(strResult, stringval);
     163    if ( result != 0 ) {
     164        fprintf(stderr,"Failed test point #7 strcmp result = %d expected %d",result,0);
     165        tpResult = false;
     166        tpFails++;
     167    } else {
     168        tpResult = true;
     169    }
     170    // Memory should not have been allocated
     171    printFooter(stderr, "PS_STRING", "Verify creation of string literal", tpResult);
     172
     173    // Check for memory leaks
     174    memBlockAllocated = psMemCheckLeaks(0, memBlockPtr, stderr);
     175    if ( memBlockAllocated != 0 ) {
     176        fprintf(stderr,"Failed - Memory leaks detected - Blocks still allocated = %d\n",
     177                memBlockAllocated);
     178        tpFails++;
     179    }
    139180
    140181    // Display test driver fail message if tpFail not zero
Note: See TracChangeset for help on using the changeset viewer.