diff options
Diffstat (limited to 'unittest/gtest_hal_usb_client.cpp')
-rwxr-xr-x | unittest/gtest_hal_usb_client.cpp | 236 |
1 files changed, 0 insertions, 236 deletions
diff --git a/unittest/gtest_hal_usb_client.cpp b/unittest/gtest_hal_usb_client.cpp deleted file mode 100755 index 597823c..0000000 --- a/unittest/gtest_hal_usb_client.cpp +++ /dev/null @@ -1,236 +0,0 @@ - -#include <iostream> -#include <gtest/gtest.h> -#include <system_info.h> -#include "hw/usb_client.h" -#include "unittest.h" - -using namespace std; - -/* - * main class - */ -struct hw_info *info; -struct usb_client *client_dev; -struct usb_gadget *gadget_dev; -struct usb_gadget_id gadget_id; -struct usb_gadget_translator *gadget_translator; -static bool need_modelcheck = true; - -#define MODEL_NAME "http://tizen.org/system/model_name" - -class USBCLIENTHalTest : public testing::Test -{ - public: - virtual void SetUp() - { - int ret; - char *model_name = NULL; - - if (need_modelcheck) { - ret = system_info_get_platform_string(MODEL_NAME, &model_name); - EXPECT_EQ(SYSTEM_INFO_ERROR_NONE, ret) << "system_info_get_platform_bool failed"; - - if (!strncmp(model_name, "artik", 5)) { - supported = true; - } else { - supported = false; - } - cout << "supported " << supported << endl; - need_modelcheck = false; - free(model_name); - } - } - - virtual void TearDown() - { - - } -}; - -/* - * testcase - */ -TEST_F(USBCLIENTHalTest, InitP) -{ - int ret; - - if (!supported) - return; - - ret = hw_get_info(USB_CLIENT_HARDWARE_DEVICE_ID, - (const struct hw_info **)&info); - if (ret < 0) { - cout << "There is no device for usb client" << ret << endl; - return; - } else { - EXPECT_EQ(ret, 0) << "Fail to get hal for usb client (" << ret << ")"; - } - if (!info || !info->open) { - cout << "There is no function for info open" << endl; - return; - } - ret = info->open(info, NULL, (struct hw_common**)&client_dev); - EXPECT_EQ(ret, 0) << "Fail to open usb client device (" << ret << ")"; - EXPECT_NE(client_dev, nullptr) << "Fail to get usb client device structure"; - - ret = hw_get_info(USB_GADGET_DEVICE_ID, - (const struct hw_info **)&info); - if (ret < 0) { - cout << "There is no device for usb gadget" << ret << endl; - return; - } else { - EXPECT_EQ(ret, 0) << "Fail to get hal for usb gadget (" << ret << ")"; - } - - if (!info || !info->open) { - cout << "There is no function for info open" << endl; - return; - } - ret = info->open(info, NULL, (struct hw_common**)&gadget_translator); - EXPECT_EQ(ret, 0) << "Fail to open usb gadget device (" << ret << ")"; -} - -TEST_F(USBCLIENTHalTest, EnableP) -{ - int ret; - char str[256]; - - if (!supported) - return; - - //dummy code to prevent error for not used function - snprintf(str, 255, "%s,", _available_funcs[2]->name); - - if (!client_dev || !client_dev->enable) { - cout << "There is no function for enable" << endl; - return; - } - ret = client_dev->enable(client_dev); - EXPECT_EQ(ret, 0) << "Fail to enable (" << ret << ")"; -} - -TEST_F(USBCLIENTHalTest, ReConfigureGadgetP) -{ - int ret; - - if (!supported) - return; - - if (!gadget_translator || !gadget_translator->id_to_gadget) { - cout << "There is no function for id_to_gadget" << endl; - return; - } - gadget_id.function_mask = 7; - ret = gadget_translator->id_to_gadget(&gadget_id, &gadget_dev); - EXPECT_EQ(ret, 0) << "Fail to id_to_gadget (" << ret << ")"; - - if (!client_dev || !client_dev->disable) { - cout << "There is no function for disable" << endl; - return; - } - ret = client_dev->disable(client_dev); - EXPECT_EQ(ret, 0) << "Fail to disable (" << ret << ")"; - - if (!client_dev || !client_dev->reconfigure_gadget) { - cout << "There is no function for reconfigure_gadget" << endl; - return; - } - ret = client_dev->reconfigure_gadget(client_dev, gadget_dev); - EXPECT_EQ(ret, 0) << "Fail to reconfigure_gadget (" << ret << ")"; -} - -TEST_F(USBCLIENTHalTest, IsGadgetSupportedP) -{ - bool flag; - - if (!supported) - return; - - if (!client_dev || !client_dev->is_gadget_supported) { - cout << "There is no function for is_gadget_supported" << endl; - return; - } - flag = client_dev->is_gadget_supported(client_dev, gadget_dev); - EXPECT_EQ(flag, true) << "Fail to is_gadget_supported (" << flag << ")"; -} - -TEST_F(USBCLIENTHalTest, IsFunctionSupportedP) -{ - bool flag; - - if (!supported) - return; - - if (!client_dev || !client_dev->is_function_supported) { - cout << "There is no function for is_function_supported" << endl; - return; - } - flag = client_dev->is_function_supported(client_dev, *gadget_dev->funcs); - EXPECT_EQ(flag, true) << "Fail to is_function_supported (" << flag << ")"; -} - -TEST_F(USBCLIENTHalTest, GetCurrentGadgetP) -{ - int ret; - - if (!supported) - return; - - if (!client_dev || !client_dev->get_current_gadget) { - cout << "There is no function for get_current_gadget" << endl; - return; - } - ret = client_dev->get_current_gadget(client_dev, &gadget_dev); - EXPECT_EQ(ret, 0) << "Fail to get_current_gadget (" << ret << ")"; -} - -TEST_F(USBCLIENTHalTest, DisableP) -{ - int ret; - - if (!supported) - return; - - if (!client_dev || !client_dev->disable) { - cout << "There is no function for disable" << endl; - return; - } - ret = client_dev->disable(client_dev); - EXPECT_EQ(ret, 0) << "Fail to disable (" << ret << ")"; -} - -TEST_F(USBCLIENTHalTest, FreeGadgetP) -{ - if (!supported) - return; - - if (!client_dev || !client_dev->free_gadget) { - cout << "There is no function for free_gadget" << endl; - return; - } - client_dev->free_gadget(gadget_dev); -} - -TEST_F(USBCLIENTHalTest, DeinitP) -{ - int ret; - - if (!supported) - return; - - if (!info || !info->close) { - cout << "There is no function for info close" << endl; - return; - } - ret = info->close((struct hw_common *)client_dev); - EXPECT_EQ(ret, 0) << "Fail to close usb client device (" << ret << ")"; -} - -int main(int argc, char **argv) -{ - testing::InitGoogleTest(&argc, argv); - - return RUN_ALL_TESTS(); -} - |