/**
 *  C Implementation: tap_psMetadataConfigWrite
 *
 * Description:  Tests for psMetadataConfigWrite
 *
 * Author: dRob <David.Robbins@mhpcc.hpc.mil>, (C) 2006
 *
 * Copyright: See COPYING file that comes with this distribution
 *
 */

#include <pslib.h>
#include <string.h>

#include "tap.h"
#include "pstap.h"

int main(void)
{
    plan_tests(7);

    //Return false for NULL metadata input
    {
        ok( !psMetadataConfigWrite(NULL, "mdcfg.wrt"),
            "return false for NULL metadata input.");
    }

    //Return false for NULL filename input
    {
        psMetadata *md = psMetadataAlloc();
        ok( !psMetadataConfigWrite(md, NULL),
            "return false for NULL filename input.");
        psFree(md);
    }

    //Return false for invalid filename input
    {
        psMetadata *md = psMetadataAlloc();
        ok( !psMetadataConfigWrite(md, "."),
            "return false for invalid filename input.");
        psFree(md);
    }

    //Return false for empty metadata input
    {
        psMetadata *md = psMetadataAlloc();
        ok( !psMetadataConfigWrite(md, "mdcfg.wrt"),
            "return false for empty metadata input.");
        psFree(md);
    }

    //Return true for valid inputs
    {
        psMetadata *md = psMetadataAlloc();
        psMetadataAddBool(md, PS_LIST_TAIL, "item1-1", 0, "I am a boolean", true);
        ok( psMetadataConfigWrite(md, "mdcfg.wrt"),
            "return true for valid inputs.");
        char configTest[61];
        char fileStr[62];
        FILE *mdcfg = fopen("mdcfg.wrt", "r");
        fgets(fileStr, 61, mdcfg);
        strncpy(configTest,
                "item1-1          BOOL      T                # I am a boolean", 60);
        ok_strn(configTest, fileStr, 60,
                "return correct output.");
        fclose(mdcfg);
        remove
            ("mdcfg.wrt");
        psFree(md);
    }

    done();
}
