1
0
mirror of https://github.com/pevans/erc-c.git synced 2024-11-23 23:32:45 +00:00

Add tests for apple2.kb.c

This commit is contained in:
Peter Evans 2018-01-17 14:58:42 -06:00
parent 6670df930b
commit 53f40ff960
2 changed files with 61 additions and 0 deletions

23
include/apple2.tests.h Normal file
View File

@ -0,0 +1,23 @@
#ifndef _APPLE2_TESTS_H_
#define _APPLE2_TESTS_H_
#include "apple2.h"
#include "vm_segment.h"
static apple2 *mach = NULL;
static void
setup()
{
mach = apple2_create(100, 100);
vm_segment_set_map_machine(mach);
}
static void
teardown()
{
apple2_free(mach);
vm_segment_set_map_machine(NULL);
}
#endif

View File

@ -0,0 +1,38 @@
#include <criterion/criterion.h>
#include "apple2.kb.h"
#include "apple2.tests.h"
TestSuite(apple2_kb, .init = setup, .fini = teardown);
Test(apple2_kb, map)
{
int i;
vm_segment *segments[2];
segments[0] = mach->main;
segments[1] = mach->aux;
for (i = 0; i < 2; i++) {
cr_assert_eq(segments[i]->read_table[0xC000], apple2_kb_switch_read);
cr_assert_eq(segments[i]->read_table[0xC010], apple2_kb_switch_read);
}
}
Test(apple2_kb, switch_read)
{
// Without strobe
mach->screen->last_key = 'a';
cr_assert_eq(vm_segment_get(mach->main, 0xC000), 'a');
// With strobe
mach->strobe = true;
cr_assert_eq(vm_segment_get(mach->main, 0xC000), 'a' | 0x80);
mach->screen->key_pressed = true;
cr_assert_eq(vm_segment_get(mach->main, 0xC010), 0x80);
cr_assert_eq(mach->strobe, false);
mach->screen->key_pressed = false;
cr_assert_eq(vm_segment_get(mach->main, 0xC010), 0x00);
}