From 350a06890ab529328116911e7954f2cf917d7e99 Mon Sep 17 00:00:00 2001 From: Peter Evans Date: Sat, 10 Feb 2018 18:31:38 -0600 Subject: [PATCH] Split up logic for keyboard test In accordance with the split in logic we had made for the source function --- tests/vm_event.c | 39 +++++++++++++++++++++++++++++---------- 1 file changed, 29 insertions(+), 10 deletions(-) diff --git a/tests/vm_event.c b/tests/vm_event.c index f875f2a..6ef4d81 100644 --- a/tests/vm_event.c +++ b/tests/vm_event.c @@ -2,6 +2,25 @@ #include "vm_event.h" +static vm_event ev; +static vm_screen *scr; + +static void +setup() +{ + scr = vm_screen_create(); + ev.screen = scr; +} + +static void +teardown() +{ + vm_screen_free(scr); + memset(&ev, 0, sizeof(vm_event)); +} + +TestSuite(vm_event, .init = setup, .fini = teardown); + /* * There's not really much we can test here--right now--since almost * everything is driven by the SDL_PollEvent() function. @@ -16,21 +35,19 @@ Test(vm_event, poll) */ Test(vm_event, keyboard) { - vm_event ev; - vm_screen *scr; - - scr = vm_screen_create(); - ev.screen = scr; - ev.event.type = SDL_KEYDOWN; ev.event.key.keysym.sym = 'b'; cr_assert_eq(scr->dirty, false); cr_assert_eq(scr->key_pressed, false); vm_event_keyboard(&ev); +} - cr_assert_eq(scr->dirty, true); - cr_assert_eq(scr->key_pressed, true); +Test(vm_event, keyboard_normal) +{ + ev.event.type = SDL_KEYDOWN; + ev.event.key.keysym.sym = 'b'; + vm_event_keyboard(&ev); cr_assert_eq(scr->last_key, 'b'); ev.event.key.keysym.mod = KMOD_LSHIFT; @@ -45,12 +62,14 @@ Test(vm_event, keyboard) ev.event.type = SDL_KEYUP; vm_event_keyboard(&ev); cr_assert_eq(scr->key_pressed, false); +} +Test(vm_event, keyboard_special) +{ + ev.event.type = SDL_KEYUP; cr_assert_eq(scr->should_exit, false); ev.event.key.keysym.sym = 'q'; ev.event.key.keysym.mod = KMOD_ALT; vm_event_keyboard(&ev); cr_assert_eq(scr->should_exit, true); - - vm_screen_free(scr); }