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

!1647 fileio新增close,fdatasyncSync测试用例

Merge pull request !1647 from raoxian/master
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
import { import {
fileio, fileio,
describe, it, expect, describe, it, expect, nextFileName, prepareFile, FILE_CONTENT
} from '../../Common'; } from '../../Common';
describe('fileio_close', function () { describe('fileio_close', function () {
...@@ -55,4 +55,74 @@ describe('fileio_close', function () { ...@@ -55,4 +55,74 @@ describe('fileio_close', function () {
console.log('fileio_test_close_sync_001 has failed for ' + e); console.log('fileio_test_close_sync_001 has failed for ' + e);
} }
}) })
/**
* @tc.number SUB_DF_FILEIO_CLOSE_ASYNC_0000
* @tc.name fileio_test_close_async_000
* @tc.desc Test close() interfaces
* @tc.size MEDIUM(中型)
* @tc.type Function
* @tc.level Level 0
* @tc.require
*/
it('fileio_test_close_async_000', 0, async function (done) {
let fpath = await nextFileName('fileio_test_close_async_000');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
let fd = fileio.openSync(fpath, 0o102, 0o666);
fileio.close(fd, function (err) {
expect(fileio.unlinkSync(fpath) == null).assertTrue();
done();
});
} catch (e) {
console.log('fileio_test_close_async_000 has failed for ' + e);
expect(null).assertFail();
}
})
/**
* @tc.number SUB_DF_FILEIO_CLOSE_ASYNC_0010
* @tc.name fileio_test_close_async_001
* @tc.desc Test close() interfaces
* @tc.size MEDIUM(中型)
* @tc.type Function
* @tc.level Level 0
* @tc.require
*/
it('fileio_test_close_async_001', 0, async function (done) {
let fpath = await nextFileName('fileio_test_close_async_001');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
let fd = fileio.openSync(fpath, 0o102, 0o666);
expect(await fileio.close(fd) == null).assertTrue();
expect(fileio.unlinkSync(fpath) == null).assertTrue();
done();
} catch (e) {
console.log('fileio_test_close_async_001 has failed for ' + e);
expect(null).assertFail();
}
})
/**
* @tc.number SUB_DF_FILEIO_CLOSE_ASYNC_0020
* @tc.name fileio_test_close_async_002
* @tc.desc Test close() interfaces
* @tc.size MEDIUM(中型)
* @tc.type Function
* @tc.level Level 0
* @tc.require
*/
it('fileio_test_close_async_002', 0, async function (done) {
try {
await fileio.close(-1);
expect(null).assertFail();
done();
} catch (e) {
expect(!!e).assertTrue();
console.log('fileio_test_close_async_002 has failed for ' + e);
done();
}
})
}) })
...@@ -48,7 +48,7 @@ describe('fileio_fdatasync', async function () { ...@@ -48,7 +48,7 @@ describe('fileio_fdatasync', async function () {
/** /**
* @tc.number SUB_DF_FILEIO_FDATASYNC_ASYNC_0010 * @tc.number SUB_DF_FILEIO_FDATASYNC_ASYNC_0010
* @tc.name fileio_test_fdatasync_async_001 * @tc.name fileio_test_fdatasync_async_001
* @tc.desc Test fdatasyncSync() interfaces. * @tc.desc Test fdatasync() interfaces.
* @tc.size MEDIUM * @tc.size MEDIUM
* @tc.type Function * @tc.type Function
* @tc.level Level 0 * @tc.level Level 0
...@@ -60,11 +60,17 @@ describe('fileio_fdatasync', async function () { ...@@ -60,11 +60,17 @@ describe('fileio_fdatasync', async function () {
try { try {
let fd = fileio.openSync(fpath, 0o102, 0o666); let fd = fileio.openSync(fpath, 0o102, 0o666);
fileio
fileio.write(fd, FILE_CONTENT); .fdatasync(fd)
expect(fileio.closeSync(fd) == null).assertTrue(); .then(function (err) {
expect(fileio.unlinkSync(fpath) == null).assertTrue(); expect(fileio.closeSync(fd) == null).assertTrue();
expect(fileio.unlinkSync(fpath) == null).assertTrue();
})
.catch(function (err) {
expect(null).assertFail();
});
} catch (e) { } catch (e) {
console.log('fileio_test_fdatasync_async_001 has failed for ' + e);
expect(null).assertFail(); expect(null).assertFail();
} }
}); });
...@@ -78,46 +84,61 @@ describe('fileio_fdatasync', async function () { ...@@ -78,46 +84,61 @@ describe('fileio_fdatasync', async function () {
* @tc.level Level 0 * @tc.level Level 0
* @tc.require * @tc.require
*/ */
it('fileio_test_fdatasync_async_002', 0, async function () { it('fileio_test_fdatasync_async_002', 0, async function (done) {
let fpath = await nextFileName('fileio_test_fdatasync_async_002'); let fpath = await nextFileName('fileio_test_fdatasync_async_002');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try { try {
let fd = fileio.openSync(fpath, 0o102, 0o666); let fd = -1;
fileio await fileio.fdatasync(fd);
.fdatasync(fd) expect(null).assertFail();
.then(function (err) { done()
expect(fileio.closeSync(fd) == null).assertTrue();
expect(fileio.unlinkSync(fpath) == null).assertTrue();
})
.catch(function (err) {
expect(null).assertFail();
});
} catch (e) { } catch (e) {
expect(!!e).assertTrue();
console.log('fileio_test_fdatasync_async_002 has failed for ' + e); console.log('fileio_test_fdatasync_async_002 has failed for ' + e);
expect(null).assertFail(); done();
} }
}); });
/** /**
* @tc.number SUB_DF_FILEIO_FDATASYNC_ASYNC_0030 * @tc.number SUB_DF_FILEIO_FDATASYNC_SYNC_0000
* @tc.name fileio_test_fdatasync_async_003 * @tc.name fileio_test_fdatasync_sync_000
* @tc.desc Test fdatasync() interfaces. * @tc.desc Test fdatasyncSync() interfaces.
* @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_fdatasync_async_003', 0, async function () { it('fileio_test_fdatasync_sync_000', 0, async function () {
let fpath = await nextFileName('fileio_test_fdatasync_async_003'); let fpath = await nextFileName('fileio_test_fdatasync_sync_000');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try { try {
let fd = -1; let fd = fileio.openSync(fpath, 0o102, 0o666);
await fileio.fdatasync(fd); expect(fileio.fdatasyncSync(fd) == null).assertTrue();
expect(fileio.closeSync(fd) == null).assertTrue();
expect(fileio.unlinkSync(fpath) == null).assertTrue();
} catch (e) {
console.log('fileio_test_fdatasync_sync_000 has failed for ' + e);
expect(null).assertFail();
}
});
/**
* @tc.number SUB_DF_FILEIO_FDATASYNC_SYNC_0010
* @tc.name fileio_test_fdatasync_sync_001
* @tc.desc Test fdatasyncSync() interfaces.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
* @tc.require
*/
it('fileio_test_fdatasync_sync_001', 0, async function () {
try {
fileio.fdatasyncSync(-1);
expect(null).assertFail(); expect(null).assertFail();
} catch (e) { } catch (e) {
console.log('fileio_test_fdatasync_async_003 has failed for ' + e); console.log('fileio_test_fdatasync_sync_001 has failed for ' + e);
} }
}); });
}); });
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册