1
0
mirror of https://github.com/pevans/erc-c.git synced 2024-11-01 04:04:28 +00:00

Tests for bitfont and screen

This commit is contained in:
Peter Evans 2017-12-27 01:02:56 -06:00
parent eeecaf4bdc
commit bcf354989d
2 changed files with 102 additions and 4 deletions

61
tests/vm_bitfont.c Normal file
View File

@ -0,0 +1,61 @@
/*
* vm_bitfont.c
*/
#include <criterion/criterion.h>
#include "vm_bitfont.h"
static vm_bitfont *font;
static void
setup()
{
vm_screen *screen;
screen = vm_screen_create();
font = vm_bitfont_create(screen, "apple2-system", 7, 8, 0x7F);
}
static void
teardown()
{
vm_bitfont_free(font);
}
TestSuite(vm_bitfont, .init = setup, .fini = teardown);
Test(vm_bitfont, create)
{
cr_assert_neq(font, NULL);
cr_assert_eq(font->width, 7);
cr_assert_eq(font->height, 8);
cr_assert_eq(font->cmask, 0x7F);
// This should be NULL because we have no screen
cr_assert_eq(font->texture, NULL);
}
Test(vm_bitfont, offset)
{
char ch = 'p';
int x = 0;
int y = 0;
vm_bitfont_offset(font, ch, &x, &y);
cr_assert_eq(x, (ch & 0x0f) * font->width);
cr_assert_eq(y, (ch >> 4) * font->height);
}
/*
* A note: I omitted a test for vm_bitfont_render(), as this function is
* a) reliant on vm_bitfont_offset for the right glyph to render, and b)
* is otherwise reliant on our graphics library to properly render the
* character. As we run our tests in a headless mode, we are unable to
* automate that specific kind of test.
*/
Test(vm_bitfont, render)
{
}

View File

@ -1,11 +1,34 @@
/*
* 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.
*/
#include <criterion/criterion.h> #include <criterion/criterion.h>
#include "vm_screen.h" #include "vm_screen.h"
Test(vm_screen, create) { static vm_screen *screen;
vm_screen *screen;
static void
setup()
{
screen = vm_screen_create(); screen = vm_screen_create();
}
static void
teardown()
{
vm_screen_free(screen);
}
TestSuite(vm_screen, .init = setup, .fini = teardown);
Test(vm_screen, create) {
cr_assert_neq(screen, NULL); cr_assert_neq(screen, NULL);
cr_assert_eq(screen->window, NULL); cr_assert_eq(screen->window, NULL);
@ -16,6 +39,20 @@ Test(vm_screen, create) {
cr_assert_eq(screen->rect.h, 0); cr_assert_eq(screen->rect.h, 0);
cr_assert_eq(screen->xcoords, 0); cr_assert_eq(screen->xcoords, 0);
cr_assert_eq(screen->ycoords, 0); cr_assert_eq(screen->ycoords, 0);
}
vm_screen_free(screen);
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);
} }