/** @file  tst_psMatrix_01.c
*
*  @brief Test driver for psMatrix transpose function
*
*  This test driver contains the following tests for psMatrix test point 1:
*     A)  Create input and output images
*     B)  Transpose input image into output image
*     C)  Transpose input image into auto allocated NULL output image 
*     D)  Free images and check for leaks
*
*  @author  Ross Harman, MHPCC
*
*  @version $Revision: 1.6 $  $Name: not supported by cvs2svn $
*  @date  $Date: 2004-08-06 22:34:06 $
*
*  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
*
*/

#include "pslib.h"
#include "psTest.h"

#define PRINT_MATRIX(IMAGE)                         \
for(int i=IMAGE->numRows-1; i>-1; i--) {        \
    for(int j=0; j<IMAGE->numCols; j++) {       \
        printf("%f ", IMAGE->data.F64[i][j]);   \
    }                                          \
    printf("\n");                              \
}

int main( int argc,
          char* argv[] )
{
    psImage * tempImage = NULL;


    // Test A - Create input and output images
    printPositiveTestHeader( stdout, "psMatrix", "Create input and output images" );
    psImage *inImage = ( psImage* ) psImageAlloc( 3, 3, PS_TYPE_F64 );
    psImage *outImage = ( psImage* ) psImageAlloc( 3, 3, PS_TYPE_F64 );
    inImage->data.F64[ 0 ][ 0 ] = 1;
    inImage->data.F64[ 0 ][ 1 ] = 2;
    inImage->data.F64[ 0 ][ 2 ] = 3;
    inImage->data.F64[ 1 ][ 0 ] = 4;
    inImage->data.F64[ 1 ][ 1 ] = 5;
    inImage->data.F64[ 1 ][ 2 ] = 6;
    inImage->data.F64[ 2 ][ 0 ] = 7;
    inImage->data.F64[ 2 ][ 1 ] = 8;
    inImage->data.F64[ 2 ][ 2 ] = 9;
    PRINT_MATRIX( inImage );
    printFooter( stdout, "psMatrix", "Create input and output images", true );


    // Test B - Transpose input image into output image
    printPositiveTestHeader( stdout, "psMatrix", "Transpose input image into output image" );
    tempImage = outImage;
    outImage = psMatrixTranspose( outImage, inImage );
    PRINT_MATRIX( outImage );
    if ( outImage->type.dimen != PS_DIMEN_IMAGE ) {
        printf( "Error: Resulting image is not PS_DIMEN_IMAGE\n" );
    } else
        if ( outImage != tempImage ) {
            printf( "Error: Return pointer not equal to output argument pointer\n" );
        }
    printFooter( stdout, "psMatrix", "Transpose input image into output image", true );


    // Test C -  Transpose input image into auto allocated NULL output image
    printPositiveTestHeader( stdout, "psMatrix", "ranspose input image into auto allocated NULL output image" );
    psImage *outImageNull = NULL;
    outImageNull = psMatrixTranspose( outImageNull, inImage );
    PRINT_MATRIX( outImageNull );
    printFooter( stdout, "psMatrix", "ranspose input image into auto allocated NULL output image", true );


    // Test D - Free images and check for leaks
    printPositiveTestHeader( stdout, "psMatrix", "Free images and check for leaks" );
    psFree( inImage );
    psFree( outImage );
    psFree( outImageNull );
    int nLeaks = psMemCheckLeaks( 0, NULL, stdout );
    if ( nLeaks != 0 ) {
        printf( "ERROR: Found %d memory leaks\n", nLeaks );
    }
    int nBad = psMemCheckCorruption( 0 );
    if ( nBad ) {
        printf( "ERROR: Found %d bad memory blocks\n", nBad );
    }
    printFooter( stdout, "psMatrix" , "Free images and check for leaks", true );

    return 0;
}
