summaryrefslogtreecommitdiff
path: root/unittest/gtest_hal_usb_gadget.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'unittest/gtest_hal_usb_gadget.cpp')
-rwxr-xr-xunittest/gtest_hal_usb_gadget.cpp98
1 files changed, 98 insertions, 0 deletions
diff --git a/unittest/gtest_hal_usb_gadget.cpp b/unittest/gtest_hal_usb_gadget.cpp
new file mode 100755
index 0000000..4b567c2
--- /dev/null
+++ b/unittest/gtest_hal_usb_gadget.cpp
@@ -0,0 +1,98 @@
+
+#include <iostream>
+#include <gtest/gtest.h>
+#include <system_info.h>
+#include "hw/usb_gadget.h"
+#include "unittest.h"
+
+using namespace std;
+
+/*
+ * main class
+ */
+struct hw_info *info;
+struct usb_gadget *gadget_dev;
+struct usb_gadget_translator *gadget_translator;
+
+class USBGADGETHalTest : public testing::Test
+{
+ public:
+ virtual void SetUp()
+ {
+
+ }
+
+ virtual void TearDown()
+ {
+
+ }
+};
+
+/*
+ * testcase
+ */
+TEST_F(USBGADGETHalTest, InitP)
+{
+ int ret;
+
+ 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(USBGADGETHalTest, IdToGadget)
+{
+ struct usb_gadget_id gadget_id;
+ int ret;
+ char str[256];
+
+ if (!gadget_translator || !gadget_translator->id_to_gadget) {
+ cout << "There is no function for id_to_gadget" << endl;
+ return;
+ }
+ //dummy code to prevent error for not used function
+ snprintf(str, 255, "%s,", _available_funcs[2]->name);
+ 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 << ")";
+}
+
+TEST_F(USBGADGETHalTest, CleanUpGadget)
+{
+ if (!gadget_translator || !gadget_translator->cleanup_gadget) {
+ cout << "There is no function for cleanup_gadget" << endl;
+ return;
+ }
+ gadget_translator->cleanup_gadget(gadget_dev);
+}
+
+TEST_F(USBGADGETHalTest, DeinitP)
+{
+ int ret;
+
+ if (!info || !info->close) {
+ cout << "There is no function for info close" << endl;
+ return;
+ }
+ ret = info->close((struct hw_common *)gadget_translator);
+ EXPECT_EQ(ret, 0) << "Fail to close usb gadget device (" << ret << ")";
+}
+
+int main(int argc, char **argv)
+{
+ testing::InitGoogleTest(&argc, argv);
+
+ return RUN_ALL_TESTS();
+}