/*
   Test-ZTransform.cpp
Author: Charles Lena <cmlena@762studios.com>
Created: 3/29/2012

Purpose: 

Tests to ensure that the math transform routines function accurately.
*/

#include "ZUnitTest.hpp"
#include <stdio.h>
#include <stdlib.h>
#include <climits>
#include <cfloat>
#include <math.h>
#include <SST/SST_File.h>
#include <ZUtil/ZBinaryDataWriter.hpp>

inline bool fpcomp(float typed_1, float typed_2, float tol = FLT_EPSILON) {
		return (abs(typed_1 - typed_2) <= tol);
}
inline bool dpcomp(double typed_1, double typed_2, double tol = DBL_EPSILON) {
	return (abs(typed_1 - typed_2) <= tol);
}
/* class ZBinaryDataWriter
{
protected:
 SST_File file;
 bool swapEndian;

public:
 ZBinaryDataWriter( SST_File _file, bool _swapEndian = false)
  : file(_file), swapEndian(_swapEndian)
 {
 }

 ~ZBinaryDataWriter() {}

 bool GetWillSwap();
 void SetWillSwap( bool _swap );

 void WriteChar(   const char _out);
 inline void WriteInt8(  const int8_t _out) { WriteChar( _out); }
 void WriteInt16(   const int16_t _out);
 void WriteInt32(   const int32_t _out);
 void WriteInt64(   const int64_t _out);
 void WriteUInt16(  const uint16_t _out);
 void WriteUInt32(  const uint32_t _out);
 void WriteUInt64(  const uint64_t _out);
 void WriteFloat(   const float _out);
 void WriteDouble(  const double _out);

 void WriteCharArray(  const char* _out,  size_t _count);
 void WriteInt16Array( const int16_t* _out, size_t _count);
 void WriteInt32Array( const int32_t* _out, size_t _count);
 void WriteInt64Array( const int64_t* _out, size_t _count);
 void WriteUInt16Array( const uint16_t* _out, size_t _count);
 void WriteUInt32Array( const uint32_t* _out, size_t _count);
 void WriteUInt64Array( const uint64_t* _out, size_t _count);
 void WriteFloatArray( const float* _out,  size_t _count);
 void WriteDoubleArray( const double* _out,  size_t _count);
}; */
static const char* testGetWillSwap();
static const char* testSetWillSwap();
static const char* testWriteChar();
static const char* testWriteChar(); 
static const char* testWriteInt16();
static const char* testWriteInt32();
static const char* testWriteInt64();
static const char* testWriteUInt16();
static const char* testWriteUInt32();
static const char* testWriteUInt64();
static const char* testWriteFloat();
static const char* testWriteDouble();
static const char* testWriteCharArray();
static const char* testWriteInt16Array();
static const char* testWriteInt32Array();
static const char* testWriteInt64Array();
static const char* testWriteUInt16Array();
static const char* testWriteUInt32Array();
static const char* testWriteUInt64Array();
static const char* testWriteFloatArray();
static const char* testWriteDoubleArray();

//List of unit tests
ZUnitTest ZBinaryDataWriterUnitTests[] =
{
{"testGetWillSwap",testGetWillSwap},
{"testSetWillSwap",testSetWillSwap},
{"testWriteChar",testWriteChar},
{"testWriteChar",testWriteChar}, 
{"testWriteInt16",testWriteInt16},
{"testWriteInt32",testWriteInt32},
{"testWriteInt64",testWriteInt64},
{"testWriteUInt16",testWriteUInt16},
{"testWriteUInt32",testWriteUInt32},
{"testWriteUInt64",testWriteUInt64},
{"testWriteFloat",testWriteFloat},
{"testWriteDouble",testWriteDouble},
{"testWriteCharArray",testWriteCharArray},
{"testWriteInt16Array",testWriteInt16Array},
{"testWriteInt32Array",testWriteInt32Array},
{"testWriteInt64Array",testWriteInt64Array},
{"testWriteUInt16Array",testWriteUInt16Array},
{"testWriteUInt32Array",testWriteUInt32Array},
{"testWriteUInt64Array",testWriteUInt64Array},
{"testWriteFloatArray",testWriteFloatArray},
{"testWriteDoubleArray",testWriteDoubleArray},
};

