From c56144c5059109cfb53f726fb989dd60ec947bfa Mon Sep 17 00:00:00 2001 From: renjiecui Date: Tue, 30 Aug 2022 16:24:52 +0800 Subject: [PATCH] request-TDD Signed-off-by: renjiecui --- BUILD.gn | 1 + bundle.json | 1 + test/unittest/common/BUILD.gn | 30 ++++++++ test/unittest/common/RequestJsunit.test.js | 62 ++++++++++++++++ test/unittest/common/config.json | 81 +++++++++++++++++++++ test/unittest/common/openharmony_sx.p7b | Bin 0 -> 3443 bytes 6 files changed, 175 insertions(+) create mode 100644 test/unittest/common/BUILD.gn create mode 100644 test/unittest/common/RequestJsunit.test.js create mode 100644 test/unittest/common/config.json create mode 100644 test/unittest/common/openharmony_sx.p7b diff --git a/BUILD.gn b/BUILD.gn index d97f2648..bfd7ca05 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -22,6 +22,7 @@ group("request_packages") { "download/interfaces/kits/js/napi/download_single:downloadsingle", "download/sa_profile:download_sa_profiles", "download/services:download_server", + "test/unittest/common:unittest", ] } } diff --git a/bundle.json b/bundle.json index 6ffee1ad..ae35ea1d 100644 --- a/bundle.json +++ b/bundle.json @@ -79,6 +79,7 @@ "//base/request/request/upload/unitest:upload_obtain_file_UT_test", "//base/request/request/upload/unitest:upload_UT_test", "//base/request/request/test/fuzztest:fuzztest" + "//base/request/request/test/unittest/common:unittest" ] } } diff --git a/test/unittest/common/BUILD.gn b/test/unittest/common/BUILD.gn new file mode 100644 index 00000000..e9c8f847 --- /dev/null +++ b/test/unittest/common/BUILD.gn @@ -0,0 +1,30 @@ +# 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("//build/test.gni") + +module_output_path = "request/napi" + +ohos_js_unittest("RequestJsTest") { + module_out_path = module_output_path + + hap_profile = "./config.json" + +# certificate_profile = "//test/developertest/signature/openharmony_sx.p7b" + certificate_profile = "./openharmony_sx.p7b" +} + +group("unittest") { + testonly = true + deps = [ ":RequestJsTest" ] +} diff --git a/test/unittest/common/RequestJsunit.test.js b/test/unittest/common/RequestJsunit.test.js new file mode 100644 index 00000000..a69aa6c5 --- /dev/null +++ b/test/unittest/common/RequestJsunit.test.js @@ -0,0 +1,62 @@ +/* + * 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 {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index'; +import request from '@ohos.request'; + +const TAG = "REQUEST_TEST"; +let keyStr = 'download test '; + + +let DownloadConfig = { + //https://sf3-cn.feishucdn.com/obj/ee-appcenter/6d6bc5/Feishu-win32_ia32-5.10.6-signed.exe + // url: 'https://sf3-cn.feishucdn.com/obj/ee-appcenter/6d6bc5/Feishu-win32_ia32-5.10.6-signed.exe', // Resource address. + //url: 'https://www.baidu.com/img/PCtm_d9c8750bed0b3c7d089fa7d55720d6cf.png', // Resource address. + url: 'http://192.168.8.128:8080/HFS_SERVER/123.rar', + // url: 'http://sf3-cn.feishucdn.com/obj/ee-appcenter/6d6bc5/Feishu-win32_ia32-5.10.6-signed.exe', + filePath: '/data/storage/el2/base/haps/entry/files/123.rar', // Sets the path for downloads./data/accounts/account_0/appdata/com.example.downloaddemo/files/picture.png + enableMetered: false, + enableRoaming: false, + networkType: 65536, //65536 wifi 1 sim卡网络 + background: true, +} + +describe('requestTest',function () { + + console.log(TAG + "*************Unit Test Begin*************"); + + + /** + * @tc.name: downloadTest001 + * @tc.desc see if download starts correctly + * @tc.type: FUNC + * @tc.require: + */ + it('downloadTest001', 0, function () { + console.log(TAG + "************* downloadTest001 start *************"); + + request.download(DownloadConfig).then((DownloadTask) => { + console.log(keyStr + 'download start, DownloadTask: ' + DownloadTask); + console.log(keyStr + 'download start, DownloadTask: ' + JSON.stringify(DownloadTask)); + DownloadTask.on('progress',(receivedSize, totalSize) => { + expect(totalSize == 0).assertEqual(false) + expect(receivedSize == 0).assertEqual(false); + }) + }) + + console.log(TAG + "************* downloadTest001 end *************"); + }) + + console.log(TAG + "*************Unit Test End*************"); +}) \ No newline at end of file diff --git a/test/unittest/common/config.json b/test/unittest/common/config.json new file mode 100644 index 00000000..c4dab5c3 --- /dev/null +++ b/test/unittest/common/config.json @@ -0,0 +1,81 @@ +{ + "app": { + "bundleName": "com.example.myapplication", + "vendor": "example", + "version": { + "code": 1, + "name": "1.0" + }, + "apiVersion": { + "compatible": 4, + "target": 5 + } + }, + "deviceConfig": {}, + "module": { + "package": "com.example.myapplication", + "name": ".MyApplication", + "deviceType": [ + "phone" + ], + "distro": { + "deliveryWithInstall": true, + "moduleName": "entry", + "moduleType": "entry" + }, + "defPermissions": [ + { + "availableScope": [], + "grantMode": "user_grant", + "name": "ohos.permission.DISTRIBUTED_DATASYNC" + } + ], + "reqPermissions": [ + { + "name": "ohos.permission.GRANT_SENSITIVE_PERMISSIONS", + "reason": "ceshi" + }, + { + "name": "ohos.permission.DISTRIBUTED_DATASYNC", + "reason": "ceshi" + }, + { + "name": "ohos.permission.INTERNET", + "reason": "ceshi" + } + ], + "abilities": [ + { + "visible": true, + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ], + "name": "com.example.myapplication.MainAbility", + "icon": "$media:icon", + "description": "$string:mainability_description", + "label": "MyApplication", + "type": "page", + "launchType": "standard" + } + ], + "js": [ + { + "pages": [ + "pages/index/index" + ], + "name": "default", + "window": { + "designWidth": 720, + "autoDesignWidth": false + } + } + ] + } +} diff --git a/test/unittest/common/openharmony_sx.p7b b/test/unittest/common/openharmony_sx.p7b new file mode 100644 index 0000000000000000000000000000000000000000..66b4457a8a81fb8d3356cf46d67226c850944858 GIT binary patch literal 3443 zcmcgvYj6|S8MPj^V?bbHu)zUrguxV$eOH!j$tfhe(&~j*^2(BJ8Bw#6Ru5a+m8F$e z7KKoe&=>-grhpq>=4Bu;(DE|wG>}Juk_0FTWjZM)HPlI=G?d~bG!)vE?SRd|k4|RL z5AA&4J@@X}@1F16xgaj0Q_^NE(=Gc(#7pJ3#zhN2Tx93-c#sGTPf1&_OvfVyLOu_~ zlSe%S@>=7`Ny51BKMTc;WGL*TDT$MIk>XNl)`J8^1h|A4DgXsQJWCvj_*`5l2htLU zQb|hWZthQ3EO$wia-fh9N)kXtGPj$A6damq3MM9pNIyx0NiIPIgA$i7%!GW72$Oi< z0D=zJ`Y49^Lr|^Wn5#m~7QIHVf-PuY)=pu1y$Xw|RIr2ez^opDJ$jTdsS0Ci7(+as25)_x zsT{}EFl&V|Ef!V9U<2YYRwA&?0@oW&+zMu#MLjlkC63QUS*F~nt&CJ?HBF8xWrVb# zH5lU5!jKhJMKRn`g!moxUavC%H9DwzPo=ifYo{C*v<_3DeJD7J5s#wqYJ_!Y{dKl# zbI>7`d2oQTI#itWjMb#pQF0&==*tju`)aL$UCE23tZj*onZ@#D%qMUx!zW7U>s7pT(2?vZB-yTR}BaHF_^_p z>A)i>RKq&8(V$JL0R&eIy~f~oaNp~cTG=WKY(YHEf$Hj!M5XOif2}bDVT~#nwm57i z6^;k1BfkI#2a7>4e42{8g?g`>nbo*tA?vQh{fRzIem6Y!&u8`Yow^C zqOv67Mm26i&zNJdsSk}S5ZJ9i5g1b;GMLpRDryEM1hJu-awZyzc>Q+DX-4p{!Nodj z8p@BoYeJz0+)sJZt zuEPepall8Mbf92R2NrOKP{5F3h655oKi75PrZ7VWYMqI0@AnH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