tests - Sort tests into subdirectories

This commit is contained in:
madmaurice 2023-09-09 14:45:47 +02:00
commit 15c4811804
9 changed files with 5 additions and 1 deletions

16
tests/memory/test_bus.cpp Normal file
View file

@ -0,0 +1,16 @@
#include "doctest.h"
#include <memory/bus.h>
#include <memory/ram.h>
TEST_CASE("Bus can map same device twice")
{
RAM r(0x1000);
Bus b;
b.map_device(0x0000, 0x0FFF, &r);
b.map_device(0x2000, 0x2FFF, &r);
b.write8(0x60, 42);
CHECK(b.read8(0x2060) == 42);
}

View file

@ -0,0 +1,25 @@
#include "doctest.h"
#include <cpu/cpu.h>
#include <memory/bus.h>
#include <memory/ram.h>
#include <memory/register.h>
TEST_CASE("IE controllable via bus")
{
u8 test_ram[] = {
0x3E, 0xA5, // LD A, $0xA5
0xE0, 0xFF, // LDH [FF:FF], A
};
Bus b;
Cpu cpu(&b);
b.map_device(0x0000, 0x0004, new RAM(test_ram, 0x4, true));
b.map_device(0xFFFF, 0xFFFF, new BoundRegister(cpu.state.IE));
cpu.step();
cpu.step();
CHECK(cpu.state.IE == 0xA5);
}

33
tests/memory/test_ram.cpp Normal file
View file

@ -0,0 +1,33 @@
#include "doctest.h"
#include <memory/ram.h>
TEST_SUITE_BEGIN("memory/ram");
TEST_CASE("byte order for 16-byte write is correct")
{
RAM r(0x10);
r.write16(0x0,0xAA55);
CHECK(r.read8(0x0) == 0x55);
CHECK(r.read8(0x1) == 0xAA);
}
TEST_CASE("byte order for 16-byte write is correct")
{
RAM r(0x10);
r.write8(0x0, 0x55);
r.write8(0x1, 0xAA);
CHECK(r.read16(0x0) == 0xAA55);
}
TEST_CASE("can be read only")
{
u8 data[1] = { 0x00 };
RAM r(data, 1, true);
r.write8(0,0x10);
CHECK(r.read8(0) == 0x00);
}
TEST_SUITE_END();