Merge "Add LCOV macro for coverage" into tizen
[platform/core/api/connection.git] / unittest / utc-connection-common.h
1 //
2 // Copyright (c) 2020 Samsung Electronics Co., Ltd.
3 //
4 // Licensed under the Apache License, Version 2.0 (the License);
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 //     http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 //
16
17 #ifndef _CONNECTION_COMMON_H_
18 #define _CONNECTION_COMMON_H_
19
20 #include <tct_common.h>
21 #include <system_info.h>
22 #include <glib.h>
23 #include <stdlib.h>
24 #include <string.h>
25 #include <time.h>
26 #include <net_connection.h>
27 #include <dlog.h>
28 #include "assert_local.h"
29
30 #ifdef DEBUG_GCOV
31 #define COMMON_DEBUG                                    1
32 #else
33 #define COMMON_DEBUG                                    0
34 #endif
35
36 #define GMAINTIMEOUT                    20000
37 #define CUSTOM_PROFILE_NAME             "Net"
38
39 #define FEATURE_WIFI                            "http://tizen.org/feature/network.wifi"
40 #define FEATURE_ETHERNET                        "http://tizen.org/feature/network.ethernet"
41 #define FEATURE_TELEPHONY                       "http://tizen.org/feature/network.telephony"
42 #define FEATURE_BT_TETHERING                    "http://tizen.org/feature/network.tethering.bluetooth"
43 #define FEATURE_ROUTE                           "http://tizen.org/feature/network.route"
44 #define CALLBACK_RETURN                         "callback return"
45
46 extern GMainLoop *g_pMainLoop;
47 extern guint g_nTimeoutId;
48 extern int g_CallbackRet;
49
50 extern bool wifi_supported;
51 extern bool telephony_supported;
52 extern bool bt_tethering_supported;
53 extern bool ethernet_supported;
54 extern bool route_supported;
55 extern bool all_features_not_supported;
56
57 extern connection_profile_h profile_cellular;
58 extern connection_profile_h profile_wifi;
59 extern connection_profile_h profile_temp;
60 extern connection_h connection;
61
62 #define RUN_GMAIN_LOOP { \
63         g_pMainLoop = g_main_loop_new(NULL, false); \
64         g_nTimeoutId = g_timeout_add(GMAINTIMEOUT, test_connection_timeout_callback, g_pMainLoop); \
65         if (COMMON_DEBUG) { \
66                 PRINT_LOG(DLOG_INFO, "NativeTCT", "[Line:%5d][%s] Run mainloop [%p]", \
67                                 __LINE__, __FUNCTION__, g_pMainLoop); \
68         } \
69         g_main_loop_run(g_pMainLoop); \
70         g_source_remove(g_nTimeoutId); \
71         g_pMainLoop = NULL; \
72 }
73
74 #define QUIT_GMAIN_LOOP { \
75         if (g_pMainLoop) { \
76                 if (COMMON_DEBUG) { \
77                         PRINT_LOG(DLOG_INFO, "NativeTCT", "[Line:%5d][%s] Quit mainloop [%p]", \
78                                         __LINE__, __FUNCTION__, g_pMainLoop); \
79                 } \
80                 g_main_loop_quit(g_pMainLoop); \
81         } \
82 }
83
84 #define FREE_RESOURCE(var) { \
85         if (var != NULL) { \
86                 g_free(var); \
87                 var = NULL; \
88         } \
89 }
90
91 #define PRINT_RETURN(api, ret) { \
92         if (COMMON_DEBUG) { \
93                 PRINT_LOG(DLOG_INFO, "NativeTCT", "[Line:%5d][%s] %s returned = %s", \
94                                 __LINE__, __FUNCTION__, api, connection_get_error(ret)); \
95         } \
96 }
97
98 #define CHECK_RETURN(api, ret, val) ({ \
99         if (ret != val) { \
100                 if (COMMON_DEBUG) { \
101                         PRINT_LOG(DLOG_INFO, "NativeTCT", "[Line:%5d][%s] %s failed, error returned = %s", \
102                                         __LINE__, __FUNCTION__, api, connection_get_error(ret)); \
103                 } \
104                 return 1; \
105         } else { \
106                 if (COMMON_DEBUG) { \
107                         PRINT_LOG(DLOG_INFO, "NativeTCT", "[Line:%5d][%s] %s", \
108                                         __LINE__, __FUNCTION__, api); \
109                 } \
110         } \
111 })
112
113 #define DEBUG_LOG { \
114         PRINT_LOG(DLOG_INFO, "NativeTCT", "[Line:%5d][%s] ***** DEBUG *****", __LINE__, __FUNCTION__); \
115 }
116
117 gboolean test_connection_timeout_callback(gpointer data);
118 const char *connection_get_error(connection_error_e error);
119 bool connection_check_feature_supported(char *key);
120 int test_get_any_profile(connection_profile_h *profile);
121 int test_get_profile_by_type(connection_profile_h *profile, connection_profile_type_e type);
122
123 #endif /* _CONNECTION_COMMON_H_ */