2019-04-10 13:42:17 -05:00
|
|
|
// 10 april 2019
|
2019-04-19 11:10:45 -05:00
|
|
|
#include <string.h>
|
2019-04-10 13:42:17 -05:00
|
|
|
#include "../ui.h"
|
|
|
|
#include "testing.h"
|
|
|
|
|
2019-04-20 20:38:26 -05:00
|
|
|
// TODO fix up the formatting of testing.c so we can use newlines on the got/want stuff
|
|
|
|
|
|
|
|
#define errInvalidOptions "options parameter to uiInit() must be NULL"
|
|
|
|
#define errAlreadyInitialized "libui already initialized"
|
2019-04-19 11:10:45 -05:00
|
|
|
|
2019-04-10 19:17:40 -05:00
|
|
|
testingTestBefore(Init)
|
2019-04-10 13:42:17 -05:00
|
|
|
{
|
2019-04-20 20:38:26 -05:00
|
|
|
uiInitError err;
|
2019-04-19 11:10:45 -05:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = uiInit(NULL, NULL);
|
|
|
|
if (ret != 0)
|
|
|
|
testingTErrorf(t, "uiInit() with NULL error succeeded with return value %d; expected failure", ret);
|
|
|
|
|
|
|
|
memset(&err, 0, sizeof (uiInitError));
|
|
|
|
|
|
|
|
err.Size = 2;
|
|
|
|
ret = uiInit(NULL, &err);
|
|
|
|
if (ret != 0)
|
|
|
|
testingTErrorf(t, "uiInit() with error with invalid size succeeded with return value %d; expected failure", ret);
|
|
|
|
|
|
|
|
err.Size = sizeof (uiInitError);
|
|
|
|
|
|
|
|
ret = uiInit(&err, &err);
|
|
|
|
if (ret != 0)
|
|
|
|
testingTErrorf(t, "uiInit() with non-NULL options succeeded with return value %d; expected failure", err);
|
2019-04-20 20:38:26 -05:00
|
|
|
if (strcmp(err.Message, errInvalidOptions) != 0)
|
|
|
|
testingTErrorf(t, "uiInit() with non-NULL options returned bad error message: got %s, want %s", err.Message, errInvalidOptions);
|
2019-04-19 11:10:45 -05:00
|
|
|
|
|
|
|
memset(&err, 0, sizeof (uiInitError));
|
|
|
|
err.Size = sizeof (uiInitError);
|
|
|
|
ret = uiInit(NULL, &err);
|
|
|
|
if (ret == 0)
|
|
|
|
testingTErrorf(t, "uiInit() failed: %s", err.Message);
|
|
|
|
|
|
|
|
memset(&err, 0, sizeof (uiInitError));
|
|
|
|
err.Size = sizeof (uiInitError);
|
|
|
|
ret = uiInit(NULL, &err);
|
|
|
|
if (ret != 0)
|
|
|
|
testingTErrorf(t, "uiInit() after a previous successful call succeeded with return value %d; expected failure", ret);
|
2019-04-20 20:38:26 -05:00
|
|
|
if (strcmp(err.Message, errAlreadyInitialized) != 0)
|
|
|
|
testingTErrorf(t, "uiInit() after a previous successful call returned bad error message: got %s, want %s", err.Message, errAlreadyInitialized);
|
2019-04-10 13:42:17 -05:00
|
|
|
}
|
|
|
|
|
2019-04-10 19:17:40 -05:00
|
|
|
testingTestAfter(Uninit)
|
2019-04-10 13:42:17 -05:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static void queued(void *data)
|
|
|
|
{
|
|
|
|
int *flag = (int *) data;
|
|
|
|
|
|
|
|
*flag = 1;
|
|
|
|
}
|
|
|
|
|
2019-04-10 19:11:44 -05:00
|
|
|
static void timer(void *data)
|
2019-04-10 13:42:17 -05:00
|
|
|
{
|
|
|
|
int *n = (int *) data;
|
|
|
|
|
|
|
|
// TODO return stop if n == 5, continue otherwise
|
|
|
|
*n++;
|
|
|
|
}
|
|
|
|
|
2019-04-10 19:11:44 -05:00
|
|
|
testingTest(QueueMain)
|
2019-04-10 13:42:17 -05:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2019-04-10 19:11:44 -05:00
|
|
|
// TODO testingTest(QueueMain_DifferentThread)
|
2019-04-10 13:42:17 -05:00
|
|
|
|
2019-04-10 19:11:44 -05:00
|
|
|
testingTest(Timer)
|
2019-04-10 13:42:17 -05:00
|
|
|
{
|
|
|
|
}
|