#include "unity.h"
#include "unity_fixture.h"
#include "ofc/config.h"
#include "ofc/persist.h"
#include "ofc/env.h"
#include "ofc/app.h"
#include "ofc/sched.h"
#include "ofc/timer.h"
#include "ofc/libc.h"
#include "ofc/event.h"
typedef enum {
TIMER_TEST_STATE_IDLE,
TIMER_TEST_STATE_RUNNING,
} TIMER_TEST_STATE;
#define TIMER_TEST_INTERVAL 1000
#define TIMER_TEST_COUNT 10
typedef struct {
TIMER_TEST_STATE state;
} OFC_TIMER_TEST;
static OFC_APP_TEMPLATE TimerTestAppDef =
{
"Timer Test Application",
&TimerTestPreSelect,
&TimerTestPostSelect,
&TimerTestDestroy,
#if defined(OFC_APP_DEBUG)
#endif
};
OFC_TIMER_TEST *timerTest;
TIMER_TEST_STATE entry_state;
timerTest = ofc_app_get_data(app);
do {
entry_state = timerTest->state;
ofc_sched_clear_wait(timerTest->scheduler, app);
switch (timerTest->state) {
default:
case TIMER_TEST_STATE_IDLE:
timerTest->hTimer = ofc_timer_create("TIMER TEST");
ofc_timer_set(timerTest->hTimer, TIMER_TEST_INTERVAL);
timerTest->state = TIMER_TEST_STATE_RUNNING;
ofc_sched_add_wait(timerTest->scheduler, app,
timerTest->hTimer);
}
break;
case TIMER_TEST_STATE_RUNNING:
ofc_sched_add_wait(timerTest->scheduler, app, timerTest->hTimer);
break;
}
} while (timerTest->state != entry_state);
}
}
OFC_TIMER_TEST *timerTest;
timerTest = ofc_app_get_data(app);
for (progress =
OFC_TRUE; progress && !ofc_app_destroying(app);) {
switch (timerTest->state) {
default:
case TIMER_TEST_STATE_IDLE:
break;
case TIMER_TEST_STATE_RUNNING:
if (hEvent == timerTest->hTimer) {
ofc_printf("Timer Expired %d\n", timerTest->count);
timerTest->count++;
if (timerTest->count >= TIMER_TEST_COUNT) {
ofc_app_kill(app);
} else
ofc_timer_set(timerTest->hTimer, TIMER_TEST_INTERVAL);
}
break;
}
}
}
}
OFC_TIMER_TEST *timerTest;
timerTest = ofc_app_get_data(app);
switch (timerTest->state) {
default:
case TIMER_TEST_STATE_IDLE:
break;
case TIMER_TEST_STATE_RUNNING:
ofc_timer_destroy(timerTest->hTimer);
break;
}
}
}
TEST_GROUP(timer);
TEST_SETUP(timer) {
TEST_ASSERT_FALSE_MESSAGE(test_startup(), "Failed to Startup Framework");
}
TEST_TEAR_DOWN(timer) {
test_shutdown();
}
TEST(timer, test_timer) {
OFC_TIMER_TEST *timerTest;
timerTest->count = 0;
timerTest->state = TIMER_TEST_STATE_IDLE;
timerTest->scheduler = hScheduler;
hApp = ofc_app_create(hScheduler, &TimerTestAppDef, timerTest);
ofc_app_set_wait(hApp, hDone);
ofc_event_wait(hDone);
}
}
TEST_GROUP_RUNNER(timer) {
RUN_TEST_CASE(timer, test_timer);
}
#if !defined(NO_MAIN)
static void runAllTests(void)
{
RUN_TEST_GROUP(timer);
}
int main(int argc, const char *argv[])
{
if (argc >= 2) {
if (ofc_strcmp(argv[1], "--config") == 0) {
}
}
return UnityMain(argc, argv, runAllTests);
}
#endif
#define OFC_MAX_PATH
Definition: file.h:119
#define OFC_HANDLE_NULL
Definition: handle.h:64
OFC_DWORD_PTR OFC_HANDLE
Definition: handle.h:43
OFC_CORE_LIB OFC_VOID ofc_free(OFC_LPVOID mem)
OFC_CORE_LIB OFC_LPVOID ofc_malloc(OFC_SIZET size)
@ OFC_FALSE
Definition: types.h:632
@ OFC_TRUE
Definition: types.h:636
void OFC_VOID
Definition: types.h:159
OFC_UINT8 OFC_BOOL
Definition: types.h:624
#define OFC_NULL
Definition: types.h:656
char OFC_CHAR
Definition: types.h:143
int OFC_INT
Definition: types.h:119