Open
serial接口整改 #24
wanghongenAdd on Jun 2
serial接口整改 #24
Open
Total: 4 files changed+25-25
| @@ -28,7 +28,7 @@ constexpr int32_t HDF_FAILURE = -1; | |||
| 28 | // MockSerialsImpl 实现 | 28 | // MockSerialsImpl 实现 |
| 29 | // ============================================================================ | 29 | // ============================================================================ |
| 30 | 30 | ||
| 31 | -int32_t MockSerialsImpl::QueryDevices(std::vector<OHOS::HDI::Serials::V1_0::SerialDeviceInfo>& devices) | 31 | +int32_t MockSerialsImpl::QueryDevices(std::vector<OHOS::HDI::Serial::V1_0::SerialDeviceInfo>& devices) |
| 32 | { | 32 | { |
| 33 | std::lock_guard<std::mutex> lock(mockMutex_); | 33 | std::lock_guard<std::mutex> lock(mockMutex_); |
| 34 | if (!queryDevicesSuccess_) { | 34 | if (!queryDevicesSuccess_) { |
| @@ -39,9 +39,9 @@ int32_t MockSerialsImpl::QueryDevices(std::vector<OHOS::HDI::Serials::V1_0::Seri | |||
| 39 | return HDF_SUCCESS; | 39 | return HDF_SUCCESS; |
| 40 | } | 40 | } |
| 41 | 41 | ||
| 42 | -int32_t MockSerialsImpl::OpenDevice(const std::string& portName, const OHOS::HDI::Serials::V1_0::SerialConfig& config, | 42 | +int32_t MockSerialsImpl::OpenDevice(const std::string& portName, const OHOS::HDI::Serial::V1_0::SerialConfig& config, |
| 43 | - const sptr<OHOS::HDI::Serials::V1_0::ISerialDeviceCallback>& cb, | 43 | + const sptr<OHOS::HDI::Serial::V1_0::ISerialDeviceCallback>& cb, |
| 44 | - sptr<OHOS::HDI::Serials::V1_0::ISerialDevice>& device) | 44 | + sptr<OHOS::HDI::Serial::V1_0::ISerialDevice>& device) |
| 45 | { | 45 | { |
| 46 | std::lock_guard<std::mutex> lock(mockMutex_); | 46 | std::lock_guard<std::mutex> lock(mockMutex_); |
| 47 | 47 | ||
| @@ -66,7 +66,7 @@ bool MockSerialsImpl::IsProxy() | |||
| 66 | return false; | 66 | return false; |
| 67 | } | 67 | } |
| 68 | 68 | ||
| 69 | -void MockSerialsImpl::SetMockDevices(const std::vector<OHOS::HDI::Serials::V1_0::SerialDeviceInfo>& devices) | 69 | +void MockSerialsImpl::SetMockDevices(const std::vector<OHOS::HDI::Serial::V1_0::SerialDeviceInfo>& devices) |
| 70 | { | 70 | { |
| 71 | std::lock_guard<std::mutex> lock(mockMutex_); | 71 | std::lock_guard<std::mutex> lock(mockMutex_); |
| 72 | mockDevices_ = devices; | 72 | mockDevices_ = devices; |
| @@ -111,7 +111,7 @@ MockSerials::~MockSerials() | |||
| 111 | } | 111 | } |
| 112 | 112 | ||
| 113 | // 辅助方法代理 | 113 | // 辅助方法代理 |
| 114 | -void MockSerials::SetMockDevices(const std::vector<OHOS::HDI::Serials::V1_0::SerialDeviceInfo>& devices) | 114 | +void MockSerials::SetMockDevices(const std::vector<OHOS::HDI::Serial::V1_0::SerialDeviceInfo>& devices) |
| 115 | { | 115 | { |
| 116 | impl_.SetMockDevices(devices); | 116 | impl_.SetMockDevices(devices); |
| 117 | } | 117 | } |
| @@ -45,7 +45,7 @@ namespace Serial { | |||
| 45 | * @details 使用 gmock 实现所有 ISerialDevice 方法,允许测试设置预期行为。 | 45 | * @details 使用 gmock 实现所有 ISerialDevice 方法,允许测试设置预期行为。 |
| 46 | * @since 2026-04-23 | 46 | * @since 2026-04-23 |
| 47 | */ | 47 | */ |
| 48 | -class MockSerialDevice : public OHOS::HDI::Serials::V1_0::ISerialDevice { | 48 | +class MockSerialDevice : public OHOS::HDI::Serial::V1_0::ISerialDevice { |
| 49 | public: | 49 | public: |
| 50 | MockSerialDevice() = default; | 50 | MockSerialDevice() = default; |
| 51 | ~MockSerialDevice() override = default; | 51 | ~MockSerialDevice() override = default; |
| @@ -74,20 +74,20 @@ public: | |||
| 74 | MockSerialsImpl() = default; | 74 | MockSerialsImpl() = default; |
| 75 | ~MockSerialsImpl() = default; | 75 | ~MockSerialsImpl() = default; |
| 76 | 76 | ||
| 77 | - int32_t QueryDevices(std::vector<OHOS::HDI::Serials::V1_0::SerialDeviceInfo>& devices); | 77 | + int32_t QueryDevices(std::vector<OHOS::HDI::Serial::V1_0::SerialDeviceInfo>& devices); |
| 78 | - int32_t OpenDevice(const std::string& portName, const OHOS::HDI::Serials::V1_0::SerialConfig& config, | 78 | + int32_t OpenDevice(const std::string& portName, const OHOS::HDI::Serial::V1_0::SerialConfig& config, |
| 79 | - const sptr<OHOS::HDI::Serials::V1_0::ISerialDeviceCallback>& cb, | 79 | + const sptr<OHOS::HDI::Serial::V1_0::ISerialDeviceCallback>& cb, |
| 80 | - sptr<OHOS::HDI::Serials::V1_0::ISerialDevice>& device); | 80 | + sptr<OHOS::HDI::Serial::V1_0::ISerialDevice>& device); |
| 81 | bool IsProxy(); | 81 | bool IsProxy(); |
| 82 | 82 | ||
| 83 | - void SetMockDevices(const std::vector<OHOS::HDI::Serials::V1_0::SerialDeviceInfo>& devices); | 83 | + void SetMockDevices(const std::vector<OHOS::HDI::Serial::V1_0::SerialDeviceInfo>& devices); |
| 84 | void SetOpenDeviceResult(bool success); | 84 | void SetOpenDeviceResult(bool success); |
| 85 | void SetQueryDevicesResult(bool success); | 85 | void SetQueryDevicesResult(bool success); |
| 86 | uint32_t GetOpenedDeviceCount(); | 86 | uint32_t GetOpenedDeviceCount(); |
| 87 | 87 | ||
| 88 | private: | 88 | private: |
| 89 | std::mutex mockMutex_; | 89 | std::mutex mockMutex_; |
| 90 | - std::vector<OHOS::HDI::Serials::V1_0::SerialDeviceInfo> mockDevices_; | 90 | + std::vector<OHOS::HDI::Serial::V1_0::SerialDeviceInfo> mockDevices_; |
| 91 | std::map<std::string, sptr<MockSerialDevice>> openedDevices_; | 91 | std::map<std::string, sptr<MockSerialDevice>> openedDevices_; |
| 92 | bool openDeviceSuccess_ = true; | 92 | bool openDeviceSuccess_ = true; |
| 93 | bool queryDevicesSuccess_ = true; | 93 | bool queryDevicesSuccess_ = true; |
| @@ -106,16 +106,16 @@ public: | |||
| 106 | ~MockSerials() override; | 106 | ~MockSerials() override; |
| 107 | 107 | ||
| 108 | // gmock 方法声明 | 108 | // gmock 方法声明 |
| 109 | - MOCK_METHOD(int32_t, QueryDevices, (std::vector<OHOS::HDI::Serials::V1_0::SerialDeviceInfo> & devices), (override)); | 109 | + MOCK_METHOD(int32_t, QueryDevices, (std::vector<OHOS::HDI::Serial::V1_0::SerialDeviceInfo> & devices), (override)); |
| 110 | MOCK_METHOD(int32_t, OpenDevice, | 110 | MOCK_METHOD(int32_t, OpenDevice, |
| 111 | - (const std::string& portName, const OHOS::HDI::Serials::V1_0::SerialConfig& config, | 111 | + (const std::string& portName, const OHOS::HDI::Serial::V1_0::SerialConfig& config, |
| 112 | - const sptr<OHOS::HDI::Serials::V1_0::ISerialDeviceCallback>& cb, | 112 | + const sptr<OHOS::HDI::Serial::V1_0::ISerialDeviceCallback>& cb, |
| 113 | - sptr<OHOS::HDI::Serials::V1_0::ISerialDevice>& device), | 113 | + sptr<OHOS::HDI::Serial::V1_0::ISerialDevice>& device), |
| 114 | (override)); | 114 | (override)); |
| 115 | MOCK_METHOD(bool, IsProxy, (), (override)); | 115 | MOCK_METHOD(bool, IsProxy, (), (override)); |
| 116 | 116 | ||
| 117 | // 辅助方法 - 代理到 impl_ | 117 | // 辅助方法 - 代理到 impl_ |
| 118 | - void SetMockDevices(const std::vector<OHOS::HDI::Serials::V1_0::SerialDeviceInfo>& devices); | 118 | + void SetMockDevices(const std::vector<OHOS::HDI::Serial::V1_0::SerialDeviceInfo>& devices); |
| 119 | void SetOpenDeviceResult(bool success); | 119 | void SetOpenDeviceResult(bool success); |
| 120 | void SetQueryDevicesResult(bool success); | 120 | void SetQueryDevicesResult(bool success); |
| 121 | uint32_t GetOpenedDeviceCount(); | 121 | uint32_t GetOpenedDeviceCount(); |
| @@ -43,7 +43,7 @@ | |||
| 43 | using namespace testing; | 43 | using namespace testing; |
| 44 | using namespace testing::ext; | 44 | using namespace testing::ext; |
| 45 | using namespace OHOS::Serial; | 45 | using namespace OHOS::Serial; |
| 46 | -using namespace OHOS::HDI::Serials::V1_0; | 46 | +using namespace OHOS::HDI::Serial::V1_0; |
| 47 | 47 | ||
| 48 | namespace OHOS { | 48 | namespace OHOS { |
| 49 | namespace Serial { | 49 | namespace Serial { |