From 5b5fb3fbbe67e2d9c46499af332b6e53aceb5414 Mon Sep 17 00:00:00 2001 From: gaoxi Date: Sun, 24 Jul 2022 15:52:03 +0800 Subject: [PATCH] add new testcase Signed-off-by: gaoxi --- miscservices/BUILD.gn | 1 + .../test/RequestDownloadTaskJsunit.test.ets | 171 +++++++++++ .../MainAbility/test/RequestJsunit.test.ets | 43 +++ .../js/default/test/SystemTimeJsunit.test.js | 265 ++++++++++++++++-- .../src/main/js/default/test/List.test.js | 3 +- .../js/default/test/PasteBoard2Jsunit.test.js | 88 ++++++ 6 files changed, 547 insertions(+), 24 deletions(-) create mode 100644 miscservices/actspasteboardjsapitest/entry/src/main/js/default/test/PasteBoard2Jsunit.test.js diff --git a/miscservices/BUILD.gn b/miscservices/BUILD.gn index 073e36c5a..0e05ce9de 100755 --- a/miscservices/BUILD.gn +++ b/miscservices/BUILD.gn @@ -20,6 +20,7 @@ group("miscservices") { "TimeTest_js:ActsTimeJSApiTest", "TimerTest_js:ActsTimerJSApiTest", "actspasteboardjsapitest:ActsPasteBoardJSApiTest", + "screenlock_js:ActsScreenLockJSApiTest", "wallpaper_js:ActsWallpaperJSApiTest", ] } diff --git a/miscservices/InputMethodTest_ets/entry/src/main/ets/MainAbility/test/RequestDownloadTaskJsunit.test.ets b/miscservices/InputMethodTest_ets/entry/src/main/ets/MainAbility/test/RequestDownloadTaskJsunit.test.ets index 6b9f4278d..acec29cec 100644 --- a/miscservices/InputMethodTest_ets/entry/src/main/ets/MainAbility/test/RequestDownloadTaskJsunit.test.ets +++ b/miscservices/InputMethodTest_ets/entry/src/main/ets/MainAbility/test/RequestDownloadTaskJsunit.test.ets @@ -335,5 +335,176 @@ export default function requestDownloadJsunit() { done(); }); + /** + * @tc.number requestDownload_test_015 + * @tc.name Test The request DownloadTask + * @tc.desc Function test + */ + it('requestDownload_test_015', 0, async function (done) { + console.info("requestDownload_test_015 start") + request.download(downloadConfig, (downloadTask) => { + console.info("downloadConfig result:" + JSON.stringify(downloadTask)) + downloadTask.remove().then((result) => { + if (result) { + expect(result != null).assertTrue(); + console.info('Download task removed.'); + } else { + console.info('Failed to remove the download task.'); + } + }).catch((err) => { + expect(true).assertTrue(); + console.info('Failed to remove the download task.'); + }); + }); + console.info("requestDownload_test_015 end") + done(); + }); + + /** + * @tc.number requestDownload_test_016 + * @tc.name Test The request UploadTask + * @tc.desc Function test + */ + it('requestDownload_test_016', 0, async function (done) { + console.info("requestDownload_test_016 start") + request.download(downloadConfig, (downloadTask) => { + console.info("downloadConfig result:" + JSON.stringify(downloadTask)) + downloadTask.pause().then((result) => { + if (result) { + expect(result != null).assertTrue(); + console.info('Download task paused. '); + } else { + console.info('Failed to pause the download task. Cause:' + JSON.stringify(result)); + } + }).catch((err) => { + expect(true).assertTrue(); + console.info('Failed to pause the download task. Cause:' + JSON.stringify(err)); + }); + }); + console.info("requestDownload_test_016 end") + done(); + }); + + /** + * @tc.number requestDownload_test_017 + * @tc.name Test The request UploadTask + * @tc.desc Function test + */ + it('requestDownload_test_017', 0, async function (done) { + console.info("requestDownload_test_017 start") + request.download(downloadConfig, (downloadTask) => { + console.info("downloadConfig result:" + JSON.stringify(downloadTask)) + downloadTask.pause((err, result)=>{ + if(err) { + console.info('Failed to pause the download task. Cause:' + JSON.stringify(err)); + expect(true).assertTrue(); + return; + } + if (result) { + console.info('Download task paused. '); + expect(result != null).assertTrue(); + } else { + console.info('Failed to pause the download task. Cause:' + JSON.stringify(result)); + } + }); + }); + console.info("requestDownload_test_017 end") + done(); + }); + + /** + * @tc.number requestDownload_test_018 + * @tc.name Test The request UploadTask + * @tc.desc Function test + */ + it('requestDownload_test_018', 0, async function (done) { + console.info("requestDownload_test_018 start") + request.download(downloadConfig, (downloadTask) => { + console.info("downloadConfig result:" + JSON.stringify(downloadTask)) + downloadTask.resume().then((result) => { + if (result) { + expect(result != null).assertTrue(); + console.info('Download task resumed.') + } else { + console.error('Failed to resume the download task. '); + } + console.info('Download task resumed.') + }).catch((err) => { + expect(true).assertEqual(true); + console.error('Failed to resume the download task. Cause:' + err); + }); + }); + console.info("requestDownload_test_018 end") + done(); + }); + + /** + * @tc.number requestDownload_test_019 + * @tc.name Test The request UploadTask + * @tc.desc Function test + */ + it('requestDownload_test_019', 0, async function (done) { + console.info("requestDownload_test_019 start") + request.download(downloadConfig, (downloadTask) => { + console.info("downloadConfig result:" + JSON.stringify(downloadTask)) + downloadTask.resume((err, result)=>{ + if (err) { + expect(true).assertEqual(true); + console.info('Failed to resume the download task. Cause:' + err); + return; + } + if (result) { + expect(result != null).assertTrue(); + console.info('Download task resumed.'); + } else { + console.info('Failed to resume the download task.'); + } + }); + }); + console.info("requestDownload_test_019 end") + done(); + }); + + /** + * @tc.number requestDownload_test_020 + * @tc.name Test The request UploadTask + * @tc.desc Function test + */ + it('requestDownload_test_020', 0, async function (done) { + console.info("requestDownload_test_020 start") + request.download(downloadConfig, (downloadTask) => { + console.info("downloadConfig result:" + JSON.stringify(downloadTask)) + downloadTask.query().then((downloadInfo) => { + expect(downloadInfo != null).assertTrue(); + console.info('Download task queried. Data:' + JSON.stringify(downloadInfo)) + }) .catch((err) => { + expect(true).assertEqual(true); + console.info('Failed to query the download task. Cause:' + err) + }); + }); + console.info("requestDownload_test_020 end") + done(); + }); + + /** + * @tc.number requestDownload_test_021 + * @tc.name Test The request UploadTask + * @tc.desc Function test + */ + it('requestDownload_test_021', 0, async function (done) { + console.info("requestDownload_test_021 start") + request.download(downloadConfig, (downloadTask) => { + console.info("downloadConfig result:" + JSON.stringify(downloadTask)) + downloadTask.queryMimeType().then((data) => { + expect(data != null).assertTrue(); + console.info('Download task queried. Data:' + JSON.stringify(data)); + }).catch((err) => { + expect(true).assertEqual(true); + console.error('Failed to query the download MimeType. Cause:' + JSON.stringify(err)) + }); + }); + console.info("requestDownload_test_021 end") + done(); + }); }) } diff --git a/miscservices/InputMethodTest_ets/entry/src/main/ets/MainAbility/test/RequestJsunit.test.ets b/miscservices/InputMethodTest_ets/entry/src/main/ets/MainAbility/test/RequestJsunit.test.ets index 58cf8b8d7..cc6340584 100644 --- a/miscservices/InputMethodTest_ets/entry/src/main/ets/MainAbility/test/RequestJsunit.test.ets +++ b/miscservices/InputMethodTest_ets/entry/src/main/ets/MainAbility/test/RequestJsunit.test.ets @@ -196,6 +196,49 @@ export default function requestJsunit() { console.log("-----------------------request_upload_0006 end-----------------------"); done(); }) + + /** + * @tc.name: ohos.request_request_upload + * @tc.desc: request_upload Method detection + * @tc.author: kangyuntao + */ + it('request_upload_0007', 0, async function (done) { + console.log("-----------------------Request_test_0006 is starting-----------------------"); + console.log("request_upload_0007 getUploadConfig() " + getUploadConfig()); + request.upload(getUploadConfig(), (err, uploadTask) => { + uploadTask.remove().then((result) => { + if (result) { + console.info('Upload task removed successfully. '); + } else { + console.error('Failed to remove the upload task. '); + } + }).catch((err) => { + expect(true).assertEqual(true); + console.error('Failed to remove the upload task. Cause: ' + JSON.stringify(err)); + }); + }) + console.log("-----------------------request_upload_0007 end-----------------------"); + done(); + }) + + /** + * @tc.name: ohos.request_request_upload + * @tc.desc: request_upload Method detection + * @tc.author: kangyuntao + */ + it('request_upload_0008', 0, async function (done) { + console.log("-----------------------request_upload_0008 is starting-----------------------"); + let uploadTask; + request.upload(getUploadConfig()).then((data) => { + uploadTask = data; + expect(uploadTask != null).assertTrue(); + }).catch((err) => { + expect(true).assertTrue(); + console.info('Failed to request the upload. Cause: ' + JSON.stringify(err)); + }) + console.log("-----------------------request_upload_0008 end-----------------------"); + done(); + }) }) function getUploadConfig() { diff --git a/miscservices/TimeTest_js/src/main/js/default/test/SystemTimeJsunit.test.js b/miscservices/TimeTest_js/src/main/js/default/test/SystemTimeJsunit.test.js index 97d8bc16a..566e1b270 100644 --- a/miscservices/TimeTest_js/src/main/js/default/test/SystemTimeJsunit.test.js +++ b/miscservices/TimeTest_js/src/main/js/default/test/SystemTimeJsunit.test.js @@ -22,11 +22,12 @@ import { afterAll, it, expect, - } from "deccjsunit/index"; - import systemTime from "@ohos.systemTime"; - - describe("TimeTest", function () { - console.log("start################################start"); +} from "deccjsunit/index"; +import systemTime from "@ohos.systemTime"; +import request from '@system.request'; + +describe("TimeTest", function () { + console.log("start################################start"); /** * @tc.number SUB_systemTime_getRealActiveTime_JS_API_0100 * @tc.name Test systemTime.getRealActiveTime @@ -36,16 +37,16 @@ import { * @tc.level : Level 0 */ it("systemTime_getRealActiveTime_test1", 0, async function (done) { - console.log("SUB_systemTime_getRealActiveTime_JS_API_0100 start"); - - systemTime.getRealActiveTime().then((data) => { - console.log("f_ActiveTime1: getRealActiveTime data = " + data); - }); - expect(true).assertTrue(); - console.log("SUB_systemTime_getRealActiveTime_JS_API_0100 end"); - done(); + console.log("SUB_systemTime_getRealActiveTime_JS_API_0100 start"); + + systemTime.getRealActiveTime().then((data) => { + console.log("f_ActiveTime1: getRealActiveTime data = " + data); + }); + expect(true).assertTrue(); + console.log("SUB_systemTime_getRealActiveTime_JS_API_0100 end"); + done(); }); - + /** * @tc.number SUB_systemTime_getRealTime_JS_API_0100 * @tc.name Test systemTime.getRealTime @@ -55,14 +56,232 @@ import { * @tc.level : Level 0 */ it("systemTime_getRealTime_test1", 0, async function (done) { - console.log("SUB_systemTime_getRealTime_JS_API_0100 start"); - - systemTime.getRealTime().then((data) => { - console.log("f_RealTime1: getRealTime data = " + data); - }); - expect(true).assertTrue(); - console.log("SUB_systemTime_getRealTime_JS_API_0100 end"); - done(); + console.log("SUB_systemTime_getRealTime_JS_API_0100 start"); + + systemTime.getRealTime().then((data) => { + console.log("f_RealTime1: getRealTime data = " + data); + }); + expect(true).assertTrue(); + console.log("SUB_systemTime_getRealTime_JS_API_0100 end"); + done(); + }); + + /** + * @tc.number SUB_systemTime_getCurrentTime_JS_API_0100 + * @tc.name Test systemTime.getCurrentTime Invalid value + * @tc.desc Test systemTime_getCurrentTime API functionality. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('systemTime_getCurrentTime_test1', 0, async function (done) { + console.info("SUB_systemTime_getCurrentTime_JS_API_0100 start"); + systemTime.getCurrentTime().then((data) => { + expect(data != null).assertTrue(); + console.info(`systemTime.getCurrentTime success data : ` + JSON.stringify(data)); + }).catch((error) => { + expect(true).assertTrue(); + console.info(`failed to systemTime.getCurrentTime because ` + JSON.stringify(error)); + }); + done(); + }); + + /** + * @tc.number SUB_systemTime_getCurrentTime_JS_API_0200 + * @tc.name Test systemTime.getCurrentTime Invalid value + * @tc.desc Test systemTime_getCurrentTime API functionality. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('systemTime_getCurrentTime_test2', 0, async function (done) { + console.info("SUB_systemTime_getCurrentTime_JS_API_0200 start"); + systemTime.getCurrentTime(true, (error, data) => { + if (error) { + expect(true).assertTrue(); + console.info(`failed to systemTime.getCurrentTime because ` + JSON.stringify(error)); + return; + } + expect(data != null).assertTrue(); + console.info(`systemTime.getCurrentTime success data : ` + JSON.stringify(data)); + }); + done(); + }); + + /** + * @tc.number SUB_systemTime_getCurrentTime_JS_API_0200 + * @tc.name Test systemTime.getCurrentTime Invalid value + * @tc.desc Test systemTime_getCurrentTime API functionality. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('systemTime_getDate_test1', 0, async function (done) { + console.info("SUB_systemTime_getDate_JS_API_0100 start"); + systemTime.getDate((error, data) => { + if (error) { + expect(true).assertTrue(); + console.info(`failed to systemTime.getDate because ` + JSON.stringify(error)); + return; + } + expect(data != null).assertTrue(); + console.info(`systemTime.getDate success data : ` + JSON.stringify(data)); + }); + done(); + }); + + /** + * @tc.number SUB_systemTime_getCurrentTime_JS_API_0200 + * @tc.name Test systemTime.getCurrentTime Invalid value + * @tc.desc Test systemTime_getCurrentTime API functionality. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('systemTime_getDate_test2', 0, async function (done) { + console.info("SUB_systemTime_getDate_JS_API_0200 start"); + systemTime.getDate().then((data) => { + expect(data != null).assertTrue(); + console.log(`systemTime.getDate success data : ` + JSON.stringify(data)); + }).catch((error) => { + expect(true).assertTrue(); + console.error(`failed to systemTime.getDate because ` + JSON.stringify(error)); + }); + done(); + }); + + /** + * @tc.number SUB_systemTime_getTimezone_JS_API_0200 + * @tc.name Test systemTime.getTimezone Invalid value + * @tc.desc Test systemTime_getTimezone API functionality. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('systemTime_getTimezon_test1', 0, async function (done) { + console.info("SUB_systemTime_getTimezon_JS_API_0100 start"); + systemTime.getTimezone((error, data) => { + if (error) { + expect(true).assertTrue(); + console.error(`failed to systemTime.getTimezone because ` + JSON.stringify(error)); + return; + } + expect(data != null).assertTrue(); + console.log(`systemTime.getTimezone success data : ` + JSON.stringify(data)); + }); + done(); + }); + + /** + * @tc.number SUB_systemTime_getTimezone_JS_API_0200 + * @tc.name Test systemTime.getTimezone Invalid value + * @tc.desc Test systemTime_getTimezone API functionality. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('systemTime_getTimezon_test2', 0, async function (done) { + console.info("SUB_systemTime_getTimezon_JS_API_0200 start"); + systemTime.getTimezone().then((data) => { + expect(data != null).assertTrue(); + console.info(`systemTime.getTimezone success data : ` + JSON.stringify(data)); + }).catch((error) => { + expect(true).assertTrue(); + console.info(`failed to systemTime.getTimezone because ` + JSON.stringify(error)); + }); + done(); + }); + + /** + * @tc.number SystemRequest_upload_test01 + * @tc.name Test SystemRequest_upload Invalid value + * @tc.desc Test SystemRequest_upload API functionality. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SystemRequest_upload_test01', 0, async function (done) { + console.info("SystemRequest_upload_test01 start"); + request.upload({ + url: 'http://www.path.com', + files: [ + { + uri: 'internal://cache/path/to/file.txt', + name: 'file', + filename: 'file.txt', + }, + ], + data: [ + { + name: 'name1', + value: 'value', + }, + ], + success: function (data) { + expect(data != null).assertTrue(); + console.info('upload success, code:' + data.code); + console.info('upload success, code:' + data.data); + console.info('upload success, code:' + data.headers); + }, + fail: function () { + expect(true).assertTrue(); + console.info('upload fail'); + }, + complete: null + }); + done(); + }); + + /** + * @tc.number SystemRequest_download_test01 + * @tc.name Test SystemRequest_download Invalid value + * @tc.desc Test SystemRequest_download API functionality. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SystemRequest_download_test01', 0, async function (done) { + console.info("SystemRequest_download_test01 start"); + request.download({ + url: 'http://www.path.com', + success: function (data) { + expect(data != null).assertTrue(); + console.info('call success callback success: ' + data.token); + }, + fail: function (data, code) { + console.info('handling fail'); + }, + filename: "文件名", + header: null, + description: "描述", + complete: null + }); + done(); + }); + + /** + * @tc.number SystemRequest_onDownloadComplete_test01 + * @tc.name Test SystemRequest_onDownloadComplete Invalid value + * @tc.desc Test SystemRequest_onDownloadComplete API functionality. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SystemRequest_onDownloadComplete_test01', 0, async function (done) { + console.info("SystemRequest_onDownloadComplete_test01 start"); + request.onDownloadComplete({ + token: 'token-index', + success: function (data) { + expect(data != null).assertTrue(); + console.info('download success, uri:' + data.uri); + }, + fail: function (data, code) { + expect(true).assertTrue(); + console.info('download fail'); + }, + complete: null + }); + done(); }); - }); +}); \ No newline at end of file diff --git a/miscservices/actspasteboardjsapitest/entry/src/main/js/default/test/List.test.js b/miscservices/actspasteboardjsapitest/entry/src/main/js/default/test/List.test.js index 7518e7b60..ac407afbb 100644 --- a/miscservices/actspasteboardjsapitest/entry/src/main/js/default/test/List.test.js +++ b/miscservices/actspasteboardjsapitest/entry/src/main/js/default/test/List.test.js @@ -13,4 +13,5 @@ * limitations under the License. */ -require('./PasteBoardJsunit.test.js') \ No newline at end of file +require('./PasteBoardJsunit.test.js') +require('./PasteBoard2Jsunit.test.js') \ No newline at end of file diff --git a/miscservices/actspasteboardjsapitest/entry/src/main/js/default/test/PasteBoard2Jsunit.test.js b/miscservices/actspasteboardjsapitest/entry/src/main/js/default/test/PasteBoard2Jsunit.test.js new file mode 100644 index 000000000..f4ec8baa4 --- /dev/null +++ b/miscservices/actspasteboardjsapitest/entry/src/main/js/default/test/PasteBoard2Jsunit.test.js @@ -0,0 +1,88 @@ +/* + * Copyright (C) 2021 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. + */ + +// @ts-nocheck +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from 'deccjsunit/index' +import pasteboard from '@ohos.pasteboard' + +describe('PasteBoardTest2', function () { + console.log('start################################start'); + + /** + * @tc.number SUB_pasteBoard_function_JS_API_7100 + * @tc.name 复制文本、uri格式 + * @tc.desc Test pasteBoard API functionality. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('pasteboard_function_test71', 0, async function (done) { + console.info('SUB_pasteBoard_function_JS_API_7100 start') + + var record = pasteboard.createUriRecord("dataability:///com.example.myapplication1?user.txt"); + record.convertToText((err, data) => { + if (err) { + expect(true).assertTrue(); + console.info('convertToText failed because ' + JSON.stringify(err)); + return; + } + expect(data != null).assertTrue(); + console.info('convertToText success data : ' + JSON.stringify(data)); + }); + console.info('SUB_pasteBoard_function_JS_API_7100 end'); + done(); + + }) + + /** + * @tc.number SUB_pasteBoard_function_JS_API_7200 + * @tc.name 复制文本、uri格式 + * @tc.desc Test pasteBoard API functionality. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('pasteboard_function_test72', 0, async function (done) { + console.info('SUB_pasteBoard_function_JS_API_7200 start') + var html = "\n" + "\n" + "\n" + "\n" + "HTML-PASTEBOARD_HTML\n" + "\n" + "\n" + "

HEAD

\n" + "

\n" + "\n" + ""; + var pasteData = pasteboard.createHtmlData(html); + var htmlText = pasteData.getPrimaryHtml(); + expect(htmlText != null).assertTrue(); + console.info('SUB_pasteBoard_function_JS_API_7200 end'); + done(); + }) + + /** + * @tc.number SUB_pasteBoard_function_JS_API_7300 + * @tc.name 复制文本、uri格式 + * @tc.desc Test pasteBoard API functionality. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('pasteboard_function_test73', 0, async function (done) { + console.info('SUB_pasteBoard_function_JS_API_7300 start') + var record = pasteboard.createUriRecord("dataability:///com.example.myapplication1?user.txt"); + record.convertToText().then((data) => { + expect(data != null).assertTrue(); + console.info('convertToText success data : ' + JSON.stringify(data)); + }).catch((error) => { + expect(true).assertTrue(); + console.info('convertToText failed because ' + JSON.stringify(error)); + }); + console.info('SUB_pasteBoard_function_JS_API_7300 end'); + done(); + }) +}) -- GitLab