mirror of https://github.com/mgba-emu/mgba.git
GB Test: Some basic memory patching tests
This commit is contained in:
parent
4573c22fa8
commit
c1c27b46fe
|
@ -7,12 +7,14 @@
|
||||||
|
|
||||||
M_TEST_SUITE_DECLARE(GBCore);
|
M_TEST_SUITE_DECLARE(GBCore);
|
||||||
M_TEST_SUITE_DECLARE(GBMBC);
|
M_TEST_SUITE_DECLARE(GBMBC);
|
||||||
|
M_TEST_SUITE_DECLARE(GBMemory);
|
||||||
M_TEST_SUITE_DECLARE(GBRTC);
|
M_TEST_SUITE_DECLARE(GBRTC);
|
||||||
|
|
||||||
int TestRunGB(void) {
|
int TestRunGB(void) {
|
||||||
int failures = 0;
|
int failures = 0;
|
||||||
failures += M_TEST_SUITE_RUN(GBCore);
|
failures += M_TEST_SUITE_RUN(GBCore);
|
||||||
failures += M_TEST_SUITE_RUN(GBMBC);
|
failures += M_TEST_SUITE_RUN(GBMBC);
|
||||||
|
failures += M_TEST_SUITE_RUN(GBMemory);
|
||||||
failures += M_TEST_SUITE_RUN(GBRTC);
|
failures += M_TEST_SUITE_RUN(GBRTC);
|
||||||
return failures;
|
return failures;
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,78 @@
|
||||||
|
/* Copyright (c) 2013-2016 Jeffrey Pfau
|
||||||
|
*
|
||||||
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
#include "util/test/suite.h"
|
||||||
|
|
||||||
|
#include "core/core.h"
|
||||||
|
#include "gb/core.h"
|
||||||
|
#include "gb/gb.h"
|
||||||
|
#include "gb/mbc.h"
|
||||||
|
#include "util/vfs.h"
|
||||||
|
|
||||||
|
M_TEST_SUITE_SETUP(GBMemory) {
|
||||||
|
struct VFile* vf = VFileMemChunk(NULL, GB_SIZE_CART_BANK0 * 4);
|
||||||
|
GBSynthesizeROM(vf);
|
||||||
|
struct mCore* core = GBCoreCreate();
|
||||||
|
core->init(core);
|
||||||
|
core->loadROM(core, vf);
|
||||||
|
*state = core;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
M_TEST_SUITE_TEARDOWN(GBMemory) {
|
||||||
|
if (!*state) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
struct mCore* core = *state;
|
||||||
|
core->deinit(core);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
M_TEST_DEFINE(patchROMBank0) {
|
||||||
|
struct mCore* core = *state;
|
||||||
|
struct GB* gb = core->board;
|
||||||
|
int8_t oldExpected = gb->memory.rom[0];
|
||||||
|
int8_t old;
|
||||||
|
int8_t newExpected = 0x40;
|
||||||
|
|
||||||
|
core->reset(core);
|
||||||
|
GBPatch8(gb->cpu, 0, newExpected, &old, 0);
|
||||||
|
assert_int_equal(old, oldExpected);
|
||||||
|
assert_int_equal(gb->memory.rom[0], newExpected);
|
||||||
|
assert_int_equal(GBView8(gb->cpu, 0, 0), newExpected);
|
||||||
|
}
|
||||||
|
|
||||||
|
M_TEST_DEFINE(patchROMBank1) {
|
||||||
|
struct mCore* core = *state;
|
||||||
|
struct GB* gb = core->board;
|
||||||
|
int8_t oldExpected = gb->memory.rom[GB_SIZE_CART_BANK0];
|
||||||
|
int8_t old;
|
||||||
|
int8_t newExpected = 0x41;
|
||||||
|
|
||||||
|
core->reset(core);
|
||||||
|
GBPatch8(gb->cpu, GB_SIZE_CART_BANK0, newExpected, &old, 1);
|
||||||
|
assert_int_equal(old, oldExpected);
|
||||||
|
assert_int_equal(gb->memory.rom[GB_SIZE_CART_BANK0], newExpected);
|
||||||
|
assert_int_equal(GBView8(gb->cpu, GB_SIZE_CART_BANK0, 1), newExpected);
|
||||||
|
}
|
||||||
|
|
||||||
|
M_TEST_DEFINE(patchROMBank2) {
|
||||||
|
struct mCore* core = *state;
|
||||||
|
struct GB* gb = core->board;
|
||||||
|
int8_t oldExpected = gb->memory.rom[GB_SIZE_CART_BANK0 * 2];
|
||||||
|
int8_t old;
|
||||||
|
int8_t newExpected = 0x42;
|
||||||
|
|
||||||
|
core->reset(core);
|
||||||
|
GBPatch8(gb->cpu, GB_SIZE_CART_BANK0, newExpected, &old, 2);
|
||||||
|
assert_int_equal(old, oldExpected);
|
||||||
|
assert_int_equal(gb->memory.rom[GB_SIZE_CART_BANK0 * 2], newExpected);
|
||||||
|
assert_int_equal(GBView8(gb->cpu, GB_SIZE_CART_BANK0, 2), newExpected);
|
||||||
|
}
|
||||||
|
|
||||||
|
M_TEST_SUITE_DEFINE_SETUP_TEARDOWN(GBMemory,
|
||||||
|
cmocka_unit_test(patchROMBank0),
|
||||||
|
cmocka_unit_test(patchROMBank1),
|
||||||
|
cmocka_unit_test(patchROMBank2))
|
Loading…
Reference in New Issue