未验证 提交 cdfdb524 编写于 作者: O openharmony_ci 提交者: Gitee

!5120 【杂散】【上传下载】整改request测试用例,覆盖未覆盖的属性

Merge pull request !5120 from 张育帅/master
......@@ -12,16 +12,10 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import inputMethodJSUnit from './inputMethodJSUnit.ets';
import inputMethodEngineJSUnit from './inputMethodEngineJSUnit.ets';
import inputRequestJSUnit from './inputRequestJSUnit.ets';
import requestJSUnit from './requestJSUnit.ets';
import requestDownloadJSUnit from './requestDownloadJSUnit.ets';
import inputMethodJSUnit from './inputMethodJSUnit';
import inputMethodEngineJSUnit from './inputMethodEngineJSUnit';
export default function testsuite() {
inputMethodJSUnit();
inputMethodEngineJSUnit();
inputRequestJSUnit();
requestDownloadJSUnit();
requestJSUnit();
}
\ No newline at end of file
// @ts-nocheck
/**
* 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, it, expect} from 'hypium/index';
import request from '@ohos.request';
export default function inputRequestJSUnit() {
describe('inputRequestTest', function () {
console.log("************* request Test start*************");
/**
* @tc.number inputRequest_DownloadConfig_Test_001
* @tc.name Request DownloadConfig
* @tc.desc interface DownloadConfig
*/
it('inputRequest_DownloadConfig_Test_001', 0, async function (done) {
let caseName: string = "inputRequest_DownloadConfig_Test_001";
console.log(`==========> ${caseName} Test start ==========>`);
let downloadConfig = {
header: "HTTP",
url: "www.testdownload.com",
enableMetered: false,
enableRoaming: false,
description: "test download",
title: "",
networkType: "",
};
try {
let promise = request.download(downloadConfig);
expect(promise).assertEqual(undefined);
} catch (err) {
console.log(`${caseName} fail,case success,error:${toString(err)}`);
expect(true).assertTrue();
done();
return;
}
console.log(`==========> ${caseName} Test end ==========>`);
done();
});
/**
* @tc.number inputRequest_DownloadInfo_Test_002
* @tc.name Request DownloadInfo
* @tc.desc interface DownloadInfo
*/
it('inputRequest_DownloadInfo_Test_002', 0, async function (done) {
let caseName: string = "inputRequest_DownloadInfo_Test_002";
try {
request.download({
url: "www.testdownload.com"
}).then(downloadTask => {
if (downloadTask !== undefined) {
downloadTask.query((err, downloadInfo) => {
if (downloadInfo !== undefined) {
expect("info").assertEqual(downloadInfo.description);
expect(100).assertEqual(downloadInfo.downloadedBytes);
expect(1).assertEqual(downloadInfo.downloadId);
expect(101).assertEqual(downloadInfo.failedReason);
expect("download.txt").assertEqual(downloadInfo.fileName);
expect("C://").assertEqual(downloadInfo.filePath);
expect(102).assertEqual(downloadInfo.pausedReason);
expect(200).assertEqual(downloadInfo.status);
expect("download url").assertEqual(downloadInfo.targetURI);
expect("download test").assertEqual(downloadInfo.downloadTitle);
expect(1000).assertEqual(downloadInfo.downloadTotalBytes);
}
});
}
}).catch(err => {
});
} catch (err) {
console.log(`${caseName} fail,case success,error:${toString(err)}`);
expect(true).assertTrue();
done();
return;
}
console.log(`==========> ${caseName} Test end ==========>`);
done();
});
})
}
\ No newline at end of file
// @ts-nocheck
/**
* 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, it, expect} from "deccjsunit/index.ets";
import request from '@ohos.request';
export default function requestDownloadJSUnit() {
describe('requestDownloadTest', function () {
let downloadConfig = {
url: "www.baidu.com"
};
let file = {
filename: 'text.txt',
name: 'text.txt',
uri: 'C:\\Program Files',
type: 'text'
};
let uploadConfig = {
url: "www.baidu.com",
header: 'HTTP',
method: 'post',
files: file,
data: 'json/xml'
};
let receivedSize;
let totalSize;
console.log("************* settings Test start*************");
/**
* @tc.number requestDownload_test_001
* @tc.name Test The request DownloadTask
* @tc.desc Function test
*/
it('requestDownload_test_001', 0, async function (done) {
try {
request.download(downloadConfig, (downloadTask) => {
console.log("downloadConfig result:" + JSON.stringify(downloadTask))
downloadTask.on('progress', (receivedSize, totalSize) => {
console.log("downloadTask on_progress:" + JSON.stringify(receivedSize));
console.log("downloadTask on_progress:" + JSON.stringify(totalSize));
this.receivedSize = receivedSize;
this.totalSize = totalSize;
expect(true).assertTrue();
})
});
} catch (exception) {
console.log("requestDownload_test_001 failed due to execute timeout 5s");
expect(true).assertTrue();
}
done();
});
/**
* @tc.number requestDownload_test_002
* @tc.name Test The request DownloadTask
* @tc.desc Function test
*/
it('requestDownload_test_002', 0, async function (done) {
try {
request.download(downloadConfig, (downloadTask) => {
console.log("downloadConfig result:" + JSON.stringify(downloadTask))
downloadTask.off('progress', (receivedSize, totalSize) => {
console.log("downloadTask off_progress:" + JSON.stringify(receivedSize));
console.log("downloadTask off_progress:" + JSON.stringify(totalSize));
this.receivedSize = receivedSize;
this.totalSize = totalSize;
expect(true).assertTrue();
})
});
} catch (exception) {
console.log("requestDownload_test_002 failed due to execute timeout 5s");
expect(true).assertTrue();
}
done();
});
/**
* @tc.number requestDownload_test_003
* @tc.name Test The request DownloadTask
* @tc.desc Function test
*/
it('requestDownload_test_003', 0, async function (done) {
try {
request.download(downloadConfig, (downloadTask) => {
console.log("downloadConfig result:" + JSON.stringify(downloadTask))
downloadTask.on('complete', (err) => {
console.log("downloadTask on_complete err:" + err);
expect(true).assertTrue();
});
});
} catch (exception) {
console.log("requestDownload_test_003 failed due to execute timeout 5s");
expect(true).assertTrue();
}
done();
});
/**
* @tc.number requestDownload_test_004
* @tc.name Test The request DownloadTask
* @tc.desc Function test
*/
it('requestDownload_test_004', 0, async function (done) {
try {
request.download(downloadConfig, (downloadTask) => {
console.log("downloadConfig result:" + JSON.stringify(downloadTask))
downloadTask.on('pause', (err) => {
console.log("downloadTask on_pause err:" + err);
expect(true).assertTrue();
});
});
} catch (exception) {
console.log("requestDownload_test_004 failed due to execute timeout 5s");
expect(true).assertTrue();
}
done();
});
/**
* @tc.number requestDownload_test_005
* @tc.name Test The request DownloadTask
* @tc.desc Function test
*/
it('requestDownload_test_005', 0, async function (done) {
try {
request.download(downloadConfig, (downloadTask) => {
console.log("downloadConfig result:" + JSON.stringify(downloadTask))
downloadTask.on('remove', (err) => {
console.log("downloadTask on_remove err:" + err);
expect(true).assertTrue();
});
});
} catch (exception) {
console.log("requestDownload_test_005 failed due to execute timeout 5s");
expect(true).assertTrue();
}
done();
});
/**
* @tc.number requestDownload_test_006
* @tc.name Test The request DownloadTask
* @tc.desc Function test
*/
it('requestDownload_test_006', 0, async function (done) {
try {
request.download(downloadConfig, (downloadTask) => {
console.log("downloadConfig result:" + JSON.stringify(downloadTask));
downloadTask.off('complete', (err) => {
console.log("downloadTask off_complete err:" + err);
expect(true).assertTrue();
});
});
} catch (exception) {
console.log("requestDownload_test_006 failed due to execute timeout 5s");
expect(true).assertTrue();
}
done();
});
/**
* @tc.number requestDownload_test_007
* @tc.name Test The request DownloadTask
* @tc.desc Function test
*/
it('requestDownload_test_007', 0, async function (done) {
try {
request.download(downloadConfig, (downloadTask) => {
console.log("downloadConfig result:" + JSON.stringify(downloadTask))
downloadTask.off('pause', (err) => {
console.log("downloadTask off_pause err:" + err);
expect(true).assertTrue();
});
});
} catch (exception) {
console.log("requestDownload_test_007 failed due to execute timeout 5s");
expect(true).assertTrue();
}
done();
});
/**
* @tc.number requestDownload_test_007
* @tc.name Test The request DownloadTask
* @tc.desc Function test
*/
it('requestDownload_test_008', 0, async function (done) {
try {
request.download(downloadConfig, (downloadTask) => {
console.log("downloadConfig result:" + JSON.stringify(downloadTask))
downloadTask.off('remove', (err) => {
console.log("downloadTask off_remove err:" + err);
expect(true).assertTrue();
});
});
} catch (exception) {
console.log("requestDownload_test_008 failed due to execute timeout 5s");
expect(true).assertTrue();
}
done();
});
/**
* @tc.number requestDownload_test_009
* @tc.name Test The request DownloadTask
* @tc.desc Function test
*/
it('requestDownload_test_009', 0, async function (done) {
try {
request.download(downloadConfig, (downloadTask) => {
console.log("downloadConfig result:" + JSON.stringify(downloadTask))
downloadTask.on('fail', (err) => {
console.log("downloadTask on_fail err:" + err);
expect(true).assertTrue();
});
});
} catch (exception) {
console.log("requestDownload_test_009 failed due to execute timeout 5s");
expect(true).assertTrue();
}
done();
});
/**
* @tc.number requestDownload_test_010
* @tc.name Test The request DownloadTask
* @tc.desc Function test
*/
it('requestDownload_test_010', 0, async function (done) {
try {
request.download(downloadConfig, (downloadTask) => {
console.log("downloadConfig result:" + JSON.stringify(downloadTask))
downloadTask.off('fail', (err) => {
console.log("downloadTask off_fail err:" + err);
expect(true).assertTrue();
});
});
} catch (exception) {
console.log("requestDownload_test_010 failed due to execute timeout 5s");
expect(true).assertTrue();
}
done();
});
/**
* @tc.number requestDownload_test_011
* @tc.name Test The request DownloadTask
* @tc.desc Function test
*/
it('requestDownload_test_011', 0, async function (done) {
try {
request.download(downloadConfig, (downloadTask) => {
console.log("downloadConfig result:" + JSON.stringify(downloadTask))
downloadTask.remove((err) => {
console.log("downloadTask remove err:" + err);
expect(true).assertTrue();
});
});
} catch (exception) {
console.log("requestDownload_test_011 failed due to execute timeout 5s");
expect(true).assertTrue();
}
done();
});
/**
* @tc.number requestDownload_test_012
* @tc.name Test The request DownloadTask
* @tc.desc Function test
*/
it('requestDownload_test_012', 0, async function (done) {
try {
request.download(downloadConfig, (downloadTask) => {
console.log("downloadConfig result:" + JSON.stringify(downloadTask))
downloadTask.query((err) => {
console.log("downloadTask query err:" + err);
expect(true).assertTrue();
});
});
} catch (err) {
console.log("requestDownload_test_012 invoke download error : " + JSON.stringify(err));
expect(true).assertTrue();
}
done();
});
/**
* @tc.number requestDownload_test_013
* @tc.name Test The request DownloadTask
* @tc.desc Function test
*/
it('requestDownload_test_013', 0, async function (done) {
try {
request.download(downloadConfig, (downloadTask) => {
console.log("downloadConfig result:" + JSON.stringify(downloadTask))
downloadTask.queryMimeType((err) => {
console.log("downloadTask queryMimeType err:" + err);
expect(true).assertTrue();
});
});
} catch (exception) {
console.log("requestDownload_test_013 failed due to execute timeout 5s");
expect(true).assertTrue();
}
done();
});
/**
* @tc.number requestDownload_test_007
* @tc.name Test The request UploadTask
* @tc.desc Function test
*/
it('requestDownload_test_014', 0, async function (done) {
try {
request.upload(uploadConfig, (uploadTask) => {
console.log("downloadConfig result:" + JSON.stringify(uploadTask))
expect(true).assertTrue();
});
} catch (exception) {
console.log("requestDownload_test_014 failed due to execute timeout 5s");
expect(true).assertTrue();
}
done();
});
/**
* @tc.number requestDownload_test_015
* @tc.name testRequestDownloadTask_015
* @tc.desc Function test
*/
it('requestDownload_test_015', 0, async function (done) {
try {
request.download(downloadConfig, (downloadTask) => {
console.log("downloadConfig result:" + JSON.stringify(downloadTask))
downloadTask.remove().then((result) => {
console.info('requestDownload_test_015 Download task removed result=' + result);
expect(true).assertTrue();
}).catch ((err) => {
console.log("requestDownload_test_015 downloadTask remove err:" + err);
expect(true).assertTrue();
});
});
} catch (exception) {
console.log("requestDownload_test_015 failed due to execute timeout 5s");
expect(true).assertTrue();
}
done();
});
/**
* @tc.number requestDownload_test_016
* @tc.name testRequestDownloadTask_016
* @tc.desc Function test
*/
it('requestDownload_test_016', 0, async function (done) {
try {
request.download(downloadConfig, (downloadTask) => {
console.log("downloadConfig result:" + JSON.stringify(downloadTask))
downloadTask.query().then((downloadInfo) => {
console.info('requestDownload_test_016 Data:' + JSON.stringify(downloadInfo));
expect(true).assertTrue();
}) .catch((err) => {
console.log("downloadTask query err:" + err);
expect(true).assertTrue();
});
});
} catch (err) {
console.log("requestDownload_test_016 invoke download error : " + JSON.stringify(err));
expect(true).assertTrue();
}
done();
});
/**
* @tc.number requestDownload_test_017
* @tc.name testRequestDownloadTask_017
* @tc.desc Function test
*/
it('requestDownload_test_017', 0, async function (done) {
try {
request.download(downloadConfig, (downloadTask) => {
console.log("downloadConfig result:" + JSON.stringify(downloadTask))
downloadTask.queryMimeType().then((data) => {
console.info('requestDownload_test_017. Data:' + JSON.stringify(data));
expect(true).assertTrue();
}).catch((err) => {
console.log("downloadTask queryMimeType err:" + err);
expect(true).assertTrue();
});
});
} catch (exception) {
console.log("requestDownload_test_017 failed due to execute timeout 5s");
expect(true).assertTrue();
}
done();
});
/**
* @tc.number requestDownload_test_018
* @tc.name testRequestDownloadTask_018
* @tc.desc Function test
*/
it('requestDownload_test_018', 0, async function (done) {
try {
request.download(downloadConfig, (downloadTask) => {
console.log("downloadConfig result:" + JSON.stringify(downloadTask))
downloadTask.pause().then((data) => {
console.info('requestDownload_test_018. Data:' + JSON.stringify(data));
expect(true).assertTrue();
}).catch((err) => {
console.log("requestDownload_test_018 err:" + err);
expect(true).assertTrue();
});
});
} catch (exception) {
console.log("requestDownload_test_018 failed due to execute timeout 5s");
expect(true).assertTrue();
}
done();
});
/**
* @tc.number requestDownload_test_019
* @tc.name testRequestDownloadTask_019
* @tc.desc Function test
*/
it('requestDownload_test_019', 0, async function (done) {
try {
request.download(downloadConfig, (downloadTask) => {
console.log("downloadConfig result:" + JSON.stringify(downloadTask))
downloadTask.pause((err, result)=>{
if(err) {
console.error('requestDownload_test_019 error:' + JSON.stringify(err));
expect(true).assertTrue();
} else {
console.info('requestDownload_test_019. result:' + JSON.stringify(result));
expect(true).assertTrue();
}
});
});
} catch (exception) {
console.log("requestDownload_test_019 failed due to execute timeout 5s");
expect(true).assertTrue();
}
done();
});
/**
* @tc.number requestDownload_test_020
* @tc.name testRequestDownloadTask_020
* @tc.desc Function test
*/
it('requestDownload_test_020', 0, async function (done) {
try {
request.download(downloadConfig, (downloadTask) => {
console.log("downloadConfig result:" + JSON.stringify(downloadTask))
downloadTask.resume().then((data) => {
console.info('requestDownload_test_020. Data:' + JSON.stringify(data));
expect(true).assertTrue();
}).catch((err) => {
console.log("requestDownload_test_020 err:" + err);
expect(true).assertTrue();
});
});
} catch (exception) {
console.log("requestDownload_test_020 failed due to execute timeout 5s");
expect(true).assertTrue();
}
done();
});
/**
* @tc.number requestDownload_test_021
* @tc.name testRequestDownloadTask_021
* @tc.desc Function test
*/
it('requestDownload_test_021', 0, async function (done) {
try {
request.download(downloadConfig, (downloadTask) => {
console.log("downloadConfig result:" + JSON.stringify(downloadTask))
downloadTask.resume((err, result)=>{
if(err) {
console.error('requestDownload_test_021 error:' + JSON.stringify(err));
expect(true).assertTrue();
} else {
console.info('requestDownload_test_021. result:' + JSON.stringify(result));
expect(true).assertTrue();
}
});
});
} catch (exception) {
console.log("requestDownload_test_021 failed due to execute timeout 5s");
expect(true).assertTrue();
}
done();
});
})
}
// @ts-nocheck
/**
* 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, it, expect} from "deccjsunit/index.ets";
import request from '@ohos.request';
export default function requestJSUnit() {
describe('requestTest', function () {
/**
* @tc.name: ohos.request_request_0001
* @tc.desc: NETWORK_MOBILE NETWORK_WIFI ERROR_CANNOT_RESUME ERROR_DEVICE_NOT_FOUND Values detection
*
* @tc.author: kangyuntao
*/
it('request_test_0001', 0, async function (done) {
console.log("-----------------------Request_test_0001 is starting-----------------------");
try {
request.NETWORK_MOBILE = 1;
console.log("request_test_0001 request.NETWORK_MOBILE:" + request.NETWORK_MOBILE);
expect(request.NETWORK_MOBILE).assertEqual(1);
request.NETWORK_WIFI = 2;
console.log("request_test_0001 request.NETWORK_WIFI:" + request.NETWORK_WIFI);
expect(request.NETWORK_WIFI).assertEqual(2);
request.ERROR_CANNOT_RESUME = 3;
console.log("request_test_0001 request.ERROR_CANNOT_RESUME:" + request.ERROR_CANNOT_RESUME);
expect(request.ERROR_CANNOT_RESUME).assertEqual(3);
request.ERROR_DEVICE_NOT_FOUND = 4;
console.log("request_test_0001 request.ERROR_DEVICE_NOT_FOUND:" + request.ERROR_DEVICE_NOT_FOUND);
expect(request.ERROR_DEVICE_NOT_FOUND).assertEqual(4);
} catch (err) {
expect(true).assertEqual(true);
console.error("request_test_0001 error: " + err);
}
console.log("-----------------------Request_test_0001 end-----------------------");
done();
});
/**
* @tc.name: ohos.request_request_0002
* @tc.desc: ERROR_FILE_ALREADY_EXISTS ERROR_FILE_ERROR ERROR_HTTP_DATA_ERROR
* ERROR_INSUFFICIENT_SPACE Values detection
* @tc.author: kangyuntao
*/
it('request_test_0002', 0, async function (done) {
console.log("-----------------------Request_test_0002 is starting-----------------------");
try {
request.ERROR_FILE_ALREADY_EXISTS = 5;
console.log("request_test_0002 request.ERROR_FILE_ALREADY_EXISTS:" + request.ERROR_FILE_ALREADY_EXISTS);
expect(request.ERROR_FILE_ALREADY_EXISTS).assertEqual(5);
request.ERROR_FILE_ERROR = 6;
console.log("request_test_0002 request.ERROR_FILE_ERROR:" + request.ERROR_FILE_ERROR);
expect(request.ERROR_FILE_ERROR).assertEqual(6);
request.ERROR_HTTP_DATA_ERROR = 7;
console.log("request_test_0002 request.ERROR_HTTP_DATA_ERROR:" + request.ERROR_HTTP_DATA_ERROR);
expect(request.ERROR_HTTP_DATA_ERROR).assertEqual(7);
request.ERROR_INSUFFICIENT_SPACE = 8;
console.log("request_test_0002 request.ERROR_INSUFFICIENT_SPACE:" + request.ERROR_INSUFFICIENT_SPACE);
expect(request.ERROR_INSUFFICIENT_SPACE).assertEqual(8);
} catch (err) {
expect(true).assertEqual(true);
console.error("request_test_0002 error: " + err);
}
console.log("-----------------------Request_test_0002 end-----------------------");
done();
});
/**
* @tc.name: ohos.request_request_0003
* @tc.desc: ERROR_TOO_MANY_REDIRECTS ERROR_UNHANDLED_HTTP_CODE ERROR_UNHANDLED_HTTP_CODE
* PAUSED_QUEUED_FOR_WIFI Values detection
* @tc.author: kangyuntao
*/
it('request_test_0003', 0, async function (done) {
console.log("-----------------------Request_test_0003 is starting-----------------------");
try {
request.ERROR_TOO_MANY_REDIRECTS = 9;
console.log("request_test_0003 request.ERROR_TOO_MANY_REDIRECTS:" + request.ERROR_TOO_MANY_REDIRECTS);
expect(request.ERROR_TOO_MANY_REDIRECTS).assertEqual(9);
request.ERROR_UNHANDLED_HTTP_CODE = 10;
console.log("request_test_0003 request.ERROR_UNHANDLED_HTTP_CODE:" + request.ERROR_UNHANDLED_HTTP_CODE);
expect(request.ERROR_UNHANDLED_HTTP_CODE).assertEqual(10);
request.ERROR_UNKNOWN = 11;
console.log("request_test_0003 request.ERROR_UNKNOWN:" + request.ERROR_UNKNOWN);
expect(request.ERROR_UNKNOWN).assertEqual(11);
request.PAUSED_QUEUED_FOR_WIFI = 12;
console.log("request_test_0003 request.PAUSED_QUEUED_FOR_WIFI:" + request.PAUSED_QUEUED_FOR_WIFI);
expect(request.PAUSED_QUEUED_FOR_WIFI).assertEqual(12);
} catch (err) {
expect(true).assertEqual(true);
console.error("request_test_0003 error: " + err);
}
console.log("-----------------------Request_test_0003 end-----------------------");
done();
});
/**
* @tc.name: ohos.request_request_0004
* @tc.desc: PAUSED_UNKNOWN PAUSED_WAITING_FOR_NETWORK PAUSED_WAITING_TO_RETRY ESSION_FAILED Values detection
* @tc.author: kangyuntao
*/
it('request_test_0004', 0, async function (done) {
console.log("-----------------------Request_test_0004 is starting-----------------------");
try {
request.PAUSED_UNKNOWN = 13;
console.log("request_test_0004 request.PAUSED_UNKNOWN:" + request.PAUSED_UNKNOWN);
expect(request.PAUSED_UNKNOWN).assertEqual(13);
request.PAUSED_WAITING_FOR_NETWORK = 14;
console.log("request_test_0004 request.PAUSED_WAITING_FOR_NETWORK:" + request.PAUSED_WAITING_FOR_NETWORK);
expect(request.PAUSED_WAITING_FOR_NETWORK).assertEqual(14);
request.PAUSED_WAITING_TO_RETRY = 15;
console.log("request_test_0004 request.PAUSED_WAITING_TO_RETRY:" + request.PAUSED_WAITING_TO_RETRY);
expect(request.PAUSED_WAITING_TO_RETRY).assertEqual(15);
request.SESSION_FAILED = 16;
console.log("request_test_0004 request.SESSION_FAILED:" + request.SESSION_FAILED);
expect(request.SESSION_FAILED).assertEqual(16);
} catch (err) {
expect(true).assertEqual(true);
console.error("request_test_0004 error: " + err);
}
console.log("-----------------------Request_test_0004 end-----------------------");
done();
});
/**
* @tc.name: ohos.request_request_0005
* @tc.desc: SESSION_PAUSED SESSION_PENDING SESSION_RUNNING SESSION_SUCCESSFUL Values detection
* @tc.author: kangyuntao
*/
it('request_test_0005', 0, async function (done) {
console.log("-----------------------Request_test_0005 is starting-----------------------");
try {
request.SESSION_PAUSED = 17;
console.log("request_test_0004 request.SESSION_PAUSED:" + request.SESSION_PAUSED);
expect(request.SESSION_PAUSED).assertEqual(17);
request.SESSION_PENDING = 18;
console.log("request_test_0004 request.SESSION_PENDING:" + request.SESSION_PENDING);
expect(request.SESSION_PENDING).assertEqual(18);
request.SESSION_RUNNING = 19;
console.log("request_test_0004 request.SESSION_RUNNING:" + request.SESSION_RUNNING);
expect(request.SESSION_RUNNING).assertEqual(19);
request.SESSION_SUCCESSFUL = 20;
console.log("request_test_0004 request.SESSION_SUCCESSFUL:" + request.SESSION_SUCCESSFUL);
expect(request.SESSION_SUCCESSFUL).assertEqual(20);
} catch (err) {
expect(true).assertEqual(true);
console.error("request_test_0005 error: " + err);
}
console.log("-----------------------Request_test_0005 end-----------------------");
done();
});
/**
* @tc.name: ohos.request_request_upload
* @tc.desc: request_upload Method detection
* @tc.author: kangyuntao
*/
it('request_upload_0006', 0, async function (done) {
console.log("-----------------------Request_test_0006 is starting-----------------------");
try {
console.log("request_upload_0006 getUploadConfig() " + getUploadConfig());
request.upload(getUploadConfig(), (err, uploadTask) => {
if (err) {
expect().assertFail();
} else {
console.log("request_upload_0006 progress uploadTask =" + JSON.stringify(uploadTask));
uploadTask.on('progress', function (data1, data2) {
console.log("request_upload_0006 on data1 =" + data1);
console.log("request_upload_0006 on data2 =" + data2);
})
uploadTask.off('progress', function (data1, data2) {
console.log("request_upload_0006 off data1 =" + data1);
console.log("request_upload_0006 off data2 =" + data2);
})
uploadTask.remove((err, data) => {
console.log("request_upload_0006 remove =" + data);
})
}
})
} catch (err) {
expect(true).assertEqual(true);
console.error("request_upload_0006 error: " + err);
}
console.log("-----------------------request_upload_0006 end-----------------------");
done();
});
/**
* @tc.number request_upload_0007
* @tc.name: test_request_upload_0007
* @tc.desc: request_upload Method detection
*/
it('request_upload_0007', 0, async function (done) {
console.log("-----------------------request_upload_0007 is starting-----------------------");
try {
console.log("request_upload_0007 getUploadConfig() " + getUploadConfig());
request.upload(getUploadConfig(), (err, uploadTask) => {
if (err) {
expect().assertFail();
} else {
console.log("request_upload_0007 progress uploadTask =" + JSON.stringify(uploadTask));
uploadTask.on('headerReceive', function (data1, data2) {
console.log("request_upload_0007 headerReceive on data1 =" + data1);
console.log("request_upload_0007 headerReceive on data2 =" + data2);
})
uploadTask.off('headerReceive', function (data1, data2) {
console.log("request_upload_0007 headerReceive off data1 =" + data1);
console.log("request_upload_0007 headerReceive off data2 =" + data2);
})
uploadTask.remove().then((result) => {
console.log("request_upload_0006 remove =" + result);
}).catch((err) => {
console.error('Failed to remove the upload task. Cause: ' + JSON.stringify(err));
});
}
})
} catch (err) {
expect(true).assertEqual(true);
console.error("request_upload_0007 error: " + err);
}
console.log("-----------------------request_upload_0007 end-----------------------");
done();
})
});
function getUploadConfig() {
let file = {
filename: 'test',
name: 'test',
uri: 'internal://cache/test.txt',
type: 'txt'
}
let requestData = [{
name: 'name', value: '123'
}]
let fileArray = new Array();
fileArray[0] = file;
let headerHttp = {
headers: 'http'
}
let uploadConfig = {
url: 'http://192.168.112.124/upload_test/',
header: headerHttp,
method: 'POST',
files: fileArray,
data: requestData
}
return uploadConfig
}
}
......@@ -13,8 +13,10 @@
* limitations under the License.
*/
import uploadRequestJSUnitTest from './uploadCallbackXTSJSUnitTest';
import requestUploadJSUnit from './requestUpload.test';
import requestDownloadJSUnit from './requestDownload.test';
export default function testsuite() {
uploadRequestJSUnitTest()
requestUploadJSUnit()
requestDownloadJSUnit()
}
\ No newline at end of file
/*
* 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, it, expect} from 'deccjsunit/index'
import request from '@ohos.request'
let RequestData = [{
name: '', // Represents the name of the form element.
value: '' // Represents the value of the form element.
}]
let RequestDataArray=new Array();
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
function getUploadConfig(fileURL){
let File = {
filename: 'test', // When multipart is submitted, the file name in the request header.
name: 'test', // When multipart is submitted, the name of the form item. The default is file.
uri: 'internal://cache/test.txt',
//The local storage path of the file
// (please refer to the storage directory definition for path usage).
type: 'txt'
//The content type of the file is obtained by default
// according to the suffix of the file name or path.
}
let FileArray=new Array();
FileArray[0] = File;
let headerHttp = { headers: 'http' }
let UploadConfig = {
url: 'http://192.168.112.124/upload_test/',// Resource address.
header: headerHttp, // Adds an HTTP or HTTPS header to be included with the upload request.
method: 'POST', // Request method: POST, PUT. The default POST.
files: FileArray, // A list of files to be uploaded. Please use multipart/form-data to submit.
data: RequestData // The requested form data.
}
return UploadConfig
}
//upload公共方法
function publicUpload(UploadConfig){
console.info(`TestUpdate UploadConfig ${JSON.stringify(UploadConfig)}`)
return new Promise(function(resolve, reject) {
request.upload(UploadConfig, (err, data) => {
console.info("TestUpdate publicOnProgress UpdateTask =" + JSON.stringify(data));
resolve(data);
})
})
}
//OnProgress公共方法
function publicOnProgress(UpdateTask, Type){
return new Promise(function(resolve, reject) {
UpdateTask.on(Type, function(data1 ,data2){
let progress = {
uploadedSize : data1,
totalSize : data2
}
console.info("TestUpdate publicOnProgress uploadedSize =" + data1);
console.info("TestUpdate publicOnProgress totalSize =" + data2);
resolve(progress);
})
})
}
//OffProgress公共方法
function publicOffProgress(UpdateTask, Type){
return new Promise(function(resolve, reject) {
UpdateTask.off(Type, function(data1 ,data2){
let progress = {
uploadedSize : data1,
totalSize : data2
}
console.info("TestUpdate publicOffProgress uploadedSize =" + data1);
console.info("TestUpdate publicOffProgress totalSize =" + data2);
resolve(progress);
})
})
}
//其他on公共方法
function publicOn(UpdateTask, Type){
return new Promise(function(resolve, reject) {
UpdateTask.on(Type, function(data){
console.info("TestUpdate publicOn =" + data);
resolve(data);
})
})
}
//其他off公共方法
function publicOff(UpdateTask, Type){
return new Promise(function(resolve, reject) {
UpdateTask.off(Type, function(data){
console.info("TestUpdate publicOff =" + data);
resolve(data);
})
})
}
//remove公共方法
function publicRemove(UpdateTask){
return new Promise(function(resolve, reject) {
UpdateTask.remove((err,data) => {
console.info("TestUpdate publicRemove =" + data);
resolve(data);
})
})
}
export{publicUpload,publicOn,publicOff,publicRemove,publicOnProgress,publicOffProgress,getUploadConfig,sleep}
\ No newline at end of file
// @ts-nocheck
/*
* 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 "hypium/index";
import AbilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry';
import request from "@ohos.request";
export default function requestUploadJSUnit() {
describe('requestUploadTest', 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');
});
/**
* sleep function.
*/
function sleep(date, time){
while(Date.now() - date <= time);
}
let uploadTask;
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_0001
* @tc.name Test requestUploadTest type = TIMER_TYPE_REALTIME
* @tc.desc Test requestUploadTest API functionality.
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_REQUEST_UPLOAD_API_0001', 0, async function (done) {
console.info("-----------------------SUB_REQUEST_UPLOAD_API_0001 is starting-----------------------");
try {
console.info("SUB_REQUEST_UPLOAD_API_0001 request.NETWORK_MOBILE:" + request.NETWORK_MOBILE);
expect(request.NETWORK_MOBILE).assertEqual(1);
console.info("SUB_REQUEST_UPLOAD_API_0001 request.NETWORK_WIFI:" + request.NETWORK_WIFI);
expect(request.NETWORK_WIFI).assertEqual(65536);
console.info("SUB_REQUEST_UPLOAD_API_0001 request.ERROR_CANNOT_RESUME:" + request.ERROR_CANNOT_RESUME);
expect(request.ERROR_CANNOT_RESUME).assertEqual(0);
console.info("SUB_REQUEST_UPLOAD_API_0001 request.ERROR_DEVICE_NOT_FOUND:" + request.ERROR_DEVICE_NOT_FOUND);
expect(request.ERROR_DEVICE_NOT_FOUND).assertEqual(1);
} catch (err) {
expect(true).assertEqual(true);
console.error("SUB_REQUEST_UPLOAD_API_0001 error: " + err);
}
console.info("-----------------------SUB_REQUEST_UPLOAD_API_0001 end-----------------------");
done();
});
/**
* @tc.number SUB_REQUEST_UPLOAD_API_0002
* @tc.name Test requestUploadTest type = TIMER_TYPE_REALTIME
* @tc.desc Test requestUploadTest API functionality.
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_REQUEST_UPLOAD_API_0002', 0, async function (done) {
console.info("-----------------------SUB_REQUEST_UPLOAD_API_0002 is starting-----------------------");
try {
console.info("SUB_REQUEST_UPLOAD_API_0002 request.ERROR_FILE_ALREADY_EXISTS:" + request.ERROR_FILE_ALREADY_EXISTS);
expect(request.ERROR_FILE_ALREADY_EXISTS).assertEqual(2);
console.info("SUB_REQUEST_UPLOAD_API_0002 request.ERROR_FILE_ERROR:" + request.ERROR_FILE_ERROR);
expect(request.ERROR_FILE_ERROR).assertEqual(3);
console.info("SUB_REQUEST_UPLOAD_API_0002 request.ERROR_HTTP_DATA_ERROR:" + request.ERROR_HTTP_DATA_ERROR);
expect(request.ERROR_HTTP_DATA_ERROR).assertEqual(4);
console.info("SUB_REQUEST_UPLOAD_API_0002 request.ERROR_INSUFFICIENT_SPACE:" + request.ERROR_INSUFFICIENT_SPACE);
expect(request.ERROR_INSUFFICIENT_SPACE).assertEqual(5);
} catch (err) {
expect(true).assertEqual(true);
console.error("SUB_REQUEST_UPLOAD_API_0002 error: " + err);
}
console.info("-----------------------SUB_REQUEST_UPLOAD_API_0002 end-----------------------");
done();
});
/**
* @tc.number SUB_REQUEST_UPLOAD_API_0003
* @tc.name Test requestUploadTest type = TIMER_TYPE_REALTIME
* @tc.desc Test requestUploadTest API functionality.
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_REQUEST_UPLOAD_API_0003', 0, async function (done) {
console.info("-----------------------SUB_REQUEST_UPLOAD_API_0003 is starting-----------------------");
try {
console.info("SUB_REQUEST_UPLOAD_API_0003 request.ERROR_TOO_MANY_REDIRECTS:" + request.ERROR_TOO_MANY_REDIRECTS);
expect(request.ERROR_TOO_MANY_REDIRECTS).assertEqual(6);
console.info("SUB_REQUEST_UPLOAD_API_0003 request.ERROR_UNHANDLED_HTTP_CODE:" + request.ERROR_UNHANDLED_HTTP_CODE);
expect(request.ERROR_UNHANDLED_HTTP_CODE).assertEqual(7);
console.info("SUB_REQUEST_UPLOAD_API_0003 request.ERROR_UNKNOWN:" + request.ERROR_UNKNOWN);
expect(request.ERROR_UNKNOWN).assertEqual(8);
console.info("SUB_REQUEST_UPLOAD_API_0003 request.PAUSED_QUEUED_FOR_WIFI:" + request.PAUSED_QUEUED_FOR_WIFI);
expect(request.PAUSED_QUEUED_FOR_WIFI).assertEqual(0);
} catch (err) {
expect(true).assertEqual(true);
console.error("SUB_REQUEST_UPLOAD_API_0003 error: " + err);
}
console.info("-----------------------SUB_REQUEST_UPLOAD_API_0003 end-----------------------");
done();
});
/**
* @tc.number SUB_REQUEST_UPLOAD_API_0004
* @tc.name Test requestUploadTest type = TIMER_TYPE_REALTIME
* @tc.desc Test requestUploadTest API functionality.
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_REQUEST_UPLOAD_API_0004', 0, async function (done) {
console.info("-----------------------SUB_REQUEST_UPLOAD_API_0004 is starting-----------------------");
try {
console.info("SUB_REQUEST_UPLOAD_API_0004 request.PAUSED_UNKNOWN:" + request.PAUSED_UNKNOWN);
expect(request.PAUSED_UNKNOWN).assertEqual(4);
console.info("SUB_REQUEST_UPLOAD_API_0004 request.PAUSED_WAITING_FOR_NETWORK:" + request.PAUSED_WAITING_FOR_NETWORK);
expect(request.PAUSED_WAITING_FOR_NETWORK).assertEqual(1);
console.info("SUB_REQUEST_UPLOAD_API_0004 request.PAUSED_WAITING_TO_RETRY:" + request.PAUSED_WAITING_TO_RETRY);
expect(request.PAUSED_WAITING_TO_RETRY).assertEqual(2);
console.info("SUB_REQUEST_UPLOAD_API_0004 request.SESSION_FAILED:" + request.SESSION_FAILED);
expect(request.SESSION_FAILED).assertEqual(4);
} catch (err) {
expect(true).assertEqual(true);
console.error("SUB_REQUEST_UPLOAD_API_0004 error: " + err);
}
console.info("-----------------------SUB_REQUEST_UPLOAD_API_0004 end-----------------------");
done();
});
/**
* @tc.number SUB_REQUEST_UPLOAD_API_0005
* @tc.name Test requestUploadTest type = TIMER_TYPE_REALTIME
* @tc.desc Test requestUploadTest API functionality.
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_REQUEST_UPLOAD_API_0005', 0, async function (done) {
console.info("-----------------------SUB_REQUEST_UPLOAD_API_0005 is starting-----------------------");
try {
console.info("SUB_REQUEST_UPLOAD_API_0004 request.SESSION_PAUSED:" + request.SESSION_PAUSED);
expect(request.SESSION_PAUSED).assertEqual(3);
console.info("SUB_REQUEST_UPLOAD_API_0004 request.SESSION_PENDING:" + request.SESSION_PENDING);
expect(request.SESSION_PENDING).assertEqual(2);
console.info("SUB_REQUEST_UPLOAD_API_0004 request.SESSION_RUNNING:" + request.SESSION_RUNNING);
expect(request.SESSION_RUNNING).assertEqual(1);
console.info("SUB_REQUEST_UPLOAD_API_0004 request.SESSION_SUCCESSFUL:" + request.SESSION_SUCCESSFUL);
expect(request.SESSION_SUCCESSFUL).assertEqual(0);
} catch (err) {
expect(true).assertEqual(true);
console.error("SUB_REQUEST_UPLOAD_API_0005 error: " + err);
}
console.info("-----------------------SUB_REQUEST_UPLOAD_API_0005 end-----------------------");
done();
});
/**
* @tc.number SUB_REQUEST_UPLOAD_API_CALLBACK_0001
* @tc.name Test requestUploadTest type = TIMER_TYPE_REALTIME
* @tc.desc Test requestUploadTest API functionality.
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 1
*/
it('SUB_REQUEST_UPLOAD_API_CALLBACK_0001', 0, async function (done) {
console.info("-----------------------SUB_REQUEST_UPLOAD_API_CALLBACK_0001 is starting-----------------------");
try {
console.info("SUB_REQUEST_UPLOAD_API_CALLBACK_0001 uploadConfig = " + JSON.stringify(uploadConfig));
request.upload(uploadConfig, (data) => {
uploadTask = data;
console.info("SUB_REQUEST_UPLOAD_API_CALLBACK_0001 progress uploadTask =" + JSON.stringify(uploadTask));
expect(uploadTask != undefined).assertEqual(true);
uploadTask.on('progress', function (data1, data2) {
console.info("SUB_REQUEST_UPLOAD_API_CALLBACK_0001 on data1 =" + data1);
console.info("SUB_REQUEST_UPLOAD_API_CALLBACK_0001 on data2 =" + data2);
});
uploadTask.off('progress', function (data1, data2) {
console.info("SUB_REQUEST_UPLOAD_API_CALLBACK_0001 off data1 =" + data1);
console.info("SUB_REQUEST_UPLOAD_API_CALLBACK_0001 off data2 =" + data2);
});
uploadTask.remove((err, data) => {
console.info("SUB_REQUEST_UPLOAD_API_CALLBACK_0001 remove =" + data);
});
});
} catch (err) {
console.error("SUB_REQUEST_UPLOAD_API_CALLBACK_0001 error: " + err);
expect().assertFail();
}
sleep(Date.now(), 20000);
console.info("-----------------------SUB_REQUEST_UPLOAD_API_CALLBACK_0001 end-----------------------");
done();
});
/**
* @tc.number SUB_REQUEST_UPLOAD_API_CALLBACK_0002
* @tc.name Test requestUploadTest type = TIMER_TYPE_REALTIME
* @tc.desc Test requestUploadTest API functionality.
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 1
*/
it('SUB_REQUEST_UPLOAD_API_CALLBACK_0002', 0, async function (done) {
console.info("-----------------------Request_test_0006 is starting-----------------------");
try {
console.info("SUB_REQUEST_UPLOAD_API_CALLBACK_0002 uploadConfig = " + JSON.stringify(uploadConfig));
let abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator();
let appContext = abilityDelegator.getAppContext();
console.info("SUB_REQUEST_UPLOAD_API_CALLBACK_0002 context = " + appContext);
request.upload(appContext, uploadConfig, (data) => {
uploadTask = data;
console.info("SUB_REQUEST_UPLOAD_API_CALLBACK_0002 progress uploadTask =" + JSON.stringify(uploadTask));
expect(uploadTask != undefined).assertEqual(true);
uploadTask.on('progress', function (data1, data2) {
console.info("SUB_REQUEST_UPLOAD_API_CALLBACK_0002 on data1 =" + data1);
console.info("SUB_REQUEST_UPLOAD_API_CALLBACK_0002 on data2 =" + data2);
});
uploadTask.off('progress', function (data1, data2) {
console.info("SUB_REQUEST_UPLOAD_API_CALLBACK_0002 off data1 =" + data1);
console.info("SUB_REQUEST_UPLOAD_API_CALLBACK_0002 off data2 =" + data2);
});
uploadTask.remove((err, data) => {
console.info("SUB_REQUEST_UPLOAD_API_CALLBACK_0002 remove =" + data);
});
});
} catch (err) {
console.error("SUB_REQUEST_UPLOAD_API_CALLBACK_0002 error: " + err);
expect().assertFail();
}
sleep(Date.now(), 20000);
console.info("-----------------------SUB_REQUEST_UPLOAD_API_CALLBACK_0002 end-----------------------");
done();
});
/*
* @tc.number : SUB_REQUEST_UPLOAD_API_PROMISE_0001
* @tc.name : Use getEntries get the value by mixing the string key
* @tc.desc : Mixed strings value can be obtained correctly
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 1
*/
it('SUB_REQUEST_UPLOAD_API_PROMISE_0001', 0, async function (done) {
try {
console.info("SUB_REQUEST_UPLOAD_API_PROMISE_0001 UploadConfig = " + JSON.stringify(uploadConfig));
request.upload(uploadConfig).then((data) => {
uploadTask = data;
console.info("SUB_REQUEST_UPLOAD_API_PROMISE_0001 uploadTask = " + uploadTask);
expect(true).assertEqual((uploadTask != undefined) || (uploadTask != "") || (uploadTask != {}));
uploadTask.on('headerReceive', (header) => {
console.info("SUB_REQUEST_UPLOAD_API_PROMISE_0001 header = " + header);
expect(true).assertEqual((header != undefined) || (header != "") || (header != {}));
});
uploadTask.off('headerReceive', (header) => {
console.info("SUB_REQUEST_UPLOAD_API_PROMISE_0001 header = " + header);
expect(true).assertEqual((header != undefined) || (header != "") || (header != {}));
});
uploadTask.remove().then((result)=>{
console.info("SUB_REQUEST_UPLOAD_API_PROMISE_0001 remove result = " + result);
expect(result).assertEqual(true);
});
});
} catch (e) {
console.error("SUB_REQUEST_UPLOAD_API_PROMISE_0001 error: " + JSON.stringify(e));
expect(e).assertFail();
}
sleep(Date.now(), 20000);
done();
});
/*
* @tc.number : SUB_REQUEST_UPLOAD_API_PROMISE_0002
* @tc.name : Use getEntries get the value by mixing the string key
* @tc.desc : Mixed strings value can be obtained correctly
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 1
*/
it('SUB_REQUEST_UPLOAD_API_PROMISE_0002', 0, async function (done) {
try {
console.info("SUB_REQUEST_UPLOAD_API_PROMISE_0002 UploadConfig = " + JSON.stringify(uploadConfig));
let abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator();
let appContext = abilityDelegator.getAppContext();
console.info("SUB_REQUEST_UPLOAD_API_PROMISE_0002 context = " + appContext);
request.upload(appContext, uploadConfig).then((data) => {
uploadTask = data;
console.info("SUB_REQUEST_UPLOAD_API_PROMISE_0002 uploadTask = " + uploadTask);
expect(data != undefined).assertEqual(true);
uploadTask.on('headerReceive', (header) => {
console.info("SUB_REQUEST_UPLOAD_API_PROMISE_0002 header = " + header);
expect(true).assertEqual((header != undefined) || (header != "") || (header != {}));
});
uploadTask.off('headerReceive', (header) => {
console.info("SUB_REQUEST_UPLOAD_API_PROMISE_0002 header = " + header);
expect(true).assertEqual((header != undefined) || (header != "") || (header != {}));
});
uploadTask.remove().then((result)=>{
console.info("SUB_REQUEST_UPLOAD_API_PROMISE_0002 remove result = " + result);
expect(result).assertEqual(true);
});
});
} catch (e) {
console.error("SUB_REQUEST_UPLOAD_API_PROMISE_0002 error: " + JSON.stringify(e));
expect(e).assertFail();
}
sleep(Date.now(), 20000);
done();
});
})
}
/*
* 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';
import * as pubFun from './publicFunction.ets'
var typeProgress = 'progress';
var typeHeaderReceive = 'headerReceive';
var typeFail = 'fail';
let uploadTask;
let file7url = 'internal://cache/test.txt';
export default function uploadRequestJSUnitTest() {
describe('UploadTest', function () {
beforeAll(function () {
console.info('beforeAll: Prerequisites at the test suite level, ' +
'which are executed before the test suite is executed.');
})
beforeEach(function () {
console.info('beforeEach: Prerequisites at the test case level,' +
' which are executed before each test case is executed.');
})
afterEach(function () {
console.info('afterEach: Test case-level clearance conditions, ' +
'which are executed after each test case is executed.');
})
afterAll(function () {
console.info('afterAll: Test suite-level cleanup condition, ' +
'which is executed after the test suite is executed');
})
/*
* @tc.number : SUB_MISC_REQUEST_API_UploadTask_0001
* @tc.name : Use getEntries get the value by mixing the string key
* @tc.desc : Mixed strings value can be obtained correctly
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 1
*/
it('SUB_MISC_REQUEST_API_UploadTask_0001', 0, async function (done) {
try {
console.info("TestUpdate before getUploadConfig");
let UploadConfig = pubFun.getUploadConfig(file7url)
console.info("TestUpdate before upload UploadConfig = " + JSON.stringify(UploadConfig));
console.info("TestUpdate before upload");
await pubFun.publicUpload(UploadConfig).then((data) => {
console.info("TestUpdate going upload uploadTask = " + data);
uploadTask = data;
expect(true).assertEqual((data != undefined) || (data != "") || (data != {}));
done();
}).catch((err) => {
console.info("SUB_MISC_REQUEST_API_UploadTask_0001 fail 1" + JSON.stringify(err));
expect(err).assertFail();
done();
})
} catch (e) {
console.info("SUB_MISC_REQUEST_API_UploadTask_0001 fail 2" + JSON.stringify(e));
expect(e).assertFail();
done();
}
})
/*
* @tc.number : SUB_MISC_REQUEST_API_OnProgress_0001
* @tc.name : Use getEntries get the value by mixing the string key
* @tc.desc : Mixed strings value can be obtained correctly
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 1
*/
it('SUB_MISC_REQUEST_API_OnProgress_0001', 0, async function (done) {
try {
pubFun.publicOnProgress(uploadTask, typeProgress);
expect(true).assertEqual(0 == 0);
done();
} catch (err) {
console.info("TestUpdate SUB_MISC_REQUEST_API_OnProgress_0001 catch err " + JSON.stringify(err));
expect(err).assertFail();
done();
}
});
/*
* @tc.number : SUB_MISC_REQUEST__OffProgress_0001
* @tc.name : Use getEntries get the value by mixing the string key
* @tc.desc : Mixed strings value can be obtained correctly
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 1
*/
it('SUB_MISC_REQUEST_OffProgress_0001', 0, async function (done) {
try {
pubFun.publicOnProgress(uploadTask, typeProgress);
expect(true).assertEqual(0 == 0);
await pubFun.publicOffProgress(uploadTask, typeProgress).then((data) => {
console.info("SUB_MISC_REQUEST_OffProgress_0001 data" + JSON.stringify(data));
expect(7).assertEqual(data["totalSize"]);
done();
}).catch((err) => {
console.info("SUB_MISC_REQUEST_OffProgress_0001 fail 2" + JSON.stringify(err));
expect(err).assertFail();
done();
})
} catch (e) {
console.info("SUB_MISC_REQUEST_OffProgress_0001 fail 3" + JSON.stringify(e));
expect(e).assertFail();
done();
}
})
/*
* @tc.number : SUB_MISC_REQUEST_OnFail_0001
* @tc.name : Use getEntries get the value by mixing the string key
* @tc.desc : Mixed strings value can be obtained correctly
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 1
*/
it('SUB_MISC_REQUEST_OnFail_0001', 0, async function (done) {
try {
await pubFun.publicOn(uploadTask, typeFail).then((data) => {
console.info("SUB_MISC_REQUEST_OnFail_0001 data " + data);
expect(5).assertEqual(data);
done();
}).catch((err) => {
console.info("SUB_MISC_REQUEST_OnFail_0001 fail 2" + JSON.stringify(err));
expect(err).assertFail();
done();
})
} catch (e) {
console.info("SUB_MISC_REQUEST_OnFail_0001 fail 3" + JSON.stringify(e));
expect(e).assertFail();
done();
}
})
/*
* @tc.number : SUB_MISC_REQUEST_OffFail_0001
* @tc.name : Use getEntries get the value by mixing the string key
* @tc.desc : Mixed strings value can be obtained correctly
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 1
*/
it('SUB_MISC_REQUEST_OffFail_0001', 0, async function (done) {
try {
await pubFun.publicOn(uploadTask, typeFail)
await pubFun.publicOff(uploadTask, typeFail).then((data) => {
console.info("SUB_MISC_REQUEST_OffFail_0001 data " + data);
expect(5).assertEqual(data);
done();
}).catch((err) => {
console.info("SUB_MISC_REQUEST_OffFail_0001 fail 2" + JSON.stringify(err));
done();
expect(err).assertFail();
})
} catch (e) {
console.info("SUB_MISC_REQUEST_OffFail_0001 fail 3" + JSON.stringify(e));
expect(e).assertFail();
done();
}
})
/*
* @tc.number : SUB_MISC_REQUEST_RmvCB_0001
* @tc.name : Use getEntries get the value by mixing the string key
* @tc.desc : Mixed strings value can be obtained correctly
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 1
*/
it('SUB_MISC_REQUEST_RmvCB_0001', 0, async function (done) {
try {
await pubFun.publicRemove(uploadTask).then((data) => {
console.info("SUB_MISC_REQUEST_RmvCB_0001 data " + data);
expect(true).assertEqual(data);
done();
}).catch((err) => {
console.info("SUB_MISC_REQUEST_RmvCB_0001 fail 2" + JSON.stringify(err));
expect(err).assertFail();
done();
})
} catch (e) {
console.info("SUB_MISC_REQUEST_RmvCB_0001 fail 3" + JSON.stringify(e));
expect(e).assertFail();
done();
}
})
})
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册