Add cpp files for HAL test
[platform/core/system/libdevice-node.git] / unittest / gtest_hal_rgb.cpp
1
2 #include <iostream>
3 #include <gtest/gtest.h>
4 #include <system_info.h>
5 #include "hw/led.h"
6 #include "unittest.h"
7
8 using namespace std;
9
10 /*
11  * main class
12  */
13 struct hw_info *info;
14 struct led_device *rgb_dev;
15 static bool need_featurecheck = true;
16
17 class RGBHalTest : 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_LED, &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(RGBHalTest, InitP)
41 {
42         int ret;
43
44         if (!supported)
45                 return;
46
47         ret = hw_get_info(LED_HARDWARE_DEVICE_ID,
48                         (const struct hw_info **)&info);
49         EXPECT_EQ(ret, 0) << "Fail to get hal for rgb (" << ret << ")";
50
51         if (!info->open) {
52                 cout << "There is no function for info open" << endl;
53                 return;
54         }
55         ret = info->open(info, LED_ID_NOTIFICATION, (struct hw_common**)&rgb_dev);
56         EXPECT_EQ(ret, 0) << "Fail to open rgb device (" << ret << ")";
57 }
58
59 TEST_F(RGBHalTest, SetStateP)
60 {
61         struct led_state state;
62         int ret;
63
64         if (!supported)
65                 return;
66
67         if (!rgb_dev->set_state) {
68                 cout << "There is no function for set_state" << endl;
69                 return;
70         }
71
72         state.type = LED_TYPE_BLINK;
73         state.color = 0xFFFFFF;
74         state.duty_on = 500;
75         state.duty_off = 500;
76         ret = rgb_dev->set_state(&state);
77         EXPECT_GE(ret, 0) << "Fail to set_state (" << ret << ")";
78 }
79
80 TEST_F(RGBHalTest, DeinitP)
81 {
82         int ret;
83
84         if (!supported)
85                 return;
86
87         if (!info->close) {
88                 cout << "There is no function for info close" << endl;
89                 return;
90         }
91         ret = info->close((struct hw_common *)rgb_dev);
92         EXPECT_GE(ret, 0) << "Fail to close rgb device (" << ret << ")";
93 }
94
95 int main(int argc, char **argv)
96 {
97         testing::InitGoogleTest(&argc, argv);
98
99         return RUN_ALL_TESTS();
100 }