!779 【xts_hats】【master】HDI接口requestTest用例整改

Merge pull request !779 from 李晓枫/hats_request
This commit is contained in:
openharmony_ci 2023-08-03 07:01:50 +00:00 committed by Gitee
commit 2ba14da672
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
3 changed files with 251 additions and 173 deletions

View File

@ -20,6 +20,7 @@ ohos_moduletest_suite("HatsHdfUsbRequestTest") {
module_out_path = module_output_path
sources = [
"../UsbSubscriberTest/UsbSubscriberTest.cpp",
"./common/usbd_interface_test.cpp",
"./common/usbd_request_test.cpp",
]
configs = [ ":hdf_usb" ]

View File

@ -0,0 +1,250 @@
/*
* Copyright (c) 2023 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <gtest/gtest.h>
#include <iostream>
#include "UsbSubscriberTest.h"
#include "hdf_log.h"
#include "usbd_request_test.h"
#include "v1_0/iusb_interface.h"
#include "v1_0/usb_types.h"
using OHOS::HDI::Usb::V1_0::UsbDev;
namespace {
const uint8_t INDEX_0 = 0;
const uint8_t INDEX_1 = 1;
const uint8_t INDEX_INVALID = 255;
const uint8_t BUS_NUM_INVALID = 255;
const uint8_t DEV_ADDR_INVALID = 255;
const uint8_t INTERFACEID_OK = 1;
const uint8_t INTERFACEID_INVALID = 255;
const int SLEEP_TIME = 3;
class UsbdInterfaceTest : public testing::Test {
public:
static void SetUpTestCase();
static void TearDownTestCase();
void SetUp();
void TearDown();
static UsbDev dev_;
};
UsbDev UsbdInterfaceTest::dev_ = {0, 0};
using namespace testing::ext;
using namespace OHOS;
using namespace OHOS::USB;
using namespace std;
using namespace OHOS::HDI::Usb::V1_0;
sptr<IUsbInterface> g_usbInterface = nullptr;
void UsbdInterfaceTest::SetUpTestCase(void)
{
g_usbInterface = IUsbInterface::Get();
if (g_usbInterface == nullptr) {
HDF_LOGE("%{public}s:IUsbInterface::Get() failed.", __func__);
exit(0);
}
auto ret = g_usbInterface->SetPortRole(1, 1, 1);
sleep(SLEEP_TIME);
HDF_LOGI("UsbdInterfaceTest::[Device] %{public}d SetPortRole=%{public}d", __LINE__, ret);
ASSERT_EQ(0, ret);
if (ret != 0) {
exit(0);
}
sptr<UsbSubscriberTest> subscriber = new UsbSubscriberTest();
if (g_usbInterface->BindUsbdSubscriber(subscriber) != HDF_SUCCESS) {
HDF_LOGE("%{public}s: bind usbd subscriber failed", __func__);
exit(0);
}
std::cout << "please connect device, press enter to continue" << std::endl;
int c;
while ((c = getchar()) != '\n' && c != EOF) {}
dev_ = {subscriber->busNum_, subscriber->devAddr_};
ret = g_usbInterface->OpenDevice(dev_);
ASSERT_EQ(0, ret);
HDF_LOGI("UsbdInterfaceTest:: %{public}d OpenDevice=%{public}d", __LINE__, ret);
ret = g_usbInterface->ClaimInterface(dev_, 1, 1);
ASSERT_EQ(0, ret);
}
void UsbdInterfaceTest::TearDownTestCase(void)
{
sptr<UsbSubscriberTest> subscriber = new UsbSubscriberTest();
if (g_usbInterface->BindUsbdSubscriber(subscriber) != HDF_SUCCESS) {
HDF_LOGE("%{public}s: bind usbd subscriber failed", __func__);
exit(0);
}
dev_ = {subscriber->busNum_, subscriber->devAddr_};
auto ret = g_usbInterface->CloseDevice(dev_);
HDF_LOGI("UsbdInterfaceTest:: %{public}d Close=%{public}d", __LINE__, ret);
ASSERT_EQ(0, ret);
}
void UsbdInterfaceTest::SetUp(void) {}
void UsbdInterfaceTest::TearDown(void) {}
/**
* @tc.name: SUB_USB_HDI_1170
* @tc.desc: Test functions to SetInterface
* @tc.desc: int32_t SetInterface(const UsbDev &dev, uint8_t interfaceId, uint8_t altIndex);
* @tc.desc: Positive test: parameters correctly
* @tc.type: FUNC
*/
HWTEST_F(UsbdInterfaceTest, SUB_USB_HDI_1170, TestSize.Level1)
{
uint8_t interfaceId = INTERFACEID_OK;
uint8_t altIndex = INDEX_0;
struct UsbDev dev = dev_;
auto ret = g_usbInterface->SetInterface(dev, interfaceId, altIndex);
HDF_LOGI("UsbdInterfaceTest::SUB_USB_HDI_1170 %{public}d ret=%{public}d", __LINE__, ret);
ASSERT_EQ(0, ret);
}
/**
* @tc.name: SUB_USB_HDI_1180
* @tc.desc: Test functions to SetInterface
* @tc.desc: int32_t SetInterface(const UsbDev &dev, uint8_t interfaceId, uint8_t altIndex);
* @tc.desc: Negative test: parameters exception, busNum error
* @tc.type: FUNC
*/
HWTEST_F(UsbdInterfaceTest, SUB_USB_HDI_1180, TestSize.Level1)
{
uint8_t interfaceId = INTERFACEID_OK;
uint8_t altIndex = INDEX_0;
struct UsbDev dev = dev_;
;
dev.busNum = BUS_NUM_INVALID;
auto ret = g_usbInterface->SetInterface(dev, interfaceId, altIndex);
HDF_LOGI("UsbdInterfaceTest::SUB_USB_HDI_1180 %{public}d ret=%{public}d", __LINE__, ret);
ASSERT_NE(ret, 0);
}
/**
* @tc.name: SUB_USB_HDI_1190
* @tc.desc: Test functions to SetInterface
* @tc.desc: int32_t SetInterface(const UsbDev &dev, uint8_t interfaceId, uint8_t altIndex);
* @tc.desc: Negative test: parameters exception, devAddr error
* @tc.type: FUNC
*/
HWTEST_F(UsbdInterfaceTest, SUB_USB_HDI_1190, TestSize.Level1)
{
uint8_t interfaceId = INTERFACEID_OK;
uint8_t altIndex = INDEX_INVALID;
struct UsbDev dev = dev_;
dev.devAddr = DEV_ADDR_INVALID;
auto ret = g_usbInterface->SetInterface(dev, interfaceId, altIndex);
HDF_LOGI("UsbdInterfaceTest::SUB_USB_HDI_1190 %{public}d ret=%{public}d", __LINE__, ret);
ASSERT_NE(ret, 0);
}
/**
* @tc.name: SUB_USB_HDI_1200
* @tc.desc: Test functions to SetInterface
* @tc.desc: int32_t SetInterface(const UsbDev &dev, uint8_t interfaceId, uint8_t altIndex);
* @tc.desc: Negative test: parameters exception, interfaceId error
* @tc.type: FUNC
*/
HWTEST_F(UsbdInterfaceTest, SUB_USB_HDI_1200, TestSize.Level1)
{
uint8_t interfaceId = INTERFACEID_INVALID;
uint8_t altIndex = INDEX_INVALID;
struct UsbDev dev = dev_;
auto ret = g_usbInterface->SetInterface(dev, interfaceId, altIndex);
HDF_LOGI("UsbdInterfaceTest::SUB_USB_HDI_1200 %{public}d ret=%{public}d", __LINE__, ret);
ASSERT_NE(ret, 0);
}
/**
* @tc.name: SUB_USB_HDI_1210
* @tc.desc: Test functions to SetInterface
* @tc.desc: int32_t SetInterface(const UsbDev &dev, uint8_t interfaceId, uint8_t altIndex);
* @tc.desc: Negative test: parameters exception, busNum && devAddr error
* @tc.type: FUNC
*/
HWTEST_F(UsbdInterfaceTest, SUB_USB_HDI_1210, TestSize.Level1)
{
uint8_t interfaceId = INTERFACEID_OK;
uint8_t altIndex = INDEX_0;
struct UsbDev dev = dev_;
dev.busNum = BUS_NUM_INVALID;
dev.devAddr = DEV_ADDR_INVALID;
auto ret = g_usbInterface->SetInterface(dev, interfaceId, altIndex);
HDF_LOGI("UsbdInterfaceTest::SUB_USB_HDI_1210 %{public}d ret=%{public}d", __LINE__, ret);
ASSERT_NE(ret, 0);
}
/**
* @tc.name: SUB_USB_HDI_1220
* @tc.desc: Test functions to SetInterface
* @tc.desc: int32_t SetInterface(const UsbDev &dev, uint8_t interfaceId, uint8_t altIndex);
* @tc.desc: Negative test: parameters exception, busNum && interfaceId error
* @tc.type: FUNC
*/
HWTEST_F(UsbdInterfaceTest, SUB_USB_HDI_1220, TestSize.Level1)
{
int32_t interfaceId = INTERFACEID_INVALID;
uint8_t altIndex = INDEX_1;
struct UsbDev dev = dev_;
dev.busNum = BUS_NUM_INVALID;
auto ret = g_usbInterface->SetInterface(dev, interfaceId, altIndex);
HDF_LOGI("UsbdInterfaceTest::SUB_USB_HDI_1220 %{public}d ret=%{public}d", __LINE__, ret);
ASSERT_NE(ret, 0);
}
/**
* @tc.name: SUB_USB_HDI_1230
* @tc.desc: Test functions to SetInterface
* @tc.desc: int32_t SetInterface(const UsbDev &dev, uint8_t interfaceId, uint8_t altIndex);
* @tc.desc: Negative test: parameters exception, devAddr && interfaceId error
* @tc.type: FUNC
*/
HWTEST_F(UsbdInterfaceTest, SUB_USB_HDI_1230, TestSize.Level1)
{
int32_t interfaceId = INTERFACEID_INVALID;
uint8_t altIndex = INDEX_INVALID;
struct UsbDev dev = dev_;
dev.devAddr = DEV_ADDR_INVALID;
auto ret = g_usbInterface->SetInterface(dev, interfaceId, altIndex);
HDF_LOGI("UsbdInterfaceTest::SUB_USB_HDI_1230 %{public}d ret=%{public}d", __LINE__, ret);
ASSERT_NE(ret, 0);
}
/**
* @tc.name: SUB_USB_HDI_1240
* @tc.desc: Test functions to SetInterface
* @tc.desc: int32_t SetInterface(const UsbDev &dev, uint8_t interfaceId, uint8_t altIndex);
* @tc.desc: Negative test: parameters exception, busNum && devAddr && interfaceId error
* @tc.type: FUNC
*/
HWTEST_F(UsbdInterfaceTest, SUB_USB_HDI_1240, TestSize.Level1)
{
uint8_t altIndex = INDEX_INVALID;
int32_t interfaceId = INTERFACEID_INVALID;
struct UsbDev dev = dev_;
dev.busNum = BUS_NUM_INVALID;
dev.devAddr = DEV_ADDR_INVALID;
auto ret = g_usbInterface->SetInterface(dev, interfaceId, altIndex);
HDF_LOGI("UsbdInterfaceTest::SUB_USB_HDI_1240 %{public}d ret=%{public}d", __LINE__, ret);
ASSERT_NE(ret, 0);
}
} // namespace

