IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 9750


Ignore:
Timestamp:
Oct 25, 2006, 6:44:09 PM (20 years ago)
Author:
drobbin
Message:

Update MetadataConfig tests. Removed unreachable spots from psMetadataConfigParse.

Location:
trunk/psLib
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/psLib/src/types/psMetadataConfig.c

    r9736 r9750  
    1010*  @author Eric Van Alst, MHPCC
    1111*
    12 *  @version $Revision: 1.97 $ $Name: not supported by cvs2svn $
    13 *  @date $Date: 2006-10-25 00:16:33 $
     12*  @version $Revision: 1.98 $ $Name: not supported by cvs2svn $
     13*  @date $Date: 2006-10-26 04:44:09 $
    1414*
    1515*  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    11661166    // Attempt to open specified file
    11671167    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) {
    11691171        // XXX really should return strerror() here
    11701172        psError(PS_ERR_IO, true,
    11711173                _("Failed to open file '%s'. Check if it exists and it has the proper "
    11721174                  "permissions."), filename);
     1175        close(fd);
    11731176        return NULL;
    11741177    }
    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.
    11771179    if (fstat(fd, &buf) != 0) {
    11781180        psError(PS_ERR_IO, true, _("Unable to stat file '%s'.\n"), filename);
     
    11801182        return NULL;
    11811183    }
    1182 
     1184    */
    11831185    // psMetadataConfigParse() is going to read the entire file into memory so
    11841186    // we're trying to be nice by allowing the VM to flush the file out of
     
    11881190    if (file == MAP_FAILED) {
    11891191        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);
    11951199        return NULL;
    11961200    }
     
    11991203
    12001204    munmap(file, (size_t)buf.st_size);
    1201 
     1205    /*
    12021206    if (close(fd) != 0) {
    12031207        // XXX really should return strerror() here
     
    12051209        return NULL;
    12061210    }
    1207 
     1211    */
     1212    close(fd);
    12081213    return md;
    12091214}
     
    12411246
    12421247    psList *doc = psStringSplit(str, "\n", false);
    1243     if (!doc) {
     1248    if (!doc || doc->n == 0) {
     1249        if (doc != NULL)
     1250            psFree(doc);
    12441251        psFree(parseLevelInfoArray);
    12451252        psFree(md);
  • trunk/psLib/test/types/tap_psMetadataConfig_input.c

    r9739 r9750  
    1212#include <pslib.h>
    1313#include <string.h>
     14#include <fcntl.h>
     15#include <unistd.h>
     16
    1417
    1518#include "tap.h"
     
    2225int main(void)
    2326{
    24     plan_tests(4);
     27    plan_tests(10);
    2528
    2629    diag("Tests for psMetadataConfig Input Functions");
     
    3942    unsigned int nfail = 0;
    4043    md = psMetadataAlloc();
    41     psMetadataAddS32(md, PS_LIST_HEAD, "new S32", 0, "", 666);
     44    psMetadataAddS32(md, PS_LIST_HEAD, "new_S32", 0, "", 666);
    4245
    4346    //Return NULL for NULL filename input
     
    4750            "psMetadataConfigRead:           return NULL for NULL filename input.");
    4851    }
    49     //Return false for invalid filename input
     52    //Return NULL for invalid filename input
    5053    {
    5154        out = psMetadataConfigRead(out, &nfail, ".", false);
     
    5356            "psMetadataConfigRead:           return NULL for invalid filename input.");
    5457    }
     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    }
    5573    //Return true for valid inputs
    5674    {
    57         skip_start(  !psMetadataConfigWrite(md, "mdcfg.wrt"), 1,
    58                      "Skipping 1 tests because psMetadataConfigWrite failed");
     75        skip_start(  !psMetadataConfigWrite(md, "mdcfg.wrt"), 2,
     76                     "Skipping 2 tests because psMetadataConfigWrite failed");
    5977        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,
    6180            "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();
    6287        skip_end();
    6388    }
     
    76101{
    77102    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
    78140    /*    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
    124183}
    125184
  • trunk/psLib/test/types/tap_psMetadataConfig_output.c

    r9739 r9750  
    124124}
    125125
    126 
    127 /*
    128 void testLookupTableAlloc(void)
    129 {
    130     diag("  >>>Test 1:  psLookupTableAlloc & psMemCheckLookupTable Fxns");
    131  
    132     psLookupTable *lt = NULL;
    133  
    134 //Tests for psLookupTableAlloc
    135    //Return NULL for NULL filename input
    136     {
    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 inputs
    142     {
    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 leaks
    151     {
    152         psFree(lt);
    153         checkMem();
    154     }
    155 }
    156 */
    157 
Note: See TracChangeset for help on using the changeset viewer.