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