View File

@ -23,7 +23,6 @@
#include "v1_0/usb_types.h"
const int SLEEP_TIME = 3;
const uint8_t INDEX_0 = 0;
const uint8_t INDEX_1 = 1;
const uint8_t INDEX_INVALID = 255;
const uint8_t CONFIG_ID_0 = 0;
@ -430,178 +429,6 @@ HWTEST_F(UsbdRequestTest, SUB_USB_HDI_1080, Function | MediumTest | Level1)
/**********************************************************************************************************/
/**
* @tc.name: SUB_USB_HDI_1170
* @tc.desc: Test functions to SetInterface
* @tc.desc: int32_t SetInterface(const UsbDev &dev, uint8_t interfaceId, uint8_t altIndex);
* @tc.desc: Positive test: parameters correctly
* @tc.type: FUNC
*/
HWTEST_F(UsbdRequestTest, SUB_USB_HDI_1170, Function | MediumTest | Level1)
{
uint8_t interfaceId = INTERFACEID_OK;
uint8_t altIndex = INDEX_0;
struct UsbDev dev = dev_;
auto ret = g_usbInterface->ClaimInterface(dev, interfaceId, 1);
HDF_LOGI("UsbdRequestTest::SUB_USB_HDI_1170 %{public}d ClaimInterface=%{public}d", __LINE__, ret);
ASSERT_EQ(0, ret);
ret = g_usbInterface->SetInterface(dev, interfaceId, altIndex);
HDF_LOGI("UsbdRequestTest::SUB_USB_HDI_1170 %{public}d ret=%{public}d", __LINE__, ret);
ASSERT_EQ(0, ret);
}
/**
* @tc.name: SUB_USB_HDI_1180
* @tc.desc: Test functions to SetInterface
* @tc.desc: int32_t SetInterface(const UsbDev &dev, uint8_t interfaceId, uint8_t altIndex);
* @tc.desc: Negative test: parameters exception, busNum error
* @tc.type: FUNC
*/
HWTEST_F(UsbdRequestTest, SUB_USB_HDI_1180, Function | MediumTest | Level1)
{
uint8_t interfaceId = INTERFACEID_OK;
uint8_t altIndex = INDEX_0;
struct UsbDev dev = dev_;
auto ret = g_usbInterface->ClaimInterface(dev, interfaceId, 1);
HDF_LOGI("UsbdRequestTest::SUB_USB_HDI_1180 %{public}d ClaimInterface=%{public}d", __LINE__, ret);
ASSERT_EQ(0, ret);
dev.busNum = BUS_NUM_INVALID;
ret = g_usbInterface->SetInterface(dev, interfaceId, altIndex);
HDF_LOGI("UsbdRequestTest::SUB_USB_HDI_1180 %{public}d ret=%{public}d", __LINE__, ret);
ASSERT_NE(ret, 0);
}
/**
* @tc.name: SUB_USB_HDI_1190
* @tc.desc: Test functions to SetInterface
* @tc.desc: int32_t SetInterface(const UsbDev &dev, uint8_t interfaceId, uint8_t altIndex);
* @tc.desc: Negative test: parameters exception, devAddr error
* @tc.type: FUNC
*/
HWTEST_F(UsbdRequestTest, SUB_USB_HDI_1190, Function | MediumTest | Level1)
{
uint8_t interfaceId = INTERFACEID_OK;
uint8_t altIndex = INDEX_INVALID;
struct UsbDev dev = dev_;
auto ret = g_usbInterface->ClaimInterface(dev, interfaceId, 1);
HDF_LOGI("UsbdRequestTest::SUB_USB_HDI_1190 %{public}d ClaimInterface=%{public}d", __LINE__, ret);
ASSERT_EQ(0, ret);
dev.devAddr = DEV_ADDR_INVALID;
ret = g_usbInterface->SetInterface(dev, interfaceId, altIndex);
HDF_LOGI("UsbdRequestTest::SUB_USB_HDI_1190 %{public}d ret=%{public}d", __LINE__, ret);
ASSERT_NE(ret, 0);
}
/**
* @tc.name: SUB_USB_HDI_1200
* @tc.desc: Test functions to SetInterface
* @tc.desc: int32_t SetInterface(const UsbDev &dev, uint8_t interfaceId, uint8_t altIndex);
* @tc.desc: Negative test: parameters exception, interfaceId error
* @tc.type: FUNC
*/
HWTEST_F(UsbdRequestTest, SUB_USB_HDI_1200, Function | MediumTest | Level1)
{
uint8_t interfaceId = INTERFACEID_OK;
uint8_t altIndex = INDEX_INVALID;
struct UsbDev dev = dev_;
auto ret = g_usbInterface->ClaimInterface(dev, interfaceId, 1);
HDF_LOGI("UsbdRequestTest::SUB_USB_HDI_1200 %{public}d ClaimInterface=%{public}d", __LINE__, ret);
ASSERT_EQ(0, ret);
interfaceId = INTERFACEID_INVALID;
ret = g_usbInterface->SetInterface(dev, interfaceId, altIndex);
HDF_LOGI("UsbdRequestTest::SUB_USB_HDI_1200 %{public}d ret=%{public}d", __LINE__, ret);
ASSERT_NE(ret, 0);
}
/**
* @tc.name: SUB_USB_HDI_1210
* @tc.desc: Test functions to SetInterface
* @tc.desc: int32_t SetInterface(const UsbDev &dev, uint8_t interfaceId, uint8_t altIndex);
* @tc.desc: Negative test: parameters exception, busNum && devAddr error
* @tc.type: FUNC
*/
HWTEST_F(UsbdRequestTest, SUB_USB_HDI_1210, Function | MediumTest | Level1)
{
uint8_t interfaceId = INTERFACEID_OK;
uint8_t altIndex = INDEX_0;
struct UsbDev dev = dev_;
auto ret = g_usbInterface->ClaimInterface(dev, interfaceId, 1);
HDF_LOGI("UsbdRequestTest::SUB_USB_HDI_1210 %{public}d ClaimInterface=%{public}d", __LINE__, ret);
ASSERT_EQ(0, ret);
dev.busNum = BUS_NUM_INVALID;
dev.devAddr = DEV_ADDR_INVALID;
ret = g_usbInterface->SetInterface(dev, interfaceId, altIndex);
HDF_LOGI("UsbdRequestTest::SUB_USB_HDI_1210 %{public}d ret=%{public}d", __LINE__, ret);
ASSERT_NE(ret, 0);
}
/**
* @tc.name: SUB_USB_HDI_1220
* @tc.desc: Test functions to SetInterface
* @tc.desc: int32_t SetInterface(const UsbDev &dev, uint8_t interfaceId, uint8_t altIndex);
* @tc.desc: Negative test: parameters exception, busNum && interfaceId error
* @tc.type: FUNC
*/
HWTEST_F(UsbdRequestTest, SUB_USB_HDI_1220, Function | MediumTest | Level1)
{
int32_t interfaceId = INTERFACEID_OK;
uint8_t altIndex = INDEX_1;
struct UsbDev dev = dev_;
auto ret = g_usbInterface->ClaimInterface(dev, interfaceId, 1);
HDF_LOGI("UsbdRequestTest::SUB_USB_HDI_1220 %{public}d ClaimInterface=%{public}d", __LINE__, ret);
ASSERT_EQ(0, ret);
dev.busNum = BUS_NUM_INVALID;
interfaceId = INTERFACEID_INVALID;
ret = g_usbInterface->SetInterface(dev, interfaceId, altIndex);
HDF_LOGI("UsbdRequestTest::SUB_USB_HDI_1220 %{public}d ret=%{public}d", __LINE__, ret);
ASSERT_NE(ret, 0);
}
/**
* @tc.name: SUB_USB_HDI_1230
* @tc.desc: Test functions to SetInterface
* @tc.desc: int32_t SetInterface(const UsbDev &dev, uint8_t interfaceId, uint8_t altIndex);
* @tc.desc: Negative test: parameters exception, devAddr && interfaceId error
* @tc.type: FUNC
*/
HWTEST_F(UsbdRequestTest, SUB_USB_HDI_1230, Function | MediumTest | Level1)
{
int32_t interfaceId = INTERFACEID_OK;
uint8_t altIndex = INDEX_INVALID;
struct UsbDev dev = dev_;
auto ret = g_usbInterface->ClaimInterface(dev, interfaceId, 1);
HDF_LOGI("UsbdRequestTest::SUB_USB_HDI_1230 %{public}d ClaimInterface=%{public}d", __LINE__, ret);
ASSERT_EQ(0, ret);
dev.devAddr = DEV_ADDR_INVALID;
interfaceId = INTERFACEID_INVALID;
ret = g_usbInterface->SetInterface(dev, interfaceId, altIndex);
HDF_LOGI("UsbdRequestTest::SUB_USB_HDI_1230 %{public}d ret=%{public}d", __LINE__, ret);
ASSERT_NE(ret, 0);
}
/**
* @tc.name: SUB_USB_HDI_1240
* @tc.desc: Test functions to SetInterface
* @tc.desc: int32_t SetInterface(const UsbDev &dev, uint8_t interfaceId, uint8_t altIndex);
* @tc.desc: Negative test: parameters exception, busNum && devAddr && interfaceId error
* @tc.type: FUNC
*/
HWTEST_F(UsbdRequestTest, SUB_USB_HDI_1240, Function | MediumTest | Level1)
{
uint8_t altIndex = INDEX_INVALID;
int32_t interfaceId = INTERFACEID_OK;
struct UsbDev dev = dev_;
auto ret = g_usbInterface->ClaimInterface(dev, interfaceId, 1);
HDF_LOGI("UsbdRequestTest::SUB_USB_HDI_1240 %{public}d ClaimInterface=%{public}d", __LINE__, ret);
ASSERT_EQ(0, ret);
dev.busNum = BUS_NUM_INVALID;
dev.devAddr = DEV_ADDR_INVALID;
interfaceId = INTERFACEID_INVALID;
ret = g_usbInterface->SetInterface(dev, interfaceId, altIndex);
HDF_LOGI("UsbdRequestTest::SUB_USB_HDI_1240 %{public}d ret=%{public}d", __LINE__, ret);
ASSERT_NE(ret, 0);
}
/**
* @tc.name: SUB_USB_HDI_0210
* @tc.desc: Test functions to GetDeviceDescriptor