/** @file  tst_psMatrix_02.c
 *
 *  @brief Test driver for negative tests for psMatrix transpose function
 *
 *  This test driver contains the following tests for psMatrix test point 2:
 *     A)  Input pointer same as output pointer
 *     B)  Null input psImage
 *     C)  Incorrect type for input pointer
 *     D)  Incorrect type for output pointer
 *     E)  Matrix not square for output pointer
 *
 *  @author  Ross Harman, MHPCC
 *
 *  @version $Revision: 1.1 $  $Name: not supported by cvs2svn $
 *  @date  $Date: 2006-12-20 20:02:29 $
 *
 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
 *
 */
#include <stdio.h>
#include <string.h>
#include <pslib.h>
#include "tap.h"
#include "pstap.h"

psS32 main(psS32 argc,
           char* argv[])
{
    psLogSetFormat("HLNM");
    plan_tests(11);

    // Test A - Input pointer same as output pointer
    if (0) {
        psMemId id = psMemGetId();
        psImage *inImage = (psImage*)psImageAlloc(3, 3, PS_TYPE_F64);
        ok(psMatrixTranspose(inImage, inImage) == NULL, "psMatrixTranspose(): inImage = outImage results in NULL");
        ok(psMemGetRefCounter(inImage) == 1, "psMatrixTranspose(): the output image was freed on an error.");
        psFree(inImage);
        ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
    }

    // Test B - Null input psImage
    {
        psMemId id = psMemGetId();
        psImage *nullImage = NULL;
        psImage *outImage = (psImage*)psImageAlloc(3, 3, PS_TYPE_F64);
        psMemIncrRefCounter(outImage);
        ok(psMatrixTranspose(outImage, nullImage) == NULL, "psMatrixTranspose(): inImage = NULL results in NULL return");
        ok(psMemGetRefCounter(outImage) == 1, "psMatrixTranspose(): the output image was freed on an error.");
        psFree(outImage);
        ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
    }

    // Test C - Incorrect type for input pointer
    {
        psMemId id = psMemGetId();
        psImage *outImage = (psImage*)psImageAlloc(3, 3, PS_TYPE_F64);
        psImage *badImage1 = (psImage*)psImageAlloc(3, 3, PS_TYPE_C32);
        psMemIncrRefCounter(outImage);
        ok(psMatrixTranspose(outImage, badImage1) == NULL, "psMatrixTranspose(): inImage = outImage results in NULL return");
        ok(psMemGetRefCounter(outImage) == 1, "the output image was freed on the error.");
        psFree(outImage);
        psFree(badImage1);
        ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
    }

    // Test D - Incorrect type for output pointer
    {
        psMemId id = psMemGetId();
        psImage *inImage = (psImage*)psImageAlloc(3, 3, PS_TYPE_F64);
        psImage *badImage1 = (psImage*)psImageAlloc(3, 3, PS_TYPE_C32);
        badImage1 = psMatrixTranspose(badImage1, inImage);
        ok(badImage1 != NULL, "psMatrixTranspose() results in non-NULL return");
        // check that the type was changed.
        ok(badImage1->type.type == PS_TYPE_F64, "the output type was changed to F64");
        psFree(inImage);
        psFree(badImage1);
        ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
    }

    // Test E - Matrix not square for output pointer
    // XXX: We should probably do more here.
    {
        psMemId id = psMemGetId();
        psImage *inImage = (psImage*)psImageAlloc(3, 3, PS_TYPE_F64);
        psImage *badImage2 = (psImage*)psImageAlloc(3, 2, PS_TYPE_F64);
        ok(psMatrixTranspose(badImage2, inImage) != NULL, "psMatrixTranspose(): non-square matrix results in non-NULL");
        psFree(inImage);
        psFree(badImage2);
        ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
    }
    return 0;
}
