Add cpp files for HAL test
[platform/core/system/libdevice-node.git] / unittest / gtest_hal_usb_gadget.cpp
1
2 #include <iostream>
3 #include <gtest/gtest.h>
4 #include <system_info.h>
5 #include "hw/usb_gadget.h"
6 #include "unittest.h"
7
8 using namespace std;
9
10 /*
11  * main class
12  */
13 struct hw_info *info;
14 struct usb_gadget *gadget_dev;
15 struct usb_gadget_translator *gadget_translator;
16
17 class USBGADGETHalTest : public testing::Test
18 {
19         public:
20                 virtual void SetUp()
21                 {
22
23                 }
24
25                 virtual void TearDown()
26                 {
27
28                 }
29 };
30
31 /*
32  * testcase
33  */
34 TEST_F(USBGADGETHalTest, InitP)
35 {
36         int ret;
37
38         ret = hw_get_info(USB_GADGET_DEVICE_ID,
39                         (const struct hw_info **)&info);
40         if (ret < 0) {
41                 cout << "There is no device for usb gadget" << ret << endl;
42                 return;
43         } else {
44                 EXPECT_EQ(ret, 0) << "Fail to get hal for usb gadget (" << ret << ")";
45         }
46
47         if (!info || !info->open) {
48                 cout << "There is no function for info open" << endl;
49                 return;
50         }
51         ret = info->open(info, NULL, (struct hw_common**)&gadget_translator);
52         EXPECT_EQ(ret, 0) << "Fail to open usb gadget device (" << ret << ")";
53 }
54
55 TEST_F(USBGADGETHalTest, IdToGadget)
56 {
57         struct usb_gadget_id gadget_id;
58         int ret;
59         char str[256];
60
61         if (!gadget_translator || !gadget_translator->id_to_gadget) {
62                 cout << "There is no function for id_to_gadget" << endl;
63                 return;
64         }
65         //dummy code to prevent error for not used function
66         snprintf(str, 255, "%s,", _available_funcs[2]->name);
67         gadget_id.function_mask = 7;
68         ret = gadget_translator->id_to_gadget(&gadget_id, &gadget_dev);
69         EXPECT_EQ(ret, 0) << "Fail to id_to_gadget (" << ret << ")";
70 }
71
72 TEST_F(USBGADGETHalTest, CleanUpGadget)
73 {
74         if (!gadget_translator || !gadget_translator->cleanup_gadget) {
75                 cout << "There is no function for cleanup_gadget" << endl;
76                 return;
77         }
78         gadget_translator->cleanup_gadget(gadget_dev);
79 }
80
81 TEST_F(USBGADGETHalTest, DeinitP)
82 {
83         int ret;
84
85         if (!info || !info->close) {
86                 cout << "There is no function for info close" << endl;
87                 return;
88         }
89         ret = info->close((struct hw_common *)gadget_translator);
90         EXPECT_EQ(ret, 0) << "Fail to close usb gadget device (" << ret << ")";
91 }
92
93 int main(int argc, char **argv)
94 {
95         testing::InitGoogleTest(&argc, argv);
96
97         return RUN_ALL_TESTS();
98 }