Add cpp files for HAL test
[platform/core/system/libdevice-node.git] / unittest / gtest_hal_ir.cpp
1
2 #include <iostream>
3 #include <gtest/gtest.h>
4 #include <system_info.h>
5 #include "hw/ir.h"
6 #include "unittest.h"
7
8 using namespace std;
9
10 /*
11  * main class
12  */
13 struct hw_info *info;
14 struct ir_device *ir_dev;
15 static bool need_featurecheck = true;
16
17 class IRHalTest : public testing::Test
18 {
19         public:
20                 virtual void SetUp()
21                 {
22                         int ret;
23
24                         if (need_featurecheck) {
25                                 ret = system_info_get_platform_bool(FEATURE_IR, &supported);
26                                 EXPECT_EQ(SYSTEM_INFO_ERROR_NONE, ret) << "system_info_get_platform_bool failed";
27                                 need_featurecheck = false;
28                         }
29                 }
30
31                 virtual void TearDown()
32                 {
33
34                 }
35 };
36
37 /*
38  * testcase
39  */
40 TEST_F(IRHalTest, InitP)
41 {
42         int ret;
43
44         if (!supported)
45                 return;
46
47         ret = hw_get_info(IR_HARDWARE_DEVICE_ID,
48                         (const struct hw_info **)&info);
49         EXPECT_EQ(ret, 0) << "Fail to get hal for ir (" << ret << ")";
50
51         if (!info->open) {
52                 cout << "There is no function for info open" << endl;
53                 return;
54         }
55         ret = info->open(info, NULL, (struct hw_common**)&ir_dev);
56         EXPECT_EQ(ret, 0) << "Fail to open ir device (" << ret << ")";
57 }
58
59 TEST_F(IRHalTest, IsAvailableP)
60 {
61         int ret;
62         bool val;
63
64         if (!supported)
65                 return;
66
67         if (!ir_dev->is_available) {
68                 cout << "There is no function for is_available" << endl;
69                 return;
70         }
71         ret = ir_dev->is_available(&val);
72         EXPECT_EQ(ret, 0) << "Fail to is_available (" << ret << ")";
73 }
74
75 TEST_F(IRHalTest, TransmitP)
76 {
77         int ret;
78         int pattern[5] = {100, 200, 300, 400, 500};
79
80         if (!supported)
81                 return;
82
83         if (!ir_dev->transmit) {
84                 cout << "There is no function for transmit" << endl;
85                 return;
86         }
87         ret = ir_dev->transmit(pattern, 5);
88         EXPECT_EQ(ret, 0) << "Fail to transmit (" << ret << ")";
89 }
90
91 TEST_F(IRHalTest, DeinitP)
92 {
93         int ret;
94
95         if (!supported)
96                 return;
97
98         if (!info->close) {
99                 cout << "There is no function for info close" << endl;
100                 return;
101         }
102         ret = info->close((struct hw_common *)ir_dev);
103         EXPECT_EQ(ret, 0) << "Fail to close ir device (" << ret << ")";
104 }
105
106 int main(int argc, char **argv)
107 {
108         testing::InitGoogleTest(&argc, argv);
109
110         return RUN_ALL_TESTS();
111 }