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

#include "pslib.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 );
    testArgument();
    //    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, "-float", PS_DATA_F32, "Test Float", 0.0);
    psMetadata *ints = psMetadataAlloc();
    psMetadataAdd(ints, PS_LIST_TAIL, "int1", PS_DATA_S32, "Int1", 1);
    psMetadataAdd(ints, PS_LIST_TAIL, "int2", PS_DATA_S32, "Int2", 2);
    psMetadataAdd(args, PS_LIST_TAIL, "-int", PS_DATA_METADATA, "Integers", ints);
    psFree(ints);                       // Drop reference

    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(NULL, args, 4);

    psFree(args);
    return 0;
}

