ADD_TESTS(cmocka-memory-cgroup "${UNIT_TESTS_CFLAGS}" "-Wl,--wrap=fread_int,--wrap=fread_uint,--wrap=fread_ulonglong -O0" cmocka-memory-cgroup.c)
ADD_TESTS(cmocka-fd-handler "${UNIT_TESTS_CFLAGS}" "-Wl,--wrap=malloc,--wrap=free -O0" cmocka-fd-handler.c)
ADD_TESTS(cmocka-config-parser "${UNIT_TESTS_CFLAGS}" "-Wl,--wrap=fread_int,--wrap=fread_uint,--wrap=fread_ulonglong -O0" cmocka-config-parser.c)
+ADD_TESTS(cmocka-notifier "${UNIT_TESTS_CFLAGS}" "-Wl,--wrap=malloc,--wrap=free,--wrap=g_slist_append,--wrap=g_slist_remove -O0" cmocka-notifier.c)
function(ADD_SKIP_TEST name wraps sources)
ADD_EXECUTABLE(${name} ${sources})
return 0;
}
-struct resourced_notifier *g_resourced_notifier;
+struct resourced_notifier *g_resourced_notifier[RESOURCED_NOTIFIER_MAX];
void *__wrap_malloc(size_t size)
{
if (!wrap_append)
return __real_g_slist_append(list, data);
- g_resourced_notifier = (struct resourced_notifier *)data;
+ int notifier_type = mock_type(int);
+
+ g_resourced_notifier[notifier_type] = (struct resourced_notifier *)data;
- if (!g_resourced_notifier->func)
+ if (!g_resourced_notifier[notifier_type]->func)
return NULL;
- int notifier_type = mock_type(int);
void *func = mock_ptr_type(void *);
- assert(func == (void*) g_resourced_notifier->func);
+ assert(func == (void*) g_resourced_notifier[notifier_type]->func);
- (void) notifier_type;
(void) func;
GSList *new_list = (GSList *)calloc(1, sizeof (GSList));
GSList *__wrap_g_slist_remove(GSList *list, gconstpointer data)
{
struct resourced_notifier *resourced_notifier = (struct resourced_notifier *)data;
- bool wrap_remove = mock_type(bool);
+ bool wrap_remove = mock_type(bool);
+ int notifier_type = mock_type(int);
- assert(resourced_notifier == g_resourced_notifier);
+ assert(resourced_notifier == g_resourced_notifier[notifier_type]);
if (!list)
return NULL;
__real_free(list);
- (void) resourced_notifier;
-
return NULL;
}
assert_int_equal(unregister_notifier(1, NULL), -EINVAL);
will_return(__wrap_free, true);
- expect_value(__wrap_free, ptr, cast_ptr_to_largest_integral_type(g_resourced_notifier));
+ expect_value(__wrap_free, ptr, cast_ptr_to_largest_integral_type(g_resourced_notifier[1]));
will_return(__wrap_g_slist_remove, true);
+ will_return(__wrap_g_slist_remove, 1);
assert_int_equal(unregister_notifier(1, fptr), 0);
}