From 060b7000de2e489bde4bd1ed9a8c4459f4c4ec83 Mon Sep 17 00:00:00 2001 From: Peter Evans Date: Tue, 12 Dec 2017 15:07:26 -0600 Subject: [PATCH] Add tests to prove read/write mappers are used --- tests/vm_segment.c | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/tests/vm_segment.c b/tests/vm_segment.c index 73a4604..1b4af12 100644 --- a/tests/vm_segment.c +++ b/tests/vm_segment.c @@ -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); +}