1 /*
2 * Copyright (C) 2022 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 "medialibrary_mtp_unit_test.h"
17 #include <iomanip>
18 #include <unistd.h>
19 #include "mtp_driver.h"
20 #include "media_log.h"
21 #include "mtp_operation.h"
22 #include "mtp_service.h"
23 #include "mtp_test.h"
24
25 using namespace std;
26 using namespace testing::ext;
27
28 namespace OHOS {
29 namespace Media {
30 // MTP_OPERATION_OPEN_SESSION_CODE
31 static std::vector<uint8_t> testData_open = { 0x0C, 0x00, 0x00, 0x00, 0x01, 0x00, 0x02, 0x10, 0x00, 0x00, 0x00, 0x00};
32
SetUpTestCase(void)33 void MediaLibraryMTPUnitTest::SetUpTestCase(void) {}
TearDownTestCase(void)34 void MediaLibraryMTPUnitTest::TearDownTestCase(void) {}
35 // SetUp:Execute before each test case
SetUp()36 void MediaLibraryMTPUnitTest::SetUp() {}
TearDown(void)37 void MediaLibraryMTPUnitTest::TearDown(void) {}
38
39 /*
40 * Feature: MediaLibraryMTP
41 * Function:
42 * SubFunction: NA
43 * FunctionPoints: NA
44 * EnvConditions: NA
45 * CaseDescription: MTP_OPERATION_OPEN_SESSION_CODE
46 */
47 HWTEST_F(MediaLibraryMTPUnitTest, medialibrary_MTP_message_testlevel0_001, TestSize.Level0)
48 {
49 std::shared_ptr<OHOS::Media::MtpTest> mtpTest = OHOS::Media::MtpTest::GetInstance();
50 std::shared_ptr<MtpOperation> operationPtr_;
51 if (operationPtr_ == nullptr) {
52 operationPtr_ = make_shared<MtpOperation>();
53 }
54
55 // set test data
56 mtpTest->setOutBuffer(testData_open);
57 // execute
58 operationPtr_->Execute();
59 // get output
60 std::vector<uint8_t> output;
61 mtpTest->getOutBuffer(output);
62 for (auto && i : output) {
63 MEDIA_DEBUG_LOG("i: %{public}d", i);
64 }
65 std::vector<uint8_t> targetData = { 12, 0, 0, 0, 3, 0, 1, 32, 0, 0, 0, 0 };
66
67 MEDIA_DEBUG_LOG("MtpDriver::output.size: %{public}d", output.size());
68 EXPECT_EQ(output == targetData, true);
69 }
70
71 /*
72 * Feature: MediaLibraryMTP
73 * Function:
74 * SubFunction: NA
75 * FunctionPoints: NA
76 * EnvConditions: NA
77 * CaseDescription: MTP_OPERATION_GET_DEVICE_INFO_CODE
78 */
79 HWTEST_F(MediaLibraryMTPUnitTest, medialibrary_MTP_message_testlevel0_002, TestSize.Level0)
80 {
81 std::shared_ptr<OHOS::Media::MtpTest> mtpTest = OHOS::Media::MtpTest::GetInstance();
82 std::shared_ptr<MtpOperation> operationPtr_;
83 if (operationPtr_ == nullptr) {
84 operationPtr_ = make_shared<MtpOperation>();
85 }
86
87 // MTP_OPERATION_GET_DEVICE_INFO_CODE
88 static std::vector<uint8_t> testData = { 0x0C, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x10, 0x01, 0x00, 0x00, 0x00 };
89 // set test data
90 mtpTest->setOutBuffer(testData);
91 // execute
92 operationPtr_->Execute();
93 // get output
94 std::vector<uint8_t> output;
95 mtpTest->getOutBuffer(output);
96 for (auto && i : output) {
97 MEDIA_DEBUG_LOG("i: %{public}d", i);
98 }
99 std::vector<uint8_t> targetData = { 12, 0, 0, 0, 3, 0, 1, 32, 1, 0, 0, 0 };
100
101 MEDIA_DEBUG_LOG("MtpDriver::output.size: %{public}d", output.size());
102 EXPECT_EQ(output == targetData, true);
103 }
104
105 /*
106 * Feature: MediaLibraryMTP
107 * Function:
108 * SubFunction: NA
109 * FunctionPoints: NA
110 * EnvConditions: NA
111 * CaseDescription: MTP_OPERATION_GET_STORAGE_IDS_CODE
112 */
113 HWTEST_F(MediaLibraryMTPUnitTest, medialibrary_MTP_message_testlevel0_003, TestSize.Level0)
114 {
115 std::shared_ptr<OHOS::Media::MtpTest> mtpTest = OHOS::Media::MtpTest::GetInstance();
116 std::shared_ptr<MtpOperation> operationPtr_;
117 if (operationPtr_ == nullptr) {
118 operationPtr_ = make_shared<MtpOperation>();
119 }
120
121 // set test data
122 mtpTest->setOutBuffer(testData_open);
123 // execute
124 operationPtr_->Execute();
125
126 // MTP_OPERATION_GET_STORAGE_IDS_CODE
127 static std::vector<uint8_t> testData = { 0x0C, 0x00, 0x00, 0x00, 0x01, 0x00, 0x04, 0x10, 0x21, 0x00, 0x00, 0x00 };
128 // set test data
129 mtpTest->setOutBuffer(testData);
130 // execute
131 operationPtr_->Execute();
132 // get output
133 std::vector<uint8_t> output;
134 mtpTest->getOutBuffer(output);
135 for (auto && i : output) {
136 MEDIA_DEBUG_LOG("i: %{public}d", i);
137 }
138 std::vector<uint8_t> targetData = { 12, 0, 0, 0, 3, 0, 1, 32, 33, 0, 0, 0 };
139
140 MEDIA_DEBUG_LOG("MtpDriver::output.size: %{public}d", output.size());
141 EXPECT_EQ(output == targetData, true);
142 }
143 /*
144 * Feature: MediaLibraryMTP
145 * Function:
146 * SubFunction: NA
147 * FunctionPoints: NA
148 * EnvConditions: NA
149 * CaseDescription: MTP_OPERATION_GET_STORAGE_INFO_CODE
150 */
151 HWTEST_F(MediaLibraryMTPUnitTest, medialibrary_MTP_message_testlevel0_004, TestSize.Level0)
152 {
153 std::shared_ptr<OHOS::Media::MtpTest> mtpTest = OHOS::Media::MtpTest::GetInstance();
154 std::shared_ptr<MtpOperation> operationPtr_;
155 if (operationPtr_ == nullptr) {
156 operationPtr_ = make_shared<MtpOperation>();
157 }
158
159 // set test data
160 mtpTest->setOutBuffer(testData_open);
161 // execute
162 operationPtr_->Execute();
163
164 // MTP_OPERATION_GET_STORAGE_IDS_CODE
165 static std::vector<uint8_t> testData_1 =
166 { 0x0C, 0x00, 0x00, 0x00, 0x01, 0x00, 0x04, 0x10, 0x21, 0x00, 0x00, 0x00 };
167 // set test data
168 mtpTest->setOutBuffer(testData_1);
169 // execute
170 operationPtr_->Execute();
171 // MTP_OPERATION_GET_STORAGE_INFO_CODE
172 static std::vector<uint8_t> testData =
173 { 0x10, 0x00, 0x00, 0x00, 0x01, 0x00, 0x05, 0x10, 0x8C, 0x07, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00 };
174 mtpTest->setOutBuffer(testData);
175 // execute
176 operationPtr_->Execute();
177 // get output
178 std::vector<uint8_t> output;
179 mtpTest->getOutBuffer(output);
180 for (auto && i : output) {
181 MEDIA_DEBUG_LOG("i: %{public}d", i);
182 }
183 std::vector<uint8_t> targetData = { 12, 0, 0, 0, 3, 0, 1, 32, 140, 7, 0, 0 };
184
185 MEDIA_DEBUG_LOG("MtpDriver::output.size: %{public}d", output.size());
186 EXPECT_EQ(output == targetData, true);
187 }
188
189 /*
190 * Feature: MediaLibraryMTP
191 * Function:
192 * SubFunction: NA
193 * FunctionPoints: NA
194 * EnvConditions: NA
195 * CaseDescription: MTP_OPERATION_GET_OBJECT_HANDLES_CODE
196 */
197 HWTEST_F(MediaLibraryMTPUnitTest, medialibrary_MTP_message_testlevel0_005, TestSize.Level0)
198 {
199 std::shared_ptr<OHOS::Media::MtpTest> mtpTest = OHOS::Media::MtpTest::GetInstance();
200 std::shared_ptr<MtpOperation> operationPtr_;
201 if (operationPtr_ == nullptr) {
202 operationPtr_ = make_shared<MtpOperation>();
203 }
204
205 mtpTest->setOutBuffer(testData_open);
206 // execute
207 operationPtr_->Execute();
208
209 // MTP_OPERATION_GET_STORAGE_IDS_CODE
210 static std::vector<uint8_t> testData_1 =
211 { 0x0C, 0x00, 0x00, 0x00, 0x01, 0x00, 0x04, 0x10, 0x21, 0x00, 0x00, 0x00 };
212 // set test data
213 mtpTest->setOutBuffer(testData_1);
214 // execute
215 operationPtr_->Execute();
216
217 // MTP_OPERATION_GET_STORAGE_INFO_CODE
218 static std::vector<uint8_t> testData_2 =
219 { 0x10, 0x00, 0x00, 0x00, 0x01, 0x00, 0x05, 0x10, 0x8C, 0x07, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00 };
220 mtpTest->setOutBuffer(testData_2);
221 // execute
222 operationPtr_->Execute();
223
224 // MTP_OPERATION_GET_OBJECT_HANDLES_CODE
225 static std::vector<uint8_t> testData = { 0x18, 0x00, 0x00, 0x00, 0x01, 0x00, 0x07, 0x10, 0x23,
226 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff };
227 mtpTest->setOutBuffer(testData);
228 // execute
229 operationPtr_->Execute();
230
231 // get output
232 std::vector<uint8_t> output;
233 mtpTest->getOutBuffer(output);
234 for (auto && i : output) {
235 MEDIA_DEBUG_LOG("i: %{public}d", i);
236 }
237 std::vector<uint8_t> targetData = { 12, 0, 0, 0, 3, 0, 1, 32, 35, 0, 0, 0 };
238
239 MEDIA_DEBUG_LOG("MtpDriver::output.size: %{public}d", output.size());
240 EXPECT_EQ(output == targetData, true);
241 }
242
243 /*
244 * Feature: MediaLibraryMTP
245 * Function:
246 * SubFunction: NA
247 * FunctionPoints: NA
248 * EnvConditions: NA
249 * CaseDescription: MTP_OPERATION_GET_DEVICE_PROP_DESC_CODE
250 */
251 HWTEST_F(MediaLibraryMTPUnitTest, medialibrary_MTP_message_testlevel0_006, TestSize.Level0)
252 {
253 std::shared_ptr<OHOS::Media::MtpTest> mtpTest = OHOS::Media::MtpTest::GetInstance();
254 std::shared_ptr<MtpOperation> operationPtr_;
255 if (operationPtr_ == nullptr) {
256 operationPtr_ = make_shared<MtpOperation>();
257 }
258
259 // set test data
260 mtpTest->setOutBuffer(testData_open);
261 // execute
262 operationPtr_->Execute();
263
264 // MTP_OPERATION_GET_DEVICE_PROP_DESC_CODE
265 static std::vector<uint8_t> testData =
266 { 0x10, 0x00, 0x00, 0x00, 0x01, 0x00, 0x14, 0x10, 0x05, 0x00, 0x00, 0x00, 0x02, 0xD4, 0x00, 0x00 };
267 mtpTest->setOutBuffer(testData);
268 // execute
269 operationPtr_->Execute();
270
271 // get output
272 std::vector<uint8_t> output;
273 mtpTest->getOutBuffer(output);
274 for (auto&& i : output) {
275 MEDIA_DEBUG_LOG("i: %{public}d", i);
276 }
277 std::vector<uint8_t> targetData = { 12, 0, 0, 0, 3, 0, 1, 32, 5, 0, 0, 0 };
278
279 MEDIA_DEBUG_LOG("MtpDriver::output.size: %{public}d", output.size());
280 EXPECT_EQ(output == targetData, true);
281 }
282
283 /*
284 * Feature: MediaLibraryMTP
285 * Function:
286 * SubFunction: NA
287 * FunctionPoints: NA
288 * EnvConditions: NA
289 * CaseDescription: MTP_OPERATION_GET_OBJECT_PROP_DESC_CODE
290 */
291 HWTEST_F(MediaLibraryMTPUnitTest, medialibrary_MTP_message_testlevel0_007, TestSize.Level0)
292 {
293 std::shared_ptr<OHOS::Media::MtpTest> mtpTest = OHOS::Media::MtpTest::GetInstance();
294 std::shared_ptr<MtpOperation> operationPtr_;
295 if (operationPtr_ == nullptr) {
296 operationPtr_ = make_shared<MtpOperation>();
297 }
298
299 // set test data
300 mtpTest->setOutBuffer(testData_open);
301 // execute
302 operationPtr_->Execute();
303
304 // MTP_OPERATION_GET_OBJECT_PROP_DESC_CODE
305 static std::vector<uint8_t> testData = { 0x14, 0x00, 0x00, 0x00, 0x01, 0x00, 0x02, 0x98, 0x24, 0x00,
306 0x00, 0x00, 0x02, 0xDC, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00 };
307 mtpTest->setOutBuffer(testData);
308 operationPtr_->Execute();
309
310 // get output
311 std::vector<uint8_t> output;
312 mtpTest->getOutBuffer(output);
313 for (auto&& i : output) {
314 MEDIA_DEBUG_LOG("i: %{public}d", i);
315 }
316 std::vector<uint8_t> targetData = { 12, 0, 0, 0, 3, 0, 1, 32, 36, 0, 0, 0 };
317
318 MEDIA_DEBUG_LOG("MtpDriver::output.size: %{public}d", output.size());
319 EXPECT_EQ(output == targetData, true);
320 }
321
322 /*
323 * Feature: MediaLibraryMTP
324 * Function:
325 * SubFunction: NA
326 * FunctionPoints: NA
327 * EnvConditions: NA
328 * CaseDescription: MTP_OPERATION_GET_OBJECT_PROPS_SUPPORTED_CODE
329 */
330 HWTEST_F(MediaLibraryMTPUnitTest, medialibrary_MTP_message_testlevel0_008, TestSize.Level0)
331 {
332 std::shared_ptr<OHOS::Media::MtpTest> mtpTest = OHOS::Media::MtpTest::GetInstance();
333 std::shared_ptr<MtpOperation> operationPtr_;
334 if (operationPtr_ == nullptr) {
335 operationPtr_ = make_shared<MtpOperation>();
336 }
337
338 // set test data
339 mtpTest->setOutBuffer(testData_open);
340 // execute
341 operationPtr_->Execute();
342
343 // MTP_OPERATION_GET_OBJECT_PROPS_SUPPORTED_CODE, MTP_FORMAT_EXIF_JPEG_CODE
344 static std::vector<uint8_t> testData =
345 { 0x10, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x98, 0x20, 0x00, 0x00, 0x00, 0x01, 0x38, 0x00, 0x00 };
346 mtpTest->setOutBuffer(testData);
347 operationPtr_->Execute();
348
349 // get output
350 std::vector<uint8_t> output;
351 mtpTest->getOutBuffer(output);
352 for (auto && i : output) {
353 MEDIA_DEBUG_LOG("i: %{public}d", i);
354 }
355 std::vector<uint8_t> targetData = { 40, 0, 0, 0, 3, 0, 1, 32, 32, 0, 0, 0, 12, 0, 0, 0, 1, 220, 2, 220,
356 3, 220, 4, 220, 7, 220, 9, 220, 11, 220, 65, 220, 68, 220, 224, 220, 78, 220, 72, 220 };
357
358 MEDIA_DEBUG_LOG("MtpDriver::output.size: %{public}d", output.size());
359 EXPECT_EQ(output == targetData, true);
360 }
361
362 /*
363 * Feature: MediaLibraryMTP
364 * Function:
365 * SubFunction: NA
366 * FunctionPoints: NA
367 * EnvConditions: NA
368 * CaseDescription: MTP_OPERATION_GET_OBJECT_PROP_VALUE_CODE
369 */
370 HWTEST_F(MediaLibraryMTPUnitTest, medialibrary_MTP_message_testlevel0_009, TestSize.Level0)
371 {
372 std::shared_ptr<OHOS::Media::MtpTest> mtpTest = OHOS::Media::MtpTest::GetInstance();
373 std::shared_ptr<MtpOperation> operationPtr_;
374 if (operationPtr_ == nullptr) {
375 operationPtr_ = make_shared<MtpOperation>();
376 }
377
378 // set test data
379 mtpTest->setOutBuffer(testData_open);
380 // execute
381 operationPtr_->Execute();
382
383 // MTP_OPERATION_GET_OBJECT_PROP_VALUE_CODE
384 static std::vector<uint8_t> testData = { 0x14, 0x00, 0x00, 0x00, 0x01, 0x00, 0x03, 0x98, 0x40, 0x00, 0x00,
385 0x00, 0x89, 0x00, 0x00, 0x00, 0x01, 0xDC, 0x00, 0x00 };
386 mtpTest->setOutBuffer(testData);
387 operationPtr_->Execute();
388
389 // get output
390 std::vector<uint8_t> output;
391 mtpTest->getOutBuffer(output);
392 for (auto&& i : output) {
393 MEDIA_DEBUG_LOG("i: %{public}d", i);
394 }
395 std::vector<uint8_t> targetData = { 12, 0, 0, 0, 3, 0, 1, 32, 64, 0, 0, 0 };
396
397 MEDIA_DEBUG_LOG("MtpDriver::output.size: %{public}d", output.size());
398 EXPECT_EQ(output == targetData, true);
399 }
400
401 /*
402 * Feature: MediaLibraryMTP
403 * Function:
404 * SubFunction: NA
405 * FunctionPoints: NA
406 * EnvConditions: NA
407 * CaseDescription: MTP_OPERATION_SET_OBJECT_PROP_VALUE_CODE
408 */
409 HWTEST_F(MediaLibraryMTPUnitTest, medialibrary_MTP_message_testlevel0_010, TestSize.Level0)
410 {
411 std::shared_ptr<OHOS::Media::MtpTest> mtpTest = OHOS::Media::MtpTest::GetInstance();
412 std::shared_ptr<MtpOperation> operationPtr_;
413 if (operationPtr_ == nullptr) {
414 operationPtr_ = make_shared<MtpOperation>();
415 }
416
417 mtpTest->setOutBuffer(testData_open);
418 // execute
419 operationPtr_->Execute();
420
421 // MTP_OPERATION_GET_STORAGE_IDS_CODE
422 static std::vector<uint8_t> testData_1 =
423 { 0x0C, 0x00, 0x00, 0x00, 0x01, 0x00, 0x04, 0x10, 0x21, 0x00, 0x00, 0x00 };
424 // set test data
425 mtpTest->setOutBuffer(testData_1);
426 // execute
427 operationPtr_->Execute();
428
429 // MTP_OPERATION_GET_STORAGE_INFO_CODE
430 static std::vector<uint8_t> testData_2 =
431 { 0x10, 0x00, 0x00, 0x00, 0x01, 0x00, 0x05, 0x10, 0x8C, 0x07, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00 };
432 mtpTest->setOutBuffer(testData_2);
433 // execute
434 operationPtr_->Execute();
435
436 // MTP_OPERATION_GET_OBJECT_HANDLES_CODE
437 static std::vector<uint8_t> testData_3 = { 0x18, 0x00, 0x00, 0x00, 0x01, 0x00, 0x07, 0x10, 0x23, 0x00,
438 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff };
439 mtpTest->setOutBuffer(testData_3);
440 // execute
441 operationPtr_->Execute();
442
443 // MTP_OPERATION_SET_OBJECT_PROP_VALUE_CODE
444 static std::vector<uint8_t> testData = { 0x14, 0x00, 0x00, 0x00, 0x01, 0x00, 0x04, 0x98, 0xc3, 0x00, 0x00,
445 0x00, 0x0c, 0x00, 0x00, 0x00, 0x07, 0xdc, 0x00 };
446 mtpTest->setOutBuffer(testData);
447 operationPtr_->Execute();
448
449 // get output
450 std::vector<uint8_t> output;
451 mtpTest->getOutBuffer(output);
452 for (auto && i : output) {
453 MEDIA_DEBUG_LOG("i: %{public}d", i);
454 }
455 std::vector<uint8_t> targetData = { 12, 0, 0, 0, 3, 0, 1, 32, 195, 0, 0, 0 };
456
457 MEDIA_DEBUG_LOG("MtpDriver::output.size: %{public}d", output.size());
458 EXPECT_EQ(output == targetData, true);
459 }
460
461 /*
462 * Feature: MediaLibraryMTP
463 * Function:
464 * SubFunction: NA
465 * FunctionPoints: NA
466 * EnvConditions: NA
467 * CaseDescription: MTP_OPERATION_GET_OBJECT_PROP_LIST_CODE
468 */
469 HWTEST_F(MediaLibraryMTPUnitTest, medialibrary_MTP_message_testlevel0_011, TestSize.Level0)
470 {
471 std::shared_ptr<OHOS::Media::MtpTest> mtpTest = OHOS::Media::MtpTest::GetInstance();
472 std::shared_ptr<MtpOperation> operationPtr_;
473 if (operationPtr_ == nullptr) {
474 operationPtr_ = make_shared<MtpOperation>();
475 }
476
477 // set test data
478 mtpTest->setOutBuffer(testData_open);
479 // execute
480 operationPtr_->Execute();
481
482 // MTP_OPERATION_GET_OBJECT_PROP_LIST_CODE
483 static std::vector<uint8_t> testData =
484 { 0x20, 0x00, 0x00, 0x00, 0x01, 0x00, 0x05, 0x98, 0x40, 0x00, 0x00, 0x00, 0x89, 0x00, 0x00, 0x00, 0x00,
485 0x00, 0x00, 0x00, 0x02, 0xDC, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
486 mtpTest->setOutBuffer(testData);
487 operationPtr_->Execute();
488
489 // get output
490 std::vector<uint8_t> output;
491 mtpTest->getOutBuffer(output);
492 for (auto && i : output) {
493 MEDIA_DEBUG_LOG("i: %{public}d", i);
494 }
495 std::vector<uint8_t> targetData = { 12, 0, 0, 0, 3, 0, 1, 32, 64, 0, 0, 0 };
496
497 MEDIA_DEBUG_LOG("MtpDriver::output.size: %{public}d", output.size());
498 EXPECT_EQ(output == targetData, true);
499 }
500
501 /*
502 * Feature: MediaLibraryMTP
503 * Function:
504 * SubFunction: NA
505 * FunctionPoints: NA
506 * EnvConditions: NA
507 * CaseDescription: MTP_OPERATION_SEND_OBJECT_INFO_CODE
508 */
509 HWTEST_F(MediaLibraryMTPUnitTest, medialibrary_MTP_message_testlevel0_012, TestSize.Level0)
510 {
511 std::shared_ptr<OHOS::Media::MtpTest> mtpTest = OHOS::Media::MtpTest::GetInstance();
512 std::shared_ptr<MtpOperation> operationPtr_;
513 if (operationPtr_ == nullptr) {
514 operationPtr_ = make_shared<MtpOperation>();
515 }
516
517 // set test data
518 mtpTest->setOutBuffer(testData_open);
519 // execute
520 operationPtr_->Execute();
521
522 // MTP_OPERATION_SEND_OBJECT_INFO_CODE
523 static std::vector<uint8_t> testData = { 0x14, 0x00, 0x00, 0x00, 0x01, 0x00, 0x0c, 0x10, 0xac, 0x00, 0x00,
524 0x00, 0x01, 0x00, 0x01, 0x00, 0x07, 0x00, 0x00, 0x00 };
525 mtpTest->setOutBuffer(testData);
526 operationPtr_->Execute();
527
528 // get output
529 std::vector<uint8_t> output;
530 mtpTest->getOutBuffer(output);
531 for (auto && i : output) {
532 MEDIA_DEBUG_LOG("i: %{public}d", i);
533 }
534 std::vector<uint8_t> targetData = { 24, 0, 0, 0, 3, 0, 1, 32, 172, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
535
536 MEDIA_DEBUG_LOG("MtpDriver::output.size: %{public}d", output.size());
537 EXPECT_EQ(output == targetData, true);
538 }
539
540 /*
541 * Feature: MediaLibraryMTP
542 * Function:
543 * SubFunction: NA
544 * FunctionPoints: NA
545 * EnvConditions: NA
546 * CaseDescription: MTP_OPERATION_SEND_OBJECT_CODE
547 */
548 HWTEST_F(MediaLibraryMTPUnitTest, medialibrary_MTP_message_testlevel0_013, TestSize.Level0)
549 {
550 std::shared_ptr<OHOS::Media::MtpTest> mtpTest = OHOS::Media::MtpTest::GetInstance();
551 std::shared_ptr<MtpOperation> operationPtr_;
552 if (operationPtr_ == nullptr) {
553 operationPtr_ = make_shared<MtpOperation>();
554 }
555
556 // set test data
557 mtpTest->setOutBuffer(testData_open);
558 // execute
559 operationPtr_->Execute();
560
561 // MTP_OPERATION_SEND_OBJECT_CODE
562 static std::vector<uint8_t> testData = { 0x0c, 0x00, 0x00, 0x00, 0x01, 0x00, 0x0d, 0x10, 0xbc, 0x00, 0x00, 0x00 };
563 mtpTest->setOutBuffer(testData);
564 operationPtr_->Execute();
565
566 // get output
567 std::vector<uint8_t> output;
568 mtpTest->getOutBuffer(output);
569 for (auto && i : output) {
570 MEDIA_DEBUG_LOG("i: %{public}d", i);
571 }
572 std::vector<uint8_t> targetData = { 12, 0, 0, 0, 3, 0, 1, 32, 188, 0, 0, 0 };
573
574 MEDIA_DEBUG_LOG("MtpDriver::output.size: %{public}d", output.size());
575 EXPECT_EQ(output == targetData, true);
576 }
577
578 /*
579 * Feature: MediaLibraryMTP
580 * Function:
581 * SubFunction: NA
582 * FunctionPoints: NA
583 * EnvConditions: NA
584 * CaseDescription: MTP_OPERATION_GET_OBJECT_INFO_CODE
585 */
586 HWTEST_F(MediaLibraryMTPUnitTest, medialibrary_MTP_message_testlevel0_014, TestSize.Level0)
587 {
588 std::shared_ptr<OHOS::Media::MtpTest> mtpTest = OHOS::Media::MtpTest::GetInstance();
589 std::shared_ptr<MtpOperation> operationPtr_;
590 if (operationPtr_ == nullptr) {
591 operationPtr_ = make_shared<MtpOperation>();
592 }
593
594 mtpTest->setOutBuffer(testData_open);
595 // execute
596 operationPtr_->Execute();
597
598 // MTP_OPERATION_GET_STORAGE_IDS_CODE
599 static std::vector<uint8_t> testData_1 =
600 { 0x0C, 0x00, 0x00, 0x00, 0x01, 0x00, 0x04, 0x10, 0x21, 0x00, 0x00, 0x00 };
601 // set test data
602 mtpTest->setOutBuffer(testData_1);
603 // execute
604 operationPtr_->Execute();
605
606 // MTP_OPERATION_GET_STORAGE_INFO_CODE
607 static std::vector<uint8_t> testData_2 =
608 { 0x10, 0x00, 0x00, 0x00, 0x01, 0x00, 0x05, 0x10, 0x8C, 0x07, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00 };
609 mtpTest->setOutBuffer(testData_2);
610 // execute
611 operationPtr_->Execute();
612
613 // MTP_OPERATION_GET_OBJECT_HANDLES_CODE
614 static std::vector<uint8_t> testData_3 = { 0x18, 0x00, 0x00, 0x00, 0x01, 0x00, 0x07, 0x10, 0x23, 0x00, 0x00,
615 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff };
616 mtpTest->setOutBuffer(testData_3);
617 // execute
618 operationPtr_->Execute();
619
620 // MTP_OPERATION_GET_OBJECT_INFO_CODE
621 static std::vector<uint8_t> testData =
622 { 0x10, 0x00, 0x00, 0x00, 0x01, 0x00, 0x08, 0x10, 0x5c, 0x01, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00 };
623 mtpTest->setOutBuffer(testData);
624 operationPtr_->Execute();
625
626 // get output
627 std::vector<uint8_t> output;
628 mtpTest->getOutBuffer(output);
629 for (auto && i : output) {
630 MEDIA_DEBUG_LOG("i: %{public}d", i);
631 }
632 std::vector<uint8_t> targetData = { 12, 0, 0, 0, 3, 0, 1, 32, 92, 1, 0, 0 };
633
634 MEDIA_DEBUG_LOG("MtpDriver::output.size: %{public}d", output.size());
635 EXPECT_EQ(output == targetData, true);
636 }
637
638 /*
639 * Feature: MediaLibraryMTP
640 * Function:
641 * SubFunction: NA
642 * FunctionPoints: NA
643 * EnvConditions: NA
644 * CaseDescription: MTP_OPERATION_GET_OBJECT_CODE
645 */
646 HWTEST_F(MediaLibraryMTPUnitTest, medialibrary_MTP_message_testlevel0_015, TestSize.Level0)
647 {
648 std::shared_ptr<OHOS::Media::MtpTest> mtpTest = OHOS::Media::MtpTest::GetInstance();
649 std::shared_ptr<MtpOperation> operationPtr_;
650 if (operationPtr_ == nullptr) {
651 operationPtr_ = make_shared<MtpOperation>();
652 }
653
654 mtpTest->setOutBuffer(testData_open);
655 // execute
656 operationPtr_->Execute();
657
658 // MTP_OPERATION_GET_STORAGE_IDS_CODE
659 static std::vector<uint8_t> testData_1 =
660 { 0x0C, 0x00, 0x00, 0x00, 0x01, 0x00, 0x04, 0x10, 0x21, 0x00, 0x00, 0x00 };
661 // set test data
662 mtpTest->setOutBuffer(testData_1);
663 // execute
664 operationPtr_->Execute();
665
666 // MTP_OPERATION_GET_STORAGE_INFO_CODE
667 static std::vector<uint8_t> testData_2 =
668 { 0x10, 0x00, 0x00, 0x00, 0x01, 0x00, 0x05, 0x10, 0x8C, 0x07, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00 };
669 mtpTest->setOutBuffer(testData_2);
670 // execute
671 operationPtr_->Execute();
672
673 // MTP_OPERATION_GET_OBJECT_HANDLES_CODE
674 static std::vector<uint8_t> testData_3 = { 0x18, 0x00, 0x00, 0x00, 0x01, 0x00, 0x07, 0x10, 0x23, 0x00,
675 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff };
676 mtpTest->setOutBuffer(testData_3);
677 // execute
678 operationPtr_->Execute();
679
680 // MTP_OPERATION_GET_OBJECT_CODE
681 static std::vector<uint8_t> testData =
682 { 0x10, 0x00, 0x00, 0x00, 0x01, 0x00, 0x09, 0x10, 0x5f, 0x01, 0x00, 0x00, 0x0b, 0x00, 0x00, 0x00 };
683 mtpTest->setOutBuffer(testData);
684 operationPtr_->Execute();
685
686 // get output
687 std::vector<uint8_t> output;
688 mtpTest->getOutBuffer(output);
689 for (auto && i : output) {
690 MEDIA_DEBUG_LOG("i: %{public}d", i);
691 }
692 std::vector<uint8_t> targetData = { 12, 0, 0, 0, 3, 0, 1, 32, 95, 1, 0, 0 };
693
694 MEDIA_DEBUG_LOG("MtpDriver::output.size: %{public}d", output.size());
695 EXPECT_EQ(output == targetData, true);
696 }
697
698 /*
699 * Feature: MediaLibraryMTP
700 * Function:
701 * SubFunction: NA
702 * FunctionPoints: NA
703 * EnvConditions: NA
704 * CaseDescription: MTP_OPERATION_GET_THUMB_CODE
705 */
706 HWTEST_F(MediaLibraryMTPUnitTest, medialibrary_MTP_message_testlevel0_016, TestSize.Level0)
707 {
708 std::shared_ptr<OHOS::Media::MtpTest> mtpTest = OHOS::Media::MtpTest::GetInstance();
709 std::shared_ptr<MtpOperation> operationPtr_;
710 if (operationPtr_ == nullptr) {
711 operationPtr_ = make_shared<MtpOperation>();
712 }
713
714 mtpTest->setOutBuffer(testData_open);
715 // execute
716 operationPtr_->Execute();
717
718 // MTP_OPERATION_GET_STORAGE_IDS_CODE
719 static std::vector<uint8_t> testData_1 =
720 { 0x0C, 0x00, 0x00, 0x00, 0x01, 0x00, 0x04, 0x10, 0x21, 0x00, 0x00, 0x00 };
721 // set test data
722 mtpTest->setOutBuffer(testData_1);
723 // execute
724 operationPtr_->Execute();
725
726 // MTP_OPERATION_GET_STORAGE_INFO_CODE
727 static std::vector<uint8_t> testData_2 =
728 { 0x10, 0x00, 0x00, 0x00, 0x01, 0x00, 0x05, 0x10, 0x8C, 0x07, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00 };
729 mtpTest->setOutBuffer(testData_2);
730 // execute
731 operationPtr_->Execute();
732
733 // MTP_OPERATION_GET_OBJECT_HANDLES_CODE
734 static std::vector<uint8_t> testData_3 = { 0x18, 0x00, 0x00, 0x00, 0x01, 0x00, 0x07, 0x10, 0x23, 0x00, 0x00,
735 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff };
736 mtpTest->setOutBuffer(testData_3);
737 // execute
738 operationPtr_->Execute();
739
740 // MTP_OPERATION_GET_THUMB_CODE
741 static std::vector<uint8_t> testData =
742 { 0x10, 0x00, 0x00, 0x00, 0x01, 0x00, 0x0a, 0x10, 0x71, 0x01, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00 };
743 mtpTest->setOutBuffer(testData);
744 operationPtr_->Execute();
745
746 // get output
747 std::vector<uint8_t> output;
748 mtpTest->getOutBuffer(output);
749 for (auto && i : output) {
750 MEDIA_DEBUG_LOG("i: %{public}d", i);
751 }
752 std::vector<uint8_t> targetData = { 12, 0, 0, 0, 3, 0, 1, 32, 113, 1, 0, 0 };
753
754 MEDIA_DEBUG_LOG("MtpDriver::output.size: %{public}d", output.size());
755 EXPECT_EQ(output == targetData, true);
756 }
757
758
759 /*
760 * Feature: MediaLibraryMTP
761 * Function:
762 * SubFunction: NA
763 * FunctionPoints: NA
764 * EnvConditions: NA
765 * CaseDescription: MTP_OPERATION_DELETE_OBJECT_CODE
766 */
767 HWTEST_F(MediaLibraryMTPUnitTest, medialibrary_MTP_message_testlevel0_017, TestSize.Level0)
768 {
769 std::shared_ptr<OHOS::Media::MtpTest> mtpTest = OHOS::Media::MtpTest::GetInstance();
770 std::shared_ptr<MtpOperation> operationPtr_;
771 if (operationPtr_ == nullptr) {
772 operationPtr_ = make_shared<MtpOperation>();
773 }
774
775 mtpTest->setOutBuffer(testData_open);
776 // execute
777 operationPtr_->Execute();
778
779 // MTP_OPERATION_GET_STORAGE_IDS_CODE
780 static std::vector<uint8_t> testData_1 =
781 { 0x0C, 0x00, 0x00, 0x00, 0x01, 0x00, 0x04, 0x10, 0x21, 0x00, 0x00, 0x00 };
782 // set test data
783 mtpTest->setOutBuffer(testData_1);
784 // execute
785 operationPtr_->Execute();
786
787 // MTP_OPERATION_GET_STORAGE_INFO_CODE
788 static std::vector<uint8_t> testData_2 =
789 { 0x10, 0x00, 0x00, 0x00, 0x01, 0x00, 0x05, 0x10, 0x8C, 0x07, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00 };
790 mtpTest->setOutBuffer(testData_2);
791 // execute
792 operationPtr_->Execute();
793
794 // MTP_OPERATION_GET_OBJECT_HANDLES_CODE
795 static std::vector<uint8_t> testData_3 = { 0x18, 0x00, 0x00, 0x00, 0x01, 0x00, 0x07, 0x10, 0x23, 0x00, 0x00,
796 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff };
797 mtpTest->setOutBuffer(testData_3);
798 // execute
799 operationPtr_->Execute();
800
801 // MTP_OPERATION_DELETE_OBJECT_CODE
802 static std::vector<uint8_t> testData = { 0x14, 0x00, 0x00, 0x00, 0x01, 0x00, 0x0b, 0x10, 0xc8, 0x00, 0x00,
803 0x00, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
804 mtpTest->setOutBuffer(testData);
805 operationPtr_->Execute();
806
807 // get output
808 std::vector<uint8_t> output;
809 mtpTest->getOutBuffer(output);
810 for (auto && i : output) {
811 MEDIA_DEBUG_LOG("i: %{public}d", i);
812 }
813 std::vector<uint8_t> targetData = { 12, 0, 0, 0, 3, 0, 1, 32, 200, 0, 0, 0 };
814
815 MEDIA_DEBUG_LOG("MtpDriver::output.size: %{public}d", output.size());
816 EXPECT_EQ(output == targetData, true);
817 }
818
819 /*
820 * Feature: MediaLibraryMTP
821 * Function:
822 * SubFunction: NA
823 * FunctionPoints: NA
824 * EnvConditions: NA
825 * CaseDescription: MTP_OPERATION_SET_DEVICE_PROP_VALUE_CODE
826 */
827 HWTEST_F(MediaLibraryMTPUnitTest, medialibrary_MTP_message_testlevel0_018, TestSize.Level0)
828 {
829 std::shared_ptr<OHOS::Media::MtpTest> mtpTest = OHOS::Media::MtpTest::GetInstance();
830 std::shared_ptr<MtpOperation> operationPtr_;
831 if (operationPtr_ == nullptr) {
832 operationPtr_ = make_shared<MtpOperation>();
833 }
834
835 mtpTest->setOutBuffer(testData_open);
836 // execute
837 operationPtr_->Execute();
838
839 // MTP_OPERATION_SET_DEVICE_PROP_VALUE_CODE
840 static std::vector<uint8_t> testData =
841 { 0x10, 0x00, 0x00, 0x00, 0x01, 0x00, 0x16, 0x10, 0x9d, 0x00, 0x00, 0x00, 0x02, 0xd4, 0x00, 0x00 };
842 mtpTest->setOutBuffer(testData);
843 operationPtr_->Execute();
844
845 // get output
846 std::vector<uint8_t> output;
847 mtpTest->getOutBuffer(output);
848 for (auto && i : output) {
849 MEDIA_DEBUG_LOG("i: %{public}d", i);
850 }
851 std::vector<uint8_t> targetData = { 12, 0, 0, 0, 3, 0, 1, 32, 157, 0, 0, 0 };
852
853 MEDIA_DEBUG_LOG("MtpDriver::output.size: %{public}d", output.size());
854 EXPECT_EQ(output == targetData, true);
855 }
856
857 /*
858 * Feature: MediaLibraryMTP
859 * Function:
860 * SubFunction: NA
861 * FunctionPoints: NA
862 * EnvConditions: NA
863 * CaseDescription: MTP_OPERATION_GET_DEVICE_PROP_VALUE_CODE
864 */
865 HWTEST_F(MediaLibraryMTPUnitTest, medialibrary_MTP_message_testlevel0_019, TestSize.Level0)
866 {
867 std::shared_ptr<OHOS::Media::MtpTest> mtpTest = OHOS::Media::MtpTest::GetInstance();
868 std::shared_ptr<MtpOperation> operationPtr_;
869 if (operationPtr_ == nullptr) {
870 operationPtr_ = make_shared<MtpOperation>();
871 }
872
873 // set test data
874 mtpTest->setOutBuffer(testData_open);
875 // execute
876 operationPtr_->Execute();
877
878 // MTP_OPERATION_GET_DEVICE_PROP_VALUE_CODE
879 static std::vector<uint8_t> testData =
880 { 0x10, 0x00, 0x00, 0x00, 0x01, 0x00, 0x15, 0x10, 0x05, 0x00, 0x00, 0x00, 0x02, 0xD4, 0x00, 0x00 };
881 mtpTest->setOutBuffer(testData);
882 // execute
883 operationPtr_->Execute();
884
885 // get output
886 std::vector<uint8_t> output;
887 mtpTest->getOutBuffer(output);
888 for (auto && i : output) {
889 MEDIA_DEBUG_LOG("i: %{public}d", i);
890 }
891 std::vector<uint8_t> targetData = { 12, 0, 0, 0, 3, 0, 1, 32, 5, 0, 0, 0 };
892
893 MEDIA_DEBUG_LOG("MtpDriver::output.size: %{public}d", output.size());
894 EXPECT_EQ(output == targetData, true);
895 }
896
897 /*
898 * Feature: MediaLibraryMTP
899 * Function:
900 * SubFunction: NA
901 * FunctionPoints: NA
902 * EnvConditions: NA
903 * CaseDescription: MTP_OPERATION_COPY_OBJECT_CODE
904 */
905 HWTEST_F(MediaLibraryMTPUnitTest, medialibrary_MTP_message_testlevel0_020, TestSize.Level0)
906 {
907 std::shared_ptr<OHOS::Media::MtpTest> mtpTest = OHOS::Media::MtpTest::GetInstance();
908 std::shared_ptr<MtpOperation> operationPtr_;
909 if (operationPtr_ == nullptr) {
910 operationPtr_ = make_shared<MtpOperation>();
911 }
912
913 // set test data
914 mtpTest->setOutBuffer(testData_open);
915 // execute
916 operationPtr_->Execute();
917
918 // MTP_OPERATION_GET_STORAGE_IDS_CODE
919 static std::vector<uint8_t> testData_1 =
920 { 0x0C, 0x00, 0x00, 0x00, 0x01, 0x00, 0x04, 0x10, 0x21, 0x00, 0x00, 0x00 };
921 // set test data
922 mtpTest->setOutBuffer(testData_1);
923 // execute
924 operationPtr_->Execute();
925
926 // MTP_OPERATION_GET_STORAGE_INFO_CODE
927 static std::vector<uint8_t> testData_2 =
928 { 0x10, 0x00, 0x00, 0x00, 0x01, 0x00, 0x05, 0x10, 0x8C, 0x07, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00 };
929 mtpTest->setOutBuffer(testData_2);
930 // execute
931 operationPtr_->Execute();
932
933 // MTP_OPERATION_GET_OBJECT_HANDLES_CODE
934 static std::vector<uint8_t> testData_3 = { 0x18, 0x00, 0x00, 0x00, 0x01, 0x00, 0x07, 0x10, 0x23, 0x00, 0x00,
935 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff };
936 mtpTest->setOutBuffer(testData_3);
937 // execute
938 operationPtr_->Execute();
939
940 static std::vector<uint8_t> testData = { 0x18, 0x00, 0x00, 0x00, 0x01, 0x00, 0x1a, 0x10, 0xb7, 0x00, 0x00};
941 mtpTest->setOutBuffer(testData);
942 // execute
943 operationPtr_->Execute();
944
945 // get output
946 std::vector<uint8_t> output;
947 mtpTest->getOutBuffer(output);
948 for (auto && i : output) {
949 MEDIA_DEBUG_LOG("i: %{public}d", i);
950 }
951 std::vector<uint8_t> targetData = { 12, 0, 0, 0, 3, 0, 29, 32, 0, 0, 0, 0};
952
953 MEDIA_DEBUG_LOG("MtpDriver::output.size: %{public}d", output.size());
954 EXPECT_EQ(output == targetData, true);
955 }
956
957 /*
958 * Feature: MediaLibraryMTP
959 * Function:
960 * SubFunction: NA
961 * FunctionPoints: NA
962 * EnvConditions: NA
963 * CaseDescription: MTP_OPERATION_MOVE_OBJECT_CODE
964 */
965 HWTEST_F(MediaLibraryMTPUnitTest, medialibrary_MTP_message_testlevel0_021, TestSize.Level0)
966 {
967 std::shared_ptr<OHOS::Media::MtpTest> mtpTest = OHOS::Media::MtpTest::GetInstance();
968 std::shared_ptr<MtpOperation> operationPtr_;
969 if (operationPtr_ == nullptr) {
970 operationPtr_ = make_shared<MtpOperation>();
971 }
972
973 // set test data
974 mtpTest->setOutBuffer(testData_open);
975 // execute
976 operationPtr_->Execute();
977
978 // MTP_OPERATION_GET_STORAGE_IDS_CODE
979 static std::vector<uint8_t> testData_1 =
980 { 0x0C, 0x00, 0x00, 0x00, 0x01, 0x00, 0x04, 0x10, 0x21, 0x00, 0x00, 0x00 };
981 // set test data
982 mtpTest->setOutBuffer(testData_1);
983 // execute
984 operationPtr_->Execute();
985
986 // MTP_OPERATION_GET_STORAGE_INFO_CODE
987 static std::vector<uint8_t> testData_2 =
988 { 0x10, 0x00, 0x00, 0x00, 0x01, 0x00, 0x05, 0x10, 0x8C, 0x07, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00 };
989 mtpTest->setOutBuffer(testData_2);
990 // execute
991 operationPtr_->Execute();
992
993 // MTP_OPERATION_GET_OBJECT_HANDLES_CODE
994 static std::vector<uint8_t> testData_3 = { 0x18, 0x00, 0x00, 0x00, 0x01, 0x00, 0x07, 0x10, 0x23, 0x00, 0x00,
995 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff };
996 mtpTest->setOutBuffer(testData_3);
997 // execute
998 operationPtr_->Execute();
999
1000 // MTP_OPERATION_MOVE_OBJECT_CODE
1001 static std::vector<uint8_t> testData = { 0x18, 0x00, 0x00, 0x00, 0x01, 0x00, 0x19, 0x10, 0x8b, 0x00, 0x00,
1002 0x00, 0x0b, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00 };
1003 mtpTest->setOutBuffer(testData);
1004 // execute
1005 operationPtr_->Execute();
1006
1007 // get output
1008 std::vector<uint8_t> output;
1009 mtpTest->getOutBuffer(output);
1010 for (auto && i : output) {
1011 MEDIA_DEBUG_LOG("i: %{public}d", i);
1012 }
1013 std::vector<uint8_t> targetData = { 12, 0, 0, 0, 3, 0, 1, 32, 139, 0, 0, 0 };
1014
1015 MEDIA_DEBUG_LOG("MtpDriver::output.size: %{public}d", output.size());
1016 EXPECT_EQ(output == targetData, true);
1017 }
1018
1019 /*
1020 * Feature: MediaLibraryMTP
1021 * Function:
1022 * SubFunction: NA
1023 * FunctionPoints: NA
1024 * EnvConditions: NA
1025 * CaseDescription: MTP_SESSION_NOT_OPEN_CODE
1026 */
1027 HWTEST_F(MediaLibraryMTPUnitTest, medialibrary_MTP_message_testlevel0_023, TestSize.Level0)
1028 {
1029 std::shared_ptr<OHOS::Media::MtpTest> mtpTest = OHOS::Media::MtpTest::GetInstance();
1030 std::shared_ptr<MtpOperation> operationPtr_;
1031 if (operationPtr_ == nullptr) {
1032 operationPtr_ = make_shared<MtpOperation>();
1033 }
1034
1035 // MTP_OPERATION_GET_STORAGE_IDS_CODE
1036 static std::vector<uint8_t> testData = { 0x0C, 0x00, 0x00, 0x00, 0x01, 0x00, 0x04, 0x10, 0x21, 0x00, 0x00, 0x00 };
1037 // set test data
1038 mtpTest->setOutBuffer(testData);
1039 // execute
1040 operationPtr_->Execute();
1041 // get output
1042 std::vector<uint8_t> output;
1043 mtpTest->getOutBuffer(output);
1044 for (auto && i : output) {
1045 MEDIA_DEBUG_LOG("i: %{public}d", i);
1046 }
1047 // MTP_SESSION_NOT_OPEN_CODE
1048 std::vector<uint8_t> targetData = { 12, 0, 0, 0, 3, 0, 3, 32, 33, 0, 0, 0 };
1049
1050 MEDIA_DEBUG_LOG("MtpDriver::output.size: %{public}d", output.size());
1051 EXPECT_EQ(output == targetData, true);
1052 }
1053
1054 /*
1055 * Feature: MediaLibraryMTP
1056 * Function:
1057 * SubFunction: NA
1058 * FunctionPoints: NA
1059 * EnvConditions: NA
1060 * CaseDescription: MTP_OPERATION_GET_OBJECT_PROP_DESC_CODE
1061 */
1062 HWTEST_F(MediaLibraryMTPUnitTest, medialibrary_MTP_message_testlevel0_024, TestSize.Level0)
1063 {
1064 std::shared_ptr<OHOS::Media::MtpTest> mtpTest = OHOS::Media::MtpTest::GetInstance();
1065 std::shared_ptr<MtpOperation> operationPtr_;
1066 if (operationPtr_ == nullptr) {
1067 operationPtr_ = make_shared<MtpOperation>();
1068 }
1069
1070 // set test data
1071 mtpTest->setOutBuffer(testData_open);
1072 // execute
1073 operationPtr_->Execute();
1074
1075 // MTP_OPERATION_GET_OBJECT_PROP_DESC_CODE
1076 static std::vector<uint8_t> testData = { 0x14, 0x00, 0x00, 0x00, 0x01, 0x00, 0x02, 0x98, 0x24, 0x00,
1077 0x00, 0x00, 0x09, 0xDC, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00 }; // MTP_PROPERTY_DATE_MODIFIED_CODE
1078 mtpTest->setOutBuffer(testData);
1079 operationPtr_->Execute();
1080
1081 // get output
1082 std::vector<uint8_t> output;
1083 mtpTest->getOutBuffer(output);
1084 for (auto&& i : output) {
1085 MEDIA_DEBUG_LOG("i: %{public}d", i);
1086 }
1087 std::vector<uint8_t> targetData = { 12, 0, 0, 0, 3, 0, 1, 32, 36, 0, 0, 0 };
1088
1089 MEDIA_DEBUG_LOG("MtpDriver::output.size: %{public}d", output.size());
1090 EXPECT_EQ(output == targetData, true);
1091
1092 // MTP_OPERATION_GET_OBJECT_PROP_DESC_CODE
1093 static std::vector<uint8_t> testData2 = { 0x14, 0x00, 0x00, 0x00, 0x01, 0x00, 0x02, 0x98, 0x24, 0x00,
1094 0x00, 0x00, 0x92, 0xDE, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00 }; // MTP_PROPERTY_BITRATE_TYPE_CODE
1095 mtpTest->setOutBuffer(testData2);
1096 operationPtr_->Execute();
1097
1098 // get output
1099 output.clear();
1100 mtpTest->getOutBuffer(output);
1101 for (auto&& i : output) {
1102 MEDIA_DEBUG_LOG("i: %{public}d", i);
1103 }
1104 MEDIA_DEBUG_LOG("MtpDriver::output.size: %{public}d", output.size());
1105 EXPECT_EQ(output == targetData, true);
1106
1107 // MTP_OPERATION_GET_OBJECT_PROP_DESC_CODE
1108 static std::vector<uint8_t> testData3 = { 0x14, 0x00, 0x00, 0x00, 0x01, 0x00, 0x02, 0x98, 0x24, 0x00,
1109 0x00, 0x00, 0x9A, 0xDE, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00 }; // MTP_PROPERTY_AUDIO_BITRATE_CODE
1110 mtpTest->setOutBuffer(testData3);
1111 operationPtr_->Execute();
1112
1113 // get output
1114 output.clear();
1115 mtpTest->getOutBuffer(output);
1116 for (auto&& i : output) {
1117 MEDIA_DEBUG_LOG("i: %{public}d", i);
1118 }
1119 MEDIA_DEBUG_LOG("MtpDriver::output.size: %{public}d", output.size());
1120 EXPECT_EQ(output == targetData, true);
1121
1122 // MTP_OPERATION_GET_OBJECT_PROP_DESC_CODE
1123 static std::vector<uint8_t> testData4 = { 0x14, 0x00, 0x00, 0x00, 0x01, 0x00, 0x02, 0x98, 0x24, 0x00,
1124 0x00, 0x00, 0x94, 0xDE, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00 }; // MTP_PROPERTY_NUMBER_OF_CHANNELS_CODE
1125 mtpTest->setOutBuffer(testData4);
1126 operationPtr_->Execute();
1127
1128 // get output
1129 output.clear();
1130 mtpTest->getOutBuffer(output);
1131 for (auto&& i : output) {
1132 MEDIA_DEBUG_LOG("i: %{public}d", i);
1133 }
1134 MEDIA_DEBUG_LOG("MtpDriver::output.size: %{public}d", output.size());
1135 EXPECT_EQ(output == targetData, true);
1136
1137 // MTP_OPERATION_GET_OBJECT_PROP_DESC_CODE
1138 static std::vector<uint8_t> testData5 = { 0x14, 0x00, 0x00, 0x00, 0x01, 0x00, 0x02, 0x98, 0x24, 0x00,
1139 0x00, 0x00, 0x93, 0xDE, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00 }; // MTP_PROPERTY_SAMPLE_RATE_CODE
1140 mtpTest->setOutBuffer(testData5);
1141 operationPtr_->Execute();
1142
1143 // get output
1144 output.clear();
1145 mtpTest->getOutBuffer(output);
1146 for (auto&& i : output) {
1147 MEDIA_DEBUG_LOG("i: %{public}d", i);
1148 }
1149 MEDIA_DEBUG_LOG("MtpDriver::output.size: %{public}d", output.size());
1150 EXPECT_EQ(output == targetData, true);
1151 }
1152
1153 /*
1154 * Feature: MediaLibraryMTP
1155 * Function:
1156 * SubFunction: NA
1157 * FunctionPoints: NA
1158 * EnvConditions: NA
1159 * CaseDescription: MTP_OPERATION_GET_OBJECT_PROP_VALUE_CODE
1160 */
1161 HWTEST_F(MediaLibraryMTPUnitTest, medialibrary_MTP_message_testlevel0_025, TestSize.Level0)
1162 {
1163 std::shared_ptr<OHOS::Media::MtpTest> mtpTest = OHOS::Media::MtpTest::GetInstance();
1164 std::shared_ptr<MtpOperation> operationPtr_;
1165 if (operationPtr_ == nullptr) {
1166 operationPtr_ = make_shared<MtpOperation>();
1167 }
1168
1169 // set test data
1170 mtpTest->setOutBuffer(testData_open);
1171 // execute
1172 operationPtr_->Execute();
1173
1174 // MTP_OPERATION_GET_OBJECT_PROP_VALUE_CODE
1175 static std::vector<uint8_t> testData = { 0x0C, 0x00, 0x00, 0x00, 0x01, 0x00, 0x03, 0x98, 0x40, 0x00, 0x00, 0x00 };
1176 mtpTest->setOutBuffer(testData);
1177 operationPtr_->Execute();
1178
1179 // get output
1180 std::vector<uint8_t> output;
1181 mtpTest->getOutBuffer(output);
1182 for (auto&& i : output) {
1183 MEDIA_DEBUG_LOG("i: %{public}d", i);
1184 }
1185 std::vector<uint8_t> targetData = { 12, 0, 0, 0, 3, 0, 1, 32, 64, 0, 0, 0 };
1186
1187 MEDIA_DEBUG_LOG("MtpDriver::output.size: %{public}d", output.size());
1188 EXPECT_EQ(output == targetData, true);
1189
1190 // MTP_OPERATION_GET_OBJECT_PROP_VALUE_CODE
1191 static std::vector<uint8_t> testData2 = { 0x14, 0x00, 0x00, 0x00, 0x01, 0x00, 0x03, 0x98, 0x40, 0x00, 0x00,
1192 0x00, 0x89, 0x00, 0x00, 0x00, 0x07, 0xDC, 0x00, 0x00 };
1193 mtpTest->setOutBuffer(testData2);
1194 operationPtr_->Execute();
1195
1196 // get output
1197 output.clear();
1198 mtpTest->getOutBuffer(output);
1199 for (auto&& i : output) {
1200 MEDIA_DEBUG_LOG("i: %{public}d", i);
1201 }
1202 MEDIA_DEBUG_LOG("MtpDriver::output.size: %{public}d", output.size());
1203 EXPECT_EQ(output == targetData, true);
1204 }
1205 } // namespace Media
1206 } // namespace OHOS
1207