2017-12-27 07:02:56 +00:00
|
|
|
/*
|
|
|
|
* vm_screen.c
|
|
|
|
*
|
|
|
|
* Generally speaking the tests here are very incomplete; this is partly
|
|
|
|
* because a lot of the code in vm_screen depends on a third-party
|
|
|
|
* graphics library, but I think we can do a better job of decoupling
|
|
|
|
* some concepts (like screen areas) from the graphics library, such
|
|
|
|
* that we can make the code that uses those testable.
|
|
|
|
*/
|
|
|
|
|
2017-12-02 19:05:53 +00:00
|
|
|
#include <criterion/criterion.h>
|
|
|
|
|
|
|
|
#include "vm_screen.h"
|
|
|
|
|
2017-12-27 07:02:56 +00:00
|
|
|
static vm_screen *screen;
|
2017-12-02 19:05:53 +00:00
|
|
|
|
2017-12-27 07:02:56 +00:00
|
|
|
static void
|
|
|
|
setup()
|
|
|
|
{
|
2017-12-24 21:07:24 +00:00
|
|
|
screen = vm_screen_create();
|
2017-12-27 07:02:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
teardown()
|
|
|
|
{
|
|
|
|
vm_screen_free(screen);
|
|
|
|
}
|
|
|
|
|
|
|
|
TestSuite(vm_screen, .init = setup, .fini = teardown);
|
|
|
|
|
2018-01-08 01:42:03 +00:00
|
|
|
/*
|
|
|
|
* We're missing a good way of testing some functions here... I'm going
|
|
|
|
* to list them for now. FIXME
|
|
|
|
*
|
|
|
|
* Test(vm_screen, init)
|
|
|
|
* Test(vm_screen, finish)
|
|
|
|
* Test(vm_screen, set_logical_coords)
|
|
|
|
* Test(vm_screen, add_window)
|
|
|
|
* Test(vm_screen, active)
|
|
|
|
* Test(vm_screen, refresh)
|
|
|
|
* Test(vm_screen, set_color)
|
|
|
|
* Test(vm_screen, draw_rect)
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Test(vm_screen, free) */
|
2017-12-27 07:02:56 +00:00
|
|
|
Test(vm_screen, create) {
|
2017-12-17 22:42:05 +00:00
|
|
|
cr_assert_neq(screen, NULL);
|
2017-12-02 19:05:53 +00:00
|
|
|
|
2017-12-18 20:46:40 +00:00
|
|
|
cr_assert_eq(screen->window, NULL);
|
|
|
|
cr_assert_eq(screen->render, NULL);
|
2017-12-24 21:07:24 +00:00
|
|
|
cr_assert_eq(screen->xcoords, 0);
|
|
|
|
cr_assert_eq(screen->ycoords, 0);
|
2017-12-27 07:02:56 +00:00
|
|
|
}
|
2017-12-02 19:05:53 +00:00
|
|
|
|
2017-12-27 07:02:56 +00:00
|
|
|
Test(vm_screen, xcoords)
|
|
|
|
{
|
|
|
|
screen->xcoords = 123;
|
|
|
|
cr_assert_eq(screen->xcoords, 123);
|
|
|
|
screen->xcoords = 234;
|
|
|
|
cr_assert_eq(screen->xcoords, 234);
|
|
|
|
}
|
|
|
|
|
|
|
|
Test(vm_screen, ycoords)
|
|
|
|
{
|
|
|
|
screen->ycoords = 123;
|
|
|
|
cr_assert_eq(screen->ycoords, 123);
|
|
|
|
screen->ycoords = 234;
|
|
|
|
cr_assert_eq(screen->ycoords, 234);
|
2017-12-02 19:05:53 +00:00
|
|
|
}
|
2017-12-27 23:10:51 +00:00
|
|
|
|
2018-01-17 21:16:12 +00:00
|
|
|
Test(vm_screen, key_pressed)
|
|
|
|
{
|
|
|
|
screen->key_pressed = true;
|
|
|
|
cr_assert_eq(vm_screen_key_pressed(screen), true);
|
|
|
|
screen->key_pressed = false;
|
|
|
|
cr_assert_eq(vm_screen_key_pressed(screen), false);
|
|
|
|
}
|
|
|
|
|
|
|
|
Test(vm_screen, last_key)
|
|
|
|
{
|
|
|
|
screen->last_key = 'e';
|
|
|
|
cr_assert_eq(vm_screen_last_key(screen), 'e');
|
|
|
|
screen->last_key = 'y';
|
|
|
|
cr_assert_eq(vm_screen_last_key(screen), 'y');
|
|
|
|
}
|
2018-02-04 04:01:27 +00:00
|
|
|
|
|
|
|
Test(vm_screen, dirty)
|
|
|
|
{
|
|
|
|
cr_assert_eq(vm_screen_dirty(screen), false);
|
|
|
|
screen->dirty = true;
|
|
|
|
cr_assert_eq(vm_screen_dirty(screen), true);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Not a ton we can do for this function; it's all SDL
|
|
|
|
/* Test(vm_screen, prepare) */
|