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

!3307 update access.test.js

Merge pull request !3307 from raoxian/master
...@@ -25,7 +25,7 @@ describe('fileio_access', function () { ...@@ -25,7 +25,7 @@ describe('fileio_access', function () {
* @tc.name fileio_test_access_sync_000 * @tc.name fileio_test_access_sync_000
* @tc.desc Test accessSync() interface. * @tc.desc Test accessSync() interface.
* This interface shall work properly in normal case * This interface shall work properly in normal case
* @tc.size MEDIUM(中型) * @tc.size MEDIUM
* @tc.type Function * @tc.type Function
* @tc.level Level 0 * @tc.level Level 0
* @tc.require * @tc.require
...@@ -35,20 +35,20 @@ describe('fileio_access', function () { ...@@ -35,20 +35,20 @@ describe('fileio_access', function () {
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try { try {
expect(fileio.accessSync(fpath) == null).assertTrue(); fileio.accessSync(fpath);
expect(fileio.unlinkSync(fpath) == null).assertTrue(); fileio.unlinkSync(fpath);
} catch (e) { } catch (err) {
console.log('fileio_test_access_sync_000 has failed for ' + e); console.info('fileio_test_access_sync_000 has failed for ' + err);
expect(null).assertFail(); expect(null).assertFail();
} }
}); });
/** /**
* @tc.number SUB_DF_FILEIO_ACCESSSYNC_0010 * @tc.number SUB_DF_FILEIO_ACCESSSYNC_0100
* @tc.name fileio_test_access_sync_001 * @tc.name fileio_test_access_sync_001
* @tc.desc Test accessSync() interface. * @tc.desc Test accessSync() interface.
* This interface shall throw an exception when the fpath is not given * Test that the current process has write permission.
* @tc.size MEDIUM(中型) * @tc.size MEDIUM
* @tc.type Function * @tc.type Function
* @tc.level Level 0 * @tc.level Level 0
* @tc.require * @tc.require
...@@ -58,20 +58,20 @@ describe('fileio_access', function () { ...@@ -58,20 +58,20 @@ describe('fileio_access', function () {
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try { try {
expect(fileio.accessSync(fpath, 0x2) == null).assertTrue(); fileio.accessSync(fpath, 2);
expect(fileio.unlinkSync(fpath) == null).assertTrue(); fileio.unlinkSync(fpath);
} catch (e) { } catch (err) {
console.log('fileio_test_access_sync_001' + e); console.info('fileio_test_access_sync_001 has failed for ' + err);
expect(null).assertFail(); expect(null).assertFail();
} }
}); });
/** /**
* @tc.number SUB_DF_FILEIO_ACCESSSYNC_0020 * @tc.number SUB_DF_FILEIO_ACCESSSYNC_0200
* @tc.name fileio_test_access_sync_002 * @tc.name fileio_test_access_sync_002
* @tc.desc Test accessSync() interface. * @tc.desc Test accessSync() interface.
* This interface shall throw an exception when the fpath is not given * Test that the current process has read permission.
* @tc.size MEDIUM(中型) * @tc.size MEDIUM
* @tc.type Function * @tc.type Function
* @tc.level Level 0 * @tc.level Level 0
* @tc.require * @tc.require
...@@ -81,20 +81,20 @@ describe('fileio_access', function () { ...@@ -81,20 +81,20 @@ describe('fileio_access', function () {
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try { try {
expect(fileio.accessSync(fpath, 0x4) == null).assertTrue(); fileio.accessSync(fpath, 4);
expect(fileio.unlinkSync(fpath) == null).assertTrue(); fileio.unlinkSync(fpath);
} catch (e) { } catch (err) {
console.log('fileio_test_access_sync_002' + e); console.info('fileio_test_access_sync_002 has failed for ' + err);
expect(null).assertFail(); expect(null).assertFail();
} }
}); });
/** /**
* @tc.number SUB_DF_FILEIO_ACCESSSYNC_0030 * @tc.number SUB_DF_FILEIO_ACCESSSYNC_0300
* @tc.name fileio_test_access_sync_003 * @tc.name fileio_test_access_sync_003
* @tc.desc Test accessSync() interface. * @tc.desc Test accessSync() interface.
* This interface shall throw an exception when the fpath is not given. * Test that the current process has read and write permissions.
* @tc.size MEDIUM(中型) * @tc.size MEDIUM
* @tc.type Function * @tc.type Function
* @tc.level Level 0 * @tc.level Level 0
* @tc.require * @tc.require
...@@ -104,32 +104,55 @@ describe('fileio_access', function () { ...@@ -104,32 +104,55 @@ describe('fileio_access', function () {
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try { try {
expect(fileio.accessSync(fpath, 0x2 | 0x4) == null).assertTrue(); fileio.accessSync(fpath, 2 | 4);
expect(fileio.unlinkSync(fpath) == null).assertTrue(); fileio.unlinkSync(fpath);
} catch (e) { } catch (err) {
console.log('fileio_test_access_sync_003' + e); console.info('fileio_test_access_sync_003 has failed for ' + err);
expect(null).assertFail(); expect(null).assertFail();
} }
}); });
/** /**
* @tc.number SUB_DF_FILEIO_ACCESSSYNC_0040 * @tc.number SUB_DF_FILEIO_ACCESSSYNC_0400
* @tc.name fileio_test_access_sync_004 * @tc.name fileio_test_access_sync_004
* @tc.desc Test accessSync() interface. * @tc.desc Test accessSync() interface.
* This interface shall throw an exception when the fpath is not given * Test that the current process has executable permissions.
* @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('fileio_test_access_sync_004', 0, async function () { it('fileio_test_access_sync_004', 0, async function () {
let fpath = await nextFileName('fileIOTest'); let fpath = await nextFileName('fileio_test_access_sync_004');
fileio.openSync(fpath, 0o102, 0o777);
try { try {
fileio.accessSync(fpath); fileio.accessSync(fpath, 1);
fileio.unlinkSync(fpath);
} catch (err) {
console.info('fileio_test_access_sync_004 has failed for ' + err);
expect(null).assertFail(); expect(null).assertFail();
} catch (e) { }
console.log('fileio_test_access_sync_004' + e); });
/**
* @tc.number SUB_DF_FILEIO_ACCESSSYNC_0500
* @tc.name fileio_test_access_sync_005
* @tc.desc Test accessSync() interface.
* The test file is not exist.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
* @tc.require
*/
it('fileio_test_access_sync_005', 0, async function () {
let fpath = await nextFileName('fileio_test_access_sync_005');
try {
fileio.accessSync(fpath);
} catch (err) {
console.info('fileio_test_access_sync_005 has failed for ' + err);
expect(err.message == 'No such file or directory').assertTrue();
} }
}); });
...@@ -137,8 +160,8 @@ describe('fileio_access', function () { ...@@ -137,8 +160,8 @@ describe('fileio_access', function () {
* @tc.number SUB_DF_FILEIO_ACCESSASYNC_0000 * @tc.number SUB_DF_FILEIO_ACCESSASYNC_0000
* @tc.name fileio_test_access_async_000 * @tc.name fileio_test_access_async_000
* @tc.desc Test accessAsync() interface. * @tc.desc Test accessAsync() interface.
* This interface shall throw an exception when the fpath is not given * This interface shall work properly in normal case.
* @tc.size MEDIUM(中型) * @tc.size MEDIUM
* @tc.type Function * @tc.type Function
* @tc.level Level 0 * @tc.level Level 0
* @tc.require * @tc.require
...@@ -149,20 +172,20 @@ describe('fileio_access', function () { ...@@ -149,20 +172,20 @@ describe('fileio_access', function () {
try { try {
await fileio.access(fpath); await fileio.access(fpath);
expect(fileio.unlinkSync(fpath) == null).assertTrue(); fileio.unlinkSync(fpath);
done(); done();
} catch (error) { } catch (err) {
console.log('fileio_test_access_async_000 has failed for ' + error); console.info('fileio_test_access_async_000 has failed for ' + err);
expect(null).assertFail(); expect(null).assertFail();
} }
}); });
/** /**
* @tc.number SUB_DF_FILEIO_ACCESSASYNC_0010 * @tc.number SUB_DF_FILEIO_ACCESSASYNC_0100
* @tc.name fileio_test_access_async_001 * @tc.name fileio_test_access_async_001
* @tc.desc Test accessAsync() interface. * @tc.desc Test accessAsync() interface.
* This interface shall throw an exception when the fpath is not given * Use promise to test that the current process has read permission. Async method reads data from file.
* @tc.size MEDIUM(中型) * @tc.size MEDIUM
* @tc.type Function * @tc.type Function
* @tc.level Level 0 * @tc.level Level 0
* @tc.require * @tc.require
...@@ -172,27 +195,25 @@ describe('fileio_access', function () { ...@@ -172,27 +195,25 @@ describe('fileio_access', function () {
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try { try {
expect(await fileio.access(fpath, 4) == null).assertTrue(); await fileio.access(fpath, 4);
let fd = fileio.openSync(fpath); let fd = fileio.openSync(fpath);
expect(isIntNum(fd)).assertTrue(); expect(isIntNum(fd)).assertTrue();
expect( expect((await fileio.read(fd, new ArrayBuffer(4096))) != null).assertTrue();
(await fileio.read(fd, new ArrayBuffer(4096))) != null fileio.closeSync(fd);
).assertTrue(); fileio.unlinkSync(fpath);
expect(fileio.closeSync(fd) == null).assertTrue();
expect(fileio.unlinkSync(fpath) == null).assertTrue();
done(); done();
} catch (error) { } catch (err) {
console.log('fileio_test_access_async_001 has failed for ' + error); console.info('fileio_test_access_async_001 has failed for ' + err);
expect(null).assertFail(); expect(null).assertFail();
} }
}); });
/** /**
* @tc.number SUB_DF_FILEIO_ACCESSASYNC_0020 * @tc.number SUB_DF_FILEIO_ACCESSASYNC_0200
* @tc.name fileio_test_access_async_002 * @tc.name fileio_test_access_async_002
* @tc.desc Test accessAsync() interface. * @tc.desc Test accessAsync() interface.
* This interface shall throw an exception when the fpath is not given * Test file exists.
* @tc.size MEDIUM(中型) * @tc.size MEDIUM
* @tc.type Function * @tc.type Function
* @tc.level Level 0 * @tc.level Level 0
* @tc.require * @tc.require
...@@ -203,21 +224,21 @@ describe('fileio_access', function () { ...@@ -203,21 +224,21 @@ describe('fileio_access', function () {
try { try {
fileio.access(fpath, function (error) { fileio.access(fpath, function (error) {
expect(fileio.unlinkSync(fpath) == null).assertTrue(); fileio.unlinkSync(fpath);
done(); done();
}); });
} catch (error) { } catch (err) {
console.log('fileio_test_access_async_002 has failed for ' + error); console.info('fileio_test_access_async_002 has failed for ' + err);
expect(null).assertFail(); expect(null).assertFail();
} }
}); });
/** /**
* @tc.number SUB_DF_FILEIO_ACCESSASYNC_0030 * @tc.number SUB_DF_FILEIO_ACCESSASYNC_0300
* @tc.name fileio_test_access_async_003 * @tc.name fileio_test_access_async_003
* @tc.desc Test accessAsync() interface. * @tc.desc Test accessAsync() interface.
* This interface shall throw an exception when the fpath is not given * Use callback to test that the current process has read permission. Async method reads data from file.
* @tc.size MEDIUM(中型) * @tc.size MEDIUM
* @tc.type Function * @tc.type Function
* @tc.level Level 0 * @tc.level Level 0
* @tc.require * @tc.require
...@@ -230,46 +251,85 @@ describe('fileio_access', function () { ...@@ -230,46 +251,85 @@ describe('fileio_access', function () {
fileio.access(fpath, 4, async function (error) { fileio.access(fpath, 4, async function (error) {
let fd = fileio.openSync(fpath); let fd = fileio.openSync(fpath);
expect(isIntNum(fd)).assertTrue(); expect(isIntNum(fd)).assertTrue();
expect( expect((await fileio.read(fd, new ArrayBuffer(4096))) != null).assertTrue();
(await fileio.read(fd, new ArrayBuffer(4096))) != null fileio.closeSync(fd);
).assertTrue(); fileio.unlinkSync(fpath);
expect(fileio.closeSync(fd) == null).assertTrue();
expect(fileio.unlinkSync(fpath) == null).assertTrue();
}); });
done(); done();
} catch (error) { } catch (err) {
console.log('fileio_test_access_async_003 has failed for ' + error); console.info('fileio_test_access_async_003 has failed for ' + err);
expect(null).assertFail(); expect(null).assertFail();
} }
}); });
/** /**
* @tc.number SUB_DF_FILEIO_ACCESSASYNC_0040 * @tc.number SUB_DF_FILEIO_ACCESSASYNC_0400
* @tc.name fileio_test_access_async_004 * @tc.name fileio_test_access_async_004
* @tc.desc Test accessAsync() interface. * @tc.desc Test accessAsync() interface.
* This interface shall throw an exception when the fpath is not given. * Use promises to test that the current process has executable permissions.
* @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('fileio_test_access_async_004', 0, async function (done) { it('fileio_test_access_async_004', 0, async function (done) {
let fpath = await nextFileName('fileio_test_access_async_004'); let fpath = await nextFileName('fileio_test_access_async_004');
fileio.openSync(fpath, 0o102, 0o777);
try { try {
fileio await fileio.access(fpath, 1);
.access(fpath) fileio.unlinkSync(fpath);
.then(function (err) { done();
expect(null).assertFail(); } catch (err) {
done(); console.info('fileio_test_access_async_004 has failed for ' + err);
})
.catch(function (e) {
expect(!!e).assertTrue();
done();
});
} catch (e) {
console.log('fileio_test_access_async_004 has failed for ' + e);
expect(null).assertFail(); expect(null).assertFail();
} }
}); });
/**
* @tc.number SUB_DF_FILEIO_ACCESSASYNC_0500
* @tc.name fileio_test_access_async_005
* @tc.desc Test accessAsync() interface.
* Use callback to test that the current process has write permission.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
* @tc.require
*/
it('fileio_test_access_async_005', 0, async function (done) {
let fpath = await nextFileName('fileio_test_access_async_005');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
fileio.access(fpath, 2, function (error) {
fileio.unlinkSync(fpath);
done();
});
} catch (err) {
console.info('fileio_test_access_async_005 has failed for ' + err);
expect(null).assertFail();
}
});
/**
* @tc.number SUB_DF_FILEIO_ACCESSASYNC_0600
* @tc.name fileio_test_access_async_006
* @tc.desc Test accessAsync() interface.
* Async test file does not exist.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
* @tc.require
*/
it('fileio_test_access_async_006', 0, async function (done) {
let fpath = await nextFileName('fileio_test_access_async_006');
try {
await fileio.access(fpath);
} catch (err) {
console.info('fileio_test_access_async_006 has failed for ' + err);
expect(err.message == 'No such file or directory').assertTrue();
done();
}
});
}); });
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册