tizen 2.3 release
[framework/api/radio.git] / test / radio_test.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 "radio.h"
28 #include "radio_test_type.h"
29 #include <unistd.h>
30
31 #define DEFAULT_TEST_FREQ       107700
32 #define MENU_ITEM_MAX   19
33 #define _MAX_INPUT_STRING_ 100
34
35
36 /* test items...*/
37 int __test_radio_init(void);
38 int __test_radio_listen_gorealra(void);
39 int __test_repeat_init_release(void);
40 int __test_repeat_start_stop(void);
41 int __test_repeat_seek(void);
42 int __test_repeat_whole(void);
43 int __test_manual_api_calling(void);
44 int __test_radio_hw_debug(void);
45
46
47 /* functions*/
48 static void __print_menu(void);
49 static void __run_test(int key);
50
51 int mm_radio_rt_api_test(void);
52 static int __menu(void);
53 static void __call_api( int choosen );
54 void __radio_seek_completed_cb(int frequency, void *user_data);
55 void __radio_scan_updated_cb(int freq, void *user_data);
56 void __radio_scan_stop_cb(void *user_data);
57 void __radio_set_scan_completed_cb(void *user_param);
58 void __radio_set_interrupted_cb(radio_interrupted_code_e code, void *user_param);
59
60
61
62 /* list of tests*/
63 test_item_t g_tests[100] =
64 {
65         /* menu string : short string to be displayed to menu
66              description : detailed description
67              test function :  a pointer to a actual test function
68              0 : to be filled with return value of test function
69          */
70         {
71                 "init test",
72                 "check radio init function",
73                 __test_radio_init,
74         0
75         },
76
77         {
78                 "listening gorealra",
79                 "let's listen to the gorealra!",
80                 __test_radio_listen_gorealra,
81         0
82         },
83
84         {
85                 "repeat_init_release",
86                 "repeat init and release and check if it working and memory usage increment",
87                 __test_repeat_init_release,
88         0
89         },
90
91         {
92                 "repeat_start_stop",
93                 "repeat start and stop and check if it working and memory usage increment",
94                 __test_repeat_start_stop,
95         0
96         },
97
98         {
99                 "repeat_seek",
100                 "repeat seek and check if it working and memory usage increment",
101                 __test_repeat_seek,
102         0
103         },
104
105         {
106                 "repeat_whole",
107                 "repeat whole radio sequence and check if it working and memory usage increment",
108                 __test_repeat_whole,
109         0
110         },
111
112         {
113                 "manual api calling test",
114                 "mapping each api to each test manu. just like other testsuite. try to reproduce the bugs with it.",
115                 __test_manual_api_calling,
116         0
117         },
118
119         /* add tests here*/
120
121         /* NOTE : do not remove this last item */
122         {"end", "", NULL, 0},
123 };
124
125 int g_num_of_tests = 0;
126 static radio_h g_my_radio = 0;
127
128 int main(int argc, char **argv)
129 {
130         int key = 0;
131
132         do {
133                 __print_menu();
134
135                 do {
136                         key = getchar();
137
138                         if ( key >= '0' && key <= '9')
139                         {
140                                 __run_test( key - '0' );
141                         }
142                 }while ( key == '\n' );
143                 if(key == 'Q' || key == 'q')
144                         break;
145         }while(1);
146
147         printf("radio test client finished\n");
148
149         return 0;
150 }
151
152 void __print_menu(void)
153 {
154         int i = 0;
155
156         printf("\n\nFMRadio testing menu\n");
157         printf("------------------------------------------\n");
158
159         for ( i = 0; g_tests[i].func; i++ )
160         {
161                 printf( "[%d] %s\n", i, g_tests[i].menu_string );
162         }
163         printf("[q] quit\n");
164
165         g_num_of_tests = i;
166
167         printf("Choose one : ");
168 }
169
170 void __run_test(int key)
171 {
172         int ret = 0;
173
174         /* check index */
175         printf("#tests : %d    key : %d\n", g_num_of_tests, key);
176         if ( key >= g_num_of_tests || key < 0 )
177         {
178                 printf("unassigned key has pressed : %d\n", key);
179                 return;
180         }
181
182         /* display description*/
183         printf( "excuting test : %s\n", g_tests[key].menu_string );
184         printf( "description : %s\n", g_tests[key].description );
185
186         /* calling test function*/
187         ret = g_tests[key].func();
188
189         g_tests[key].result =  ret;
190
191         if ( ret )
192         {
193                 printf( "TEST FAILED. ret code : %d\n", g_tests[key].result);
194         }
195         else
196         {
197                 printf( "TEST SUCCEDED. ret code : %d\n", g_tests[key].result);
198         }
199 }
200
201
202 /* test items...*/
203 int __test_radio_init(void)
204 {
205         printf("%s\n", __FUNCTION__);
206
207         int ret = RADIO_ERROR_NONE;
208         radio_h radio;
209
210         RADIO_TEST__(    radio_create(&radio);  )
211         RADIO_TEST__( radio_destroy(radio); )
212         return ret;
213 }
214
215 int __test_radio_listen_gorealra(void)
216 {
217         printf("%s\n", __FUNCTION__);
218
219         int ret = RADIO_ERROR_NONE;
220         radio_h radio;
221
222         RADIO_TEST__( radio_create(&radio);     )
223         RADIO_TEST__( radio_set_frequency( radio, DEFAULT_TEST_FREQ ); )
224         RADIO_TEST__( radio_start(radio); )
225         usleep(5000 * 1000);
226         RADIO_TEST__( radio_stop(radio); )
227         RADIO_TEST__( radio_destroy(radio); )
228         return ret;
229 }
230
231 int __test_repeat_init_release(void)
232 {
233         printf("%s\n", __FUNCTION__);
234
235         int ret = RADIO_ERROR_NONE;
236         int cnt = 0;
237         radio_h radio;
238
239         while ( cnt < 1000 )
240         {
241                 RADIO_TEST__(    radio_create(&radio);  )
242                 RADIO_TEST__( radio_destroy(radio); )
243
244                 cnt++;
245
246                 printf("%s : repeat count : %d\n", __FUNCTION__, cnt);
247         }
248
249         return 0;
250 }
251
252 int __test_repeat_start_stop(void)
253 {
254         printf("%s\n", __FUNCTION__);
255         int ret = RADIO_ERROR_NONE;
256         int cnt = 0;
257         radio_h radio;
258
259         RADIO_TEST__(    radio_create(&radio);  )
260         RADIO_TEST__( radio_set_frequency( radio, DEFAULT_TEST_FREQ ); )
261
262         while(cnt < 10)
263         {
264                 RADIO_TEST__( radio_start(radio); )
265                 usleep(2000 * 1000);
266                 RADIO_TEST__( radio_stop(radio); )
267
268                 cnt++;
269
270                 printf("%s : repeat count : %d\n", __FUNCTION__, cnt);
271         }
272
273         return 0;
274 }
275
276 int __test_repeat_seek(void)
277 {
278         printf("__test_repeat_seek\n");
279         return 0;
280 }
281
282 int __test_repeat_whole(void)
283 {
284         printf("__test_repeat_whole\n");
285         return 0;
286 }
287
288 int __test_manual_api_calling(void)
289 {
290
291         mm_radio_rt_api_test();
292
293         return 0;
294 }
295
296
297 int mm_radio_rt_api_test(void)
298 {
299         while(1)
300         {
301                 int choosen = 0;
302
303                 choosen = __menu();
304
305                 if ( choosen == -1)
306                         continue;
307
308                 if ( choosen == 0 )
309                         break;
310
311                 __call_api( choosen );
312         }
313
314         printf("radio test client finished\n");
315
316         return 0;
317 }
318
319 int __menu(void)
320 {
321         int menu_item = 0;
322
323         printf("---------------------------------------------------------\n");
324         printf("mm-radio rt api test. try now!\n");
325         printf("---------------------------------------------------------\n");
326         printf("[1] radio_create\n");
327         printf("[2] radio_destroy\n");
328         printf("[3] radio_get_state\n");
329         printf("[4] radio_start\n");
330         printf("[5] radio_stop\n");
331         printf("[6] radio_seek_up\n");
332         printf("[7] radio_seek_down\n");
333         printf("[8] radio_set_frequency(ex.107700)\n");
334         printf("[9] radio_get_frequency\n");
335         printf("[10] radio_signal_strength\n");
336         printf("[11] radio_scan_start\n");
337         printf("[12] radio_scan_stop\n");
338         printf("[13] radio_set_mute\n");
339         printf("[14] radio_is_muted\n");
340         printf("[15] radio_set_scan_completed_cb\n");
341         printf("[16] radio_unset_scan_completed_cb\n");
342         printf("[17] radio_set_interrupted_cb\n");
343         printf("[18] radio_unset_interrupted_cb\n");
344
345         printf("[0] quit\n");
346         printf("---------------------------------------------------------\n");
347         printf("choose one : ");
348
349         if ( scanf("%d", &menu_item) == 0)
350         {
351                 char temp[_MAX_INPUT_STRING_];
352                 if (scanf("%s", temp) ==0)
353                 {
354                         printf("Error while flushing the input buffer - but lets continue\n");
355                 }
356                 return -1;
357         }
358
359
360         if ( menu_item > MENU_ITEM_MAX )
361                 menu_item = -1;
362
363         return menu_item;
364 }
365
366 void __call_api( int choosen )
367 {
368         int ret = RADIO_ERROR_NONE;
369
370         switch( choosen )
371         {
372                 case 1:
373                 {
374                         RADIO_TEST__( radio_create( &g_my_radio ); )
375                 }
376                 break;
377
378                 case 2:
379                 {
380                         RADIO_TEST__( radio_destroy( g_my_radio ); )
381                         g_my_radio = 0;
382                 }
383                 break;
384
385                 case 3:
386                 {
387                         radio_state_e state;
388                         RADIO_TEST__( radio_get_state(g_my_radio, &state); )
389
390                         printf("state : %d\n", state);
391                 }
392                 break;
393
394                 case 4:
395                 {
396                         RADIO_TEST__( radio_start(g_my_radio); )
397                 }
398                 break;
399
400                 case 5:
401                 {
402                         RADIO_TEST__( radio_stop(g_my_radio); )
403                 }
404                 break;
405
406                 case 6:
407                 {
408                         RADIO_TEST__( radio_seek_up(g_my_radio, __radio_seek_completed_cb, NULL); )
409
410                 }
411                 break;
412
413                 case 7:
414                 {
415                         RADIO_TEST__( radio_seek_down(g_my_radio, __radio_seek_completed_cb, NULL); )
416                 }
417                 break;
418
419                 case 8:
420                 {
421                         int freq = 0;
422                         printf("input freq : ");
423                         if (scanf("%d", &freq) == 0)
424                                 return;
425
426                         RADIO_TEST__( radio_set_frequency(g_my_radio, freq); )
427                 }
428                 break;
429
430                 case 9:
431                 {
432                         int freq = 0;
433                         RADIO_TEST__( radio_get_frequency(g_my_radio, &freq ); )
434
435                         printf("freq : %d\n", freq);
436                 }
437                 break;
438
439                 case 10:
440                 {
441                         int signal_strength = 0;
442                         RADIO_TEST__( radio_get_signal_strength(g_my_radio, &signal_strength); )
443                         printf("signal strength is : %d \n", signal_strength);
444                 }
445                 break;
446
447                 case 11:
448                 {
449                         RADIO_TEST__( radio_scan_start(g_my_radio, &__radio_scan_updated_cb, NULL); )
450                 }
451                 break;
452
453                 case 12:
454                 {
455                         RADIO_TEST__( radio_scan_stop(g_my_radio, &__radio_scan_stop_cb, NULL); )
456                 }
457                 break;
458
459                 case 13:
460                 {
461                         int muted = 0;
462                         printf("select one(0:UNMUTE/1:MUTE) : ");
463                         if ( scanf("%d", &muted) == 0)
464                                 return;
465                         RADIO_TEST__( radio_set_mute(g_my_radio, muted); )
466                 }
467                 break;
468
469                 case 14:
470                 {
471                         bool muted = 0;
472                         RADIO_TEST__( radio_is_muted(g_my_radio, &muted); )
473                         printf("muted : %d \n", muted);
474                 }
475                 break;
476
477
478                 case 15:
479                 {
480                         RADIO_TEST__( radio_set_scan_completed_cb(g_my_radio, &__radio_set_scan_completed_cb, NULL); )
481                 }
482                 break;
483
484                 case 16:
485                 {
486                         RADIO_TEST__( radio_unset_scan_completed_cb(g_my_radio); )
487                 }
488                 break;
489
490                 case 17:
491                 {
492                         RADIO_TEST__( radio_set_interrupted_cb(g_my_radio, &__radio_set_interrupted_cb, NULL ); )
493                 }
494                 break;
495
496                 case 18:
497                 {
498                         RADIO_TEST__( radio_unset_interrupted_cb(g_my_radio); )
499                 }
500                 break;
501
502                 default:
503                         break;
504         }
505 }
506
507
508 void __radio_seek_completed_cb(int frequency, void *user_data)
509 {
510         printf("__radio_seek_completed_cb freq is %d\n" , frequency);
511 }
512 void __radio_scan_updated_cb(int frequency, void *user_param)
513 {
514         printf("__radio_scan_updated_cb freq is %d\n" , frequency);
515 }
516
517 void __radio_scan_stop_cb(void *user_param)
518 {
519         printf("__radio_scan_stop_cb\n");
520 }
521
522 void __radio_set_scan_completed_cb(void *user_param)
523 {
524         printf("__radio_scan_completed_cb\n");
525 }
526
527 void __radio_set_interrupted_cb(radio_interrupted_code_e code, void *user_param)
528 {
529         printf("__radio_set_interrupted_cb\n");
530 }
531