Tizen 2.1 base
[platform/core/api/camera.git] / TC / testcase / utc_media_camera_working.c
1 /*
2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
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
18
19 #include <tet_api.h>
20 #include <media/camera.h>
21 #include <stdio.h>
22 #include <glib.h>
23
24 #define MY_ASSERT( fun , test , msg ) \
25 {\
26         if( !test ) \
27                 dts_fail(fun , msg ); \
28 }               
29
30 static GMainLoop *g_mainloop = NULL;
31 static GThread *event_thread;
32 int preview_win = 0;    
33
34
35 static void startup(void);
36 static void cleanup(void);
37
38 void (*tet_startup)(void) = startup;
39 void (*tet_cleanup)(void) = cleanup;
40
41 static void utc_media_camera_attribute_test(void);
42 static void utc_media_camera_preview_test(void);
43 static void utc_media_camera_state_change_test(void);
44 static void utc_media_camera_capture_test(void);
45 static void utc_media_capture_resolution_test(void);
46
47 struct tet_testlist tet_testlist[] = {
48         { utc_media_camera_attribute_test , 1 },
49         { utc_media_camera_preview_test, 2} ,
50         { utc_media_camera_state_change_test , 3 },
51         { utc_media_camera_capture_test , 4 },
52         { utc_media_capture_resolution_test , 5 },
53         { NULL, 0 },
54 };
55
56
57 gpointer GmainThread(gpointer data){
58         g_mainloop = g_main_loop_new (NULL, 0);
59         g_main_loop_run (g_mainloop);
60         
61         return NULL;
62 }
63
64
65 static void startup(void)
66 {
67         if( !g_thread_supported() )
68         {
69                 g_thread_init(NULL);
70         }
71         
72         GError *gerr = NULL;
73         event_thread = g_thread_create(GmainThread, NULL, 1, &gerr);
74 }
75
76 static void cleanup(void)
77 {
78         g_main_loop_quit (g_mainloop);
79         g_thread_join(event_thread);
80 }
81
82
83 void state_cb(camera_state_e previous , camera_state_e current , int by_asm, void *user_data){
84         char *state_table[] ={
85                         "CAMERA_STATE_NONE",                            /**< camera is not created yet */
86                         "CAMERA_STATE_CREATED",                         /**< camera is created, but not initialized yet */
87                         "CAMERA_STATE_PREVIEW",                         /**< camera is prepared to capture (Preview) */
88                         "CAMERA_STATE_CAPTURING",                       /**< While capturing*/
89                         "CAMERA_STATE_CAPTURED",                        /**< camera is now recording */
90                         "CAMERA_STATE_NUM",                                     /**< Number of camera states */
91                 };
92         printf("%s\n", state_table[current]);
93 }
94
95 void capture_cb(void *image_buffer, int buffer_size, int width, int height, camera_pixel_format_e format, void *user_data)
96 {
97         char * filepath = (char*)user_data;
98         FILE* f = fopen(filepath, "w+");
99         bool ret;
100         if(f!=NULL && image_buffer !=NULL)
101         {
102                 fwrite(image_buffer,1,  buffer_size, f);
103                 printf("capture(%s) %dx%d, buffer_size=%d\n", filepath, width, height, buffer_size);
104                 ret = TRUE;
105         }
106         else
107         {
108                 ret = FALSE;
109         }
110         
111         fclose(f);
112 }
113
114 int capture_complete(void *user_data){
115         camera_h cam = (camera_h)user_data;
116         
117         printf("capture_complete!!\n");
118
119         camera_start_preview(cam);
120         
121         return 1;       
122 }
123
124
125 bool g_preview_fps_pass;
126 bool _preview_fps_cb(camera_attr_fps_e fps, void *user_data){
127         int ret;
128         camera_attr_fps_e get_fps;
129         camera_h camera = (camera_h) user_data;
130         ret = camera_attr_set_preview_fps(camera, fps);
131         printf("-set preview fps %d\tret=%x\n", fps, ret);      
132         ret = camera_attr_get_preview_fps(camera, &get_fps);
133         printf("-get preview fps %d\tret=%x", get_fps, ret);    
134         
135         if(get_fps == fps)
136                 printf("\t\t\tpass\n");
137         else{
138                 printf("\t\t\tfail\n");
139                 g_preview_fps_pass = false;
140                 return false;
141         }               
142         return true;
143 }
144
145
146 int preview_fps_test(camera_h camera)
147 {
148         g_preview_fps_pass = true;
149         printf("------------- PREVIEW FPS TEST -------------\n");
150         camera_attr_foreach_supported_fps(camera, _preview_fps_cb,(void*)camera);
151         printf("--------------------------------------------\n");       
152         if( g_preview_fps_pass ){
153                 printf("PREVIEW FPS TEST PASS\n\n");
154                 return 0;
155         }else{
156                 printf("PREVIEW FPS TEST FAIL\n\n");
157                 return -1;
158         }
159 }
160
161 int image_quality_test(camera_h camera){
162         int ret1;       
163         int ret2;
164         int i;
165         printf("------------- IMAGE QUALITY TEST -------------\n");
166         for( i =-10; i <= 110 ; i+=10){
167                 int quality;
168                 ret1 = camera_attr_set_image_quality(camera,i);
169                 printf("-set image quality %d\tret=%x\n",i,ret1);
170                 ret2 = camera_attr_get_image_quality(camera,&quality);
171                 printf("-get image quality %d\tret=%x",quality,ret2);
172                 
173                 if( i >=0 && i <= 100){
174                         if( quality == i ){
175                                 printf("\t\t\tpass\n");
176                         }else
177                         {
178                                 printf("\t\t\tfail\n");                 
179                                 return -1;
180                         }
181                 }else{  //out of bound error
182                         if( ret1 == 0){
183                                 printf("\t\t\tfail\n");
184                                 return -1;
185                         }else{
186                                 printf("\t\t\tpass\n");
187                         }
188                 }
189                 
190         }
191         printf("--------------------------------------------\n");       
192         printf("IMAGE QUALITY TEST PASS\n\n");
193         
194         return 0;
195 }
196
197 int zoom_test(camera_h camera){
198         int ret1 ;
199         int ret2 ;      
200         int i;
201         int min, max;
202         printf("------------- ZOOM TEST -------------\n");
203         camera_attr_get_zoom_range(camera, &min, &max);
204         if(max == -1 )
205                 return 0;       
206         for( i = min ; i <= max; i+=5 ){
207                 int zoom;
208                 ret1 = camera_attr_set_zoom(camera, i);
209                 printf("-set zoom %d\tret=%x\n",i, ret1);
210                 ret2 = camera_attr_get_zoom(camera,&zoom);
211                 printf("-get zoom %d\tret=%x",zoom, ret2);
212
213                 if( i >=min && i <= max ){
214                         if( i == zoom )
215                                 printf("\t\t\tpass\n");
216                         else{
217                                 printf("\t\t\tfail\n");
218                                 return -1;
219                         }       
220                 }else{
221                         if( ret1 == 0 ){
222                                 printf("\t\t\tfail\n");
223                                 return -1;
224                         }else{
225                                 printf("\t\t\tpass\n");
226                         }
227                 }
228         }
229         printf("--------------------------------------------\n");       
230         printf("ZOOM TEST PASS\n\n");
231
232         camera_attr_set_zoom(camera, 10);       
233         return 0;
234 }
235
236 bool g_af_test_pass ;
237 bool _af_mode_test_cb(camera_attr_af_mode_e mode, void *user_data){
238         camera_h camera = (camera_h) user_data;
239         int ret;
240         camera_attr_af_mode_e get_mode;
241         ret= camera_attr_set_af_mode(camera, mode);
242         printf("-set af mode %d\tret=%x\n", mode, ret);
243         ret= camera_attr_get_af_mode(camera, &get_mode);
244         printf("-get af mode %d\tret=%x", get_mode, ret);       
245         if( mode != get_mode ){
246                 printf("\t\t\tFAIL\n");
247                 g_af_test_pass= false;
248                 return false;
249         }else
250                 printf("\t\t\tPASS\n");
251         return true;
252 }
253
254 int af_mode_test(camera_h camera){
255         g_af_test_pass = true;
256         camera_attr_foreach_supported_af_mode(camera, _af_mode_test_cb, camera);
257         return g_af_test_pass ? 0 : -1;
258 }
259
260 bool g_exposure_mode_pass;
261 bool _exposure_mode_test_cb(camera_attr_exposure_mode_e mode, void *user_data){
262         camera_h camera = (camera_h) user_data;
263         int ret;
264         camera_attr_exposure_mode_e get_mode;
265         
266         ret = camera_attr_set_exposure_mode(camera, mode);
267         printf("-set exposure mode %d\tret=%x\n", mode,ret);
268         ret = camera_attr_get_exposure_mode(camera,&get_mode);
269         printf("-get exposure mode %d\tret=%x\n", get_mode,ret);                
270         if( get_mode != mode ){
271                 g_exposure_mode_pass = false;
272                 return false;
273         }
274         return true;
275 }
276
277 int exposure_mode_test(camera_h camera){
278         g_exposure_mode_pass = true;
279         camera_attr_foreach_supported_exposure_mode(camera,_exposure_mode_test_cb, camera);
280         camera_attr_set_exposure_mode(camera, CAMERA_ATTR_EXPOSURE_MODE_ALL);
281         
282         return g_exposure_mode_pass ? 0 : -1;
283 }
284
285 int exposure_test(camera_h camera){
286         int i;
287         int ret1, ret2;
288         int default_value;
289         int min,max;
290         ret1 = camera_attr_get_exposure(camera, &default_value );       
291         camera_attr_get_exposure_range(camera, &min, &max);
292         printf("exposure range %d~%d\n", min, max);
293         if(max == -1 )
294                 return 0;       
295         for( i = 1; i < 13 ; i++ ){
296                 int value;
297                 ret1 = camera_attr_set_exposure(camera, i );
298                 printf("-set exposure %d\tret=%x\n",i,ret1);
299                 ret2 = camera_attr_get_exposure(camera, &value);
300                 printf("-get exposure %d\tret=%x\n",value,ret2);
301                 if( i >= min && i <= max ){
302                         if( value != i)
303                                 return -1;
304                 }else{ // out of bound error
305                         if( ret1 == 0 )
306                                 return -1;
307                 }
308         }       
309         ret1 = camera_attr_set_exposure(camera, default_value );        
310         return 0;
311 }
312
313 bool g_iso_test_pass ;
314 bool _iso_test_cb(camera_attr_iso_e iso, void *user_data){
315         camera_h camera = (camera_h) user_data;
316         int ret;
317         camera_attr_iso_e get_iso;
318         ret = camera_attr_set_iso(camera, iso);
319         printf("-set iso %d\tret=%x\n", iso, ret);
320         ret = camera_attr_get_iso(camera,&get_iso);
321         printf("-get iso %d\tret=%x\n", get_iso, ret);  
322         if( get_iso != iso ){
323                 g_iso_test_pass = false;
324                 return false;
325         }
326         return true;
327 }
328
329 int iso_test(camera_h camera){
330         g_iso_test_pass = true;
331         camera_attr_foreach_supported_iso(camera,_iso_test_cb, camera);
332         return g_iso_test_pass ? 0 : -1;
333 }
334
335 int brightness_test(camera_h camera){
336         int i;
337         int ret1,ret2;
338         int default_value;
339         int min,max;
340         ret1 = camera_attr_get_brightness(camera, &default_value );     
341         camera_attr_get_brightness_range(camera, &min, &max);
342         if(max == -1 )
343                 return 0;       
344         for( i = 1; i < 13 ; i++ ){
345                 int value;
346                 ret1 = camera_attr_set_brightness(camera, i );
347                 printf("-set brightness %d\tret=%x\n",i,ret1);
348                 ret2 = camera_attr_get_brightness(camera, &value);
349                 printf("-get brightness %d\tret=%x\n",value,ret2);
350
351                 if( i >= min && i <= max ){
352                         if( value != i)
353                                 return -1;
354                 }else{ // out of bound error
355                         if( ret1 == 0 )
356                                 return -1;
357                 }
358                 
359         }       
360         ret1 = camera_attr_set_brightness(camera, default_value );      
361         return 0;
362         
363 }
364
365 int contrast_test(camera_h camera){
366         int i;
367         int ret1,ret2;
368         int default_value;
369         int min,max;
370         ret1 = camera_attr_get_contrast (camera, &default_value );      
371         camera_attr_get_contrast_range(camera, &min, &max);
372         if(max == -1 )
373                 return 0;
374         for( i = 1; i < 13 ; i++ ){
375                 int value;
376                 ret1 = camera_attr_set_contrast (camera, i );
377                 printf("-set contrast %d\tret=%x\n",i,ret1);
378                 ret2 = camera_attr_get_contrast (camera, &value);
379                 printf("-get contrast %d\tret=%x\n",value,ret2);
380
381                 if( i >= min && i <= max ){
382                         if( value != i)
383                                 return -1;
384                 }else{ // out of bound error
385                         if( ret1 == 0 )
386                                 return -1;
387                 }               
388         }       
389         ret1 = camera_attr_set_contrast (camera, default_value );       
390         return 0;       
391 }
392
393 bool _whitebalance_test_cb(camera_attr_whitebalance_e wb,  void *user_data){
394         camera_h camera = (camera_h) user_data;
395         int ret;
396         ret = camera_attr_set_whitebalance(camera, wb);
397         printf("-set whitebalance %d\tret=%x\n", wb,ret);
398         ret = camera_attr_get_whitebalance(camera,&wb);
399         printf("-get whitebalance %d\tret=%x\n", wb,ret);               
400         return true;    
401 }
402
403
404 int whitebalance_test(camera_h camera){
405         camera_attr_foreach_supported_whitebalance(camera, _whitebalance_test_cb ,camera);
406         return 0;
407 }
408
409 bool _effect_test_cb(camera_attr_effect_mode_e effect,  void *user_data){
410         camera_h camera = (camera_h) user_data;
411         int ret;
412         ret = camera_attr_set_effect(camera, effect);
413         printf("-set effect %d\tret=%x\n", effect,ret);
414         ret = camera_attr_get_effect(camera,&effect);
415         printf("-get effect %d\tret=%x\n", effect,ret);         
416         return true;
417 }
418
419
420 int effect_test(camera_h camera){
421         camera_attr_foreach_supported_effect(camera, _effect_test_cb, camera);
422         return 0;
423 }
424
425
426 bool _scene_mode_test_cb (camera_attr_scene_mode_e mode,  void *user_data){
427         camera_h camera = (camera_h) user_data;
428         int ret;
429         ret = camera_attr_set_scene_mode(camera, mode);
430         printf("-set scene %d\tret=%x\n", mode,ret);
431         ret = camera_attr_get_scene_mode(camera,&mode);
432         printf("-get scene %d\tret=%x\n", mode,ret);            
433         return true;
434 }
435
436 int scene_mode_test(camera_h camera){
437         camera_attr_foreach_supported_scene_mode(camera, _scene_mode_test_cb, camera);
438         return 0;
439 }
440
441 int tag_enable_test(camera_h camera){
442         int ret;
443         bool enable;
444         ret = camera_attr_enable_tag(camera, true);
445         printf("-set enable tag true\tret=%x\n",ret);
446         ret = camera_attr_is_enabled_tag(camera, &enable);
447         printf("-get enable tag %d\tret=%x\n",enable, ret);
448         return 0;
449 }
450
451 int tag_orientation_test(camera_h camera){
452         int ret;
453         camera_attr_tag_orientation_e orientation;
454         
455         ret = camera_attr_set_tag_orientation(camera, 1);
456         printf("-set tag orientation %d\tret=%x\n",1 ,ret);
457         ret= camera_attr_get_tag_orientation(camera, &orientation);
458         printf("-get tag orientation %d\tret=%x\n",orientation,ret);    
459
460         
461         ret |= camera_attr_set_tag_orientation(camera, 2 );
462         printf("-set tag orientation %d\tret=%x\n",2 ,ret);
463         ret |= camera_attr_get_tag_orientation(camera, &orientation);
464         printf("-get tag orientation %d\tret=%x\n",orientation,ret);            
465
466         ret |= camera_attr_set_tag_orientation(camera, 3 );
467         printf("-set tag orientation %d\tret=%x\n",3 ,ret);
468         ret |= camera_attr_get_tag_orientation(camera, &orientation);
469         printf("-get tag orientation %d\tret=%x\n",orientation,ret);            
470
471         ret |= camera_attr_set_tag_orientation(camera, 4 );
472         printf("-set tag orientation %d\tret=%x\n",4 ,ret);
473         ret |= camera_attr_get_tag_orientation(camera, &orientation);
474         printf("-get tag orientation %d\tret=%x\n",orientation,ret);            
475
476         ret |= camera_attr_set_tag_orientation(camera, 5  );
477         printf("-set tag orientation %d\tret=%x\n",5  ,ret);
478         ret |= camera_attr_get_tag_orientation(camera, &orientation);
479         printf("-get tag orientation %d\tret=%x\n",orientation,ret);            
480
481         ret |= camera_attr_set_tag_orientation(camera, 6 );
482         printf("-set tag orientation %d\tret=%x\n",6 ,ret);
483         ret |= camera_attr_get_tag_orientation(camera, &orientation);
484         printf("-get tag orientation %d\tret=%x\n",orientation,ret);            
485
486         ret |= camera_attr_set_tag_orientation(camera, 7  );
487         printf("-set tag orientation %d\tret=%x\n",7  ,ret);
488         ret |= camera_attr_get_tag_orientation(camera, &orientation);
489         printf("-get tag orientation %d\tret=%x\n",orientation,ret);            
490
491         ret |= camera_attr_set_tag_orientation(camera, 8  );
492         printf("-set tag orientation %d\tret=%x\n",8  ,ret);
493         ret |= camera_attr_get_tag_orientation(camera, &orientation);
494         printf("-get tag orientation %d\tret=%x\n",orientation,ret);            
495
496         return ret == 0 ? 0 : -1;
497         
498 }
499
500 int tag_image_description_test(camera_h camera){
501         char *buffer;
502         int ret;
503         ret = camera_attr_set_tag_image_description(camera, "hello capi");
504         printf("-set tag image description \"hello capi\"\tret=%x\n", ret);
505         ret = camera_attr_get_tag_image_description(camera, &buffer);
506         printf("-get tag image description \"%s\"\tret=%x\n", buffer, ret);
507         free(buffer);
508         ret = camera_attr_set_tag_image_description(camera, "12345678901234567890");
509         printf("-set tag image description \"12345678901234567890\"\tret=%x\n", ret);
510         ret = camera_attr_get_tag_image_description(camera, &buffer);
511         printf("-get tag image description \"%s\"\tret=%x\n", buffer, ret);
512         free(buffer);
513         return 0;
514 }
515
516 int tag_software_test(camera_h camera){
517         char *buffer;
518         int ret;
519         ret = camera_attr_set_tag_software(camera, "hello capi");
520         printf("-set tag software \"hello capi\"\tret=%x\n", ret);
521         ret = camera_attr_get_tag_software(camera, &buffer);
522         printf("-get tag software  \"%s\"\tret=%x\n", buffer, ret);
523         free(buffer);
524
525         ret = camera_attr_set_tag_software(camera, "12345678901234567890");
526         printf("-set tag software \"12345678901234567890\"\tret=%x\n", ret);
527         ret = camera_attr_get_tag_software(camera, &buffer);
528         printf("-get tag software \"%s\"\tret=%x\n", buffer, ret);
529         free(buffer);
530         return 0;       
531 }
532
533
534 bool _flash_mode_test_cb(camera_attr_flash_mode_e mode,  void *user_data){
535         camera_h camera = (camera_h) user_data;
536         int ret;
537         ret = camera_attr_set_flash_mode(camera, mode);
538         printf("-set flash mode %d\tret=%x\n", mode,ret);
539         ret = camera_attr_get_flash_mode(camera,&mode);
540         printf("-get flash mode %d\tret=%x\n", mode,ret);               
541         return true;
542 }
543
544
545 int flash_mode_test(camera_h camera){
546         camera_attr_foreach_supported_flash_mode(camera, _flash_mode_test_cb,camera);
547         return 0;
548 }
549
550 int gps_test(camera_h camera){
551         double lng = 1.12;
552         double lat = 1.13;
553         double alt = 1.14;
554         int ret;
555         ret = camera_attr_set_geotag(camera, lat, lng , alt );
556         if( ret != 0)
557                 return -1;
558         ret = camera_attr_get_geotag(camera, &lat , &lng , &alt);
559         if( ret != 0 )
560                 return -1;
561         return 0;
562 }
563
564
565 void utc_media_camera_attribute_test(void)
566 {
567         int ret;
568         camera_h camera ;
569         int ret2;
570         camera_create(CAMERA_DEVICE_CAMERA0 , &camera);
571         camera_set_display(camera, CAMERA_DISPLAY_TYPE_X11, GET_DISPLAY(preview_win));
572         camera_set_x11_display_rotation(camera, CAMERA_ROTATION_270);   
573         printf("-----------------------create camera-----------------------------\n");
574
575         ret = preview_fps_test(camera);
576         printf("preview_fps_test %d\n", ret);   
577         ret += image_quality_test(camera);
578         printf("image_quality_test %d\n", ret);         
579         
580         ret2 = camera_start_preview(camera);
581         printf("--------------------------preview-started----------%x-------------------------\n", ret2);
582         ret += zoom_test(camera);
583         printf("zoom_test %d\n", ret);          
584         ret += af_mode_test(camera);
585         printf("af_mode_test %d\n", ret);       
586         ret += exposure_mode_test(camera);
587         printf("exposure_mode_test %d\n", ret);         
588         ret += exposure_test(camera);
589         printf("exposure_test %d\n", ret);              
590         ret += iso_test(camera);
591         printf("iso_test %d\n", ret);           
592         ret += brightness_test(camera);
593         printf("brightness_test %d\n", ret);            
594         ret += contrast_test(camera);
595         printf("contrast_test %d\n", ret);              
596         ret += whitebalance_test(camera);
597         printf("whitebalance_test %d\n", ret);          
598         ret += effect_test(camera);
599         printf("effect_test %d\n", ret);        
600         ret += scene_mode_test(camera);
601         printf("scene_mode_test %d\n", ret);    
602         ret += tag_enable_test(camera);
603         printf("tag_enable_test %d\n", ret);
604         ret += tag_orientation_test(camera);
605         printf("tag_orientation_test %d\n", ret);       
606         ret += tag_image_description_test(camera);
607         printf("tag_image_description_test %d\n", ret); 
608         ret += tag_software_test(camera);
609         printf("tag_software_test %d\n", ret);  
610         ret += flash_mode_test(camera);
611         printf("flash_mode_test %d\n", ret);    
612         ret += gps_test(camera);
613         printf("gps_test %d\n", ret);   
614         
615         camera_stop_preview(camera);
616         camera_destroy(camera);
617
618         MY_ASSERT(__func__, ret == 0 , "error attribute get set test");
619         dts_pass(__func__, "PASS");
620         
621 }
622
623
624 typedef struct {
625         camera_h camera;
626         camera_pixel_format_e in_format;
627         bool iscalled;
628         bool result;
629 } camera_preview_test_s;
630
631  void _camera_preview_test_cb(void *stream_buffer, int buffer_size, int width, int height, camera_pixel_format_e format,  void *user_data){
632         camera_preview_test_s * data = (camera_preview_test_s*)user_data;
633         data->iscalled = true;
634         if( format == data->in_format )
635                 data->result = true;
636
637 }
638
639 bool _preview_format_test_cb(camera_pixel_format_e format,  void *user_data){
640         int *table = (int*)user_data;
641         table[format] = 1;      
642         return true;
643 }
644
645
646 void utc_media_camera_preview_test(void)
647 {
648         int ret;
649         camera_h camera ;
650         int i;
651         camera_preview_test_s preview_test_data;
652         int enable_preview_format[CAMERA_PIXEL_FORMAT_JPEG+1] = {0,};
653         
654         
655         camera_create(CAMERA_DEVICE_CAMERA0 , &camera);
656         camera_set_display(camera, CAMERA_DISPLAY_TYPE_X11, GET_DISPLAY(preview_win));
657         camera_set_x11_display_rotation(camera, CAMERA_ROTATION_270);   
658         camera_set_preview_cb(camera,    _camera_preview_test_cb        , &preview_test_data);
659
660         ret = camera_foreach_supported_preview_format(camera, _preview_format_test_cb,enable_preview_format);
661
662         printf("-----------------------PREVIEW FORMAT TEST-----------------------------\n");
663         
664         for(i =0; i<= CAMERA_PIXEL_FORMAT_JPEG ; i++){
665                 if( enable_preview_format[i] ){
666                         preview_test_data.in_format = i;
667                         preview_test_data.camera = camera;
668                         preview_test_data.iscalled = false;
669                         preview_test_data.result = false;
670                         camera_set_preview_format(camera, i);
671                         printf("-------------PREVIEW FORMAT %d TEST--------------------\n", i);
672                         camera_start_preview(camera);
673                         sleep(1);
674                         camera_stop_preview(camera);
675                         if( preview_test_data.iscalled && preview_test_data.result ){
676                                 printf("PASS\n");
677                         }else{
678                                 printf("FAIL\n");
679                                 camera_destroy(camera);
680                                 dts_fail("CAMERA_PREVIEW_TEST", "preview cb is not called");
681                                 return;
682                         }
683                         
684                 }
685         }
686
687         camera_destroy(camera);
688
689         dts_pass(__func__,"PASS");
690         return;
691         
692         
693 }
694
695
696 typedef struct{
697         bool iscalled;
698         bool ispreviewed;
699         bool iscapturing;
700         bool iscaptured;
701         camera_state_e state;
702 } state_change_data;
703
704 void _state_change_test_cb(camera_state_e previous , camera_state_e current , bool by_asm,  void *user_data){
705         state_change_data * data = (state_change_data*)user_data;
706         data->iscalled = true;
707         if( current == CAMERA_STATE_PREVIEW )
708                 data->ispreviewed = true;
709         if( current == CAMERA_STATE_CAPTURED )
710                 data->iscaptured = true;
711         if( current == CAMERA_STATE_CAPTURING )
712                 data->iscapturing = true;
713         data->state = current;
714 }
715
716 void _capture_test_cb(camera_image_data_s* image, camera_image_data_s* postview, camera_image_data_s* thumbnail, void *user_data){
717         
718 }
719
720
721 void utc_media_camera_state_change_test(void){
722         camera_h camera ;
723         state_change_data data;
724         bool ispass = true;
725         
726         camera_create(CAMERA_DEVICE_CAMERA0 , &camera);
727         camera_set_display(camera, CAMERA_DISPLAY_TYPE_X11, GET_DISPLAY(preview_win));
728         camera_set_x11_display_rotation(camera, CAMERA_ROTATION_270);
729         camera_set_state_changed_cb(camera, _state_change_test_cb, &data);
730
731         printf("------------------- PREVIEW STATE Change test------------------\n");
732         data.iscalled = false;
733         data.state = 0; 
734         camera_start_preview(camera);
735         sleep(1);
736         if( data.iscalled && data.state == CAMERA_STATE_PREVIEW )
737                 printf("PASS\n");
738         else{
739                 printf("FAIL\n");
740                 ispass = false;
741         }
742
743
744         printf("------------------- CREATED STATE Change test------------------\n");
745         
746         data.iscalled = false;
747         data.state = 0;
748         camera_stop_preview(camera);
749         sleep(1);
750         if( data.iscalled && data.state == CAMERA_STATE_CREATED)
751                 printf("PASS\n");
752         else{
753                 printf("FAIL\n");
754                 ispass = false;
755         }
756
757
758         printf("------------------- CAPTURED STATE Change test------------------\n");
759
760         camera_start_preview(camera);
761         sleep(1);
762         data.iscalled = false;
763         data.state = 0;
764         data.iscaptured = false;
765         data.ispreviewed= false;        
766         data.iscapturing = false;       
767         camera_start_capture(camera, _capture_test_cb, NULL, NULL);
768         sleep(3);
769         if( data.iscalled &&  data.iscaptured && data.iscapturing && data.state == CAMERA_STATE_CAPTURED)
770                 printf("PASS\n");
771         else{
772                 printf("FAIL\n");
773                 ispass = false;
774         }
775         
776         camera_start_preview(camera);
777         camera_stop_preview(camera);
778         camera_destroy(camera);
779         MY_ASSERT(__func__, ispass , "camera_state_change_test FAIL");
780         dts_pass(__func__, "PASS");
781         
782 }
783
784 void _capture_test2_cb(camera_image_data_s* image, camera_image_data_s* postview, camera_image_data_s* thumbnail, void *user_data){
785         int *iscalled = (int*)user_data;
786         *iscalled = 1;
787 }
788
789 void utc_media_camera_capture_test(void){
790         camera_h camera ;
791         int iscalled;
792         camera_state_e state ;
793         bool ispass = true;
794         int timeout = 5;
795
796         printf("---------------------CAPTURE Test -----------------\n");
797         
798         camera_create(CAMERA_DEVICE_CAMERA0 , &camera);
799         camera_set_display(camera, CAMERA_DISPLAY_TYPE_X11, GET_DISPLAY(preview_win));
800         camera_set_x11_display_rotation(camera, CAMERA_ROTATION_270);   
801         camera_start_preview(camera);
802         iscalled = 0;
803         camera_start_capture(camera, _capture_test2_cb,NULL,  &iscalled);
804         
805         while( timeout-- >0 && camera_get_state(camera, &state ) == 0 && state != CAMERA_STATE_CAPTURED)
806                 sleep(1);
807         
808         if( iscalled == 1 )
809                 printf("PASS\n");
810         else{
811                 printf("FAIL\n");
812                 ispass = false;
813         }
814
815         
816         camera_start_preview(camera);
817         camera_stop_preview(camera);
818         camera_destroy(camera);
819
820         MY_ASSERT(__func__, ispass,"capture test fail");
821         dts_pass(__func__, "PASS");
822
823         
824 }
825
826
827 typedef struct{
828         int width[100];
829         int height[100];
830         int count;
831 } resolution_stack;
832
833
834 bool capture_resolution_test_cb(int width, int height,  void *user_data){
835         resolution_stack *data = (resolution_stack*)user_data;
836         data->width[data->count] = width;
837         data->height[data->count] = height;
838         data->count++;
839
840         printf("%dx%d\n",width, height);
841         
842         return true;
843 }
844
845 typedef struct{
846         int expected_width;
847         int expected_height;
848         bool ispass;
849 }preview_test_data;
850 void _capture_test3_cb(camera_image_data_s* image, camera_image_data_s* postview, camera_image_data_s* thumbnail, void *user_data){
851         preview_test_data *data = (preview_test_data*)user_data;
852         if( data->expected_height == image->height && data->expected_width == image->width )
853                 data->ispass = true;
854
855 }
856
857
858 void utc_media_capture_resolution_test(void){
859         camera_h camera ;
860         resolution_stack resolution_list;
861         int i;
862         camera_state_e state ;
863         int ret = 0;
864
865         camera_create(CAMERA_DEVICE_CAMERA0 , &camera);
866         camera_set_display(camera, CAMERA_DISPLAY_TYPE_X11, GET_DISPLAY(preview_win));
867         camera_set_x11_display_rotation(camera, CAMERA_ROTATION_270);
868         resolution_list.count = 0;
869         camera_foreach_supported_capture_resolution(camera, capture_resolution_test_cb, &resolution_list);
870         //camera_set_state_changed_cb(camera, state_cb, NULL);
871
872         printf("-----------------CAPTURE RESOLUTION TEST---------------------\n");
873
874         for(i =0 ; i < resolution_list.count ; i++){
875                 preview_test_data data;
876                 data.ispass = false;
877                 data.expected_width = resolution_list.width[i];
878                 data.expected_height = resolution_list.height[i];
879                 int timeout=5;
880
881                 printf("-----------------CAPTURE RESOLUTION (%dx%d)---------------------\n",data.expected_width  ,data.expected_height);
882                 
883                 printf("resolution set test %x\n", (unsigned int)camera_set_capture_resolution(camera,data.expected_width  ,data.expected_height));
884
885                 camera_start_preview(camera);
886                 
887                 camera_start_capture(camera, _capture_test3_cb, NULL , &data);
888                 
889                 while( timeout-- > 0 && camera_get_state(camera, &state ) == 0 && state != CAMERA_STATE_CAPTURED ){
890                         sleep(1);
891                 }
892
893                 camera_start_preview(camera);
894                 camera_stop_preview(camera);
895                 if( !data.ispass ){
896                         ret += -1;
897                         printf("FAIL\n");
898                 }else{
899                         printf("PASS\n");               
900                 }
901         }
902
903         MY_ASSERT(__func__,ret == 0, "capture resolution test fail");
904         dts_pass(__func__, "PASS");
905 }
906