1 /* 2 * Copyright (c) 2025 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 #ifndef USBD_HUB_DEVICE_TEST_H 16 #define USBD_HUB_DEVICE_TEST_H 17 18 #include <gtest/gtest.h> 19 #include "v2_0/iusb_host_interface.h" 20 #include "v2_0/usb_types.h" 21 #include "v2_0/iusbd_subscriber.h" 22 #include "usbd_type.h" 23 using OHOS::HDI::Usb::V2_0::UsbDev; 24 25 struct DevBusInfo { 26 int32_t busNum; 27 int32_t devAddr; 28 }; 29 class UsbSubscriberTest : public OHOS::HDI::Usb::V2_0::IUsbdSubscriber { 30 public: 31 UsbSubscriberTest() = default; 32 ~UsbSubscriberTest() = default; DeviceEvent(const OHOS::HDI::Usb::V2_0::USBDeviceInfo & info)33 int32_t DeviceEvent(const OHOS::HDI::Usb::V2_0::USBDeviceInfo &info) override 34 { 35 if (info.status == ACT_UPDEVICE || info.status == ACT_DOWNDEVICE) { 36 return 0; 37 } 38 busNum_ = info.busNum; 39 devAddr_ = info.devNum; 40 DevBusInfo busInfo; 41 busInfo.busNum = busNum_; 42 busInfo.devAddr = devAddr_; 43 busInfos.push_back(busInfo); 44 return 0; 45 } PortChangedEvent(const OHOS::HDI::Usb::V2_0::PortInfo & info)46 int32_t PortChangedEvent(const OHOS::HDI::Usb::V2_0::PortInfo &info) override 47 { 48 return 0; 49 }; 50 51 int32_t busNum_ = 0; 52 int32_t devAddr_ = 0; 53 std::vector<DevBusInfo> busInfos; 54 }; 55 56 namespace { 57 class UsbdHubDeviceTest : public testing::Test { 58 public: 59 static void SetUpTestCase(); 60 static void TearDownTestCase(); 61 void SetUp(); 62 void TearDown(); 63 64 static UsbDev dev_; 65 static UsbDev hubDev_; 66 static OHOS::sptr<UsbSubscriberTest> subscriber_; 67 }; 68 } // namespace 69 #endif // USBD_HUB_DEVICE_TEST_H 70