src/util/test/suite.h (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#ifndef SUITE_H
7#define SUITE_H
8#include <mgba-util/common.h>
9
10#include <setjmp.h>
11#include <cmocka.h>
12
13#define M_TEST_DEFINE(NAME) static void NAME (void **state ATTRIBUTE_UNUSED)
14
15#define M_TEST_SUITE_DEFINE(NAME, ...) M_TEST_SUITE_DEFINE_EX(NAME, NULL, NULL, __VA_ARGS__)
16#define M_TEST_SUITE_DEFINE_SETUP(NAME, ...) M_TEST_SUITE_DEFINE_EX(NAME, _testSuite_setup_ ## NAME, NULL, __VA_ARGS__)
17#define M_TEST_SUITE_DEFINE_TEARDOWN(NAME, ...) M_TEST_SUITE_DEFINE_EX(NAME, NULL, _testSuite_teardown_ ## NAME, __VA_ARGS__)
18#define M_TEST_SUITE_DEFINE_SETUP_TEARDOWN(NAME, ...) M_TEST_SUITE_DEFINE_EX(NAME, _testSuite_setup_ ## NAME, _testSuite_teardown_ ## NAME, __VA_ARGS__)
19#define M_TEST_SUITE_DEFINE_EX(NAME, SETUP, TEARDOWN, ...) \
20 int main(void) { \
21 static const struct CMUnitTest tests[] = { \
22 __VA_ARGS__ \
23 }; \
24 return cmocka_run_group_tests_name(# NAME, tests, SETUP, TEARDOWN); \
25 }
26
27#define M_TEST_SUITE_SETUP(NAME) static int _testSuite_setup_ ## NAME (void **state ATTRIBUTE_UNUSED)
28#define M_TEST_SUITE_TEARDOWN(NAME) static int _testSuite_teardown_ ## NAME (void **state ATTRIBUTE_UNUSED)
29
30#endif