all repos — mgba @ a760c7bb4a85c8abea17ff9db466e96ebe20a8de

mGBA Game Boy Advance Emulator

src/gb/test/core.c (view raw)

 1/* Copyright (c) 2013-2016 Jeffrey Pfau
 2 *
 3 * This Source Code Form is subject to the terms of the Mozilla Public
 4 * License, v. 2.0. If a copy of the MPL was not distributed with this
 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 6#include "util/test/suite.h"
 7
 8#include <mgba/core/core.h>
 9#include <mgba/gb/core.h>
10#include <mgba/internal/gb/gb.h>
11#include <mgba-util/vfs.h>
12
13M_TEST_DEFINE(create) {
14	struct mCore* core = GBCoreCreate();
15	assert_non_null(core);
16	assert_true(core->init(core));
17	core->deinit(core);
18}
19
20M_TEST_DEFINE(platform) {
21	struct mCore* core = GBCoreCreate();
22	assert_non_null(core);
23	assert_int_equal(core->platform(core), mPLATFORM_GB);
24	assert_true(core->init(core));
25	core->deinit(core);
26}
27
28M_TEST_DEFINE(reset) {
29	struct mCore* core = GBCoreCreate();
30	assert_non_null(core);
31	assert_true(core->init(core));
32	mCoreInitConfig(core, NULL);
33	core->reset(core);
34	mCoreConfigDeinit(&core->config);
35	core->deinit(core);
36}
37
38M_TEST_DEFINE(loadNullROM) {
39	struct mCore* core = GBCoreCreate();
40	assert_non_null(core);
41	assert_true(core->init(core));
42	mCoreInitConfig(core, NULL);
43	assert_false(core->loadROM(core, NULL));
44	core->reset(core);
45	mCoreConfigDeinit(&core->config);
46	core->deinit(core);
47}
48
49M_TEST_DEFINE(isROM) {
50	struct VFile* vf = VFileMemChunk(NULL, 2048);
51	GBSynthesizeROM(vf);
52	assert_true(GBIsROM(vf));
53	struct mCore* core = mCoreFindVF(vf);
54	assert_non_null(core);
55	assert_int_equal(core->platform(core), mPLATFORM_GB);
56	vf->close(vf);
57	assert_true(core->init(core));
58
59	core->deinit(core);
60}
61
62M_TEST_SUITE_DEFINE(GBCore,
63	cmocka_unit_test(create),
64	cmocka_unit_test(platform),
65	cmocka_unit_test(reset),
66	cmocka_unit_test(loadNullROM),
67	cmocka_unit_test(isROM))