/** @file  tst_psArguments.c
*
*  @brief Test driver for psArguments functions
*
*  @author  David Robbins, MHPCC
*
*  @version $Revision: 1.1 $  $Name: not supported by cvs2svn $
*  @date  $Date: 2006-01-23 23:52:15 $
*
*  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
*
*/

#include "psTest.h"
#include "pslib_strict.h"

static psS32 testArgument(void);

testDescription tests[] = {
                              {testArgument, 666, "Test psArgument fxns", 0, false},
                              {NULL}
                          };

int main(int argc, char* argv[])
{
    psLogSetLevel( PS_LOG_INFO );
    if( !runTestSuite(stderr,"psArguments",tests,argc,argv)) {
        return 1;
    }
    return 0;
}

psS32 testArgument(void)
{
    char *argv[6];
    argv[0] = "./program";
    argv[1] = "-string";
    argv[2] = "new";
    argv[3] = "-float";
    argv[4] = "6.66";
    argv[5] = "-vvv";
    int argc = 6;

    int i = psArgumentGet(argc, argv, "-float");
    if ( i != 0 ) {
        if ( !psArgumentRemove(i, &argc, argv) ) {
            printf("\n Failed to remove float from argument list\n");
        }
    } else {
        printf("\nFailed to find string in argument list\n");
        return 1;
    }
    psArgumentRemove(i, &argc, argv);
    printf("\n Argument %d has been removed", i);
    int log = psArgumentVerbosity(&argc, argv);
    printf("\nLog level = %d \n", log);

    psMetadata *args = psMetadataAlloc();
    psMetadataAdd(args, PS_LIST_TAIL, "-string", PS_DATA_STRING, "Test String", "SomeString");
    psMetadataAdd(args, PS_LIST_TAIL, "-int", PS_DATA_S32 | PS_META_DUPLICATE_OK, "Int1", 1);
    psMetadataAdd(args, PS_LIST_TAIL, "-int", PS_DATA_S32 | PS_META_DUPLICATE_OK, "Int2", 2);
    psMetadataAdd(args, PS_LIST_TAIL, "-float", PS_DATA_F32, "Test Float", 0.0);

    printf("\nThis Should print the Argument Help list.\n\n");
    psArgumentHelp(args);

    if ( !psArgumentParse(args, &argc, argv) || argc != 1 ) {
        psArgumentHelp(args);
        psFree(args);
        return 2;
    }

    psMetadataPrint(args, 4);

    psFree(args);
    return 0;
}

