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