#ifndef VCZH_UNITTEST
#define VCZH_UNITTEST
#include "../String.h"
#include "../Function.h"
#include "../Exception.h"
namespace
{
namespace
{
using
=
void
(*)();
class
{
public
:
() =
delete
;
enum
class
{
,
,
,
,
,
};
static
void
(
const
&
,
);
#ifdef VCZH_MSVC
static
int
(
int
,
wchar_t
*
[]);
#else
static int RunAndDisposeTests(int argc, char* argv[]);
#endif
static
void
(
const
char
*
,
);
static
void
(
const
&
,
bool
,
<
void
()>&&
);
static
void
();
};
class
{
public
:
(
const
char
*
,
)
{
::
(
,
);
}
};
struct
{
const
wchar_t
*
;
(
const
wchar_t
*
) :message(
) {}
};
struct
{
const
wchar_t
*
;
(
const
wchar_t
*
) :message(
) {}
};
#define TEST_FILE\
static void VLPPTEST_TESTFILE();\
static ::vl::unittest::UnitTestFile VLPPTEST_TESTFILE_INSTANCE(__FILE__, &VLPPTEST_TESTFILE);\
static void VLPPTEST_TESTFILE()\
#define TEST_CATEGORY(DESCRIPTION)\
::vl::unittest::UnitTest::RunCategoryOrCase((DESCRIPTION), true, [&]()\
#define TEST_CASE(DESCRIPTION)\
::vl::unittest::UnitTest::RunCategoryOrCase((DESCRIPTION), false, [&]()\
#define TEST_ASSERT(CONDITION)\
do{\
::vl::unittest::UnitTest::EnsureLegalToAssert();\
if(!(CONDITION))throw ::vl::unittest::UnitTestAssertError(L"Assertion failure: " #CONDITION);\
}while(0)\
#define TEST_ERROR(STATEMENT)\
do{\
::vl::unittest::UnitTest::EnsureLegalToAssert();\
try{STATEMENT; throw ::vl::unittest::UnitTestAssertError(L"Expect an error but nothing occurred: " #STATEMENT);}\
catch(const ::vl::Error&){}\
catch(const ::vl::unittest::UnitTestAssertError&) { throw; }\
catch (const ::vl::unittest::UnitTestConfigError&) { throw; }\
}while(0)\
#define TEST_EXCEPTION(STATEMENT,EXCEPTION,ASSERT_FUNCTION)\
do{\
auto __ASSERT_FUNCTION__ = ASSERT_FUNCTION;\
try{STATEMENT; throw ::vl::unittest::UnitTestAssertError(L"Expect [" #EXCEPTION "] but nothing occurred: " #STATEMENT);}\
catch(const EXCEPTION& e){ __ASSERT_FUNCTION__(e); }\
catch(...){ throw ::vl::unittest::UnitTestAssertError(L"Expect [" #EXCEPTION "] but get unexpected exception: " #STATEMENT); }\
}while(0)\
#define TEST_PRINT(MESSAGE)\
::vl::unittest::UnitTest::PrintMessage((MESSAGE), ::vl::unittest::UnitTest::MessageKind::Info)\
#define TEST_CASE_ASSERT(CONDITION)\
TEST_CASE(L ## # CONDITION) { TEST_ASSERT(CONDITION); })\
}
}
#endif