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