#pragma once
#include "Common.h"
BEGIN_NAMESPACE


// Runs all the unit tests
void runUnitTests(int a_verbosity);


#if defined(NDEBUG)

#  define UNIT_TEST(TestName, Verbose) \
                      static void UnitTest##TestName()	// Ensures test names are unique, even in release
#  define CHECK(val) \
                      ((val))								// Ensures abusing this macro will have consistent side-effects

#else

#  define UNIT_TEST(TestName, Verbose) \
                      struct UnitTest##TestName : public UnitTestBase \
                      { \
                        UnitTest##TestName() : UnitTestBase(#TestName, Verbose) {} \
                        void runTest(); \
                      } g_run##TestName; \
                      void UnitTest##TestName::runTest()
#  define CHECK(val) \
                      checkHelper((val), #val, __FILE__, __LINE__)

#endif


// Implementation detail, not intended as part of the user accessed API
struct UnitTestBase
{
	UnitTestBase(const char* name, int a_verbosity);
	void checkHelper(bool res, const char* str, const char* file, int line);
	virtual void runTest() = 0;
	const char* testName;
	int passCount, failCount, verbose;
	UnitTestBase* nextTest;
};


END_NAMESPACE

