Add multi handle test 67/201867/1 accepted/tizen/unified/20190325.070833 submit/tizen/20190322.054530
authorhyunuktak <hyunuk.tak@samsung.com>
Wed, 20 Mar 2019 08:37:56 +0000 (17:37 +0900)
committerhyunuktak <hyunuk.tak@samsung.com>
Wed, 20 Mar 2019 08:37:59 +0000 (17:37 +0900)
Change-Id: Ia86695c47f8b278a400b5ccd4f126dedbceb0dc8
Signed-off-by: hyunuktak <hyunuk.tak@samsung.com>
src/internal/stc-private.c
src/stc.c
test/restriction.c
test/stc_test.c

index c885879729862cf47e2130a9bcd72af027eb2195..da3899ff8276e0ee7fcaea9fb2b27a6ca21f152f 100755 (executable)
@@ -676,7 +676,6 @@ void _stc_handle_remove(stc_h stc)
        g_stc_handle_list = g_slist_remove(g_stc_handle_list, stc);
 
        g_free(stc);
-       stc = NULL;
 }
 
 bool _stc_handle_check_validity(stc_h stc)
index a0fbef3ce9299b0cd2bd89fe27c83286c819f18d..a8f4dcf966e4f4f252b9722e6fb77bf0ec7f5544 100755 (executable)
--- a/src/stc.c
+++ b/src/stc.c
@@ -108,10 +108,10 @@ EXPORT_API int stc_deinitialize(stc_h stc)
        }
 
        STC_LOGI("Destroy handle [%p]", stc);
-       _stc_handle_remove(stc);
-
        _stc_deinitialize(stc);
 
+       _stc_handle_remove(stc);
+
        STC_LOGI("STC successfully de-initialized");
 
        STC_UNLOCK;
index 0b8ec5e2d0b2f6cb9c416f3e4a4301bb1811e158..1ca96a079336a338db81b984750c80df74d90b7a 100755 (executable)
@@ -58,6 +58,7 @@ static char g_rstn_type[MENU_DATA_SIZE] = "1";
 static char g_rstn_rule_index[MENU_DATA_SIZE] = "0";
 
 extern stc_h g_stc;
+extern stc_h g_stc_sub;
 static stc_restriction_rule_h g_restriction_rule_h = NULL;
 static stc_restriction_list_h g_restriction_list_h = NULL;
 static int g_restriction_rule_index = 0;
