1 /*
2 * Copyright (c) 2024 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
16 #include "usbfn_mtp_test.h"
17
18 #include <cinttypes>
19 #include <cstdio>
20 #include <iostream>
21 #include <sstream>
22 #include <vector>
23 #include <fcntl.h>
24
25 #include "directory_ex.h"
26 #include "file_ex.h"
27 #include "hdf_log.h"
28 #include "securec.h"
29 #include "v1_0/iusb_interface.h"
30 #include "v1_0/iusbfn_mtp_interface.h"
31 #include "v1_0/usb_types.h"
32 #include "v1_0/usbfn_mtp_types.h"
33
34 #define HDF_LOG_TAG usbfn_mtp_ut
35
36 using namespace testing::ext;
37 using namespace OHOS;
38 using namespace OHOS::HDI::Usb::V1_0;
39 using namespace std;
40 using namespace OHOS::HDI::Usb::Gadget::Mtp::V1_0;
41
42 namespace {
43 constexpr int32_t SLEEP_TIME = 3;
44 constexpr int32_t MTP_EVENT_PACKET_MAX_BYTES = 28;
45 constexpr int32_t MTP_EVENT_PACKET_VALID_LEN = 20;
46 constexpr int32_t MTP_EVENT_PACKET_INVALID_LEN = 29;
47 constexpr uint16_t CMD_CODE_GET_DEVICE_INFO = 0x1001;
48 constexpr uint32_t MTP_PACKET_HEADER_SIZE = 12;
49 constexpr uint32_t BULK_IN_ONCE_MAX_SIZE = 1024;
50 constexpr uint32_t BULK_IN_LESS_THEN_ONCE = 45;
51 constexpr uint32_t BULK_IN_MORE_THEN_ONCE = 2023;
52 constexpr int64_t MTP_MAX_FILE_SIZE = 0xFFFFFFFFLL;
53 constexpr int64_t GEN_FILE_BUF_SIZE = 1024;
54 constexpr int64_t GEN_FILE_LIMIT_512MB = 512 * 1024 * 1024;
55 constexpr int32_t PRINT_VECTOR_MAX_LENGTH = 30;
56 const std::string WORKED_UT_PATH = "/data/local/tmp/";
57 const std::string MTP_TEST_SEND_FILE = "/data/local/tmp/sampleFile.mtp";
58 const std::string MTP_TEST_RECV_FILE = "/data/local/tmp/sampleFile.mtp";
59
60 sptr<IUsbfnMtpInterface> g_usbfnMtpInterface = nullptr;
61 sptr<IUsbInterface> g_usbInterface = nullptr;
62 int32_t g_currentFunc = USB_FUNCTION_NONE;
63 int32_t g_fileTestCount = 0;
64
65 struct UsbFnMtpFileSlice g_mfs = {
66 .offset = 0,
67 .length = 0,
68 .command = 0,
69 .transactionId = 0,
70 };
71
PrintVector(const std::string &msg, std::vector<uint8_t> &data, bool hexFormat)72 void PrintVector(const std::string &msg, std::vector<uint8_t> &data, bool hexFormat)
73 {
74 size_t printLen = data.size();
75 bool ignore = false;
76 if (printLen > static_cast<size_t>(PRINT_VECTOR_MAX_LENGTH)) {
77 printLen = static_cast<size_t>(PRINT_VECTOR_MAX_LENGTH);
78 ignore = true;
79 }
80 std::stringstream ss;
81 for (size_t i = 0; i < printLen; i++) {
82 if (hexFormat) {
83 ss << std::hex << "0x" << (0xFF & data.at(i)) << " ";
84 } else {
85 ss << data.at(i);
86 }
87 }
88 std::string output = msg + std::string("(") + std::to_string(printLen) + std::string("):") + ss.str();
89 if (ignore) {
90 output += "......";
91 }
92 HDF_LOGV("UsbfnMtpTestAdditional::PrintVector %{public}s", output.c_str());
93 }
94
GetFileSize(const std::string &pathName)95 uint64_t GetFileSize(const std::string &pathName)
96 {
97 struct stat statbuf;
98 uint64_t ret = stat(pathName.c_str(), &statbuf);
99 if (ret != 0) {
100 return 0;
101 }
102 return static_cast<uint64_t>(statbuf.st_size);
103 }
104
WriteRandomDataToFile(const std::string &pathName, uint64_t fileSize)105 bool WriteRandomDataToFile(const std::string &pathName, uint64_t fileSize)
106 {
107 int32_t random = open("/dev/urandom", O_RDONLY);
108 if (random < 0) {
109 HDF_LOGE("UsbfnMtpTestAdditional::WriteRandomDataToFile get random data failed");
110 return false;
111 }
112 FILE *opFile = std::fopen(pathName.c_str(), "w");
113 if (opFile == nullptr) {
114 HDF_LOGE("UsbfnMtpTestAdditional::WriteRandomDataToFile create file failed: %{public}s", pathName.c_str());
115 return false;
116 }
117 char buffer[GEN_FILE_BUF_SIZE];
118 int64_t count = static_cast<int64_t>(fileSize);
119 while (count > 0) {
120 (void)memset_s(buffer, sizeof(buffer), 0, sizeof(buffer));
121 int64_t readSize = count > GEN_FILE_BUF_SIZE ? GEN_FILE_BUF_SIZE : count;
122 ssize_t readActual = read(random, static_cast<void *>(buffer), static_cast<size_t>(readSize));
123 if (readActual != static_cast<ssize_t>(readSize)) {
124 HDF_LOGW("UsbfnMtpTestAdditional::WriteRandomDataToFile read random failed");
125 break;
126 }
127 size_t writeActual = std::fwrite(static_cast<void *>(buffer), 1, static_cast<size_t>(readSize), opFile);
128 if (writeActual != static_cast<size_t>(readSize)) {
129 HDF_LOGW("UsbfnMtpTestAdditional::WriteRandomDataToFile write failed");
130 break;
131 }
132 count -= readSize;
133 }
134 std::fflush(opFile);
135 std::fclose(opFile);
136 close(random);
137 HDF_LOGV("UsbfnMtpTestAdditional::WriteRandomDataToFile file %{public}s: %{public}" PRIu64 "/%{public}" PRIu64 "",
138 pathName.c_str(), GetFileSize(pathName), fileSize);
139 return count > 0 ? false : true;
140 }
141
GenerateFile(const std::string &pathName, int64_t fileSize)142 bool GenerateFile(const std::string &pathName, int64_t fileSize)
143 {
144 if (GetFileSize(pathName) == static_cast<uint64_t>(fileSize)) {
145 HDF_LOGW("UsbfnMtpTestAdditional::GenerateFile file already exist");
146 return true;
147 }
148 if (fileSize > GEN_FILE_LIMIT_512MB) {
149 int32_t ret = truncate(pathName.c_str(), static_cast<off_t>(fileSize));
150 if (ret != 0) {
151 HDF_LOGE("UsbfnMtpTestAdditional::GenerateFile fail to truncate file to size: %{public}" PRId64 "",
152 fileSize);
153 return false;
154 }
155 HDF_LOGV("UsbfnMtpTestAdditional::GenerateFile truncate %{public}s %{public}" PRId64 "", pathName.c_str(),
156 fileSize);
157 return true;
158 }
159 return WriteRandomDataToFile(pathName, static_cast<uint64_t>(fileSize));
160 }
161
SwitchErrCode(int32_t ret)162 int32_t SwitchErrCode(int32_t ret)
163 {
164 return ret == HDF_ERR_NOT_SUPPORT ? HDF_SUCCESS : ret;
165 }
166
SetUpTestCase(void)167 void UsbfnMtpTestAdditional::SetUpTestCase(void)
168 {
169 ASSERT_TRUE(GetCurrentProcPath() == WORKED_UT_PATH);
170 std::cout << "===>please connect to PC use USB 3.0 interface, press enter to continue set function to mtp"
171 << std::endl;
172 int32_t c;
173 while ((c = getchar()) != '\n' && c != EOF) {
174 }
175
176 g_usbInterface = IUsbInterface::Get();
177 ASSERT_TRUE(g_usbInterface != nullptr);
178 auto ret = g_usbInterface->SetPortRole(DEFAULT_PORT_ID, POWER_ROLE_SINK, DATA_ROLE_DEVICE);
179 sleep(SLEEP_TIME);
180 ret = SwitchErrCode(ret);
181 ASSERT_EQ(0, ret);
182 ret = g_usbInterface->GetCurrentFunctions(g_currentFunc);
183 ASSERT_EQ(0, ret);
184 std::cout << "===>current function=" << g_currentFunc << ", set function to mtp, please wait" << std::endl;
185 ret = g_usbInterface->SetCurrentFunctions(USB_FUNCTION_MTP);
186 ASSERT_EQ(0, ret);
187
188 g_usbfnMtpInterface = IUsbfnMtpInterface::Get();
189 ASSERT_TRUE(g_usbfnMtpInterface != nullptr);
190 ret = g_usbfnMtpInterface->Start();
191 ASSERT_EQ(0, ret);
192 }
193
TearDownTestCase(void)194 void UsbfnMtpTestAdditional::TearDownTestCase(void)
195 {
196 HDF_LOGV("UsbfnMtpTestAdditional::TearDownTestCase");
197 ASSERT_TRUE(g_usbfnMtpInterface != nullptr);
198 auto ret = g_usbfnMtpInterface->Stop();
199 ASSERT_EQ(0, ret);
200 ASSERT_TRUE(g_usbInterface != nullptr);
201 ret = g_usbInterface->SetCurrentFunctions(g_currentFunc);
202 ASSERT_EQ(0, ret);
203 if (g_fileTestCount == 0) {
204 return;
205 }
206 /* 1 means single test, run with '--gtest_filter=' option */
207 if (g_fileTestCount == 1) {
208 std::cout << "===>please delete temporary test file if needed: sendfile=" << MTP_TEST_SEND_FILE
209 << " recvfile=" << MTP_TEST_RECV_FILE << std::endl;
210 return;
211 }
212 if (FileExists(std::string(MTP_TEST_SEND_FILE))) {
213 if (remove(MTP_TEST_SEND_FILE.c_str()) != 0) {
214 std::cout << "[-] remove send file failed: " << MTP_TEST_SEND_FILE << std::endl;
215 }
216 }
217 if (FileExists(std::string(MTP_TEST_RECV_FILE))) {
218 if (remove(MTP_TEST_RECV_FILE.c_str()) != 0) {
219 std::cout << "[-] remove recv file failed: " << MTP_TEST_RECV_FILE << std::endl;
220 }
221 }
222 }
223
SetUp(void)224 void UsbfnMtpTestAdditional::SetUp(void) {}
225
TearDown(void)226 void UsbfnMtpTestAdditional::TearDown(void) {}
227 /**
228 * @tc.number: SUB_USB_DeviceManager_HDI_MTPPTPTest_0100
229 * @tc.name: testHdiUsbMtpTestReceiveFile001
230 * @tc.desc: mfs Indicates the mtp file slice info. mfs.length = 1.
231 */
HWTEST_F(UsbfnMtpTestAdditional, testHdiUsbMtpTestReceiveFile001, Function | MediumTest | Level1)232 HWTEST_F(UsbfnMtpTestAdditional, testHdiUsbMtpTestReceiveFile001, Function | MediumTest | Level1)
233 {
234 ASSERT_TRUE(g_usbfnMtpInterface != nullptr);
235 ASSERT_TRUE(GetCurrentProcPath() == WORKED_UT_PATH);
236 g_fileTestCount++;
237 struct UsbFnMtpFileSlice mfs = g_mfs;
238 mfs.length = 1;
239 std::cout << "testHdiUsbMtpTestReceiveFile001===>use libusb in PC launch bulk-out transfer(size = " << mfs.length
240 << "), press enter to continue" << std::endl;
241 int32_t c;
242 while ((c = getchar()) != '\n' && c != EOF) {
243 }
244
245 std::string filePathName = MTP_TEST_RECV_FILE;
246 mfs.fd = open(filePathName.c_str(), O_CREAT | O_RDWR | O_TRUNC, 0777);
247 ASSERT_GT(mfs.fd, 0);
248 auto ret = g_usbfnMtpInterface->ReceiveFile(mfs);
249 close(mfs.fd);
250 ASSERT_EQ(ret, 0);
251 ASSERT_EQ(GetFileSize(filePathName), static_cast<uint64_t>(mfs.length));
252 }
253
254 /**
255 * @tc.number: SUB_USB_DeviceManager_HDI_MTPPTPTest_0200
256 * @tc.name: testHdiUsbMtpTestReceiveFile002
257 * @tc.desc: mfs Indicates the mtp file slice info. mfs.length = 100.
258 */
HWTEST_F(UsbfnMtpTestAdditional, testHdiUsbMtpTestReceiveFile002, Function | MediumTest | Level1)259 HWTEST_F(UsbfnMtpTestAdditional, testHdiUsbMtpTestReceiveFile002, Function | MediumTest | Level1)
260 {
261 ASSERT_TRUE(g_usbfnMtpInterface != nullptr);
262 ASSERT_TRUE(GetCurrentProcPath() == WORKED_UT_PATH);
263 g_fileTestCount++;
264 struct UsbFnMtpFileSlice mfs = g_mfs;
265 mfs.length = 100;
266 std::cout << "testHdiUsbMtpTestReceiveFile002===>use libusb in PC launch bulk-out transfer(size = " << mfs.length
267 << "), press enter to continue" << std::endl;
268 int32_t c;
269 while ((c = getchar()) != '\n' && c != EOF) {
270 }
271
272 std::string filePathName = MTP_TEST_RECV_FILE;
273 mfs.fd = open(filePathName.c_str(), O_CREAT | O_RDWR | O_TRUNC, 0777);
274 ASSERT_GT(mfs.fd, 0);
275 auto ret = g_usbfnMtpInterface->ReceiveFile(mfs);
276 close(mfs.fd);
277 ASSERT_EQ(ret, 0);
278 ASSERT_EQ(GetFileSize(filePathName), static_cast<uint64_t>(mfs.length));
279 }
280
281 /**
282 * @tc.number: SUB_USB_DeviceManager_HDI_MTPPTPTest_0300
283 * @tc.name: testHdiUsbMtpTestReceiveFile003
284 * @tc.desc: mfs Indicates the mtp file slice info. mfs.length = 255.
285 */
HWTEST_F(UsbfnMtpTestAdditional, testHdiUsbMtpTestReceiveFile003, Function | MediumTest | Level1)286 HWTEST_F(UsbfnMtpTestAdditional, testHdiUsbMtpTestReceiveFile003, Function | MediumTest | Level1)
287 {
288 ASSERT_TRUE(g_usbfnMtpInterface != nullptr);
289 ASSERT_TRUE(GetCurrentProcPath() == WORKED_UT_PATH);
290 g_fileTestCount++;
291 struct UsbFnMtpFileSlice mfs = g_mfs;
292 mfs.length = 255;
293 std::cout << "testHdiUsbMtpTestReceiveFile003===>use libusb in PC launch bulk-out transfer(size = " << mfs.length
294 << "), press enter to continue" << std::endl;
295 int32_t c;
296 while ((c = getchar()) != '\n' && c != EOF) {
297 }
298
299 std::string filePathName = MTP_TEST_RECV_FILE;
300 mfs.fd = open(filePathName.c_str(), O_CREAT | O_RDWR | O_TRUNC, 0777);
301 ASSERT_GT(mfs.fd, 0);
302 auto ret = g_usbfnMtpInterface->ReceiveFile(mfs);
303 close(mfs.fd);
304 ASSERT_EQ(ret, 0);
305 ASSERT_EQ(GetFileSize(filePathName), static_cast<uint64_t>(mfs.length));
306 }
307
308 /**
309 * @tc.number: SUB_USB_DeviceManager_HDI_MTPPTPTest_0400
310 * @tc.name: testHdiUsbMtpTestReceiveFile004
311 * @tc.desc: mfs Indicates the mtp file slice info. mfs.length = 1000.
312 */
HWTEST_F(UsbfnMtpTestAdditional, testHdiUsbMtpTestReceiveFile004, Function | MediumTest | Level1)313 HWTEST_F(UsbfnMtpTestAdditional, testHdiUsbMtpTestReceiveFile004, Function | MediumTest | Level1)
314 {
315 ASSERT_TRUE(g_usbfnMtpInterface != nullptr);
316 ASSERT_TRUE(GetCurrentProcPath() == WORKED_UT_PATH);
317 g_fileTestCount++;
318 struct UsbFnMtpFileSlice mfs = g_mfs;
319 mfs.length = 1000;
320 std::cout << "testHdiUsbMtpTestReceiveFile004===>use libusb in PC launch bulk-out transfer(size = " << mfs.length
321 << "), press enter to continue" << std::endl;
322 int32_t c;
323 while ((c = getchar()) != '\n' && c != EOF) {
324 }
325
326 std::string filePathName = MTP_TEST_RECV_FILE;
327 mfs.fd = open(filePathName.c_str(), O_CREAT | O_RDWR | O_TRUNC, 0777);
328 ASSERT_GT(mfs.fd, 0);
329 auto ret = g_usbfnMtpInterface->ReceiveFile(mfs);
330 close(mfs.fd);
331 ASSERT_EQ(ret, 0);
332 ASSERT_EQ(GetFileSize(filePathName), static_cast<uint64_t>(mfs.length));
333 }
334
335 /**
336 * @tc.number: SUB_USB_DeviceManager_HDI_MTPPTPTest_0500
337 * @tc.name: testHdiUsbMtpTestReceiveFile005
338 * @tc.desc: mfs Indicates the mtp file slice info. mfs.length = MTP_MAX_FILE_SIZE - 2.
339 */
HWTEST_F(UsbfnMtpTestAdditional, testHdiUsbMtpTestReceiveFile005, Function | MediumTest | Level1)340 HWTEST_F(UsbfnMtpTestAdditional, testHdiUsbMtpTestReceiveFile005, Function | MediumTest | Level1)
341 {
342 ASSERT_TRUE(g_usbfnMtpInterface != nullptr);
343 ASSERT_TRUE(GetCurrentProcPath() == WORKED_UT_PATH);
344 g_fileTestCount++;
345 struct UsbFnMtpFileSlice mfs = g_mfs;
346 mfs.length = MTP_MAX_FILE_SIZE - 2;
347 std::cout << "testHdiUsbMtpTestReceiveFile005===>use libusb in PC launch bulk-out transfer(size = " << mfs.length
348 << "), press enter to continue" << std::endl;
349 int32_t c;
350 while ((c = getchar()) != '\n' && c != EOF) {
351 }
352
353 std::string filePathName = MTP_TEST_RECV_FILE;
354 mfs.fd = open(filePathName.c_str(), O_CREAT | O_RDWR | O_TRUNC, 0777);
355 ASSERT_GT(mfs.fd, 0);
356 auto ret = g_usbfnMtpInterface->ReceiveFile(mfs);
357 close(mfs.fd);
358 ASSERT_EQ(ret, 0);
359 ASSERT_EQ(GetFileSize(filePathName), static_cast<uint64_t>(mfs.length));
360 }
361
362 /**
363 * @tc.number: SUB_USB_DeviceManager_HDI_MTPPTPTest_0600
364 * @tc.name: testHdiUsbMtpTestReceiveFile006
365 * @tc.desc: mfs Indicates the mtp file slice info. mfs.length = MTP_MAX_FILE_SIZE - 1024.
366 */
HWTEST_F(UsbfnMtpTestAdditional, testHdiUsbMtpTestReceiveFile006, Function | MediumTest | Level1)367 HWTEST_F(UsbfnMtpTestAdditional, testHdiUsbMtpTestReceiveFile006, Function | MediumTest | Level1)
368 {
369 ASSERT_TRUE(g_usbfnMtpInterface != nullptr);
370 ASSERT_TRUE(GetCurrentProcPath() == WORKED_UT_PATH);
371 g_fileTestCount++;
372 struct UsbFnMtpFileSlice mfs = g_mfs;
373 mfs.length = MTP_MAX_FILE_SIZE - 1024;
374 std::cout << "testHdiUsbMtpTestReceiveFile006===>use libusb in PC launch bulk-out transfer(size = " << mfs.length
375 << "), press enter to continue" << std::endl;
376 int32_t c;
377 while ((c = getchar()) != '\n' && c != EOF) {
378 }
379
380 std::string filePathName = MTP_TEST_RECV_FILE;
381 mfs.fd = open(filePathName.c_str(), O_CREAT | O_RDWR | O_TRUNC, 0777);
382 ASSERT_GT(mfs.fd, 0);
383 auto ret = g_usbfnMtpInterface->ReceiveFile(mfs);
384 close(mfs.fd);
385 ASSERT_EQ(ret, 0);
386 ASSERT_EQ(GetFileSize(filePathName), static_cast<uint64_t>(mfs.length));
387 }
388
389 /**
390 * @tc.number: SUB_USB_DeviceManager_HDI_MTPPTPTest_0700
391 * @tc.name: testHdiUsbMtpTestReceiveFile007
392 * @tc.desc: mfs Indicates the mtp file slice info.mfs.length = 1 mfs.command = 1 mfs.transactionId = 1.
393 */
HWTEST_F(UsbfnMtpTestAdditional, testHdiUsbMtpTestReceiveFile007, Function | MediumTest | Level1)394 HWTEST_F(UsbfnMtpTestAdditional, testHdiUsbMtpTestReceiveFile007, Function | MediumTest | Level1)
395 {
396 ASSERT_TRUE(g_usbfnMtpInterface != nullptr);
397 ASSERT_TRUE(GetCurrentProcPath() == WORKED_UT_PATH);
398 g_fileTestCount++;
399 struct UsbFnMtpFileSlice mfs = g_mfs;
400 mfs.length = 1;
401 mfs.command = 1;
402 mfs.transactionId = 1;
403 std::cout << "testHdiUsbMtpTestReceiveFile007===>use libusb in PC launch bulk-out transfer(size = " << mfs.length
404 << "), press enter to continue" << std::endl;
405 int32_t c;
406 while ((c = getchar()) != '\n' && c != EOF) {
407 }
408
409 std::string filePathName = MTP_TEST_RECV_FILE;
410 mfs.fd = open(filePathName.c_str(), O_CREAT | O_RDWR | O_TRUNC, 0777);
411 ASSERT_GT(mfs.fd, 0);
412 auto ret = g_usbfnMtpInterface->ReceiveFile(mfs);
413 close(mfs.fd);
414 ASSERT_EQ(ret, 0);
415 ASSERT_EQ(GetFileSize(filePathName), static_cast<uint64_t>(mfs.length));
416 }
417
418 /**
419 * @tc.number: SUB_USB_DeviceManager_HDI_MTPPTPTest_0800
420 * @tc.name: testHdiUsbMtpTestReceiveFile008
421 * @tc.desc: mfs Indicates the mtp file slice info. mfs.length = 100 mfs.command = 100 mfs.transactionId = 100.
422 */
HWTEST_F(UsbfnMtpTestAdditional, testHdiUsbMtpTestReceiveFile008, Function | MediumTest | Level1)423 HWTEST_F(UsbfnMtpTestAdditional, testHdiUsbMtpTestReceiveFile008, Function | MediumTest | Level1)
424 {
425 ASSERT_TRUE(g_usbfnMtpInterface != nullptr);
426 ASSERT_TRUE(GetCurrentProcPath() == WORKED_UT_PATH);
427 g_fileTestCount++;
428 struct UsbFnMtpFileSlice mfs = g_mfs;
429 mfs.length = 100;
430 mfs.command = 100;
431 mfs.transactionId = 100;
432 std::cout << "testHdiUsbMtpTestReceiveFile008===>use libusb in PC launch bulk-out transfer(size = " << mfs.length
433 << "), press enter to continue" << std::endl;
434 int32_t c;
435 while ((c = getchar()) != '\n' && c != EOF) {
436 }
437
438 std::string filePathName = MTP_TEST_RECV_FILE;
439 mfs.fd = open(filePathName.c_str(), O_CREAT | O_RDWR | O_TRUNC, 0777);
440 ASSERT_GT(mfs.fd, 0);
441 auto ret = g_usbfnMtpInterface->ReceiveFile(mfs);
442 close(mfs.fd);
443 ASSERT_EQ(ret, 0);
444 ASSERT_EQ(GetFileSize(filePathName), static_cast<uint64_t>(mfs.length));
445 }
446
447 /**
448 * @tc.number: SUB_USB_DeviceManager_HDI_MTPPTPTest_0900
449 * @tc.name: testHdiUsbMtpTestReceiveFile009
450 * @tc.desc: mfs Indicates the mtp file slice info. mfs.length = 1000 mfs.command = 1000 mfs.transactionId = 1000.
451 */
HWTEST_F(UsbfnMtpTestAdditional, testHdiUsbMtpTestReceiveFile009, Function | MediumTest | Level1)452 HWTEST_F(UsbfnMtpTestAdditional, testHdiUsbMtpTestReceiveFile009, Function | MediumTest | Level1)
453 {
454 ASSERT_TRUE(g_usbfnMtpInterface != nullptr);
455 ASSERT_TRUE(GetCurrentProcPath() == WORKED_UT_PATH);
456 g_fileTestCount++;
457 struct UsbFnMtpFileSlice mfs = g_mfs;
458 mfs.length = 1000;
459 mfs.command = 1000;
460 mfs.transactionId = 1000;
461 std::cout << "testHdiUsbMtpTestReceiveFile009===>use libusb in PC launch bulk-out transfer(size = " << mfs.length
462 << "), press enter to continue" << std::endl;
463 int32_t c;
464 while ((c = getchar()) != '\n' && c != EOF) {
465 }
466
467 std::string filePathName = MTP_TEST_RECV_FILE;
468 mfs.fd = open(filePathName.c_str(), O_CREAT | O_RDWR | O_TRUNC, 0777);
469 ASSERT_GT(mfs.fd, 0);
470 auto ret = g_usbfnMtpInterface->ReceiveFile(mfs);
471 close(mfs.fd);
472 ASSERT_EQ(ret, 0);
473 ASSERT_EQ(GetFileSize(filePathName), static_cast<uint64_t>(mfs.length));
474 }
475
476 /**
477 * @tc.number: SUB_USB_DeviceManager_HDI_MTPPTPTest_1000
478 * @tc.name: testHdiUsbMtpTestReceiveFile010
479 * @tc.desc: mfs Indicates the mtp file slice info. mfs.length = 25 mfs.command = 100 mfs.transactionId = 100.
480 */
HWTEST_F(UsbfnMtpTestAdditional, testHdiUsbMtpTestReceiveFile010, Function | MediumTest | Level1)481 HWTEST_F(UsbfnMtpTestAdditional, testHdiUsbMtpTestReceiveFile010, Function | MediumTest | Level1)
482 {
483 ASSERT_TRUE(g_usbfnMtpInterface != nullptr);
484 ASSERT_TRUE(GetCurrentProcPath() == WORKED_UT_PATH);
485 g_fileTestCount++;
486 struct UsbFnMtpFileSlice mfs = g_mfs;
487 mfs.length = 25;
488 mfs.command = 100;
489 mfs.transactionId = 100;
490 std::cout << "testHdiUsbMtpTestReceiveFile010===>use libusb in PC launch bulk-out transfer(size = " << mfs.length
491 << "), press enter to continue" << std::endl;
492 int32_t c;
493 while ((c = getchar()) != '\n' && c != EOF) {
494 }
495
496 std::string filePathName = MTP_TEST_RECV_FILE;
497 mfs.fd = open(filePathName.c_str(), O_CREAT | O_RDWR | O_TRUNC, 0777);
498 ASSERT_GT(mfs.fd, 0);
499 auto ret = g_usbfnMtpInterface->ReceiveFile(mfs);
500 close(mfs.fd);
501 ASSERT_EQ(ret, 0);
502 ASSERT_EQ(GetFileSize(filePathName), static_cast<uint64_t>(mfs.length));
503 }
504
505 /**
506 * @tc.number: SUB_USB_DeviceManager_HDI_MTPPTPTest_1100
507 * @tc.name: testHdiUsbMtpTestReceiveFile011
508 * @tc.desc: mfs Indicates the mtp file slice info. mfs.length = 100 mfs.command = 200 mfs.transactionId = 300.
509 */
HWTEST_F(UsbfnMtpTestAdditional, testHdiUsbMtpTestReceiveFile011, Function | MediumTest | Level1)510 HWTEST_F(UsbfnMtpTestAdditional, testHdiUsbMtpTestReceiveFile011, Function | MediumTest | Level1)
511 {
512 ASSERT_TRUE(g_usbfnMtpInterface != nullptr);
513 ASSERT_TRUE(GetCurrentProcPath() == WORKED_UT_PATH);
514 g_fileTestCount++;
515 struct UsbFnMtpFileSlice mfs = g_mfs;
516 mfs.length = 100;
517 mfs.command = 200;
518 mfs.transactionId = 300;
519 std::cout << "testHdiUsbMtpTestReceiveFile011===>use libusb in PC launch bulk-out transfer(size = " << mfs.length
520 << "), press enter to continue" << std::endl;
521 int32_t c;
522 while ((c = getchar()) != '\n' && c != EOF) {
523 }
524
525 std::string filePathName = MTP_TEST_RECV_FILE;
526 mfs.fd = open(filePathName.c_str(), O_CREAT | O_RDWR | O_TRUNC, 0777);
527 ASSERT_GT(mfs.fd, 0);
528 auto ret = g_usbfnMtpInterface->ReceiveFile(mfs);
529 close(mfs.fd);
530 ASSERT_EQ(ret, 0);
531 ASSERT_EQ(GetFileSize(filePathName), static_cast<uint64_t>(mfs.length));
532 }
533
534 /**
535 * @tc.number: SUB_USB_DeviceManager_HDI_MTPPTPTest_1200
536 * @tc.name: testHdiUsbMtpTestReceiveFile012
537 * @tc.desc: mfs Indicates the mtp file slice info. mfs.length = 1000 mfs.command = 2000 mfs.transactionId = 3000.
538 */
HWTEST_F(UsbfnMtpTestAdditional, testHdiUsbMtpTestReceiveFile012, Function | MediumTest | Level1)539 HWTEST_F(UsbfnMtpTestAdditional, testHdiUsbMtpTestReceiveFile012, Function | MediumTest | Level1)
540 {
541 ASSERT_TRUE(g_usbfnMtpInterface != nullptr);
542 ASSERT_TRUE(GetCurrentProcPath() == WORKED_UT_PATH);
543 g_fileTestCount++;
544 struct UsbFnMtpFileSlice mfs = g_mfs;
545 mfs.length = 1000;
546 mfs.command = 2000;
547 mfs.transactionId = 3000;
548 std::cout << "testHdiUsbMtpTestReceiveFile012===>use libusb in PC launch bulk-out transfer(size = " << mfs.length
549 << "), press enter to continue" << std::endl;
550 int32_t c;
551 while ((c = getchar()) != '\n' && c != EOF) {
552 }
553
554 std::string filePathName = MTP_TEST_RECV_FILE;
555 mfs.fd = open(filePathName.c_str(), O_CREAT | O_RDWR | O_TRUNC, 0777);
556 ASSERT_GT(mfs.fd, 0);
557 auto ret = g_usbfnMtpInterface->ReceiveFile(mfs);
558 close(mfs.fd);
559 ASSERT_EQ(ret, 0);
560 ASSERT_EQ(GetFileSize(filePathName), static_cast<uint64_t>(mfs.length));
561 }
562
563 /**
564 * @tc.number: SUB_USB_DeviceManager_HDI_MTPPTPTest_1300
565 * @tc.name: testHdiUsbMtpTestReceiveFile013
566 * @tc.desc: mfs Indicates the mtp file slice info. mfs.length = 1 mfs.command = 1 mfs.transactionId = 100.
567 */
HWTEST_F(UsbfnMtpTestAdditional, testHdiUsbMtpTestReceiveFile013, Function | MediumTest | Level1)568 HWTEST_F(UsbfnMtpTestAdditional, testHdiUsbMtpTestReceiveFile013, Function | MediumTest | Level1)
569 {
570 ASSERT_TRUE(g_usbfnMtpInterface != nullptr);
571 ASSERT_TRUE(GetCurrentProcPath() == WORKED_UT_PATH);
572 g_fileTestCount++;
573 struct UsbFnMtpFileSlice mfs = g_mfs;
574 mfs.length = 1;
575 mfs.command = 1;
576 mfs.transactionId = 100;
577 std::cout << "testHdiUsbMtpTestReceiveFile013===>use libusb in PC launch bulk-out transfer(size = " << mfs.length
578 << "), press enter to continue" << std::endl;
579 int32_t c;
580 while ((c = getchar()) != '\n' && c != EOF) {
581 }
582
583 std::string filePathName = MTP_TEST_RECV_FILE;
584 mfs.fd = open(filePathName.c_str(), O_CREAT | O_RDWR | O_TRUNC, 0777);
585 ASSERT_GT(mfs.fd, 0);
586 auto ret = g_usbfnMtpInterface->ReceiveFile(mfs);
587 close(mfs.fd);
588 ASSERT_EQ(ret, 0);
589 ASSERT_EQ(GetFileSize(filePathName), static_cast<uint64_t>(mfs.length));
590 }
591
592 /**
593 * @tc.number: SUB_USB_DeviceManager_HDI_MTPPTPTest_1400
594 * @tc.name: testHdiUsbMtpTestSendEvent001
595 * @tc.desc: Send event data by USB MTP/PTP driver. devData.assign(MTP_EVENT_PACKET_VALID_LEN, 'S').
596 */
HWTEST_F(UsbfnMtpTestAdditional, testHdiUsbMtpTestSendEvent001, Function | MediumTest | Level1)597 HWTEST_F(UsbfnMtpTestAdditional, testHdiUsbMtpTestSendEvent001, Function | MediumTest | Level1)
598 {
599 ASSERT_TRUE(g_usbfnMtpInterface != nullptr);
600 std::vector<uint8_t> devData;
601 devData.assign(MTP_EVENT_PACKET_VALID_LEN, 'S');
602 std::cout << "testHdiUsbMtpTestSendEvent001===>use libusb in PC launch intr-in transfer(expect=" << devData.size()
603 << "), press enter to continue" << std::endl;
604 int32_t c;
605 while ((c = getchar()) != '\n' && c != EOF) {
606 }
607
608 auto ret = g_usbfnMtpInterface->SendEvent(devData);
609 ASSERT_EQ(0, ret);
610 }
611
612 /**
613 * @tc.number: SUB_USB_DeviceManager_HDI_MTPPTPTest_1500
614 * @tc.name: testHdiUsbMtpTestSendEvent002
615 * @tc.desc: Send event data by USB MTP/PTP driver. devData.assign(MTP_EVENT_PACKET_MAX_BYTES, 'S').
616 */
HWTEST_F(UsbfnMtpTestAdditional, testHdiUsbMtpTestSendEvent002, Function | MediumTest | Level1)617 HWTEST_F(UsbfnMtpTestAdditional, testHdiUsbMtpTestSendEvent002, Function | MediumTest | Level1)
618 {
619 ASSERT_TRUE(g_usbfnMtpInterface != nullptr);
620 std::vector<uint8_t> devData;
621 devData.assign(MTP_EVENT_PACKET_MAX_BYTES, 'S');
622 std::cout << "testHdiUsbMtpTestSendEvent002===>use libusb in PC launch intr-in transfer(expect=" << devData.size()
623 << "), press enter to continue" << std::endl;
624 int32_t c;
625 while ((c = getchar()) != '\n' && c != EOF) {
626 }
627 auto ret = g_usbfnMtpInterface->SendEvent(devData);
628 ASSERT_EQ(0, ret);
629 }
630
631 /**
632 * @tc.number: SUB_USB_DeviceManager_HDI_MTPPTPTest_1600
633 * @tc.name: testHdiUsbMtpTestSendEvent003
634 * @tc.desc: Send event data by USB MTP/PTP driver. devData.assign(MTP_EVENT_PACKET_INVALID_LEN, 'S').
635 */
HWTEST_F(UsbfnMtpTestAdditional, testHdiUsbMtpTestSendEvent003, Function | MediumTest | Level2)636 HWTEST_F(UsbfnMtpTestAdditional, testHdiUsbMtpTestSendEvent003, Function | MediumTest | Level2)
637 {
638 ASSERT_TRUE(g_usbfnMtpInterface != nullptr);
639 std::vector<uint8_t> devData;
640 devData.assign(MTP_EVENT_PACKET_INVALID_LEN, 'S');
641 std::cout << "testHdiUsbMtpTestSendEvent003===>use libusb in PC launch intr-in transfer(expect=no data, "
642 << "or error), press enter to continue" << std::endl;
643 int32_t c;
644 while ((c = getchar()) != '\n' && c != EOF) {
645 }
646
647 auto ret = g_usbfnMtpInterface->SendEvent(devData);
648 ASSERT_NE(0, ret);
649 std::cout << "testHdiUsbMtpTestSendEvent003===>make sure transfer timeout in PC, then start next test "
650 << std::endl;
651 }
652
653 /**
654 * @tc.number: SUB_USB_DeviceManager_HDI_MTPPTPTest_1700
655 * @tc.name: testHdiUsbMtpTestSendEvent004
656 * @tc.desc: Send event data by USB MTP/PTP driver. Cycle 10 times.
657 */
HWTEST_F(UsbfnMtpTestAdditional, testHdiUsbMtpTestSendEvent004, Function | MediumTest | Level1)658 HWTEST_F(UsbfnMtpTestAdditional, testHdiUsbMtpTestSendEvent004, Function | MediumTest | Level1)
659 {
660 ASSERT_TRUE(g_usbfnMtpInterface != nullptr);
661 std::vector<uint8_t> devData = {0x65, 0x76, 0x65, 0x6E, 0x74, 0x30, 0x30, 0x34};
662 int32_t ret;
663 int32_t c;
664 for (int i = 0; i < 5; i++) {
665 std::cout
666 << "testHdiUsbMtpTestSendEvent004===>use libusb in PC launch intr-in transfer(expect string=event004), "
667 << "press enter to continue" << std::endl;
668
669 while ((c = getchar()) != '\n' && c != EOF) {
670 }
671
672 ret = g_usbfnMtpInterface->SendEvent(devData);
673 ASSERT_EQ(0, ret);
674
675 PrintVector("event004", devData, true);
676 }
677 }
678
679 /**
680 * @tc.number: SUB_USB_DeviceManager_HDI_MTPPTPTest_1800
681 * @tc.name: testHdiUsbMtpTestRead001
682 * @tc.desc: Read data by USB MTP/PTP driver.
683 */
HWTEST_F(UsbfnMtpTestAdditional, testHdiUsbMtpTestRead001, Function | MediumTest | Level1)684 HWTEST_F(UsbfnMtpTestAdditional, testHdiUsbMtpTestRead001, Function | MediumTest | Level1)
685 {
686 ASSERT_TRUE(g_usbfnMtpInterface != nullptr);
687 std::vector<uint8_t> devData;
688
689 std::cout << "testHdiUsbMtpTestRead001===>use libusb in PC launch bulk-out transfer(size=" << 5
690 << "), press enter to continue" << std::endl;
691 int32_t c;
692 while ((c = getchar()) != '\n' && c != EOF) {
693 }
694
695 int32_t ret = g_usbfnMtpInterface->Read(devData);
696 ASSERT_EQ(ret, 0);
697 ASSERT_EQ(devData.size(), static_cast<size_t>(5));
698 }
699
700 /**
701 * @tc.number: SUB_USB_DeviceManager_HDI_MTPPTPTest_1900
702 * @tc.name: testHdiUsbMtpTestWrite001
703 * @tc.desc: Write data by USB MTP/PTP driver.devData.assign(BULK_IN_LESS_THEN_ONCE, 'r').
704 */
HWTEST_F(UsbfnMtpTestAdditional, testHdiUsbMtpTestWrite001, Function | MediumTest | Level1)705 HWTEST_F(UsbfnMtpTestAdditional, testHdiUsbMtpTestWrite001, Function | MediumTest | Level1)
706 {
707 ASSERT_TRUE(g_usbfnMtpInterface != nullptr);
708 uint32_t length = BULK_IN_LESS_THEN_ONCE;
709 std::vector<uint8_t> devData;
710 devData.assign(length, 'r');
711
712 std::cout << "testHdiUsbMtpTestWrite001===>use libusb in PC launch bulk-in transfer(expect=" << length
713 << "), press enter to continue" << std::endl;
714 int32_t c;
715 while ((c = getchar()) != '\n' && c != EOF) {
716 }
717
718 auto ret = g_usbfnMtpInterface->Write(devData);
719 ASSERT_EQ(ret, 0);
720 }
721
722 /**
723 * @tc.number: SUB_USB_DeviceManager_HDI_MTPPTPTest_2000
724 * @tc.name: testHdiUsbMtpTestWrite002
725 * @tc.desc: Write data by USB MTP/PTP driver.devData.assign(BULK_IN_ONCE_MAX_SIZE, 'r').
726 */
HWTEST_F(UsbfnMtpTestAdditional, testHdiUsbMtpTestWrite002, Function | MediumTest | Level1)727 HWTEST_F(UsbfnMtpTestAdditional, testHdiUsbMtpTestWrite002, Function | MediumTest | Level1)
728 {
729 ASSERT_TRUE(g_usbfnMtpInterface != nullptr);
730 uint32_t length = BULK_IN_ONCE_MAX_SIZE;
731 std::vector<uint8_t> devData;
732 devData.assign(length, 'r');
733 std::cout << "testHdiUsbMtpTestWrite002===>use libusb in PC launch bulk-in transfer(expect=" << length
734 << "), press enter to continue" << std::endl;
735 int32_t c;
736 while ((c = getchar()) != '\n' && c != EOF) {
737 }
738
739 auto ret = g_usbfnMtpInterface->Write(devData);
740 ASSERT_EQ(ret, 0);
741 }
742
743 /**
744 * @tc.number: SUB_USB_DeviceManager_HDI_MTPPTPTest_2100
745 * @tc.name: testHdiUsbMtpTestWrite003
746 * @tc.desc: Write data by USB MTP/PTP driver.devData.assign(BULK_IN_MORE_THEN_ONCE, 'r').
747 */
HWTEST_F(UsbfnMtpTestAdditional, testHdiUsbMtpTestWrite003, Function | MediumTest | Level1)748 HWTEST_F(UsbfnMtpTestAdditional, testHdiUsbMtpTestWrite003, Function | MediumTest | Level1)
749 {
750 ASSERT_TRUE(g_usbfnMtpInterface != nullptr);
751 uint32_t length = BULK_IN_MORE_THEN_ONCE;
752 std::vector<uint8_t> devData;
753 devData.assign(length, 'r');
754 std::cout << "testHdiUsbMtpTestWrite003===>use libusb in PC launch bulk-in transfer(expect=" << length
755 << "), press enter to continue" << std::endl;
756 int32_t c;
757 while ((c = getchar()) != '\n' && c != EOF) {
758 }
759
760 auto ret = g_usbfnMtpInterface->Write(devData);
761 ASSERT_EQ(ret, 0);
762 }
763
764 /**
765 * @tc.number: SUB_USB_DeviceManager_HDI_MTPPTPTest_2200
766 * @tc.name: testHdiUsbMtpTestWrite004
767 * @tc.desc: Write data by USB MTP/PTP driver.devData.assign(BULK_IN_MORE_THEN_ONCE, 'i').
768 */
HWTEST_F(UsbfnMtpTestAdditional, testHdiUsbMtpTestWrite004, Function | MediumTest | Level1)769 HWTEST_F(UsbfnMtpTestAdditional, testHdiUsbMtpTestWrite004, Function | MediumTest | Level1)
770 {
771 ASSERT_TRUE(g_usbfnMtpInterface != nullptr);
772 uint32_t length = BULK_IN_MORE_THEN_ONCE;
773 std::vector<uint8_t> devData;
774 devData.assign(length, 'i');
775 std::cout << "testHdiUsbMtpTestWrite004===>use libusb in PC launch bulk-in transfer(expect=" << length
776 << "), press enter to continue" << std::endl;
777 int32_t c;
778 while ((c = getchar()) != '\n' && c != EOF) {
779 }
780
781 auto ret = g_usbfnMtpInterface->Write(devData);
782 ASSERT_EQ(ret, 0);
783 }
784 /**
785 * @tc.number: SUB_USB_DeviceManager_HDI_MTPPTPTest_2300
786 * @tc.name: testHdiUsbMtpTestWrite005
787 * @tc.desc: Write data by USB MTP/PTP driver.Cycle 10 times.
788 */
HWTEST_F(UsbfnMtpTestAdditional, testHdiUsbMtpTestWrite005, Function | MediumTest | Level1)789 HWTEST_F(UsbfnMtpTestAdditional, testHdiUsbMtpTestWrite005, Function | MediumTest | Level1)
790 {
791 ASSERT_TRUE(g_usbfnMtpInterface != nullptr);
792 int32_t ret;
793 int i;
794 int32_t c;
795 std::vector<uint8_t> devData = {0x77, 0x72, 0x69, 0x74, 0x65, 0x30, 0x30, 0x35};
796 for (i = 0; i < 5; i++) {
797 std::cout << "testHdiUsbMtpTestWrite005===>use libusb in PC launch bulk-in transfer(expect string=write005), "
798 << "press enter to continue" << std::endl;
799
800 while ((c = getchar()) != '\n' && c != EOF) {
801 }
802
803 ret = g_usbfnMtpInterface->Write(devData);
804 ASSERT_EQ(ret, 0);
805
806 PrintVector("write005", devData, true);
807 }
808 }
809
810 /**
811 * @tc.number: SUB_USB_DeviceManager_HDI_MTPPTPTest_2400
812 * @tc.name: testHdiUsbMtpTestSendFile001
813 * @tc.desc: Send file by USB MTP/PTP driver.mfs.length = 1.
814 */
HWTEST_F(UsbfnMtpTestAdditional, testHdiUsbMtpTestSendFile001, Function | MediumTest | Level1)815 HWTEST_F(UsbfnMtpTestAdditional, testHdiUsbMtpTestSendFile001, Function | MediumTest | Level1)
816 {
817 ASSERT_TRUE(g_usbfnMtpInterface != nullptr);
818 ASSERT_TRUE(GetCurrentProcPath() == WORKED_UT_PATH);
819 g_fileTestCount++;
820 struct UsbFnMtpFileSlice mfs = g_mfs;
821 mfs.length = 1;
822 std::string filePathName = MTP_TEST_SEND_FILE;
823 EXPECT_TRUE(GenerateFile(filePathName, mfs.length));
824 std::cout << "testHdiUsbMtpTestSendFile001===>use libusb in PC launch bulk-in transfer(expect " << mfs.length
825 << "), press enter to continue" << std::endl;
826 int32_t c;
827 while ((c = getchar()) != '\n' && c != EOF) {
828 }
829
830 mfs.fd = open(filePathName.c_str(), O_CREAT | O_RDONLY);
831 ASSERT_GT(mfs.fd, 0);
832 auto ret = g_usbfnMtpInterface->SendFile(mfs);
833 close(mfs.fd);
834 ASSERT_EQ(ret, 0);
835 }
836
837 /**
838 * @tc.number: SUB_USB_DeviceManager_HDI_MTPPTPTest_2500
839 * @tc.name: testHdiUsbMtpTestSendFile002
840 * @tc.desc: Send file by USB MTP/PTP driver.mfs.length = 100.
841 */
HWTEST_F(UsbfnMtpTestAdditional, testHdiUsbMtpTestSendFile002, Function | MediumTest | Level1)842 HWTEST_F(UsbfnMtpTestAdditional, testHdiUsbMtpTestSendFile002, Function | MediumTest | Level1)
843 {
844 ASSERT_TRUE(g_usbfnMtpInterface != nullptr);
845 ASSERT_TRUE(GetCurrentProcPath() == WORKED_UT_PATH);
846 g_fileTestCount++;
847 struct UsbFnMtpFileSlice mfs = g_mfs;
848 mfs.length = 100;
849 std::string filePathName = MTP_TEST_SEND_FILE;
850 EXPECT_TRUE(GenerateFile(filePathName, mfs.length));
851 std::cout << "testHdiUsbMtpTestSendFile002===>use libusb in PC launch bulk-in transfer(expect " << mfs.length
852 << "), press enter to continue" << std::endl;
853 int32_t c;
854 while ((c = getchar()) != '\n' && c != EOF) {
855 }
856
857 mfs.fd = open(filePathName.c_str(), O_CREAT | O_RDONLY);
858 ASSERT_GT(mfs.fd, 0);
859 auto ret = g_usbfnMtpInterface->SendFile(mfs);
860 close(mfs.fd);
861 ASSERT_EQ(ret, 0);
862 }
863
864 /**
865 * @tc.number: SUB_USB_DeviceManager_HDI_MTPPTPTest_2600
866 * @tc.name: testHdiUsbMtpTestSendFile003
867 * @tc.desc: Send file by USB MTP/PTP driver.mfs.length = 1000.
868 */
HWTEST_F(UsbfnMtpTestAdditional, testHdiUsbMtpTestSendFile003, Function | MediumTest | Level1)869 HWTEST_F(UsbfnMtpTestAdditional, testHdiUsbMtpTestSendFile003, Function | MediumTest | Level1)
870 {
871 ASSERT_TRUE(g_usbfnMtpInterface != nullptr);
872 ASSERT_TRUE(GetCurrentProcPath() == WORKED_UT_PATH);
873 g_fileTestCount++;
874 struct UsbFnMtpFileSlice mfs = g_mfs;
875 mfs.length = 1000;
876 std::string filePathName = MTP_TEST_SEND_FILE;
877 EXPECT_TRUE(GenerateFile(filePathName, mfs.length));
878 std::cout << "testHdiUsbMtpTestSendFile003===>use libusb in PC launch bulk-in transfer(expect " << mfs.length
879 << "), press enter to continue" << std::endl;
880 int32_t c;
881 while ((c = getchar()) != '\n' && c != EOF) {
882 }
883
884 mfs.fd = open(filePathName.c_str(), O_CREAT | O_RDONLY);
885 ASSERT_GT(mfs.fd, 0);
886 auto ret = g_usbfnMtpInterface->SendFile(mfs);
887 close(mfs.fd);
888 ASSERT_EQ(ret, 0);
889 }
890
891 /**
892 * @tc.number: SUB_USB_DeviceManager_HDI_MTPPTPTest_2700
893 * @tc.name: testHdiUsbMtpTestSendFile004
894 * @tc.desc: Send file by USB MTP/PTP driver.mfs.length = 1024.
895 */
HWTEST_F(UsbfnMtpTestAdditional, testHdiUsbMtpTestSendFile004, Function | MediumTest | Level1)896 HWTEST_F(UsbfnMtpTestAdditional, testHdiUsbMtpTestSendFile004, Function | MediumTest | Level1)
897 {
898 ASSERT_TRUE(g_usbfnMtpInterface != nullptr);
899 ASSERT_TRUE(GetCurrentProcPath() == WORKED_UT_PATH);
900 g_fileTestCount++;
901 struct UsbFnMtpFileSlice mfs = g_mfs;
902 mfs.length = 1024;
903 std::string filePathName = MTP_TEST_SEND_FILE;
904 EXPECT_TRUE(GenerateFile(filePathName, mfs.length));
905 std::cout << "testHdiUsbMtpTestSendFile004===>use libusb in PC launch bulk-in transfer(expect " << mfs.length
906 << "), press enter to continue" << std::endl;
907 int32_t c;
908 while ((c = getchar()) != '\n' && c != EOF) {
909 }
910
911 mfs.fd = open(filePathName.c_str(), O_CREAT | O_RDONLY);
912 ASSERT_GT(mfs.fd, 0);
913 auto ret = g_usbfnMtpInterface->SendFile(mfs);
914 close(mfs.fd);
915 ASSERT_EQ(ret, 0);
916 }
917
918 /**
919 * @tc.number: SUB_USB_DeviceManager_HDI_MTPPTPTest_2800
920 * @tc.name: testHdiUsbMtpTestSendFile005
921 * @tc.desc: Send file by USB MTP/PTP driver.mfs.length = 255.
922 */
HWTEST_F(UsbfnMtpTestAdditional, testHdiUsbMtpTestSendFile005, Function | MediumTest | Level1)923 HWTEST_F(UsbfnMtpTestAdditional, testHdiUsbMtpTestSendFile005, Function | MediumTest | Level1)
924 {
925 ASSERT_TRUE(g_usbfnMtpInterface != nullptr);
926 ASSERT_TRUE(GetCurrentProcPath() == WORKED_UT_PATH);
927 g_fileTestCount++;
928 struct UsbFnMtpFileSlice mfs = g_mfs;
929 mfs.length = 255;
930 std::string filePathName = MTP_TEST_SEND_FILE;
931 EXPECT_TRUE(GenerateFile(filePathName, mfs.length));
932 std::cout << "testHdiUsbMtpTestSendFile005===>use libusb in PC launch bulk-in transfer(expect " << mfs.length
933 << "), press enter to continue" << std::endl;
934 int32_t c;
935 while ((c = getchar()) != '\n' && c != EOF) {
936 }
937
938 mfs.fd = open(filePathName.c_str(), O_CREAT | O_RDONLY);
939 ASSERT_GT(mfs.fd, 0);
940 auto ret = g_usbfnMtpInterface->SendFile(mfs);
941 close(mfs.fd);
942 ASSERT_EQ(ret, 0);
943 }
944
945 /**
946 * @tc.number: SUB_USB_DeviceManager_HDI_MTPPTPTest_2900
947 * @tc.name: testHdiUsbMtpTestSendFile006
948 * @tc.desc: Send file by USB MTP/PTP driver.mfs.length = 1 mfs.command = CMD_CODE_GET_DEVICE_INFO.
949 */
HWTEST_F(UsbfnMtpTestAdditional, testHdiUsbMtpTestSendFile006, Function | MediumTest | Level1)950 HWTEST_F(UsbfnMtpTestAdditional, testHdiUsbMtpTestSendFile006, Function | MediumTest | Level1)
951 {
952 ASSERT_TRUE(g_usbfnMtpInterface != nullptr);
953 ASSERT_TRUE(GetCurrentProcPath() == WORKED_UT_PATH);
954 g_fileTestCount++;
955 struct UsbFnMtpFileSlice mfs = g_mfs;
956 mfs.length = 1;
957 mfs.command = CMD_CODE_GET_DEVICE_INFO;
958 std::string filePathName = MTP_TEST_SEND_FILE;
959 EXPECT_TRUE(GenerateFile(filePathName, mfs.length));
960 std::cout << "testHdiUsbMtpTestSendFile006===>use libusb in PC launch bulk-in transfer(expect " << mfs.length
961 << "), press enter to continue" << std::endl;
962 int32_t c;
963 while ((c = getchar()) != '\n' && c != EOF) {
964 }
965
966 mfs.fd = open(filePathName.c_str(), O_CREAT | O_RDONLY);
967 ASSERT_GT(mfs.fd, 0);
968 auto ret = g_usbfnMtpInterface->SendFile(mfs);
969 close(mfs.fd);
970 ASSERT_EQ(ret, 0);
971 }
972
973 /**
974 * @tc.number: SUB_USB_DeviceManager_HDI_MTPPTPTest_3000
975 * @tc.name: testHdiUsbMtpTestSendFile007
976 * @tc.desc: Send file by USB MTP/PTP driver.mfs.length = 100 command = CMD_CODE_GET_DEVICE_INFO.
977 */
HWTEST_F(UsbfnMtpTestAdditional, testHdiUsbMtpTestSendFile007, Function | MediumTest | Level1)978 HWTEST_F(UsbfnMtpTestAdditional, testHdiUsbMtpTestSendFile007, Function | MediumTest | Level1)
979 {
980 ASSERT_TRUE(g_usbfnMtpInterface != nullptr);
981 ASSERT_TRUE(GetCurrentProcPath() == WORKED_UT_PATH);
982 g_fileTestCount++;
983 struct UsbFnMtpFileSlice mfs = g_mfs;
984 mfs.length = 100;
985 mfs.command = CMD_CODE_GET_DEVICE_INFO;
986 std::string filePathName = MTP_TEST_SEND_FILE;
987 EXPECT_TRUE(GenerateFile(filePathName, mfs.length));
988 std::cout << "testHdiUsbMtpTestSendFile007===>use libusb in PC launch bulk-in transfer(expect " << mfs.length
989 << "), press enter to continue" << std::endl;
990 int32_t c;
991 while ((c = getchar()) != '\n' && c != EOF) {
992 }
993
994 mfs.fd = open(filePathName.c_str(), O_CREAT | O_RDONLY);
995 ASSERT_GT(mfs.fd, 0);
996 auto ret = g_usbfnMtpInterface->SendFile(mfs);
997 close(mfs.fd);
998 ASSERT_EQ(ret, 0);
999 }
1000
1001 /**
1002 * @tc.number: SUB_USB_DeviceManager_HDI_MTPPTPTest_3100
1003 * @tc.name: testHdiUsbMtpTestSendFile008
1004 * @tc.desc: Send file by USB MTP/PTP driver.mfs.length = 1000 command = CMD_CODE_GET_DEVICE_INFO.
1005 */
HWTEST_F(UsbfnMtpTestAdditional, testHdiUsbMtpTestSendFile008, Function | MediumTest | Level1)1006 HWTEST_F(UsbfnMtpTestAdditional, testHdiUsbMtpTestSendFile008, Function | MediumTest | Level1)
1007 {
1008 ASSERT_TRUE(g_usbfnMtpInterface != nullptr);
1009 ASSERT_TRUE(GetCurrentProcPath() == WORKED_UT_PATH);
1010 g_fileTestCount++;
1011 struct UsbFnMtpFileSlice mfs = g_mfs;
1012 mfs.length = 1000;
1013 mfs.command = CMD_CODE_GET_DEVICE_INFO;
1014 std::string filePathName = MTP_TEST_SEND_FILE;
1015 EXPECT_TRUE(GenerateFile(filePathName, mfs.length));
1016 std::cout << "testHdiUsbMtpTestSendFile008===>use libusb in PC launch bulk-in transfer(expect " << mfs.length
1017 << "), press enter to continue" << std::endl;
1018 int32_t c;
1019 while ((c = getchar()) != '\n' && c != EOF) {
1020 }
1021
1022 mfs.fd = open(filePathName.c_str(), O_CREAT | O_RDONLY);
1023 ASSERT_GT(mfs.fd, 0);
1024 auto ret = g_usbfnMtpInterface->SendFile(mfs);
1025 close(mfs.fd);
1026 ASSERT_EQ(ret, 0);
1027 }
1028
1029 /**
1030 * @tc.number: SUB_USB_DeviceManager_HDI_MTPPTPTest_3200
1031 * @tc.name: testHdiUsbMtpTestSendFile009
1032 * @tc.desc: Send file by USB MTP/PTP driver.mfs.length = 1024 command = CMD_CODE_GET_DEVICE_INFO.
1033 */
HWTEST_F(UsbfnMtpTestAdditional, testHdiUsbMtpTestSendFile009, Function | MediumTest | Level1)1034 HWTEST_F(UsbfnMtpTestAdditional, testHdiUsbMtpTestSendFile009, Function | MediumTest | Level1)
1035 {
1036 ASSERT_TRUE(g_usbfnMtpInterface != nullptr);
1037 ASSERT_TRUE(GetCurrentProcPath() == WORKED_UT_PATH);
1038 g_fileTestCount++;
1039 struct UsbFnMtpFileSlice mfs = g_mfs;
1040 mfs.length = 1024;
1041 mfs.command = CMD_CODE_GET_DEVICE_INFO;
1042 std::string filePathName = MTP_TEST_SEND_FILE;
1043 EXPECT_TRUE(GenerateFile(filePathName, mfs.length));
1044 std::cout << "testHdiUsbMtpTestSendFile009===>use libusb in PC launch bulk-in transfer(expect " << mfs.length
1045 << "), press enter to continue" << std::endl;
1046 int32_t c;
1047 while ((c = getchar()) != '\n' && c != EOF) {
1048 }
1049
1050 mfs.fd = open(filePathName.c_str(), O_CREAT | O_RDONLY);
1051 ASSERT_GT(mfs.fd, 0);
1052 auto ret = g_usbfnMtpInterface->SendFile(mfs);
1053 close(mfs.fd);
1054 ASSERT_EQ(ret, 0);
1055 }
1056
1057 /**
1058 * @tc.number: SUB_USB_DeviceManager_HDI_MTPPTPTest_3300
1059 * @tc.name: testHdiUsbMtpTestSendFile010
1060 * @tc.desc: Send file by USB MTP/PTP driver.mfs.length = 255 command = CMD_CODE_GET_DEVICE_INFO.
1061 */
HWTEST_F(UsbfnMtpTestAdditional, testHdiUsbMtpTestSendFile010, Function | MediumTest | Level1)1062 HWTEST_F(UsbfnMtpTestAdditional, testHdiUsbMtpTestSendFile010, Function | MediumTest | Level1)
1063 {
1064 ASSERT_TRUE(g_usbfnMtpInterface != nullptr);
1065 ASSERT_TRUE(GetCurrentProcPath() == WORKED_UT_PATH);
1066 g_fileTestCount++;
1067 struct UsbFnMtpFileSlice mfs = g_mfs;
1068 mfs.length = 255;
1069 mfs.command = CMD_CODE_GET_DEVICE_INFO;
1070 std::string filePathName = MTP_TEST_SEND_FILE;
1071 EXPECT_TRUE(GenerateFile(filePathName, mfs.length));
1072 std::cout << "testHdiUsbMtpTestSendFile010===>use libusb in PC launch bulk-in transfer(expect " << mfs.length
1073 << "), press enter to continue" << std::endl;
1074 int32_t c;
1075 while ((c = getchar()) != '\n' && c != EOF) {
1076 }
1077
1078 mfs.fd = open(filePathName.c_str(), O_CREAT | O_RDONLY);
1079 ASSERT_GT(mfs.fd, 0);
1080 auto ret = g_usbfnMtpInterface->SendFile(mfs);
1081 close(mfs.fd);
1082 ASSERT_EQ(ret, 0);
1083 }
1084
1085 /**
1086 * @tc.number: SUB_USB_DeviceManager_HDI_MTPPTPTest_3400
1087 * @tc.name: testHdiUsbMtpTestSendFile011
1088 * @tc.desc: Send file by USB MTP/PTP driver.mfs.length = MTP_MAX_FILE_SIZE - 1.
1089 */
HWTEST_F(UsbfnMtpTestAdditional, testHdiUsbMtpTestSendFile011, Function | MediumTest | Level1)1090 HWTEST_F(UsbfnMtpTestAdditional, testHdiUsbMtpTestSendFile011, Function | MediumTest | Level1)
1091 {
1092 ASSERT_TRUE(g_usbfnMtpInterface != nullptr);
1093 ASSERT_TRUE(GetCurrentProcPath() == WORKED_UT_PATH);
1094 g_fileTestCount++;
1095 struct UsbFnMtpFileSlice mfs = g_mfs;
1096 mfs.length = MTP_MAX_FILE_SIZE - 1;
1097 std::string filePathName = MTP_TEST_SEND_FILE;
1098 EXPECT_TRUE(GenerateFile(filePathName, mfs.length));
1099 std::cout << "testHdiUsbMtpTestSendFile011===>use libusb in PC launch bulk-in transfer(speed, expect " << mfs.length
1100 << "), press enter to continue" << std::endl;
1101 int32_t c;
1102 while ((c = getchar()) != '\n' && c != EOF) {
1103 }
1104
1105 mfs.fd = open(filePathName.c_str(), O_CREAT | O_RDONLY);
1106 ASSERT_GT(mfs.fd, 0);
1107 auto ret = g_usbfnMtpInterface->SendFile(mfs);
1108 close(mfs.fd);
1109 ASSERT_EQ(0, ret);
1110 }
1111
1112 /**
1113 * @tc.number: SUB_USB_DeviceManager_HDI_MTPPTPTest_3500
1114 * @tc.name: testHdiUsbMtpTestSendFile012
1115 * @tc.desc: Send file by USB MTP/PTP driver.mfs.length = MTP_MAX_FILE_SIZE - 2.
1116 */
HWTEST_F(UsbfnMtpTestAdditional, testHdiUsbMtpTestSendFile012, Function | MediumTest | Level1)1117 HWTEST_F(UsbfnMtpTestAdditional, testHdiUsbMtpTestSendFile012, Function | MediumTest | Level1)
1118 {
1119 ASSERT_TRUE(g_usbfnMtpInterface != nullptr);
1120 ASSERT_TRUE(GetCurrentProcPath() == WORKED_UT_PATH);
1121 g_fileTestCount++;
1122 struct UsbFnMtpFileSlice mfs = g_mfs;
1123 mfs.length = MTP_MAX_FILE_SIZE - 2;
1124 std::string filePathName = MTP_TEST_SEND_FILE;
1125 EXPECT_TRUE(GenerateFile(filePathName, mfs.length));
1126 std::cout << "testHdiUsbMtpTestSendFile012===>use libusb in PC launch bulk-in transfer(speed, expect " << mfs.length
1127 << "), press enter to continue" << std::endl;
1128 int32_t c;
1129 while ((c = getchar()) != '\n' && c != EOF) {
1130 }
1131
1132 mfs.fd = open(filePathName.c_str(), O_CREAT | O_RDONLY);
1133 ASSERT_GT(mfs.fd, 0);
1134 auto ret = g_usbfnMtpInterface->SendFile(mfs);
1135 close(mfs.fd);
1136 ASSERT_EQ(0, ret);
1137 }
1138
1139 /**
1140 * @tc.number: SUB_USB_DeviceManager_HDI_MTPPTPTest_3600
1141 * @tc.name: testHdiUsbMtpTestSendFile013
1142 * @tc.desc: Send file by USB MTP/PTP driver.mfs.mfs.length = BULK_IN_LESS_THEN_ONCE mfs.command =
1143 * CMD_CODE_GET_DEVICE_INFO Cycle 10 times.
1144 */
HWTEST_F(UsbfnMtpTestAdditional, testHdiUsbMtpTestSendFile013, Function | MediumTest | Level1)1145 HWTEST_F(UsbfnMtpTestAdditional, testHdiUsbMtpTestSendFile013, Function | MediumTest | Level1)
1146 {
1147 ASSERT_TRUE(g_usbfnMtpInterface != nullptr);
1148 ASSERT_TRUE(GetCurrentProcPath() == WORKED_UT_PATH);
1149 g_fileTestCount++;
1150 struct UsbFnMtpFileSlice mfs = g_mfs;
1151 mfs.length = BULK_IN_LESS_THEN_ONCE;
1152 mfs.command = CMD_CODE_GET_DEVICE_INFO;
1153 std::string filePathName = MTP_TEST_SEND_FILE;
1154 EXPECT_TRUE(GenerateFile(filePathName, mfs.length));
1155 int32_t ret;
1156 int i;
1157 int32_t c;
1158 for (i = 0; i < 10; i++) {
1159 std::cout << "testHdiUsbMtpTestSendFile013===>use libusb in PC launch bulk-in transfer(expect "
1160 << mfs.length + MTP_PACKET_HEADER_SIZE << "), press enter to continue" << std::endl;
1161
1162 while ((c = getchar()) != '\n' && c != EOF) {
1163 }
1164 mfs.fd = open(filePathName.c_str(), O_CREAT | O_RDONLY);
1165 ASSERT_GT(mfs.fd, 0);
1166
1167 ret = g_usbfnMtpInterface->SendFile(mfs);
1168 close(mfs.fd);
1169 ASSERT_EQ(0, ret);
1170 }
1171 }
1172
1173 /**
1174 * @tc.number: SUB_USB_DeviceManager_HDI_MTPPTPTest_3700
1175 * @tc.name: testHdiUsbMtpTestSendFile014
1176 * @tc.desc: Send file by USB MTP/PTP driver.mfs.length = 1 mfs.command = 1.
1177 */
HWTEST_F(UsbfnMtpTestAdditional, testHdiUsbMtpTestSendFile014, Function | MediumTest | Level1)1178 HWTEST_F(UsbfnMtpTestAdditional, testHdiUsbMtpTestSendFile014, Function | MediumTest | Level1)
1179 {
1180 ASSERT_TRUE(g_usbfnMtpInterface != nullptr);
1181 ASSERT_TRUE(GetCurrentProcPath() == WORKED_UT_PATH);
1182 g_fileTestCount++;
1183 struct UsbFnMtpFileSlice mfs = g_mfs;
1184 mfs.length = 1;
1185 mfs.command = 1;
1186 std::string filePathName = MTP_TEST_SEND_FILE;
1187 EXPECT_TRUE(GenerateFile(filePathName, mfs.length));
1188 std::cout << "testHdiUsbMtpTestSendFile014===>use libusb in PC launch bulk-in transfer(expect " << mfs.length
1189 << "), press enter to continue" << std::endl;
1190 int32_t c;
1191 while ((c = getchar()) != '\n' && c != EOF) {
1192 }
1193
1194 mfs.fd = open(filePathName.c_str(), O_CREAT | O_RDONLY);
1195 ASSERT_GT(mfs.fd, 0);
1196 auto ret = g_usbfnMtpInterface->SendFile(mfs);
1197 close(mfs.fd);
1198 ASSERT_EQ(ret, 0);
1199 }
1200
1201 /**
1202 * @tc.number: SUB_USB_DeviceManager_HDI_MTPPTPTest_3800
1203 * @tc.name: testHdiUsbMtpTestSendFile015
1204 * @tc.desc: Send file by USB MTP/PTP driver.mfs.length = 100 mfs.command = 100.
1205 */
HWTEST_F(UsbfnMtpTestAdditional, testHdiUsbMtpTestSendFile015, Function | MediumTest | Level1)1206 HWTEST_F(UsbfnMtpTestAdditional, testHdiUsbMtpTestSendFile015, Function | MediumTest | Level1)
1207 {
1208 ASSERT_TRUE(g_usbfnMtpInterface != nullptr);
1209 ASSERT_TRUE(GetCurrentProcPath() == WORKED_UT_PATH);
1210 g_fileTestCount++;
1211 struct UsbFnMtpFileSlice mfs = g_mfs;
1212 mfs.length = 100;
1213 mfs.command = 100;
1214 std::string filePathName = MTP_TEST_SEND_FILE;
1215 EXPECT_TRUE(GenerateFile(filePathName, mfs.length));
1216 std::cout << "testHdiUsbMtpTestSendFile015===>use libusb in PC launch bulk-in transfer(expect " << mfs.length
1217 << "), press enter to continue" << std::endl;
1218 int32_t c;
1219 while ((c = getchar()) != '\n' && c != EOF) {
1220 }
1221
1222 mfs.fd = open(filePathName.c_str(), O_CREAT | O_RDONLY);
1223 ASSERT_GT(mfs.fd, 0);
1224 auto ret = g_usbfnMtpInterface->SendFile(mfs);
1225 close(mfs.fd);
1226 ASSERT_EQ(ret, 0);
1227 }
1228
1229 /**
1230 * @tc.number: SUB_USB_DeviceManager_HDI_MTPPTPTest_3900
1231 * @tc.name: testHdiUsbMtpTestSendFile016
1232 * @tc.desc: Send file by USB MTP/PTP driver.mfs.length = 1000 mfs.command = 1000.
1233 */
HWTEST_F(UsbfnMtpTestAdditional, testHdiUsbMtpTestSendFile016, Function | MediumTest | Level1)1234 HWTEST_F(UsbfnMtpTestAdditional, testHdiUsbMtpTestSendFile016, Function | MediumTest | Level1)
1235 {
1236 ASSERT_TRUE(g_usbfnMtpInterface != nullptr);
1237 ASSERT_TRUE(GetCurrentProcPath() == WORKED_UT_PATH);
1238 g_fileTestCount++;
1239 struct UsbFnMtpFileSlice mfs = g_mfs;
1240 mfs.length = 1000;
1241 mfs.command = 1000;
1242 std::string filePathName = MTP_TEST_SEND_FILE;
1243 EXPECT_TRUE(GenerateFile(filePathName, mfs.length));
1244 std::cout << "testHdiUsbMtpTestSendFile016===>use libusb in PC launch bulk-in transfer(expect " << mfs.length
1245 << "), press enter to continue" << std::endl;
1246 int32_t c;
1247 while ((c = getchar()) != '\n' && c != EOF) {
1248 }
1249
1250 mfs.fd = open(filePathName.c_str(), O_CREAT | O_RDONLY);
1251 ASSERT_GT(mfs.fd, 0);
1252 auto ret = g_usbfnMtpInterface->SendFile(mfs);
1253 close(mfs.fd);
1254 ASSERT_EQ(ret, 0);
1255 }
1256
1257 /**
1258 * @tc.number: SUB_USB_DeviceManager_HDI_MTPPTPTest_4000
1259 * @tc.name: testHdiUsbMtpTestSendFile017
1260 * @tc.desc: Send file by USB MTP/PTP driver.mfs.length = 1024 mfs.command = 1024.
1261 */
HWTEST_F(UsbfnMtpTestAdditional, testHdiUsbMtpTestSendFile017, Function | MediumTest | Level1)1262 HWTEST_F(UsbfnMtpTestAdditional, testHdiUsbMtpTestSendFile017, Function | MediumTest | Level1)
1263 {
1264 ASSERT_TRUE(g_usbfnMtpInterface != nullptr);
1265 ASSERT_TRUE(GetCurrentProcPath() == WORKED_UT_PATH);
1266 g_fileTestCount++;
1267 struct UsbFnMtpFileSlice mfs = g_mfs;
1268 mfs.length = 1024;
1269 mfs.command = 1024;
1270 std::string filePathName = MTP_TEST_SEND_FILE;
1271 EXPECT_TRUE(GenerateFile(filePathName, mfs.length));
1272 std::cout << "testHdiUsbMtpTestSendFile017===>use libusb in PC launch bulk-in transfer(expect " << mfs.length
1273 << "), press enter to continue" << std::endl;
1274 int32_t c;
1275 while ((c = getchar()) != '\n' && c != EOF) {
1276 }
1277
1278 mfs.fd = open(filePathName.c_str(), O_CREAT | O_RDONLY);
1279 ASSERT_GT(mfs.fd, 0);
1280 auto ret = g_usbfnMtpInterface->SendFile(mfs);
1281 close(mfs.fd);
1282 ASSERT_EQ(ret, 0);
1283 }
1284
1285 /**
1286 * @tc.number: SUB_USB_DeviceManager_HDI_MTPPTPTest_4100
1287 * @tc.name: testHdiUsbMtpTestSendFile018
1288 * @tc.desc: Send file by USB MTP/PTP driver.mfs.length = 255 mfs.command = 255.
1289 */
HWTEST_F(UsbfnMtpTestAdditional, testHdiUsbMtpTestSendFile018, Function | MediumTest | Level1)1290 HWTEST_F(UsbfnMtpTestAdditional, testHdiUsbMtpTestSendFile018, Function | MediumTest | Level1)
1291 {
1292 ASSERT_TRUE(g_usbfnMtpInterface != nullptr);
1293 ASSERT_TRUE(GetCurrentProcPath() == WORKED_UT_PATH);
1294 g_fileTestCount++;
1295 struct UsbFnMtpFileSlice mfs = g_mfs;
1296 mfs.length = 255;
1297 mfs.command = 255;
1298 std::string filePathName = MTP_TEST_SEND_FILE;
1299 EXPECT_TRUE(GenerateFile(filePathName, mfs.length));
1300 std::cout << "testHdiUsbMtpTestSendFile018===>use libusb in PC launch bulk-in transfer(expect " << mfs.length
1301 << "), press enter to continue" << std::endl;
1302 int32_t c;
1303 while ((c = getchar()) != '\n' && c != EOF) {
1304 }
1305
1306 mfs.fd = open(filePathName.c_str(), O_CREAT | O_RDONLY);
1307 ASSERT_GT(mfs.fd, 0);
1308 auto ret = g_usbfnMtpInterface->SendFile(mfs);
1309 close(mfs.fd);
1310 ASSERT_EQ(ret, 0);
1311 }
1312
1313 /**
1314 * @tc.number: SUB_USB_DeviceManager_HDI_MTPPTPTest_4200
1315 * @tc.name: testHdiUsbMtpTestSendFile019
1316 * @tc.desc: Send file by USB MTP/PTP driver.mfs.length = 200.mfs.command = 200.
1317 */
HWTEST_F(UsbfnMtpTestAdditional, testHdiUsbMtpTestSendFile019, Function | MediumTest | Level1)1318 HWTEST_F(UsbfnMtpTestAdditional, testHdiUsbMtpTestSendFile019, Function | MediumTest | Level1)
1319 {
1320 ASSERT_TRUE(g_usbfnMtpInterface != nullptr);
1321 ASSERT_TRUE(GetCurrentProcPath() == WORKED_UT_PATH);
1322 g_fileTestCount++;
1323 struct UsbFnMtpFileSlice mfs = g_mfs;
1324 mfs.length = 200;
1325 mfs.command = 200;
1326 std::string filePathName = MTP_TEST_SEND_FILE;
1327 EXPECT_TRUE(GenerateFile(filePathName, mfs.length));
1328 std::cout << "testHdiUsbMtpTestSendFile019===>use libusb in PC launch bulk-in transfer(expect " << mfs.length
1329 << "), press enter to continue" << std::endl;
1330 int32_t c;
1331 while ((c = getchar()) != '\n' && c != EOF) {
1332 }
1333
1334 mfs.fd = open(filePathName.c_str(), O_CREAT | O_RDONLY);
1335 ASSERT_GT(mfs.fd, 0);
1336 auto ret = g_usbfnMtpInterface->SendFile(mfs);
1337 close(mfs.fd);
1338 ASSERT_EQ(ret, 0);
1339 }
1340
1341 /**
1342 * @tc.number: SUB_USB_DeviceManager_HDI_MTPPTPTest_4300
1343 * @tc.name: testHdiUsbMtpTestStart001
1344 * @tc.desc: Opens a USB MTP/PTP driver.
1345 */
HWTEST_F(UsbfnMtpTestAdditional, testHdiUsbMtpTestStart001, Function | MediumTest | Level1)1346 HWTEST_F(UsbfnMtpTestAdditional, testHdiUsbMtpTestStart001, Function | MediumTest | Level1)
1347 {
1348 ASSERT_TRUE(g_usbfnMtpInterface != nullptr);
1349 auto ret = g_usbfnMtpInterface->Start();
1350 ASSERT_EQ(0, ret);
1351 ret = g_usbfnMtpInterface->Stop();
1352 ASSERT_EQ(0, ret);
1353 }
1354
1355 /**
1356 * @tc.number: SUB_USB_DeviceManager_HDI_MTPPTPTest_4400
1357 * @tc.name: testHdiUsbMtpTestStop001
1358 * @tc.desc: Closes a USB MTP/PTP driver.
1359 */
HWTEST_F(UsbfnMtpTestAdditional, testHdiUsbMtpTestStop001, Function | MediumTest | Level1)1360 HWTEST_F(UsbfnMtpTestAdditional, testHdiUsbMtpTestStop001, Function | MediumTest | Level1)
1361 {
1362 ASSERT_TRUE(g_usbfnMtpInterface != nullptr);
1363 int32_t ret;
1364 int i;
1365 for (i = 0; i < 10; i++) {
1366 ret = g_usbfnMtpInterface->Start();
1367 ASSERT_EQ(0, ret);
1368 ret = g_usbfnMtpInterface->Stop();
1369 ASSERT_EQ(0, ret);
1370 }
1371 }
1372 } // namespace
1373