From a30599e2396c4920d4b068caa682c6ba4c6e8830 Mon Sep 17 00:00:00 2001 From: Jeffrey Pfau Date: Fri, 21 Oct 2016 18:54:44 -0700 Subject: [PATCH] Test: More basic tests --- src/gb/test/core.c | 47 ++++++++++++++++++++++++++++++++++ src/gb/test/gb.c | 14 ++++++++++ src/gb/test/gb.h | 12 +++++++++ src/gba/test/core.c | 47 ++++++++++++++++++++++++++++++++++ src/gba/test/gba.c | 14 ++++++++++ src/gba/test/gba.h | 12 +++++++++ src/platform/test/suite-main.c | 12 +++++++++ src/util/test/suite.h | 4 +-- 8 files changed, 160 insertions(+), 2 deletions(-) create mode 100644 src/gb/test/core.c create mode 100644 src/gb/test/gb.c create mode 100644 src/gb/test/gb.h create mode 100644 src/gba/test/core.c create mode 100644 src/gba/test/gba.c create mode 100644 src/gba/test/gba.h diff --git a/src/gb/test/core.c b/src/gb/test/core.c new file mode 100644 index 000000000..6aba3898e --- /dev/null +++ b/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)) diff --git a/src/gb/test/gb.c b/src/gb/test/gb.c new file mode 100644 index 000000000..d637c3aea --- /dev/null +++ b/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; +} diff --git a/src/gb/test/gb.h b/src/gb/test/gb.h new file mode 100644 index 000000000..2bb574f01 --- /dev/null +++ b/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 diff --git a/src/gba/test/core.c b/src/gba/test/core.c new file mode 100644 index 000000000..5864f3d05 --- /dev/null +++ b/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)) diff --git a/src/gba/test/gba.c b/src/gba/test/gba.c new file mode 100644 index 000000000..58186cd00 --- /dev/null +++ b/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; +} diff --git a/src/gba/test/gba.h b/src/gba/test/gba.h new file mode 100644 index 000000000..c769e5320 --- /dev/null +++ b/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 diff --git a/src/platform/test/suite-main.c b/src/platform/test/suite-main.c index 5d5419fc7..2eb03f626 100644 --- a/src/platform/test/suite-main.c +++ b/src/platform/test/suite-main.c @@ -7,9 +7,21 @@ #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; } diff --git a/src/util/test/suite.h b/src/util/test/suite.h index 041633e01..5a2e0429b 100644 --- a/src/util/test/suite.h +++ b/src/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 \ No newline at end of file +#endif