mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-02 23:33:54 -06:00
tests: add qtest_add_data_func_full
Allows one to specify a destroy function for the test data. Add a fallback using glib g_test_add_vtable() internal function, whose signature changed over time. Tested with glib 2.22, 2.26 and 2.48, which according to git log should be enough to cover all variations. Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com> Reviewed-by: Eric Blake <eblake@redhat.com>
This commit is contained in:
parent
f73480c36f
commit
822e36ca35
2 changed files with 36 additions and 0 deletions
|
@ -758,6 +758,25 @@ void qtest_add_func(const char *str, void (*fn)(void))
|
|||
g_free(path);
|
||||
}
|
||||
|
||||
void qtest_add_data_func_full(const char *str, void *data,
|
||||
void (*fn)(const void *),
|
||||
GDestroyNotify data_free_func)
|
||||
{
|
||||
gchar *path = g_strdup_printf("/%s/%s", qtest_get_arch(), str);
|
||||
#if GLIB_CHECK_VERSION(2, 34, 0)
|
||||
g_test_add_data_func_full(path, data, fn, data_free_func);
|
||||
#elif GLIB_CHECK_VERSION(2, 26, 0)
|
||||
/* back-compat casts, remove this once we can require new-enough glib */
|
||||
g_test_add_vtable(path, 0, data, NULL,
|
||||
(GTestFixtureFunc)fn, (GTestFixtureFunc) data_free_func);
|
||||
#else
|
||||
/* back-compat casts, remove this once we can require new-enough glib */
|
||||
g_test_add_vtable(path, 0, data, NULL,
|
||||
(void (*)(void)) fn, (void (*)(void)) data_free_func);
|
||||
#endif
|
||||
g_free(path);
|
||||
}
|
||||
|
||||
void qtest_add_data_func(const char *str, const void *data,
|
||||
void (*fn)(const void *))
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue