/*
	Test-ZArray.cpp
	Author: Chris Ertel (crertel@762studios.com)

	Purpose :	Unit tests for ZAssert.

	Changelog :
	1/8/2012 - Created (crertel)
*/

#include "ZUnitTest.hpp"

#include <ZUtil/ZAssert.hpp>

static const char* testRuntimeAssert();

//List of unit tests
ZUnitTest ZAssertUnitTests[] =
{
	{
		"Runtime assert",
		testRuntimeAssert
	}
};

DECLARE_ZTESTBLOCK(ZAssert);

/*************************************************************************/

static int handleAssert(const char* _msg, void* _arg)
{
	*((int*)_arg) = 1337;
	printf("Assert thrown: %s\n", _msg);
	return 1;
}

static int manhandleAssert(const char* _msg, void* _arg)
{
	*((int*)_arg) = 357;
	printf("Assert failed: %s\n",_msg);
	return 1;
}

/*************************************************************************/

static const char* testRuntimeAssert()
{
	int var = 762;
	SST_OS_SetRuntimeAssertHandler(handleAssert, &var);

	ZASSERT_RUNTIME(false,"Assert test.\n");
	TASSERT(var == 1337, "var was not reset by assertion handler\n");
	SST_OS_SetRuntimeAssertHandler(manhandleAssert, &var);
	ZASSERT_RUNTIME_FAIL("Assert fail test.\n");
	TASSERT(var == 357, "var was not reset by assertion failure\n");

	SST_OS_SetRuntimeAssertHandler(NULL,NULL);

	return ZTEST_SUCCESS;
}
