mirror of
https://github.com/pevans/erc-c.git
synced 2024-12-30 06:29:48 +00:00
Split up logic for keyboard test
In accordance with the split in logic we had made for the source function
This commit is contained in:
parent
69d425db2d
commit
350a06890a
@ -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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user