DECLARE_ZTESTBLOCK(ZBinaryDataWriter);

// =======================================
#include <stdio.h>
#if SST_COMPILER == SST_COMPILER_MSVC
#pragma warning(push)
#pragma warning(disable:4127)
#endif
static const char* testGetWillSwap(){
	SST_File File;
	bool result;
	File = SST_OS_OpenFile("test.dat",SST_OPEN_WRITE);
	ZBinaryDataWriter Z( File , false);
	result = Z.GetWillSwap();
	SST_OS_CloseFile(File);


	TASSERT(result == false,"GetWillSwap() failed to detect false!");
	return ZTEST_SUCCESS;
}
static const char* testSetWillSwap(){
	SST_File File;
	bool result;
	File = SST_OS_OpenFile("test.dat",SST_OPEN_WRITE);
	ZBinaryDataWriter Z( File , false);
	Z.SetWillSwap(true);
	result = Z.GetWillSwap();
	SST_OS_CloseFile(File);


	TASSERT(result == true,"SetWillSwap() failed to detect true!");
	return ZTEST_SUCCESS;
}
static const char* testWriteChar(){
	SST_File File;
	bool result;
	File = SST_OS_OpenFile("char.dat",SST_OPEN_WRITE);
	ZBinaryDataWriter Z( File , false);
	Z.WriteChar('C');
	SST_OS_CloseFile(File);


	TASSERT(result == false,"WriteChar() failed to detect false!");
	return ZTEST_SUCCESS;
}
static const char* testWriteInt16(){
	bool result;

	TASSERT(result == false,"WriteInt16() failed to produce desired results!");
	return ZTEST_SUCCESS;
}
static const char* testWriteInt32(){
	TASSERT(false,"WriteInt32() failed to produce the desired results!");
	return ZTEST_SUCCESS;
}
static const char* testWriteInt64(){

	TASSERT(false,"Test Not Implemented Yet!");
	return ZTEST_SUCCESS;
}
static const char* testWriteUInt16(){

	TASSERT(false,"Test Not Implemented Yet!");
	return ZTEST_SUCCESS;
}
static const char* testWriteUInt32(){

	TASSERT(false,"Test Not Implemented Yet!");
	return ZTEST_SUCCESS;
}
static const char* testWriteUInt64(){

	TASSERT(false,"Test Not Implemented Yet!");
	return ZTEST_SUCCESS;
}
static const char* testWriteFloat(){

	TASSERT(false,"Test Not Implemented Yet!");
	return ZTEST_SUCCESS;
}
static const char* testWriteDouble(){

	TASSERT(false,"Test Not Implemented Yet!");
	return ZTEST_SUCCESS;
}
static const char* testWriteCharArray(){

	TASSERT(false,"Test Not Implemented Yet!");
	return ZTEST_SUCCESS;
}
static const char* testWriteInt16Array(){

	TASSERT(false,"Test Not Implemented Yet!");
	return ZTEST_SUCCESS;
}
static const char* testWriteInt32Array(){

	TASSERT(false,"Test Not Implemented Yet!");
	return ZTEST_SUCCESS;
}
static const char* testWriteInt64Array(){

	TASSERT(false,"Test Not Implemented Yet!");
	return ZTEST_SUCCESS;
}
static const char* testWriteUInt16Array(){

	TASSERT(false,"Test Not Implemented Yet!");
	return ZTEST_SUCCESS;
}
static const char* testWriteUInt32Array(){

	TASSERT(false,"Test Not Implemented Yet!");
	return ZTEST_SUCCESS;
}
static const char* testWriteUInt64Array(){

	TASSERT(false,"Test Not Implemented Yet!");
	return ZTEST_SUCCESS;
}
static const char* testWriteFloatArray(){

	TASSERT(false,"Test Not Implemented Yet!");
	return ZTEST_SUCCESS;
}
static const char* testWriteDoubleArray(){

	TASSERT(false,"Test Not Implemented Yet!");
	return ZTEST_SUCCESS;
}
#if SST_COMPILER == SST_COMPILER_MSVC
#pragma warning(pop)
#endif
