libei: use a macro to define the tests

Having to define a separate name and test function for each test is annoying.
The unit-tests can leak the tests names anyway, so let's shortcut this with a
macro.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
This commit is contained in:
Peter Hutterer 2020-08-13 14:27:21 +10:00
parent f35b591b9c
commit 09f6ef8d7a
2 changed files with 13 additions and 8 deletions

View file

@ -281,19 +281,21 @@ test_device_context(const MunitParameter params[], void *user_data)
return MUNIT_OK;
}
#define TEST(_func) \
{ .name = #_func, .test = _func }
static MunitTest ei_device_tests[] = {
{ "/new", test_device_new, NULL, NULL, MUNIT_TEST_OPTION_NONE, NULL},
{ "/ids", test_device_ids, NULL, NULL, MUNIT_TEST_OPTION_NONE, NULL},
{ "/ref", test_device_ref_unref, NULL, NULL, MUNIT_TEST_OPTION_NONE, NULL},
{ "/capability", test_device_cap, NULL, NULL, MUNIT_TEST_OPTION_NONE, NULL},
{ "/context", test_device_context, NULL, NULL, MUNIT_TEST_OPTION_NONE, NULL},
TEST(test_device_new),
TEST(test_device_ids),
TEST(test_device_ref_unref),
TEST(test_device_cap),
TEST(test_device_context),
{ NULL },
};
static const MunitSuite libei_device_suite
__attribute__((used))
__attribute__((section("test_section"))) = {
"/device",
"/device/",
ei_device_tests,
NULL,
1,

View file

@ -858,9 +858,12 @@ test_configure_name(const MunitParameter params[], void *user_data)
return MUNIT_OK;
}
#define TEST(_func) \
{ .name = #_func, .test = _func }
static MunitTest ei_tests[] = {
{ "/init_unref", test_init_unref, NULL, NULL, MUNIT_TEST_OPTION_NONE, NULL},
{ "/name", test_configure_name, NULL, NULL, MUNIT_TEST_OPTION_NONE, NULL},
TEST(test_init_unref),
TEST(test_configure_name),
{ NULL },
};