[ITC][shortcut][ACT-810][Add TCs for new callback APIs]
authorAmritanshu Pandia <a.pandia1@samsung.com>
Fri, 25 Nov 2016 10:44:15 +0000 (16:14 +0530)
committershobhit verma <shobhit.v@samsung.com>
Mon, 28 Nov 2016 09:56:29 +0000 (01:56 -0800)
Change-Id: I209597def345cdabeb43f9aff059bf8a193ed3cf
Signed-off-by: Amritanshu Pandia <a.pandia1@samsung.com>
src/itc/shortcut/ITs-shortcut-common.h
src/itc/shortcut/ITs-shortcut.c
src/itc/shortcut/tct-shortcut-native_mobile.h

index 10399ed..14e5a91 100755 (executable)
@@ -38,6 +38,7 @@ GMainLoop *g_pShortcutMainLoop;
 bool g_bCallbackHit;
 bool g_bRequestCBCallbackHit;
 bool g_b2CallbackValueCheck;
+bool g_bCallbackHitRemoveCb;
 
 #define API_NAMESPACE                          "SHORTCUT_ITC"
 #define TEST_SHORTCUT_APPID                    "org.tizen.shortcut_test"
index 37a6f8f..94f8891 100755 (executable)
@@ -226,6 +226,39 @@ static int ShortcutListCallBack(const char *package_name, const char *icon, cons
        return -1;
 }
 
+/**
+ * @function           ShortcutRemoveCb
+ * @description                Callback function
+ * @parameter          const char *package_name, const char *name, int sender_pid, void *user_data
+ * @return                     int
+ */
+static int ShortcutRemoveCb(const char *package_name, const char *name, int sender_pid, void *user_data)
+{
+       g_bCallbackHitRemoveCb = true;
+       FPRINTF("[Line : %d][%s] Inside ShortcutRemoveCb callback function\\n", __LINE__, API_NAMESPACE);
+       QUIT_GMAIN_LOOP;
+       return 0;
+}
+
+/**
+ * @function           ShortcutRemoveFromHomeCB
+ * @description                Callback function
+ * @parameter          int ret, void *data
+ * @return                     int
+ */
+static int ShortcutRemoveFromHomeCB(int ret, void *data)
+{
+       FPRINTF("[Line : %d][%s] ShortcutRemoveFromHomeCB callback called\\n", __LINE__, API_NAMESPACE);
+       if ( ret < 0 )
+       {
+               FPRINTF("[Line : %d][%s] Failed to remove shortcut : %s\\n", __LINE__, API_NAMESPACE, strerror(errno));
+               QUIT_GMAIN_LOOP;
+               return 0;
+       }
+       
+       QUIT_GMAIN_LOOP
+       return 0;
+}
 /**********************************************************CallBack End**********************************************************/
 
 
@@ -328,9 +361,10 @@ int ITc_shortcut_add_to_home_p(void)
 
        nRet = shortcut_add_to_home(pszName, LAUNCH_BY_APP, TEST_SHORTCUT_APPID, g_pszICON_PATH, DUPLICATEALLOWED, ShortcutAddToHomeCB, TESTSTRING);
        RUN_POLLING_LOOP;
-       PRINT_RESULT(SHORTCUT_ERROR_NONE, nRet, "shortcut_add_to_home", ShortcutError(nRet));
+       PRINT_RESULT_CLEANUP(SHORTCUT_ERROR_NONE, nRet, "shortcut_add_to_home", ShortcutError(nRet), shortcut_unset_request_cb());
        CHECK_CALLBACK_STATUS("shortcut_add_to_home", g_bCallbackHit, g_bRequestCBCallbackHit);
 
+       shortcut_unset_request_cb();
        return 0;
 }
 
@@ -388,8 +422,9 @@ int ITc_shortcut_add_to_home_widget_p(void)
 
                nRet = shortcut_add_to_home_widget(pszName, eShortcutWidgetSize[enum_counter1], TEST_SHORTCUT_APPID, g_pszICON_PATH, SHORTCUTPERIOD, DUPLICATEALLOWED, ShortcutAddToHomeWidgetCB, TESTSTRING);
                RUN_POLLING_LOOP;
-               PRINT_RESULT(SHORTCUT_ERROR_NONE, nRet, "shortcut_add_to_home_widget", ShortcutError(nRet));
+               PRINT_RESULT_CLEANUP(SHORTCUT_ERROR_NONE, nRet, "shortcut_add_to_home_widget", ShortcutError(nRet), shortcut_unset_request_cb());
                CHECK_CALLBACK_STATUS("shortcut_add_to_home_widget", g_bCallbackHit, g_bRequestCBCallbackHit);
+               shortcut_unset_request_cb();
        }
 
        return 0;
@@ -412,7 +447,7 @@ int ITc_shortcut_add_to_home_widget_p(void)
 //& purpose: Test shortcut_set_request_cb
 //& type: auto
 
-int ITc_shortcut_set_request_cb_p(void)
+int ITc_shortcut_set_unset_request_cb_p(void)
 {
        START_TEST;
        g_b2CallbackValueCheck = true;
@@ -428,9 +463,10 @@ int ITc_shortcut_set_request_cb_p(void)
 
        nRet = shortcut_add_to_home(pszName, LAUNCH_BY_APP, TEST_SHORTCUT_APPID, g_pszICON_PATH, DUPLICATEALLOWED, ShortcutAddToHomeCB, TESTSTRING);
        RUN_POLLING_LOOP;
-       PRINT_RESULT(SHORTCUT_ERROR_NONE, nRet, "shortcut_add_to_home", ShortcutError(nRet));
+       PRINT_RESULT_CLEANUP(SHORTCUT_ERROR_NONE, nRet, "shortcut_add_to_home", ShortcutError(nRet), shortcut_unset_request_cb());
        CHECK_CALLBACK_STATUS("shortcut_set_request_cb", g_bCallbackHit, g_bRequestCBCallbackHit);
 
+       shortcut_unset_request_cb();
        return 0;
 }
 
