• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
16import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index';
17import request from '@ohos.request';
18import featureAbility from '@ohos.ability.featureAbility';
19import fs from '@ohos.file.fs';
20
21const TAG = "UPLOAD_TEST";
22
23describe('RequestUploadTest', async function () {
24    beforeAll(function () {
25        console.info('beforeAll called')
26    })
27
28    afterAll(function () {
29        console.info('afterAll called')
30    })
31
32    beforeEach(function () {
33        console.info('beforeEach called')
34    })
35
36    afterEach(function () {
37        console.info('afterEach called');
38        if (fs.accessSync(cacheDir + '/test.txt')) {
39          fs.unlinkSync(cacheDir + '/test.txt');
40        }
41    })
42    console.log(TAG + "*************Unit Test Begin*************");
43
44    let cacheDir = await featureAbility.getContext().getCacheDir();
45
46    let uploadTask;
47    let RequestData = {
48      name: 'name',
49      value: '123'
50    }
51
52    let File = {
53      filename: 'test',
54      name: 'test',
55      uri: 'internal://cache/test.txt',
56      type: 'txt'
57    }
58
59    let File1 = {
60      filename: 'test1',
61      name: 'test',
62      uri: 'internal://cache/test1.txt',
63      type: 'txt'
64    }
65
66    let File2 = {
67      filename: 'test2',
68      name: 'test',
69      uri: 'internal://cache/test2.txt',
70      type: 'txt'
71    }
72
73    let uploadConfig = {
74      url: 'http://127.0.0.1',
75      header: {
76        headers: 'http'
77      },
78      method: 'POST',
79      files: [File],
80      data: [RequestData]
81    };
82
83    let uploadConfig1 = {
84        url: 'http://127.0.0.1',
85        header: {
86          headers: 'http'
87        },
88        method: 'PUT',
89        files: [File],
90        data: [RequestData]
91    };
92
93    let uploadConfig2 = {
94      url:  'http://127.0.0.1',
95      header: {
96        headers: 'http'
97      },
98      index: 1,
99      begins: 50,
100      ends: 100,
101      method: 'POST',
102      files: [File1, File2],
103      data: [RequestData]
104    };
105
106    let uploadConfig3 = {
107      url:  'http://127.0.0.1',
108      header: {
109        headers: 'http'
110      },
111      index: 1,
112      begins: "50",
113      ends: 100,
114      method: 'POST',
115      files: [File1, File2],
116      data: [RequestData]
117    };
118
119    let uploadConfig4 = {
120      url:  'http://127.0.0.1',
121      header: {
122        headers: 'http'
123      },
124      index: 1,
125      begins: undefined,
126      ends: 100,
127      method: 'POST',
128      files: [File1, File2],
129      data: [RequestData]
130    };
131
132    /**
133     * @tc.number    SUB_REQUEST_UPLOAD_API_0001
134     * @tc.name      Test requestUploadTest type = TIMER_TYPE_REALTIME
135     * @tc.desc      Test requestUploadTest API functionality.
136     * @tc.size      : MEDIUM
137     * @tc.type      : Function
138     * @tc.level     : Level 0
139     */
140    it('SUB_REQUEST_UPLOAD_API_0001', 0, async function (done) {
141      console.info("-----------------------SUB_REQUEST_UPLOAD_API_0001 is starting-----------------------");
142      try {
143        console.info("SUB_REQUEST_UPLOAD_API_0001 request.NETWORK_MOBILE: " + request.NETWORK_MOBILE);
144        expect(request.NETWORK_MOBILE).assertEqual(1);
145        console.info("SUB_REQUEST_UPLOAD_API_0001 request.NETWORK_WIFI: " + request.NETWORK_WIFI);
146        expect(request.NETWORK_WIFI).assertEqual(65536);
147        console.info("SUB_REQUEST_UPLOAD_API_0001 request.ERROR_CANNOT_RESUME: " + request.ERROR_CANNOT_RESUME);
148        expect(request.ERROR_CANNOT_RESUME).assertEqual(0);
149        console.info("SUB_REQUEST_UPLOAD_API_0001 request.ERROR_DEVICE_NOT_FOUND: " + request.ERROR_DEVICE_NOT_FOUND);
150        expect(request.ERROR_DEVICE_NOT_FOUND).assertEqual(1);
151      } catch (err) {
152        console.error("SUB_REQUEST_UPLOAD_API_0001 error: " + err);
153        expect().assertFail();
154      }
155      console.info("-----------------------SUB_REQUEST_UPLOAD_API_0001 end-----------------------");
156      done();
157    });
158
159    /**
160     * @tc.number    SUB_REQUEST_UPLOAD_API_0002
161     * @tc.name      Test requestUploadTest type = TIMER_TYPE_REALTIME
162     * @tc.desc      Test requestUploadTest API functionality.
163     * @tc.size      : MEDIUM
164     * @tc.type      : Function
165     * @tc.level     : Level 0
166     */
167    it('SUB_REQUEST_UPLOAD_API_0002', 0, async function (done) {
168      console.info("-----------------------SUB_REQUEST_UPLOAD_API_0002 is starting-----------------------");
169      try {
170        console.info("SUB_REQUEST_UPLOAD_API_0002 request.ERROR_FILE_ALREADY_EXISTS: " + request.ERROR_FILE_ALREADY_EXISTS);
171        expect(request.ERROR_FILE_ALREADY_EXISTS).assertEqual(2);
172        console.info("SUB_REQUEST_UPLOAD_API_0002 request.ERROR_FILE_ERROR: " + request.ERROR_FILE_ERROR);
173        expect(request.ERROR_FILE_ERROR).assertEqual(3);
174        console.info("SUB_REQUEST_UPLOAD_API_0002 request.ERROR_HTTP_DATA_ERROR: " + request.ERROR_HTTP_DATA_ERROR);
175        expect(request.ERROR_HTTP_DATA_ERROR).assertEqual(4);
176        console.info("SUB_REQUEST_UPLOAD_API_0002 request.ERROR_INSUFFICIENT_SPACE: " + request.ERROR_INSUFFICIENT_SPACE);
177        expect(request.ERROR_INSUFFICIENT_SPACE).assertEqual(5);
178      } catch (err) {
179        console.error("SUB_REQUEST_UPLOAD_API_0002 error: " + err);
180        expect().assertFail();
181      }
182      console.info("-----------------------SUB_REQUEST_UPLOAD_API_0002 end-----------------------");
183      done();
184    });
185
186    /**
187     * @tc.number    SUB_REQUEST_UPLOAD_API_0003
188     * @tc.name      Test requestUploadTest type = TIMER_TYPE_REALTIME
189     * @tc.desc      Test requestUploadTest API functionality.
190     * @tc.size      : MEDIUM
191     * @tc.type      : Function
192     * @tc.level     : Level 0
193     */
194    it('SUB_REQUEST_UPLOAD_API_0003', 0, async function (done) {
195      console.info("-----------------------SUB_REQUEST_UPLOAD_API_0003 is starting-----------------------");
196      try {
197        console.info("SUB_REQUEST_UPLOAD_API_0003 request.ERROR_TOO_MANY_REDIRECTS:" + request.ERROR_TOO_MANY_REDIRECTS);
198        expect(request.ERROR_TOO_MANY_REDIRECTS).assertEqual(6);
199        console.info("SUB_REQUEST_UPLOAD_API_0003 request.ERROR_UNHANDLED_HTTP_CODE:" + request.ERROR_UNHANDLED_HTTP_CODE);
200        expect(request.ERROR_UNHANDLED_HTTP_CODE).assertEqual(7);
201        console.info("SUB_REQUEST_UPLOAD_API_0003 request.ERROR_UNKNOWN:" + request.ERROR_UNKNOWN);
202        expect(request.ERROR_UNKNOWN).assertEqual(8);
203        console.info("SUB_REQUEST_UPLOAD_API_0003 request.PAUSED_QUEUED_FOR_WIFI:" + request.PAUSED_QUEUED_FOR_WIFI);
204        expect(request.PAUSED_QUEUED_FOR_WIFI).assertEqual(0);
205      } catch (err) {
206        console.error("SUB_REQUEST_UPLOAD_API_0003 error: " + err);
207        expect().assertFail();
208      }
209      console.info("-----------------------SUB_REQUEST_UPLOAD_API_0003 end-----------------------");
210      done();
211    });
212
213    /**
214     * @tc.number    SUB_REQUEST_UPLOAD_API_0004
215     * @tc.name      Test requestUploadTest type = TIMER_TYPE_REALTIME
216     * @tc.desc      Test requestUploadTest API functionality.
217     * @tc.size      : MEDIUM
218     * @tc.type      : Function
219     * @tc.level     : Level 0
220     */
221    it('SUB_REQUEST_UPLOAD_API_0004', 0, async function (done) {
222      console.info("-----------------------SUB_REQUEST_UPLOAD_API_0004 is starting-----------------------");
223      try {
224        console.info("SUB_REQUEST_UPLOAD_API_0004 request.PAUSED_UNKNOWN:" + request.PAUSED_UNKNOWN);
225        expect(request.PAUSED_UNKNOWN).assertEqual(4);
226        console.info("SUB_REQUEST_UPLOAD_API_0004 request.PAUSED_WAITING_FOR_NETWORK:" + request.PAUSED_WAITING_FOR_NETWORK);
227        expect(request.PAUSED_WAITING_FOR_NETWORK).assertEqual(1);
228        console.info("SUB_REQUEST_UPLOAD_API_0004 request.PAUSED_WAITING_TO_RETRY:" + request.PAUSED_WAITING_TO_RETRY);
229        expect(request.PAUSED_WAITING_TO_RETRY).assertEqual(2);
230        console.info("SUB_REQUEST_UPLOAD_API_0004 request.SESSION_FAILED:" + request.SESSION_FAILED);
231        expect(request.SESSION_FAILED).assertEqual(4);
232      } catch (err) {
233        console.error("SUB_REQUEST_UPLOAD_API_0004 error: " + err);
234        expect().assertFail();
235      }
236      console.info("-----------------------SUB_REQUEST_UPLOAD_API_0004 end-----------------------");
237      done();
238    });
239
240    /**
241     * @tc.number    SUB_REQUEST_UPLOAD_API_0005
242     * @tc.name      Test requestUploadTest type = TIMER_TYPE_REALTIME
243     * @tc.desc      Test requestUploadTest API functionality.
244     * @tc.size      : MEDIUM
245     * @tc.type      : Function
246     * @tc.level     : Level 0
247     */
248    it('SUB_REQUEST_UPLOAD_API_0005', 0, async function (done) {
249      console.info("-----------------------SUB_REQUEST_UPLOAD_API_0005 is starting-----------------------");
250      try {
251        console.info("SUB_REQUEST_UPLOAD_API_0005 request.SESSION_PAUSED:" + request.SESSION_PAUSED);
252        expect(request.SESSION_PAUSED).assertEqual(3);
253        console.info("SUB_REQUEST_UPLOAD_API_0005 request.SESSION_PENDING:" + request.SESSION_PENDING);
254        expect(request.SESSION_PENDING).assertEqual(2);
255        console.info("SUB_REQUEST_UPLOAD_API_0005 request.SESSION_RUNNING:" + request.SESSION_RUNNING);
256        expect(request.SESSION_RUNNING).assertEqual(1);
257        console.info("SUB_REQUEST_UPLOAD_API_0005 request.SESSION_SUCCESSFUL:" + request.SESSION_SUCCESSFUL);
258        expect(request.SESSION_SUCCESSFUL).assertEqual(0);
259      } catch (err) {
260        console.error("SUB_REQUEST_UPLOAD_API_0005 error: " + err);
261        expect().assertFail();
262      }
263      console.info("-----------------------SUB_REQUEST_UPLOAD_API_0005 end-----------------------");
264      done();
265    });
266
267    /**
268     * @tc.number    SUB_REQUEST_UPLOAD_API_CALLBACK_0001
269     * @tc.name      Test requestUploadTest type = TIMER_TYPE_REALTIME
270     * @tc.desc      Test requestUploadTest API functionality.
271     * @tc.size      : MEDIUM
272     * @tc.type      : Function
273     * @tc.level     : Level 1
274     */
275    it('SUB_REQUEST_UPLOAD_API_CALLBACK_0001', 0, async function (done) {
276        let file = fs.openSync(cacheDir + '/test.txt', fs.OpenMode.READ_WRITE | fs.OpenMode.CREATE);
277        fs.closeSync(file);
278        console.info("-----------------------SUB_REQUEST_UPLOAD_API_CALLBACK_0001 is starting-----------------------");
279        try {
280          console.info("SUB_REQUEST_UPLOAD_API_CALLBACK_0001 uploadConfig: " + JSON.stringify(uploadConfig1));
281          request.upload(uploadConfig1, (err, data) => {
282            uploadTask = data;
283            console.info("SUB_REQUEST_UPLOAD_API_CALLBACK_0001 progress uploadTask: " + JSON.stringify(uploadTask));
284            expect(uploadTask !== undefined).assertEqual(true);
285
286            function ProgressCallback(data1, data2) {
287              console.info("SUB_REQUEST_UPLOAD_API_CALLBACK_0001 on data1: " + data1 + ", data1: " + data2);
288              expect(true).assertEqual((data1 !== undefined) || (data1 !== "") || (data1 !== {}));
289              expect(true).assertEqual((data2 !== undefined) || (data2 != "") || (data2 !== {}));
290            }
291            uploadTask.on('progress', ProgressCallback);
292            uploadTask.off('progress', ProgressCallback);
293
294            uploadTask.remove((result) => {
295              console.info("SUB_REQUEST_UPLOAD_API_CALLBACK_0001 remove: " + result);
296              expect(result).assertEqual(true);
297            });
298          });
299        } catch (err) {
300          console.error("SUB_REQUEST_UPLOAD_API_CALLBACK_0001 error: " + err);
301          expect().assertFail();
302        }
303        console.info("-----------------------SUB_REQUEST_UPLOAD_API_CALLBACK_0001 end-----------------------");
304        done();
305    });
306
307    /**
308     * @tc.number    : SUB_REQUEST_UPLOAD_API_PROMISE_0001
309     * @tc.name      : Use getEntries get the value by mixing the string key
310     * @tc.desc      : Mixed strings value can be obtained correctly
311     * @tc.size      : MediumTest
312     * @tc.type      : Function
313     * @tc.level     : Level 1
314     */
315    it('SUB_REQUEST_UPLOAD_API_PROMISE_0001', 0, async function (done) {
316        let file = fs.openSync(cacheDir + '/test.txt', fs.OpenMode.READ_WRITE | fs.OpenMode.CREATE);
317        fs.closeSync(file);
318        console.info("-----------------------SUB_REQUEST_UPLOAD_API_PROMISE_0001 is starting-----------------------");
319        try {
320          console.info("SUB_REQUEST_UPLOAD_API_PROMISE_0001 UploadConfig: " + JSON.stringify(uploadConfig1));
321          request.upload(uploadConfig1).then((data) => {
322            uploadTask = data;
323            console.info("SUB_REQUEST_UPLOAD_API_PROMISE_0001 uploadTask: " + uploadTask);
324            expect(true).assertEqual((uploadTask !== undefined) || (uploadTask !== "") || (uploadTask !== {}));
325            function HeaderReceiveCallback(header) {
326              console.info("SUB_REQUEST_UPLOAD_API_PROMISE_0001 on header: " + header);
327              expect(true).assertEqual((header !== undefined) || (header !== "") || (header !== {}));
328            }
329            uploadTask.on('headerReceive', HeaderReceiveCallback);
330            uploadTask.off('headerReceive', HeaderReceiveCallback);
331
332            uploadTask.remove().then((result)=>{
333              console.info("SUB_REQUEST_UPLOAD_API_PROMISE_0001 remove result: " + result);
334              expect(result).assertEqual(true);
335            });
336          });
337        } catch (e) {
338          console.error("SUB_REQUEST_UPLOAD_API_PROMISE_0001 error: " + JSON.stringify(e));
339          expect().assertFail();
340        }
341        console.info("-----------------------SUB_REQUEST_UPLOAD_API_PROMISE_0001 end-----------------------");
342        done();
343    });
344
345    /**
346     * @tc.number    : SUB_REQUEST_UPLOAD_API_PROMISE_0002
347     * @tc.name      : Use getEntries get the value by mixing the string key
348     * @tc.desc      : Called when the current upload session complete or fail.
349     * @tc.size      : MediumTest
350     * @tc.type      : Function
351     * @tc.level     : Level 1
352     */
353    it('SUB_REQUEST_UPLOAD_API_PROMISE_0002', 0, async function (done) {
354        let file = fs.openSync(cacheDir + '/test.txt', fs.OpenMode.READ_WRITE | fs.OpenMode.CREATE);
355        fs.closeSync(file);
356        console.info("-----------------------SUB_REQUEST_UPLOAD_API_PROMISE_0002 is starting-----------------------");
357        try {
358          console.info("SUB_REQUEST_UPLOAD_API_PROMISE_0002 UploadConfig: " + JSON.stringify(uploadConfig));
359          request.upload(uploadConfig).then((data) => {
360            uploadTask = data;
361            console.info("SUB_REQUEST_UPLOAD_API_PROMISE_0002 uploadTask: " + uploadTask);
362            expect(true).assertEqual((uploadTask !== undefined) || (uploadTask !== "") || (uploadTask !== {}));
363            uploadTask.on('fail', (TaskState) => {
364              console.info("SUB_REQUEST_UPLOAD_API_PROMISE_0002 fail TaskState.path: " + TaskState.path +
365                ", TaskState.responseCode: " + TaskState.responseCode + ", TaskState.message: " + TaskState.message);
366
367              expect(typeof(TaskState.path) == "string").assertEqual(true);
368              expect(typeof(TaskState.responseCode) == "number").assertEqual(true);
369              expect(typeof(TaskState.message) == "string").assertEqual(true);
370            });
371          });
372        } catch (e) {
373          console.error("SUB_REQUEST_UPLOAD_API_PROMISE_0002 error: " + JSON.stringify(e));
374          expect().assertFail();
375        }
376        console.info("-----------------------SUB_REQUEST_UPLOAD_API_PROMISE_0002 end-----------------------");
377        done();
378    });
379
380    /**
381     * @tc.number    : SUB_REQUEST_UPLOAD_API_PROMISE_0003
382     * @tc.name      : Use getEntries get the value by mixing the string key
383     * @tc.desc      : Called when the current upload session complete or fail.
384     * @tc.size      : MediumTest
385     * @tc.type      : Function
386     * @tc.level     : Level 1
387    */
388    it('SUB_REQUEST_UPLOAD_API_PROMISE_0003', 0, async function (done) {
389        let file = fs.openSync(cacheDir + '/test.txt', fs.OpenMode.READ_WRITE | fs.OpenMode.CREATE);
390        fs.closeSync(file);
391        console.info("-----------------------SUB_REQUEST_UPLOAD_API_PROMISE_0003 is starting-----------------------");
392        try {
393          console.info("SUB_REQUEST_UPLOAD_API_PROMISE_0003 UploadConfig: " + JSON.stringify(uploadConfig));
394          request.upload(uploadConfig).then((data) => {
395            uploadTask = data;
396            console.info("SUB_REQUEST_UPLOAD_API_PROMISE_0003 uploadTask: " + uploadTask);
397            expect(true).assertEqual((uploadTask !== undefined) || (uploadTask !== "") || (uploadTask !== {}));
398
399            uploadTask.off('complete');
400            uploadTask.off('fail');
401          });
402        } catch (e) {
403          console.error("SUB_REQUEST_UPLOAD_API_PROMISE_0003 error: " + JSON.stringify(e));
404          expect().assertFail();
405        }
406        console.info("-----------------------SUB_REQUEST_UPLOAD_API_PROMISE_0003 end-----------------------");
407        done();
408    });
409
410    /**
411     * @tc.number    SUB_REQUEST_UPLOADFILE_API_PARTIAL_0001
412     * @tc.name      Test function of partial upload.
413     * @tc.desc      Test if the partial upload success or fail.
414     * @tc.size      : MEDIUM
415     * @tc.type      : Function
416     * @tc.level     : Level 0
417     */
418    it('SUB_REQUEST_UPLOADFILE_API_PARTIAL_0001', 0, async function (done) {
419      console.info("====>-----------------------SUB_REQUEST_UPLOADFILE_API_PARTIAL_0001 is starting-----------------------");
420      try {
421        console.info("====>SUB_REQUEST_UPLOADFILE_API_PARTIAL_0001 UploadConfig2 = " + JSON.stringify(uploadConfig2));
422        // @ts-ignore
423        await request.uploadFile(globalThis.abilityContext, uploadConfig2).then((uploadTask) => {
424          console.info("====>SUB_REQUEST_UPLOADFILE_API_PARTIAL_0001 uploadTask = " + uploadTask);
425          expect(true).assertEqual((uploadTask != undefined));
426          let complete_callback = async (tasks) => {
427            try {
428              uploadTask.off('complete');
429              console.info("====>SUB_REQUEST_UPLOADFILE_API_PARTIAL_0001 tasks0 = " + JSON.stringify(tasks[0])
430              + ", path = " + tasks[0].path + ", responseCode" + tasks[0].responseCode + ", message = " + tasks[0].message);
431              let bool = await uploadTask.delete();
432              console.info("====>SUB_REQUEST_UPLOADFILE_API_PARTIAL_0001 remove result = " + bool);
433              done();
434            } catch (err) {
435              console.info("====>SUB_REQUEST_UPLOADFILE_API_PARTIAL_0001 fail = " + JSON.stringify(err));
436              done();
437            }
438          }
439
440          console.info("====>SUB_REQUEST_UPLOADFILE_API_PARTIAL_0001 headerReceive success");
441          uploadTask.on('complete', complete_callback);
442
443        }).catch((err) => {
444          console.error("====>SUB_REQUEST_UPLOADFILE_API_PARTIAL_0001 catch err: " + JSON.stringify(err));
445        });
446      } catch (err) {
447        console.error("====>SUB_REQUEST_UPLOADFILE_API_PARTIAL_0001 fail error: " + JSON.stringify(err));
448        done();
449      }
450    });
451
452    /**
453     * @tc.number    SUB_REQUEST_UPLOADFILE_API_PARTIAL_0002
454     * @tc.name      Test function of partial upload.
455     * @tc.desc      Test if the partial upload with abnormal input success or fail.
456     * @tc.size      : MEDIUM
457     * @tc.type      : Function
458     * @tc.level     : Level 0
459     */
460    it('SUB_REQUEST_UPLOADFILE_API_PARTIAL_0002', 0, async function (done) {
461      console.info("====>-----------------------SUB_REQUEST_UPLOADFILE_API_PARTIAL_0002 is starting-----------------------");
462      try {
463        console.info("====>SUB_REQUEST_UPLOADFILE_API_PARTIAL_0002 UploadConfig3 = " + JSON.stringify(UploadConfig3));
464        // @ts-ignore
465        await request.uploadFile(globalThis.abilityContext, UploadConfig3).then((uploadTask) => {
466          console.info("====>SUB_REQUEST_UPLOADFILE_API_PARTIAL_0002 uploadTask = " + uploadTask);
467          expect(true).assertEqual((uploadTask != undefined));
468          let complete_callback = async (tasks) => {
469            try {
470              uploadTask.off('complete');
471              console.info("====>SUB_REQUEST_UPLOADFILE_API_PARTIAL_0001 tasks0 = " + JSON.stringify(tasks[0])
472              + ", path = " + tasks[0].path + ", responseCode" + tasks[0].responseCode + ", message = " + tasks[0].message);
473              let bool = await uploadTask.delete();
474              console.info("====>SUB_REQUEST_UPLOADFILE_API_PARTIAL_0002 remove result = " + bool);
475              done();
476            } catch (err) {
477              console.info("====>SUB_REQUEST_UPLOADFILE_API_PARTIAL_0002 fail = " + JSON.stringify(err));
478              done();
479            }
480          }
481
482          console.info("====>SUB_REQUEST_UPLOADFILE_API_PARTIAL_0002 headerReceive success");
483          uploadTask.on('complete', complete_callback);
484
485        }).catch((err) => {
486          console.error("====>SUB_REQUEST_UPLOADFILE_API_PARTIAL_0002 catch err: " + JSON.stringify(err));
487        });
488      } catch (err) {
489        console.error("====>SUB_REQUEST_UPLOADFILE_API_PARTIAL_0002 fail error: " + JSON.stringify(err));
490        done();
491      }
492    });
493
494    /**
495     * @tc.number    SUB_REQUEST_UPLOADFILE_API_PARTIAL_0003
496     * @tc.name      Test function of partial upload.
497     * @tc.desc      Test if the partial upload with abnormal input success or fail.
498     * @tc.size      : MEDIUM
499     * @tc.type      : Function
500     * @tc.level     : Level 0
501     */
502    it('SUB_REQUEST_UPLOADFILE_API_PARTIAL_0003', 0, async function (done) {
503      console.info("====>-----------------------SUB_REQUEST_UPLOADFILE_API_PARTIAL_0003 is starting-----------------------");
504      try {
505        console.info("====>SUB_REQUEST_UPLOADFILE_API_PARTIAL_0003 UploadConfig4 = " + JSON.stringify(UploadConfig4));
506        // @ts-ignore
507        await request.uploadFile(globalThis.abilityContext, UploadConfig4).then((uploadTask) => {
508          console.info("====>SUB_REQUEST_UPLOADFILE_API_PARTIAL_0003 uploadTask = " + uploadTask);
509          expect(true).assertEqual((uploadTask != undefined));
510          let complete_callback = async (tasks) => {
511            try {
512              uploadTask.off('complete');
513              console.info("====>SUB_REQUEST_UPLOADFILE_API_PARTIAL_0001 tasks0 = " + JSON.stringify(tasks[0])
514              + ", path = " + tasks[0].path + ", responseCode" + tasks[0].responseCode + ", message = " + tasks[0].message);
515              let bool = await uploadTask.delete();
516              console.info("====>SUB_REQUEST_UPLOADFILE_API_PARTIAL_0003 remove result = " + bool);
517              done();
518            } catch (err) {
519              console.info("====>SUB_REQUEST_UPLOADFILE_API_PARTIAL_0003 fail = " + JSON.stringify(err));
520              done();
521            }
522          }
523
524          console.info("====>SUB_REQUEST_UPLOADFILE_API_PARTIAL_0003 headerReceive success");
525          uploadTask.on('complete', complete_callback);
526
527        }).catch((err) => {
528          console.error("====>SUB_REQUEST_UPLOADFILE_API_PARTIAL_0003 catch err: " + JSON.stringify(err));
529        });
530      } catch (err) {
531        console.error("====>SUB_REQUEST_UPLOADFILE_API_PARTIAL_0003 fail error: " + JSON.stringify(err));
532        done();
533      }
534    });
535
536    console.log(TAG + "*************Unit Test End*************");
537})