/** @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.3 $  $Name: not supported by cvs2svn $
 *  @date  $Date: 2007-05-02 04:20:06 $
 *
 *  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"

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

    // Input pointer same as output pointer
    // XXX: This results in a seg fault.  It's not clear that passing this test is
    // a requirement.  However, we should probably fix the case where the input
    // image equals the output image.
    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");
    }


    // Null input psImage
    // Merge with tap_psMatrix01.c, get rid of this test (redundant)
    {
        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");
    }


    // Incorrect type for input pointer
    // Merge with tap_psMatrix01.c, get rid of this test (redundant)
    {
        psMemId id = psMemGetId();
        psImage *outImage = (psImage*)psImageAlloc(3, 3, PS_TYPE_F64);
        psImage *badImage1 = (psImage*)psImageAlloc(3, 3, PS_TYPE_U8);
        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");
    }


    // 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_U8);
        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");
    }


    // 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");
    }
}
