提交 646aba9f 编写于 作者: Z zhuhongtao66 提交者: futurezhou

Add xts for mod_securitylabel and mod_statfs

Signed-off-by: Nzhuhongtao66 <zhuhongtao12@huawei.com>
上级 3de19324
/* /*
* Copyright (C) 2021 Huawei Device Co., Ltd. * Copyright (C) 2021-2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the 'License'); * Licensed under the Apache License, Version 2.0 (the 'License');
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
...@@ -13,8 +13,9 @@ ...@@ -13,8 +13,9 @@
* limitations under the License. * limitations under the License.
*/ */
import securityLabel from '@ohos.securityLabel'; import securityLabel from '@ohos.file.securityLabel';
import fileio from '@ohos.fileio'; import fileio from '@ohos.fileio';
import fileIO from '@ohos.file.fs';
import featureAbility from '@ohos.ability.featureAbility'; import featureAbility from '@ohos.ability.featureAbility';
import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium' import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium'
...@@ -35,5 +36,6 @@ export { ...@@ -35,5 +36,6 @@ export {
it, it,
expect, expect,
securityLabel, securityLabel,
fileio fileio,
fileIO
}; };
\ No newline at end of file
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
* limitations under the License. * limitations under the License.
*/ */
import securitylabel from './securitylabel.test.js' import security_label from './securitylabel.test.js'
export default function testsuite() { export default function testsuite() {
securitylabel() security_label()
} }
/* /*
* Copyright (C) 2021 Huawei Device Co., Ltd. * Copyright (C) 2021-2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the 'License'); * Licensed under the Apache License, Version 2.0 (the 'License');
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
...@@ -14,43 +14,43 @@ ...@@ -14,43 +14,43 @@
*/ */
import { import {
describe, it, expect, securityLabel, nextFileName, fileio describe, it, expect, securityLabel, nextFileName, fileio, fileIO
} from './Common'; } from './Common';
export default function securitylabel() { export default function security_label() {
describe('securitylabel', function () { describe('security_label', function () {
/** /**
* @tc.number SUB_DF_SECURITYLABEL_SET_SECURITY_LABEL_SYNC_0000 * @tc.number SUB_DF_SECURITYLABEL_SET_SECURITY_LABEL_SYNC_0000
* @tc.name securitylabel_test_set_security_label_sync_000 * @tc.name securitylabel_test_set_security_label_sync_000
* @tc.desc Test the setSecurityLabelSync() interface,and the getSecurityLabelSync() interface to get the data label. * @tc.desc Test the setSecurityLabelSync() interface, and the getSecurityLabelSync() interface to get the data label.
* @tc.size MEDIUM * @tc.size MEDIUM
* @tc.type Function * @tc.type Function
* @tc.level Level 0 * @tc.level Level 0
* @tc.require * @tc.require
*/ */
it('securitylabel_test_set_security_label_sync_000', 0, async function () { it('securitylabel_test_set_security_label_sync_000', 0, async function () {
try { try {
let dataLevel = ["s0","s1","s2","s3","s4"]; let dataLevel = ["s0","s1","s2","s3","s4"];
for(let i=0;i<dataLevel.length;i++){ for (let i = 0; i < dataLevel.length; i++) {
let fpath = await nextFileName("test"+dataLevel[i]+'.txt'); let fpath = await nextFileName("test" + dataLevel[i] + '.txt');
fileio.openSync(fpath, 0o102, 0o666); fileIO.openSync(fpath, fileIO.OpenMode.CREATE | fileIO.OpenMode.READ_WRITE);
securityLabel.setSecurityLabelSync(fpath, dataLevel[i]); securityLabel.setSecurityLabelSync(fpath, dataLevel[i]);
let level = securityLabel.getSecurityLabelSync(fpath); let level = securityLabel.getSecurityLabelSync(fpath);
expect(level == dataLevel[i]).assertTrue(); expect(level == dataLevel[i]).assertTrue();
fileio.unlinkSync(fpath); fileio.unlinkSync(fpath);
} }
} catch (e) { } catch (e) {
console.log('securitylabel_test_set_security_label_sync_000 has failed for ' + e); console.log('securitylabel_test_set_security_label_sync_000 has failed for ' + e.message + ', code: ' + e.code);
expect(null).assertFail(); expect(false).assertTrue();
} }
}); });
/** /**
* @tc.number SUB_DF_SECURITYLABEL_SET_SECURITY_LABEL_SYNC_0010 * @tc.number SUB_DF_SECURITYLABEL_SET_SECURITY_LABEL_SYNC_0100
* @tc.name securitylabel_test_set_security_label_sync_001 * @tc.name securitylabel_test_set_security_label_sync_001
* @tc.desc Test the setSecurityLabelSync() interface, When the dataLevel is wrong. * @tc.desc Test the setSecurityLabelSync() interface, when the dataLevel is wrong.
* @tc.size MEDIUM * @tc.size MEDIUM
* @tc.type Function * @tc.type Function
* @tc.level Level 0 * @tc.level Level 0
...@@ -58,39 +58,42 @@ describe('securitylabel', function () { ...@@ -58,39 +58,42 @@ describe('securitylabel', function () {
*/ */
it('securitylabel_test_set_security_label_sync_001', 0, async function () { it('securitylabel_test_set_security_label_sync_001', 0, async function () {
let fpath = await nextFileName("test.txt"); let fpath = await nextFileName("test.txt");
fileio.openSync(fpath, 0o102, 0o666); fileIO.openSync(fpath, fileIO.OpenMode.CREATE | fileIO.OpenMode.READ_WRITE);
try { try {
securityLabel.setSecurityLabelSync(fpath, "abc"); securityLabel.setSecurityLabelSync(fpath, "abc");
} catch (err) { expect(false).assertTrue();
console.log('securitylabel_test_set_security_label_sync_001 has failed for ' + err); } catch (e) {
expect(err.message == "Invalid Argument of dataLevelEnum").assertTrue();
fileio.unlinkSync(fpath); fileio.unlinkSync(fpath);
console.log('securitylabel_test_set_security_label_sync_001 has failed for ' + e.message + ', code: ' + e.code);
expect(e.code == 13900020 && e.message == 'Invalid argument').assertTrue();
} }
}); });
/** /**
* @tc.number SUB_DF_SECURITYLABEL_SET_SECURITY_LABEL_SYNC_0020 * @tc.number SUB_DF_SECURITYLABEL_SET_SECURITY_LABEL_SYNC_0200
* @tc.name securitylabel_test_set_security_label_sync_002 * @tc.name securitylabel_test_set_security_label_sync_002
* @tc.desc Test the setSecurityLabelSync() interface,When the path does not exist. * @tc.desc Test the setSecurityLabelSync() interface, when the path does not exist.
* @tc.size MEDIUM * @tc.size MEDIUM
* @tc.type Function * @tc.type Function
* @tc.level Level 0 * @tc.level Level 0
* @tc.require * @tc.require
*/ */
it('securitylabel_test_set_security_label_sync_002', 0, async function () { it('securitylabel_test_set_security_label_sync_002', 0, async function () {
try { try {
let result = securityLabel.setSecurityLabelSync("/data/aaa.txt", "s0"); securityLabel.setSecurityLabelSync("/data/aaa.txt", "s0");
expect(result.message == "No such file or directory").assertTrue(); expect(false).assertTrue();
} catch (err) { } catch (e) {
console.log('securitylabel_test_set_security_label_sync_002 has failed for ' + err); console.log('securitylabel_test_set_security_label_sync_002 has failed for ' + e.message + ', code: ' + e.code);
expect(e.code == 13900002 && e.message == 'No such file or directory').assertTrue();
} }
}); });
/** /**
* @tc.number SUB_DF_SECURITYLABEL_SET_SECURITY_LABEL_SYNC_0030 * @tc.number SUB_DF_SECURITYLABEL_SET_SECURITY_LABEL_SYNC_0300
* @tc.name securitylabel_test_set_security_label_sync_003 * @tc.name securitylabel_test_set_security_label_sync_003
* @tc.desc Test the setSecurityLabelSync() interface,When the dataLevel type is wrong. * @tc.desc Test the setSecurityLabelSync() interface, when the dataLevel type is wrong.
* @tc.size MEDIUM * @tc.size MEDIUM
* @tc.type Function * @tc.type Function
* @tc.level Level 0 * @tc.level Level 0
...@@ -98,20 +101,22 @@ describe('securitylabel', function () { ...@@ -98,20 +101,22 @@ describe('securitylabel', function () {
*/ */
it('securitylabel_test_set_security_label_sync_003', 0, async function () { it('securitylabel_test_set_security_label_sync_003', 0, async function () {
let fpath = await nextFileName("test.txt"); let fpath = await nextFileName("test.txt");
fileio.openSync(fpath, 0o102, 0o666); fileIO.openSync(fpath, fileIO.OpenMode.CREATE | fileIO.OpenMode.READ_WRITE);
try { try {
securityLabel.setSecurityLabelSync(fpath, 1); securityLabel.setSecurityLabelSync(fpath, 1);
} catch (err) { expect(false).assertTrue();
console.log('securitylabel_test_set_security_label_sync_003 has failed for ' + err); } catch (e) {
expect(err.message == "Invalid dataLevel").assertTrue();
fileio.unlinkSync(fpath); fileio.unlinkSync(fpath);
console.log('securitylabel_test_set_security_label_sync_003 has failed for ' + e.message + ', code: ' + e.code);
expect(e.code == 13900020 && e.message == 'Invalid argument').assertTrue();
} }
}); });
/** /**
* @tc.number SUB_DF_SECURITYLABEL_SET_SECURITY_LABEL_SYNC_0040 * @tc.number SUB_DF_SECURITYLABEL_SET_SECURITY_LABEL_SYNC_0400
* @tc.name securitylabel_test_set_security_label_sync_004 * @tc.name securitylabel_test_set_security_label_sync_004
* @tc.desc Test the setSecurityLabelSync() interface,When there is no datalevel parameter. * @tc.desc Test the setSecurityLabelSync() interface, when there is no datalevel parameter.
* @tc.size MEDIUM * @tc.size MEDIUM
* @tc.type Function * @tc.type Function
* @tc.level Level 0 * @tc.level Level 0
...@@ -119,20 +124,23 @@ describe('securitylabel', function () { ...@@ -119,20 +124,23 @@ describe('securitylabel', function () {
*/ */
it('securitylabel_test_set_security_label_sync_004', 0, async function () { it('securitylabel_test_set_security_label_sync_004', 0, async function () {
let fpath = await nextFileName("test.txt"); let fpath = await nextFileName("test.txt");
fileio.openSync(fpath, 0o102, 0o666); fileIO.openSync(fpath, fileIO.OpenMode.CREATE | fileIO.OpenMode.READ_WRITE);
try { try {
securityLabel.setSecurityLabelSync(fpath); securityLabel.setSecurityLabelSync(fpath);
} catch (err) { expect(false).assertTrue();
console.log('securitylabel_test_set_security_label_sync_004 has failed for ' + err); } catch (e) {
expect(err.message == "Number of arguments unmatched").assertTrue();
fileio.unlinkSync(fpath); fileio.unlinkSync(fpath);
console.log('securitylabel_test_set_security_label_sync_004 has failed for ' + e.message + ', code: ' + e.code);
expect(e.code == 13900020 && e.message == "Invalid argument").assertTrue();
} }
}); });
/** /**
* @tc.number SUB_DF_SECURITYLABEL_SET_SECURITY_LABEL_0000 * @tc.number SUB_DF_SECURITYLABEL_SET_SECURITY_LABEL_0000
* @tc.name securitylabel_test_set_security_label_async_000 * @tc.name securitylabel_test_set_security_label_async_000
* @tc.desc Test that the setSecurityLabel() interface callback to set the data label. Test the getSecurityLabel() interface callback to get the data label. * @tc.desc Test that the setSecurityLabel() interface callback to set the data label.
* Test the getSecurityLabel() interface callback to get the data label.
* @tc.size MEDIUM * @tc.size MEDIUM
* @tc.type Function * @tc.type Function
* @tc.level Level 0 * @tc.level Level 0
...@@ -140,26 +148,35 @@ describe('securitylabel', function () { ...@@ -140,26 +148,35 @@ describe('securitylabel', function () {
*/ */
it('securitylabel_test_set_security_label_async_000', 0, async function (done) { it('securitylabel_test_set_security_label_async_000', 0, async function (done) {
let fpath = await nextFileName('test.txt'); let fpath = await nextFileName('test.txt');
fileio.openSync(fpath, 0o102, 0o666); fileIO.openSync(fpath, fileIO.OpenMode.CREATE | fileIO.OpenMode.READ_WRITE);
try { try {
securityLabel.setSecurityLabel(fpath, 's0', function (err) { securityLabel.setSecurityLabel(fpath, 's0', (err) => {
securityLabel.getSecurityLabel(fpath, function (err, dataLevel) { if (err) {
console.log('securitylabel_test_set_security_label_async_000 error package1: ' + JSON.stringify(err));
expect(false).assertTrue();
}
securityLabel.getSecurityLabel(fpath, (err, dataLevel) => {
if (err) {
console.log('securitylabel_test_set_security_label_async_000 error package2: ' + JSON.stringify(err));
expect(false).assertTrue();
}
expect(dataLevel == 's0').assertTrue(); expect(dataLevel == 's0').assertTrue();
fileio.unlinkSync(fpath); fileio.unlinkSync(fpath);
done(); done();
}) })
}) })
} catch (e) { } catch (e) {
console.log('securitylabel_test_set_security_label_async_000 has failed for ' + e); console.log('securitylabel_test_set_security_label_async_000 has failed for ' + e.message + ', code: ' + e.code);
expect(null).assertFail(); expect(false).assertTrue();
} }
}); });
/** /**
* @tc.number SUB_DF_SECURITYLABEL_SET_SECURITY_LABEL_0010 * @tc.number SUB_DF_SECURITYLABEL_SET_SECURITY_LABEL_0100
* @tc.name securitylabel_test_set_security_label_async_001 * @tc.name securitylabel_test_set_security_label_async_001
* @tc.desc Test that the setSecurityLabel() interface callback to set the data label. Test the getSecurityLabel() interface promises to get the data label. * @tc.desc Test that the setSecurityLabel() interface callback to set the data label.
* Test the getSecurityLabel() interface promises to get the data label.
* @tc.size MEDIUM * @tc.size MEDIUM
* @tc.type Function * @tc.type Function
* @tc.level Level 0 * @tc.level Level 0
...@@ -167,25 +184,35 @@ describe('securitylabel', function () { ...@@ -167,25 +184,35 @@ describe('securitylabel', function () {
*/ */
it('securitylabel_test_set_security_label_async_001', 0, async function (done) { it('securitylabel_test_set_security_label_async_001', 0, async function (done) {
let fpath = await nextFileName('test1.txt'); let fpath = await nextFileName('test1.txt');
fileio.openSync(fpath, 0o102, 0o666); fileIO.openSync(fpath, fileIO.OpenMode.CREATE | fileIO.OpenMode.READ_WRITE);
try { try {
securityLabel.setSecurityLabel(fpath, 's1', async function (err) { securityLabel.setSecurityLabel(fpath, 's1', (err) => {
let dataLevel = await securityLabel.getSecurityLabel(fpath); if (err) {
console.log('securitylabel_test_set_security_label_async_001 error package1: ' + JSON.stringify(err));
expect(false).assertTrue();
}
securityLabel.getSecurityLabel(fpath, (err, dataLevel) => {
if (err) {
console.log('securitylabel_test_set_security_label_async_001 error package2: ' + JSON.stringify(err));
expect(false).assertTrue();
}
expect(dataLevel == 's1').assertTrue(); expect(dataLevel == 's1').assertTrue();
fileio.unlinkSync(fpath); fileio.unlinkSync(fpath);
done(); done();
});
}) })
} catch (e) { } catch (e) {
console.log('securitylabel_test_set_security_label_async_001 has failed for ' + e); console.log('securitylabel_test_set_security_label_async_001 has failed for ' + e.message + ', code: ' + e.code);
expect(null).assertFail(); expect(false).assertTrue();
} }
}); });
/** /**
* @tc.number SUB_DF_SECURITYLABEL_SET_SECURITY_LABEL_0020 * @tc.number SUB_DF_SECURITYLABEL_SET_SECURITY_LABEL_0200
* @tc.name securitylabel_test_set_security_label_async_002 * @tc.name securitylabel_test_set_security_label_async_002
* @tc.desc Test that the setSecurityLabel() interface promises to set the data label. Test the getSecurityLabel() interface callback to get the data label. * @tc.desc Test that the setSecurityLabel() interface promises to set the data label.
* Test the getSecurityLabel() interface callback to get the data label.
* @tc.size MEDIUM * @tc.size MEDIUM
* @tc.type Function * @tc.type Function
* @tc.level Level 0 * @tc.level Level 0
...@@ -193,25 +220,30 @@ describe('securitylabel', function () { ...@@ -193,25 +220,30 @@ describe('securitylabel', function () {
*/ */
it('securitylabel_test_set_security_label_async_002', 0, async function (done) { it('securitylabel_test_set_security_label_async_002', 0, async function (done) {
let fpath = await nextFileName('test2.txt'); let fpath = await nextFileName('test2.txt');
fileio.openSync(fpath, 0o102, 0o666); fileIO.openSync(fpath, fileIO.OpenMode.CREATE | fileIO.OpenMode.READ_WRITE);
try { try {
await securityLabel.setSecurityLabel(fpath, 's2'); await securityLabel.setSecurityLabel(fpath, 's2');
securityLabel.getSecurityLabel(fpath, function (err, dataLevel) { securityLabel.getSecurityLabel(fpath, (err, dataLevel) => {
if(err) {
console.log('securitylabel_test_set_security_label_async_002 error package: ' + JSON.stringify(err));
expect(false).assertTrue();
}
expect(dataLevel == 's2').assertTrue(); expect(dataLevel == 's2').assertTrue();
fileio.unlinkSync(fpath); fileio.unlinkSync(fpath);
done(); done();
}) })
} catch (e) { } catch (e) {
console.log('securitylabel_test_set_security_label_async_002 has failed for ' + e); console.log('securitylabel_test_set_security_label_async_002 has failed for ' + e.message + ', code: ' + e.code);
expect(null).assertFail(); expect(false).assertTrue();
} }
}); });
/** /**
* @tc.number SUB_DF_SECURITYLABEL_SET_SECURITY_LABEL_0030 * @tc.number SUB_DF_SECURITYLABEL_SET_SECURITY_LABEL_0300
* @tc.name securitylabel_test_set_security_label_async_003 * @tc.name securitylabel_test_set_security_label_async_003
* @tc.desc Test that the setSecurityLabel() interface promises to set the data label. Test the getSecurityLabel() interface promises to get the data label. * @tc.desc Test that the setSecurityLabel() interface promises to set the data label.
* Test the getSecurityLabel() interface promises to get the data label.
* @tc.size MEDIUM * @tc.size MEDIUM
* @tc.type Function * @tc.type Function
* @tc.level Level 0 * @tc.level Level 0
...@@ -219,7 +251,7 @@ describe('securitylabel', function () { ...@@ -219,7 +251,7 @@ describe('securitylabel', function () {
*/ */
it('securitylabel_test_set_security_label_async_003', 0, async function (done) { it('securitylabel_test_set_security_label_async_003', 0, async function (done) {
let fpath = await nextFileName('test3.txt'); let fpath = await nextFileName('test3.txt');
fileio.openSync(fpath, 0o102, 0o666); fileIO.openSync(fpath, fileIO.OpenMode.CREATE | fileIO.OpenMode.READ_WRITE);
try { try {
await securityLabel.setSecurityLabel(fpath, 's3'); await securityLabel.setSecurityLabel(fpath, 's3');
...@@ -228,15 +260,16 @@ describe('securitylabel', function () { ...@@ -228,15 +260,16 @@ describe('securitylabel', function () {
fileio.unlinkSync(fpath); fileio.unlinkSync(fpath);
done(); done();
} catch (e) { } catch (e) {
console.log('securitylabel_test_set_security_label_async_003 has failed for ' + e); console.log('securitylabel_test_set_security_label_async_003 has failed for ' + e.message + ', code: ' + e.code);
expect(null).assertFail(); expect(false).assertTrue();
} }
}); });
/** /**
* @tc.number SUB_DF_SECURITYLABEL_SET_SECURITY_LABEL_0040 * @tc.number SUB_DF_SECURITYLABEL_SET_SECURITY_LABEL_0400
* @tc.name securitylabel_test_set_security_label_async_004 * @tc.name securitylabel_test_set_security_label_async_004
* @tc.desc Test that the setSecurityLabel() interface promises to set the data label. Test the getSecurityLabel() interface promises to get the data label. * @tc.desc Test that the setSecurityLabel() interface promises to set the data label.
* Test the getSecurityLabel() interface promises to get the data label.
* @tc.size MEDIUM * @tc.size MEDIUM
* @tc.type Function * @tc.type Function
* @tc.level Level 0 * @tc.level Level 0
...@@ -244,7 +277,7 @@ describe('securitylabel', function () { ...@@ -244,7 +277,7 @@ describe('securitylabel', function () {
*/ */
it('securitylabel_test_set_security_label_async_004', 0, async function (done) { it('securitylabel_test_set_security_label_async_004', 0, async function (done) {
let fpath = await nextFileName('test4.txt'); let fpath = await nextFileName('test4.txt');
fileio.openSync(fpath, 0o102, 0o666); fileIO.openSync(fpath, fileIO.OpenMode.CREATE | fileIO.OpenMode.READ_WRITE);
try { try {
await securityLabel.setSecurityLabel(fpath, 's4'); await securityLabel.setSecurityLabel(fpath, 's4');
...@@ -253,72 +286,78 @@ describe('securitylabel', function () { ...@@ -253,72 +286,78 @@ describe('securitylabel', function () {
fileio.unlinkSync(fpath); fileio.unlinkSync(fpath);
done(); done();
} catch (e) { } catch (e) {
console.log('securitylabel_test_set_security_label_async_004 has failed for ' + e); console.log('securitylabel_test_set_security_label_async_004 has failed for ' + e.message + ', code: ' + e.code);
expect(null).assertFail(); expect(false).assertTrue();
} }
}); });
/** /**
* @tc.number SUB_DF_SECURITYLABEL_SET_SECURITY_LABEL_0050 * @tc.number SUB_DF_SECURITYLABEL_SET_SECURITY_LABEL_0500
* @tc.name securitylabel_test_set_security_label_async_005 * @tc.name securitylabel_test_set_security_label_async_005
* @tc.desc Test setSecurityLabel() interfaces,When the path type is wrong. * @tc.desc Test setSecurityLabel() interfaces, when the path type is wrong.
* @tc.size MEDIUM * @tc.size MEDIUM
* @tc.type Function * @tc.type Function
* @tc.level Level 0 * @tc.level Level 0
* @tc.require * @tc.require
*/ */
it('securitylabel_test_set_security_label_async_005', 0, async function (done) { it('securitylabel_test_set_security_label_async_005', 0, async function (done) {
try { try {
await securityLabel.setSecurityLabel(123, 's0'); await securityLabel.setSecurityLabel(123, 's0');
} catch (err) { expect(false).assertTrue();
console.log('securitylabel_test_set_security_label_async_005 has failed for ' + err); } catch (e) {
expect(err.message == "Invalid path").assertTrue(); console.log('securitylabel_test_set_security_label_async_005 has failed for ' + e.message + ', code: ' + e.code);
expect(e.code == 13900020 && e.message == "Invalid argument").assertTrue();
done(); done();
} }
}); });
/** /**
* @tc.number SUB_DF_SECURITYLABEL_SET_SECURITY_LABEL_0060 * @tc.number SUB_DF_SECURITYLABEL_SET_SECURITY_LABEL_0600
* @tc.name securitylabel_test_set_security_label_async_006 * @tc.name securitylabel_test_set_security_label_async_006
* @tc.desc Test setSecurityLabel() interfaces,return false when the path is invalid. * @tc.desc Test setSecurityLabel() interfaces, return false when the path is invalid.
* @tc.size MEDIUM * @tc.size MEDIUM
* @tc.type Function * @tc.type Function
* @tc.level Level 0 * @tc.level Level 0
* @tc.require * @tc.require
*/ */
it('securitylabel_test_set_security_label_async_006', 0, async function (done) { it('securitylabel_test_set_security_label_async_006', 0, async function (done) {
try { try {
await securityLabel.setSecurityLabel('/data/test.txt', 's0'); await securityLabel.setSecurityLabel('/data/test.txt', 's0');
} catch (err) { expect(false).assertTrue();
console.log('securitylabel_test_set_security_label_async_006 has failed for ' + err); } catch (e) {
expect(err.message == "No such file or directory").assertTrue(); console.log('securitylabel_test_set_security_label_async_006 has failed for ' + e.message + ', code: ' + e.code);
expect(e.code == 13900002 && e.message == 'No such file or directory').assertTrue();
done(); done();
} }
}); });
/** /**
* @tc.number SUB_DF_SECURITYLABEL_SET_SECURITY_LABEL_0070 * @tc.number SUB_DF_SECURITYLABEL_SET_SECURITY_LABEL_0700
* @tc.name securitylabel_test_set_security_label_async_007 * @tc.name securitylabel_test_set_security_label_async_007
* @tc.desc Test setSecurityLabel() interfaces,Throw exception when path is empty. * @tc.desc Test setSecurityLabel() interfaces. Throw exception when path is empty.
* @tc.size MEDIUM * @tc.size MEDIUM
* @tc.type Function * @tc.type Function
* @tc.level Level 0 * @tc.level Level 0
* @tc.require * @tc.require
*/ */
it('securitylabel_test_set_security_label_async_007', 0, async function (done) { it('securitylabel_test_set_security_label_async_007', 0, async function (done) {
try { try {
await securityLabel.setSecurityLabel('s0'); await securityLabel.setSecurityLabel('s0');
} catch (err) { expect(false).assertTrue();
console.log('securitylabel_test_set_security_label_async_007 has failed for ' + err); } catch (e) {
expect(err.message == "Number of arguments unmatched").assertTrue(); console.log('securitylabel_test_set_security_label_async_007 has failed for ' + e.message + ', code: ' + e.code);
expect(e.code == 13900020 && e.message == "Invalid argument").assertTrue();
done(); done();
} }
}); });
/** /**
* @tc.number SUB_DF_SECURITYLABEL_SET_SECURITY_LABEL_0080 * @tc.number SUB_DF_SECURITYLABEL_SET_SECURITY_LABEL_0800
* @tc.name securitylabel_test_set_security_label_async_008 * @tc.name securitylabel_test_set_security_label_async_008
* @tc.desc Test setSecurityLabel() interfaces,When the dataLevel type is wrong. * @tc.desc Test setSecurityLabel() interfaces, when the dataLevel type is wrong.
* @tc.size MEDIUM * @tc.size MEDIUM
* @tc.type Function * @tc.type Function
* @tc.level Level 0 * @tc.level Level 0
...@@ -326,21 +365,23 @@ describe('securitylabel', function () { ...@@ -326,21 +365,23 @@ describe('securitylabel', function () {
*/ */
it('securitylabel_test_set_security_label_async_008', 0, async function (done) { it('securitylabel_test_set_security_label_async_008', 0, async function (done) {
let fpath = await nextFileName('test5.txt'); let fpath = await nextFileName('test5.txt');
fileio.openSync(fpath, 0o102, 0o666); fileIO.openSync(fpath, fileIO.OpenMode.CREATE | fileIO.OpenMode.READ_WRITE);
try { try {
await securityLabel.setSecurityLabel(fpath, 1) await securityLabel.setSecurityLabel(fpath, 1);
} catch (err) { expect(false).assertTrue();
console.log('securitylabel_test_set_security_label_async_008 has failed for ' + err); } catch (e) {
expect(err.message == "Invalid dataLevel").assertTrue(); fileio.unlinkSync(fpath);
console.log('securitylabel_test_set_security_label_async_008 has failed for ' + e.message + ', code: ' + e.code);
expect(e.code == 13900020 && e.message == "Invalid argument").assertTrue();
done(); done();
} }
}); });
/** /**
* @tc.number SUB_DF_SECURITYLABEL_SET_SECURITY_LABEL_0090 * @tc.number SUB_DF_SECURITYLABEL_SET_SECURITY_LABEL_0900
* @tc.name securitylabel_test_set_security_label_async_009 * @tc.name securitylabel_test_set_security_label_async_009
* @tc.desc Test setSecurityLabel() interfaces,return false when the dataLevel is invalid. * @tc.desc Test setSecurityLabel() interfaces, return false when the dataLevel is invalid.
* @tc.size MEDIUM * @tc.size MEDIUM
* @tc.type Function * @tc.type Function
* @tc.level Level 0 * @tc.level Level 0
...@@ -348,21 +389,23 @@ describe('securitylabel', function () { ...@@ -348,21 +389,23 @@ describe('securitylabel', function () {
*/ */
it('securitylabel_test_set_security_label_async_009', 0, async function (done) { it('securitylabel_test_set_security_label_async_009', 0, async function (done) {
let fpath = await nextFileName('test6.txt'); let fpath = await nextFileName('test6.txt');
fileio.openSync(fpath, 0o102, 0o666); fileIO.openSync(fpath, fileIO.OpenMode.CREATE | fileIO.OpenMode.READ_WRITE);
try { try {
await securityLabel.setSecurityLabel(fpath, 'ss'); await securityLabel.setSecurityLabel(fpath, 'ss');
} catch (err) { expect(false).assertTrue();
console.log('securitylabel_test_set_security_label_async_009 has failed for ' + err); } catch (e) {
expect(err.message == "Invalid Argument of dataLevelEnum").assertTrue(); fileio.unlinkSync(fpath);
console.log('securitylabel_test_set_security_label_async_009 has failed for ' + e.message + ', code: ' + e.code);
expect(e.code == 13900020 && e.message == "Invalid argument").assertTrue();
done(); done();
} }
}); });
/** /**
* @tc.number SUB_DF_SECURITYLABEL_SET_SECURITY_LABEL_0100 * @tc.number SUB_DF_SECURITYLABEL_SET_SECURITY_LABEL_1000
* @tc.name securitylabel_test_set_security_label_async_010 * @tc.name securitylabel_test_set_security_label_async_010
* @tc.desc Test setSecurityLabel() interfaces,Throw exception when dataLevel is empty. * @tc.desc Test setSecurityLabel() interfaces. Throw exception when dataLevel is empty.
* @tc.size MEDIUM * @tc.size MEDIUM
* @tc.type Function * @tc.type Function
* @tc.level Level 0 * @tc.level Level 0
...@@ -370,22 +413,23 @@ describe('securitylabel', function () { ...@@ -370,22 +413,23 @@ describe('securitylabel', function () {
*/ */
it('securitylabel_test_set_security_label_async_010', 0, async function (done) { it('securitylabel_test_set_security_label_async_010', 0, async function (done) {
let fpath = await nextFileName('test7.txt'); let fpath = await nextFileName('test7.txt');
fileio.openSync(fpath, 0o102, 0o666); fileIO.openSync(fpath, fileIO.OpenMode.CREATE | fileIO.OpenMode.READ_WRITE);
try { try {
await securityLabel.setSecurityLabel(fpath); await securityLabel.setSecurityLabel(fpath);
} catch (err) { expect(false).assertTrue();
console.log('securitylabel_test_set_security_label_async_010 has failed for ' + err); } catch (e) {
fileio.unlinkSync(fpath); fileio.unlinkSync(fpath);
expect(err.message == "Number of arguments unmatched").assertTrue(); console.log('securitylabel_test_set_security_label_async_010 has failed for ' + e.message + ', code: ' + e.code);
expect(e.code == 13900020 && e.message == "Invalid argument").assertTrue();
done(); done();
} }
}); });
/** /**
* @tc.number SUB_DF_SECURITYLABEL_SET_SECURITY_LABEL_0110 * @tc.number SUB_DF_SECURITYLABEL_SET_SECURITY_LABEL_1100
* @tc.name securitylabel_test_set_security_label_async_011 * @tc.name securitylabel_test_set_security_label_async_011
* @tc.desc Test setSecurityLabel() interfaces,Throws an exception when passing multiple parameters. * @tc.desc Test setSecurityLabel() interfaces. Throws an exception when passing multiple parameters.
* @tc.size MEDIUM * @tc.size MEDIUM
* @tc.type Function * @tc.type Function
* @tc.level Level 0 * @tc.level Level 0
...@@ -393,158 +437,195 @@ describe('securitylabel', function () { ...@@ -393,158 +437,195 @@ describe('securitylabel', function () {
*/ */
it('securitylabel_test_set_security_label_async_011', 0, async function (done) { it('securitylabel_test_set_security_label_async_011', 0, async function (done) {
let fpath = await nextFileName('test8.txt'); let fpath = await nextFileName('test8.txt');
fileio.openSync(fpath, 0o102, 0o666); fileIO.openSync(fpath, fileIO.OpenMode.CREATE | fileIO.OpenMode.READ_WRITE);
try { try {
securityLabel.setSecurityLabel(fpath, 's0', '', function (err) { securityLabel.setSecurityLabel(fpath, 's0', '', () => {
done(); expect(false).assertTrue();
}) })
} catch (err) { } catch (e) {
console.log('securitylabel_test_set_security_label_async_011 has failed for ' + err);
fileio.unlinkSync(fpath); fileio.unlinkSync(fpath);
expect(err.message == "Number of arguments unmatched").assertTrue(); console.log('securitylabel_test_set_security_label_async_011 has failed for ' + e.message + ', code: ' + e.code);
expect(e.code == 13900020 && e.message == "Invalid argument").assertTrue();
done();
}
});
/**
* @tc.number SUB_DF_SECURITYLABEL_SET_SECURITY_LABEL_1200
* @tc.name securitylabel_test_set_security_label_async_012
* @tc.desc Test setSecurityLabel() interfaces, return false when the path is invalid.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
* @tc.require
*/
it('securitylabel_test_set_security_label_async_012', 0, async function (done) {
try {
securityLabel.setSecurityLabel('/data/test.txt', 's0', (err) => {
if (err) {
console.log(
'securitylabel_test_set_security_label_async_012 error package: {'
+ err.message + ', code: ' + err.code + '}');
expect(err.code == 13900002 && err.message == 'No such file or directory').assertTrue();
done(); done();
} }
}); });
} catch (e) {
console.log('securitylabel_test_set_security_label_async_006 has failed for ' + e.message + ', code: ' + e.code);
expect(false).assertTrue();
}
});
/** /**
* @tc.number SUB_DF_SECURITYLABEL_GET_SECURITY_LABEL_SYNC_0000 * @tc.number SUB_DF_SECURITYLABEL_GET_SECURITY_LABEL_SYNC_0000
* @tc.name securitylabel_test_get_security_label_sync_000 * @tc.name securitylabel_test_get_security_label_sync_000
* @tc.desc Test getSecurityLabelSync() interfaces,return empty when path is empty string. * @tc.desc Test getSecurityLabelSync() interfaces, return empty when path is empty string.
* @tc.size MEDIUM * @tc.size MEDIUM
* @tc.type Function * @tc.type Function
* @tc.level Level 0 * @tc.level Level 0
* @tc.require * @tc.require
*/ */
it('securitylabel_test_get_security_label_sync_000', 0, function () { it('securitylabel_test_get_security_label_sync_000', 0, function () {
try { try {
let dataLevel = securityLabel.getSecurityLabelSync(''); let dataLevel = securityLabel.getSecurityLabelSync('');
expect(dataLevel == '').assertTrue(); expect(dataLevel == '').assertTrue();
} catch (e) { } catch (e) {
console.log('securitylabel_test_get_security_label_sync_000 has failed for ' + e); console.log('securitylabel_test_get_security_label_sync_000 has failed for ' + e.message + ', code: ' + e.code);
expect(null).assertFail(); expect(false).assertTrue();
} }
}); });
/** /**
* @tc.number SUB_DF_SECURITYLABEL_GET_SECURITY_LABEL_SYNC_0010 * @tc.number SUB_DF_SECURITYLABEL_GET_SECURITY_LABEL_SYNC_0100
* @tc.name securitylabel_test_get_security_label_sync_001 * @tc.name securitylabel_test_get_security_label_sync_001
* @tc.desc Test getSecurityLabelSync() interfaces,return empty when the path is invalid. * @tc.desc Test getSecurityLabelSync() interfaces, return empty when the path is invalid.
* @tc.size MEDIUM * @tc.size MEDIUM
* @tc.type Function * @tc.type Function
* @tc.level Level 0 * @tc.level Level 0
* @tc.require * @tc.require
*/ */
it('securitylabel_test_get_security_label_sync_001', 0, function () { it('securitylabel_test_get_security_label_sync_001', 0, function () {
try { try {
let dataLevel = securityLabel.getSecurityLabelSync('/data/test.txt'); let dataLevel = securityLabel.getSecurityLabelSync('/data/test.txt');
expect(dataLevel == '').assertTrue(); expect(dataLevel == '').assertTrue();
} catch (e) { } catch (e) {
console.log('securitylabel_test_get_security_label_sync_001 has failed for ' + e); console.log('securitylabel_test_get_security_label_sync_001 has failed for ' + e.message + ', code: ' + e.code);
expect(null).assertFail(); expect(false).assertTrue();
} }
}); });
/** /**
* @tc.number SUB_DF_SECURITYLABEL_GET_SECURITY_LABEL_SYNC_0020 * @tc.number SUB_DF_SECURITYLABEL_GET_SECURITY_LABEL_SYNC_0200
* @tc.name securitylabel_test_get_security_label_sync_002 * @tc.name securitylabel_test_get_security_label_sync_002
* @tc.desc Test getSecurityLabelSync() interfaces,When there are no parameters. * @tc.desc Test getSecurityLabelSync() interfaces, when there are no parameters.
* @tc.size MEDIUM * @tc.size MEDIUM
* @tc.type Function * @tc.type Function
* @tc.level Level 0 * @tc.level Level 0
* @tc.require * @tc.require
*/ */
it('securitylabel_test_get_security_label_sync_002', 0, function () { it('securitylabel_test_get_security_label_sync_002', 0, function () {
try { try {
securityLabel.getSecurityLabelSync(); securityLabel.getSecurityLabelSync();
} catch (err) { expect(false).assertTrue();
console.log('securitylabel_test_get_security_label_sync_002 has failed for ' + err); } catch (e) {
expect(err.message == "Number of arguments unmatched").assertTrue(); console.log('securitylabel_test_get_security_label_sync_002 has failed for ' + e.message + ', code: ' + e.code);
expect(e.code == 13900020 && e.message == "Invalid argument").assertTrue();
} }
}); });
/** /**
* @tc.number SUB_DF_SECURITYLABEL_GET_SECURITY_LABEL_SYNC_0030 * @tc.number SUB_DF_SECURITYLABEL_GET_SECURITY_LABEL_SYNC_0300
* @tc.name securitylabel_test_get_security_label_sync_003 * @tc.name securitylabel_test_get_security_label_sync_003
* @tc.desc Test getSecurityLabelSync() interfaces,When the path type is wrong. * @tc.desc Test getSecurityLabelSync() interfaces, when the path type is wrong.
* @tc.size MEDIUM * @tc.size MEDIUM
* @tc.type Function * @tc.type Function
* @tc.level Level 0 * @tc.level Level 0
* @tc.require * @tc.require
*/ */
it('securitylabel_test_get_security_label_sync_003', 0, function () { it('securitylabel_test_get_security_label_sync_003', 0, function () {
try { try {
securityLabel.getSecurityLabelSync(123); securityLabel.getSecurityLabelSync(123);
} catch (err) { expect(false).assertTrue();
console.log('securitylabel_test_get_security_label_sync_003 has failed for ' + err); } catch (e) {
expect(err.message == "Invalid path").assertTrue(); console.log('securitylabel_test_get_security_label_sync_003 has failed for ' + e.message + ', code: ' + e.code);
expect(e.code == 13900020 && e.message == "Invalid argument").assertTrue();
} }
}); });
/** /**
* @tc.number SUB_DF_SECURITYLABEL_GET_SECURITY_LABEL_0000 * @tc.number SUB_DF_SECURITYLABEL_GET_SECURITY_LABEL_0000
* @tc.name securitylabel_test_get_security_label_async_000 * @tc.name securitylabel_test_get_security_label_async_000
* @tc.desc Test getSecurityLabel() interfaces,When the path type is wrong. * @tc.desc Test getSecurityLabel() interfaces, when the path type is wrong.
* @tc.size MEDIUM * @tc.size MEDIUM
* @tc.type Function * @tc.type Function
* @tc.level Level 0 * @tc.level Level 0
* @tc.require * @tc.require
*/ */
it('securitylabel_test_get_security_label_async_000', 0, async function (done) { it('securitylabel_test_get_security_label_async_000', 0, async function (done) {
try { try {
await securityLabel.getSecurityLabel(123); await securityLabel.getSecurityLabel(123);
} catch (err) { expect(false).assertTrue();
console.log('securitylabel_test_get_security_label_async_000 has failed for ' + err); } catch (e) {
expect(err.message == "Invalid path").assertTrue(); console.log('securitylabel_test_get_security_label_async_000 has failed for ' + e.message + ', code: ' + e.code);
expect(e.code == 13900020 && e.message == "Invalid argument").assertTrue();
done(); done();
} }
}); });
/** /**
* @tc.number SUB_DF_SECURITYLABEL_GET_SECURITY_LABEL_0010 * @tc.number SUB_DF_SECURITYLABEL_GET_SECURITY_LABEL_0100
* @tc.name securitylabel_test_get_security_label_async_001 * @tc.name securitylabel_test_get_security_label_async_001
* @tc.desc Test getSecurityLabel() interfaces,return empty when the path is invalid. * @tc.desc Test getSecurityLabel() interfaces, return empty when the path is invalid.
* @tc.size MEDIUM * @tc.size MEDIUM
* @tc.type Function * @tc.type Function
* @tc.level Level 0 * @tc.level Level 0
* @tc.require * @tc.require
*/ */
it('securitylabel_test_get_security_label_async_001', 0, async function (done) { it('securitylabel_test_get_security_label_async_001', 0, async function (done) {
try { try {
let dataLevel = await securityLabel.getSecurityLabel('/data/test.txt'); let dataLevel = await securityLabel.getSecurityLabel('/data/test.txt');
expect(dataLevel == '').assertTrue(); expect(dataLevel == '').assertTrue();
done(); done();
} catch (e) { } catch (e) {
console.log('securitylabel_test_get_security_label_async_001 has failed for ' + e); console.log('securitylabel_test_get_security_label_async_001 has failed for ' + e.message + ', code: ' + e.code);
expect(null).assertFail(); expect(false).assertTrue();
done();
} }
}); });
/** /**
* @tc.number SUB_DF_SECURITYLABEL_GET_SECURITY_LABEL_0020 * @tc.number SUB_DF_SECURITYLABEL_GET_SECURITY_LABEL_0200
* @tc.name securitylabel_test_get_security_label_async_002 * @tc.name securitylabel_test_get_security_label_async_002
* @tc.desc Test getSecurityLabel() interfaces,Throw exception when path is empty. * @tc.desc Test getSecurityLabel() interfaces. Throw exception when path is empty.
* @tc.size MEDIUM * @tc.size MEDIUM
* @tc.type Function * @tc.type Function
* @tc.level Level 0 * @tc.level Level 0
* @tc.require * @tc.require
*/ */
it('securitylabel_test_get_security_label_async_002', 0, async function (done) { it('securitylabel_test_get_security_label_async_002', 0, async function (done) {
try { try {
await securityLabel.getSecurityLabel(); await securityLabel.getSecurityLabel();
} catch (err) { expect(false).assertTrue();
console.log('securitylabel_test_get_security_label_async_002 has failed for ' + err); } catch (e) {
expect(err.message == "Number of arguments unmatched").assertTrue(); console.log('securitylabel_test_get_security_label_async_002 has failed for ' + e.message + ', code: ' + e.code);
expect(e.code == 13900020 && e.message == "Invalid argument").assertTrue();
done(); done();
} }
}); });
/** /**
* @tc.number SUB_DF_SECURITYLABEL_GET_SECURITY_LABEL_0030 * @tc.number SUB_DF_SECURITYLABEL_GET_SECURITY_LABEL_0300
* @tc.name securitylabel_test_get_security_label_async_003 * @tc.name securitylabel_test_get_security_label_async_003
* @tc.desc Test getSecurityLabel() interfaces,Throws an exception when passing multiple parameters. * @tc.desc Test getSecurityLabel() interfaces. Throws an exception when passing multiple parameters.
* @tc.size MEDIUM * @tc.size MEDIUM
* @tc.type Function * @tc.type Function
* @tc.level Level 0 * @tc.level Level 0
...@@ -552,15 +633,16 @@ describe('securitylabel', function () { ...@@ -552,15 +633,16 @@ describe('securitylabel', function () {
*/ */
it('securitylabel_test_get_security_label_async_003', 0, async function (done) { it('securitylabel_test_get_security_label_async_003', 0, async function (done) {
let fpath = await nextFileName('test9.txt'); let fpath = await nextFileName('test9.txt');
fileio.openSync(fpath, 0o102, 0o666); fileIO.openSync(fpath, fileIO.OpenMode.CREATE | fileIO.OpenMode.READ_WRITE);
try { try {
securityLabel.getSecurityLabel(fpath, '', function(err, dataLevel) { securityLabel.getSecurityLabel(fpath, '', () => {
done(); expect(false).assertTrue();
}); });
} catch (err) { } catch (e) {
console.log('securitylabel_test_get_security_label_async_003 has failed for ' + err);
fileio.unlinkSync(fpath); fileio.unlinkSync(fpath);
expect(err.message == "Number of arguments unmatched").assertTrue(); console.log('securitylabel_test_get_security_label_async_003 has failed for ' + e.message + ', code: ' + e.code);
expect(e.code == 13900020 && e.message == "Invalid argument").assertTrue();
done(); done();
} }
}); });
......
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
*/ */
import statfs from '@ohos.statfs'; import statfs from '@ohos.statfs';
import statvfs from '@ohos.file.statvfs'
export const FILE_CONTENT = 'hello world'; export const FILE_CONTENT = 'hello world';
...@@ -32,5 +33,6 @@ export { ...@@ -32,5 +33,6 @@ export {
afterAll, afterAll,
it, it,
expect, expect,
statfs statfs,
statvfs
}; };
\ No newline at end of file
/* /*
* Copyright (C) 2021 Huawei Device Co., Ltd. * Copyright (C) 2021-2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
...@@ -14,6 +14,8 @@ ...@@ -14,6 +14,8 @@
*/ */
import statfs_test from './statfs.test.js' import statfs_test from './statfs.test.js'
import statvfs_test from './statvfs.test.js'
export default function testsuite() { export default function testsuite() {
statfs_test() statfs_test()
statvfs_test()
} }
/*
* 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, isIntNum, statvfs} from './Common';
import featureAbility from '@ohos.ability.featureAbility';
export default function statvfs_test() {
describe('statvfs_test', function () {
/**
* @tc.number SUB_DF_STATFS_GET_FREE_SIZE_0000
* @tc.name statvfs_test_get_free_size_async_000
* @tc.desc Test getFreeSize() interfaces, when the path is a sandbox path, promise way back.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
* @tc.require
*/
it('statvfs_test_get_free_size_async_000', 0, async function (done) {
try {
let context = featureAbility.getContext();
let data = await context.getFilesDir();
let number = await statvfs.getFreeSize(data);
console.log("getFreeSize getFilesDir===>" + (number / 1024));
expect(isIntNum(number)).assertTrue();
done();
} catch (e) {
console.log('statvfs_test_get_free_size_async_000 has failed for ' + e.message + ', code: ' + e.code);
expect(false).assertTrue();
}
});
/**
* @tc.number SUB_DF_STATFS_GET_FREE_SIZE_0100
* @tc.name statvfs_test_get_free_size_async_001
* @tc.desc Test getFreeSize() interfaces, when the path is dev, callback way back.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
* @tc.require
*/
it('statvfs_test_get_free_size_async_001', 0, async function (done) {
try {
statvfs.getFreeSize("/dev", (err, number) => {
if (err) {
console.log('statvfs_test_get_free_size_async_001 error package: ' + JSON.stringify(err));
expect(false).assertTrue();
}
console.log("getFreeSizeNumber dev===>:" + (number / 1024));
expect(isIntNum(number)).assertTrue();
done();
});
} catch (e) {
console.log('statvfs_test_get_free_size_async_001 has failed for ' + e.message + ', code: ' + e.code);
expect(false).assertTrue();
}
});
/**
* @tc.number SUB_DF_STATFS_GET_FREE_SIZE_0200
* @tc.name statvfs_test_get_free_size_async_002
* @tc.desc Test getFreeSize() interfaces, when the parameter type is wrong.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
* @tc.require
*/
it('statvfs_test_get_free_size_async_002', 0, async function (done) {
try {
await statvfs.getFreeSize(1);
expect(false).assertTrue();
} catch (e) {
console.log('statvfs_test_get_free_size_async_002 has failed for ' + e.message + ', code: ' + e.code);
expect(e.code == 13900020 && e.message == "Invalid argument").assertTrue();
done();
}
});
/**
* @tc.number SUB_DF_STATFS_GET_FREE_SIZE_0300
* @tc.name statvfs_test_get_free_size_async_003
* @tc.desc Test getFreeSize() interfaces, when there are no parameters.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
* @tc.require
*/
it('statvfs_test_get_free_size_async_003', 0, async function (done) {
try {
await statvfs.getFreeSize();
expect(false).assertTrue();
} catch (e) {
console.log('statvfs_test_get_free_size_async_003 has failed for ' + e.message + ', code: ' + e.code);
expect(e.code == 13900020 && e.message == "Invalid argument").assertTrue();
done();
}
});
/**
* @tc.number SUB_DF_STATFS_GET_FREE_SIZE_0400
* @tc.name statvfs_test_get_free_size_async_004
* @tc.desc Test getFreeSize() interfaces, when the path is empty.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
* @tc.require
*/
it('statvfs_test_get_free_size_async_004', 0, async function (done) {
try {
await statvfs.getFreeSize("");
expect(false).assertTrue();
} catch (e) {
console.log('statvfs_test_get_free_size_async_004 has failed for ' + e.message + ', code: ' + e.code);
expect(e.code == 13900002 && e.message == 'No such file or directory').assertTrue();
done();
}
});
/**
* @tc.number SUB_DF_STATFS_GET_FREE_SIZE_0500
* @tc.name statvfs_test_get_free_size_async_005
* @tc.desc Test getFreeSize() interfaces, when the path is empty.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
* @tc.require
*/
it('statvfs_test_get_free_size_async_005', 0, async function (done) {
try {
statvfs.getFreeSize("", (err) => {
if (err) {
console.log(
'statvfs_test_get_free_size_async_005 error package: {' + err.message + ', code: ' + err.code + '}');
expect(err.code == 13900002 && err.message == 'No such file or directory').assertTrue();
done();
}
});
} catch (e) {
console.log('statvfs_test_get_free_size_async_005 has failed for ' + e.message + ', code: ' + e.code);
expect(false).assertTrue();
}
});
/**
* @tc.number SUB_DF_STATFS_GET_TOTAL_SIZE_0000
* @tc.name statvfs_test_get_total_size_async_000
* @tc.desc Test getTotalSize() interfaces, when the path is a sandbox path, promise way back.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
* @tc.require
*/
it('statvfs_test_get_total_size_async_000', 0, async function (done) {
try {
let context = featureAbility.getContext();
let data = await context.getFilesDir();
let number = await statvfs.getTotalSize(data);
console.log("getTotalSizeNumber GetFilesDir====>:" + (number / 1024));
expect(isIntNum(number)).assertTrue();
done();
} catch (e) {
console.log('statvfs_test_get_total_size_async_000 has failed for ' + e.message + ', code: ' + e.code);
expect(false).assertTrue();
}
});
/**
* @tc.number SUB_DF_STATFS_GET_TOTAL_SIZE_0100
* @tc.name statvfs_test_get_total_size_async_001
* @tc.desc Test getTotalSize() interfaces, when the path is dev, callback way back.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
* @tc.require
*/
it('statvfs_test_get_total_size_async_001', 0, async function (done) {
try {
statvfs.getTotalSize("/dev", (err, number) => {
if (err) {
console.log('statvfs_test_get_total_size_async_001 error package: ' + JSON.stringify(err));
expect(false).assertTrue();
}
console.log("getTotalSizeNumber dev===>:" + (number / 1024));
expect(isIntNum(number)).assertTrue();
done();
});
} catch (e) {
console.log('statvfs_test_get_total_size_async_001 has failed for ' + e.message + ', code: ' + e.code);
expect(false).assertTrue();
}
});
/**
* @tc.number SUB_DF_STATFS_GET_TOTAL_SIZE_0200
* @tc.name statvfs_test_get_total_size_async_002
* @tc.desc Test getTotalSize() interfaces, when the parameter type is wrong.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
* @tc.require
*/
it('statvfs_test_get_total_size_async_002', 0, async function (done) {
try {
await statvfs.getTotalSize(1);
expect(false).assertTrue();
} catch (e) {
console.log('statvfs_test_get_total_size_async_002 has failed for ' + e.message + ', code: ' + e.code);
expect(e.code == 13900020 && e.message == "Invalid argument").assertTrue();
done();
}
});
/**
* @tc.number SUB_DF_STATFS_GET_TOTAL_SIZE_0300
* @tc.name statvfs_test_get_total_size_async_003
* @tc.desc Test getTotalSize() interfaces, when there are no parameters.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
* @tc.require
*/
it('statvfs_test_get_total_size_async_003', 0, async function (done) {
try {
await statvfs.getTotalSize();
expect(false).assertTrue();
} catch (e) {
console.log('statvfs_test_get_total_size_async_003 has failed for ' + e.message + ', code: ' + e.code);
expect(e.code == 13900020 && e.message == "Invalid argument").assertTrue();
done();
}
});
/**
* @tc.number SUB_DF_STATFS_GET_TOTAL_SIZE_0400
* @tc.name statvfs_test_get_total_size_async_004
* @tc.desc Test getTotalSize() interfaces, when the path is empty.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
* @tc.require
*/
it('statvfs_test_get_total_size_async_004', 0, async function (done) {
try {
await statvfs.getTotalSize("");
expect(false).assertTrue();
} catch (e) {
console.log('statvfs_test_get_total_size_async_004 has failed for ' + e.message + ', code: ' + e.code);
expect(e.code == 13900002 && e.message == 'No such file or directory').assertTrue();
done();
}
});
/**
* @tc.number SUB_DF_STATFS_GET_TOTAL_SIZE_0500
* @tc.name statvfs_test_get_total_size_async_005
* @tc.desc Test getTotalSize() interfaces, when the path is empty.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
* @tc.require
*/
it('statvfs_test_get_total_size_async_005', 0, async function (done) {
try {
statvfs.getTotalSize("", (err) => {
if (err) {
console.log(
'statvfs_test_get_total_size_async_005 error package: {' + err.message + ', code: ' + err.code + '}');
expect(err.code == 13900002 && err.message == 'No such file or directory').assertTrue();
done();
}
});
} catch (e) {
console.log('statvfs_test_get_total_size_async_004 has failed for ' + e.message + ', code: ' + e.code);
expect(false).assertTrue();
}
});
});
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册