tizen 2.4 release
[framework/multimedia/libmm-radio.git] / test / mm_radio_testsuite.c
1 /*
2  * libmm-radio
3  *
4  * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Contact: JongHyuk Choi <jhchoi.choi@samsung.com>, YoungHwan An <younghwan_.an@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
22 /* testsuite for mm-radio library */
23 #include <stdlib.h>
24 #include <stdio.h>
25
26
27 #include "mm_radio.h"
28 #include "mm_radio_test_type.h"
29 #include "mm_radio_rt_api_test.h"
30
31 #define DEFAULT_TEST_FREQ       107700
32
33 /* test items...*/
34 int __test_radio_init(void);
35 int __test_radio_listen_gorealra(void);
36 int __test_repeat_init_release(void);
37 int __test_repeat_start_stop(void);
38 int __test_repeat_seek(void);
39 int __test_repeat_whole(void);
40 int __test_manual_api_calling(void);
41 int __test_radio_hw_debug(void);
42
43 static int __msg_callback(int message, void *param, void *user_param);
44
45 /* functions*/
46 static void __print_menu(void);
47 static void __run_test(int key);
48
49 /* list of tests*/
50 test_item_t g_tests[100] = {
51         /* menu string : short string to be displayed to menu
52              description : detailed description
53              test function :  a pointer to a actual test function
54              0 : to be filled with return value of test function
55          */
56         {
57                 "init test",
58                 "check radio init function",
59                 __test_radio_init,
60                 0
61         },
62
63         {
64                 "listening gorealra",
65                 "let's listen to the gorealra!",
66                 __test_radio_listen_gorealra,
67                 0
68         },
69
70         {
71                 "repeat_init_release",
72                 "repeat init and release and check if it working and memory usage increment",
73                 __test_repeat_init_release,
74                 0
75         },
76
77         {
78                 "repeat_start_stop",
79                 "repeat start and stop and check if it working and memory usage increment",
80                 __test_repeat_start_stop,
81                 0
82         },
83
84         {
85                 "repeat_seek",
86                 "repeat seek and check if it working and memory usage increment",
87                 __test_repeat_seek,
88                 0
89         },
90
91         {
92                 "repeat_whole",
93                 "repeat whole radio sequence and check if it working and memory usage increment",
94                 __test_repeat_whole,
95                 0
96         },
97
98         {
99                 "manual api calling test",
100                 "mapping each api to each test manu. just like other testsuite. try to reproduce the bugs with it.",
101                 __test_manual_api_calling,
102                 0
103         },
104
105         /* add tests here*/
106
107         /* NOTE : do not remove this last item */
108         {"end", "", NULL, 0},
109 };
110
111 int g_num_of_tests = 0;
112
113 int main(int argc, char **argv)
114 {
115         int key = 0;
116
117         do {
118                 __print_menu();
119
120                 do {
121                         key = getchar();
122
123                         if (key >= '0' && key <= '9') {
124                                 __run_test(key - '0');
125                         }
126                 } while (key == '\n');
127         } while (key != 'q' && key == 'Q');
128
129         printf("radio test client finished\n");
130
131         return 0;
132 }
133
134 void __print_menu(void)
135 {
136         int i = 0;
137
138         printf("\n\nFMRadio testing menu\n");
139         printf("------------------------------------------\n");
140
141         for (i = 0; g_tests[i].func; i++) {
142                 printf("[%d] %s\n", i, g_tests[i].menu_string);
143         }
144         printf("[q] quit\n");
145
146         g_num_of_tests = i;
147
148         printf("Choose one : ");
149 }
150
151 void __run_test(int key)
152 {
153         int ret = 0;
154
155         /* check index */
156         printf("#tests : %d    key : %d\n", g_num_of_tests, key);
157         if (key >= g_num_of_tests || key < 0) {
158                 printf("unassigned key has pressed : %d\n", key);
159                 return;
160         }
161
162         /* display description*/
163         printf("excuting test : %s\n", g_tests[key].menu_string);
164         printf("description : %s\n", g_tests[key].description);
165
166         /* calling test function*/
167         ret = g_tests[key].func();
168
169         g_tests[key].result =  ret;
170
171         if (ret) {
172                 printf("TEST FAILED. ret code : %d\n", g_tests[key].result);
173         } else {
174                 printf("TEST SUCCEDED. ret code : %d\n", g_tests[key].result);
175         }
176 }
177
178 static int __msg_callback(int message, void *pParam, void *user_param)
179 {
180         MMMessageParamType *param = (MMMessageParamType *)pParam;
181         MMHandleType radio = (MMHandleType) user_param;
182         int ret = 0;
183
184         printf("incomming message : %d\n", message);
185
186         switch (message) {
187                 case MM_MESSAGE_STATE_CHANGED:
188                         printf("MM_MESSAGE_STATE_CHANGED: current : %d    old : %d\n"
189                                , param->state.current, param->state.previous);
190                         break;
191                 case MM_MESSAGE_RADIO_SCAN_START:
192                         printf("MM_MESSAGE_RADIO_SCAN_START\n");
193                         break;
194                 case MM_MESSAGE_RADIO_SCAN_INFO:
195                         assert(param);
196                         printf("MM_MESSAGE_RADIO_SCAN_INFO : freq : %d KHz\n", param->radio_scan.frequency);
197                         break;
198                 case MM_MESSAGE_RADIO_SCAN_STOP:
199                         printf("MM_MESSAGE_RADIO_SCAN_STOP\n");
200                         break;
201                 case MM_MESSAGE_RADIO_SCAN_FINISH:
202                         printf("MM_MESSAGE_RADIO_SCAN_FINISHED\n");
203                         RADIO_TEST__(mm_radio_scan_stop(radio);)
204                         break;
205                 case MM_MESSAGE_RADIO_SEEK_START:
206                         printf("MM_MESSAGE_RADIO_SEEK_START\n");
207                         break;
208                 case MM_MESSAGE_RADIO_SEEK_FINISH:
209                         printf("MM_MESSAGE_RADIO_SEEK_FINISHED : freq : %d KHz\n", param->radio_scan.frequency);
210                         break;
211                 case MM_MESSAGE_STATE_INTERRUPTED:
212                         printf("MM_MESSAGE_STATE_INTERRUPTED code - %d\n", param->code);
213                         break;
214                 case MM_MESSAGE_READY_TO_RESUME:
215                         printf("MM_MESSAGE_READY_TO_RESUME\n");
216                         RADIO_TEST__(mm_radio_start(radio);)
217                         break;
218                 default:
219                         printf("ERROR : unknown message received!\n");
220                         break;
221         }
222
223         return true;
224 }
225
226 /* test items...*/
227 int __test_radio_init(void)
228 {
229         printf("%s\n", __FUNCTION__);
230
231         int ret = MM_ERROR_NONE;
232         MMHandleType radio = 0;
233
234         RADIO_TEST__(mm_radio_create(&radio);)
235         RADIO_TEST__(mm_radio_set_message_callback(radio, (MMMessageCallback)__msg_callback, (void *)radio);)
236         RADIO_TEST__(mm_radio_realize(radio);)
237         RADIO_TEST__(mm_radio_unrealize(radio);)
238         RADIO_TEST__(mm_radio_destroy(radio);)
239         return ret;
240 }
241
242 int __test_radio_listen_gorealra(void)
243 {
244         printf("%s\n", __FUNCTION__);
245
246         int ret = MM_ERROR_NONE;
247         MMHandleType radio = 0;
248
249         RADIO_TEST__(mm_radio_create(&radio);)
250         RADIO_TEST__(mm_radio_set_message_callback(radio, (MMMessageCallback)__msg_callback, (void *)radio);)
251         RADIO_TEST__(mm_radio_realize(radio);)
252         RADIO_TEST__(mm_radio_set_frequency(radio, DEFAULT_TEST_FREQ);)
253         RADIO_TEST__(mm_radio_start(radio);)
254         return ret;
255 }
256
257 int __test_repeat_init_release(void)
258 {
259         printf("%s\n", __FUNCTION__);
260
261         int ret = MM_ERROR_NONE;
262         int cnt = 0;
263         MMHandleType radio = 0;
264
265         while (1) {
266                 RADIO_TEST__(mm_radio_create(&radio);)
267                 RADIO_TEST__(mm_radio_set_message_callback(radio, (MMMessageCallback)__msg_callback, (void *)radio);)
268                 RADIO_TEST__(mm_radio_realize(radio);)
269                 RADIO_TEST__(mm_radio_unrealize(radio);)
270                 RADIO_TEST__(mm_radio_destroy(radio);)
271
272                 cnt++;
273
274                 printf("%s : repeat count : %d\n", __FUNCTION__, cnt);
275         }
276
277         return 0;
278 }
279
280 int __test_repeat_start_stop(void)
281 {
282         printf("%s\n", __FUNCTION__);
283         int ret = MM_ERROR_NONE;
284         int cnt = 0;
285         MMHandleType radio = 0;
286
287         RADIO_TEST__(mm_radio_create(&radio);)
288         RADIO_TEST__(mm_radio_set_message_callback(radio, (MMMessageCallback)__msg_callback, (void *)radio);)
289         RADIO_TEST__(mm_radio_realize(radio);)
290         RADIO_TEST__(mm_radio_set_frequency(radio, DEFAULT_TEST_FREQ);)
291
292         while (1) {
293                 RADIO_TEST__(mm_radio_start(radio);)
294                 RADIO_TEST__(mm_radio_stop(radio);)
295
296                 cnt++;
297
298                 printf("%s : repeat count : %d\n", __FUNCTION__, cnt);
299         }
300
301         return 0;
302 }
303
304 int __test_repeat_seek(void)
305 {
306         printf("__test_repeat_seek\n");
307         return 0;
308 }
309
310 int __test_repeat_whole(void)
311 {
312         printf("__test_repeat_whole\n");
313         return 0;
314 }
315
316 int __test_manual_api_calling(void)
317 {
318
319         mm_radio_rt_api_test();
320
321         return 0;
322 }
323