3 #include <gtest/gtest.h>
4 #include <system_info.h>
5 #include "hw/usb_client.h"
14 struct usb_client *client_dev;
15 struct usb_gadget *gadget_dev;
16 struct usb_gadget_id gadget_id;
17 struct usb_gadget_translator *gadget_translator;
18 static bool need_modelcheck = true;
20 #define MODEL_NAME "http://tizen.org/system/model_name"
22 class USBCLIENTHalTest : public testing::Test
28 char *model_name = NULL;
30 if (need_modelcheck) {
31 ret = system_info_get_platform_string(MODEL_NAME, &model_name);
32 EXPECT_EQ(SYSTEM_INFO_ERROR_NONE, ret) << "system_info_get_platform_bool failed";
34 if (!strncmp(model_name, "artik", 5)) {
39 cout << "supported " << supported << endl;
40 need_modelcheck = false;
44 virtual void TearDown()
53 TEST_F(USBCLIENTHalTest, InitP)
60 ret = hw_get_info(USB_CLIENT_HARDWARE_DEVICE_ID,
61 (const struct hw_info **)&info);
63 cout << "There is no device for usb client" << ret << endl;
66 EXPECT_EQ(ret, 0) << "Fail to get hal for usb client (" << ret << ")";
68 if (!info || !info->open) {
69 cout << "There is no function for info open" << endl;
72 ret = info->open(info, NULL, (struct hw_common**)&client_dev);
73 EXPECT_EQ(ret, 0) << "Fail to open usb client device (" << ret << ")";
74 EXPECT_NE(client_dev, nullptr) << "Fail to get usb client device structure";
76 ret = hw_get_info(USB_GADGET_DEVICE_ID,
77 (const struct hw_info **)&info);
79 cout << "There is no device for usb gadget" << ret << endl;
82 EXPECT_EQ(ret, 0) << "Fail to get hal for usb gadget (" << ret << ")";
85 if (!info || !info->open) {
86 cout << "There is no function for info open" << endl;
89 ret = info->open(info, NULL, (struct hw_common**)&gadget_translator);
90 EXPECT_EQ(ret, 0) << "Fail to open usb gadget device (" << ret << ")";
93 TEST_F(USBCLIENTHalTest, EnableP)
101 //dummy code to prevent error for not used function
102 snprintf(str, 255, "%s,", _available_funcs[2]->name);
104 if (!client_dev || !client_dev->enable) {
105 cout << "There is no function for enable" << endl;
108 ret = client_dev->enable(client_dev);
109 EXPECT_EQ(ret, 0) << "Fail to enable (" << ret << ")";
112 TEST_F(USBCLIENTHalTest, ReConfigureGadgetP)
119 if (!gadget_translator || !gadget_translator->id_to_gadget) {
120 cout << "There is no function for id_to_gadget" << endl;
123 gadget_id.function_mask = 7;
124 ret = gadget_translator->id_to_gadget(&gadget_id, &gadget_dev);
125 EXPECT_EQ(ret, 0) << "Fail to id_to_gadget (" << ret << ")";
127 if (!client_dev || !client_dev->disable) {
128 cout << "There is no function for disable" << endl;
131 ret = client_dev->disable(client_dev);
132 EXPECT_EQ(ret, 0) << "Fail to disable (" << ret << ")";
134 if (!client_dev || !client_dev->reconfigure_gadget) {
135 cout << "There is no function for reconfigure_gadget" << endl;
138 ret = client_dev->reconfigure_gadget(client_dev, gadget_dev);
139 EXPECT_EQ(ret, 0) << "Fail to reconfigure_gadget (" << ret << ")";
142 TEST_F(USBCLIENTHalTest, IsGadgetSupportedP)
149 if (!client_dev || !client_dev->is_gadget_supported) {
150 cout << "There is no function for is_gadget_supported" << endl;
153 flag = client_dev->is_gadget_supported(client_dev, gadget_dev);
154 EXPECT_EQ(flag, true) << "Fail to is_gadget_supported (" << flag << ")";
157 TEST_F(USBCLIENTHalTest, IsFunctionSupportedP)
164 if (!client_dev || !client_dev->is_function_supported) {
165 cout << "There is no function for is_function_supported" << endl;
168 flag = client_dev->is_function_supported(client_dev, *gadget_dev->funcs);
169 EXPECT_EQ(flag, true) << "Fail to is_function_supported (" << flag << ")";
172 TEST_F(USBCLIENTHalTest, GetCurrentGadgetP)
179 if (!client_dev || !client_dev->get_current_gadget) {
180 cout << "There is no function for get_current_gadget" << endl;
183 ret = client_dev->get_current_gadget(client_dev, &gadget_dev);
184 EXPECT_EQ(ret, 0) << "Fail to get_current_gadget (" << ret << ")";
187 TEST_F(USBCLIENTHalTest, DisableP)
194 if (!client_dev || !client_dev->disable) {
195 cout << "There is no function for disable" << endl;
198 ret = client_dev->disable(client_dev);
199 EXPECT_EQ(ret, 0) << "Fail to disable (" << ret << ")";
202 TEST_F(USBCLIENTHalTest, DeinitP)
209 if (!info || !info->close) {
210 cout << "There is no function for info close" << endl;
213 ret = info->close((struct hw_common *)client_dev);
214 EXPECT_EQ(ret, 0) << "Fail to close usb client device (" << ret << ")";
217 int main(int argc, char **argv)
219 testing::InitGoogleTest(&argc, argv);
221 return RUN_ALL_TESTS();