/** @file  tst_psTime_04.c
 *
 *  @brief Test driver for psTime functions
 *
 *  This test driver contains the following tests for psTime:
 *      Test A - Initialize time
 *      Test B - Attempt to open non-existant time config file
 *      Test C - Attempt to open non-existant time data files
 *      Test D - Attempt to read incorrect number of files
 *      Test E - Attempt to read incorrect number of from values
 *      Test F - Attempt to read data file with typo in number
 *      Test G - Free data
 *
 *  @author  Ross Harman, MHPCC
 *
 *  @version $Revision: 1.11 $  $Name: not supported by cvs2svn $
 *  @date  $Date: 2005-04-07 20:27:41 $
 *
 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
 *
 */
#include "config.h"

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


int main(int argc, char* argv[])
{
    // Test A - Initialize time
    printPositiveTestHeader(stdout, "psTime", "Test A - Initialize time");
    psLibInit(true, "psTime.config");
    psLibFinalize();
    printFooter(stdout, "psTime", "Test A - Initialize time", true);


    // Test B - Attempt to open non-existant time config file
    printNegativeTestHeader(stdout,"psTime", "Test B - Attempt to open non-existant time config file",
                            "Failed to open file 'zzz'.  Check if it exists and it has the proper permissions.", 0);
    psLibInit(true, "zzz");
    printFooter(stdout, "psTime", "Test B - Attempt to open non-existant time config file", true);


    // Test C - Attempt to open non-existant time data files
    printNegativeTestHeader(stdout,"psTime", "Test C - Attempt to open non-existant time data files",
                            "Failed to open file 'zzz'.  Check if it exists and it has the proper permissions.", 0);
    psLibInit(true, "test.psTime.config1");
    psLibFinalize();
    printFooter(stdout, "psTime", "Test C - Attempt to open non-existant time data files", true);


    // Test D - Attempt to read incorrect number of files
    printNegativeTestHeader(stdout,"psTime", "Test D - Attempt to read incorrect number of files",
                            "Incorrect number of table files entered. Found: 3. Expected: 4.", 0);
    psLibInit(true, "test.psTime.config2");
    psLibFinalize();
    printFooter(stdout, "psTime", "Test D - Attempt to read incorrect number of files", true);


    // Test E - Attempt to read incorrect number of from values
    printNegativeTestHeader(stdout,"psTime", "Test E - Attempt to read incorrect number of from values",
                            "Incorrect vector size. Size: 3, Expected 4.", 0);
    psLibInit(true, "test.psTime.config3");
    psLibFinalize();
    printFooter(stdout, "psTime", "Test E - Attempt to read incorrect number of from values", true);


    // Test F - Attempt to read data file with typo in number
    printNegativeTestHeader(stdout,"psTime", "Test F - Attempt to read data file with typo in number",
                            "Unable to parse string, number on line 16.", 0);
    psLibInit(true, "test.psTime.config4");
    psLibFinalize();
    printFooter(stdout, "psTime", "Test F - Attempt to read data file with typo in number", true);


    // Test G - Free data
    printPositiveTestHeader(stdout, "psTime", "Test G - Free data");
    psLibFinalize();
    if( psMemCheckLeaks(0, NULL, stdout,false) != 0 ) {
        psError(PS_ERR_UNKNOWN,true,"Memory leak detected.");
        return 10;
    }
    psMemCheckCorruption(0);
    int nBad = psMemCheckCorruption(0);
    if(nBad) {
        printf("ERROR: Found %d bad memory blocks\n", nBad);
    }
    printFooter(stdout, "psTime", "Test G - Free data", true);

    return 0;
}

