Generic TEST that executes a function
This commit is contained in:
1 parent
d91d550341
commit
509ff4c7e0
3 files changed
+63
-3
No files matched your search
+38
-3
@@ -4,6 +4,7 @@
|
||||
#include "gpu_regs.h"
|
||||
#include "main.h"
|
||||
#include "malloc.h"
|
||||
#include "random.h"
|
||||
#include "test.h"
|
||||
#include "test_runner.h"
|
||||
|
||||
@@ -12,6 +13,7 @@
|
||||
void CB2_TestRunner(void);
|
||||
|
||||
EWRAM_DATA struct TestRunnerState gTestRunnerState;
|
||||
EWRAM_DATA struct FunctionTestRunnerState *gFunctionTestRunnerState;
|
||||
|
||||
void TestRunner_Battle(const struct Test *);
|
||||
|
||||
@@ -230,6 +232,38 @@ void Test_ExpectedResult(enum TestResult result)
|
||||
gTestRunnerState.expectedResult = result;
|
||||
}
|
||||
|
||||
static void FunctionTest_SetUp(void *data)
|
||||
{
|
||||
(void)data;
|
||||
gFunctionTestRunnerState = AllocZeroed(sizeof(*gFunctionTestRunnerState));
|
||||
SeedRng(0);
|
||||
}
|
||||
|
||||
static void FunctionTest_Run(void *data)
|
||||
{
|
||||
void (*function)(void) = data;
|
||||
do
|
||||
{
|
||||
if (gFunctionTestRunnerState->parameters)
|
||||
MgbaPrintf_(":N%s %d/%d", gTestRunnerState.test->name, gFunctionTestRunnerState->runParameter + 1, gFunctionTestRunnerState->parameters);
|
||||
gFunctionTestRunnerState->parameters = 0;
|
||||
function();
|
||||
} while (++gFunctionTestRunnerState->runParameter < gFunctionTestRunnerState->parameters);
|
||||
}
|
||||
|
||||
static void FunctionTest_TearDown(void *data)
|
||||
{
|
||||
(void)data;
|
||||
FREE_AND_SET_NULL(gFunctionTestRunnerState);
|
||||
}
|
||||
|
||||
const struct TestRunner gFunctionTestRunner =
|
||||
{
|
||||
.setUp = FunctionTest_SetUp,
|
||||
.run = FunctionTest_Run,
|
||||
.tearDown = FunctionTest_TearDown,
|
||||
};
|
||||
|
||||
static void Assumptions_Run(void *data)
|
||||
{
|
||||
void (*function)(void) = data;
|
||||
@@ -288,11 +322,12 @@ static void Intr_Timer2(void)
|
||||
|
||||
void Test_ExitWithResult(enum TestResult result, const char *fmt, ...)
|
||||
{
|
||||
bool32 handled = FALSE;
|
||||
gTestRunnerState.result = result;
|
||||
ReinitCallbacks();
|
||||
if (gTestRunnerState.test->runner->handleExitWithResult
|
||||
&& !gTestRunnerState.test->runner->handleExitWithResult(gTestRunnerState.test->data, result)
|
||||
&& gTestRunnerState.result != gTestRunnerState.expectedResult)
|
||||
if (gTestRunnerState.test->runner->handleExitWithResult)
|
||||
handled = gTestRunnerState.test->runner->handleExitWithResult(gTestRunnerState.test->data, result);
|
||||
if (!handled && gTestRunnerState.result != gTestRunnerState.expectedResult)
|
||||
{
|
||||
va_list va;
|
||||
va_start(va, fmt);
|
||||
|
||||
Reference in new issue
Block a user