all repos — mgba @ a30599e2396c4920d4b068caa682c6ba4c6e8830

mGBA Game Boy Advance Emulator

Test: More basic tests
Jeffrey Pfau jeffrey@endrift.com
Fri, 21 Oct 2016 18:54:44 -0700
commit

a30599e2396c4920d4b068caa682c6ba4c6e8830

parent

e54772fead056618fa39a7b3743a51749ec54f81

A src/gb/test/core.c

@@ -0,0 +1,47 @@

+/* 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" + +M_TEST_DEFINE(create) { + struct mCore* core = GBCoreCreate(); + assert_non_null(core); + assert_true(core->init(core)); + core->deinit(core); +} + +M_TEST_DEFINE(platform) { + struct mCore* core = GBCoreCreate(); + assert_non_null(core); + assert_true(core->platform(core) == PLATFORM_GB); + assert_true(core->init(core)); + core->deinit(core); +} + +M_TEST_DEFINE(reset) { + struct mCore* core = GBCoreCreate(); + assert_non_null(core); + assert_true(core->init(core)); + core->reset(core); + core->deinit(core); +} + +M_TEST_DEFINE(loadNullROM) { + struct mCore* core = GBCoreCreate(); + assert_non_null(core); + assert_true(core->init(core)); + assert_false(core->loadROM(core, NULL)); + core->reset(core); + core->deinit(core); +} + +M_TEST_SUITE_DEFINE(GBCore, + cmocka_unit_test(create), + cmocka_unit_test(platform), + cmocka_unit_test(reset), + cmocka_unit_test(loadNullROM))
A src/gb/test/gb.c

@@ -0,0 +1,14 @@

+/* 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" + +M_TEST_SUITE_DECLARE(GBCore); + +int TestRunGB(void) { + int failures = 0; + failures += M_TEST_SUITE_RUN(GBCore); + return failures; +}
A src/gb/test/gb.h

@@ -0,0 +1,12 @@

+/* 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/. */ +#ifndef TEST_GB_H +#define TEST_GB_H +#include "util/common.h" + +int TestRunGB(void); + +#endif
A src/gba/test/core.c

@@ -0,0 +1,47 @@

+/* 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 "gba/core.h" + +M_TEST_DEFINE(create) { + struct mCore* core = GBACoreCreate(); + assert_non_null(core); + assert_true(core->init(core)); + core->deinit(core); +} + +M_TEST_DEFINE(platform) { + struct mCore* core = GBACoreCreate(); + assert_non_null(core); + assert_true(core->platform(core) == PLATFORM_GBA); + assert_true(core->init(core)); + core->deinit(core); +} + +M_TEST_DEFINE(reset) { + struct mCore* core = GBACoreCreate(); + assert_non_null(core); + assert_true(core->init(core)); + core->reset(core); + core->deinit(core); +} + +M_TEST_DEFINE(loadNullROM) { + struct mCore* core = GBACoreCreate(); + assert_non_null(core); + assert_true(core->init(core)); + assert_false(core->loadROM(core, NULL)); + core->reset(core); + core->deinit(core); +} + +M_TEST_SUITE_DEFINE(GBACore, + cmocka_unit_test(create), + cmocka_unit_test(platform), + cmocka_unit_test(reset), + cmocka_unit_test(loadNullROM))
A src/gba/test/gba.c

@@ -0,0 +1,14 @@

+/* 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" + +M_TEST_SUITE_DECLARE(GBACore); + +int TestRunGBA(void) { + int failures = 0; + failures += M_TEST_SUITE_RUN(GBACore); + return failures; +}
A src/gba/test/gba.h

@@ -0,0 +1,12 @@

+/* 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/. */ +#ifndef TEST_GBA_H +#define TEST_GBA_H +#include "util/common.h" + +int TestRunGBA(void); + +#endif
M src/platform/test/suite-main.csrc/platform/test/suite-main.c

@@ -7,9 +7,21 @@ #include "util/test/suite.h"

#include "util/test/util.h" #include "core/test/core.h" +#ifdef M_CORE_GBA +#include "gba/test/gba.h" +#endif +#ifdef M_CORE_GB +#include "gb/test/gb.h" +#endif int main() { int failures = TestRunUtil(); failures += TestRunCore(); +#ifdef M_CORE_GBA + failures += TestRunGBA(); +#endif +#ifdef M_CORE_GB + failures += TestRunGB(); +#endif return failures != 0; }
M src/util/test/suite.hsrc/util/test/suite.h

@@ -13,7 +13,7 @@

#define M_TEST_DEFINE(NAME) static void NAME (void **state ATTRIBUTE_UNUSED) #define M_TEST_SUITE(NAME) _testSuite_ ## NAME -#define M_TEST_SUITE_RUN(NAME) M_TEST_SUITE(NAME)() +#define M_TEST_SUITE_RUN(NAME) printf("\nRunning suite %s\n", # NAME), M_TEST_SUITE(NAME)() #define M_TEST_SUITE_DEFINE(NAME, ...) \ int M_TEST_SUITE(NAME) (void) { \ const static struct CMUnitTest tests[] = { \

@@ -24,4 +24,4 @@ }

#define M_TEST_SUITE_DECLARE(NAME) extern int M_TEST_SUITE(NAME) (void) -#endif+#endif