IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
May 16, 2005, 9:43:53 AM (21 years ago)
Author:
evanalst
Message:

Bug #392 fix.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psLib/test/collections/tst_psMetadataIO.c

    r3779 r3945  
    44 *
    55 *  This test driver contains the following tests for psMetadata:
    6  *    Test A - Read config file with overwrite set true
    7  *    Test B - Read config file with overwrite set false
    8  *    Test C - Read config file without auto-allocation of metadata
    9  *    Test D - Attempt to use null fileName argument
    10  *    Test E - Attempt to open nonexistant file
    11  *    Test F - Free psMetadata
     6 *    Read config file with overwrite set true
     7 *    Read config file with overwrite set false
     8 *    Attempt to use null fileName argument
     9 *    Attempt to open nonexistant file
    1210 *
    1311 *  @author  Ross Harman, MHPCC
    1412 *  @author  Robert DeSonia, MHPCC
     13 *  @author  Eric Van Alst, MHPCC
    1514 *
    16  *  @version $Revision: 1.14 $  $Name: not supported by cvs2svn $
    17  *  @date  $Date: 2005-04-28 02:45:12 $
     15 *  @version $Revision: 1.15 $  $Name: not supported by cvs2svn $
     16 *  @date  $Date: 2005-05-16 19:41:40 $
    1817 *
    1918 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    2524#include "psTest.h"
    2625
    27 static void printMetadataItem(psMetadataItem *metadataItem, char *spaces);
    28 static void printMetadata(psMetadata *metadata);
    29 static void printMetadataList(psList *metadataItemList, char* spaces);
    30 static void printMetadataTable(psHash *mdTable);
    31 
    32 static void printMetadata(psMetadata *metadata)
    33 {
    34     printf("Contents of metadata list:\n");
    35     printMetadataList(metadata->list, " ");
    36     printf("\nContents of metadata table:\n");
    37     printMetadataTable(metadata->table);
    38 }
    39 
    40 static void printMetadataList(psList *metadataItemList, char* spaces)
    41 {
    42     psMetadataItem *entryChild = NULL;
    43 
     26static psS32 testMetadataParseConfig(void);
     27static psS32 testMetadataParseConfig1(void);
     28static psS32 testMetadataParseConfig2(void);
     29
     30testDescription tests[] = {
     31                              {testMetadataParseConfig,000,"psMetadataParseConfig",0,false},
     32                              {testMetadataParseConfig1,000,"psMetadataParseConfig",0,false},
     33                              {testMetadataParseConfig2,000,"psMetadataParseConfig",0,false},
     34                              {NULL}
     35                          };
     36
     37static void writeMetadataItem(psMetadataItem* metadataIem, char* indentStr);
     38static void writeMetadata(psMetadata* metadata, char* indentStr);
     39static void writeMetadataList(psList *metadataItemList, char* indentStr);
     40
     41static psBool checkFailedLines(psS32 failedLines, psS32 expectedFailedLines, char* configFile);
     42static psBool checkNumberOfItems(psMetadata* md, psS32 expectedItems, char* configFile);
     43static psBool checkItemName(psMetadataItem* mdItem, char* expectedName, char* configFile);
     44static psBool checkItemType(psMetadataItem* mdItem, psS32 expectedType, char* configFile);
     45static psBool checkItemComment(psMetadataItem* mdItem, char* expectedComment, char* configFile);
     46
     47#define ERROR_TOL  0.0001
     48
     49const char testConfig3[] = "test3.config";
     50const psS32 testConfig3Fails = 1;
     51
     52const char testConfig2[] = "test2.config";
     53const psS32 testConfig2Fails = 17;
     54
     55// SDR-14 test config file #1
     56const char  testConfig1[] = "test1.config";
     57const psS32 testConfig1FailsOverwrite = 0;
     58const psS32 testConfig1Fails = 1;
     59const psS32 testConfig1Items = 25;
     60const char* testConfig1KeyOverwrite[] =
     61    {
     62        "Double","String","boolean","primes","comment",
     63        "comment","comment","comment","comment","Float",
     64        "boolean1","negprimes","vector1","vector2","vector3",
     65        "vector4","vector5","vector6","vector7","vector8",
     66        "CELL.00", "CELL.01","MYCELL","MYCELL","cell"
     67    };
     68const char* testConfig1CommentOverwrite[] =
     69    {
     70        "This is a comment","comment","The value of 'boolean' is 'true'","These are prime numbers",
     71        "","","","","",
     72        "This generates a warning, and, if 'overwrite' is 'false', is ignored","The value of 'boolean' is 'false'",
     73        "","","","","",
     74        "","","","",
     75        "","","","A number",""
     76    };
     77const psMetadataType testConfig1TypeOverwrite[] =
     78    {
     79        PS_META_F64, PS_META_STR, PS_META_BOOL, PS_META_VEC, PS_META_STR,
     80        PS_META_STR, PS_META_STR, PS_META_STR, PS_META_STR,  PS_META_F64,
     81        PS_META_BOOL, PS_META_VEC, PS_META_VEC, PS_META_VEC, PS_META_VEC,
     82        PS_META_VEC, PS_META_VEC, PS_META_VEC, PS_META_VEC, PS_META_VEC,
     83        PS_META_META, PS_META_META, PS_META_META, PS_META_S32, PS_META_META
     84    };
     85const psS32 testConfig1ValueS32Overwrite[] =
     86    {
     87        0, 0, 0, 0, 0,
     88        0, 0, 0, 0, 0,
     89        0, 0, 0, 0, 0,
     90        0, 0, 0, 0, 0,
     91        0, 0, 0, 123, 0
     92    };
     93const psF32 testConfig1ValueF32Overwrite[] =
     94    {
     95        0.0, 0.0, 0.0, 0.0, 0.0,
     96        0.0, 0.0, 0.0, 0.0, 0.0,
     97        0.0, 0.0, 0.0, 0.0, 0.0,
     98        0.0, 0.0, 0.0, 0.0, 0.0,
     99        0.0, 0.0, 0.0, 0.0, 0.0
     100    };
     101const psF64 testConfig1ValueF64Overwrite[] =
     102    {
     103        1.23456789, 0.0, 0.0, 0.0, 0.0,
     104        0.0, 0.0, 0.0, 0.0, 1.23456,
     105        0.0, 0.0, 0.0, 0.0, 0.0,
     106        0.0, 0.0, 0.0, 0.0, 0.0,
     107        0.0, 0.0, 0.0, 0.0, 0.0
     108    };
     109const psBool testConfig1ValueBoolOverwrite[] =
     110    {
     111        false, false, true, false, false,
     112        false, false, false, false, false,
     113        false, false, false, false, false,
     114        false, false, false, false, false,
     115        false, false, false, false, false
     116    };
     117const char* testConfig1ValueStrOverwrite[] =
     118    {
     119        "", "This is the string that forms the value","","","This",
     120        "is","a","non-unique","key","",
     121        "","","","","",
     122        "","","","","",
     123        "","","","",""
     124    };
     125const psS32 testConfig1ValueVecItemsU8 = 7;
     126const psElemType testConfig1ValueVecTypeU8 = PS_TYPE_U8;
     127const psU8 testConfig1ValueVecValueU8[] =
     128    {
     129        2, 3, 5, 7, 11, 13, 17
     130    };
     131const psS32 testConfig1ValueVecItemsS8 = 8;
     132const psElemType testConfig1ValueVecTypeS8 = PS_TYPE_S8;
     133const psS8 testConfig1ValueVecValueS8[] =
     134    {
     135        -2, -3, -5, -7, -11, -13, -17, -19
     136    };
     137const psS32 testConfig1ValueVecItemsU16 = 5;
     138const psElemType testConfig1ValueVecTypeU16 = PS_TYPE_U16;
     139const psU16 testConfig1ValueVecValueU16[] =
     140    {
     141        0, 1, 2, 4, 8
     142    };
     143const psS32 testConfig1ValueVecItemsU32 = 6;
     144const psElemType testConfig1ValueVecTypeU32 = PS_TYPE_U32;
     145const psU32 testConfig1ValueVecValueU32[] =
     146    {
     147        0, 8, 16, 32, 64, 128
     148    };
     149const psS32 testConfig1ValueVecItemsU64 = 3;
     150const psElemType testConfig1ValueVecTypeU64 = PS_TYPE_U64;
     151const psU64 testConfig1ValueVecValueU64[] =
     152    {
     153        0, 64, 256
     154    };
     155const psS32 testConfig1ValueVecItemsS16 = 5;
     156const psElemType testConfig1ValueVecTypeS16 = PS_TYPE_S16;
     157const psS16 testConfig1ValueVecValueS16[] =
     158    {
     159        -2, -1, 0, 1, 2
     160    };
     161const psS32 testConfig1ValueVecItemsS32 = 6;
     162const psElemType testConfig1ValueVecTypeS32 = PS_TYPE_S32;
     163const psS32 testConfig1ValueVecValueS32[] =
     164    {
     165        -4, -2, 0, 2, 4, 6
     166    };
     167const psS32 testConfig1ValueVecItemsS64 = 7;
     168const psElemType testConfig1ValueVecTypeS64 = PS_TYPE_S64;
     169const psS64 testConfig1ValueVecValueS64[] =
     170    {
     171        -16, -4, 0, 4, 16, 36, 64
     172    };
     173const psS32 testConfig1ValueVecItemsF32 = 4;
     174const psElemType testConfig1ValueVecTypeF32 = PS_TYPE_F32;
     175const psF32 testConfig1ValueVecValueF32[] =
     176    {
     177        -1.03, 1.04, -1.05, 1.06
     178    };
     179const psS32 testConfig1ValueVecItemsF64 = 5;
     180const psElemType testConfig1ValueVecTypeF64 = PS_TYPE_F64;
     181const psF64 testConfig1ValueVecValueF64[] =
     182    {
     183        -2.22, 2.21, -2.20, 2.19, -2.18
     184    };
     185const psS32 testConfig1ValueMetaItems1 = 3;
     186const char* testConfig1ValueMetaNames1[] =
     187    {
     188        "EXTNAME","BIASSEC","CHIP"
     189    };
     190const psMetadataType testConfig1ValueMetaTypes1[] =
     191    {
     192        PS_META_STR, PS_META_STR, PS_META_STR
     193    };
     194const char* testConfig1ValueMetaValue1[] =
     195    {
     196        "CCD00","BSEC-00","CHIP.00"
     197    };
     198const psS32 testConfig1ValueMetaItems2 = 3;
     199const char* testConfig1ValueMetaNames2[] =
     200    {
     201        "EXTNAME","BIASSEC","CHIP"
     202    };
     203const psMetadataType testConfig1ValueMetaTypes2[] =
     204    {
     205        PS_META_STR, PS_META_STR, PS_META_STR
     206    };
     207const char* testConfig1ValueMetaValue2[] =
     208    {
     209        "CCD01","BSEC-01","CHIP.00"
     210    };
     211const psS32 testConfig1ValueMetaItems3 = 4;
     212const char* testConfig1ValueMetaNames3[] =
     213    {
     214        "EXTNAME","BIASSEC","CHIP","NCELL"
     215    };
     216const psMetadataType testConfig1ValueMetaTypes3[] =
     217    {
     218        PS_META_STR, PS_META_STR, PS_META_STR, PS_META_S32
     219    };
     220const char* testConfig1ValueMetaValueStr3[] =
     221    {
     222        "CCD00","BSEC-00","CHIP.00",""
     223    };
     224const psS32 testConfig1ValueMetaValueS323[] =
     225    {
     226        0, 0, 0, 24
     227    };
     228
     229static void writeMetadata(psMetadata* metadata, char* indentStr)
     230{
     231    writeMetadataList(metadata->list, indentStr);
     232}
     233
     234static void writeMetadataList(psList* metadataItemList, char* indentStr)
     235{
     236    psMetadataItem* entryChild        = NULL;
     237    psMetadataItem* searchChild       = NULL;
     238    psArray*        nonUniqueKeyArray = NULL;
     239    psBool          keyFound          = false;
     240    char*           tempKey           = NULL;
     241
     242    // Allocate iterator for moving through metadata list
    44243    psListIterator* iter = psListIteratorAlloc(metadataItemList, PS_LIST_HEAD, true);
    45 
    46     while ( (entryChild=psListGetAndIncrement(iter)) != NULL) {
    47         printMetadataItem(entryChild, spaces);
     244    psListIterator* searchIter = psListIteratorAlloc(metadataItemList, PS_LIST_HEAD, true);
     245
     246    // Allocate array for nonUnique key names
     247    nonUniqueKeyArray = psArrayAlloc(10);
     248    nonUniqueKeyArray->n = 0;
     249
     250
     251    // Loop through all items in the list
     252    while ( (entryChild = psListGetAndIncrement(iter)) != NULL) {
     253        // Search list for another entry with same key name
     254        // Check if last entry
     255        if(iter->index != metadataItemList->size) {
     256            // Set search iterator to index
     257            if(!psListIteratorSet(searchIter,iter->index) ) {
     258                psError(PS_ERR_UNKNOWN,true,"Error searching list for multiple keys");
     259                break;
     260            }
     261            keyFound = false;
     262            while ( (searchChild = psListGetAndIncrement(searchIter)) != NULL) {
     263                if(strcmp(entryChild->name,searchChild->name) == 0) {
     264                    // Search nonUnique key array
     265                    for(psS32 i = 0; i < nonUniqueKeyArray->n; i++) {
     266                        if(strcmp(entryChild->name,nonUniqueKeyArray->data[i]) == 0) {
     267                            keyFound = true;
     268                        }
     269                    }
     270                    if(!keyFound) {
     271                        // Add key to non-unique array
     272                        tempKey = psStringCopy(entryChild->name);
     273                        nonUniqueKeyArray = psArrayAdd(nonUniqueKeyArray,1,tempKey);
     274                        psFree(tempKey);
     275
     276                        // Print MULTI line
     277                        printf("%-25s MULTI\n",entryChild->name);
     278
     279                        // Break out of loop
     280                        break;
     281                    }
     282                }
     283            }
     284        }
     285        writeMetadataItem(entryChild,indentStr);
    48286    }
    49287
    50288    psFree(iter);
    51 }
    52 
    53 static void printMetadataTable(psHash *mdTable)
    54 {
    55     psS32 i;
    56     psHashBucket* ptr = NULL;
    57     for(i=0; i<mdTable->nbucket; i++) {
    58         ptr = mdTable->buckets[i];
    59         while (ptr != NULL) {
    60             printMetadataItem(ptr->data, " ");
    61             ptr = ptr->next;
    62         }
    63     }
    64 }
    65 
    66 static void printMetadataItem(psMetadataItem *metadataItem, char *spaces)
    67 {
    68     char* vecStr;
    69 
    70     printf("%sKey Name: %8s  ", spaces, metadataItem->name);
    71     printf("Key mdType: 0x%08x ", metadataItem->type);
    72 
    73     switch (metadataItem->type) {
    74     case PS_META_MULTI:
    75         printf("Key Value: %17c", ' ');
     289    psFree(searchIter);
     290    psFree(nonUniqueKeyArray);
     291}
     292
     293char* vectorToConfigString(psVector* vector)
     294{
     295    psS32  maxLength = 256;
     296
     297    char* str = psAlloc(sizeof(char)*maxLength+1);
     298
     299    if (vector == NULL) {
     300        snprintf(str,maxLength, "NULL");
     301        return str;
     302    }
     303
     304    int size = vector->n;
     305
     306    if (size == 0) {
     307        snprintf(str,maxLength, " ");
     308        return str;
     309    }
     310
     311    char* tempStr = psAlloc(sizeof(char)*maxLength+1);
     312    *str = '\0';
     313    bool full = false;
     314
     315    #define APPEND_ELEMENTS_CASE(TYPE, NATIVE_TYPE, FORMAT) \
     316case PS_TYPE_##TYPE: \
     317    strcat(str,#TYPE); \
     318    for(psS32 i = 0; i < (strlen(str)-6); i++) {  \
     319        strcat(str," "); \
     320    } \
     321    for (lcv=0; lcv < size && ! full; lcv++) { \
     322        snprintf(tempStr, maxLength, "%s" FORMAT, prefix, (NATIVE_TYPE) (vector->data.TYPE[lcv])); \
     323        strncat(str,tempStr,maxLength); \
     324        full = (strlen(str) > maxLength-2); \
     325        prefix = ","; \
     326    } \
     327    break;
     328
     329    int lcv;
     330    char* prefix = " ";
     331    switch(vector->type.type) {
     332        APPEND_ELEMENTS_CASE(S8,char,"%hd")
     333        APPEND_ELEMENTS_CASE(S16,short int,"%hd")
     334        APPEND_ELEMENTS_CASE(S32,int,"%d")
     335        APPEND_ELEMENTS_CASE(S64,long,"%ld")
     336        APPEND_ELEMENTS_CASE(U8,unsigned char,"%hu")
     337        APPEND_ELEMENTS_CASE(U16,unsigned short,"%hu")
     338        APPEND_ELEMENTS_CASE(U32,unsigned int, "%u")
     339        APPEND_ELEMENTS_CASE(U64,unsigned long,"%lu")
     340        APPEND_ELEMENTS_CASE(F32,double,"%g")
     341        APPEND_ELEMENTS_CASE(F64,double,"%g")
     342    default:
     343        snprintf(str,maxLength,"INVALID TYPE");
    76344        break;
     345    }
     346
     347    psFree(tempStr);
     348
     349    return str;
     350}
     351
     352
     353static void writeMetadataItem(psMetadataItem *metadataItem, char* indentStr)
     354{
     355    char*  vecStr;
     356
     357    switch(metadataItem->type) {
    77358    case PS_META_BOOL:
    78         printf("Key Value: %15d  ", metadataItem->data.B);
     359        printf("%s%-25s BOOL  %40d",indentStr,metadataItem->name,metadataItem->data.B);
    79360        break;
    80361    case PS_META_S32:
    81         printf("Key Value: %15d  ", metadataItem->data.S32);
     362        printf("%s%-25s S32   %40d",indentStr,metadataItem->name,metadataItem->data.S32);
    82363        break;
    83364    case PS_META_F32:
    84         printf("Key Value: %15.3f  ", metadataItem->data.F32);
     365        printf("%s%-25s F32   %40f",indentStr,metadataItem->name,metadataItem->data.F32);
    85366        break;
    86367    case PS_META_F64:
    87         printf("Key Value: %15.3f  ", metadataItem->data.F64);
     368        printf("%s%-25s F64   %40lf",indentStr,metadataItem->name,metadataItem->data.F64);
    88369        break;
    89370    case PS_META_VEC:
    90         vecStr = (char*)psVectorToString((psVector*)metadataItem->data.V, 15);
    91         printf("Key Value: %15s  ", vecStr);
     371        vecStr = (char*)vectorToConfigString((psVector*)metadataItem->data.V);
     372        printf("%s@%-24s %s",indentStr,metadataItem->name,vecStr);
    92373        psFree(vecStr);
    93374        break;
    94375    case PS_META_STR:
    95         printf("Key Value: %15s  ", (char*)metadataItem->data.V);
     376        printf("%s%-25s STR   %40s",indentStr,metadataItem->name,(char*)metadataItem->data.V);
     377        break;
     378    case PS_META_META:
     379        printf("%s%-25s METADATA\n",indentStr,metadataItem->name);
     380        writeMetadata((psMetadata*)metadataItem->data.md,"    ");
    96381        break;
    97382    default:
    98         printf("Bad type: 0x%08x ", metadataItem->type);
    99     }
    100     printf("Key Comment: %s\n", metadataItem->comment);
    101 
    102     if(metadataItem->data.V && metadataItem->type==PS_META_MULTI) {
    103         printMetadataList(metadataItem->data.V, "    ");
    104     }
    105 }
    106 
     383        printf("#%s%-24s BAD TYPE=%d",indentStr,metadataItem->name,metadataItem->type);
     384        break;
     385    }
     386    if(strlen(metadataItem->comment) > 0) {
     387        printf("  # %-20s\n",metadataItem->comment);
     388    } else {
     389        printf("\n");
     390    }
     391}
     392
     393static psBool checkFailedLines(psS32 failedLines, psS32 expectedFailedLines, char* configFile)
     394{
     395    psBool     returnValue = true;
     396
     397    // Verify the expected number of failed lines
     398    if(failedLines != expectedFailedLines) {
     399        psError(PS_ERR_UNKNOWN,true,"File: %s : Number of failed lines = %d not as expected %d",
     400                configFile,failedLines,expectedFailedLines);
     401        returnValue = false;
     402    }
     403    return returnValue;
     404}
     405
     406static psBool checkNumberOfItems(psMetadata* md, psS32 expectedItems, char* configFile)
     407{
     408    psBool     returnValue = true;
     409
     410    // Verify the number of items in metadata
     411    if(md->list->size != expectedItems) {
     412        psError(PS_ERR_UNKNOWN,true,"File: %s : Number of items = %d not as expected %d",
     413                configFile,md->list->size, expectedItems);
     414        returnValue = false;
     415    }
     416    return returnValue;
     417}
     418
     419static psBool checkItemName(psMetadataItem* mdItem, char* expectedName, char* configFile)
     420{
     421    psBool    returnValue = true;
     422
     423    // Compare key names
     424    if(strcmp(mdItem->name,expectedName) != 0) {
     425        psError(PS_ERR_UNKNOWN,true,"File: %s : Key name %s not as expected %s",
     426                configFile,mdItem->name,expectedName);
     427        returnValue = false;
     428    }
     429
     430    return returnValue;
     431}
     432
     433static psBool checkItemType(psMetadataItem* mdItem, psS32 expectedType, char* configFile)
     434{
     435    psBool     returnValue = true;
     436
     437    // Compare types
     438    if(mdItem->type != expectedType) {
     439        psError(PS_ERR_UNKNOWN,true,"File: %s : Type %d not as expected %d",
     440                configFile,mdItem->type,expectedType);
     441        returnValue = false;
     442    }
     443    return returnValue;
     444}
     445
     446static psBool checkItemComment(psMetadataItem* mdItem, char* expectedComment, char* configFile)
     447{
     448    psBool    returnValue = true;
     449
     450    // Compare comments
     451    if(strcmp(mdItem->comment,expectedComment) != 0) {
     452        psError(PS_ERR_UNKNOWN,true,"File: %s : Comment %s not as expected %s",
     453                configFile,mdItem->comment,expectedComment);
     454        returnValue = false;
     455    }
     456    return returnValue;
     457}
    107458
    108459psS32 main(psS32 argc, char* argv[])
    109460{
    110     // Test A - Read config file with overwrite set true
    111     printPositiveTestHeader(stdout, "psMetadata", "Test A - Read config file with overwrite set true");
    112     psMetadata *metadata1 = NULL;
    113     psU32 failedLines1 = 0;
    114     metadata1 = psMetadataParseConfig(metadata1, &failedLines1, "test.config", true);
    115     printf("Failed lines: %d Expected: 6\n", failedLines1);
    116     printMetadata(metadata1);
    117     printFooter(stdout, "psMetadata", "Test A - Read config file with overwrite set true", true);
    118 
    119 
    120     // Test B - Read config file with overwrite set false
    121     printPositiveTestHeader(stdout, "psMetadata", "Test B - Read config file with overwrite set false");
    122     psMetadata *metadata2 = NULL;
    123     psU32 failedLines2 = 0;
    124     metadata2 = psMetadataParseConfig(metadata2, &failedLines2, "test.config", false);
    125     printf("Failed lines: %d Expected: 7 ", failedLines2);
    126     printMetadata(metadata2);
    127     printFooter(stdout, "psMetadata", "Test B - Read config file with overwrite set false", true);
    128 
    129 
    130     // Test C - Read config file without auto-allocation of metadata
    131     printPositiveTestHeader(stdout, "psMetadata", "Test C - Read config file without auto-allocation of metadata");
    132     psMetadata *metadata3 = psMetadataAlloc();
    133     psU32 failedLines3 = 0;
    134     metadata3 = psMetadataParseConfig(metadata3, &failedLines3, "test.config", true);
    135     printf("Failed lines: %d Expected: 6 ", failedLines3);
    136     printMetadata(metadata3);
    137     printFooter(stdout, "psMetadata", "Test C - Read config file without auto-allocation of metadata", true);
    138 
    139 
    140     // Test D - Attempt to use null fileName argument
    141     printNegativeTestHeader(stdout,"psMetadataIO", "Test D - Attempt to use null fileName argument",
    142                             "Null failedLines not allowed", 0);
    143     psMetadataParseConfig(metadata1, &failedLines1, NULL, true);
    144     printFooter(stdout, "psMetadata", "Test D - Attempt to use null fileName argument", true);
    145 
    146 
    147     // Test E - Attempt to open nonexistant file
    148     printNegativeTestHeader(stdout,"psMetadataIO", "Test E - Attempt to open nonexistant file",
    149                             "Error opening file", 0);
    150     psMetadataParseConfig(metadata1, &failedLines1, "abcedfg", true);
    151     printFooter(stdout, "psMetadata", "Test E - Attempt to open nonexistant file", true);
    152 
    153 
    154     // Test F - Free psMetadata
    155     printPositiveTestHeader(stdout, "psMetadata", "Test F - Free psMetadata");
     461    psLogSetLevel(PS_LOG_INFO);
     462
     463    if( !runTestSuite(stderr,"psMetadataParseConfig",tests,argc,argv)) {
     464        return 1;
     465    }
     466
     467    return 0;
     468}
     469
     470psS32 testMetadataParseConfig(void)
     471{
     472    psMetadata*       metadata1      = NULL;
     473    psMetadataItem*   entryChild     = NULL;
     474    psS32             failedLines    = 0;
     475    psListIterator*   iter           = NULL;
     476    psListIterator*   mdIter         = NULL;
     477    psMetadataItem*   mdChild        = NULL;
     478    psS32             metaCounter    = 0;
     479    psS32             mdCounter      = 0;
     480
     481    // Read config file test1.config with overwrite set true
     482    metadata1 = psMetadataParseConfig(metadata1,&failedLines,testConfig1,true);
     483    // Verify the expected number of failed lines
     484    if(!checkFailedLines(failedLines,testConfig1FailsOverwrite,(char*)testConfig1)) {
     485        return 1;
     486    }
     487    // Verify the number of items in metadata
     488    if(!checkNumberOfItems(metadata1,testConfig1Items,(char*)testConfig1)) {
     489        return 2;
     490    }
     491    // Verify metadata item quads
     492    iter = psListIteratorAlloc(metadata1->list, PS_LIST_HEAD, true);
     493    for(psS32 i = 0; i < testConfig1Items; i++) {
     494        // Get list item
     495        entryChild = psListGetAndIncrement(iter);
     496
     497        // Verify end of list not reached prematurely
     498        if(entryChild == NULL) {
     499            psError(PS_ERR_UNKNOWN,true,"End of list encountered at %d not as expected %d",
     500                    i,testConfig1Items);
     501            return i*10+1;
     502        }
     503        // Verify name
     504        if(!checkItemName(entryChild,(char*)testConfig1KeyOverwrite[i],(char*)testConfig1)) {
     505            return i*10+2;
     506        }
     507        // Verify type
     508        if(!checkItemType(entryChild,testConfig1TypeOverwrite[i],(char*)testConfig1)) {
     509            return i*10+3;
     510        }
     511        // Verify comment
     512        if(!checkItemComment(entryChild,(char*)testConfig1CommentOverwrite[i],(char*)testConfig1)) {
     513            return i*10+4;
     514        }
     515        // Compare values
     516        switch(entryChild->type) {
     517        case PS_META_S32:
     518            if(entryChild->data.S32 != testConfig1ValueS32Overwrite[i]) {
     519                psError(PS_ERR_UNKNOWN,true,"File: %s : Value %d not as expected %d",
     520                        testConfig1,entryChild->data.S32, testConfig1ValueS32Overwrite[i]);
     521                return i*10+5;
     522            }
     523            break;
     524        case PS_META_F32:
     525            if(fabs(entryChild->data.F32 - testConfig1ValueF32Overwrite[i]) > ERROR_TOL) {
     526                psError(PS_ERR_UNKNOWN,true,"File: %s : Value %f not as expected %f",
     527                        testConfig1,entryChild->data.F32, testConfig1ValueF32Overwrite[i]);
     528                return i*10+5;
     529            }
     530            break;
     531        case PS_META_F64:
     532            if(fabs(entryChild->data.F64 - testConfig1ValueF64Overwrite[i]) > ERROR_TOL) {
     533                psError(PS_ERR_UNKNOWN,true,"File: %s : Value %lf not as expected %lf",
     534                        testConfig1,entryChild->data.F64, testConfig1ValueF64Overwrite[i]);
     535                return i*10+5;
     536            }
     537            break;
     538        case PS_META_BOOL:
     539            if(entryChild->data.B != testConfig1ValueBoolOverwrite[i]) {
     540                psError(PS_ERR_UNKNOWN,true,"File: %s : Value %d not as expected %d",
     541                        testConfig1,entryChild->data.B,testConfig1ValueBoolOverwrite[i]);
     542                return i*10+5;
     543            }
     544            break;
     545        case PS_META_STR:
     546            if(strcmp(entryChild->data.V,testConfig1ValueStrOverwrite[i]) != 0) {
     547                psError(PS_ERR_UNKNOWN,true,"File: %s : Value %s not as expected %s",
     548                        testConfig1,entryChild->data.V,testConfig1ValueStrOverwrite[i]);
     549                return i*10+5;
     550            }
     551            break;
     552        case PS_META_VEC:
     553            // Verify the correct number of entries
     554            switch(((psVector*)(entryChild->data.V))->type.type) {
     555            case PS_TYPE_U8:
     556                if(((psVector*)(entryChild->data.V))->n != testConfig1ValueVecItemsU8) {
     557                    psError(PS_ERR_UNKNOWN,true,"File: %s : Vector entries %d not as expected %d",
     558                            testConfig1,((psVector*)(entryChild->data.V))->n,testConfig1ValueVecItemsU8);
     559                    return i*10+5;
     560                }
     561                // Verify the correct type
     562                if(((psVector*)(entryChild->data.V))->type.type != testConfig1ValueVecTypeU8) {
     563                    psError(PS_ERR_UNKNOWN,true,"File: %s : Vector type %d not as expected %s",
     564                            testConfig1,((psVector*)entryChild->data.V)->type.type,testConfig1ValueVecTypeU8);
     565                    return i*10+5;
     566                }
     567                // Verify the values in vector
     568                for(psS32 j = 0; j < testConfig1ValueVecItemsU8; j++) {
     569                    if(((psVector*)entryChild->data.V)->data.U8[j] != testConfig1ValueVecValueU8[j]) {
     570                        psError(PS_ERR_UNKNOWN,true,"File: %s : Vector data[%d] = %d not as expected %d",
     571                                testConfig1,j,((psVector*)entryChild->data.V)->data.U8[j],
     572                                testConfig1ValueVecValueU8[j]);
     573                        return i*10+5*j;
     574                    }
     575                }
     576                break;
     577            case PS_TYPE_U16:
     578                if(((psVector*)(entryChild->data.V))->n != testConfig1ValueVecItemsU16) {
     579                    psError(PS_ERR_UNKNOWN,true,"File: %s : Vector entries %d not as expected %d",
     580                            testConfig1,((psVector*)(entryChild->data.V))->n,testConfig1ValueVecItemsU16);
     581                    return i*10+5;
     582                }
     583                // Verify the correct type
     584                if(((psVector*)(entryChild->data.V))->type.type != testConfig1ValueVecTypeU16) {
     585                    psError(PS_ERR_UNKNOWN,true,"File: %s : Vector type %d not as expected %s",
     586                            testConfig1,((psVector*)entryChild->data.V)->type.type,testConfig1ValueVecTypeU16);
     587                    return i*10+5;
     588                }
     589                // Verify the values in vector
     590                for(psS32 j = 0; j < testConfig1ValueVecItemsU16; j++) {
     591                    if(((psVector*)entryChild->data.V)->data.U16[j] != testConfig1ValueVecValueU16[j]) {
     592                        psError(PS_ERR_UNKNOWN,true,"File: %s : Vector data[%d] = %d not as expected %d",
     593                                testConfig1,j,((psVector*)entryChild->data.V)->data.U16[j],
     594                                testConfig1ValueVecValueU16[j]);
     595                        return i*10+5*j;
     596                    }
     597                }
     598                break;
     599            case PS_TYPE_U32:
     600                if(((psVector*)(entryChild->data.V))->n != testConfig1ValueVecItemsU32) {
     601                    psError(PS_ERR_UNKNOWN,true,"File: %s : Vector entries %d not as expected %d",
     602                            testConfig1,((psVector*)(entryChild->data.V))->n,testConfig1ValueVecItemsU32);
     603                    return i*10+5;
     604                }
     605                // Verify the correct type
     606                if(((psVector*)(entryChild->data.V))->type.type != testConfig1ValueVecTypeU32) {
     607                    psError(PS_ERR_UNKNOWN,true,"File: %s : Vector type %d not as expected %s",
     608                            testConfig1,((psVector*)entryChild->data.V)->type.type,testConfig1ValueVecTypeU32);
     609                    return i*10+5;
     610                }
     611                // Verify the values in vector
     612                for(psS32 j = 0; j < testConfig1ValueVecItemsU32; j++) {
     613                    if(((psVector*)entryChild->data.V)->data.U32[j] != testConfig1ValueVecValueU32[j]) {
     614                        psError(PS_ERR_UNKNOWN,true,"File: %s : Vector data[%d] = %d not as expected %d",
     615                                testConfig1,j,((psVector*)entryChild->data.V)->data.U32[j],
     616                                testConfig1ValueVecValueU32[j]);
     617                        return i*10+5*j;
     618                    }
     619                }
     620                break;
     621            case PS_TYPE_U64:
     622                if(((psVector*)(entryChild->data.V))->n != testConfig1ValueVecItemsU64) {
     623                    psError(PS_ERR_UNKNOWN,true,"File: %s : Vector entries %d not as expected %d",
     624                            testConfig1,((psVector*)(entryChild->data.V))->n,testConfig1ValueVecItemsU64);
     625                    return i*10+5;
     626                }
     627                // Verify the correct type
     628                if(((psVector*)(entryChild->data.V))->type.type != testConfig1ValueVecTypeU64) {
     629                    psError(PS_ERR_UNKNOWN,true,"File: %s : Vector type %d not as expected %s",
     630                            testConfig1,((psVector*)entryChild->data.V)->type.type,testConfig1ValueVecTypeU64);
     631                    return i*10+5;
     632                }
     633                // Verify the values in vector
     634                for(psS32 j = 0; j < testConfig1ValueVecItemsU64; j++) {
     635                    if(((psVector*)entryChild->data.V)->data.U64[j] != testConfig1ValueVecValueU64[j]) {
     636                        psError(PS_ERR_UNKNOWN,true,"File: %s : Vector data[%d] = %ld not as expected %ld",
     637                                testConfig1,j,((psVector*)entryChild->data.V)->data.U64[j],
     638                                testConfig1ValueVecValueU64[j]);
     639                        return i*10+5*j;
     640                    }
     641                }
     642                break;
     643            case PS_TYPE_S8:
     644                if(((psVector*)(entryChild->data.V))->n != testConfig1ValueVecItemsS8) {
     645                    psError(PS_ERR_UNKNOWN,true,"File: %s : Vector entries %d not as expected %d",
     646                            testConfig1,((psVector*)(entryChild->data.V))->n,testConfig1ValueVecItemsS8);
     647                    return i*10+5;
     648                }
     649                // Verify the correct type
     650                if(((psVector*)(entryChild->data.V))->type.type != testConfig1ValueVecTypeS8) {
     651                    psError(PS_ERR_UNKNOWN,true,"File: %s : Vector type %d not as expected %s",
     652                            testConfig1,((psVector*)entryChild->data.V)->type.type,testConfig1ValueVecTypeS8);
     653                    return i*10+5;
     654                }
     655                // Verify the values in vector
     656                for(psS32 j = 0; j < testConfig1ValueVecItemsS8; j++) {
     657                    if(((psVector*)entryChild->data.V)->data.S8[j] != testConfig1ValueVecValueS8[j]) {
     658                        psError(PS_ERR_UNKNOWN,true,"File: %s : Vector data[%d] = %d not as expected %d",
     659                                testConfig1,j,((psVector*)entryChild->data.V)->data.S8[j],
     660                                testConfig1ValueVecValueS8[j]);
     661                        return i*10+5*j;
     662                    }
     663                }
     664                break;
     665            case PS_TYPE_S16:
     666                if(((psVector*)(entryChild->data.V))->n != testConfig1ValueVecItemsS16) {
     667                    psError(PS_ERR_UNKNOWN,true,"File: %s : Vector entries %d not as expected %d",
     668                            testConfig1,((psVector*)(entryChild->data.V))->n,testConfig1ValueVecItemsS16);
     669                    return i*10+5;
     670                }
     671                // Verify the correct type
     672                if(((psVector*)(entryChild->data.V))->type.type != testConfig1ValueVecTypeS16) {
     673                    psError(PS_ERR_UNKNOWN,true,"File: %s : Vector type %d not as expected %s",
     674                            testConfig1,((psVector*)entryChild->data.V)->type.type,testConfig1ValueVecTypeS16);
     675                    return i*10+5;
     676                }
     677                // Verify the values in vector
     678                for(psS32 j = 0; j < testConfig1ValueVecItemsS16; j++) {
     679                    if(((psVector*)entryChild->data.V)->data.S16[j] != testConfig1ValueVecValueS16[j]) {
     680                        psError(PS_ERR_UNKNOWN,true,"File: %s : Vector data[%d] = %d not as expected %d",
     681                                testConfig1,j,((psVector*)entryChild->data.V)->data.S16[j],
     682                                testConfig1ValueVecValueS16[j]);
     683                        return i*10+5*j;
     684                    }
     685                }
     686                break;
     687            case PS_TYPE_S32:
     688                if(((psVector*)(entryChild->data.V))->n != testConfig1ValueVecItemsS32) {
     689                    psError(PS_ERR_UNKNOWN,true,"File: %s : Vector entries %d not as expected %d",
     690                            testConfig1,((psVector*)(entryChild->data.V))->n,testConfig1ValueVecItemsS32);
     691                    return i*10+5;
     692                }
     693                // Verify the correct type
     694                if(((psVector*)(entryChild->data.V))->type.type != testConfig1ValueVecTypeS32) {
     695                    psError(PS_ERR_UNKNOWN,true,"File: %s : Vector type %d not as expected %s",
     696                            testConfig1,((psVector*)entryChild->data.V)->type.type,testConfig1ValueVecTypeS32);
     697                    return i*10+5;
     698                }
     699                // Verify the values in vector
     700                for(psS32 j = 0; j < testConfig1ValueVecItemsS32; j++) {
     701                    if(((psVector*)entryChild->data.V)->data.S32[j] != testConfig1ValueVecValueS32[j]) {
     702                        psError(PS_ERR_UNKNOWN,true,"File: %s : Vector data[%d] = %d not as expected %d",
     703                                testConfig1,j,((psVector*)entryChild->data.V)->data.S32[j],
     704                                testConfig1ValueVecValueS32[j]);
     705                        return i*10+5*j;
     706                    }
     707                }
     708                break;
     709            case PS_TYPE_S64:
     710                if(((psVector*)(entryChild->data.V))->n != testConfig1ValueVecItemsS64) {
     711                    psError(PS_ERR_UNKNOWN,true,"File: %s : Vector entries %d not as expected %d",
     712                            testConfig1,((psVector*)(entryChild->data.V))->n,testConfig1ValueVecItemsS64);
     713                    return i*10+5;
     714                }
     715                // Verify the correct type
     716                if(((psVector*)(entryChild->data.V))->type.type != testConfig1ValueVecTypeS64) {
     717                    psError(PS_ERR_UNKNOWN,true,"File: %s : Vector type %d not as expected %s",
     718                            testConfig1,((psVector*)entryChild->data.V)->type.type,testConfig1ValueVecTypeS64);
     719                    return i*10+5;
     720                }
     721                // Verify the values in vector
     722                for(psS32 j = 0; j < testConfig1ValueVecItemsS64; j++) {
     723                    if(((psVector*)entryChild->data.V)->data.S64[j] != testConfig1ValueVecValueS64[j]) {
     724                        psError(PS_ERR_UNKNOWN,true,"File: %s : Vector data[%d] = %ld not as expected %ld",
     725                                testConfig1,j,((psVector*)entryChild->data.V)->data.S64[j],
     726                                testConfig1ValueVecValueS64[j]);
     727                        return i*10+5*j;
     728                    }
     729                }
     730                break;
     731            case PS_TYPE_F32:
     732                if(((psVector*)(entryChild->data.V))->n != testConfig1ValueVecItemsF32) {
     733                    psError(PS_ERR_UNKNOWN,true,"File: %s : Vector entries %d not as expected %d",
     734                            testConfig1,((psVector*)(entryChild->data.V))->n,testConfig1ValueVecItemsF32);
     735                    return i*10+5;
     736                }
     737                // Verify the correct type
     738                if(((psVector*)(entryChild->data.V))->type.type != testConfig1ValueVecTypeF32) {
     739                    psError(PS_ERR_UNKNOWN,true,"File: %s : Vector type %d not as expected %s",
     740                            testConfig1,((psVector*)entryChild->data.V)->type.type,testConfig1ValueVecTypeF32);
     741                    return i*10+5;
     742                }
     743                // Verify the values in vector
     744                for(psS32 j = 0; j < testConfig1ValueVecItemsF32; j++) {
     745                    if(fabs(((psVector*)entryChild->data.V)->data.F32[j]-testConfig1ValueVecValueF32[j])
     746                            > ERROR_TOL) {
     747                        psError(PS_ERR_UNKNOWN,true,"File: %s : Vector data[%d] = %f not as expected %f",
     748                                testConfig1,j,((psVector*)entryChild->data.V)->data.F32[j],
     749                                testConfig1ValueVecValueF32[j]);
     750                        return i*10+5*j;
     751                    }
     752                }
     753                break;
     754            case PS_TYPE_F64:
     755                if(((psVector*)(entryChild->data.V))->n != testConfig1ValueVecItemsF64) {
     756                    psError(PS_ERR_UNKNOWN,true,"File: %s : Vector entries %d not as expected %d",
     757                            testConfig1,((psVector*)(entryChild->data.V))->n,testConfig1ValueVecItemsF64);
     758                    return i*10+5;
     759                }
     760                // Verify the correct type
     761                if(((psVector*)(entryChild->data.V))->type.type != testConfig1ValueVecTypeF64) {
     762                    psError(PS_ERR_UNKNOWN,true,"File: %s : Vector type %d not as expected %s",
     763                            testConfig1,((psVector*)entryChild->data.V)->type.type,testConfig1ValueVecTypeF64);
     764                    return i*10+5;
     765                }
     766                // Verify the values in vector
     767                for(psS32 j = 0; j < testConfig1ValueVecItemsF64; j++) {
     768                    if(fabs(((psVector*)entryChild->data.V)->data.F64[j]-testConfig1ValueVecValueF64[j])
     769                            > ERROR_TOL) {
     770                        psError(PS_ERR_UNKNOWN,true,"File: %s : Vector data[%d] = %lf not as expected %lf",
     771                                testConfig1,j,((psVector*)entryChild->data.V)->data.F64[j],
     772                                testConfig1ValueVecValueF64[j]);
     773                        return i*10+5*j;
     774                    }
     775                }
     776                break;
     777            default:
     778                break;
     779            }
     780            break;
     781        case PS_META_META:
     782            if(metaCounter == 0) {
     783                // Check if number of items is as expected
     784                if(entryChild->data.md->list->size != testConfig1ValueMetaItems1) {
     785                    psError(PS_ERR_UNKNOWN,true,"File: %s : Metadata 1 items %d not as expected %d",
     786                            testConfig1,entryChild->data.md->list->size,testConfig1ValueMetaItems1);
     787                    return i*10+6;
     788                }
     789                // Loop through metadata items
     790                mdIter = psListIteratorAlloc(entryChild->data.md->list, PS_LIST_HEAD, true);
     791                mdCounter = 0;
     792                while ( (mdChild = psListGetAndIncrement(mdIter)) != NULL) {
     793                    if(strcmp(mdChild->name,testConfig1ValueMetaNames1[mdCounter]) != 0) {
     794                        psError(PS_ERR_UNKNOWN,true,"File: %s : Metadata 1 name[%d] %s not as expected %s",
     795                                testConfig1,mdCounter,mdChild->name,testConfig1ValueMetaNames1[mdCounter]);
     796                        return i*10+6*mdCounter;
     797                    }
     798                    if(mdChild->type != testConfig1ValueMetaTypes1[mdCounter]) {
     799                        psError(PS_ERR_UNKNOWN,true,"File: %s : Metadata 1 type[%d] %d not as expected %d",
     800                                testConfig1,mdCounter,mdChild->type,testConfig1ValueMetaTypes1[mdCounter]);
     801                        return i*10+6*mdCounter;
     802                    }
     803                    if(strcmp((char*)mdChild->data.V,testConfig1ValueMetaValue1[mdCounter]) != 0) {
     804                        psError(PS_ERR_UNKNOWN,true,"File: %s : Metadata 1 value[%d] %s not as expected %s",
     805                                testConfig1,mdCounter,(char*)mdChild->data.V,testConfig1ValueMetaValue1[mdCounter]);
     806                        return i*10+6*mdCounter;
     807                    }
     808                    mdCounter++;
     809                }
     810                psFree(mdIter);
     811            } else if(metaCounter == 1) {
     812                // Check if number of items is as expected
     813                if(entryChild->data.md->list->size != testConfig1ValueMetaItems2) {
     814                    psError(PS_ERR_UNKNOWN,true,"File: %s : Metadata 2 items %d not as expected %d",
     815                            testConfig1,entryChild->data.md->list->size,testConfig1ValueMetaItems2);
     816                    return i*10+6;
     817                }
     818                // Loop through metadata items
     819                mdIter = psListIteratorAlloc(entryChild->data.md->list, PS_LIST_HEAD, true);
     820                mdCounter = 0;
     821                while ( (mdChild = psListGetAndIncrement(mdIter)) != NULL) {
     822                    if(strcmp(mdChild->name,testConfig1ValueMetaNames2[mdCounter]) != 0) {
     823                        psError(PS_ERR_UNKNOWN,true,"File: %s : Metadata 2 name[%d] %s not as expected %s",
     824                                testConfig1,mdCounter,mdChild->name,testConfig1ValueMetaNames2[mdCounter]);
     825                        return i*10+6*mdCounter;
     826                    }
     827                    if(mdChild->type != testConfig1ValueMetaTypes2[mdCounter]) {
     828                        psError(PS_ERR_UNKNOWN,true,"File: %s : Metadata 2 type[%d] %d not as expected %d",
     829                                testConfig1,mdCounter,mdChild->type,testConfig1ValueMetaTypes2[mdCounter]);
     830                        return i*10+6*mdCounter;
     831                    }
     832                    if(strcmp((char*)mdChild->data.V,testConfig1ValueMetaValue2[mdCounter]) != 0) {
     833                        psError(PS_ERR_UNKNOWN,true,"File: %s : Metadata 2 value[%d] %s not as expected %s",
     834                                testConfig1,mdCounter,(char*)mdChild->data.V,testConfig1ValueMetaValue2[mdCounter]);
     835                        return i*10+6*mdCounter;
     836                    }
     837                    mdCounter++;
     838                }
     839                psFree(mdIter);
     840            } else if(metaCounter == 2) {
     841                // Check if number of items is as expected
     842                if(entryChild->data.md->list->size != testConfig1ValueMetaItems3) {
     843                    psError(PS_ERR_UNKNOWN,true,"File: %s : Metadata 3 items %d not as expected %d",
     844                            testConfig1,entryChild->data.md->list->size,testConfig1ValueMetaItems3);
     845                    return i*10+6;
     846                }
     847                // Loop through metadata items
     848                mdIter = psListIteratorAlloc(entryChild->data.md->list, PS_LIST_HEAD, true);
     849                mdCounter = 0;
     850                while ( (mdChild = psListGetAndIncrement(mdIter)) != NULL) {
     851                    if(strcmp(mdChild->name,testConfig1ValueMetaNames3[mdCounter]) != 0) {
     852                        psError(PS_ERR_UNKNOWN,true,"File: %s : Metadata 3 name[%d] %s not as expected %s",
     853                                testConfig1,mdCounter,mdChild->name,testConfig1ValueMetaNames3[mdCounter]);
     854                        return i*10+6*mdCounter;
     855                    }
     856                    if(mdChild->type != testConfig1ValueMetaTypes3[mdCounter]) {
     857                        psError(PS_ERR_UNKNOWN,true,"File: %s : Metadata 3 type[%d] %d not as expected %d",
     858                                testConfig1,mdCounter,mdChild->type,testConfig1ValueMetaTypes3[mdCounter]);
     859                        return i*10+6*mdCounter;
     860                    }
     861                    switch(mdChild->type) {
     862                    case PS_META_STR:
     863                        if(strcmp((char*)mdChild->data.V,testConfig1ValueMetaValueStr3[mdCounter]) != 0) {
     864                            psError(PS_ERR_UNKNOWN,true,"File: %s : Metadata 3 value[%d] %s not as expected %s",
     865                                    testConfig1,mdCounter,(char*)mdChild->data.V,
     866                                    testConfig1ValueMetaValueStr3[mdCounter]);
     867                            return i*10+6*mdCounter;
     868                        }
     869                        break;
     870                    case PS_META_S32:
     871                        if(mdChild->data.S32 != testConfig1ValueMetaValueS323[mdCounter]) {
     872                            psError(PS_ERR_UNKNOWN,true,"File: %s : Metadata 3 value[%d] %d not as expected %d",
     873                                    testConfig1,mdCounter,mdChild->data.S32,
     874                                    testConfig1ValueMetaValueS323[mdCounter]);
     875                            return i*10+6*mdCounter;
     876                        }
     877                        break;
     878                    default:
     879                        psError(PS_ERR_UNKNOWN,true,"File: %s : Metadata 3 value[%d] unknown type",
     880                                testConfig1,mdCounter);
     881                        return i*10+6*mdCounter;
     882                        break;
     883                    }
     884                    mdCounter++;
     885                }
     886                psFree(mdIter);
     887            }
     888            metaCounter++;
     889            break;
     890        default:
     891            psError(PS_ERR_UNKNOWN,true,"Unexpected type %d encountered",entryChild->type);
     892            return i*10+5;
     893            break;
     894        }
     895    }
     896
     897    writeMetadata(metadata1,"");
     898
    156899    psFree(metadata1);
    157     psFree(metadata2);
    158     psFree(metadata3);
    159     if(psMemCheckLeaks(0, NULL, stdout,false)) {
    160         psError(PS_ERR_UNKNOWN,true,"Memory leak detected");
    161         return 10;
    162     }
    163     psMemCheckCorruption(0);
    164     psS32 nBad = psMemCheckCorruption(0);
    165     if(nBad) {
    166         printf("ERROR: Found %d bad memory blocks\n", nBad);
    167     }
    168     printFooter(stdout, "psMetadata", "Test F - Free psMetadata", true);
    169 
    170900
    171901    return 0;
    172902}
     903
     904psS32 testMetadataParseConfig1(void)
     905{
     906    psMetadata*       metadata1      = NULL;
     907    psS32             failedLines    = 0;
     908
     909    // Read config file test2.config with overwrite set true
     910    // This file contains parse errors
     911    psLogMsg(__func__,PS_LOG_INFO,"Following should generate parse error message");
     912    metadata1 = psMetadataParseConfig(metadata1,&failedLines,testConfig2,true);
     913    // Verify the expected number of failed lines
     914    if(!checkFailedLines(failedLines,testConfig2Fails,(char*)testConfig2)) {
     915        return 1;
     916    }
     917    // Verify return value is null
     918    if(metadata1 != NULL) {
     919        psError(PS_ERR_UNKNOWN,true,"Expected a NULL return for failed parse");
     920        return 2;
     921    }
     922
     923    // Attempt parse a non-existant file
     924    psLogMsg(__func__,PS_LOG_INFO,"Following should generate error message");
     925    metadata1 = psMetadataParseConfig(metadata1,&failedLines,"ab.config",true);
     926    if(metadata1 != NULL) {
     927        psError(PS_ERR_UNKNOWN,true,"Expected a NULL return for non-existant file");
     928        return 3;
     929    }
     930
     931    // Attempt parse with NULL failed lines ptr
     932    psLogMsg(__func__,PS_LOG_INFO,"Following should generate an error message for NULL failed lines arg");
     933    metadata1 = psMetadataParseConfig(metadata1,NULL,testConfig2,true);
     934    if(metadata1 != NULL) {
     935        psError(PS_ERR_UNKNOWN,true,"Expected a NULL return for NULL failed lines argument");
     936        return 4;
     937    }
     938
     939    // Attempt parse with NULL file name
     940    psLogMsg(__func__,PS_LOG_INFO,"Following should generate an error message for NULL file name arg");
     941    metadata1 = psMetadataParseConfig(metadata1,&failedLines,NULL,true);
     942    if(metadata1 != NULL) {
     943        psError(PS_ERR_UNKNOWN,true,"Expected a NULL return for NULL filename argument");
     944        return 5;
     945    }
     946
     947    psFree(metadata1);
     948
     949    return 0;
     950}
     951
     952psS32 testMetadataParseConfig2(void)
     953{
     954    psMetadata*       metadata1      = NULL;
     955    psS32             failedLines    = 0;
     956
     957    // Read config file test1.config with overwrite set false
     958    psLogMsg(__func__,PS_LOG_INFO,"Following should generate an error of duplicate key names");
     959    metadata1 = psMetadataParseConfig(metadata1,&failedLines,testConfig3,false);
     960    // Verify the expected number of failed lines
     961    if(!checkFailedLines(failedLines,testConfig3Fails,(char*)testConfig3)) {
     962        return 1;
     963    }
     964    if(metadata1 != NULL) {
     965        psError(PS_ERR_UNKNOWN,true,"Expected a NULL return for failed due to overwrite false");
     966        return 2;
     967    }
     968    psFree(metadata1);
     969
     970    return 0;
     971}
     972
Note: See TracChangeset for help on using the changeset viewer.