Initialize Tizen 2.3
[framework/telephony/libslp-tapi.git] / wearable / TC / testcase / util_common.h
1 /*
2  * libslp-tapi
3  *
4  * Copyright (c) 2013 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Contact: Ja-young Gu <jygu@samsung.com>
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  */
20
21 #ifndef __UTIL_COMMON_H__
22 #define __UTIL_COMMON_H__
23
24 /**
25  * Generate default TC for no-additional-parameter type API
26  *
27  * - positive case ('utc_' prefix)
28  *   - valid handle
29  *   - with callback
30  *     check user_data validation in callback
31  *     not check result and data (modem state dependancy)
32  *   - without callback
33  *
34  * - negative case ('utc_fail_' prefix)
35  *   - invalid handle (NULL)
36  *
37  * Usage:
38  *   DO(tel_get_network_band)
39  *
40  *   struct tet_testlist tet_testlist[] = {
41  *       { ... },
42  *       { utc_tel_get_network_band, 1 },
43  *       { utc_fail_tel_get_network_band, 1 },
44  *       { ... },
45  *   };
46  *
47  */
48 #define DO(func) \
49         static void on_##func (TapiHandle *handle, int result, void *data, void *user_data) \
50         { \
51                 int *value = user_data; \
52 \
53                 async_flag = ASYNC_DONE; \
54                 util_stop_loop(); \
55 \
56                 if (*value != 0xC0FFEE) { \
57                         dts_fail(#func, "Callback userdata crashed"); \
58                 } \
59 \
60         } \
61 \
62         static void utc_##func (void) \
63         { \
64                 int ret; \
65                 int value = 0xC0FFEE; \
66 \
67                 /* with callback */ \
68                 util_init_loop(); \
69 \
70                 async_flag = ASYNC_READY; \
71                 ret = func (handle, on_##func, &value); \
72                 if (ret != TAPI_API_SUCCESS) { \
73                         dts_fail(#func, "Unexpected return"); \
74                 } \
75 \
76                 util_start_loop(); \
77                 util_free_loop(); \
78 \
79                 if (async_flag != ASYNC_DONE) { \
80                         dts_fail(#func, "Callback not invoked"); \
81                 } \
82 \
83                 /* without callback */ \
84                 ret = func (handle, NULL, NULL); \
85                 if (ret != TAPI_API_SUCCESS) { \
86                         dts_fail(#func, "Unexpected return"); \
87                         return; \
88                 } \
89 \
90                 dts_pass(#func); \
91         } \
92 \
93         static void utc_fail_##func (void) \
94         { \
95                 int ret; \
96 \
97                 ret = func (NULL, NULL, NULL); \
98                 dts_check_ne(#func, ret, TAPI_API_SUCCESS, "Unexpected return"); \
99         }
100
101 enum async_state {
102         ASYNC_READY,
103         ASYNC_DONE
104 };
105
106 void util_init_loop ();
107 void util_free_loop ();
108
109 void util_start_loop ();
110 void util_stop_loop ();
111
112 #endif