From 67251fa257bbe2129cd444c02ed7af4b751d1bce Mon Sep 17 00:00:00 2001 From: hu0475 Date: Tue, 11 Jul 2023 19:59:08 +0800 Subject: [PATCH] =?UTF-8?q?'request=E5=AD=90=E7=B3=BB=E7=BB=9F=E8=B7=A8?= =?UTF-8?q?=E5=B9=B3=E5=8F=B0API=E6=B5=8B=E8=AF=95=E5=A5=97=EF=BC=8C?= =?UTF-8?q?=E8=A6=86=E7=9B=96request=E7=9A=84=E4=B8=8B=E8=BD=BDAPI?= =?UTF-8?q?=E4=BB=A5=E5=8F=8A=E5=B8=B8=E9=87=8F'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: hu0475 --- request/BUILD.gn | 1 + .../RequestTest_ets/AppScope/app.json | 16 + .../resources/base/element/string.json | 8 + .../resources/base/media/app_icon.png | Bin 0 -> 6790 bytes .../crossplatform/RequestTest_ets/BUILD.gn | 46 ++ .../crossplatform/RequestTest_ets/Test.json | 19 + .../signature/openharmony_sx.p7b | Bin 0 -> 3453 bytes .../src/main/ets/TestAbility/TestAbility.ets | 64 ++ .../src/main/ets/TestAbility/pages/Index.ets | 49 ++ .../ets/TestRunner/OpenHarmonyTestRunner.ts | 49 ++ .../src/main/ets/test/List.test.ets | 22 + .../main/ets/test/requestConstant.test.ets | 472 +++++++++++++ .../main/ets/test/requestDownload.test.ets | 667 ++++++++++++++++++ .../src/main/ets/test/requestUpload.test.ets | 239 +++++++ .../RequestTest_ets/src/main/module.json | 60 ++ .../main/resources/base/element/color.json | 8 + .../main/resources/base/element/string.json | 16 + .../src/main/resources/base/media/icon.png | Bin 0 -> 6790 bytes .../resources/base/profile/test_pages.json | 5 + 19 files changed, 1741 insertions(+) create mode 100644 request/crossplatform/RequestTest_ets/AppScope/app.json create mode 100644 request/crossplatform/RequestTest_ets/AppScope/resources/base/element/string.json create mode 100644 request/crossplatform/RequestTest_ets/AppScope/resources/base/media/app_icon.png create mode 100644 request/crossplatform/RequestTest_ets/BUILD.gn create mode 100644 request/crossplatform/RequestTest_ets/Test.json create mode 100644 request/crossplatform/RequestTest_ets/signature/openharmony_sx.p7b create mode 100644 request/crossplatform/RequestTest_ets/src/main/ets/TestAbility/TestAbility.ets create mode 100644 request/crossplatform/RequestTest_ets/src/main/ets/TestAbility/pages/Index.ets create mode 100644 request/crossplatform/RequestTest_ets/src/main/ets/TestRunner/OpenHarmonyTestRunner.ts create mode 100644 request/crossplatform/RequestTest_ets/src/main/ets/test/List.test.ets create mode 100644 request/crossplatform/RequestTest_ets/src/main/ets/test/requestConstant.test.ets create mode 100644 request/crossplatform/RequestTest_ets/src/main/ets/test/requestDownload.test.ets create mode 100644 request/crossplatform/RequestTest_ets/src/main/ets/test/requestUpload.test.ets create mode 100644 request/crossplatform/RequestTest_ets/src/main/module.json create mode 100644 request/crossplatform/RequestTest_ets/src/main/resources/base/element/color.json create mode 100644 request/crossplatform/RequestTest_ets/src/main/resources/base/element/string.json create mode 100644 request/crossplatform/RequestTest_ets/src/main/resources/base/media/icon.png create mode 100644 request/crossplatform/RequestTest_ets/src/main/resources/base/profile/test_pages.json diff --git a/request/BUILD.gn b/request/BUILD.gn index ff090cd70..d38c886d3 100644 --- a/request/BUILD.gn +++ b/request/BUILD.gn @@ -19,5 +19,6 @@ group("request") { "RequestTest_ets:ActsRequestETSApiTest", "newRequestAuthorityTest:ActsRequestAuthorityTest", "newRequestTest:ActsRequestNewTest", + "crossplatform/RequestTest_ets:ActsRequestETSApiCrossplatformTest" ] } diff --git a/request/crossplatform/RequestTest_ets/AppScope/app.json b/request/crossplatform/RequestTest_ets/AppScope/app.json new file mode 100644 index 000000000..d4d709a01 --- /dev/null +++ b/request/crossplatform/RequestTest_ets/AppScope/app.json @@ -0,0 +1,16 @@ +{ + "app": { + "bundleName": "ohos.acts.request.crossplatform.request", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name", + "minAPIVersion": 9, + "targetAPIVersion": 9, + "car": { + "apiCompatibleVersion": 9, + "singleUser": false + } + } +} diff --git a/request/crossplatform/RequestTest_ets/AppScope/resources/base/element/string.json b/request/crossplatform/RequestTest_ets/AppScope/resources/base/element/string.json new file mode 100644 index 000000000..3811bc441 --- /dev/null +++ b/request/crossplatform/RequestTest_ets/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "xtsDemo1" + } + ] +} diff --git a/request/crossplatform/RequestTest_ets/AppScope/resources/base/media/app_icon.png b/request/crossplatform/RequestTest_ets/AppScope/resources/base/media/app_icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c GIT binary patch literal 6790 zcmX|G1ymHk)?T_}Vd;>R?p|tHQo6fg38|$UVM!6BLrPFWk?s;$LOP{GmJpBl$qoSA!PUg~PA65-S00{{S`XKG6NkG0RgjEntPrmV+?0|00mu7;+5 zrdpa{2QLqPJ4Y{j7=Mrl{BaxrkdY69+c~(w{Fv-v&aR%aEI&JYSeRTLWm!zbv;?)_ ziZB;fwGbbeL5Q}YLx`J$lp~A09KK8t_z}PZ=4ZzgdeKtgoc+o5EvN9A1K1_<>M?MBqb#!ASf&# zEX?<)!RH(7>1P+j=jqG(58}TVN-$psA6K}atCuI!KTJD&FMmH-78ZejBm)0qc{ESp z|LuG1{QnBUJRg_E=h1#XMWt2%fcoN@l7eAS!Es?Q+;XsRNPhiiE=@AqlLkJzF`O18 zbsbSmKN=aaq8k3NFYZfDWpKmM!coBU0(XnL8R{4=i|wi{!uWYM2je{U{B*K2PVdu&=E zTq*-XsEsJ$u5H4g6DIm2Y!DN`>^v|AqlwuCD;w45K0@eqauiqWf7l&o)+YLHm~|L~ z7$0v5mkobriU!H<@mVJHLlmQqzQ3d6Rh_-|%Yy2li*tHO>_vcnuZ7OR_xkAIuIU&x z-|8Y0wj|6|a6_I(v91y%k_kNw6pnkNdxjqG8!%Vz_d%c_!X+6-;1`GC9_Fpj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u@5eVAQ3?03{C{kBa|v2NhvgJg3u2H0YLE(h{7j%U1~7^Em(9H}{XPU%GgCI<}|$E8f{J zj*;AXmKXEh`%{N$U3&H(-jJT+k*kj7ZtOIJDv-y*nKpx;3$m9_{99{}DEluN+voT6 z&syC3g<#1Ju?CDw28`!${>$g{xM|D5w4^a1<~tEJ^1XFOh)~}z3V&LdpIlJFH<$aEF&()cSI%S!$ zz4s$a2mUes5X&DG%byd&{26~)zG^fU;QN84n*(MKl`ii|r883${RoL5DI_03qCxX1 zB54Mh56L5#_Xba!^%s&Ie) zkEfX;cHPqQG|lIo2zUvMPZA|7NgM&-v5(PA;-rpXQcgwY_O~YgbRfmpeWtzeV0#@i z?&Rp|@w_R(%>_&yQwW{>hS~GNhAn-z!)x~!c8ytmdhC&k-s!I{pDT+yc5R<3-g^E+ zia*0|FQhkd!OXX2{+wFaJtNILap&sW9j^oZi!G}EMA3oJ&gLzfZ-Wg@#&s=yyK~OZ z>pG>$Z56OQ!dV^-4D)C@@&5CpkvzrfjSwS9Rw^0EqonzC6!8fZD%g7C_?81XvVAK* z+FAeERd`k*|H_nYx6aWkl>7Ije!cHz;gpa2-VpxwNcqmCAzRz=r9TQCZ0>sJ&t_12 z_`-%cWmRwY9Qa_&g;Org1=P{iJRAWM7Z& z%k$TICY`<3H-QzaW6w~`-iq*cbI)w?-M4MsAFf}Y`9a{h{_Momd#_zGtPT&X!LNku z^lI-%(rwROD25UogeBPv>^%WAK9w>KpQt0RBprT```}8F&V$&o?=LbOF!h0vE`Y|f zhhiyUzx~-`upCJ1K*_^VJ|yDjZ;ahNpEB#_@h|UeSa$9^Y*vp$ui5ApY%7Xa2y);2 zt{IGZaFTQRTA=0@q})22dw2{GpDE$B7ZllAH+c_io2qne)+7TmgjFI(t7a { + if (err.code) { + hilog.error(0x0000, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? ''); + return; + } + hilog.info(0x0000, 'testTag', 'Succeeded in loading the content. Data: %{public}s', + JSON.stringify(data) ?? ''); + }); + } + + onWindowStageDestroy() { + hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onWindowStageDestroy'); + } + + onForeground() { + hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onForeground'); + } + + onBackground() { + hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onBackground'); + } +} \ No newline at end of file diff --git a/request/crossplatform/RequestTest_ets/src/main/ets/TestAbility/pages/Index.ets b/request/crossplatform/RequestTest_ets/src/main/ets/TestAbility/pages/Index.ets new file mode 100644 index 000000000..ced6b84d3 --- /dev/null +++ b/request/crossplatform/RequestTest_ets/src/main/ets/TestAbility/pages/Index.ets @@ -0,0 +1,49 @@ +/** + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import hilog from '@ohos.hilog'; + +@Entry +@Component +struct Index { + aboutToAppear() { + hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility index aboutToAppear'); + } + @State message: string = 'Hello World' + build() { + Row() { + Column() { + Text(this.message) + .fontSize(50) + .fontWeight(FontWeight.Bold) + Button() { + Text('next page 123') + .fontSize(20) + .fontWeight(FontWeight.Bold) + }.type(ButtonType.Capsule) + .margin({ + top: 20 + }) + .backgroundColor('#0D9FFB') + .width('35%') + .height('5%') + .onClick(()=>{ + }) + } + .width('100%') + } + .height('100%') + } + } \ No newline at end of file diff --git a/request/crossplatform/RequestTest_ets/src/main/ets/TestRunner/OpenHarmonyTestRunner.ts b/request/crossplatform/RequestTest_ets/src/main/ets/TestRunner/OpenHarmonyTestRunner.ts new file mode 100644 index 000000000..92a16d84e --- /dev/null +++ b/request/crossplatform/RequestTest_ets/src/main/ets/TestRunner/OpenHarmonyTestRunner.ts @@ -0,0 +1,49 @@ +import hilog from '@ohos.hilog'; +import TestRunner from '@ohos.application.testRunner'; +import AbilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry'; + +var abilityDelegator = undefined +var abilityDelegatorArguments = undefined + +async function onAbilityCreateCallback() { + hilog.info(0x0000, 'testTag', '%{public}s', 'onAbilityCreateCallback'); +} + +async function addAbilityMonitorCallback(err: any) { + hilog.info(0x0000, 'testTag', 'addAbilityMonitorCallback : %{public}s', JSON.stringify(err) ?? ''); +} + +export default class OpenHarmonyTestRunner implements TestRunner { + constructor() { + } + + onPrepare() { + hilog.info(0x0000, 'testTag', '%{public}s', 'OpenHarmonyTestRunner OnPrepare '); + } + + async onRun() { + hilog.info(0x0000, 'testTag', '%{public}s', 'OpenHarmonyTestRunner onRun run'); + abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments() + abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator() + var testAbilityName = abilityDelegatorArguments.bundleName + '.TestAbility' + let lMonitor = { + abilityName: testAbilityName, + onAbilityCreate: onAbilityCreateCallback, + }; + abilityDelegator.addAbilityMonitor(lMonitor, addAbilityMonitorCallback) + var cmd = 'aa start -d 0 -a TestAbility' + ' -b ' + abilityDelegatorArguments.bundleName + var debug = abilityDelegatorArguments.parameters['-D'] + if (debug == 'true') + { + cmd += ' -D' + } + hilog.info(0x0000, 'testTag', 'cmd : %{public}s', cmd); + abilityDelegator.executeShellCommand(cmd, + (err: any, d: any) => { + hilog.info(0x0000, 'testTag', 'executeShellCommand : err : %{public}s', JSON.stringify(err) ?? ''); + hilog.info(0x0000, 'testTag', 'executeShellCommand : data : %{public}s', d.stdResult ?? ''); + hilog.info(0x0000, 'testTag', 'executeShellCommand : data : %{public}s', d.exitCode ?? ''); + }) + hilog.info(0x0000, 'testTag', '%{public}s', 'OpenHarmonyTestRunner onRun end'); + } +} \ No newline at end of file diff --git a/request/crossplatform/RequestTest_ets/src/main/ets/test/List.test.ets b/request/crossplatform/RequestTest_ets/src/main/ets/test/List.test.ets new file mode 100644 index 000000000..3ecf594c9 --- /dev/null +++ b/request/crossplatform/RequestTest_ets/src/main/ets/test/List.test.ets @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import requestDownloadJSUnit from './requestDownload.test'; +import requestConstantJSUnit from './requestConstant.test'; + +export default function testsuite() { + requestDownloadJSUnit() + requestConstantJSUnit() +} \ No newline at end of file diff --git a/request/crossplatform/RequestTest_ets/src/main/ets/test/requestConstant.test.ets b/request/crossplatform/RequestTest_ets/src/main/ets/test/requestConstant.test.ets new file mode 100644 index 000000000..bb57cf2da --- /dev/null +++ b/request/crossplatform/RequestTest_ets/src/main/ets/test/requestConstant.test.ets @@ -0,0 +1,472 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import request from "@ohos.request"; +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium'; + +export default function requestUploadJSUnit() { + describe('requestConstantJSUnit', function () { + 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.'); + }); + + /** + * beforeEach: Prerequisites at the test case level, which are executed before each test case is executed. + */ + beforeEach(function () { + 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.'); + }); + + /** + * 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'); + }); + + /** + * @tc.number SUB_REQUEST_CONSTANT_0001 + * *@tc.name subRequestConstant0001 + * @tc.desc Test constants of the request module. + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 0 + */ + it('subRequestConstant0001', 0, async function (done) { + console.info("====>-----------------------SUB_REQUEST_CONSTANT_0001 is starting-----------------------"); + expect(typeof request.EXCEPTION_PERMISSION == 'number').assertTrue(); + done(); + }); + + /** + * @tc.number SUB_REQUEST_CONSTANT_0002 + * *@tc.name subRequestConstant0002 + * @tc.desc Test constants of the request module. + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 0 + */ + it('subRequestConstant0002', 0, async function (done) { + console.info("====>-----------------------SUB_REQUEST_CONSTANT_0002 is starting-----------------------"); + expect(typeof request.EXCEPTION_PARAMCHECK == 'number').assertTrue(); + done(); + }); + + /** + * @tc.number SUB_REQUEST_CONSTANT_0003 + * *@tc.name subRequestConstant0003 + * @tc.desc Test constants of the request module. + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 0 + */ + it('subRequestConstant0003', 0, async function (done) { + console.info("====>-----------------------SUB_REQUEST_CONSTANT_0003 is starting-----------------------"); + expect(typeof request.EXCEPTION_UNSUPPORTED == 'number').assertTrue(); + done(); + }); + + /** + * @tc.number SUB_REQUEST_CONSTANT_0004 + * *@tc.name subRequestConstant0004 + * @tc.desc Test constants of the request module. + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 0 + */ + it('subRequestConstant0004', 0, async function (done) { + console.info("====>-----------------------SUB_REQUEST_CONSTANT_0004 is starting-----------------------"); + expect(typeof request.EXCEPTION_FILEIO == 'number').assertTrue(); + done(); + }); + + /** + * @tc.number SUB_REQUEST_CONSTANT_0005 + * *@tc.name subRequestConstant0005 + * @tc.desc Test constants of the request module. + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 0 + */ + it('subRequestConstant0005', 0, async function (done) { + console.info("====>-----------------------SUB_REQUEST_CONSTANT_0005 is starting-----------------------"); + expect(typeof request.EXCEPTION_FILEPATH == 'number').assertTrue(); + done(); + }); + + /** + * @tc.number SUB_REQUEST_CONSTANT_0006 + * *@tc.name subRequestConstant0006 + * @tc.desc Test constants of the request module. + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 0 + */ + it('subRequestConstant0006', 0, async function (done) { + console.info("====>-----------------------SUB_REQUEST_CONSTANT_0006 is starting-----------------------"); + expect(typeof request.EXCEPTION_SERVICE == 'number').assertTrue(); + done(); + }); + + /** + * @tc.number SUB_REQUEST_CONSTANT_0007 + * *@tc.name subRequestConstant0007 + * @tc.desc Test constants of the request module. + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 0 + */ + it('subRequestConstant0007', 0, async function (done) { + console.info("====>-----------------------SUB_REQUEST_CONSTANT_0007 is starting-----------------------"); + expect(typeof request.EXCEPTION_OTHERS == 'number').assertTrue(); + done(); + }); + + /** + * @tc.number SUB_REQUEST_CONSTANT_0008 + * *@tc.name subRequestConstant0008 + * @tc.desc Test constants of the request module. + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 0 + */ + it('subRequestConstant0008', 0, async function (done) { + console.info("====>-----------------------SUB_REQUEST_CONSTANT_0008 is starting-----------------------"); + expect(typeof request.NETWORK_MOBILE == 'number').assertTrue(); + done(); + }); + + /** + * @tc.number SUB_REQUEST_CONSTANT_0009 + * *@tc.name subRequestConstant0009 + * @tc.desc Test constants of the request module. + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 0 + */ + it('subRequestConstant0009', 0, async function (done) { + console.info("====>-----------------------SUB_REQUEST_CONSTANT_0009 is starting-----------------------"); + expect(typeof request.NETWORK_WIFI == 'number').assertTrue(); + done(); + }); + + /** + * @tc.number SUB_REQUEST_CONSTANT_0010 + * *@tc.name subRequestConstant0010 + * @tc.desc Test constants of the request module. + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 0 + */ + it('subRequestConstant0010', 0, async function (done) { + console.info("====>-----------------------SUB_REQUEST_CONSTANT_0010 is starting-----------------------"); + expect(typeof request.ERROR_CANNOT_RESUME == 'number').assertTrue(); + done(); + }); + + /** + * @tc.number SUB_REQUEST_CONSTANT_0011 + * *@tc.name subRequestConstant0011 + * @tc.desc Test constants of the request module. + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 0 + */ + it('subRequestConstant0011', 0, async function (done) { + console.info("====>-----------------------SUB_REQUEST_CONSTANT_0011 is starting-----------------------"); + expect(typeof request.ERROR_DEVICE_NOT_FOUND == 'number').assertTrue(); + done(); + }); + + /** + * @tc.number SUB_REQUEST_CONSTANT_0012 + * *@tc.name subRequestConstant0012 + * @tc.desc Test constants of the request module. + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 0 + */ + it('subRequestConstant0012', 0, async function (done) { + console.info("====>-----------------------SUB_REQUEST_CONSTANT_0012 is starting-----------------------"); + expect(typeof request.ERROR_FILE_ALREADY_EXISTS == 'number').assertTrue(); + done(); + }); + + /** + * @tc.number SUB_REQUEST_CONSTANT_0013 + * *@tc.name subRequestConstant0013 + * @tc.desc Test constants of the request module. + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 0 + */ + it('subRequestConstant0013', 0, async function (done) { + console.info("====>-----------------------SUB_REQUEST_CONSTANT_0013 is starting-----------------------"); + expect(typeof request.ERROR_FILE_ERROR == 'number').assertTrue(); + done(); + }); + + /** + * @tc.number SUB_REQUEST_CONSTANT_0014 + * *@tc.name subRequestConstant0014 + * @tc.desc Test constants of the request module. + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 0 + */ + it('subRequestConstant0014', 0, async function (done) { + console.info("====>-----------------------SUB_REQUEST_CONSTANT_0014 is starting-----------------------"); + expect(typeof request.ERROR_HTTP_DATA_ERROR == 'number').assertTrue(); + done(); + }); + + /** + * @tc.number SUB_REQUEST_CONSTANT_0015 + * *@tc.name subRequestConstant0015 + * @tc.desc Test constants of the request module. + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 0 + */ + it('subRequestConstant0015', 0, async function (done) { + console.info("====>-----------------------SUB_REQUEST_CONSTANT_0015 is starting-----------------------"); + expect(typeof request.ERROR_INSUFFICIENT_SPACE == 'number').assertTrue(); + done(); + }); + + /** + * @tc.number SUB_REQUEST_CONSTANT_0016 + * *@tc.name subRequestConstant0016 + * @tc.desc Test constants of the request module. + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 0 + */ + it('subRequestConstant0016', 0, async function (done) { + console.info("====>-----------------------SUB_REQUEST_CONSTANT_0016 is starting-----------------------"); + expect(typeof request.ERROR_TOO_MANY_REDIRECTS == 'number').assertTrue(); + done(); + }); + + /** + * @tc.number SUB_REQUEST_CONSTANT_0017 + * *@tc.name subRequestConstant0017 + * @tc.desc Test constants of the request module. + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 0 + */ + it('subRequestConstant0017', 0, async function (done) { + console.info("====>-----------------------SUB_REQUEST_CONSTANT_0017 is starting-----------------------"); + expect(typeof request.ERROR_UNHANDLED_HTTP_CODE == 'number').assertTrue(); + done(); + }); + + /** + * @tc.number SUB_REQUEST_CONSTANT_0018 + * *@tc.name subRequestConstant0018 + * @tc.desc Test constants of the request module. + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 0 + */ + it('subRequestConstant0018', 0, async function (done) { + console.info("====>-----------------------SUB_REQUEST_CONSTANT_0018 is starting-----------------------"); + expect(typeof request.ERROR_UNKNOWN == 'number').assertTrue(); + done(); + }); + + /** + * @tc.number SUB_REQUEST_CONSTANT_0019 + * *@tc.name subRequestConstant0019 + * @tc.desc Test constants of the request module. + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 0 + */ + it('subRequestConstant0019', 0, async function (done) { + console.info("====>-----------------------SUB_REQUEST_CONSTANT_0019 is starting-----------------------"); + expect(typeof request.ERROR_OFFLINE == 'number').assertTrue(); + done(); + }); + + /** + * @tc.number SUB_REQUEST_CONSTANT_0020 + * *@tc.name subRequestConstant0020 + * @tc.desc Test constants of the request module. + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 0 + */ + it('subRequestConstant0020', 0, async function (done) { + console.info("====>-----------------------SUB_REQUEST_CONSTANT_0020 is starting-----------------------"); + expect(typeof request.ERROR_UNSUPPORTED_NETWORK_TYPE == 'number').assertTrue(); + done(); + }); + + /** + * @tc.number SUB_REQUEST_CONSTANT_0021 + * *@tc.name subRequestConstant0021 + * @tc.desc Test constants of the request module. + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 0 + */ + it('subRequestConstant0021', 0, async function (done) { + console.info("====>-----------------------SUB_REQUEST_CONSTANT_0021 is starting-----------------------"); + expect(typeof request.PAUSED_QUEUED_FOR_WIFI == 'number').assertTrue(); + done(); + }); + + /** + * @tc.number SUB_REQUEST_CONSTANT_0022 + * *@tc.name subRequestConstant0022 + * @tc.desc Test constants of the request module. + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 0 + */ + it('subRequestConstant0022', 0, async function (done) { + console.info("====>-----------------------SUB_REQUEST_CONSTANT_0022 is starting-----------------------"); + expect(typeof request.PAUSED_WAITING_FOR_NETWORK == 'number').assertTrue(); + done(); + }); + + /** + * @tc.number SUB_REQUEST_CONSTANT_0023 + * *@tc.name subRequestConstant0023 + * @tc.desc Test constants of the request module. + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 0 + */ + it('subRequestConstant0023', 0, async function (done) { + console.info("====>-----------------------SUB_REQUEST_CONSTANT_0023 is starting-----------------------"); + expect(typeof request.PAUSED_WAITING_TO_RETRY == 'number').assertTrue(); + done(); + }); + + /** + * @tc.number SUB_REQUEST_CONSTANT_0024 + * *@tc.name subRequestConstant0024 + * @tc.desc Test constants of the request module. + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 0 + */ + it('subRequestConstant0024', 0, async function (done) { + console.info("====>-----------------------SUB_REQUEST_CONSTANT_0024 is starting-----------------------"); + expect(typeof request.PAUSED_BY_USER == 'number').assertTrue(); + done(); + }); + + /** + * @tc.number SUB_REQUEST_CONSTANT_0025 + * *@tc.name subRequestConstant0025 + * @tc.desc Test constants of the request module. + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 0 + */ + it('subRequestConstant0025', 0, async function (done) { + console.info("====>-----------------------SUB_REQUEST_CONSTANT_0025 is starting-----------------------"); + expect(typeof request.PAUSED_UNKNOWN == 'number').assertTrue(); + done(); + }); + + /** + * @tc.number SUB_REQUEST_CONSTANT_0026 + * *@tc.name subRequestConstant0026 + * @tc.desc Test constants of the request module. + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 0 + */ + it('subRequestConstant0026', 0, async function (done) { + console.info("====>-----------------------SUB_REQUEST_CONSTANT_0026 is starting-----------------------"); + expect(typeof request.SESSION_SUCCESSFUL == 'number').assertTrue(); + done(); + }); + + /** + * @tc.number SUB_REQUEST_CONSTANT_0027 + * *@tc.name subRequestConstant0027 + * @tc.desc Test constants of the request module. + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 0 + */ + it('subRequestConstant0027', 0, async function (done) { + console.info("====>-----------------------SUB_REQUEST_CONSTANT_0027 is starting-----------------------"); + expect(typeof request.SESSION_RUNNING == 'number').assertTrue(); + done(); + }); + + /** + * @tc.number SUB_REQUEST_CONSTANT_0028 + * *@tc.name subRequestConstant0028 + * @tc.desc Test constants of the request module. + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 0 + */ + it('subRequestConstant0028', 0, async function (done) { + console.info("====>-----------------------SUB_REQUEST_CONSTANT_0028 is starting-----------------------"); + expect(typeof request.SESSION_PENDING == 'number').assertTrue(); + done(); + }); + + /** + * @tc.number SUB_REQUEST_CONSTANT_0029 + * *@tc.name subRequestConstant0029 + * @tc.desc Test constants of the request module. + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 0 + */ + it('subRequestConstant0029', 0, async function (done) { + console.info("====>-----------------------SUB_REQUEST_CONSTANT_0029 is starting-----------------------"); + expect(typeof request.SESSION_PAUSED == 'number').assertTrue(); + done(); + }); + + /** + * @tc.number SUB_REQUEST_CONSTANT_0030 + * *@tc.name subRequestConstant0030 + * @tc.desc Test constants of the request module. + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 0 + */ + it('subRequestConstant0030', 0, async function (done) { + console.info("====>-----------------------SUB_REQUEST_CONSTANT_0030 is starting-----------------------"); + expect(typeof request.SESSION_FAILED == 'number').assertTrue(); + done(); + }); + + }) +} diff --git a/request/crossplatform/RequestTest_ets/src/main/ets/test/requestDownload.test.ets b/request/crossplatform/RequestTest_ets/src/main/ets/test/requestDownload.test.ets new file mode 100644 index 000000000..d7c754477 --- /dev/null +++ b/request/crossplatform/RequestTest_ets/src/main/ets/test/requestDownload.test.ets @@ -0,0 +1,667 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import request from "@ohos.request"; +import fileIo from "@ohos.file.fs"; +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from "@ohos/hypium"; + +const removeFile = (filePath: string): void => { + if (fileIo.accessSync(filePath)) fileIo.unlinkSync(filePath); +}; + +export default function requestDownloadJSUnit() { + describe("requestDownloadJSUnit", function () { + 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."); + }); + + /** + * beforeEach: Prerequisites at the test case level, which are executed before each test case is executed. + */ + beforeEach(function () { + 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."); + }); + + /** + * 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"); + }); + + /** + * @tc.number SUB_REQUEST_DOWNDLOAD_FILE_STAGE_API_CALLBACK_0001 + * *@tc.name subRequestDownloadFileStageApiCallback0001 + * @tc.desc Starts a download session. + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("subRequestDownloadFileStageApiCallback0001", 0, async function (done) { + console.info("-----------------------SUB_REQUEST_downloadFile_STAGE_API_CALLBACK_0001 is starting-----------------------"); + let downloadFilePath = `${globalThis.abilityContext.tempDir}/SUB_REQUEST_downloadFile_STAGE_API_CALLBACK_0001.txt`; + console.debug("====>downloadFileConfig:" + `${globalThis.abilityContext.tempDir}/SUB_REQUEST_downloadFile_STAGE_API_CALLBACK_0001.txt`); + let downloadFileConfig = { + url: "https://gitee.com/chenzhixue/downloadTest/releases/download/v1.0/test.apk", + header: { + headers: "http", + }, + enableMetered: false, + enableRoaming: false, + description: "XTS download test!", + networkType: request.NETWORK_WIFI, + filePath: downloadFilePath, + title: "XTS download test!", + background: false, + }; + request.downloadFile(globalThis.abilityContext, downloadFileConfig, async (err, downloadTask) => { + console.info("====>SUB_REQUEST_downloadFile_STAGE_API_CALLBACK_0001 downloadTask: " + downloadTask); + try { + expect(downloadTask != undefined).assertEqual(true); + } catch (e) { + console.info("====>SUB_REQUEST_downloadFile_STAGE_API_CALLBACK_0001 except error: " + e); + } + await downloadTask.delete(); + removeFile(downloadFilePath); + console.info("-----------------------SUB_REQUEST_downloadFile_STAGE_API_CALLBACK_0001 end-----------------------"); + done(); + }); + }); + + /** + * @tc.number SUB_REQUEST_DOWNDLOAD_FILE_STAGE_API_PROMISE_0001 + * *@tc.name subRequestDownloadFileStageApiPromise0001 + * @tc.desc Starts a download session. + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("subRequestDownloadFileStageApiPromise0001", 0, async function (done) { + console.info("-----------------------SUB_REQUEST_downloadFile_STAGE_API_PROMISE_0001 is starting-----------------------"); + let downloadFilePath = `${globalThis.abilityContext.tempDir}/SUB_REQUEST_downloadFile_STAGE_API_PROMISE_0001.txt`; + console.debug("====>downloadFileConfig:" + `${globalThis.abilityContext.tempDir}/SUB_REQUEST_downloadFile_STAGE_API_PROMISE_0001.txt`); + let downloadFileConfig = { + url: "https://gitee.com/chenzhixue/downloadTest/releases/download/v1.0/test.apk", + header: { + headers: "http", + }, + enableMetered: false, + enableRoaming: false, + description: "XTS download test!", + networkType: request.NETWORK_WIFI, + filePath: downloadFilePath, + title: "XTS download test!", + background: false, + }; + try { + request + .downloadFile(globalThis.abilityContext, downloadFileConfig) + .then(async (downloadTask) => { + console.info("====>SUB_REQUEST_downloadFile_STAGE_API_PROMISE_0001 downloadTask: " + downloadTask); + expect(downloadTask != undefined).assertEqual(true); + await downloadTask.delete(); + }) + .catch((err) => { + console.error("====>SUB_REQUEST_downloadFile_STAGE_API_PROMISE_0001 error: " + err); + }) + .finally(() => { + removeFile(downloadFilePath); + done(); + }); + } catch (err) { + console.error("====>SUB_REQUEST_downloadFile_STAGE_API_PROMISE_0001 catch error: " + err); + done(); + } + }); + + /** + * @tc.number SUB_REQUEST_DOWNDLOAD_API_DELETE_0001 + * *@tc.name subRequestDownloadApiDelete0001 + * @tc.desc Delete the download task. + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("subRequestDownloadApiDelete0001", 0, async function (done) { + console.info("====>-----------------------SUB_REQUEST_DOWNLOAD_API_delete_0001 is starting-----------------------"); + let downloadFilePath = `${globalThis.abilityContext.tempDir}/SUB_REQUEST_DOWNLOAD_API_DELETE_0001.txt`; + console.debug("====>downloadFileConfig:" + `${globalThis.abilityContext.tempDir}/SUB_REQUEST_DOWNLOAD_API_DELETE_0001.txt`); + let downloadFileConfig = { + url: "https://gitee.com/chenzhixue/downloadTest/releases/download/v1.0/test.apk", + header: { + headers: "http", + }, + enableMetered: false, + enableRoaming: false, + description: "XTS download test!", + networkType: request.NETWORK_WIFI, + filePath: downloadFilePath, + title: "XTS download test!", + background: false, + }; + request.downloadFile(globalThis.abilityContext, downloadFileConfig, async (err, downloadTask) => { + console.info("====>SUB_REQUEST_DOWNLOAD_API_DELETE_0001 downloadTask: " + downloadTask); + try { + expect(downloadTask != undefined).assertEqual(true); + downloadTask.delete(async (err, data) => { + try { + if (err) { + console.error("====>SUB_REQUEST_DOWNLOAD_API_DELETE_0001 Failed to delete the download task."); + expect().assertFail(); + done(); + } + console.info("====>SUB_REQUEST_DOWNLOAD_API_DELETE_0001 Download task delete success."); + expect(typeof data == "boolean").assertTrue(); + } catch (err) { + console.error("====>SUB_REQUEST_DOWNLOAD_API_DELETE_0001 delete throw error" + err); + } finally { + await downloadTask.delete(); + removeFile(downloadFilePath); + done(); + } + }); + } catch (error) { + console.error("====>SUB_REQUEST_DOWNLOAD_API_DELETE_0001 delete catch error" + error); + await downloadTask.delete(); + removeFile(downloadFilePath); + done(); + } + }); + }); + + /** + * @tc.number SUB_REQUEST_DOWNDLOAD_API_DELETE_0002 + * *@tc.name subRequestDownloadApiDelete0002 + * @tc.desc Delete the download task. + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("subRequestDownloadApiDelete0002", 0, async function (done) { + console.info("====>-----------------------SUB_REQUEST_DOWNLOAD_API_DELETE_0002 is starting-----------------------"); + let downloadFilePath = `${globalThis.abilityContext.tempDir}/SUB_REQUEST_DOWNLOAD_API_DELETE_0002.txt`; + console.debug("====>downloadFileConfig:" + `${globalThis.abilityContext.tempDir}/SUB_REQUEST_DOWNLOAD_API_DELETE_0002.txt`); + let downloadFileConfig = { + url: "https://gitee.com/chenzhixue/downloadTest/releases/download/v1.0/test.apk", + header: { + headers: "http", + }, + enableMetered: false, + enableRoaming: false, + description: "XTS download test!", + networkType: request.NETWORK_WIFI, + filePath: downloadFilePath, + title: "XTS download test!", + background: false, + }; + request.downloadFile(globalThis.abilityContext, downloadFileConfig, async (err, downloadTask) => { + console.info("====>SUB_REQUEST_DOWNLOAD_API_DELETE_0002 downloadTask: " + downloadTask); + try { + expect(downloadTask != undefined).assertEqual(true); + downloadTask + .delete() + .then(async (data) => { + console.info("====>SUB_REQUEST_DOWNLOAD_API_DELETE_0002 Download task delete success."); + expect(data).assertEqual(true); + console.info("====>-----------------------SUB_REQUEST_DOWNLOAD_API_DELETE_0002 end-----------------------"); + }) + .catch(async (err) => { + console.info("====>SUB_REQUEST_DOWNLOAD_API_DELETE_0002 Failed to delete the download task."); + expect().assertFail(); + }) + .finally(async () => { + await downloadTask.delete(); + removeFile(downloadFilePath); + done(); + }); + } catch (error) { + console.error("====>SUB_REQUEST_DOWNLOAD_API_DELETE_0002 delete catch error"); + await downloadTask.delete(); + removeFile(downloadFilePath); + done(); + } + }); + }); + + /** + * @tc.number SUB_REQUEST_DOWNDLOAD_API_SUSPEND_0001 + * *@tc.name subRequestDownloadApiSuspend0001 + * @tc.desc Suspend the download task + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("subRequestDownloadApiSuspend0001", 0, async function (done) { + console.info("====>-----------------------SUB_REQUEST_DOWNLOAD_API_SUSPEND_0001 is starting-----------------------"); + let downloadFilePath = `${globalThis.abilityContext.tempDir}/SUB_REQUEST_DOWNLOAD_API_SUSPEND_0001.txt`; + console.debug("====>downloadFileConfig:" + `${globalThis.abilityContext.tempDir}/SUB_REQUEST_DOWNLOAD_API_SUSPEND_0001.txt`); + let downloadFileConfig = { + url: "https://gitee.com/chenzhixue/downloadTest/releases/download/v1.0/test.apk", + header: { + headers: "http", + }, + enableMetered: false, + enableRoaming: false, + description: "XTS download test!", + networkType: request.NETWORK_WIFI, + filePath: downloadFilePath, + title: "XTS download test!", + background: false, + }; + request.downloadFile(globalThis.abilityContext, downloadFileConfig, async (err, downloadTask) => { + console.info("====>SUB_REQUEST_DOWNLOAD_API_SUSPEND_0001 downloadTask: " + downloadTask); + try { + expect(downloadTask != undefined).assertEqual(true); + downloadTask.suspend(async (err, data) => { + try { + if (err) { + console.error("====>SUB_REQUEST_DOWNLOAD_API_SUSPEND_0001 Failed to suspend the download task."); + expect().assertFail(); + done(); + } + console.info("====>SUB_REQUEST_DOWNLOAD_API_SUSPEND_0001 Download task suspend success."); + expect(data == true).assertTrue(); + } catch (err) { + console.error("====>SUB_REQUEST_DOWNLOAD_API_SUSPEND_0001 throw_error: " + JSON.stringify(err)); + } + await downloadTask.delete(); + removeFile(downloadFilePath); + done(); + }); + } catch (err) { + console.error("====>SUB_REQUEST_DOWNLOAD_API_SUSPEND_0001 suspend catch error" + JSON.stringify(err)); + await downloadTask.delete(); + removeFile(downloadFilePath); + done(); + } + }); + }); + + /** + * @tc.number SUB_REQUEST_DOWNDLOAD_API_SUSPEND_0002 + * *@tc.name subRequestDownloadApiSuspend0002 + * @tc.desc Suspend the download task + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("subRequestDownloadApiSuspend0002", 0, async function (done) { + console.info("====>-----------------------SUB_REQUEST_DOWNLOAD_API_SUSPEND_0002 is starting-----------------------"); + let downloadFilePath = `${globalThis.abilityContext.tempDir}/SUB_REQUEST_DOWNLOAD_API_SUSPEND_0002.txt`; + console.debug("====>downloadFileConfig:" + `${globalThis.abilityContext.tempDir}/SUB_REQUEST_DOWNLOAD_API_SUSPEND_0002.txt`); + let downloadFileConfig = { + url: "https://gitee.com/chenzhixue/downloadTest/releases/download/v1.0/test.apk", + header: { + headers: "http", + }, + enableMetered: false, + enableRoaming: false, + description: "XTS download test!", + networkType: request.NETWORK_WIFI, + filePath: downloadFilePath, + title: "XTS download test!", + background: false, + }; + request.downloadFile(globalThis.abilityContext, downloadFileConfig, async (err, downloadTask) => { + console.info("====>SUB_REQUEST_DOWNLOAD_API_SUSPEND_0002 downloadTask: " + downloadTask); + try { + expect(downloadTask != undefined).assertEqual(true); + try { + let data = await downloadTask.suspend(); + expect(data == true).assertTrue(); + } catch (err) { + console.info("====>SUB_REQUEST_DOWNLOAD_API_SUSPEND_0002 throw_err:" + JSON.stringify(err)); + } + } catch (err) { + console.error("====>SUB_REQUEST_DOWNLOAD_API_SUSPEND_0002 suspend catch error" + JSON.stringify(err)); + } finally { + await downloadTask.delete(); + removeFile(downloadFilePath); + done(); + } + }); + }); + + /** + * @tc.number SUB_REQUEST_DOWNDLOAD_API_RESTORE_0001 + * *@tc.name subRequestDownloadApiRestore0001 + * @tc.desc Restore the download task + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("subRequestDownloadApiRestore0001", 0, async function (done) { + console.info("====>-----------------------SUB_REQUEST_DOWNLOAD_API_RESTORE_0001 is starting-----------------------"); + let downloadFilePath = `${globalThis.abilityContext.tempDir}/SUB_REQUEST_DOWNLOAD_API_RESTORE_0001.txt`; + console.debug("====>downloadFileConfig:" + `${globalThis.abilityContext.tempDir}/SUB_REQUEST_DOWNLOAD_API_RESTORE_0001.txt`); + let downloadFileConfig = { + url: "https://gitee.com/chenzhixue/downloadTest/releases/download/v1.0/test.apk", + header: { + headers: "http", + }, + enableMetered: false, + enableRoaming: false, + description: "XTS download test!", + networkType: request.NETWORK_WIFI, + filePath: downloadFilePath, + title: "XTS download test!", + background: false, + }; + request.downloadFile(globalThis.abilityContext, downloadFileConfig, async (err, downloadTask) => { + console.info("====>SUB_REQUEST_DOWNLOAD_API_RESTORE_0001 downloadTask: " + downloadTask); + try { + expect(downloadTask != undefined).assertEqual(true); + downloadTask.restore(async (err, data) => { + try { + if (err) { + console.error("====>SUB_REQUEST_DOWNLOAD_API_RESTORE_0001 Failed to restore the download task."); + expect().assertFail(); + done(); + } + console.info("====>SUB_REQUEST_DOWNLOAD_API_RESTORE_0001 Download restore success."); + expect(data == true).assertTrue(); + } catch (err) { + console.info("====>SUB_REQUEST_DOWNLOAD_API_RESTORE_0001 throw_err:" + JSON.stringify(err)); + } + await downloadTask.delete(); + removeFile(downloadFilePath); + done(); + }); + } catch (err) { + console.error("====>SUB_REQUEST_DOWNLOAD_API_RESTORE_0001 restore catch error" + JSON.stringify(err)); + await downloadTask.delete(); + removeFile(downloadFilePath); + done(); + } + }); + }); + + /** + * @tc.number SUB_REQUEST_DOWNDLOAD_API_RESTORE_0002 + * *@tc.name subRequestDownloadApiRestore0002 + * @tc.desc Restore the download task + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("subRequestDownloadApiRestore0002", 0, async function (done) { + console.info("====>-----------------------SUB_REQUEST_DOWNLOAD_API_RESTORE_0002 is starting-----------------------"); + let downloadFilePath = `${globalThis.abilityContext.tempDir}/SUB_REQUEST_DOWNLOAD_API_RESTORE_0002.txt`; + console.debug("====>downloadFileConfig:" + `${globalThis.abilityContext.tempDir}/SUB_REQUEST_DOWNLOAD_API_RESTORE_0002.txt`); + let downloadFileConfig = { + url: "https://gitee.com/chenzhixue/downloadTest/releases/download/v1.0/test.apk", + header: { + headers: "http", + }, + enableMetered: false, + enableRoaming: false, + description: "XTS download test!", + networkType: request.NETWORK_WIFI, + filePath: downloadFilePath, + title: "XTS download test!", + background: false, + }; + request.downloadFile(globalThis.abilityContext, downloadFileConfig, async (err, downloadTask) => { + console.info("====>SUB_REQUEST_DOWNLOAD_API_RESTORE_0002 downloadTask: " + downloadTask); + try { + expect(downloadTask != undefined).assertEqual(true); + downloadTask + .restore() + .then(async (data) => { + console.info("====>SUB_REQUEST_DOWNLOAD_API_RESTORE_0002 Download task restore."); + expect(data == true).assertTrue(); + await downloadTask.delete(); + }) + .catch(async (err) => { + console.info("====>SUB_REQUEST_DOWNLOAD_API_RESTORE_0002 Failed to restore the download task."); + }) + .finally(async () => { + await downloadTask.delete(); + removeFile(downloadFilePath); + done(); + }); + } catch (err) { + console.error("====>SUB_REQUEST_DOWNLOAD_API_RESTORE_0002 restore catch error" + JSON.stringify(err)); + await downloadTask.delete(); + removeFile(downloadFilePath); + done(); + } + }); + }); + + /** + * @tc.number SUB_REQUEST_DOWNDLOAD_API_GETTASKINFO_0001 + * *@tc.name subRequestDownloadApiGetTaskInfo0001 + * @tc.desc Get the download task info + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("subRequestDownloadApiGetTaskInfo0001", 0, async function (done) { + console.info("====>---------------------SUB_REQUEST_DOWNLOAD_API_GETTASKINFO_0001 is starting---------------------"); + let downloadFilePath = `${globalThis.abilityContext.tempDir}/SUB_REQUEST_DOWNLOAD_API_GETTASKINFO_0001.txt`; + console.debug("====>downloadFileConfig:" + `${globalThis.abilityContext.tempDir}/SUB_REQUEST_DOWNLOAD_API_GETTASKINFO_0001.txt`); + let downloadFileConfig = { + url: "https://gitee.com/chenzhixue/downloadTest/releases/download/v1.0/test.apk", + header: { + headers: "http", + }, + enableMetered: false, + enableRoaming: false, + description: "XTS download test!", + networkType: request.NETWORK_WIFI, + filePath: downloadFilePath, + title: "XTS download test!", + background: false, + }; + request.downloadFile(globalThis.abilityContext, downloadFileConfig, async (err, downloadTask) => { + console.info("====>SUB_REQUEST_DOWNLOAD_API_GETTASKINFO_0001 downloadTask: " + downloadTask); + try { + expect(downloadTask != undefined).assertEqual(true); + downloadTask.getTaskInfo(async (err, data) => { + try { + if (err) { + console.error("====>SUB_REQUEST_DOWNLOAD_API_GETTASKINFO_0001 Failed to getTaskInfo the download task."); + expect().assertFail(); + done(); + } + console.info("====>SUB_REQUEST_DOWNLOAD_API_GETTASKINFO_0001 Download getTaskInfo success."); + expect(typeof data == "object").assertTrue(); + } catch (err) { + console.error("====>SUB_REQUEST_DOWNLOAD_API_GETTASKINFO_0001 throw_error" + JSON.stringify(err)); + } + await downloadTask.delete(); + removeFile(downloadFilePath); + done(); + }); + } catch (err) { + console.error("====>SUB_REQUEST_DOWNLOAD_API_GETTASKINFO_0001 getTaskInfo catch error" + JSON.stringify(err)); + await downloadTask.delete(); + removeFile(downloadFilePath); + done(); + } + }); + }); + + /** + * @tc.number SUB_REQUEST_DOWNDLOAD_API_GETTASKINFO_0002 + * *@tc.name subRequestDownloadApiGetTaskInfo0002 + * @tc.desc Get the download task info + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("subRequestDownloadApiGetTaskInfo0002", 0, async function (done) { + console.info("====>-------------------SUB_REQUEST_DOWNLOAD_API_GETTASKINFO_0002 is starting----------------------"); + let downloadFilePath = `${globalThis.abilityContext.tempDir}/SUB_REQUEST_DOWNLOAD_API_GETTASKINFO_0002.txt`; + console.debug("====>downloadFileConfig:" + `${globalThis.abilityContext.tempDir}/SUB_REQUEST_DOWNLOAD_API_GETTASKINFO_0002.txt`); + let downloadFileConfig = { + url: "https://gitee.com/chenzhixue/downloadTest/releases/download/v1.0/test.apk", + header: { + headers: "http", + }, + enableMetered: false, + enableRoaming: false, + description: "XTS download test!", + networkType: request.NETWORK_WIFI, + filePath: downloadFilePath, + title: "XTS download test!", + background: false, + }; + request.downloadFile(globalThis.abilityContext, downloadFileConfig, async (err, downloadTask) => { + console.info("====>SUB_REQUEST_DOWNLOAD_API_GETTASKINFO_0002 downloadTask: " + downloadTask); + try { + expect(downloadTask != undefined).assertEqual(true); + downloadTask + .getTaskInfo() + .then(async (data) => { + console.info("====>SUB_REQUEST_DOWNLOAD_API_GETTASKINFO_0002 Download task getTaskInfo success."); + expect(typeof data == "object").assertTrue(); + }) + .catch(async (err) => { + console.error("====>SUB_REQUEST_DOWNLOAD_API_GETTASKINFO_0002 Failed to getTaskInfo the download task."); + }) + .finally(async () => { + await downloadTask.delete(); + removeFile(downloadFilePath); + done(); + }); + } catch (err) { + console.error("====>SUB_REQUEST_DOWNLOAD_API_GETTASKINFO_0002 getTaskInfo catch error" + JSON.stringify(err)); + await downloadTask.delete(); + removeFile(downloadFilePath); + done(); + } + }); + }); + + /** + * @tc.number SUB_REQUEST_DOWNLOAD_API_GETTASKMINETYPE_0002 + * *@tc.name subRequestDownloadApigetTaskMimeType0002 + * @tc.desc Get mimetype of the download task + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("subRequestDownloadApigetTaskMimeType0002", 0, async function (done) { + console.info("====>-------------------SUB_REQUEST_DOWNLOAD_API_GETTASKMINETYPE_0002 is starting----------------------"); + let downloadFilePath = `${globalThis.abilityContext.tempDir}/SUB_REQUEST_DOWNLOAD_API_GETTASKMINETYPE_0002.txt`; + console.debug("====>downloadFileConfig:" + `${globalThis.abilityContext.tempDir}/SUB_REQUEST_DOWNLOAD_API_GETTASKMINETYPE_0002.txt`); + let downloadFileConfig = { + url: "https://gitee.com/chenzhixue/downloadTest/releases/download/v1.0/test.apk", + header: { + headers: "http", + }, + enableMetered: false, + enableRoaming: false, + description: "XTS download test!", + networkType: request.NETWORK_WIFI, + filePath: downloadFilePath, + title: "XTS download test!", + background: false, + }; + + request.downloadFile(globalThis.abilityContext, downloadFileConfig, async (err, downloadTask) => { + console.info("====>SUB_REQUEST_DOWNLOAD_API_GETTASKMINETYPE_0002 downloadTask: " + downloadTask); + try { + let data = await downloadTask.getTaskMimeType(); + expect(data != undefined).assertEqual(true); + } catch (err) { + console.error("====>SUB_REQUEST_DOWNLOAD_API_GETTASKMINETYPE_0002 throw_error: " + JSON.stringify(err)); + } finally { + await downloadTask.delete(); + removeFile(downloadFilePath); + done(); + } + }); + }); + + /** + * @tc.number SUB_REQUEST_DOWNDLOAD_API_TASKINFO_0001 + * *@tc.name subRequestDownloadApiTaskInfo0001 + * @tc.desc Get the download task info, and test the field of TaskInfo + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("subRequestDownloadApiTaskInfo0001", 0, async function (done) { + console.info("====>---------------------SUB_REQUEST_DOWNDLOAD_API_TASKINFO_0001 is starting---------------------"); + let downloadFilePath = `${globalThis.abilityContext.tempDir}/SUB_REQUEST_DOWNDLOAD_API_TASKINFO_0001.txt`; + console.debug("====>downloadFileConfig:" + `${globalThis.abilityContext.tempDir}/SUB_REQUEST_DOWNDLOAD_API_TASKINFO_0001.txt`); + let downloadFileConfig = { + url: "https://gitee.com/chenzhixue/downloadTest/releases/download/v1.0/test.apk", + header: { + headers: "http", + }, + enableMetered: false, + enableRoaming: false, + description: "XTS download test!", + networkType: request.NETWORK_WIFI, + filePath: downloadFilePath, + title: "XTS download test!", + background: false, + }; + request.downloadFile(globalThis.abilityContext, downloadFileConfig, async (err, downloadTask) => { + console.info("====>SUB_REQUEST_DOWNDLOAD_API_TASKINFO_0001 downloadTask: " + downloadTask); + try { + expect(downloadTask != undefined).assertEqual(true); + downloadTask.getTaskInfo(async (err, data) => { + try { + if (err) { + console.error("====>SUB_REQUEST_DOWNDLOAD_API_TASKINFO_0001 Failed to getTaskInfo the download task."); + expect().assertFail(); + done(); + } + console.info("====>SUB_REQUEST_DOWNDLOAD_API_TASKINFO_0001 Download getTaskInfo success."); + expect(typeof data == "object").assertTrue(); + expect(typeof data.description == "string").assertTrue(); + expect(typeof data.downloadedBytes == "number").assertTrue(); + expect(typeof data.downloadId == "number").assertTrue(); + expect(typeof data.failedReason == "number").assertTrue(); + expect(typeof data.fileName == "string").assertTrue(); + expect(typeof data.filePath == "string").assertTrue(); + expect(typeof data.pausedReason == "number").assertTrue(); + expect(typeof data.status == "number").assertTrue(); + expect(typeof data.targetURI == "string").assertTrue(); + expect(typeof data.downloadTitle == "string").assertTrue(); + expect(typeof data.downloadTotalBytes == "number").assertTrue(); + } catch (err) { + console.error("====>SUB_REQUEST_DOWNDLOAD_API_TASKINFO_0001 throw_error" + JSON.stringify(err)); + } + await downloadTask.delete(); + removeFile(downloadFilePath); + done(); + }); + } catch (err) { + console.error("====>SUB_REQUEST_DOWNDLOAD_API_TASKINFO_0001 getTaskInfo catch error" + JSON.stringify(err)); + await downloadTask.delete(); + removeFile(downloadFilePath); + done(); + } + }); + }); + }); +} diff --git a/request/crossplatform/RequestTest_ets/src/main/ets/test/requestUpload.test.ets b/request/crossplatform/RequestTest_ets/src/main/ets/test/requestUpload.test.ets new file mode 100644 index 000000000..1e6474612 --- /dev/null +++ b/request/crossplatform/RequestTest_ets/src/main/ets/test/requestUpload.test.ets @@ -0,0 +1,239 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import request from "@ohos.request"; +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from "@ohos/hypium"; + +export default function requestUploadJSUnit() { + describe("requestUploadJSUnit", function () { + 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."); + }); + + /** + * beforeEach: Prerequisites at the test case level, which are executed before each test case is executed. + */ + beforeEach(function () { + 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."); + }); + + /** + * 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"); + }); + + let RequestData = { + name: "name", + value: "123", + }; + + let File = { + filename: "test", + name: "test", + uri: "internal://cache/test.txt", + type: "txt", + }; + + let uploadConfig = { + url: "http://127.0.0.1", + header: { + headers: "http", + }, + method: "POST", + files: [File], + data: [RequestData], + }; + + /** + * @tc.number SUB_REQUEST_UPLOAD_API_DELETE_0001 + * *@tc.name subRequestUploadApiDelete0001 + * @tc.desc upload file and delete the upload task. + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("subRequestUploadApiDelete0001", 0, async function (done) { + console.info("====>-----------------------SUB_REQUEST_UPLOAD_API_DELETE_0001 is starting-----------------------"); + request.uploadFile(globalThis.abilityContext, uploadConfig, (err, uploadTask) => { + try { + console.info("====>SUB_REQUEST_UPLOAD_API_DELETE_0001 uploadTask: " + uploadTask); + expect(uploadTask != undefined).assertEqual(true); + uploadTask.delete((err, data) => { + try { + if (err) { + console.error("====>SUB_REQUEST_UPLOAD_API_DELETE_0001 Failed to delete the uploadTask task."); + expect().assertFail(); + done(); + } + console.info("====>SUB_REQUEST_UPLOAD_API_DELETE_0001 uploadTask task delete success."); + expect(typeof data == "boolean").assertTrue(); + console.info("====>-----------------------SUB_REQUEST_UPLOAD_API_DELETE_0001 end-----------------------"); + done(); + } catch (err) { + console.error("====>SUB_REQUEST_UPLOAD_API_DELETE_0001 delete error" + err); + done(); + } + }); + } catch (error) { + console.error("====>SUB_REQUEST_UPLOAD_API_DELETE_0001 delete catch error" + error); + done(); + } + }); + }); + + /** + * @tc.number SUB_REQUEST_UPLOAD_API_DELETE_0002 + * *@tc.name subRequestUploadApiDelete0002 + * @tc.desc upload file and delete the upload task (Promise). + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("subRequestUploadApiDelete0002", 0, async function (done) { + console.info("====>-----------------------SUB_REQUEST_UPLOAD_API_DELETE_0002 is starting-----------------------"); + request.uploadFile(globalThis.abilityContext, uploadConfig).then((uploadTask) => { + console.info("====>SUB_REQUEST_UPLOAD_API_DELETE_0002 uploadTask: " + uploadTask); + try { + expect(uploadTask != undefined).assertEqual(true); + uploadTask + .delete() + .then((data) => { + console.info("====>SUB_REQUEST_UPLOAD_API_DELETE_0002 delete data:" + JSON.stringify(data)); + expect(data).assertEqual(true); + done(); + }) + .catch((err) => { + console.info("====>SUB_REQUEST_UPLOAD_API_DELETE_0002 Failed to delete the uploadTask task."); + expect().assertFail(); + done(); + }); + } catch (err) { + console.error("====>SUB_REQUEST_UPLOAD_API_DELETE_0002 delete catch err"); + done(); + } + }); + }); + + /** + * @tc.number SUB_REQUEST_UPLOAD_API_EVENT_0001 + * *@tc.name subRequestUploadApiEvent0001 + * @tc.desc upload file and test event. + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("subRequestUploadApiEvent0001", 0, async function (done) { + console.info("====>-----------------------SUB_REQUEST_UPLOAD_API_EVENT_0001 is starting-----------------------"); + request.uploadFile(globalThis.abilityContext, uploadConfig).then((uploadTask) => { + console.info("====>SUB_REQUEST_UPLOAD_API_EVENT_0001 uploadTask: " + uploadTask); + try { + expect(uploadTask != undefined).assertEqual(true); + uploadTask.on("progress", (uploadedSize, totalSize) => { + expect(uploadedSize != undefined).assertEqual(true); + expect(totalSize != undefined).assertEqual(true); + uploadTask.off("progress", (uploadedSize, totalSize) => { + expect(uploadedSize != undefined).assertEqual(true); + expect(totalSize != undefined).assertEqual(true); + }); + }); + done(); + } catch (err) { + console.error("====>SUB_REQUEST_UPLOAD_API_EVENT_0001 delete catch err"); + done(); + } + }); + }); + + /** + * @tc.number SUB_REQUEST_UPLOAD_API_EVENT_0002 + * *@tc.name subRequestUploadApiEvent0002 + * @tc.desc upload file and test event. + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("subRequestUploadApiEvent0002", 0, async function (done) { + console.info("====>-----------------------SUB_REQUEST_UPLOAD_API_EVENT_0002 is starting-----------------------"); + request.uploadFile(globalThis.abilityContext, uploadConfig).then((uploadTask) => { + console.info("====>SUB_REQUEST_UPLOAD_API_EVENT_0002 uploadTask: " + uploadTask); + try { + expect(uploadTask != undefined).assertEqual(true); + uploadTask.on("headerReceive", (header) => { + expect(header != undefined).assertEqual(true); + uploadTask.off("headerReceive", (header) => { + expect(header != undefined).assertEqual(true); + }); + }); + done(); + } catch (err) { + console.error("====>SUB_REQUEST_UPLOAD_API_EVENT_0002 delete catch err"); + done(); + } + }); + }); + + /** + * @tc.number SUB_REQUEST_UPLOAD_API_EVENT_0003 + * *@tc.name subRequestUploadApiEvent0003 + * @tc.desc upload file and test event. + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("subRequestUploadApiEvent0003", 0, async function (done) { + console.info("====>-----------------------SUB_REQUEST_UPLOAD_API_EVENT_0003 is starting-----------------------"); + request.uploadFile(globalThis.abilityContext, uploadConfig).then((uploadTask) => { + console.info("====>SUB_REQUEST_UPLOAD_API_EVENT_0003 uploadTask: " + uploadTask); + try { + expect(uploadTask != undefined).assertEqual(true); + uploadTask.on("complete", (taskStates) => { + const task = taskStates.length != 0 ? taskStates[0] : null; + if (task) { + expect(task.path != null).assertEqual(true); + expect(task.responseCode != null).assertEqual(true); + expect(task.message != null).assertEqual(true); + } else { + console.info("SUB_REQUEST_UPLOAD_API_EVENT_0003: task is null"); + expect().assertFail(); + done(); + } + + uploadTask.off("complete", (taskStates) => { + expect(taskStates != undefined).assertEqual(true); + }); + }); + done(); + } catch (err) { + console.error("====>SUB_REQUEST_UPLOAD_API_EVENT_0003 delete catch err"); + done(); + } + }); + }); + }); +} diff --git a/request/crossplatform/RequestTest_ets/src/main/module.json b/request/crossplatform/RequestTest_ets/src/main/module.json new file mode 100644 index 000000000..2bb17a9cd --- /dev/null +++ b/request/crossplatform/RequestTest_ets/src/main/module.json @@ -0,0 +1,60 @@ +{ + "module": { + "name": "crossplatform_request_test_ets", + "type": "feature", + "description": "$string:module_test_desc", + "mainElement": "TestAbility", + "deviceTypes": [ + "phone" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:test_pages", + "abilities": [ + { + "name": "TestAbility", + "srcEntry": "./ets/TestAbility/TestAbility.ets", + "description": "$string:TestAbility_desc", + "icon": "$media:icon", + "label": "$string:TestAbility_label", + "exported": true, + "startWindowIcon": "$media:icon", + "startWindowBackground": "$color:start_window_background", + "skills": [ + { + "actions": [ + "action.system.home" + ], + "entities": [ + "entity.system.home" + ] + } + ] + } + ], + "requestPermissions": [ + { + "name":"ohos.permission.INTERNET", + "reason":"need use ohos.permission.INTERNET." + }, + {"name": "ohos.permission.WRITE_MEDIA", + "reason": "need use ohos.permission.WRITE_MEDIA", + "usedScene": { + "ability": [ + "com.acts.request.test.MainAbility" + ], + "when":"always" + } + }, + {"name": "ohos.permission.READ_MEDIA", + "reason": "need use ohos.permission.WRITE_MEDIA", + "usedScene": { + "ability": [ + "com.acts.request.test.MainAbility" + ], + "when":"always" + } + } + ] + } +} diff --git a/request/crossplatform/RequestTest_ets/src/main/resources/base/element/color.json b/request/crossplatform/RequestTest_ets/src/main/resources/base/element/color.json new file mode 100644 index 000000000..3c712962d --- /dev/null +++ b/request/crossplatform/RequestTest_ets/src/main/resources/base/element/color.json @@ -0,0 +1,8 @@ +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + } + ] +} \ No newline at end of file diff --git a/request/crossplatform/RequestTest_ets/src/main/resources/base/element/string.json b/request/crossplatform/RequestTest_ets/src/main/resources/base/element/string.json new file mode 100644 index 000000000..65d8fa5a7 --- /dev/null +++ b/request/crossplatform/RequestTest_ets/src/main/resources/base/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "module_test_desc", + "value": "test ability description" + }, + { + "name": "TestAbility_desc", + "value": "the test ability" + }, + { + "name": "TestAbility_label", + "value": "test label" + } + ] +} \ No newline at end of file diff --git a/request/crossplatform/RequestTest_ets/src/main/resources/base/media/icon.png b/request/crossplatform/RequestTest_ets/src/main/resources/base/media/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c GIT binary patch literal 6790 zcmX|G1ymHk)?T_}Vd;>R?p|tHQo6fg38|$UVM!6BLrPFWk?s;$LOP{GmJpBl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