From 87e042a309f5433da256028f2932bc4f8fe239f3 Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Sat, 9 May 2020 22:34:42 -0400 Subject: [PATCH] Wrote in the remaining programmer error tests in test/initmain.c. --- test/initmain.c | 90 ++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 85 insertions(+), 5 deletions(-) diff --git a/test/initmain.c b/test/initmain.c index 030165b0..34d0a805 100644 --- a/test/initmain.c +++ b/test/initmain.c @@ -140,6 +140,91 @@ TestNoInit(InitIncorrectlyAfterIncorrectInitialization) endCheckProgrammerError(ctx); } +static void done(void *data) +{ + uiQuit(); +} + +Test(MainCalledTwiceIsProgrammerError) +{ + void *ctx; + + ctx = beginCheckProgrammerError("uiMain(): attempt to call more than once"); + uiQueueMain(done, NULL); + uiMain(); + uiMain(); + endCheckProgrammerError(ctx); +} + +static void mainAndQuit(void *data) +{ + uiMain(); + uiQuit(); +} + +Test(MainCalledRecursivelyIsProgrammerError) +{ + void *ctx; + + ctx = beginCheckProgrammerError("uiMain(): attempt to call more than once"); + uiQueueMain(mainAndQuit, NULL); + uiMain(); + uiMain(); + endCheckProgrammerError(ctx); +} + +// largely redundant due to InitCorrectlyAfterInitializedSuccessfully, but include it anyway just to be safe +Test(InitAfterMainIsProgrammerError) +{ + uiInitError err; + void *ctx; + + ctx = beginCheckProgrammerError("uiInit(): attempt to call more than once"); + uiQueueMain(done, NULL); + uiMain(); + memset(&err, 0, sizeof (uiInitError)); + err.Size = sizeof (uiInitError); + if (uiInit(NULL, &err)) + TestFatalf("uiInit() after a previous successful call succeeded; expected failure"); + endCheckProgrammerError(ctx); +} + +Test(QuitBeforeMainIsProgrammerError) +{ + void *ctx; + + ctx = beginCheckProgrammerError("uiQuit(): attempt to call before uiMain()"); + uiQuit(); + endCheckProgrammerError(ctx); +} + +static void quitTwice(void *data) +{ + uiQuit(); + uiQuit(); +} + +Test(QuitCalledTwiceIsProgrammerError) +{ + void *ctx; + + ctx = beginCheckProgrammerError("uiQuit(): attempt to call more than once"); + uiQueueMain(quitTwice, NULL); + uiMain(); + endCheckProgrammerError(ctx); +} + +Test(QuitAfterMainIsProgrammerError) +{ + void *ctx; + + ctx = beginCheckProgrammerError("uiQuit(): attempt to call more than once"); + uiQueueMain(done, NULL); + uiMain(); + uiQuit(); + endCheckProgrammerError(ctx); +} + struct simpleTestParams { unsigned int n; threadSysError err; @@ -241,11 +326,6 @@ queueStep(step22, struct queueTestParams, order2, 2) queueStep(step23, struct queueTestParams, order2, 3) queueStep(step24, struct queueTestParams, order2, 4) -static void done(void *data) -{ - uiQuit(); -} - static void queueOrder1(struct queueTestParams *p) { uiQueueMain(step11, p);