/** @file  tst_psLine.c
 *
 *  @brief Test driver for psLine functions
 *
 *  @author  dRob, MHPCC
 *
 *  @version $Revision: 1.1 $  $Name: not supported by cvs2svn $
 *  @date  $Date: 2006-07-14 02:26:25 $
 *
 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
 *
 */

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

static psS32 testLineAlloc(void);
static psS32 testLineInit(void);
static psS32 testLineAdd(void);
static psS32 testLineChk(void);

testDescription tests[] = {
                              {testLineAlloc, 0, "Verify Line Alloc/Free", 0, false},
                              {testLineInit, 1, "Verify Line Init", 0, false},
                              {testLineAdd, 2, "Verify Line Add", 0, false},
                              {testLineChk, 3, "Verify Line MemCheck", 0, false},
                              {NULL}
                          };

psS32 main( psS32 argc, char* argv[] )
{
    psLogSetLevel( PS_LOG_INFO );

    return ( ! runTestSuite( stderr, "psLine", tests, argc, argv ) );
}

psS32 testLineAlloc(void)
{
    psLine *lineline = NULL;
    lineline = psLineAlloc(20);

    if (lineline->NLINE != 20) {
        psError(PS_ERR_BAD_PARAMETER_VALUE, true,
                "psLine set NLINE parameter incorrectly during Allocation!\n");
        return 2;
    }
    if (lineline->Nline != 0) {
        psError(PS_ERR_BAD_PARAMETER_VALUE, true,
                "psLine set Nline parameter incorrectly during Allocation!\n");
        return 2;
    }
    strncpy(lineline->line, "Hello World", 20);
    if (strncmp(lineline->line, "Hello World", 20)) {
        psError(PS_ERR_BAD_PARAMETER_VALUE, true,
                "psLine was unable to store a simple string!\n");
        return 3;
    }

    psFree(lineline);

    return 0;
}

psS32 testLineInit(void)
{
    psLine *line = NULL;
    //Return false for NULL input
    if (psLineInit(line) ) {
        psError(PS_ERR_BAD_PARAMETER_VALUE, true,
                "psLineInit failed.  Expected false for NULL psLine input.\n");
        return 1;
    }
    //Allocate a line and return true on Init
    line = psLineAlloc(1);
    if(!psLineInit(line) ) {
        psError(PS_ERR_BAD_PARAMETER_VALUE, true,
                "psLineInit failed.  Expected true for valid psLine input.\n");
        return 2;
    }
    if (line->NLINE != 1 || line->Nline != 0) {
        psError(PS_ERR_BAD_PARAMETER_VALUE, true,
                "psLineInit failed to return the correct line parameters.\n");
        return 3;
    }

    psFree(line);

    return 0;
}

psS32 testLineAdd(void)
{
    psLine *line = NULL;
    //Return false for NULL input
    if (psLineAdd(line, "Hello World") ) {
        psError(PS_ERR_BAD_PARAMETER_VALUE, true,
                "psLineAdd failed.  Expected false for NULL psLine input.\n");
        return 1;
    }
    //Allocate and return true for valid input.
    line = psLineAlloc(20);
    if (!psLineAdd(line, "Hello %s", "World") ) {
        psError(PS_ERR_BAD_PARAMETER_VALUE, true,
                "psLineAdd failed.  Expected true for valid psLine input.\n");
        return 2;
    }
    if (line->NLINE != 20 || line->Nline != 11) {
        psError(PS_ERR_BAD_PARAMETER_VALUE, true,
                "psLineAdd failed to return the correct line parameters.\n");
        return 3;
    }
    if (strncmp(line->line, "Hello World", 20)) {
        psError(PS_ERR_BAD_PARAMETER_VALUE, true,
                "psLineAdd failed to store the correct line string.\n");
        printf("\n  %s\n", line->line);
        return 4;
    }

    psFree(line);

    return 0;
}

psS32 testLineChk(void)
{
    psLine *line = NULL;
    //Return false for Null input line
    if (psMemCheckLine(line)) {
        psError(PS_ERR_BAD_PARAMETER_VALUE, true,
                "psMemCheckLine failed to return false for NULL line input.\n");
        return 1;
    }
    line = psLineAlloc(1);
    if (!psMemCheckLine(line)) {
        psError(PS_ERR_BAD_PARAMETER_VALUE, true,
                "psMemCheckLine failed to return true for valid line input.\n");
        return 2;
    }
    psFree(line);

    return 0;
}