@@ -172,12 +173,13 @@ static void __test_stc_warn_threshold_crossed_cb(stc_restriction_rule_h rule,
 {
        int ret = STC_ERROR_NONE;
        char *app_id = NULL;
+       stc_h stc = (stc_h)user_data;
 
        msg(HR_SINGLE);
 
        ret = stc_restriction_rule_get_app_id(rule, &app_id);
        if (ret == STC_ERROR_NONE)
-               msg("Warn threshold crossed app_id: " LOG_CYAN "[%s]" LOG_END, app_id);
+               msg("[%p] Warn threshold crossed app_id: " LOG_CYAN "[%s]" LOG_END, stc, app_id);
 
        g_free(app_id);
        msg(HR_SINGLE);
@@ -188,12 +190,13 @@ static void __test_stc_restriction_threshold_crossed_cb(stc_restriction_rule_h r
 {
        int ret = STC_ERROR_NONE;
        char *app_id = NULL;
+       stc_h stc = (stc_h)user_data;
 
        msg(HR_SINGLE);
 
        ret = stc_restriction_rule_get_app_id(rule, &app_id);
        if (ret == STC_ERROR_NONE)
-               msg("Restriction threshold crossed app_id: " LOG_CYAN "[%s]" LOG_END, app_id);
+               msg("[%p] Restriction threshold crossed app_id: " LOG_CYAN "[%s]" LOG_END, stc, app_id);
 
        g_free(app_id);
        msg(HR_SINGLE);
@@ -571,19 +574,37 @@ int test_stc_restriction_list_destroy(void)
 int test_stc_restriction_register_cb(void)
 {
        int ret = stc_set_warn_threshold_crossed_cb(g_stc,
-                       __test_stc_warn_threshold_crossed_cb, NULL);
+                       __test_stc_warn_threshold_crossed_cb, g_stc);
 
        if (ret == STC_ERROR_NONE)
-               msg(LOG_GREEN "Success to register warn threshold crossed cb" LOG_END);
+               msg(LOG_GREEN "Success to register warn threshold crossed cb [%p]" LOG_END, g_stc);
+       else
+               msg("Fail to register warn threshold crossed cb " LOG_RED "[%s]" LOG_END,
+                       test_stc_convert_error_type_to_string(ret));
+
+       ret = stc_set_warn_threshold_crossed_cb(g_stc_sub,
+                       __test_stc_warn_threshold_crossed_cb, g_stc_sub);
+
+       if (ret == STC_ERROR_NONE)
+               msg(LOG_GREEN "Success to register warn threshold crossed cb [%p]" LOG_END, g_stc_sub);
        else
                msg("Fail to register warn threshold crossed cb " LOG_RED "[%s]" LOG_END,
                        test_stc_convert_error_type_to_string(ret));
 
        ret = stc_set_restriction_threshold_crossed_cb(g_stc,
-                       __test_stc_restriction_threshold_crossed_cb, NULL);
+                       __test_stc_restriction_threshold_crossed_cb, g_stc);
+
+       if (ret == STC_ERROR_NONE)
+               msg(LOG_GREEN "Success to register restriction threshold crossed cb [%p]" LOG_END, g_stc);
+       else
+               msg("Fail to register restriction threshold crossed cb " LOG_RED "[%s]" LOG_END,
+                       test_stc_convert_error_type_to_string(ret));
+
+       ret = stc_set_restriction_threshold_crossed_cb(g_stc_sub,
+                       __test_stc_restriction_threshold_crossed_cb, g_stc_sub);
 
        if (ret == STC_ERROR_NONE)
-               msg(LOG_GREEN "Success to register restriction threshold crossed cb" LOG_END);
+               msg(LOG_GREEN "Success to register restriction threshold crossed cb [%p]" LOG_END, g_stc_sub);
        else
                msg("Fail to register restriction threshold crossed cb " LOG_RED "[%s]" LOG_END,
                        test_stc_convert_error_type_to_string(ret));
@@ -596,19 +617,35 @@ int test_stc_restriction_unregister_cb(void)
        int ret = stc_unset_warn_threshold_crossed_cb(g_stc);
 
        if (ret == STC_ERROR_NONE)
-               msg(LOG_GREEN "Success to unregister warn threshold crossed cb" LOG_END);
+               msg(LOG_GREEN "Success to unregister warn threshold crossed cb [%p]" LOG_END, g_stc);
        else
                msg("Fail to unregister warn threshold crossed cb " LOG_RED "[%s]" LOG_END,
                        test_stc_convert_error_type_to_string(ret));
 
-       ret = stc_unset_restriction_threshold_crossed_cb(g_stc);
+       ret = stc_unset_warn_threshold_crossed_cb(g_stc_sub);
 
        if (ret == STC_ERROR_NONE)
-               msg(LOG_GREEN "Success to unregister warn threshold crossed cb" LOG_END);
+               msg(LOG_GREEN "Success to unregister warn threshold crossed cb [%p]" LOG_END, g_stc_sub);
        else
                msg("Fail to unregister warn threshold crossed cb " LOG_RED "[%s]" LOG_END,
                        test_stc_convert_error_type_to_string(ret));
 
+       ret = stc_unset_restriction_threshold_crossed_cb(g_stc);
+
+       if (ret == STC_ERROR_NONE)
+               msg(LOG_GREEN "Success to unregister restriction threshold crossed cb [%p]" LOG_END, g_stc);
+       else
+               msg("Fail to unregister restriction threshold crossed cb " LOG_RED "[%s]" LOG_END,
+                       test_stc_convert_error_type_to_string(ret));
+
+       ret = stc_unset_restriction_threshold_crossed_cb(g_stc_sub);
+
+       if (ret == STC_ERROR_NONE)
+               msg(LOG_GREEN "Success to unregister restriction threshold crossed cb [%p]" LOG_END, g_stc_sub);
+       else
+               msg("Fail to unregister restriction threshold crossed cb " LOG_RED "[%s]" LOG_END,
+                       test_stc_convert_error_type_to_string(ret));
+
        return ret;
 }
 
index 71d1694e1871ec22f1e08be0942fe5f94d82871b..558f713fff26c4c3589af8a0205b47498b956878 100755 (executable)
@@ -55,6 +55,7 @@ extern struct menu_data menu_pcap[];
 extern struct menu_data menu_iptables[];
 
 stc_h g_stc = NULL;
+stc_h g_stc_sub = NULL;
 
 const char *test_stc_convert_error_type_to_string(stc_error_e err)
 {
@@ -359,9 +360,23 @@ static int __test_stc_initialize(MManager *mm, struct menu_data *menu)
                g_stc = NULL;
        }
 
+       if (g_stc_sub) {
+               stc_deinitialize(g_stc_sub);
+               g_stc_sub = NULL;
+       }
+
        ret = stc_initialize(&g_stc);
        if (ret == STC_ERROR_NONE)
-               msg(LOG_GREEN "Success to initialize STC" LOG_END);
+               msg(LOG_GREEN "Success to initialize STC [%p]" LOG_END, g_stc);
+       else {
+               msg("Fail to initialize STC " LOG_RED "[%s]" LOG_END,
+                       test_stc_convert_error_type_to_string(ret));
+               return ret;
+       }
+
+       ret = stc_initialize(&g_stc_sub);
+       if (ret == STC_ERROR_NONE)
+               msg(LOG_GREEN "Success to initialize STC [%p]" LOG_END, g_stc_sub);
        else {
                msg("Fail to initialize STC " LOG_RED "[%s]" LOG_END,
                        test_stc_convert_error_type_to_string(ret));
@@ -400,7 +415,15 @@ static int __test_stc_deinitialize(void)
                                test_stc_convert_error_type_to_string(ret));
        }
 
-       g_stc = NULL;
+       if (g_stc_sub) {
+               ret = stc_deinitialize(g_stc_sub);
+               if (ret == STC_ERROR_NONE)
+                       msg(LOG_GREEN "Success to deinitialize STC" LOG_END);
+               else
+                       msg("Fail to deinitialize STC " LOG_RED "[%s]" LOG_END,
+                               test_stc_convert_error_type_to_string(ret));
+       }
+
        return ret;
 }