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