test: cmocka-notifier: Add each list per notifier type 74/320474/3
authorUnsung Lee <unsung.lee@samsung.com>
Sun, 3 Nov 2024 12:18:17 +0000 (21:18 +0900)
committerUnsung Lee <unsung.lee@samsung.com>
Mon, 25 Nov 2024 02:32:34 +0000 (11:32 +0900)
Add each list per notifier type to reflect the current notifier implementation.
This test code was created for a notifier with a single list and, therefore,
does not support the current multiple-list notfiers.

Change-Id: Ic4fa29fa988f17734bc9c0fc52824ef4c966deda
Signed-off-by: Unsung Lee <unsung.lee@samsung.com>
tests/CMakeLists.txt
tests/cmocka-notifier.c

index 9ead9df4f1ae397aa5c6cba231f0edd8c9e939c3..d3a1142eb39d03b6e8eae0cdd2307fb9ed54b618 100644 (file)
@@ -79,6 +79,7 @@ endfunction()
 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})
index 65ce4e6ed623fe4ff738a1a480804b80b63ae8d2..5f13f872f0dfc7c3d6c4858f23bff83e37003bc2 100644 (file)
@@ -50,7 +50,7 @@ static int test_notifier_cb(void *data)
        return 0;
 }
 
-struct resourced_notifier *g_resourced_notifier;
+struct resourced_notifier *g_resourced_notifier[RESOURCED_NOTIFIER_MAX];
 
 void *__wrap_malloc(size_t size)
 {
@@ -76,17 +76,17 @@ GSList *__wrap_g_slist_append(GSList *list, gpointer data)
        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));
@@ -99,9 +99,10 @@ GSList *__wrap_g_slist_append(GSList *list, gpointer data)
 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;
@@ -111,8 +112,6 @@ GSList *__wrap_g_slist_remove(GSList *list, gconstpointer data)
 
        __real_free(list);
 
-       (void) resourced_notifier;
-
        return NULL;
 }
 
@@ -149,8 +148,9 @@ static void test_unregister_notifier(void **state)
        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);
 }