@@ -469,5 +505,65 @@ int ITc_shortcut_get_list_p(void)
        return 0;
 }
 
+/**
+* @testcase            ITc_shortcut_set_unset_remove_cb_p
+* @since_tizen                 3.0
+* @author                      SRID(a.pandia1)
+* @reviewer                    SRID(shobhit.v)
+* @type                                auto
+* @description         Registers and unregisters the callback function to listen the remove requests from applications
+* @scenario                    Call shortcut_set_remove_cb, shortcut_unset_remove_cb
+* @apicovered          shortcut_set_remove_cb, shortcut_unset_remove_cb
+* @passcase                    If target API returns SHORTCUT_ERROR_NONE
+* @failcase                    If API fails to complete the scenario cycle
+* @precondition                Prepare the callback function
+* @postcondition       You have to check the return status from the callback function which is passed by the argument.
+*/
+//& purpose: Registers and unregisters the callback function to listen the remove requests from applications
+//& type: auto
+
+int ITc_shortcut_set_unset_remove_cb_p(void)
+{
+       START_TEST;
+       g_b2CallbackValueCheck = true;
+
+       int nRet = -1;
+       char *pszName = "Test";
+
+       g_bCallbackHit = false;
+       g_bRequestCBCallbackHit = false;
+
+       nRet = shortcut_set_request_cb(ShortcutRequestCB, TESTSTRING);
+       PRINT_RESULT(SHORTCUT_ERROR_NONE, nRet, "shortcut_set_request_cb", ShortcutError(nRet));
+
+       nRet = shortcut_add_to_home(pszName, LAUNCH_BY_APP, TEST_SHORTCUT_APPID, g_pszICON_PATH, DUPLICATEALLOWED, ShortcutAddToHomeCB, TESTSTRING);
+       RUN_POLLING_LOOP;
+       PRINT_RESULT_CLEANUP(SHORTCUT_ERROR_NONE, nRet, "shortcut_add_to_home", ShortcutError(nRet), shortcut_unset_request_cb());
+       CHECK_CALLBACK_STATUS("shortcut_set_request_cb", g_bCallbackHit, g_bRequestCBCallbackHit);
+       
+       g_bCallbackHitRemoveCb = false;
+       // Target API
+       nRet = shortcut_set_remove_cb(ShortcutRemoveCb, NULL);
+       PRINT_RESULT_CLEANUP(SHORTCUT_ERROR_NONE, nRet, "shortcut_set_remove_cb", ShortcutError(nRet), shortcut_unset_request_cb());
+       
+       // Callback Triggering API
+       nRet = shortcut_remove_from_home(pszName, ShortcutRemoveFromHomeCB, NULL);
+       PRINT_RESULT_CLEANUP(SHORTCUT_ERROR_NONE, nRet, "shortcut_remove_from_home", ShortcutError(nRet), shortcut_unset_remove_cb();shortcut_unset_request_cb());
+       
+       RUN_POLLING_LOOP;
+       if(!g_bCallbackHitRemoveCb)
+       {
+               FPRINTF("[Line : %d][%s] Failed to hit callback ShortcutRemoveCb\\n", __LINE__, API_NAMESPACE);
+               shortcut_unset_remove_cb();
+               shortcut_unset_request_cb();
+               return 1;
+       }
+       
+       // Target API
+       shortcut_unset_remove_cb();
+
+       shortcut_unset_request_cb();
+       return 0;
+}
 /** @} */
 /** @} */
index 7eb68cd..e79e316 100755 (executable)
@@ -24,14 +24,16 @@ extern void ITs_shortcut_cleanup(void);
 
 extern int ITc_shortcut_add_to_home_p(void);
 extern int ITc_shortcut_add_to_home_widget_p(void);
-extern int ITc_shortcut_set_request_cb_p(void);
+extern int ITc_shortcut_set_unset_request_cb_p(void);
 extern int ITc_shortcut_get_list_p(void);
+extern int ITc_shortcut_set_unset_remove_cb_p(void);
 
 testcase tc_array[] = {
     {"ITc_shortcut_add_to_home_p", ITc_shortcut_add_to_home_p, ITs_shortcut_startup, ITs_shortcut_cleanup},
     {"ITc_shortcut_add_to_home_widget_p", ITc_shortcut_add_to_home_widget_p, ITs_shortcut_startup, ITs_shortcut_cleanup},
-    {"ITc_shortcut_set_request_cb_p", ITc_shortcut_set_request_cb_p, ITs_shortcut_startup, ITs_shortcut_cleanup},
+    {"ITc_shortcut_set_unset_request_cb_p", ITc_shortcut_set_unset_request_cb_p, ITs_shortcut_startup, ITs_shortcut_cleanup},
     {"ITc_shortcut_get_list_p", ITc_shortcut_get_list_p, ITs_shortcut_startup, ITs_shortcut_cleanup},
+    {"ITc_shortcut_set_unset_remove_cb_p", ITc_shortcut_set_unset_remove_cb_p, ITs_shortcut_startup, ITs_shortcut_cleanup},
     {NULL, NULL}
 };