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

#include "pslib.h"
#include "tap.h"
#include "pstap.h"
#include "string.h"

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


psS32 main( psS32 argc, char* argv[] )
{
    plan_tests(12);

    testLineAlloc();
    testLineInit();
    testLineAdd();
    testLineChk();
}

psS32 testLineAlloc(void)
{
    diag("testLineAlloc");

    psLine *lineline = NULL;
    lineline = psLineAlloc(20);

    ok (lineline->NLINE==20, "psLine set NLINE parameter during Allocation");
    skip_start (lineline->NLINE != 20,
                2, "psLine set NLINE parameter during Allocation");

    ok (lineline->Nline == 0,
        "psLine set Nline parameter during Allocation\n");
    skip_start (lineline->Nline == 0,
                1, "psLine set Nline parameter during Allocation\n");

    strncpy(lineline->line, "Hello World", 20);
    ok (!strncmp(lineline->line, "Hello World", 20),
        "psLine was stored a simple string!\n");

    skip_end();
    skip_end();

    psFree(lineline);

    return 0;
}

psS32 testLineInit(void)
{
    diag("testLineInit");

    psLine *line = NULL;
    //Return false for NULL input
    int okay = !psLineInit(line);
    ok (okay, "psLineInit.  Expected false for NULL psLine input.\n");
    skip_start (!okay, 2, "psLineInit.  Expected NULL psLine input.\n");

    //Allocate a line and return true on Init
    line = psLineAlloc(1);
    okay = psLineInit(line);
    ok( okay, "psLineInit.  Expected true for valid psLine input.\n");
    skip_start( !okay, 1, "psLineInit. Expected true for valid psLine input.");

    ok (line->NLINE == 1 && line->Nline == 0,
        "psLineInit returned line parameters.");

    skip_end();
    skip_end();

    psFree(line);

    return 0;
}


psS32 testLineAdd(void)
{
    diag("testLineAdd");

    psLine *line = NULL;
    //Return false for NULL input
    ok (!psLineAdd(line, "Hello World"),
        "psLineAdd.  Expected false for NULL psLine input.");
    skip_start(psLineAdd(line, "Hello World"),
               3, "psLineAdd.  Expected false for NULL psLine input.");

    //Allocate and return true for valid input.
    line = psLineAlloc(20);
    int okay = psLineAdd(line, "Hello %s", "World");
    ok( okay, "psLineAdd.  Expected true for valid psLine input.\n");
    skip_start( !okay, 2, "psLineAdd.Expected true for valid psLine input.\n");

    ok (line->NLINE == 20 && line->Nline == 11,
        "psLineAdd failed to return the correct line parameters.\n");
    skip_start (line->NLINE != 20 || line->Nline != 11,
                1,"psLineAdd failed to return the correct line parameters.\n");

    ok (!strncmp(line->line, "Hello World", 20),
        "psLineAdd failed to store the correct line string.");

    skip_end();
    skip_end();
    skip_end();

    psFree(line);

    return 0;
}

psS32 testLineChk(void)
{
    diag("testLineChk");

    psLine *line = NULL;
    //Return false for Null input line
    ok (!psMemCheckLine(line),
        "psMemCheckLine return false for NULL line input.\n");
    skip_start (psMemCheckLine(line),
                1, "psMemCheckLine return false for NULL line input.\n");

    line = psLineAlloc(1);
    ok (psMemCheckLine(line),
        "psMemCheckLine return true for valid line input.\n");

    psFree(line);

    skip_end();

    return 0;
}
