ecore_timer: Check for the valid callback func 71/168771/1
authorMyoungwoon Roy, Kim <myoungwoon.kim@samsung.com>
Tue, 30 Jan 2018 05:43:11 +0000 (14:43 +0900)
committerMyoungwoon Roy, Kim <myoungwoon.kim@samsung.com>
Wed, 31 Jan 2018 00:38:09 +0000 (09:38 +0900)
Summary:
This patch checks whether the callback function is valid or not.
Callback function must be set up for the class.

Test Plan: Execute test suite

Reviewers: cedric, raster, stefan, Jaehyun_Cho

Subscribers: jpeg

Differential Revision: https://phab.enlightenment.org/D5762

Change-Id: I5ee3991cc01b696a47c52ee4ea6ccf22556350c4

src/lib/ecore/ecore_timer.c
src/tests/ecore/ecore_test_timer.c

index c473b3e..6ef4ab2 100644 (file)
@@ -176,7 +176,11 @@ ecore_timer_add(double in, Ecore_Task_Cb func, const void *data)
    EINA_MAIN_LOOP_CHECK_RETURN_VAL(NULL);
    legacy = calloc(1, sizeof (Ecore_Timer_Legacy));
    if (!legacy) return NULL;
-
+   if (!func)
+     {
+        ERR("Callback function must be set up for the class.");
+        return NULL;
+     }
    legacy->func = func;
    legacy->data = data;
    timer = efl_add(MY_CLASS, efl_main_loop_get(),
@@ -195,7 +199,11 @@ ecore_timer_loop_add(double in, Ecore_Task_Cb func, const void  *data)
    EINA_MAIN_LOOP_CHECK_RETURN_VAL(NULL);
    legacy = calloc(1, sizeof (Ecore_Timer_Legacy));
    if (!legacy) return NULL;
-
+   if (!func)
+     {
+        ERR("Callback function must be set up for the class.");
+        return NULL;
+     }
    legacy->func = func;
    legacy->data = data;
    timer = efl_add(MY_CLASS, efl_main_loop_get(),
index 66c0729..8895a36 100644 (file)
@@ -286,6 +286,16 @@ START_TEST(ecore_test_timer_lifecycle)
 }
 END_TEST
 
+
+START_TEST(ecore_test_timer_valid_callbackfunc)
+{
+   fail_if(!ecore_init(), "ERROR: Cannot init Ecore!\n");
+   Ecore_Timer *t = NULL;
+   fail_if((t = ecore_timer_add(0.5, NULL, NULL)), "ERROR: Invalid callback func!\n");
+   ecore_shutdown();
+}
+END_TEST
+
 void ecore_test_timer(TCase *tc)
 {
   tcase_add_test(tc, ecore_test_timers);
@@ -293,4 +303,5 @@ void ecore_test_timer(TCase *tc)
   tcase_add_test(tc, ecore_test_timer_lifecycle);
  */
   tcase_add_test(tc, ecore_test_timer_inside_call);
+  tcase_add_test(tc, ecore_test_timer_valid_callbackfunc);
 }