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

!7051 Modified XTS for open and truncate interface

Merge pull request !7051 from futurezhou/open
...@@ -16,15 +16,16 @@ ...@@ -16,15 +16,16 @@
import { import {
fileio, fileIO, FILE_CONTENT, prepareFile, nextFileName, isIntNum, fileio, fileIO, FILE_CONTENT, prepareFile, nextFileName, isIntNum,
describe, it, expect, describe, it, expect,
} from '../Common'; } from '../Common';
export default function fileIOOpen() { export default function fileIOOpen() {
describe('fileIO_fs_open', function () { describe('fileIO_fs_open', function () {
/** /**
* @tc.number SUB_DF_FILEIO_OPEN_SYNC_0000 * @tc.number SUB_DF_FILEIO_OPEN_SYNC_0000
* @tc.name fileIO_test_open_sync_000 * @tc.name fileIO_test_open_sync_000
* @tc.desc Test openSync() interfaces. mode=0o0. * @tc.desc Test openSync() interfaces. mode=0o0.
* Open the file in read-only mode, verifying the file is readable.
* @tc.size MEDIUM * @tc.size MEDIUM
* @tc.type Functoin * @tc.type Functoin
* @tc.level Level 0 * @tc.level Level 0
...@@ -51,6 +52,7 @@ import { ...@@ -51,6 +52,7 @@ import {
* @tc.number SUB_DF_FILEIO_OPEN_SYNC_0100 * @tc.number SUB_DF_FILEIO_OPEN_SYNC_0100
* @tc.name fileIO_test_open_sync_001 * @tc.name fileIO_test_open_sync_001
* @tc.desc Test openSync() interfaces. mode=0o1. * @tc.desc Test openSync() interfaces. mode=0o1.
* Open the file in write-only mode, verifying the file is writable.
* @tc.size MEDIUM * @tc.size MEDIUM
* @tc.type Functoin * @tc.type Functoin
* @tc.level Level 0 * @tc.level Level 0
...@@ -63,9 +65,8 @@ import { ...@@ -63,9 +65,8 @@ import {
try { try {
let file = fileIO.openSync(fpath, fileIO.OpenMode.WRITE_ONLY); let file = fileIO.openSync(fpath, fileIO.OpenMode.WRITE_ONLY);
expect(isIntNum(file.fd)).assertTrue(); expect(isIntNum(file.fd)).assertTrue();
let length = 20; let num = fileIO.writeSync(file.fd, FILE_CONTENT);
let num = fileIO.writeSync(file.fd, new ArrayBuffer(length)); expect(num == FILE_CONTENT.length).assertTrue();
expect(num == length).assertTrue();
fileio.closeSync(file.fd); fileio.closeSync(file.fd);
fileio.unlinkSync(fpath); fileio.unlinkSync(fpath);
} catch (e) { } catch (e) {
...@@ -78,6 +79,7 @@ import { ...@@ -78,6 +79,7 @@ import {
* @tc.number SUB_DF_FILEIO_OPEN_SYNC_0200 * @tc.number SUB_DF_FILEIO_OPEN_SYNC_0200
* @tc.name fileIO_test_open_sync_002 * @tc.name fileIO_test_open_sync_002
* @tc.desc Test openSync() interfaces. mode=0o2. * @tc.desc Test openSync() interfaces. mode=0o2.
* Open the file in read-write mode, verifying the file is readable and writable.
* @tc.size MEDIUM * @tc.size MEDIUM
* @tc.type Functoin * @tc.type Functoin
* @tc.level Level 0 * @tc.level Level 0
...@@ -106,7 +108,7 @@ import { ...@@ -106,7 +108,7 @@ import {
/** /**
* @tc.number SUB_DF_FILEIO_OPEN_SYNC_0300 * @tc.number SUB_DF_FILEIO_OPEN_SYNC_0300
* @tc.name fileIO_test_open_sync_003 * @tc.name fileIO_test_open_sync_003
* @tc.desc Test openSync() interfaces. Missing Parameter. * @tc.desc Test openSync() interfaces. Missing parameters.
* @tc.size MEDIUM * @tc.size MEDIUM
* @tc.type Functoin * @tc.type Functoin
* @tc.level Level 0 * @tc.level Level 0
...@@ -118,7 +120,7 @@ import { ...@@ -118,7 +120,7 @@ import {
expect(false).assertTrue(); expect(false).assertTrue();
} catch (e) { } catch (e) {
console.log('fileIO_test_open_sync_003 has failed for ' + e.message + ', code: ' + e.code); console.log('fileIO_test_open_sync_003 has failed for ' + e.message + ', code: ' + e.code);
expect(e.code == 13900020 && e.message == 'Invalid argument').assertTrue; expect(e.code == 13900020 && e.message == 'Invalid argument').assertTrue();
} }
}); });
...@@ -126,6 +128,7 @@ import { ...@@ -126,6 +128,7 @@ import {
* @tc.number SUB_DF_FILEIO_OPEN_SYNC_0400 * @tc.number SUB_DF_FILEIO_OPEN_SYNC_0400
* @tc.name fileIO_test_open_sync_004 * @tc.name fileIO_test_open_sync_004
* @tc.desc Test openSync() interfaces. mode=0o102. * @tc.desc Test openSync() interfaces. mode=0o102.
* If the path point to the file which does not exist, the file can be created.
* @tc.size MEDIUM * @tc.size MEDIUM
* @tc.type Functoin * @tc.type Functoin
* @tc.level Level 0 * @tc.level Level 0
...@@ -149,7 +152,7 @@ import { ...@@ -149,7 +152,7 @@ import {
* @tc.number SUB_DF_FILEIO_OPEN_SYNC_0500 * @tc.number SUB_DF_FILEIO_OPEN_SYNC_0500
* @tc.name fileIO_test_open_sync_005 * @tc.name fileIO_test_open_sync_005
* @tc.desc Test openSync() interfaces. mode=0o1002. * @tc.desc Test openSync() interfaces. mode=0o1002.
* If the file exists and the file is opened for write-only or read-write, trim its length to zero. * If the file exists and the file is opened for read-write, trim its length to zero.
* @tc.size MEDIUM * @tc.size MEDIUM
* @tc.type Functoin * @tc.type Functoin
* @tc.level Level 0 * @tc.level Level 0
...@@ -206,6 +209,7 @@ import { ...@@ -206,6 +209,7 @@ import {
* @tc.number SUB_DF_FILEIO_OPEN_SYNC_0700 * @tc.number SUB_DF_FILEIO_OPEN_SYNC_0700
* @tc.name fileIO_test_open_sync_007 * @tc.name fileIO_test_open_sync_007
* @tc.desc Test openSync() interfaces. mode=0o4002. * @tc.desc Test openSync() interfaces. mode=0o4002.
* If the file is a special file, the opening and subsequent IOs perform non-blocking operations.
* @tc.size MEDIUM * @tc.size MEDIUM
* @tc.type Functoin * @tc.type Functoin
* @tc.level Level 0 * @tc.level Level 0
...@@ -230,6 +234,7 @@ import { ...@@ -230,6 +234,7 @@ import {
* @tc.number SUB_DF_FILEIO_OPEN_SYNC_0800 * @tc.number SUB_DF_FILEIO_OPEN_SYNC_0800
* @tc.name fileIO_test_open_sync_008 * @tc.name fileIO_test_open_sync_008
* @tc.desc Test openSync() interfaces. mode=0o200000. * @tc.desc Test openSync() interfaces. mode=0o200000.
* The path points to a directory.
* @tc.size MEDIUM * @tc.size MEDIUM
* @tc.type Functoin * @tc.type Functoin
* @tc.level Level 0 * @tc.level Level 0
...@@ -252,7 +257,8 @@ import { ...@@ -252,7 +257,8 @@ import {
/** /**
* @tc.number SUB_DF_FILEIO_OPEN_SYNC_0900 * @tc.number SUB_DF_FILEIO_OPEN_SYNC_0900
* @tc.name fileIO_test_open_sync_009 * @tc.name fileIO_test_open_sync_009
* @tc.desc Test openSync() interfaces. mode=0o200000. Not a directory. * @tc.desc Test openSync() interfaces. mode=0o200000.
* The path does not a directory, throw error.
* @tc.size MEDIUM * @tc.size MEDIUM
* @tc.type Functoin * @tc.type Functoin
* @tc.level Level 0 * @tc.level Level 0
...@@ -266,9 +272,9 @@ import { ...@@ -266,9 +272,9 @@ import {
fileIO.openSync(fpath, fileIO.OpenMode.DIR); fileIO.openSync(fpath, fileIO.OpenMode.DIR);
expect(false).assertTrue(); expect(false).assertTrue();
} catch (e) { } catch (e) {
console.log('fileIO_test_open_sync_009 has failed for ' + e.message + ', code: ' + e.code);
expect(e.code == 13900002 && e.message == 'No such file or directory').assertTrue;
fileio.unlinkSync(fpath); fileio.unlinkSync(fpath);
console.log('fileIO_test_open_sync_009 has failed for ' + e.message + ', code: ' + e.code);
expect(e.code == 13900018 && e.message == 'Not a directory').assertTrue();
} }
}); });
...@@ -276,6 +282,7 @@ import { ...@@ -276,6 +282,7 @@ import {
* @tc.number SUB_DF_FILEIO_OPEN_SYNC_1000 * @tc.number SUB_DF_FILEIO_OPEN_SYNC_1000
* @tc.name fileIO_test_open_sync_010 * @tc.name fileIO_test_open_sync_010
* @tc.desc Test openSync() interfaces. mode=0o400002. * @tc.desc Test openSync() interfaces. mode=0o400002.
* The path does not point to a symbolic link.
* @tc.size MEDIUM * @tc.size MEDIUM
* @tc.type Functoin * @tc.type Functoin
* @tc.level Level 0 * @tc.level Level 0
...@@ -299,7 +306,8 @@ import { ...@@ -299,7 +306,8 @@ import {
/** /**
* @tc.number SUB_DF_FILEIO_OPEN_SYNC_1100 * @tc.number SUB_DF_FILEIO_OPEN_SYNC_1100
* @tc.name fileIO_test_open_sync_011 * @tc.name fileIO_test_open_sync_011
* @tc.desc Test openSync() interfaces. mode=0o400002. Shouldn't be Symbolic link. * @tc.desc Test openSync() interfaces. mode=0o400002.
* The path points to a symbolic link, throw error.
* @tc.size MEDIUM * @tc.size MEDIUM
* @tc.type Functoin * @tc.type Functoin
* @tc.level Level 0 * @tc.level Level 0
...@@ -315,10 +323,10 @@ import { ...@@ -315,10 +323,10 @@ import {
fileIO.openSync(ffpath, fileIO.OpenMode.NOFOLLOW | fileIO.OpenMode.READ_WRITE); fileIO.openSync(ffpath, fileIO.OpenMode.NOFOLLOW | fileIO.OpenMode.READ_WRITE);
expect(false).assertTrue(); expect(false).assertTrue();
} catch (e) { } catch (e) {
console.log('fileIO_test_open_sync_011 has failed for ' + e.message + ', code: ' + e.code);
expect(e.code == 13900033 && e.message == 'Too many symbolic links encountered').assertTrue;
fileio.unlinkSync(fpath); fileio.unlinkSync(fpath);
fileio.unlinkSync(ffpath); fileio.unlinkSync(ffpath);
console.log('fileIO_test_open_sync_011 has failed for ' + e.message + ', code: ' + e.code);
expect(e.code == 13900033 && e.message == 'Too many symbolic links encountered').assertTrue();
} }
}); });
...@@ -326,6 +334,7 @@ import { ...@@ -326,6 +334,7 @@ import {
* @tc.number SUB_DF_FILEIO_OPEN_SYNC_1200 * @tc.number SUB_DF_FILEIO_OPEN_SYNC_1200
* @tc.name fileIO_test_open_sync_012 * @tc.name fileIO_test_open_sync_012
* @tc.desc Test openSync() interfaces. mode=0o4010002. * @tc.desc Test openSync() interfaces. mode=0o4010002.
* Open the file in the way of synchronous IO.
* @tc.size MEDIUM * @tc.size MEDIUM
* @tc.type Functoin * @tc.type Functoin
* @tc.level Level 0 * @tc.level Level 0
...@@ -346,10 +355,32 @@ import { ...@@ -346,10 +355,32 @@ import {
} }
}); });
/**
* @tc.number SUB_DF_FILEIO_OPEN_SYNC_1300
* @tc.name fileIO_test_open_sync_013
* @tc.desc Test openSync() interfaces. Invalid path.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it('fileIO_test_open_sync_013', 0, async function (done) {
try {
fileIO.openSync(-1, fileIO.OpenMode.READ_WRITE);
expect(false).assertTrue();
} catch (e) {
console.log('fileIO_test_open_sync_013 has failed for ' + e.message + ', code: ' + e.code);
expect(e.code == 13900020 && e.message == 'Invalid argument').assertTrue();
done();
}
});
/** /**
* @tc.number SUB_DF_FILEIO_OPEN_ASYNC_0000 * @tc.number SUB_DF_FILEIO_OPEN_ASYNC_0000
* @tc.name fileIO_test_open_async_000 * @tc.name fileIO_test_open_async_000
* @tc.desc Test open() interfaces. mode=0o0. * @tc.desc Test open() interfaces. mode=0o0. Promise.
* Open the file in read-only mode, verifying the file is readable.
* @tc.size MEDIUM * @tc.size MEDIUM
* @tc.type Functoin * @tc.type Functoin
* @tc.level Level 0 * @tc.level Level 0
...@@ -360,15 +391,15 @@ import { ...@@ -360,15 +391,15 @@ import {
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try { try {
fileIO.open(fpath, fileIO.OpenMode.READ_ONLY, function (err, file) { let file = await fileIO.open(fpath, fileIO.OpenMode.READ_ONLY);
expect(isIntNum(file.fd)).assertTrue();
fileIO.read(file.fd, new ArrayBuffer(4096)) fileIO.read(file.fd, new ArrayBuffer(4096))
.then(function (res) { .then((res) => {
expect(res == FILE_CONTENT.length).assertTrue(); expect(res == FILE_CONTENT.length).assertTrue();
fileio.closeSync(file.fd); fileio.closeSync(file.fd);
fileio.unlinkSync(fpath); fileio.unlinkSync(fpath);
done(); done();
}); });
});
} catch (e) { } catch (e) {
console.log('fileIO_test_open_async_000 has failed for ' + e.message + ', code: ' + e.code); console.log('fileIO_test_open_async_000 has failed for ' + e.message + ', code: ' + e.code);
expect(false).assertTrue(); expect(false).assertTrue();
...@@ -378,7 +409,8 @@ import { ...@@ -378,7 +409,8 @@ import {
/** /**
* @tc.number SUB_DF_FILEIO_OPEN_ASYNC_0100 * @tc.number SUB_DF_FILEIO_OPEN_ASYNC_0100
* @tc.name fileIO_test_open_async_001 * @tc.name fileIO_test_open_async_001
* @tc.desc Test open() interfaces. mode=0o2. No such file. * @tc.desc Test open() interfaces. mode=0o0. Callback.
* Open the file in read-only mode, verifying the file is readable.
* @tc.size MEDIUM * @tc.size MEDIUM
* @tc.type Functoin * @tc.type Functoin
* @tc.level Level 0 * @tc.level Level 0
...@@ -386,41 +418,65 @@ import { ...@@ -386,41 +418,65 @@ import {
*/ */
it('fileIO_test_open_async_001', 0, async function (done) { it('fileIO_test_open_async_001', 0, async function (done) {
let fpath = await nextFileName('fileIO_test_open_async_001'); let fpath = await nextFileName('fileIO_test_open_async_001');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try { try {
await fileIO.open(fpath, fileIO.OpenMode.READ_WRITE); fileIO.open(fpath, fileIO.OpenMode.READ_ONLY, (err, file) => {
if(err) {
console.log('fileIO_test_open_async_001 error package: ' + JSON.stringify(err));
expect(false).assertTrue(); expect(false).assertTrue();
}
expect(isIntNum(file.fd)).assertTrue();
fileIO.read(file.fd, new ArrayBuffer(4096))
.then((res) => {
expect(res == FILE_CONTENT.length).assertTrue();
fileio.closeSync(file.fd);
fileio.unlinkSync(fpath);
done();
});
});
} catch (e) { } catch (e) {
console.log('fileIO_test_open_async_001 has failed for ' + e.message + ', code: ' + e.code); console.log('fileIO_test_open_async_001 has failed for ' + e.message + ', code: ' + e.code);
expect(e.code == 13900002 && e.message == 'No such file or directory').assertTrue; expect(false).assertTrue();
done();
} }
}); });
/** /**
* @tc.number SUB_DF_FILEIO_OPEN_ASYNC_0200 * @tc.number SUB_DF_FILEIO_OPEN_ASYNC_0200
* @tc.name fileIO_test_open_async_002 * @tc.name fileIO_test_open_async_002
* @tc.desc Test open() interfaces. Invalid fp. * @tc.desc Test open() interfaces. mode=0o1. Promise.
* Open the file in write-only mode, verifying the file is writable.
* @tc.size MEDIUM * @tc.size MEDIUM
* @tc.type Functoin * @tc.type Functoin
* @tc.level Level 0 * @tc.level Level 0
* @tc.require * @tc.require
*/ */
it('fileIO_test_open_async_002', 0, async function (done) { it('fileIO_test_open_async_002', 0, async function (done) {
let fpath = await nextFileName('fileIO_test_open_async_002');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
let length = 20;
try { try {
await fileIO.open(-1, fileIO.OpenMode.READ_WRITE); let file = await fileIO.open(fpath, fileIO.OpenMode.WRITE_ONLY);
expect(false).assertTrue(); expect(isIntNum(file.fd)).assertTrue();
fileIO.write(file.fd, new ArrayBuffer(length))
.then((num) => {
expect(num == length).assertTrue();
fileio.closeSync(file.fd);
fileio.unlinkSync(fpath);
done();
});
} catch (e) { } catch (e) {
console.log('fileIO_test_open_async_002 has failed for ' + e.message + ', code: ' + e.code); console.log('fileIO_test_open_async_002 has failed for ' + e.message + ', code: ' + e.code);
expect(e.code == 13900020 && e.message == 'Invalid argument').assertTrue(); expect(false).assertTrue();
done();
} }
}); });
/** /**
* @tc.number SUB_DF_FILEIO_OPEN_ASYNC_0300 * @tc.number SUB_DF_FILEIO_OPEN_ASYNC_0300
* @tc.name fileIO_test_open_async_003 * @tc.name fileIO_test_open_async_003
* @tc.desc Test open() interfaces. mode=0o1. * @tc.desc Test open() interfaces. mode=0o1. Callback.
* Open the file in write-only mode, verifying the file is writable.
* @tc.size MEDIUM * @tc.size MEDIUM
* @tc.type Functoin * @tc.type Functoin
* @tc.level Level 0 * @tc.level Level 0
...@@ -429,15 +485,22 @@ import { ...@@ -429,15 +485,22 @@ import {
it('fileIO_test_open_async_003', 0, async function (done) { it('fileIO_test_open_async_003', 0, async function (done) {
let fpath = await nextFileName('fileIO_test_open_async_003'); let fpath = await nextFileName('fileIO_test_open_async_003');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
let length = 20;
try { try {
let file = await fileIO.open(fpath, fileIO.OpenMode.WRITE_ONLY); fileIO.open(fpath, fileIO.OpenMode.WRITE_ONLY, (err, file) => {
if(err) {
console.log('fileIO_test_open_async_003 error package' + JSON.stringify(err));
expect(false).assertTrue();
}
expect(isIntNum(file.fd)).assertTrue(); expect(isIntNum(file.fd)).assertTrue();
let length = 20; fileIO.write(file.fd, new ArrayBuffer(length))
let num = fileIO.writeSync(file.fd, new ArrayBuffer(length)); .then((num) => {
expect(num == length).assertTrue(); expect(num == length).assertTrue();
fileio.closeSync(file.fd); fileio.closeSync(file.fd);
fileio.unlinkSync(fpath); fileio.unlinkSync(fpath);
});
});
done(); done();
} catch (e) { } catch (e) {
console.log('fileIO_test_open_async_003 has failed for ' + e.message + ', code: ' + e.code); console.log('fileIO_test_open_async_003 has failed for ' + e.message + ', code: ' + e.code);
...@@ -448,7 +511,8 @@ import { ...@@ -448,7 +511,8 @@ import {
/** /**
* @tc.number SUB_DF_FILEIO_OPEN_ASYNC_0400 * @tc.number SUB_DF_FILEIO_OPEN_ASYNC_0400
* @tc.name fileIO_test_open_async_004 * @tc.name fileIO_test_open_async_004
* @tc.desc Test open() interfaces. mode=0o2. * @tc.desc Test open() interfaces. mode=0o2. Promise.
* The path point to nothing, no such file.
* @tc.size MEDIUM * @tc.size MEDIUM
* @tc.type Functoin * @tc.type Functoin
* @tc.level Level 0 * @tc.level Level 0
...@@ -456,29 +520,22 @@ import { ...@@ -456,29 +520,22 @@ import {
*/ */
it('fileIO_test_open_async_004', 0, async function (done) { it('fileIO_test_open_async_004', 0, async function (done) {
let fpath = await nextFileName('fileIO_test_open_async_004'); let fpath = await nextFileName('fileIO_test_open_async_004');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try { try {
let file = await fileIO.open(fpath, fileIO.OpenMode.READ_WRITE); await fileIO.open(fpath, fileIO.OpenMode.READ_WRITE);
expect(isIntNum(file.fd)).assertTrue(); expect(false).assertTrue();
let readlen = fileIO.readSync(file.fd, new ArrayBuffer(4096));
expect(readlen == FILE_CONTENT.length).assertTrue();
let length = 20;
let num = fileIO.writeSync(file.fd, new ArrayBuffer(length));
expect(num == length).assertTrue();
fileio.closeSync(file.fd);
fileio.unlinkSync(fpath);
done();
} catch (e) { } catch (e) {
console.log('fileIO_test_open_async_004 has failed for ' + e.message + ', code: ' + e.code); console.log('fileIO_test_open_async_004 has failed for ' + e.message + ', code: ' + e.code);
expect(false).assertTrue(); expect(e.code == 13900002 && e.message == 'No such file or directory').assertTrue();
done();
} }
}); });
/** /**
* @tc.number SUB_DF_FILEIO_OPEN_ASYNC_0500 * @tc.number SUB_DF_FILEIO_OPEN_ASYNC_0500
* @tc.name fileIO_test_open_async_005 * @tc.name fileIO_test_open_async_005
* @tc.desc Test open() interfaces. mode=0o102. Promise. * @tc.desc Test open() interfaces. mode=0o2. Callback.
* The path point to nothing, no such file.
* @tc.size MEDIUM * @tc.size MEDIUM
* @tc.type Functoin * @tc.type Functoin
* @tc.level Level 0 * @tc.level Level 0
...@@ -488,11 +545,13 @@ import { ...@@ -488,11 +545,13 @@ import {
let fpath = await nextFileName('fileIO_test_open_async_005'); let fpath = await nextFileName('fileIO_test_open_async_005');
try { try {
let file = await fileIO.open(fpath, fileIO.OpenMode.CREATE | fileIO.OpenMode.READ_WRITE); fileIO.open(fpath, fileIO.OpenMode.READ_WRITE, (err) => {
expect(isIntNum(file.fd)).assertTrue(); if(err) {
fileio.closeSync(file.fd); console.log('fileIO_test_open_async_005 error package: {' + err.message + ', code: ' + err.code + '}');
fileio.unlinkSync(fpath); expect(err.code == 13900002 && err.message == 'No such file or directory').assertTrue();
done(); done();
}
});
} catch (e) { } catch (e) {
console.log('fileIO_test_open_async_005 has failed for ' + e.message + ', code: ' + e.code); console.log('fileIO_test_open_async_005 has failed for ' + e.message + ', code: ' + e.code);
expect(false).assertTrue(); expect(false).assertTrue();
...@@ -502,22 +561,23 @@ import { ...@@ -502,22 +561,23 @@ import {
/** /**
* @tc.number SUB_DF_FILEIO_OPEN_ASYNC_0600 * @tc.number SUB_DF_FILEIO_OPEN_ASYNC_0600
* @tc.name fileIO_test_open_async_006 * @tc.name fileIO_test_open_async_006
* @tc.desc Test open() interfaces. mode=0o102. Callback. * @tc.desc Test open() interfaces. mode=0o2. Promise.then().catch()
* The path point to nothing, no such file.
* @tc.size MEDIUM * @tc.size MEDIUM
* @tc.type Functoin * @tc.type Functoin
* @tc.level Level 0 * @tc.level Level 0
* @tc.require * @tc.require
*/ */
it('fileIO_test_open_async_006', 0, async function (done) { it('fileIO_test_open_async_006', 0, async function () {
let fpath = await nextFileName('fileIO_test_open_async_006'); let fpath = await nextFileName('fileIO_test_open_async_006');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try { try {
fileIO.open(fpath, fileIO.OpenMode.CREATE | fileIO.OpenMode.READ_WRITE, function (err, file) { fileIO.open(fpath, fileIO.OpenMode.READ_WRITE).then(() => {
expect(isIntNum(file.fd)).assertTrue(); expect(false).assertTrue();
fileio.closeSync(file.fd); }).catch((err) => {
fileio.unlinkSync(fpath); fileio.unlinkSync(fpath);
done(); console.log('fileIO_test_open_async_006 error package: {' + err.message + ', code: ' + err.code + '}');
expect(err.code == 13900002 && err.message == 'No such file or directory').assertTrue();
}); });
} catch (e) { } catch (e) {
console.log('fileIO_test_open_async_006 has failed for ' + e.message + ', code: ' + e.code); console.log('fileIO_test_open_async_006 has failed for ' + e.message + ', code: ' + e.code);
...@@ -528,66 +588,53 @@ import { ...@@ -528,66 +588,53 @@ import {
/** /**
* @tc.number SUB_DF_FILEIO_OPEN_ASYNC_0700 * @tc.number SUB_DF_FILEIO_OPEN_ASYNC_0700
* @tc.name fileIO_test_open_async_007 * @tc.name fileIO_test_open_async_007
* @tc.desc Test open() interfaces. mode=0o1002. * @tc.desc Test open() interfaces. Promise.
* If the file exists and the file is opened for write-only or read-write, trim its length to zero. * Invalid path.
* @tc.size MEDIUM * @tc.size MEDIUM
* @tc.type Functoin * @tc.type Functoin
* @tc.level Level 0 * @tc.level Level 0
* @tc.require * @tc.require
*/ */
it('fileIO_test_open_async_007', 0, async function (done) { it('fileIO_test_open_async_007', 0, async function (done) {
let fpath = await nextFileName('fileIO_test_open_async_007');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try { try {
let file = await fileIO.open(fpath, fileIO.OpenMode.TRUNC | fileIO.OpenMode.READ_WRITE); await fileIO.open(-1, fileIO.OpenMode.READ_WRITE);
expect(isIntNum(file.fd)).assertTrue(); expect(false).assertTrue();
let number = fileIO.readSync(file.fd, new ArrayBuffer(4096));
expect(number == 0).assertTrue();
fileio.closeSync(file.fd);
fileio.unlinkSync(fpath);
done();
} catch (e) { } catch (e) {
console.log('fileIO_test_open_async_007 has failed for ' + e.message + ', code: ' + e.code); console.log('fileIO_test_open_async_007 has failed for ' + e.message + ', code: ' + e.code);
expect(false).assertTrue(); expect(e.code == 13900020 && e.message == 'Invalid argument').assertTrue();
done();
} }
}); });
/** /**
* @tc.number SUB_DF_FILEIO_OPEN_ASYNC_0800 * @tc.number SUB_DF_FILEIO_OPEN_ASYNC_0800
* @tc.name fileIO_test_open_async_008 * @tc.name fileIO_test_open_async_008
* @tc.desc Test open() interfaces. mode=0o2002. * @tc.desc Test open() interfaces. Callback.
* Open as append, subsequent writes will append to the end of the file. * Invalid path.
* @tc.size MEDIUM * @tc.size MEDIUM
* @tc.type Functoin * @tc.type Functoin
* @tc.level Level 0 * @tc.level Level 0
* @tc.require * @tc.require
*/ */
it('fileIO_test_open_async_008', 0, async function (done) { it('fileIO_test_open_async_008', 0, async function (done) {
let fpath = await nextFileName('fileIO_test_open_async_008');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try { try {
let file = await fileIO.open(fpath, fileIO.OpenMode.APPEND | fileIO.OpenMode.READ_WRITE); fileIO.open(-1, fileIO.OpenMode.READ_WRITE, () => {
expect(isIntNum(file.fd)).assertTrue(); expect(false).assertTrue();
let length = 100; });
let num = fileIO.writeSync(file.fd, new ArrayBuffer(length));
expect(num == length).assertTrue();
let number = fileIO.readSync(file.fd, new ArrayBuffer(4096), { offset: 0 });
expect(number == length + FILE_CONTENT.length).assertTrue();
fileio.closeSync(file.fd);
fileio.unlinkSync(fpath);
done();
} catch (e) { } catch (e) {
console.log('fileIO_test_open_async_008 has failed for ' + e.message + ', code: ' + e.code); console.log('fileIO_test_open_async_008 has failed for ' + e.message + ', code: ' + e.code);
expect(false).assertTrue(); expect(e.code == 13900020 && e.message == 'Invalid argument').assertTrue();
done();
} }
}); });
/** /**
* @tc.number SUB_DF_FILEIO_OPEN_ASYNC_0900 * @tc.number SUB_DF_FILEIO_OPEN_ASYNC_0900
* @tc.name fileIO_test_open_async_009 * @tc.name fileIO_test_open_async_009
* @tc.desc Test open() interfaces. mode=0o4002. * @tc.desc Test open() interfaces. mode=0o102. Promise.
* If the path point to the file which does not exist, the file can be created.
* @tc.size MEDIUM * @tc.size MEDIUM
* @tc.type Functoin * @tc.type Functoin
* @tc.level Level 0 * @tc.level Level 0
...@@ -595,10 +642,9 @@ import { ...@@ -595,10 +642,9 @@ import {
*/ */
it('fileIO_test_open_async_009', 0, async function (done) { it('fileIO_test_open_async_009', 0, async function (done) {
let fpath = await nextFileName('fileIO_test_open_async_009'); let fpath = await nextFileName('fileIO_test_open_async_009');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try { try {
let file = await fileIO.open(fpath, fileIO.OpenMode.NONBLOCK | fileIO.OpenMode.READ_WRITE); let file = await fileIO.open(fpath, fileIO.OpenMode.CREATE | fileIO.OpenMode.READ_WRITE);
expect(isIntNum(file.fd)).assertTrue(); expect(isIntNum(file.fd)).assertTrue();
fileio.closeSync(file.fd); fileio.closeSync(file.fd);
fileio.unlinkSync(fpath); fileio.unlinkSync(fpath);
...@@ -612,21 +658,27 @@ import { ...@@ -612,21 +658,27 @@ import {
/** /**
* @tc.number SUB_DF_FILEIO_OPEN_ASYNC_1000 * @tc.number SUB_DF_FILEIO_OPEN_ASYNC_1000
* @tc.name fileIO_test_open_async_010 * @tc.name fileIO_test_open_async_010
* @tc.desc Test open() interfaces. mode=0o200000. * @tc.desc Test open() interfaces. mode=0o102. Callback.
* If the path point to the file which does not exist, the file can be created.
* @tc.size MEDIUM * @tc.size MEDIUM
* @tc.type Functoin * @tc.type Functoin
* @tc.level Level 0 * @tc.level Level 0
* @tc.require * @tc.require
*/ */
it('fileIO_test_open_async_010', 0, async function (done) { it('fileIO_test_open_async_010', 0, async function (done) {
let dpath = await nextFileName('fileIO_test_open_async_010'); let fpath = await nextFileName('fileIO_test_open_async_010');
fileio.mkdirSync(dpath);
try { try {
let file = await fileIO.open(dpath, fileIO.OpenMode.DIR); fileIO.open(fpath, fileIO.OpenMode.CREATE | fileIO.OpenMode.WRITE_ONLY, (err, file) => {
if(err) {
console.log('fileIO_test_open_async_010 error package: ' + JSON.stringify(err));
expect(false).assertTrue();
}
expect(isIntNum(file.fd)).assertTrue(); expect(isIntNum(file.fd)).assertTrue();
fileio.rmdirSync(dpath); fileio.closeSync(file.fd);
fileio.unlinkSync(fpath);
done(); done();
});
} catch (e) { } catch (e) {
console.log('fileIO_test_open_async_010 has failed for ' + e.message + ', code: ' + e.code); console.log('fileIO_test_open_async_010 has failed for ' + e.message + ', code: ' + e.code);
expect(false).assertTrue(); expect(false).assertTrue();
...@@ -636,7 +688,8 @@ import { ...@@ -636,7 +688,8 @@ import {
/** /**
* @tc.number SUB_DF_FILEIO_OPEN_ASYNC_1100 * @tc.number SUB_DF_FILEIO_OPEN_ASYNC_1100
* @tc.name fileIO_test_open_async_011 * @tc.name fileIO_test_open_async_011
* @tc.desc Test open() interfaces. mode=0o200000. Not a directory. * @tc.desc Test open() interfaces. mode=0o1002. Promise.
* If the file exists and the file is opened for read-write, trim its length to zero.
* @tc.size MEDIUM * @tc.size MEDIUM
* @tc.type Functoin * @tc.type Functoin
* @tc.level Level 0 * @tc.level Level 0
...@@ -644,23 +697,29 @@ import { ...@@ -644,23 +697,29 @@ import {
*/ */
it('fileIO_test_open_async_011', 0, async function (done) { it('fileIO_test_open_async_011', 0, async function (done) {
let fpath = await nextFileName('fileIO_test_open_async_011'); let fpath = await nextFileName('fileIO_test_open_async_011');
expect(prepareFile(fpath, '')).assertTrue(); expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try { try {
await fileIO.open(fpath, fileIO.OpenMode.DIR | fileIO.OpenMode.READ_WRITE); let file = await fileIO.open(fpath, fileIO.OpenMode.TRUNC | fileIO.OpenMode.READ_WRITE);
expect(false).assertTrue(); expect(isIntNum(file.fd)).assertTrue();
} catch (e) { fileIO.read(file.fd, new ArrayBuffer(4096))
.then((number) => {
expect(number == 0).assertTrue();
fileio.closeSync(file.fd);
fileio.unlinkSync(fpath); fileio.unlinkSync(fpath);
console.log('fileIO_test_open_async_011 has failed for ' + e.message + ', code: ' + e.code); });
expect(e.code == 13900002 && e.message == 'No such file or directory').assertTrue;
done(); done();
} catch (e) {
console.log('fileIO_test_open_async_011 has failed for ' + e.message + ', code: ' + e.code);
expect(false).assertTrue();
} }
}); });
/** /**
* @tc.number SUB_DF_FILEIO_OPEN_ASYNC_1200 * @tc.number SUB_DF_FILEIO_OPEN_ASYNC_1200
* @tc.name fileIO_test_open_async_012 * @tc.name fileIO_test_open_async_012
* @tc.desc Test open() interfaces. mode=0o400002. * @tc.desc Test open() interfaces. mode=0o1002. Callback.
* If the file exists and the file is opened for read-write, trim its length to zero.
* @tc.size MEDIUM * @tc.size MEDIUM
* @tc.type Functoin * @tc.type Functoin
* @tc.level Level 0 * @tc.level Level 0
...@@ -671,11 +730,20 @@ import { ...@@ -671,11 +730,20 @@ import {
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try { try {
let file = await fileIO.open(fpath, fileIO.OpenMode.NOFOLLOW | fileIO.OpenMode.READ_WRITE); fileIO.open(fpath, fileIO.OpenMode.TRUNC | fileIO.OpenMode.READ_WRITE, (err, file) => {
if(err) {
console.log('fileIO_test_open_async_012 error package: ' + JSON.stringify(err));
expect(false).assertTrue();
}
expect(isIntNum(file.fd)).assertTrue(); expect(isIntNum(file.fd)).assertTrue();
fileIO.read(file.fd, new ArrayBuffer(4096))
.then((number) => {
expect(number == 0).assertTrue();
fileio.closeSync(file.fd); fileio.closeSync(file.fd);
fileio.unlinkSync(fpath); fileio.unlinkSync(fpath);
});
done(); done();
});
} catch (e) { } catch (e) {
console.log('fileIO_test_open_async_012 has failed for ' + e.message + ', code: ' + e.code); console.log('fileIO_test_open_async_012 has failed for ' + e.message + ', code: ' + e.code);
expect(false).assertTrue(); expect(false).assertTrue();
...@@ -685,7 +753,8 @@ import { ...@@ -685,7 +753,8 @@ import {
/** /**
* @tc.number SUB_DF_FILEIO_OPEN_ASYNC_1300 * @tc.number SUB_DF_FILEIO_OPEN_ASYNC_1300
* @tc.name fileIO_test_open_async_013 * @tc.name fileIO_test_open_async_013
* @tc.desc Test open() interfaces. mode=0o400002. Shouldn't be Symbolic link. * @tc.desc Test open() interfaces. mode=0o2002. Promise.
* Open as append, subsequent writes will append to the end of the file.
* @tc.size MEDIUM * @tc.size MEDIUM
* @tc.type Functoin * @tc.type Functoin
* @tc.level Level 0 * @tc.level Level 0
...@@ -693,6 +762,327 @@ import { ...@@ -693,6 +762,327 @@ import {
*/ */
it('fileIO_test_open_async_013', 0, async function (done) { it('fileIO_test_open_async_013', 0, async function (done) {
let fpath = await nextFileName('fileIO_test_open_async_013'); let fpath = await nextFileName('fileIO_test_open_async_013');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
let length = 100;
try {
let file = await fileIO.open(fpath, fileIO.OpenMode.APPEND | fileIO.OpenMode.READ_WRITE);
expect(isIntNum(file.fd)).assertTrue();
fileIO.writeSync(file.fd, new ArrayBuffer(length));
fileIO.read(file.fd, new ArrayBuffer(4096), { offset: 0 })
.then((number) => {
expect(number == length + FILE_CONTENT.length).assertTrue();
fileIO.closeSync(file.fd);
fileio.unlinkSync(fpath);
});
done();
} catch (e) {
console.log('fileIO_test_open_async_013 has failed for ' + e.message + ', code: ' + e.code);
expect(false).assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_OPEN_ASYNC_1400
* @tc.name fileIO_test_open_async_014
* @tc.desc Test open() interfaces. mode=0o2002. Callback.
* Open as append, subsequent writes will append to the end of the file.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it('fileIO_test_open_async_014', 0, async function (done) {
let fpath = await nextFileName('fileIO_test_open_async_014');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
let length = 100;
try {
fileIO.open(fpath, fileIO.OpenMode.APPEND | fileIO.OpenMode.READ_WRITE, (err, file) => {
if(err) {
console.log('fileIO_test_open_async_014 error package: ' + JSON.stringify(err));
expect(false).assertTrue();
}
expect(isIntNum(file.fd)).assertTrue();
fileIO.writeSync(file.fd, new ArrayBuffer(length));
fileIO.read(file.fd, new ArrayBuffer(4096), { offset: 0 })
.then((number) => {
expect(number == length + FILE_CONTENT.length).assertTrue();
fileIO.closeSync(file.fd);
fileio.unlinkSync(fpath);
});
done();
});
} catch (e) {
console.log('fileIO_test_open_async_014 has failed for ' + e.message + ', code: ' + e.code);
expect(false).assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_OPEN_ASYNC_1500
* @tc.name fileIO_test_open_async_015
* @tc.desc Test open() interfaces. mode=0o4002. Promise.
* If the file is a special file, the opening and subsequent IOs perform non-blocking operations.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it('fileIO_test_open_async_015', 0, async function (done) {
let fpath = await nextFileName('fileIO_test_open_async_015');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
let file = await fileIO.open(fpath, fileIO.OpenMode.NONBLOCK | fileIO.OpenMode.READ_WRITE);
expect(isIntNum(file.fd)).assertTrue();
fileio.closeSync(file.fd);
fileio.unlinkSync(fpath);
done();
} catch (e) {
console.log('fileIO_test_open_async_015 has failed for ' + e.message + ', code: ' + e.code);
expect(false).assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_OPEN_ASYNC_1600
* @tc.name fileIO_test_open_async_016
* @tc.desc Test open() interfaces. mode=0o4002. Callback.
* If the file is a special file, the opening and subsequent IOs perform non-blocking operations.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it('fileIO_test_open_async_016', 0, async function (done) {
let fpath = await nextFileName('fileIO_test_open_async_016');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
fileIO.open(fpath, fileIO.OpenMode.NONBLOCK | fileIO.OpenMode.READ_WRITE, (err, file) => {
if(err) {
console.log('fileIO_test_open_async_016 error package: ' + JSON.stringify(err));
expect(false).assertTrue();
}
expect(isIntNum(file.fd)).assertTrue();
fileio.closeSync(file.fd);
fileio.unlinkSync(fpath);
done();
});
} catch (e) {
console.log('fileIO_test_open_async_016 has failed for ' + e.message + ', code: ' + e.code);
expect(false).assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_OPEN_ASYNC_1700
* @tc.name fileIO_test_open_async_017
* @tc.desc Test open() interfaces. mode=0o200000. Promise.
* The path points to a directory.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it('fileIO_test_open_async_017', 0, async function (done) {
let dpath = await nextFileName('fileIO_test_open_async_017');
fileio.mkdirSync(dpath);
try {
let file = await fileIO.open(dpath, fileIO.OpenMode.DIR);
expect(isIntNum(file.fd)).assertTrue();
fileio.rmdirSync(dpath);
done();
} catch (e) {
console.log('fileIO_test_open_async_017 has failed for ' + e.message + ', code: ' + e.code);
expect(false).assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_OPEN_ASYNC_1800
* @tc.name fileIO_test_open_async_018
* @tc.desc Test open() interfaces. mode=0o200000. Callback.
* The path points to a directory.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it('fileIO_test_open_async_018', 0, async function (done) {
let dpath = await nextFileName('fileIO_test_open_async_018');
fileio.mkdirSync(dpath);
try {
fileIO.open(dpath, fileIO.OpenMode.DIR, (err, file) => {
if(err) {
console.log('fileIO_test_open_async_018 error package: ' + JSON.stringify(err));
expect(false).assertTrue();
}
expect(isIntNum(file.fd)).assertTrue();
fileio.rmdirSync(dpath);
done();
});
} catch (e) {
console.log('fileIO_test_open_async_018 has failed for ' + e.message + ', code: ' + e.code);
expect(false).assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_OPEN_ASYNC_1900
* @tc.name fileIO_test_open_async_019
* @tc.desc Test open() interfaces. mode=0o200000. Promise.
* The path does not point to a directory, throw error.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it('fileIO_test_open_async_019', 0, async function (done) {
let fpath = await nextFileName('fileIO_test_open_async_019');
expect(prepareFile(fpath, '')).assertTrue();
try {
await fileIO.open(fpath, fileIO.OpenMode.DIR);
expect(false).assertTrue();
} catch (e) {
fileio.unlinkSync(fpath);
console.log('fileIO_test_open_async_019 has failed for ' + e.message + ', code: ' + e.code);
expect(e.code == 13900018 && e.message == 'Not a directory').assertTrue();
done();
}
});
/**
* @tc.number SUB_DF_FILEIO_OPEN_ASYNC_2000
* @tc.name fileIO_test_open_async_020
* @tc.desc Test open() interfaces. mode=0o200000. Callback.
* The path does not point to a directory, throw error.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it('fileIO_test_open_async_020', 0, async function (done) {
let fpath = await nextFileName('fileIO_test_open_async_020');
expect(prepareFile(fpath, '')).assertTrue();
try {
fileIO.open(fpath, fileIO.OpenMode.DIR, (err) => {
if(err) {
fileio.unlinkSync(fpath);
console.log('fileIO_test_open_async_020 error package: {' + err.message + ', code: ' + err.code + '}');
expect(err.code == 13900018 && err.message == 'Not a directory').assertTrue();
done();
}
});
} catch (e) {
console.log('fileIO_test_open_async_020 has failed for ' + e.message + ', code: ' + e.code);
expect(false).assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_OPEN_ASYNC_2100
* @tc.name fileIO_test_open_async_021
* @tc.desc Test open() interfaces. mode=0o200000. Promise.then().catch().
* The path does not point to a directory, throw error.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it('fileIO_test_open_async_021', 0, async function (done) {
let fpath = await nextFileName('fileIO_test_open_async_021');
expect(prepareFile(fpath, '')).assertTrue();
try {
fileIO.open(fpath, fileIO.OpenMode.DIR).then(() => {
expect(false).assertTrue();
}).catch((err) => {
fileio.unlinkSync(fpath);
console.log('fileIO_test_open_async_021 error package: {' + err.message + ', code: ' + err.code + '}');
expect(err.code == 13900018 && err.message == 'Not a directory').assertTrue();
done();
});
} catch (e) {
console.log('fileIO_test_open_async_021 has failed for ' + e.message + ', code: ' + e.code);
expect(false).assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_OPEN_ASYNC_2200
* @tc.name fileIO_test_open_async_022
* @tc.desc Test open() interfaces. mode=0o400002. Promise.
* The path does not point to a symbolic link.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it('fileIO_test_open_async_022', 0, async function (done) {
let fpath = await nextFileName('fileIO_test_open_async_022');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
let file = await fileIO.open(fpath, fileIO.OpenMode.NOFOLLOW | fileIO.OpenMode.READ_WRITE);
expect(isIntNum(file.fd)).assertTrue();
fileio.closeSync(file.fd);
fileio.unlinkSync(fpath);
done();
} catch (e) {
console.log('fileIO_test_open_async_022 has failed for ' + e.message + ', code: ' + e.code);
expect(false).assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_OPEN_ASYNC_2300
* @tc.name fileIO_test_open_async_023
* @tc.desc Test open() interfaces. mode=0o400002. Callback.
* The path does not point to a symbolic link.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it('fileIO_test_open_async_023', 0, async function (done) {
let fpath = await nextFileName('fileIO_test_open_async_023');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
fileIO.open(fpath, fileIO.OpenMode.NOFOLLOW | fileIO.OpenMode.READ_WRITE, (err, file) => {
if(err) {
console.log('fileIO_test_open_async_023 error package: ' + JSON.stringify(err));
expect(false).assertTrue();
}
expect(isIntNum(file.fd)).assertTrue();
fileio.closeSync(file.fd);
fileio.unlinkSync(fpath);
done();
});
} catch (e) {
console.log('fileIO_test_open_async_023 has failed for ' + e.message + ', code: ' + e.code);
expect(false).assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_OPEN_ASYNC_2400
* @tc.name fileIO_test_open_async_024
* @tc.desc Test open() interfaces. mode=0o400002. Promise.
* The path point to a symbolic link, throw error.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it('fileIO_test_open_async_024', 0, async function (done) {
let fpath = await nextFileName('fileIO_test_open_async_024');
let ffpath = fpath + 'aaaa'; let ffpath = fpath + 'aaaa';
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
...@@ -701,36 +1091,131 @@ import { ...@@ -701,36 +1091,131 @@ import {
await fileIO.open(ffpath, fileIO.OpenMode.NOFOLLOW | fileIO.OpenMode.READ_WRITE); await fileIO.open(ffpath, fileIO.OpenMode.NOFOLLOW | fileIO.OpenMode.READ_WRITE);
expect(false).assertTrue(); expect(false).assertTrue();
} catch (e) { } catch (e) {
console.log('fileIO_test_open_async_013 has failed for ' + e.message + ', code: ' + e.code);
expect(e.code == 13900033 && e.message == 'Too many symbolic links encountered').assertTrue;
fileio.unlinkSync(fpath); fileio.unlinkSync(fpath);
fileio.unlinkSync(ffpath); fileio.unlinkSync(ffpath);
console.log('fileIO_test_open_async_024 has failed for ' + e.message + ', code: ' + e.code);
expect(e.code == 13900033 && e.message == 'Too many symbolic links encountered').assertTrue();
done(); done();
} }
}); });
/** /**
* @tc.number SUB_DF_FILEIO_OPEN_ASYNC_1400 * @tc.number SUB_DF_FILEIO_OPEN_ASYNC_2500
* @tc.name fileIO_test_open_async_014 * @tc.name fileIO_test_open_async_025
* @tc.desc Test open() interfaces. mode=0o4010002. * @tc.desc Test open() interfaces. mode=0o400002. Callback.
* The path point to a symbolic link, throw error.
* @tc.size MEDIUM * @tc.size MEDIUM
* @tc.type Functoin * @tc.type Functoin
* @tc.level Level 0 * @tc.level Level 0
* @tc.require * @tc.require
*/ */
it('fileIO_test_open_async_014', 0, async function (done) { it('fileIO_test_open_async_025', 0, async function (done) {
let fpath = await nextFileName('fileIO_test_open_async_014'); let fpath = await nextFileName('fileIO_test_open_async_025');
let ffpath = fpath + 'link';
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
fileio.symlinkSync(fpath, ffpath);
fileIO.open(ffpath, fileIO.OpenMode.NOFOLLOW | fileIO.OpenMode.READ_WRITE, (err) => {
if(err) {
console.log('fileIO_test_open_async_025 error package: {' + err.message + ', code: ' + err.code + '}');
expect(err.code == 13900033 && err.message == 'Too many symbolic links encountered').assertTrue();
}
fileio.unlinkSync(fpath);
fileio.unlinkSync(ffpath);
done();
});
} catch (e) {
console.log('fileIO_test_open_async_025 has failed for ' + e.message + ', code: ' + e.code);
expect(false).assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_OPEN_ASYNC_2600
* @tc.name fileIO_test_open_async_026
* @tc.desc Test open() interfaces. mode=0o400002. Promise.then().catch()
* The path point to a symbolic link, throw error.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it('fileIO_test_open_async_026', 0, async function (done) {
let fpath = await nextFileName('fileIO_test_open_async_026');
let ffpath = fpath + 'link';
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try { try {
fileIO.open(fpath, fileIO.OpenMode.SYNC | fileIO.OpenMode.READ_WRITE, function(err, file) { fileio.symlinkSync(fpath, ffpath);
fileIO.open(ffpath, fileIO.OpenMode.NOFOLLOW | fileIO.OpenMode.READ_WRITE).then(() => {
expect(false).assertTrue();
}).catch((err) => {
console.log('fileIO_test_open_async_026 error package: {' + err.message + ', code: ' + err.code + '}');
expect(err.code == 13900033 && err.message == 'Too many symbolic links encountered').assertTrue();
fileio.unlinkSync(fpath);
fileio.unlinkSync(ffpath);
done();
});
} catch (e) {
console.log('fileIO_test_open_async_026 has failed for ' + e.message + ', code: ' + e.code);
expect(false).assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_OPEN_ASYNC_2700
* @tc.name fileIO_test_open_async_027
* @tc.desc Test open() interfaces. mode=0o4010002. Promise.
* Open the file in the way of synchronous IO.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it('fileIO_test_open_async_027', 0, async function (done) {
let fpath = await nextFileName('fileIO_test_open_async_027');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
let file = await fileIO.open(fpath, fileIO.OpenMode.SYNC | fileIO.OpenMode.READ_WRITE);
expect(isIntNum(file.fd)).assertTrue(); expect(isIntNum(file.fd)).assertTrue();
fileio.closeSync(file.fd); fileio.closeSync(file.fd);
fileio.unlinkSync(fpath); fileio.unlinkSync(fpath);
done(); done();
} catch (e) {
console.log('fileIO_test_open_async_027 has failed for ' + e.message + ', code: ' + e.code);
expect(false).assertTrue();
}
}); });
} catch (err) {
console.log('fileIO_test_open_async_014 has failed for ' + err.message + ', code: ' + err.code); /**
* @tc.number SUB_DF_FILEIO_OPEN_ASYNC_2800
* @tc.name fileIO_test_open_async_028
* @tc.desc Test open() interfaces. mode=0o4010002. Callback.
* Open the file in the way of synchronous IO.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it('fileIO_test_open_async_028', 0, async function (done) {
let fpath = await nextFileName('fileIO_test_open_async_028');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
fileIO.open(fpath, fileIO.OpenMode.SYNC | fileIO.OpenMode.READ_WRITE, (err, file) => {
if(err) {
console.log('fileIO_test_open_async_028 error package: ' + JSON.stringify(err));
expect(false).assertTrue();
}
expect(isIntNum(file.fd)).assertTrue();
fileio.closeSync(file.fd);
fileio.unlinkSync(fpath);
done();
});
} catch (e) {
console.log('fileIO_test_open_async_028 has failed for ' + e.message + ', code: ' + e.code);
expect(false).assertTrue(); expect(false).assertTrue();
} }
}); });
......
...@@ -24,7 +24,8 @@ import { ...@@ -24,7 +24,8 @@ import {
/** /**
* @tc.number SUB_DF_FILEIO_TRUNCATE_ASYNC_0000 * @tc.number SUB_DF_FILEIO_TRUNCATE_ASYNC_0000
* @tc.name fileIO_truncate_async_000 * @tc.name fileIO_truncate_async_000
* @tc.desc Test the truncate() interface that receives the fpath parameter. * @tc.desc Test the truncate() interface. Promise.
* Truncate the file with path and truncateLen = 5.
* @tc.size MEDIUM * @tc.size MEDIUM
* @tc.type Functoin * @tc.type Functoin
* @tc.level Level 0 * @tc.level Level 0
...@@ -53,7 +54,8 @@ import { ...@@ -53,7 +54,8 @@ import {
/** /**
* @tc.number SUB_DF_FILEIO_TRUNCATE_ASYNC_0100 * @tc.number SUB_DF_FILEIO_TRUNCATE_ASYNC_0100
* @tc.name fileIO_truncate_async_001 * @tc.name fileIO_truncate_async_001
* @tc.desc Test the truncate() interface that receives the fd parameter. * @tc.desc Test the truncate() interface. Callback.
* Truncate the file with fd and truncateLen = 5.
* @tc.size MEDIUM * @tc.size MEDIUM
* @tc.type Functoin * @tc.type Functoin
* @tc.level Level 0 * @tc.level Level 0
...@@ -62,13 +64,16 @@ import { ...@@ -62,13 +64,16 @@ import {
it('fileIO_truncate_async_001', 0, async function (done) { it('fileIO_truncate_async_001', 0, async function (done) {
let fpath = await nextFileName('fileIO_truncate_async_001'); let fpath = await nextFileName('fileIO_truncate_async_001');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
let file; let file = fileIO.openSync(fpath, fileIO.OpenMode.READ_WRITE);
let truncateLen = 5; let truncateLen = 5;
try { try {
file = fileIO.openSync(fpath, fileIO.OpenMode.READ_WRITE);
expect(isIntNum(file.fd)).assertTrue(); expect(isIntNum(file.fd)).assertTrue();
fileIO.truncate(file.fd, truncateLen, function (err) { fileIO.truncate(file.fd, truncateLen, (err) => {
if(err) {
console.log('fileIO_truncate_async_001 error package: ' + JSON.stringify(err));
expect(false).assertTrue();
}
let len = fileIO.readSync(file.fd, new ArrayBuffer(4096)); let len = fileIO.readSync(file.fd, new ArrayBuffer(4096));
expect(len == truncateLen).assertTrue(); expect(len == truncateLen).assertTrue();
fileio.closeSync(file.fd); fileio.closeSync(file.fd);
...@@ -84,7 +89,8 @@ import { ...@@ -84,7 +89,8 @@ import {
/** /**
* @tc.number SUB_DF_FILEIO_TRUNCATE_ASYNC_0200 * @tc.number SUB_DF_FILEIO_TRUNCATE_ASYNC_0200
* @tc.name fileIO_truncate_async_002 * @tc.name fileIO_truncate_async_002
* @tc.desc Test the truncate() interface that receives the fpath parameter. * @tc.desc Test the truncate() interface. Promise.then().catch
* Truncate the file with path and truncateLen = 2.
* @tc.size MEDIUM * @tc.size MEDIUM
* @tc.type Functoin * @tc.type Functoin
* @tc.level Level 0 * @tc.level Level 0
...@@ -96,10 +102,7 @@ import { ...@@ -96,10 +102,7 @@ import {
let truncateLen = 2; let truncateLen = 2;
try { try {
fileIO fileIO.truncate(fpath, truncateLen).then(() => {
.truncate(fpath, truncateLen)
.then(function (err) {
expect(err == null).assertTrue();
let file = fileIO.openSync(fpath, fileIO.OpenMode.READ_WRITE); let file = fileIO.openSync(fpath, fileIO.OpenMode.READ_WRITE);
expect(isIntNum(file.fd)).assertTrue(); expect(isIntNum(file.fd)).assertTrue();
let len = fileIO.readSync(file.fd, new ArrayBuffer(4096)); let len = fileIO.readSync(file.fd, new ArrayBuffer(4096));
...@@ -107,9 +110,9 @@ import { ...@@ -107,9 +110,9 @@ import {
fileio.closeSync(file.fd); fileio.closeSync(file.fd);
fileio.unlinkSync(fpath); fileio.unlinkSync(fpath);
done(); done();
}) }).catch((err) => {
.catch(function (e) { console.log('fileIO_truncate_async_002 error package: ' + JSON.stringify(err));
console.log('catch ' + e.message + ', code: ' + e.code); expect(false).assertTrue();
}); });
} catch(e) { } catch(e) {
console.log('fileIO_truncate_async_002 has failed for ' + e.message + ', code: ' + e.code); console.log('fileIO_truncate_async_002 has failed for ' + e.message + ', code: ' + e.code);
...@@ -120,7 +123,8 @@ import { ...@@ -120,7 +123,8 @@ import {
/** /**
* @tc.number SUB_DF_FILEIO_TRUNCATE_ASYNC_0300 * @tc.number SUB_DF_FILEIO_TRUNCATE_ASYNC_0300
* @tc.name fileIO_truncate_async_003 * @tc.name fileIO_truncate_async_003
* @tc.desc Test the truncate() interface that receives the fd parameter. * @tc.desc Test the truncate() interface. Promise.then().catch
* Truncate the file with fd and truncateLen = 2.
* @tc.size MEDIUM * @tc.size MEDIUM
* @tc.type Functoin * @tc.type Functoin
* @tc.level Level 0 * @tc.level Level 0
...@@ -129,23 +133,20 @@ import { ...@@ -129,23 +133,20 @@ import {
it('fileIO_truncate_async_003', 0, async function (done) { it('fileIO_truncate_async_003', 0, async function (done) {
let fpath = await nextFileName('fileIO_truncate_async_003'); let fpath = await nextFileName('fileIO_truncate_async_003');
expect(prepareFile(fpath, 'truncate')).assertTrue(); expect(prepareFile(fpath, 'truncate')).assertTrue();
let file; let file = fileIO.openSync(fpath, fileIO.OpenMode.READ_WRITE);
let truncateLen = 2; let truncateLen = 2;
try { try {
file = fileIO.openSync(fpath, fileIO.OpenMode.READ_WRITE);
expect(isIntNum(file.fd)).assertTrue(); expect(isIntNum(file.fd)).assertTrue();
fileIO.truncate(file.fd, truncateLen) fileIO.truncate(file.fd, truncateLen).then(() => {
.then(function (err) {
expect(err == null).assertTrue();
let len = fileIO.readSync(file.fd, new ArrayBuffer(4096)); let len = fileIO.readSync(file.fd, new ArrayBuffer(4096));
expect(len == truncateLen).assertTrue(); expect(len == truncateLen).assertTrue();
fileio.closeSync(file.fd); fileio.closeSync(file.fd);
fileio.unlinkSync(fpath); fileio.unlinkSync(fpath);
done(); done();
}) }).catch((err) => {
.catch(function (e) { console.log('fileIO_truncate_async_003 error package: ' + JSON.stringify(err));
console.log('catch ' + e.message + ', code: ' + e.code); expect(false).assertTrue();
}) })
} catch(e) { } catch(e) {
console.log('fileIO_truncate_async_003 has failed for ' + e.message + ', code: ' + e.code); console.log('fileIO_truncate_async_003 has failed for ' + e.message + ', code: ' + e.code);
...@@ -156,7 +157,8 @@ import { ...@@ -156,7 +157,8 @@ import {
/** /**
* @tc.number SUB_DF_FILEIO_TRUNCATE_ASYNC_0400 * @tc.number SUB_DF_FILEIO_TRUNCATE_ASYNC_0400
* @tc.name fileIO_truncate_async_004 * @tc.name fileIO_truncate_async_004
* @tc.desc Test the truncate() interface that receives the fpath parameter. * @tc.desc Test the truncate() interface. Callback.
* Truncate the file with path and truncateLen = 2.
* @tc.size MEDIUM * @tc.size MEDIUM
* @tc.type Functoin * @tc.type Functoin
* @tc.level Level 0 * @tc.level Level 0
...@@ -167,13 +169,39 @@ import { ...@@ -167,13 +169,39 @@ import {
let truncateLen = 2; let truncateLen = 2;
try { try {
fileIO.truncate(fpath, truncateLen, function (err) { fileIO.truncate(fpath, truncateLen, (err) => {
if (err) {
console.log('fileIO_truncate_async_004 error package: {' + err.message + ', code: ' + err.code + '}');
expect(err.code == 13900002 && err.message == 'No such file or directory').assertTrue();
done(); done();
}
}); });
} catch (e) { } catch (e) {
console.log('fileIO_truncate_async_004 has failed for ' + e.message + ', code: ' + e.code); console.log('fileIO_truncate_async_004 has failed for ' + e.message + ', code: ' + e.code);
expect(!!e).assertTrue(); expect(false).assertTrue();
expect(e.code == 13900020 && e.message == 'Invalid argument').assertTrue(); }
});
/**
* @tc.number SUB_DF_FILEIO_TRUNCATE_ASYNC_0500
* @tc.name fileIO_truncate_async_005
* @tc.desc Test the truncate() interface. Promise.
* Truncate the file with path and truncateLen = 2.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it('fileIO_truncate_async_005', 0, async function (done) {
let fpath = await nextFileName('fileIO_truncate_async_005');
let truncateLen = 2;
try {
await fileIO.truncate(fpath, truncateLen);
expect(false).assertTrue();
} catch (e) {
console.log('fileIO_truncate_async_005 has failed for ' + e.message + ', code: ' + e.code);
expect(e.code == 13900002 && e.message == 'No such file or directory').assertTrue();
done(); done();
} }
}); });
...@@ -181,7 +209,8 @@ import { ...@@ -181,7 +209,8 @@ import {
/** /**
* @tc.number SUB_DF_FILEIO_TRUNCATE_SYNC_0000 * @tc.number SUB_DF_FILEIO_TRUNCATE_SYNC_0000
* @tc.name fileIO_test_truncate_sync_000 * @tc.name fileIO_test_truncate_sync_000
* @tc.desc Test the truncateSync() interface that receives the fpath parameter. * @tc.desc Test the truncateSync() interface.
* Truncate the file with path.
* @tc.size MEDIUM * @tc.size MEDIUM
* @tc.type Functoin * @tc.type Functoin
* @tc.level Level 0 * @tc.level Level 0
...@@ -204,7 +233,8 @@ import { ...@@ -204,7 +233,8 @@ import {
/** /**
* @tc.number SUB_DF_FILEIO_TRUNCATE_SYNC_0100 * @tc.number SUB_DF_FILEIO_TRUNCATE_SYNC_0100
* @tc.name fileIO_test_truncate_sync_001 * @tc.name fileIO_test_truncate_sync_001
* @tc.desc Test the truncateSync() interface that receives the fd parameter. * @tc.desc Test the truncateSync() interface.
* Truncate the file with fd and truncateLen = 5.
* @tc.size MEDIUM * @tc.size MEDIUM
* @tc.type Functoin * @tc.type Functoin
* @tc.level Level 0 * @tc.level Level 0
...@@ -213,11 +243,10 @@ import { ...@@ -213,11 +243,10 @@ import {
it('fileIO_test_truncate_sync_001', 0, async function () { it('fileIO_test_truncate_sync_001', 0, async function () {
let fpath = await nextFileName('fileIO_test_truncate_sync_001'); let fpath = await nextFileName('fileIO_test_truncate_sync_001');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
let file; let file = fileIO.openSync(fpath, fileIO.OpenMode.READ_WRITE);
let truncateLen = 5; let truncateLen = 5;
try { try {
file = fileIO.openSync(fpath, fileIO.OpenMode.READ_WRITE);
expect(isIntNum(file.fd)).assertTrue(); expect(isIntNum(file.fd)).assertTrue();
fileIO.truncateSync(file.fd, truncateLen); fileIO.truncateSync(file.fd, truncateLen);
let len = fileIO.readSync(file.fd, new ArrayBuffer(4096)); let len = fileIO.readSync(file.fd, new ArrayBuffer(4096));
...@@ -233,7 +262,8 @@ import { ...@@ -233,7 +262,8 @@ import {
/** /**
* @tc.number SUB_DF_FILEIO_TRUNCATE_SYNC_0200 * @tc.number SUB_DF_FILEIO_TRUNCATE_SYNC_0200
* @tc.name fileIO_test_truncate_sync_002 * @tc.name fileIO_test_truncate_sync_002
* @tc.desc Test the truncateSync() interface that receives the fpath parameter. * @tc.desc Test the truncateSync() interface.
* The path point to nothing, no such file.
* @tc.size MEDIUM * @tc.size MEDIUM
* @tc.type Functoin * @tc.type Functoin
* @tc.level Level 0 * @tc.level Level 0
...@@ -243,10 +273,10 @@ import { ...@@ -243,10 +273,10 @@ import {
let fpath = await nextFileName('fileIO_test_truncate_sync_002'); let fpath = await nextFileName('fileIO_test_truncate_sync_002');
try { try {
let stat = fileIO.truncateSync(fpath); fileIO.truncateSync(fpath);
console.info('fileIO_test_truncate_sync_002 = ' + stat);
expect(false).assertTrue(); expect(false).assertTrue();
} catch (e) { } catch (e) {
console.log('fileIO_test_truncate_sync_002 has failed for ' + e.message + ', code: ' + e.code);
expect(e.code == 13900002 && e.message == 'No such file or directory').assertTrue(); expect(e.code == 13900002 && e.message == 'No such file or directory').assertTrue();
} }
}); });
...@@ -254,69 +284,42 @@ import { ...@@ -254,69 +284,42 @@ import {
/** /**
* @tc.number SUB_DF_FILEIO_TRUNCATE_SYNC_0300 * @tc.number SUB_DF_FILEIO_TRUNCATE_SYNC_0300
* @tc.name fileIO_test_truncate_sync_003 * @tc.name fileIO_test_truncate_sync_003
* @tc.desc Test the truncateSync() interface that receives the fd parameter. * @tc.desc Test the truncateSync() interface. Invalid parameter.
* @tc.size MEDIUM * @tc.size MEDIUM
* @tc.type Functoin * @tc.type Functoin
* @tc.level Level 0 * @tc.level Level 0
* @tc.require * @tc.require
*/ */
it('fileIO_test_truncate_sync_003', 0, async function () { it('fileIO_test_truncate_sync_003', 0, async function () {
let fpath = await nextFileName('fileIO_test_truncate_sync_003');
expect(prepareFile(fpath, 'truncate')).assertTrue();
let file;
let truncateLen = 2; let truncateLen = 2;
try { try {
file = fileIO.openSync(fpath, fileIO.OpenMode.READ_WRITE); fileIO.truncateSync(-1, truncateLen);
expect(isIntNum(file.fd)).assertTrue(); expect(false).assertTrue();
fileIO.truncateSync(file.fd, truncateLen);
let len = fileIO.readSync(file.fd, new ArrayBuffer(4096));
expect(len == truncateLen).assertTrue();
fileio.closeSync(file.fd);
fileio.unlinkSync(fpath);
} catch (e) { } catch (e) {
console.log('fileIO_test_truncate_sync_003 has failed for ' + e.message + ', code: ' + e.code); console.log('fileIO_test_truncate_sync_003 has failed for ' + e.message + ', code: ' + e.code);
expect(false).assertTrue(); expect(e.code == 13900020 && e.message == 'Invalid argument').assertTrue();
} }
}); });
/** /**
* @tc.number SUB_DF_FILEIO_TRUNCATE_SYNC_0400 * @tc.number SUB_DF_FILEIO_TRUNCATE_SYNC_0400
* @tc.name fileIO_test_truncate_sync_004 * @tc.name fileIO_test_truncate_sync_004
* @tc.desc Test truncateSync() interfaces. * @tc.desc Test truncateSync() interfaces. Missing parameters.
* @tc.size MEDIUM * @tc.size MEDIUM
* @tc.type Functoin * @tc.type Functoin
* @tc.level Level 0 * @tc.level Level 0
* @tc.require * @tc.require
*/ */
it('fileIO_test_truncate_sync_004', 0, function () { it('fileIO_test_truncate_sync_004', 0, function () {
try { try {
let stat = fileIO.truncateSync(); fileIO.truncateSync();
console.info('fileIO_test_truncate_sync_004 = ' + stat);
expect(false).assertTrue(); expect(false).assertTrue();
} catch (e) { } catch (e) {
console.log('fileIO_test_truncate_sync_004 has failed for ' + e.message + ', code: ' + e.code);
expect(e.code == 13900020 && e.message == 'Invalid argument').assertTrue(); expect(e.code == 13900020 && e.message == 'Invalid argument').assertTrue();
} }
}); });
})
/**
* @tc.number SUB_DF_FILEIO_TRUNCATE_SYNC_0500
* @tc.name fileIO_test_truncate_sync_005
* @tc.desc Test truncateSync() interfaces.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it('fileIO_test_truncate_sync_005', 0, async function () {
let fpath = await nextFileName('fileIO_test_truncate_sync_005');
let truncateLen = 2;
try {
fileIO.truncateSync(fpath, truncateLen);
} catch (e) {
console.log('fileIO_test_truncate_sync_005 has failed for ' + e.message + ', code: ' + e.code);
expect(!!e).assertTrue();
}
});
});
} }
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册