1
0
mirror of https://github.com/pevans/erc-c.git synced 2024-10-05 04:56:46 +00:00

Add tests to prove read/write mappers are used

This commit is contained in:
Peter Evans 2017-12-12 15:07:26 -06:00
parent 7da3c2ec20
commit 060b7000de

View File

@ -93,3 +93,40 @@ Test(vm_segment, write_map)
cr_assert_eq(segment->write_table[123], (vm_segment_write_fn)456);
}
static vm_8bit
read_fn(vm_segment *segment, size_t addr)
{
return 222;
}
Test(vm_segment, use_read_map)
{
size_t addr = 123;
vm_segment_set(segment, addr, 111);
cr_assert_eq(vm_segment_get(segment, addr), 111);
vm_segment_read_map(segment, addr, read_fn);
cr_assert_eq(vm_segment_get(segment, addr), 222);
vm_segment_read_map(segment, addr, NULL);
cr_assert_eq(vm_segment_get(segment, addr), 111);
}
void
write_fn(vm_segment *segment, size_t addr, vm_8bit value)
{
segment->memory[addr+1] = value;
}
Test(vm_segment, use_write_map)
{
size_t addr = 123;
vm_segment_set(segment, addr, 111);
cr_assert_eq(vm_segment_get(segment, addr), 111);
cr_assert_neq(vm_segment_get(segment, addr + 1), 111);
vm_segment_write_map(segment, addr, write_fn);
vm_segment_set(segment, addr, 111);
cr_assert_eq(vm_segment_get(segment, addr), 111);
cr_assert_eq(vm_segment_get(segment, addr + 1), 111);
}