From dc9cb62764ba4130171c8df5b7cf2bbc59fd4ce3 Mon Sep 17 00:00:00 2001 From: 15829070344 Date: Sat, 5 Nov 2022 20:29:13 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E4=B8=8A=E4=BC=A0=E4=B8=8B=E8=BD=BD?= =?UTF-8?q?=E3=80=91sleep=20modified=20to=20setTimeout?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 15829070344 Change-Id: Ifa5b1f0c717f21dcea6a74864fb2c300774af7d5 --- .../src/main/ets/MainAbility/MainAbility.ts | 2 + .../main/ets/test/requestDownload.test.ets | 39 ++-- .../src/main/ets/test/requestUpload.test.ets | 167 ++++++++++++++---- 3 files changed, 160 insertions(+), 48 deletions(-) diff --git a/request/RequestTest_Stage/entry/src/main/ets/MainAbility/MainAbility.ts b/request/RequestTest_Stage/entry/src/main/ets/MainAbility/MainAbility.ts index 9dc331bc8..ad865b2b2 100644 --- a/request/RequestTest_Stage/entry/src/main/ets/MainAbility/MainAbility.ts +++ b/request/RequestTest_Stage/entry/src/main/ets/MainAbility/MainAbility.ts @@ -35,6 +35,8 @@ export default class MainAbility extends Ability { hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO); hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageCreate'); + globalThis.abilityContext = this.context; + windowStage.loadContent('pages/index', (err, data) => { if (err.code) { hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.ERROR); diff --git a/request/RequestTest_Stage/entry/src/main/ets/test/requestDownload.test.ets b/request/RequestTest_Stage/entry/src/main/ets/test/requestDownload.test.ets index 66b23f0d8..93ef631ca 100644 --- a/request/RequestTest_Stage/entry/src/main/ets/test/requestDownload.test.ets +++ b/request/RequestTest_Stage/entry/src/main/ets/test/requestDownload.test.ets @@ -19,34 +19,34 @@ import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from export default function requestDownloadJSUnit() { describe('requestDownloadJSUnit', function () { - console.info('################################request download Test start'); + console.info('====>################################request download Test start'); /** * beforeAll: Prerequisites at the test suite level, which are executed before the test suite is executed. */ beforeAll(function () { - console.info('beforeAll: Prerequisites are executed.'); + console.info('====>beforeAll: Prerequisites are executed.'); }); /** * beforeEach: Prerequisites at the test case level, which are executed before each test case is executed. */ beforeEach(function () { - console.info('beforeEach: Prerequisites is executed.'); + console.info('====>beforeEach: Prerequisites is executed.'); }); /** * afterEach: Test case-level clearance conditions, which are executed after each test case is executed. */ afterEach(function () { - console.info('afterEach: Test case-level clearance conditions is executed.'); + console.info('====>afterEach: Test case-level clearance conditions is executed.'); }); /** * afterAll: Test suite-level cleanup condition, which is executed after the test suite is executed. */ afterAll(function () { - console.info('afterAll: Test suite-level cleanup condition is executed'); + console.info('====>afterAll: Test suite-level cleanup condition is executed'); }); let downloadTask; @@ -72,21 +72,24 @@ export default function requestDownloadJSUnit() { * @tc.level : Level 2 */ it('SUB_REQUEST_DOWNLOAD_STAGE_API_CALLBACK_0001', 0, async function (done) { - console.info("-----------------------SUB_REQUEST_DOWNLOAD_STAGE_API_CALLBACK_0001 is starting-----------------------"); + console.info("====>------------------SUB_REQUEST_DOWNLOAD_STAGE_API_CALLBACK_0001 is starting-----------------------"); let abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator(); let context = abilityDelegator.getAppContext(); try { - request.download(context, downloadConfig, (data)=>{ + request.download(context, downloadConfig, (err, data)=>{ downloadTask = data; - console.info("SUB_REQUEST_DOWNLOAD_STAGE_API_CALLBACK_0001 downloadTask: " + downloadTask); + console.info("====>SUB_REQUEST_DOWNLOAD_STAGE_API_CALLBACK_0001 downloadTask: " + downloadTask); expect(true).assertEqual(downloadTask != undefined); }); } catch (err) { - console.error("SUB_REQUEST_DOWNLOAD_STAGE_API_CALLBACK_0001 error: " + err); + console.info("====>SUB_REQUEST_DOWNLOAD_STAGE_API_CALLBACK_0001 error: " + err); expect().assertFail(); } - console.info("-----------------------SUB_REQUEST_DOWNLOAD_STAGE_API_CALLBACK_0001 end-----------------------"); - done(); + setTimeout(()=>{ + console.info("====>------------------SUB_REQUEST_DOWNLOAD_STAGE_API_CALLBACK_0001 end-----------------------"); + done(); + },5000) + }); /** @@ -97,19 +100,21 @@ export default function requestDownloadJSUnit() { * @tc.level : Level 2 */ it('SUB_REQUEST_DOWNLOAD_STAGE_API_PROMISE_0001', 0, async function (done) { - console.info("-----------------------SUB_REQUEST_DOWNLOAD_STAGE_API_PROMISE_0001 is starting-----------------------"); + console.info("====>------------------SUB_REQUEST_DOWNLOAD_STAGE_API_PROMISE_0001 is starting-----------------------"); let abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator(); let context = abilityDelegator.getAppContext(); request.download(context, downloadConfig).then(data => { downloadTask = data; - console.info("SUB_REQUEST_DOWNLOAD_STAGE_API_PROMISE_0001 downloadTask: " + downloadTask); + console.info("====>SUB_REQUEST_DOWNLOAD_STAGE_API_PROMISE_0001 downloadTask: " + downloadTask); expect(true).assertEqual(downloadTask != undefined); }).catch(err => { - console.error("SUB_REQUEST_DOWNLOAD_STAGE_API_PROMISE_0001 error: " + err); + console.info("====>SUB_REQUEST_DOWNLOAD_STAGE_API_PROMISE_0001 error: " + err); expect().assertFail(); }) - console.info("-----------------------SUB_REQUEST_DOWNLOAD_STAGE_API_PROMISE_0001 end-----------------------"); - done(); - }); + setTimeout(()=>{ + console.info("====>------------------SUB_REQUEST_DOWNLOAD_STAGE_API_PROMISE_0001 end-----------------------"); + done(); + },5000) + }); }); } \ No newline at end of file diff --git a/request/RequestTest_Stage/entry/src/main/ets/test/requestUpload.test.ets b/request/RequestTest_Stage/entry/src/main/ets/test/requestUpload.test.ets index f131dec47..589138565 100644 --- a/request/RequestTest_Stage/entry/src/main/ets/test/requestUpload.test.ets +++ b/request/RequestTest_Stage/entry/src/main/ets/test/requestUpload.test.ets @@ -19,34 +19,34 @@ import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from export default function requestUploadJSUnit() { describe('requestUploadJSUnit', function () { - console.info('################################request upload Test start'); + console.info('====>################################request upload Test start'); /** * beforeAll: Prerequisites at the test suite level, which are executed before the test suite is executed. */ beforeAll(function () { - console.info('beforeAll: Prerequisites are executed.'); + console.info('====>beforeAll: Prerequisites are executed.'); }); /** * beforeEach: Prerequisites at the test case level, which are executed before each test case is executed. */ beforeEach(function () { - console.info('beforeEach: Prerequisites is executed.'); + console.info('====>beforeEach: Prerequisites is executed.'); }); /** * afterEach: Test case-level clearance conditions, which are executed after each test case is executed. */ afterEach(function () { - console.info('afterEach: Test case-level clearance conditions is executed.'); + console.info('====>afterEach: Test case-level clearance conditions is executed.'); }); /** * afterAll: Test suite-level cleanup condition, which is executed after the test suite is executed. */ afterAll(function () { - console.info('afterAll: Test suite-level cleanup condition is executed'); + console.info('====>afterAll: Test suite-level cleanup condition is executed'); }); /** @@ -88,37 +88,38 @@ export default function requestUploadJSUnit() { * @tc.level : Level 1 */ it('SUB_REQUEST_UPLOAD_STAGE_API_CALLBACK_0001', 0, async function (done) { - console.info("-----------------------SUB_REQUEST_UPLOAD_STAGE_API_CALLBACK_0001 is starting-----------------------"); + console.info("====>------------------SUB_REQUEST_UPLOAD_STAGE_API_CALLBACK_0001 is starting-----------------------"); try { - console.info("SUB_REQUEST_UPLOAD_STAGE_API_CALLBACK_0001 uploadConfig = " + JSON.stringify(uploadConfig)); + console.info("====>SUB_REQUEST_UPLOAD_STAGE_API_CALLBACK_0001 uploadConfig = " + JSON.stringify(uploadConfig)); let abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator(); - let appContext = abilityDelegator.getAppContext(); - console.info("SUB_REQUEST_UPLOAD_STAGE_API_CALLBACK_0001 context = " + appContext); - request.upload(appContext, uploadConfig, (data) => { + request.upload(globalThis.abilityContext, uploadConfig, (err, data) => { uploadTask = data; - console.info("SUB_REQUEST_UPLOAD_STAGE_API_CALLBACK_0001 progress uploadTask =" + JSON.stringify(uploadTask)); + console.info("====>SUB_REQUEST_UPLOAD_STAGE_API_CALLBACK_0001 progress uploadTask =" + JSON.stringify(uploadTask)); + console.info("====>SUB_REQUEST_UPLOAD_STAGE_API_CALLBACK_0001 progress uploadTask =" + uploadTask); expect(true).assertEqual(uploadTask != undefined); uploadTask.on('progress', function (data1, data2) { - console.info("SUB_REQUEST_UPLOAD_STAGE_API_CALLBACK_0001 on data1 =" + data1); - console.info("SUB_REQUEST_UPLOAD_STAGE_API_CALLBACK_0001 on data2 =" + data2); + console.info("====>SUB_REQUEST_UPLOAD_STAGE_API_CALLBACK_0001 on data1 =" + data1); + console.info("====>SUB_REQUEST_UPLOAD_STAGE_API_CALLBACK_0001 on data2 =" + data2); }); uploadTask.off('progress', function (data1, data2) { - console.info("SUB_REQUEST_UPLOAD_STAGE_API_CALLBACK_0001 off data1 =" + data1); - console.info("SUB_REQUEST_UPLOAD_STAGE_API_CALLBACK_0001 off data2 =" + data2); + console.info("====>SUB_REQUEST_UPLOAD_STAGE_API_CALLBACK_0001 off data1 =" + data1); + console.info("====>SUB_REQUEST_UPLOAD_STAGE_API_CALLBACK_0001 off data2 =" + data2); }); uploadTask.remove((err, data) => { - console.info("SUB_REQUEST_UPLOAD_STAGE_API_CALLBACK_0001 remove =" + data); + console.info("====>SUB_REQUEST_UPLOAD_STAGE_API_CALLBACK_0001 remove =" + data); }); }); } catch (err) { - console.error("SUB_REQUEST_UPLOAD_STAGE_API_CALLBACK_0001 error: " + err); + console.info("====>SUB_REQUEST_UPLOAD_STAGE_API_CALLBACK_0001 error: " + err); expect().assertFail(); } - console.info("-----------------------SUB_REQUEST_UPLOAD_STAGE_API_CALLBACK_0001 end-----------------------"); - done(); + setTimeout(()=>{ + console.info("====>------------------SUB_REQUEST_UPLOAD_STAGE_API_CALLBACK_0001 end-----------------------"); + done(); + }, 10000) }); /* @@ -130,38 +131,142 @@ export default function requestUploadJSUnit() { * @tc.level : Level 1 */ it('SUB_REQUEST_UPLOAD_STAGE_API_PROMISE_0001', 0, async function (done) { - console.info("-----------------------SUB_REQUEST_UPLOAD_STAGE_API_PROMISE_0001 is starting-----------------------"); + console.info("====>------------------SUB_REQUEST_UPLOAD_STAGE_API_PROMISE_0001 is starting-----------------------"); try { - console.info("SUB_REQUEST_UPLOAD_STAGE_API_PROMISE_0001 UploadConfig = " + JSON.stringify(uploadConfig)); + console.info("====>SUB_REQUEST_UPLOAD_STAGE_API_PROMISE_0001 UploadConfig = " + JSON.stringify(uploadConfig)); let abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator(); - let appContext = abilityDelegator.getAppContext(); - console.info("SUB_REQUEST_UPLOAD_STAGE_API_PROMISE_0001 context = " + appContext); - request.upload(appContext, uploadConfig).then((data) => { + request.upload(globalThis.abilityContext, uploadConfig).then((data) => { uploadTask = data; - console.info("SUB_REQUEST_UPLOAD_STAGE_API_PROMISE_0001 uploadTask = " + uploadTask); + console.info("====>SUB_REQUEST_UPLOAD_STAGE_API_PROMISE_0001 uploadTask = " + uploadTask); expect(true).assertEqual(uploadTask != undefined); uploadTask.on('headerReceive', (header) => { - console.info("SUB_REQUEST_UPLOAD_STAGE_API_PROMISE_0001 header = " + header); + console.info("====>SUB_REQUEST_UPLOAD_STAGE_API_PROMISE_0001 header = " + header); expect(true).assertEqual((header != undefined) || (header != "") || (header != {})); }); uploadTask.off('headerReceive', (header) => { - console.info("SUB_REQUEST_UPLOAD_STAGE_API_PROMISE_0001 header = " + header); + console.info("====>SUB_REQUEST_UPLOAD_STAGE_API_PROMISE_0001 header = " + header); expect(true).assertEqual((header != undefined) || (header != "") || (header != {})); }); uploadTask.remove().then((result)=>{ - console.info("SUB_REQUEST_UPLOAD_STAGE_API_PROMISE_0001 remove result = " + result); + console.info("====>SUB_REQUEST_UPLOAD_STAGE_API_PROMISE_0001 remove result = " + result); expect(result).assertEqual(true); }); }); } catch (e) { - console.error("SUB_REQUEST_UPLOAD_STAGE_API_PROMISE_0001 error: " + JSON.stringify(e)); + console.info("====>SUB_REQUEST_UPLOAD_STAGE_API_PROMISE_0001 error: " + JSON.stringify(e)); expect(e).assertFail(); } - console.info("-----------------------SUB_REQUEST_UPLOAD_STAGE_API_PROMISE_0001 end-----------------------"); - done(); + setTimeout(()=>{ + console.info("====>------------------SUB_REQUEST_UPLOAD_STAGE_API_PROMISE_0001 end-----------------------"); + done(); + }, 10000) + }); + + /** + * @tc.number : SUB_REQUEST_UPLOAD_API_PROMISE_0002 + * @tc.name : Use getEntries get the value by mixing the string key + * @tc.desc : Called when the current upload session complete or fail. + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 1 + */ + it('SUB_REQUEST_UPLOAD_API_PROMISE_0002', 0, async function (done) { + console.info("====>------------------SUB_REQUEST_UPLOAD_API_PROMISE_0002 is starting-----------------------"); + try { + console.info("====>SUB_REQUEST_UPLOAD_API_PROMISE_0002 UploadConfig = " + JSON.stringify(uploadConfig)); + request.upload(globalThis.abilityContext, uploadConfig).then((data) => { + try{ + uploadTask = data; + console.info("====>SUB_REQUEST_UPLOAD_API_PROMISE_0002 uploadTask = " + uploadTask); + expect(true).assertEqual((uploadTask != undefined) || (uploadTask != "") || (uploadTask != {})); + + uploadTask.on('complete', (TaskState) => { + for(let i = 0; i < TaskState.length; i++){ + console.info("====>SUB_REQUEST_UPLOAD_API_PROMISE_0002 complete TaskState = " + JSON.stringify(TaskState[i])) + console.info("====>SUB_REQUEST_UPLOAD_API_PROMISE_0002 complete TaskState.path = " + TaskState[i].path); + console.info("====>SUB_REQUEST_UPLOAD_API_PROMISE_0002 complete TaskState.responseCode = " + TaskState[i].responseCode); + console.info("====>SUB_REQUEST_UPLOAD_API_PROMISE_0002 complete TaskState.TaskState.message = " + TaskState[i].message); + expect(typeof(TaskState[i].path) == "string").assertEqual(true); + expect(typeof(TaskState[i].responseCode) == "number").assertEqual(true); + expect(typeof(TaskState[i].message) == "string").assertEqual(true); + } + done(); + }); + + uploadTask.on('fail', (TaskState) => { + for(let i = 0; i < TaskState.length; i++){ + console.info("====>SUB_REQUEST_UPLOAD_API_PROMISE_0002 fail TaskState = " + JSON.stringify(TaskState[i])) + console.info("====>SUB_REQUEST_UPLOAD_API_PROMISE_0002 fail TaskState.path = " + TaskState[i].path); + console.info("====>SUB_REQUEST_UPLOAD_API_PROMISE_0002 fail TaskState.responseCode = " + TaskState[i].responseCode); + console.info("====>SUB_REQUEST_UPLOAD_API_PROMISE_0002 fail TaskState.TaskState.message = " + TaskState[i].message); + expect(typeof(TaskState[i].path) == "string").assertEqual(true); + expect(typeof(TaskState[i].responseCode) == "number").assertEqual(true); + expect(typeof(TaskState[i].message) == "string").assertEqual(true); + } + expect(true).assertEqual(true); + }); + }catch(err){ + console.info("====>SUB_REQUEST_UPLOAD_API_PROMISE_0002 error: " + JSON.stringify(err)); + expect(true).assertFail(true); + } + }).catch((err)=>{ + console.info("====>SUB_REQUEST_UPLOAD_API_PROMISE_0002 error: " + JSON.stringify(err)); + expect(true).assertFail(true); + }) + } catch (e) { + console.info("====>SUB_REQUEST_UPLOAD_API_PROMISE_0002 throw_error: " + JSON.stringify(e)); + expect(true).assertFail(true); + } + setTimeout(()=>{ + console.info("====>------------------SUB_REQUEST_UPLOAD_API_PROMISE_0002 end-----------------------"); + done(); + }, 10000) + }); + + /** + * @tc.number : SUB_REQUEST_UPLOAD_API_PROMISE_0003 + * @tc.name : Use getEntries get the value by mixing the string key + * @tc.desc : Called when the current upload session complete or fail. + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 1 + */ + it('SUB_REQUEST_UPLOAD_API_PROMISE_0003', 0, async function (done) { + console.info("====>------------------SUB_REQUEST_UPLOAD_API_PROMISE_0003 is starting-----------------------"); + try { + console.info("====>SUB_REQUEST_UPLOAD_API_PROMISE_0003 UploadConfig = " + JSON.stringify(uploadConfig)); + request.upload(globalThis.abilityContext, uploadConfig).then((data) => { + try{ + uploadTask = data; + console.info("====>SUB_REQUEST_UPLOAD_API_PROMISE_0003 uploadTask = " + uploadTask); + expect(true).assertEqual((uploadTask != undefined) || (uploadTask != "") || (uploadTask != {})); + + uploadTask.off('complete', () => { + console.info("====>SUB_REQUEST_UPLOAD_API_PROMISE_0003 TaskState success"); + expect(true).assertEqual(true); + }); + + uploadTask.off('fail', () => { + console.info("====>SUB_REQUEST_UPLOAD_API_PROMISE_0003 TaskState success"); + expect(true).assertEqual(true); + }); + }catch(err){ + expect().assertFail(); + done(); + } + + }); + } catch (e) { + console.info("====>SUB_REQUEST_UPLOAD_API_PROMISE_0003 error: " + JSON.stringify(e)); + expect(true).assertFail(true); + } + setTimeout(()=>{ + console.info("====>------------------SUB_REQUEST_UPLOAD_API_PROMISE_0003 end-----------------------"); + done(); + }, 10000) }); }) } -- GitLab