ecore_thread: Update ecore_thread_main_loop_begin test
authorse.osadchy <se.osadchy@samsung.com>
Tue, 11 Apr 2017 13:34:37 +0000 (16:34 +0300)
committerse.osadchy <se.osadchy@samsung.com>
Tue, 11 Apr 2017 13:35:33 +0000 (16:35 +0300)
Change-Id: I511c70a5236667b84fd795b8105d4d29d8ce7164
Signed-off-by: Sergey Osadchy <se.osadchy@samsung.com>
TC/ecore/ecore/utc_ecore_thread_main_loop_begin.c

index 61050c145f316bbd63551f2a2419291d35275241..516b2bfee724f525b2fa4df50cfbd008b699206d 100644 (file)
@@ -1,7 +1,10 @@
 #include <check.h>
 #include <Eina.h>
 #include <Ecore.h>
+#include <pthread.h>
+
 static int result = -1;
+static Eina_Bool function_called = EINA_FALSE;
 
 /**
  * @addtogroup ecore
@@ -33,6 +36,22 @@ static Eina_Bool _timer_cb(void *data)
    return EINA_FALSE;
 }
 
+static Eina_Bool _timer_thread_cb(void *data)
+{
+   ecore_main_loop_quit();
+
+   return EINA_FALSE;
+}
+
+static void *_new_thread_run(void *arg)
+{
+   function_called = EINA_TRUE;
+   result = ecore_thread_main_loop_begin();
+   ecore_thread_main_loop_end();
+
+   return NULL;
+}
+
 /**
  * @addtogroup ecore_thread_main_loop_begin
  * @{
@@ -52,7 +71,6 @@ static Eina_Bool _timer_cb(void *data)
  */
 START_TEST(utc_ecore_thread_main_loop_begin_p)
 {
-
    ecore_timer_add(0.1, _timer_cb, NULL);
    ecore_main_loop_begin();
 
@@ -90,6 +108,44 @@ START_TEST(utc_ecore_thread_main_loop_begin_p2)
    printf("[TEST_PASS]:: %s[%d] : Test has passed..\n", __FILE__, __LINE__);
 }
 END_TEST
+
+/**
+ * @addtogroup ecore_thread_main_loop_begin
+ * @{
+ * @objective Positive test case 3 checks if ecore_thread_main_loop_begin succeeds.
+ * @n Input Data: none.
+ *
+ * @procedure
+ * @step 1 Add a new pthread
+ * @step 2 Invoke begin and end of ecore_thread_main_loop in new_thread_run
+ * @step 3 Add a timer with _timer_cb callback
+ * @step 4 Start main loop
+ * @step 5 Quit main loop
+ * @step 6 Check status of call functions after callbacks
+ *
+ * @passcondition
+ * Variable named result must be equal to 1, and there is no segmentation fault.
+ * @}
+ */
+START_TEST(utc_ecore_thread_main_loop_begin_p3)
+{
+   pthread_attr_t attr;
+   pthread_t thread_id;
+
+   pthread_attr_init(&attr);
+   pthread_create(&thread_id, &attr, _new_thread_run, NULL);
+
+   ecore_timer_add(0.1, _timer_thread_cb, NULL);
+   ecore_main_loop_begin();
+
+   if (function_called != EINA_TRUE || result != 1)
+     {
+        ck_abort_msg("[TEST_FAIL]:: %s[%d] : Test has failed..", __FILE__, __LINE__);
+     }
+   printf("[TEST_PASS]:: %s[%d] : Test has passed..\n", __FILE__, __LINE__);
+}
+END_TEST
+
 /**
  *@}
  */
@@ -103,6 +159,7 @@ test_suite(void)
    tcase_add_checked_fixture(tcase, setup, teardown);
    tcase_add_test(tcase, utc_ecore_thread_main_loop_begin_p);
    tcase_add_test(tcase, utc_ecore_thread_main_loop_begin_p2);
+   tcase_add_test(tcase, utc_ecore_thread_main_loop_begin_p3);
    suite_add_tcase(suite, tcase);
 
    return suite;