Rescale temperature value
[platform/core/system/libdevice-node.git] / unittest / device_haltests.cpp
1
2 #include <iostream>
3 #include <gtest/gtest.h>
4 #include <system_info.h>
5 #include "unittest.h"
6 #include "hw/battery.h"
7 #include "hw/cpu.h"
8 #include "hw/display.h"
9 #include "hw/external_connection.h"
10 #include "hw/ir.h"
11 #include "hw/led.h"
12 #include "hw/thermal.h"
13 #include "hw/touchscreen.h"
14 #include "hw/usb_client.h"
15 #include "hw/usb_gadget.h"
16 #include "hw/bezel.h"
17 #include "hw/touchsensitivity.h"
18
19 using namespace std;
20
21 /*
22  * main class
23  */
24 #define MODEL_NAME      "http://tizen.org/system/model_name"
25 #define LOWBATTERY "LowBattery"
26
27 struct hw_info *info;
28 struct battery_device *battery_dev;
29 struct cpu_device *cpu_dev;
30 struct display_device *display_dev;
31 struct external_connection_device *ext_dev;
32 struct ir_device *ir_dev;
33 struct led_device *rgb_dev;
34 struct thermal_device *thermal_dev;
35 struct touchscreen_device *touchscreen_dev;
36 struct usb_client *client_dev;
37 struct usb_gadget *gadget_dev;
38 struct usb_gadget_id gadget_id;
39 struct usb_gadget_translator *gadget_translator;
40 struct bezel_device *bezel_dev;
41 struct touchsensitivity_device *touchsensitivity_dev;
42
43
44 /* Define Classes */
45 class BATTERYHalTest : public testing::Test
46 {
47         public:
48                 virtual void SetUp()
49                 {
50                         int ret;
51
52                         ret = system_info_get_platform_bool(FEATURE_BATTERY, &supported);
53                         EXPECT_EQ(SYSTEM_INFO_ERROR_NONE, ret) << "system_info_get_platform_bool failed";
54
55                 }
56
57                 virtual void TearDown()
58                 {
59
60                 }
61 };
62
63 class CPUHalTest : public testing::Test
64 {
65         public:
66                 virtual void SetUp()
67                 {
68
69                 }
70
71                 virtual void TearDown()
72                 {
73
74                 }
75 };
76
77 class DISPLAYHalTest : public testing::Test
78 {
79         public:
80                 virtual void SetUp()
81                 {
82
83                 }
84
85                 virtual void TearDown()
86                 {
87
88                 }
89 };
90
91 class EXTCONHalTest : public testing::Test
92 {
93         public:
94                 virtual void SetUp()
95                 {
96
97                 }
98
99                 virtual void TearDown()
100                 {
101
102                 }
103 };
104
105 class IRHalTest : public testing::Test
106 {
107         public:
108                 virtual void SetUp()
109                 {
110                         int ret;
111
112                         ret = system_info_get_platform_bool(FEATURE_IR, &supported);
113                         EXPECT_EQ(SYSTEM_INFO_ERROR_NONE, ret) << "system_info_get_platform_bool failed";
114                 }
115
116                 virtual void TearDown()
117                 {
118
119                 }
120 };
121
122 class RGBHalTest : public testing::Test
123 {
124         public:
125                 virtual void SetUp()
126                 {
127                         int ret;
128
129                         ret = system_info_get_platform_bool(FEATURE_LED, &supported);
130                         EXPECT_EQ(SYSTEM_INFO_ERROR_NONE, ret) << "system_info_get_platform_bool failed";
131                 }
132
133                 virtual void TearDown()
134                 {
135
136                 }
137 };
138
139 class THERMALHalTest : public testing::Test
140 {
141         public:
142                 virtual void SetUp()
143                 {
144                         int ret;
145
146                         ret = system_info_get_platform_bool(FEATURE_THERMISTOR, &supported);
147                         EXPECT_EQ(SYSTEM_INFO_ERROR_NONE, ret) << "system_info_get_platform_bool failed";
148                 }
149
150                 virtual void TearDown()
151                 {
152
153                 }
154 };
155
156 class TOUCHSCREENHalTest : public testing::Test
157 {
158         public:
159                 virtual void SetUp()
160                 {
161
162                 }
163
164                 virtual void TearDown()
165                 {
166
167                 }
168 };
169
170 class TOUCHSENSITIVITYHalTest : public testing::Test
171 {
172         public:
173                 virtual void SetUp()
174                 {
175
176                 }
177
178                 virtual void TearDown()
179                 {
180
181                 }
182 };
183
184 class BEZELHalTest : public testing::Test
185 {
186         public:
187                 virtual void SetUp()
188                 {
189                         int ret;
190
191                         ret = system_info_get_platform_bool(FEATURE_BEZEL, &supported);
192                         EXPECT_EQ(SYSTEM_INFO_ERROR_NONE, ret) << "system_info_get_platform_bool failed";
193                 }
194
195                 virtual void TearDown()
196                 {
197
198                 }
199 };
200
201 class USBCLIENTHalTest : public testing::Test
202 {
203         public:
204                 virtual void SetUp()
205                 {
206                         int ret;
207                         char *model_name = NULL;
208
209                         ret = system_info_get_platform_string(MODEL_NAME, &model_name);
210                         EXPECT_EQ(SYSTEM_INFO_ERROR_NONE, ret) << "system_info_get_platform_bool failed";
211
212                         if (!strncmp(model_name, "artik", 5)) {
213                                 supported = true;
214                         } else {
215                                 supported = false;
216                         }
217                         cout << "supported " << supported << endl;
218                         free(model_name);
219                 }
220
221                 virtual void TearDown()
222                 {
223
224                 }
225 };
226
227 class USBGADGETHalTest : public testing::Test
228 {
229         public:
230                 virtual void SetUp()
231                 {
232
233                 }
234
235                 virtual void TearDown()
236                 {
237
238                 }
239 };
240
241 /*
242  * Testcase for Battery
243  */
244 TEST_F(BATTERYHalTest, InitP)
245 {
246         int ret;
247
248         if (!supported)
249                 return;
250
251         info = NULL;
252         ret = hw_get_info(BATTERY_HARDWARE_DEVICE_ID,
253                         (const struct hw_info **)&info);
254         EXPECT_EQ(ret, 0) << "Fail to load battery hal (" << ret << ")";
255
256         if (!info->open) {
257                 cout << "There is no function for info open" << endl;
258                 return;
259         }
260         ret = info->open(info, NULL, (struct hw_common**)&battery_dev);
261         EXPECT_EQ(ret, 0) << "Fail to open battery device(" << ret << ")";
262 }
263
264 static void battery_updated_cb(struct battery_info *info, void *data)
265 {
266
267 }
268
269 TEST_F(BATTERYHalTest, RegisterChangedEventP)
270 {
271         int ret;
272
273         if (!supported)
274                 return;
275
276         if (!battery_dev->register_changed_event) {
277                 cout << "There is no function for register_changed_event" << endl;
278                 return;
279         }
280         ret = battery_dev->register_changed_event(battery_updated_cb, NULL);
281         EXPECT_EQ(ret, 0) << "Fail to register_changed_event (" << ret << ")";
282 }
283
284 TEST_F(BATTERYHalTest, UnregisterChangedEventP)
285 {
286         if (!supported)
287                 return;
288
289         if (!battery_dev->unregister_changed_event) {
290                 cout << "There is no function for unregister_changed_event" << endl;
291                 return;
292         }
293         battery_dev->unregister_changed_event(battery_updated_cb);
294 }
295
296 TEST_F(BATTERYHalTest, GetCurrentStateP)
297 {
298         int ret;
299
300         if (!supported)
301                 return;
302
303         if (!battery_dev->get_current_state) {
304                 cout << "There is no function for get_current_state" << endl;
305                 return;
306         }
307         ret = battery_dev->get_current_state(battery_updated_cb, NULL);
308         EXPECT_EQ(ret, 0) << "Fail to get_current_state (" << ret << ")";
309 }
310
311 TEST_F(BATTERYHalTest, DeinitP)
312 {
313         int ret;
314
315         if (!supported)
316                 return;
317
318         if (!info->close) {
319                 cout << "There is no function for info close" << endl;
320                 return;
321         }
322         ret = info->close((struct hw_common *)battery_dev);
323         EXPECT_EQ(ret, 0) << "Fail to close battery device(" << ret << ")";
324 }
325
326 /*
327  * Testcase for Cpu
328  */
329 TEST_F(CPUHalTest, InitP)
330 {
331         int ret;
332
333         info = NULL;
334         ret = hw_get_info(CPU_HARDWARE_DEVICE_ID,
335                         (const struct hw_info **)&info);
336         if (ret < 0) {
337                 cout << "There is no device for cpu " << ret << endl;
338                 return;
339         } else {
340                 EXPECT_EQ(ret, 0) << "Fail to load cpu hal (" << ret << ")";
341         }
342         if (!info || !info->open) {
343                 cout << "There is no function for info open" << endl;
344                 return;
345         }
346         ret = info->open(info, NULL, (struct hw_common**)&cpu_dev);
347         EXPECT_EQ(ret, 0) << "Fail to open cpu device (" << ret << ")";
348 }
349
350 TEST_F(CPUHalTest, StartBoostP)
351 {
352         int ret;
353
354         if (!cpu_dev || !cpu_dev->start_boost) {
355                 cout << "There is no function for start_boost" << endl;
356                 return;
357         }
358
359         // prprpr TODO
360         ret = cpu_dev->start_boost((void *)LOWBATTERY);
361         EXPECT_EQ(ret, 0) << "Fail to start_boost (" << ret << ")";
362 }
363
364 TEST_F(CPUHalTest, StopBoostP)
365 {
366         int ret;
367
368         if (!cpu_dev || !cpu_dev->stop_boost) {
369                 cout << "There is no function for stop_boost" << endl;
370                 return;
371         }
372
373         // prprpr TODO
374         ret = cpu_dev->stop_boost((void *)LOWBATTERY);
375         EXPECT_EQ(ret, 0) << "Fail to stop_boost (" << ret << ")";
376 }
377
378 TEST_F(CPUHalTest, DeinitP)
379 {
380         int ret;
381
382         if (!info || !info->close) {
383                 cout << "There is no function for info close" << endl;
384                 return;
385         }
386
387         ret = info->close((struct hw_common *)cpu_dev);
388         EXPECT_EQ(ret, 0) << "Fail to open cpu device (" << ret << ")";
389 }
390
391 /*
392  * Testcase for Display
393  */
394 TEST_F(DISPLAYHalTest, InitP)
395 {
396         int ret;
397
398         info = NULL;
399         ret = hw_get_info(DISPLAY_HARDWARE_DEVICE_ID,
400                         (const struct hw_info **)&info);
401         if (ret < 0) {
402                 cout << "There is no device for display" << ret << endl;
403                 return;
404         } else {
405                 EXPECT_EQ(ret, 0) << "Fail to load display hal (" << ret << ")";
406         }
407
408         if (!info || !info->open) {
409                 cout << "There is no function for info open" << endl;
410                 return;
411         }
412         ret = info->open(info, NULL, (struct hw_common**)&display_dev);
413         EXPECT_EQ(ret, 0) << "Fail to open display device (" << ret << ")";
414 }
415
416 TEST_F(DISPLAYHalTest, GetMaxBrightnessP)
417 {
418         int ret;
419         int max;
420
421         if (!display_dev || !display_dev->get_max_brightness) {
422                 cout << "There is no function for get_max_brightness" << endl;
423                 return;
424         }
425         ret = display_dev->get_max_brightness(&max);
426         EXPECT_EQ(ret, 0) << "Fail to get_max_brightness (" << ret << ")";
427 }
428
429 TEST_F(DISPLAYHalTest, GetBrightnessP)
430 {
431         int ret;
432         int brt;
433
434         if (!display_dev || !display_dev->get_brightness) {
435                 cout << "There is no function for get_brightness" << endl;
436                 return;
437         }
438         ret = display_dev->get_brightness(&brt);
439         EXPECT_EQ(ret, 0) << "Fail to get_brightness (" << ret << ")";
440 }
441
442 TEST_F(DISPLAYHalTest, SetBrightnessP)
443 {
444         int ret;
445         int max;
446
447         if (!display_dev || !display_dev->get_max_brightness) {
448                 cout << "There is no function for get_max_brightness" << endl;
449                 return;
450         }
451         ret = display_dev->get_max_brightness(&max);
452         EXPECT_EQ(ret, 0) << "Fail to get_max_brightness (" << ret << ")";
453
454         if (!display_dev || !display_dev->set_brightness) {
455                 cout << "There is no function for set_brightness" << endl;
456                 return;
457         }
458         ret = display_dev->set_brightness(max);
459         EXPECT_EQ(ret, 0) << "Fail to set_brightness (" << ret << ")";
460 }
461
462 TEST_F(DISPLAYHalTest, GetAutoBrightnessP)
463 {
464         int ret;
465         int brt;
466         float lmax = 0, lmin = 0, light = 0;
467
468         if (!display_dev || !display_dev->get_auto_brightness) {
469                 cout << "There is no function for get_auto_brightness" << endl;
470                 return;
471         }
472         ret = display_dev->get_auto_brightness(lmax, lmin, light, &brt);
473         EXPECT_GE(ret, 0) << "Fail to set_brightness (" << ret << ")";
474 }
475
476 TEST_F(DISPLAYHalTest, GetStateP)
477 {
478         int ret;
479         enum display_state state;
480
481         if (!display_dev || !display_dev->get_state) {
482                 cout << "There is no function for get_state" << endl;
483                 return;
484         }
485         ret = display_dev->get_state(&state);
486         EXPECT_GE(ret, 0) << "Fail to get_state (" << ret << ")";
487 }
488
489 TEST_F(DISPLAYHalTest, SetStateP)
490 {
491         int ret;
492
493         if (!display_dev || !display_dev->set_state) {
494                 cout << "There is no function for set_state" << endl;
495                 return;
496         }
497         ret = display_dev->set_state(DISPLAY_ON);
498         EXPECT_GE(ret, 0) << "Fail to set_state (" << ret << ")";
499 }
500
501 TEST_F(DISPLAYHalTest, GetMaxFrameRateP)
502 {
503         int ret;
504         int max;
505
506         if (!display_dev || !display_dev->get_max_frame_rate) {
507                 cout << "There is no function for get_max_frame_rate" << endl;
508                 return;
509         }
510         ret = display_dev->get_max_frame_rate(&max);
511         EXPECT_GE(ret, 0) << "Fail to get_max_frame_rate (" << ret << ")";
512 }
513
514 TEST_F(DISPLAYHalTest, GetMinFrameRateP)
515 {
516         int ret;
517         int min;
518
519         if (!display_dev || !display_dev->get_min_frame_rate) {
520                 cout << "There is no function for get_min_frame_rate" << endl;
521                 return;
522         }
523         ret = display_dev->get_min_frame_rate(&min);
524         EXPECT_GE(ret, 0) << "Fail to get_min_frame_rate (" << ret << ")";
525 }
526
527 TEST_F(DISPLAYHalTest, GetFrameRateP)
528 {
529         int ret, rate;
530
531         if (!display_dev || !display_dev->get_frame_rate) {
532                 cout << "There is no function for get_frame_rate" << endl;
533                 return;
534         }
535         ret = display_dev->get_frame_rate(&rate);
536         EXPECT_GE(ret, 0) << "Fail to get frame rate (" << ret << ")";
537 }
538
539 TEST_F(DISPLAYHalTest, SetFrameRateP)
540 {
541         int ret;
542         int max;
543
544         if (!display_dev || !display_dev->get_max_frame_rate) {
545                 cout << "There is no function for get_max_frame_rate" << endl;
546                 return;
547         }
548         ret = display_dev->get_max_frame_rate(&max);
549         EXPECT_GE(ret, 0) << "Fail to get_max_frame_rate (" << ret << ")";
550
551         if (!display_dev->set_frame_rate) {
552                 cout << "There is no function for set_frame_rate" << endl;
553                 return;
554         }
555         ret = display_dev->set_frame_rate(max);
556         EXPECT_GE(ret, 0) << "Fail to set_frame_rate (" << ret << ")";
557 }
558
559 TEST_F(DISPLAYHalTest, DeinitP)
560 {
561         int ret;
562
563         if (!info || !info->close) {
564                 cout << "There is no function for info close" << endl;
565                 return;
566         }
567         ret = info->close((struct hw_common *)display_dev);
568         EXPECT_GE(ret, 0) << "Fail to close display device (" << ret << ")";
569 }
570
571 /*
572  * Testcase for Extcon
573  */
574 TEST_F(EXTCONHalTest, InitP)
575 {
576         int ret;
577
578         info = NULL;
579         ret = hw_get_info(EXTERNAL_CONNECTION_HARDWARE_DEVICE_ID,
580                         (const struct hw_info **)&info);
581         if (ret < 0) {
582                 cout << "There is no device for extcon" << ret << endl;
583                 return;
584         } else {
585                 EXPECT_EQ(ret, 0) << "Fail to load extcon hal (" << ret << ")";
586         }
587
588         if (!info || !info->open) {
589                 cout << "There is no function for info open" << endl;
590                 return;
591         }
592         ret = info->open(info, NULL, (struct hw_common**)&ext_dev);
593         EXPECT_EQ(ret, 0) << "Fail to open extcon device(" << ret << ")";
594 }
595
596 static void extcon_updated_cb(struct connection_info *info, void *data)
597 {
598
599 }
600
601 TEST_F(EXTCONHalTest, RegisterChangedEventP)
602 {
603         int ret;
604
605         if (!ext_dev || !ext_dev->register_changed_event) {
606                 cout << "There is no function for register_changed_event" << endl;
607                 return;
608         }
609         ret = ext_dev->register_changed_event(extcon_updated_cb, NULL);
610         EXPECT_EQ(ret, 0) << "Fail to register_changed_event (" << ret << ")";
611 }
612
613 TEST_F(EXTCONHalTest, UnregisterChangedEventP)
614 {
615         if (!ext_dev || !ext_dev->unregister_changed_event) {
616                 cout << "There is no function for unregister_changed_event" << endl;
617                 return;
618         }
619         ext_dev->unregister_changed_event(extcon_updated_cb);
620 }
621
622 TEST_F(EXTCONHalTest, GetCurrentStateP)
623 {
624         int ret;
625
626         if (!ext_dev || !ext_dev->get_current_state) {
627                 cout << "There is no function for unregister_changed_event" << endl;
628                 return;
629         }
630         ret = ext_dev->get_current_state(extcon_updated_cb, NULL);
631         EXPECT_EQ(ret, 0) << "Fail to unregister_changed_event (" << ret << ")";
632 }
633
634 TEST_F(EXTCONHalTest, DeinitP)
635 {
636         int ret;
637
638         if (!info || !info->close) {
639                 cout << "There is no function for info close" << endl;
640                 return;
641         }
642         ret = info->close((struct hw_common *)ext_dev);
643         EXPECT_EQ(ret, 0) << "Fail to close extcon device(" << ret << ")";
644 }
645
646 /*
647  * Testcase for Ir
648  */
649 TEST_F(IRHalTest, InitP)
650 {
651         int ret;
652
653         if (!supported)
654                 return;
655
656         info = NULL;
657         ret = hw_get_info(IR_HARDWARE_DEVICE_ID,
658                         (const struct hw_info **)&info);
659         EXPECT_EQ(ret, 0) << "Fail to get hal for ir (" << ret << ")";
660
661         if (!info->open) {
662                 cout << "There is no function for info open" << endl;
663                 return;
664         }
665         ret = info->open(info, NULL, (struct hw_common**)&ir_dev);
666         EXPECT_EQ(ret, 0) << "Fail to open ir device (" << ret << ")";
667 }
668
669 TEST_F(IRHalTest, IsAvailableP)
670 {
671         int ret;
672         bool val;
673
674         if (!supported)
675                 return;
676
677         if (!ir_dev->is_available) {
678                 cout << "There is no function for is_available" << endl;
679                 return;
680         }
681         ret = ir_dev->is_available(&val);
682         EXPECT_EQ(ret, 0) << "Fail to is_available (" << ret << ")";
683 }
684
685 TEST_F(IRHalTest, TransmitP)
686 {
687         int ret;
688         int pattern[5] = {100, 200, 300, 400, 500};
689
690         if (!supported)
691                 return;
692
693         if (!ir_dev->transmit) {
694                 cout << "There is no function for transmit" << endl;
695                 return;
696         }
697         ret = ir_dev->transmit(pattern, 5);
698         EXPECT_EQ(ret, 0) << "Fail to transmit (" << ret << ")";
699 }
700
701 TEST_F(IRHalTest, DeinitP)
702 {
703         int ret;
704
705         if (!supported)
706                 return;
707
708         if (!info->close) {
709                 cout << "There is no function for info close" << endl;
710                 return;
711         }
712         ret = info->close((struct hw_common *)ir_dev);
713         EXPECT_EQ(ret, 0) << "Fail to close ir device (" << ret << ")";
714 }
715
716 /*
717  * Testcase for Rgb
718  */
719 TEST_F(RGBHalTest, InitP)
720 {
721         int ret;
722
723         if (!supported)
724                 return;
725
726         info = NULL;
727         ret = hw_get_info(LED_HARDWARE_DEVICE_ID,
728                         (const struct hw_info **)&info);
729         EXPECT_EQ(ret, 0) << "Fail to get hal for rgb (" << ret << ")";
730
731         if (!info->open) {
732                 cout << "There is no function for info open" << endl;
733                 return;
734         }
735         ret = info->open(info, LED_ID_NOTIFICATION, (struct hw_common**)&rgb_dev);
736         EXPECT_EQ(ret, 0) << "Fail to open rgb device (" << ret << ")";
737 }
738
739 TEST_F(RGBHalTest, SetStateP)
740 {
741         struct led_state state;
742         int ret;
743
744         if (!supported)
745                 return;
746
747         if (!rgb_dev->set_state) {
748                 cout << "There is no function for set_state" << endl;
749                 return;
750         }
751
752         state.type = LED_TYPE_BLINK;
753         state.color = 0xFFFFFF;
754         state.duty_on = 500;
755         state.duty_off = 500;
756         ret = rgb_dev->set_state(&state);
757         EXPECT_GE(ret, 0) << "Fail to set_state (" << ret << ")";
758 }
759
760 TEST_F(RGBHalTest, DeinitP)
761 {
762         int ret;
763
764         if (!supported)
765                 return;
766
767         if (!info->close) {
768                 cout << "There is no function for info close" << endl;
769                 return;
770         }
771         ret = info->close((struct hw_common *)rgb_dev);
772         EXPECT_GE(ret, 0) << "Fail to close rgb device (" << ret << ")";
773 }
774
775 /*
776  * Testcase for Thermal
777  */
778 TEST_F(THERMALHalTest, InitP)
779 {
780         int ret;
781
782         if (!supported)
783                 return;
784
785         info = NULL;
786         ret = hw_get_info(THERMAL_HARDWARE_DEVICE_ID,
787                                 (const struct hw_info **)&info);
788         if (ret < 0) {
789                 cout << "There is no device for thermal" << ret << endl;
790                 return;
791         } else {
792                 EXPECT_EQ(ret, 0) << "Fail to get hal for thermal (" << ret << ")";
793         }
794
795         if (!info || !info->open) {
796                 cout << "There is no function for info open" << endl;
797                 return;
798         }
799         ret = info->open(info, NULL, (struct hw_common**)&thermal_dev);
800         EXPECT_EQ(ret, 0) << "Fail to open thermal device (" << ret << ")";
801 }
802
803 TEST_F(THERMALHalTest, GetInfoP)
804 {
805         struct thermal_info thermal;
806         int ret;
807
808         if (!supported)
809                 return;
810
811         if (!thermal_dev || !thermal_dev->get_info) {
812                 cout << "There is no function for get_info" << endl;
813                 return;
814         }
815         ret = thermal_dev->get_info(DEVICE_THERMAL_AP, &thermal);
816         EXPECT_EQ(ret, 0) << "Fail to get_info (" << ret << ")";
817 }
818
819 static void thermal_updated_cb(struct thermal_info *info, void *data)
820 {
821
822 }
823
824 TEST_F(THERMALHalTest, RegisterChangedEventP)
825 {
826         int ret;
827
828         if (!supported)
829                 return;
830
831         if (!thermal_dev || !thermal_dev->register_changed_event) {
832                 cout << "There is no function for register_changed_event" << endl;
833                 return;
834         }
835         ret = thermal_dev->register_changed_event(thermal_updated_cb, NULL);
836         EXPECT_EQ(ret, 0) << "Fail to register_changed_event (" << ret << ")";
837 }
838
839 TEST_F(THERMALHalTest, UnregisterChangedEventP)
840 {
841         if (!supported)
842                 return;
843
844         if (!thermal_dev || !thermal_dev->unregister_changed_event) {
845                 cout << "There is no function for unregister_changed_event" << endl;
846                 return;
847         }
848         thermal_dev->unregister_changed_event(thermal_updated_cb);
849 }
850
851 TEST_F(THERMALHalTest, DeinitP)
852 {
853         int ret;
854
855         if (!supported)
856                 return;
857
858         if (!info || !info->close) {
859                 cout << "There is no function for info close" << endl;
860                 return;
861         }
862         ret = info->close((struct hw_common *)thermal_dev);
863         EXPECT_EQ(ret, 0) << "Fail to close thermal device (" << ret << ")";
864 }
865
866 /*
867  * Testcase for Touchscreen
868  */
869 TEST_F(TOUCHSCREENHalTest, InitP)
870 {
871         int ret;
872
873         info = NULL;
874         ret = hw_get_info(TOUCHSCREEN_HARDWARE_DEVICE_ID,
875                         (const struct hw_info **)&info);
876         if (ret < 0) {
877                 cout << "There is no device for touchscreen " << ret << endl;
878                 return;
879         } else {
880                 EXPECT_EQ(ret, 0) << "Fail to get hal for touchscreen (" << ret << ")";
881         }
882
883         if (!info || !info->open) {
884                 cout << "There is no function for info open" << endl;
885                 return;
886         }
887         ret = info->open(info, NULL, (struct hw_common**)&touchscreen_dev);
888         EXPECT_EQ(ret, 0) << "Fail to open touchscreen device (" << ret << ")";
889 }
890
891 TEST_F(TOUCHSCREENHalTest, SetStateP)
892 {
893         enum touchscreen_state state = TOUCHSCREEN_ON;
894         int ret;
895
896         if (!touchscreen_dev || !touchscreen_dev->set_state) {
897                 cout << "There is no function for set_state" << endl;
898                 return;
899         }
900         ret = touchscreen_dev->set_state(state);
901         EXPECT_EQ(ret, 0) << "Fail to set_state (" << ret << ")";
902 }
903
904 TEST_F(TOUCHSCREENHalTest, DeinitP)
905 {
906         int ret;
907
908         if (!info || !info->close) {
909                 cout << "There is no function for info close" << endl;
910                 return;
911         }
912         ret = info->close((struct hw_common *)touchscreen_dev);
913         EXPECT_EQ(ret, 0) << "Fail to close touchscreen device (" << ret << ")";
914 }
915
916 /*
917  * Testcase for Touchsensitivity
918  */
919 TEST_F(TOUCHSENSITIVITYHalTest, InitP)
920 {
921         int ret;
922
923         info = NULL;
924         ret = hw_get_info(TOUCHSENSITIVITY_HARDWARE_DEVICE_ID,
925                         (const struct hw_info **)&info);
926         if (ret < 0) {
927                 cout << "There is no device for touchsensitivity " << ret << endl;
928                 return;
929         } else {
930                 EXPECT_EQ(ret, 0) << "Fail to get hal for touchsensitivity (" << ret << ")";
931         }
932
933         if (!info || !info->open) {
934                 cout << "There is no function for info open" << endl;
935                 return;
936         }
937         ret = info->open(info, NULL, (struct hw_common**)&touchsensitivity_dev);
938         EXPECT_EQ(ret, 0) << "Fail to open touchsensitivity device (" << ret << ")";
939 }
940
941 TEST_F(TOUCHSENSITIVITYHalTest, GetStateP)
942 {
943         int ret, state;
944
945         if (!touchsensitivity_dev || !touchsensitivity_dev->glove_mode_get_state) {
946                 cout << "There is no function for glove_mode_get_state" << endl;
947                 return;
948         }
949         ret = touchsensitivity_dev->glove_mode_get_state(&state);
950         EXPECT_EQ(ret, 0) << "Fail to get glove state (" << ret << ")";
951 }
952
953 TEST_F(TOUCHSENSITIVITYHalTest, SetStateP)
954 {
955         int ret, state = TOUCHSENSITIVITY_GLOVE_MODE_ON;
956
957         if (!touchsensitivity_dev || !touchsensitivity_dev->glove_mode_set_state) {
958                 cout << "There is no function for glove_mode_set_state" << endl;
959                 return;
960         }
961         ret = touchsensitivity_dev->glove_mode_set_state(state);
962         EXPECT_EQ(ret, 0) << "Fail to set glove mode (" << ret << ")";
963 }
964
965 TEST_F(TOUCHSENSITIVITYHalTest, DeinitP)
966 {
967         int ret;
968
969         if (!info || !info->close) {
970                 cout << "There is no function for info close" << endl;
971                 return;
972         }
973         ret = info->close((struct hw_common *)touchsensitivity_dev);
974         EXPECT_EQ(ret, 0) << "Fail to close touchscreen device (" << ret << ")";
975 }
976
977 /*
978  * Testcase for Bezel
979  */
980 TEST_F(BEZELHalTest, InitP)
981 {
982         int ret;
983
984         if (!supported)
985                 return;
986
987         info = NULL;
988         ret = hw_get_info(BEZEL_HARDWARE_DEVICE_ID,
989                                 (const struct hw_info **)&info);
990         if (ret < 0) {
991                 cout << "There is no device for bezel" << ret << endl;
992                 return;
993         } else {
994                 EXPECT_EQ(ret, 0) << "Fail to get hal for bezel (" << ret << ")";
995         }
996
997         if (!info || !info->open) {
998                 cout << "There is no function for info open" << endl;
999                 return;
1000         }
1001         ret = info->open(info, NULL, (struct hw_common**)&bezel_dev);
1002         EXPECT_EQ(ret, 0) << "Fail to open bezel device (" << ret << ")";
1003 }
1004
1005 TEST_F(BEZELHalTest, GetStateP)
1006 {
1007         enum bezel_state state;
1008         int ret;
1009
1010         if (!supported)
1011                 return;
1012
1013         if (!bezel_dev || !bezel_dev->get_state) {
1014                 cout << "There is no function for get_info" << endl;
1015                 return;
1016         }
1017         ret = bezel_dev->get_state(&state);
1018         EXPECT_EQ(ret, 0) << "Fail to get_state (" << ret << ")";
1019 }
1020
1021 TEST_F(BEZELHalTest, SetStateP)
1022 {
1023         enum bezel_state state = BEZEL_TURNON;
1024         int ret;
1025
1026         if (!supported)
1027                 return;
1028
1029         if (!bezel_dev || !bezel_dev->set_state) {
1030                 cout << "There is no function for set_state" << endl;
1031                 return;
1032         }
1033         ret = bezel_dev->set_state(state);
1034         EXPECT_EQ(ret, 0) << "Fail to get_state (" << ret << ")";
1035 }
1036
1037 TEST_F(BEZELHalTest, DeinitP)
1038 {
1039         int ret;
1040
1041         if (!supported)
1042                 return;
1043
1044         if (!info || !info->close) {
1045                 cout << "There is no function for info close" << endl;
1046                 return;
1047         }
1048         ret = info->close((struct hw_common *)bezel_dev);
1049         EXPECT_EQ(ret, 0) << "Fail to close bezel device (" << ret << ")";
1050 }
1051
1052 /*
1053  * Testcase for Client
1054  */
1055 TEST_F(USBCLIENTHalTest, InitP)
1056 {
1057         int ret;
1058
1059         if (!supported)
1060                 return;
1061
1062         info = NULL;
1063         ret = hw_get_info(USB_CLIENT_HARDWARE_DEVICE_ID,
1064                         (const struct hw_info **)&info);
1065         if (ret < 0) {
1066                 cout << "There is no device for usb client" << ret << endl;
1067                 return;
1068         } else {
1069                 EXPECT_EQ(ret, 0) << "Fail to get hal for usb client (" << ret << ")";
1070         }
1071         if (!info || !info->open) {
1072                 cout << "There is no function for info open" << endl;
1073                 return;
1074         }
1075         ret = info->open(info, NULL, (struct hw_common**)&client_dev);
1076         EXPECT_EQ(ret, 0) << "Fail to open usb client device (" << ret << ")";
1077         EXPECT_NE(client_dev, nullptr) << "Fail to get usb client device structure";
1078
1079         ret = hw_get_info(USB_GADGET_DEVICE_ID,
1080                         (const struct hw_info **)&info);
1081         if (ret < 0) {
1082                 cout << "There is no device for usb gadget" << ret << endl;
1083                 return;
1084         } else {
1085                 EXPECT_EQ(ret, 0) << "Fail to get hal for usb gadget (" << ret << ")";
1086         }
1087
1088         if (!info || !info->open) {
1089                 cout << "There is no function for info open" << endl;
1090                 return;
1091         }
1092         ret = info->open(info, NULL, (struct hw_common**)&gadget_translator);
1093         EXPECT_EQ(ret, 0) << "Fail to open usb gadget device (" << ret << ")";
1094 }
1095
1096 TEST_F(USBCLIENTHalTest, EnableP)
1097 {
1098         int ret;
1099
1100         if (!supported)
1101                 return;
1102
1103         if (!client_dev || !client_dev->enable) {
1104                 cout << "There is no function for enable" << endl;
1105                 return;
1106         }
1107         ret = client_dev->enable(client_dev);
1108         EXPECT_EQ(ret, 0) << "Fail to enable (" << ret << ")";
1109 }
1110
1111 TEST_F(USBCLIENTHalTest, ReConfigureGadgetP)
1112 {
1113         int ret;
1114
1115         if (!supported)
1116                 return;
1117
1118         if (!gadget_translator || !gadget_translator->id_to_gadget) {
1119                 cout << "There is no function for id_to_gadget" << endl;
1120                 return;
1121         }
1122         gadget_id.function_mask = 7;
1123         ret = gadget_translator->id_to_gadget(&gadget_id, &gadget_dev);
1124         EXPECT_EQ(ret, 0) << "Fail to id_to_gadget (" << ret << ")";
1125
1126         if (!client_dev || !client_dev->disable) {
1127                 cout << "There is no function for disable" << endl;
1128                 return;
1129         }
1130         ret = client_dev->disable(client_dev);
1131         EXPECT_EQ(ret, 0) << "Fail to disable (" << ret << ")";
1132
1133         if (!client_dev || !client_dev->reconfigure_gadget) {
1134                 cout << "There is no function for reconfigure_gadget" << endl;
1135                 return;
1136         }
1137         ret = client_dev->reconfigure_gadget(client_dev, gadget_dev);
1138         EXPECT_EQ(ret, 0) << "Fail to reconfigure_gadget (" << ret << ")";
1139 }
1140
1141 TEST_F(USBCLIENTHalTest, DisableP)
1142 {
1143         int ret;
1144
1145         if (!supported)
1146                 return;
1147
1148         if (!client_dev || !client_dev->disable) {
1149                 cout << "There is no function for disable" << endl;
1150                 return;
1151         }
1152         ret = client_dev->disable(client_dev);
1153         EXPECT_EQ(ret, 0) << "Fail to disable (" << ret << ")";
1154 }
1155
1156 TEST_F(USBCLIENTHalTest, DeinitP)
1157 {
1158         int ret;
1159
1160         if (!supported)
1161                 return;
1162
1163         if (!info || !info->close) {
1164                 cout << "There is no function for info close" << endl;
1165                 return;
1166         }
1167         ret = info->close((struct hw_common *)client_dev);
1168         EXPECT_EQ(ret, 0) << "Fail to close usb client device (" << ret << ")";
1169 }
1170
1171 /*
1172  * Testcase for Gadget
1173  */
1174 TEST_F(USBGADGETHalTest, InitP)
1175 {
1176         int ret;
1177
1178         info = NULL;
1179         ret = hw_get_info(USB_GADGET_DEVICE_ID,
1180                         (const struct hw_info **)&info);
1181         if (ret < 0) {
1182                 cout << "There is no device for usb gadget" << ret << endl;
1183                 return;
1184         } else {
1185                 EXPECT_EQ(ret, 0) << "Fail to get hal for usb gadget (" << ret << ")";
1186         }
1187
1188         if (!info || !info->open) {
1189                 cout << "There is no function for info open" << endl;
1190                 return;
1191         }
1192         ret = info->open(info, NULL, (struct hw_common**)&gadget_translator);
1193         EXPECT_EQ(ret, 0) << "Fail to open usb gadget device (" << ret << ")";
1194 }
1195
1196 TEST_F(USBGADGETHalTest, IdToGadget)
1197 {
1198         struct usb_gadget_id gadget_id;
1199         int ret;
1200
1201         if (!gadget_translator || !gadget_translator->id_to_gadget) {
1202                 cout << "There is no function for id_to_gadget" << endl;
1203                 return;
1204         }
1205
1206         gadget_id.function_mask = 7;
1207         ret = gadget_translator->id_to_gadget(&gadget_id, &gadget_dev);
1208         EXPECT_EQ(ret, 0) << "Fail to id_to_gadget (" << ret << ")";
1209 }
1210
1211 TEST_F(USBGADGETHalTest, CleanUpGadget)
1212 {
1213         if (!gadget_translator || !gadget_translator->cleanup_gadget) {
1214                 cout << "There is no function for cleanup_gadget" << endl;
1215                 return;
1216         }
1217         gadget_translator->cleanup_gadget(gadget_dev);
1218 }
1219
1220 TEST_F(USBGADGETHalTest, DeinitP)
1221 {
1222         int ret;
1223
1224         if (!info || !info->close) {
1225                 cout << "There is no function for info close" << endl;
1226                 return;
1227         }
1228         ret = info->close((struct hw_common *)gadget_translator);
1229         EXPECT_EQ(ret, 0) << "Fail to close usb gadget device (" << ret << ")";
1230 }
1231
1232 int main(int argc, char **argv)
1233 {
1234         int ret = -1;
1235
1236         try {
1237                 testing::InitGoogleTest(&argc, argv);
1238         } catch(...) {
1239                 std::cout << "Exception occurred." << std::endl;
1240         }
1241
1242         try {
1243                 ret = RUN_ALL_TESTS();
1244         } catch (const ::testing::internal::GoogleTestFailureException& e) {
1245                 ret = -1;
1246                 std::cout << "GoogleTestFailureException was thrown:" << e.what() << std::endl;
1247         }
1248
1249         return ret;
1250 }