提交 d2c0c91d 编写于 作者: F fengjunqing

mod_fileio新增XTS支持option传入undefined

Signed-off-by: Nfengjunqing <fengjunqing@huawei.com>
上级 6440cfd4
......@@ -1146,10 +1146,11 @@ export default function fileIOTest() {
it('fileio_test_close_sync_001', 0, async function () {
try {
fileio.closeSync(-1);
expect(false).assertTrue();
}
catch (err) {
console.info('fileio_test_close_sync_001 has failed for ' + err);
expect(err.message == "Bad file descriptor").assertTrue();
expect(err.message == "Invalid fd").assertTrue();
}
});
......@@ -1548,10 +1549,11 @@ export default function fileIOTest() {
it('fileio_test_write_sync_008', 0, async function () {
try {
fileio.writeSync(-1, FILE_CONTENT);
expect(false).assertTrue();
}
catch (err) {
console.info('fileio_test_write_sync_008 has failed for ' + err);
expect(err.message == "Bad file descriptor").assertTrue();
expect(err.message == "Invalid fd").assertTrue();
}
});
......@@ -1691,7 +1693,7 @@ export default function fileIOTest() {
fileio.closeSync(fd);
fileio.unlinkSync(fpath);
console.info('fileio_test_read_sync_004 has failed for ' + err);
expect(err.message == "Invalid option.length, buffer limit exceeded").assertTrue();
expect(err.message == "Invalid option.length").assertTrue();
}
});
......@@ -1706,7 +1708,7 @@ export default function fileIOTest() {
}
catch (err) {
console.info('fileio_test_read_sync_005 has failed for ' + err);
expect(err.message == "Bad file descriptor").assertTrue();
expect(err.message == "Invalid fd").assertTrue();
}
});
......@@ -2201,7 +2203,7 @@ export default function fileIOTest() {
/**
* @tc.number SUB_STORAGE_FileIO_copyFileSync_0200
* @tc.name fileio_test_copy_file_sync_002
* @tc.desc Function of API, copy. fpatch is vaild, fpathTarget is invalid.
* @tc.desc Function of API, copyFileSync. fpath is vaild, fpathTarget is invalid.
*/
it('fileio_test_copy_file_sync_002', 0, async function () {
let fpath = await nextFileName('fileio_test_copy_file_sync_002');
......@@ -2210,7 +2212,7 @@ export default function fileIOTest() {
}
catch (err) {
console.info('fileio_test_copy_file_sync_002 has failed for ' + err);
expect(err.message == "No such file or directory").assertTrue();
expect(err.message == "The first/second argument requires filepath/fd").assertTrue();
}
});
......@@ -2298,7 +2300,7 @@ export default function fileIOTest() {
fileio.copyFileSync(-1, -1);
} catch (err) {
console.info('fileio_test_copy_file_sync_007 has failed for ' + err);
expect(err.message == "Invalid argument" || err.message == "Bad file descriptor").assertTrue();
expect(err.message == "The first/second argument requires filepath/fd").assertTrue();
}
});
......@@ -3117,7 +3119,7 @@ export default function fileIOTest() {
fileio.ftruncateSync(-1);
}catch (err) {
console.info('fileio_test_ftruncate_sync_003 has failed for ' + err);
expect(err.message == "Bad file descriptor").assertTrue();
expect(err.message == "Invalid fd").assertTrue();
}
});
......@@ -3182,10 +3184,11 @@ export default function fileIOTest() {
it('fileio_test_fsync_sync_002', 0, async function () {
try {
fileio.fsyncSync(-1);
expect(false).assertTrue();
}
catch (err) {
console.info('fileio_test_fsync_sync_002 has failed for ' + err);
expect(err.message == "Bad file descriptor").assertTrue();
expect(err.message == "Invalid fd").assertTrue();
}
});
......@@ -3518,10 +3521,11 @@ export default function fileIOTest() {
*/
it('fileio_test_fstat_sync_001', 0, async function () {
try {
expect(fileio.fstatSync(-1) !== null).assertTrue();
fileio.fstatSync(-1);
expect(false).assertTrue();
}catch (err) {
console.info('fileio_test_fstat_sync_001 has failed for ' + err);
expect(err.message == "Bad file descriptor").assertTrue();
expect(err.message == "Invalid fd").assertTrue();
}
});
......
......@@ -290,7 +290,7 @@ describe('fileio_randomAccessFile_read', function () {
/**
* @tc.number SUB_STORAGE_FILEIO_RANDOMACCESSFILE_READ_SYNC_1000
* @tc.name fileio_randomaccessfile_read_sync_010
* @tc.desc Test readSync() interface. When the length is negative,equivalent to omitting the parameter.
* @tc.desc Test readSync() interface. The "length" of option must > 0.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
......@@ -298,20 +298,21 @@ describe('fileio_randomAccessFile_read', function () {
*/
it('fileio_randomaccessfile_read_sync_010', 0, async function () {
let fpath = await nextFileName('fileio_randomaccessfile_read_sync_010');
let randomaccessfile;
try {
let randomaccessfile = fileio.createRandomAccessFileSync(fpath, 0, 0o102);
randomaccessfile = fileio.createRandomAccessFileSync(fpath, 0, 0o102);
let length = 4096;
let num = randomaccessfile.writeSync(new ArrayBuffer(length));
expect(num == length).assertTrue();
randomaccessfile.setFilePointerSync(0);
let number = randomaccessfile.readSync(new ArrayBuffer(16), { offset: 13, length: -1 });
expect(number == 3).assertTrue();
randomaccessfile.readSync(new ArrayBuffer(16), { offset: 13, length: -1 });
expect(false).assertTrue();
} catch (err) {
randomaccessfile.closeSync();
fileio.unlinkSync(fpath);
} catch (err) {
console.info('fileio_randomaccessfile_read_sync_010 has failed for ' + err);
expect(null).assertFail();
expect(err.message == "Invalid buffer/options").assertTrue();
}
});
......@@ -674,7 +675,7 @@ describe('fileio_randomAccessFile_read', function () {
/**
* @tc.number SUB_STORAGE_FILEIO_RANDOMACCESSFILE_READ_ASYNC_1000
* @tc.name fileio_randomaccessfile_read_async_010
* @tc.desc Test read() interface. When the length is negative,equivalent to omitting the parameter.
* @tc.desc Test read() interface. The "length" of option must > 0.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
......@@ -682,21 +683,22 @@ describe('fileio_randomAccessFile_read', function () {
*/
it('fileio_randomaccessfile_read_async_010', 0, async function (done) {
let fpath = await nextFileName('fileio_randomaccessfile_read_async_010');
let randomaccessfile;
try {
let randomaccessfile = await fileio.createRandomAccessFile(fpath, 0, 0o102);
randomaccessfile = await fileio.createRandomAccessFile(fpath, 0, 0o102);
let length = 4096;
let num = randomaccessfile.writeSync(new ArrayBuffer(length));
expect(num == length).assertTrue();
randomaccessfile.setFilePointerSync(0);
let readOut = await randomaccessfile.read(new ArrayBuffer(16), { offset: 13, length: -1 });
expect(readOut.bytesRead == 3).assertTrue();
await randomaccessfile.read(new ArrayBuffer(16), { offset: 13, length: -1 });
expect(false).assertTrue();
} catch (err) {
randomaccessfile.closeSync();
fileio.unlinkSync(fpath);
done();
} catch (err) {
console.info('fileio_randomaccessfile_read_async_010 has failed for ' + err);
expect(null).assertFail();
expect(err.message == "Invalid buffer/options").assertTrue();
done();
}
});
......
......@@ -282,7 +282,7 @@ describe('fileio_randomAccessFile_write', function () {
/**
* @tc.number SUB_STORAGE_FILEIO_RANDOMACCESSFILE_WRITE_SYNC_1000
* @tc.name fileio_randomaccessfile_write_sync_010
* @tc.desc Test writeSync() interface. When the length is negative,equivalent to omitting the parameter.
* @tc.desc Test writeSync() interface. The "length" of option must > 0.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
......@@ -290,17 +290,18 @@ describe('fileio_randomAccessFile_write', function () {
*/
it('fileio_randomaccessfile_write_sync_010', 0, async function () {
let fpath = await nextFileName('fileio_randomaccessfile_write_sync_010');
let randomaccessfile;
try {
let randomaccessfile = fileio.createRandomAccessFileSync(fpath, 0, 0o102);
randomaccessfile = fileio.createRandomAccessFileSync(fpath, 0, 0o102);
let length = 100;
let num = randomaccessfile.writeSync(new ArrayBuffer(length), { offset: 1, length: -1 });
expect(num == length - 1).assertTrue();
randomaccessfile.writeSync(new ArrayBuffer(length), { offset: 1, length: -1 });
expect(false).assertTrue();
} catch(err) {
randomaccessfile.closeSync();
fileio.unlinkSync(fpath);
} catch(err) {
console.info('fileio_randomaccessfile_write_sync_010 has failed for ' + err);
expect(null).assertFail();
expect(err.message == "Invalid buffer/options").assertTrue();
}
});
......@@ -648,7 +649,7 @@ describe('fileio_randomAccessFile_write', function () {
/**
* @tc.number SUB_STORAGE_FILEIO_RANDOMACCESSFILE_WRITE_ASYNC_1000
* @tc.name fileio_randomaccessfile_write_async_010
* @tc.desc Test write() interface. When the length is negative,equivalent to omitting the parameter.
* @tc.desc Test write() interface. The "length" of option must > 0.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
......@@ -656,18 +657,19 @@ describe('fileio_randomAccessFile_write', function () {
*/
it('fileio_randomaccessfile_write_async_010', 0, async function (done) {
let fpath = await nextFileName('fileio_randomaccessfile_write_async_010');
let randomaccessfile;
try {
let randomaccessfile = await fileio.createRandomAccessFile(fpath, 0, 0o102);
randomaccessfile = await fileio.createRandomAccessFile(fpath, 0, 0o102);
let length = 100;
let num = await randomaccessfile.write(new ArrayBuffer(length), { offset: 1, length: -1 });
expect(num == length - 1).assertTrue();
await randomaccessfile.write(new ArrayBuffer(length), { offset: 1, length: -1 });
expect(false).assertTrue();
} catch(err) {
randomaccessfile.closeSync();
fileio.unlinkSync(fpath);
done();
} catch(err) {
console.info('fileio_randomaccessfile_write_async_010 has failed for ' + err);
expect(null).assertFail();
expect(err.message == "Invalid buffer/options").assertTrue();
done();
}
});
......
......@@ -242,7 +242,7 @@ describe('fileio_stream_1', function () {
});
} catch (err) {
console.info('fileio_test_stream_read_sync_005 has failed for ' + err);
expect(err.message == "Invalid option.length, buffer limit exceeded").assertTrue();
expect(err.message == "Invalid option.length").assertTrue();
ss.closeSync();
fileio.unlinkSync(fpath);
}
......
......@@ -21,6 +21,70 @@ import {
export default function fileioStreamRead() {
describe('fileio_stream_read', function () {
/**
* @tc.number SUB_DF_FILEIO_STREAM_READSYNC_0000
* @tc.name fileio_test_stream_read_sync_000
* @tc.desc Test Stream.readSync() interface.
* Undefined option arguments, use default options.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it('fileio_test_stream_read_sync_000', 3, async function () {
let fpath = await nextFileName('fileio_test_stream_read_sync_000');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
let sr = fileio.createStreamSync(fpath, 'r+');
expect(sr !== null).assertTrue();
let readLen1 = sr.readSync(new ArrayBuffer(16), undefined);
expect(readLen1 == FILE_CONTENT.length).assertTrue();
let readLen2 = sr.readSync(new ArrayBuffer(8), undefined);
expect(readLen2 == 0).assertTrue();
sr.closeSync();
fileio.unlinkSync(fpath);
} catch (e) {
console.log('fileio_test_stream_read_sync_000 has failed for ' + e);
expect(false).assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_STREAM_READSYNC_0100
* @tc.name fileio_test_stream_read_sync_001
* @tc.desc Test Stream.readSync() interface.
* Undefined option arguments, use default options.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it('fileio_test_stream_read_sync_001', 3, async function () {
let fpath = await nextFileName('fileio_test_stream_read_sync_001');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
let sr = fileio.createStreamSync(fpath, 'r+');
expect(sr !== null).assertTrue();
let readLen1 = sr.readSync(new ArrayBuffer(16), {
offset: undefined,
length: undefined
});
expect(readLen1 == FILE_CONTENT.length).assertTrue();
let readLen2 = sr.readSync(new ArrayBuffer(8), {
offset: undefined,
length: undefined
});
expect(readLen2 == 0).assertTrue();
sr.closeSync();
fileio.unlinkSync(fpath);
} catch (e) {
console.log('fileio_test_stream_read_sync_001 has failed for ' + e);
expect(false).assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_STREAM_READASYNC_0000
* @tc.name fileio_test_stream_read_async_000
......@@ -84,7 +148,7 @@ describe('fileio_stream_read', function () {
* @tc.level Level 0
* @tc.require
*/
it('fileio_test_stream_read_async_002', 0, async function (done) {
it('fileio_test_stream_read_async_002', 0, async function (done) {
let fpath = await nextFileName('fileio_test_stream_read_async_002');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
......@@ -115,7 +179,7 @@ describe('fileio_stream_read', function () {
* @tc.level Level 0
* @tc.require
*/
it('fileio_test_stream_read_async_003', 0, async function (done) {
it('fileio_test_stream_read_async_003', 0, async function (done) {
let fpath = await nextFileName('fileio_test_stream_read_async_003');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
......@@ -144,7 +208,7 @@ describe('fileio_stream_read', function () {
* @tc.level Level 0
* @tc.require
*/
it('fileio_test_stream_read_async_004', 0, async function (done) {
it('fileio_test_stream_read_async_004', 0, async function (done) {
let fpath = await nextFileName('fileio_test_stream_read_async_004');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
......@@ -180,7 +244,7 @@ describe('fileio_stream_read', function () {
* @tc.level Level 0
* @tc.require
*/
it('fileio_test_stream_read_async_005', 0, async function (done) {
it('fileio_test_stream_read_async_005', 0, async function (done) {
let fpath = await nextFileName('fileio_test_stream_read_async_005');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
let ss = fileio.createStreamSync(fpath, 'r+');
......@@ -189,7 +253,7 @@ describe('fileio_stream_read', function () {
await ss.read(new ArrayBuffer(4096), {offset: -1});
} catch (err) {
console.info('fileio_test_stream_read_async_005 has failed for ' + err);
expect(err.message == "Failed GetReadArg").assertTrue();
expect(err.message == "Invalid option.offset, positive integer is desired").assertTrue();
ss.closeSync();
fileio.unlinkSync(fpath);
done();
......@@ -205,7 +269,7 @@ describe('fileio_stream_read', function () {
* @tc.level Level 0
* @tc.require
*/
it('fileio_test_stream_read_async_006', 0, async function (done) {
it('fileio_test_stream_read_async_006', 0, async function (done) {
let fpath = await nextFileName('fileio_test_stream_read_async_006');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
let ss = fileio.createStreamSync(fpath, 'r+');
......@@ -214,7 +278,7 @@ describe('fileio_stream_read', function () {
await ss.read(new ArrayBuffer(4096), {offset: 1,length:4096});
} catch (err) {
console.info('fileio_test_stream_read_async_006 has failed for ' + err);
expect(err.message == "Failed GetReadArg").assertTrue();
expect(err.message == "Invalid option.length").assertTrue();
ss.closeSync();
fileio.unlinkSync(fpath);
done();
......@@ -230,7 +294,7 @@ describe('fileio_stream_read', function () {
* @tc.level Level 0
* @tc.require
*/
it('fileio_test_stream_read_async_007', 0, async function (done) {
it('fileio_test_stream_read_async_007', 0, async function (done) {
let fpath = await nextFileName('fileio_test_stream_read_async_007');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
let ss = fileio.createStreamSync(fpath, 'r+');
......@@ -239,7 +303,7 @@ describe('fileio_stream_read', function () {
await ss.read(new ArrayBuffer(4096), {offset: 4097});
} catch (err) {
console.info('fileio_test_stream_read_async_007 has failed for ' + err);
expect(err.message == "Failed GetReadArg").assertTrue();
expect(err.message == "Invalid option.offset, buffer limit exceeded").assertTrue();
ss.closeSync();
fileio.unlinkSync(fpath);
done();
......@@ -255,7 +319,7 @@ describe('fileio_stream_read', function () {
* @tc.level Level 0
* @tc.require
*/
it('fileio_test_stream_read_async_008', 0, async function (done) {
it('fileio_test_stream_read_async_008', 0, async function (done) {
let fpath = await nextFileName('fileio_test_stream_read_async_008');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
let ss = fileio.createStreamSync(fpath, 'r+');
......@@ -264,7 +328,7 @@ describe('fileio_stream_read', function () {
await ss.read(new ArrayBuffer(4096), {length: 4097});
} catch (err) {
console.info('fileio_test_stream_read_async_008 has failed for ' + err);
expect(err.message == "Failed GetReadArg").assertTrue();
expect(err.message == "Invalid option.length").assertTrue();
ss.closeSync();
fileio.unlinkSync(fpath);
done();
......@@ -280,19 +344,21 @@ describe('fileio_stream_read', function () {
* @tc.level Level 0
* @tc.require
*/
it('fileio_test_stream_read_async_009', 0, async function (done) {
it('fileio_test_stream_read_async_009', 0, async function (done) {
let fpath = await nextFileName('fileio_test_stream_read_async_009');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
let ss = fileio.createStreamSync(fpath, 'r+');
expect(ss !== null).assertTrue();
try {
let readout = await ss.read(new ArrayBuffer(16), {offset:13, length: -1});
expect(readout.bytesRead == 3).assertTrue();
expect(ss !== null).assertTrue();
await ss.read(new ArrayBuffer(16), {offset:13, length: -1});
expect(false).assertTrue();
} catch (err) {
ss.closeSync();
fileio.unlinkSync(fpath);
done();
} catch (err) {
console.info('fileio_test_stream_read_async_009 has failed for ' + err);
expect(err.message == "Invalid option.length").assertTrue();
done();
}
});
......@@ -305,21 +371,21 @@ describe('fileio_stream_read', function () {
* @tc.level Level 0
* @tc.require
*/
it('fileio_test_stream_read_async_010', 0, async function (done) {
let fpath = await nextFileName('fileio_test_stream_read_async_010');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
let ss = fileio.createStreamSync(fpath, 'r+');
expect(ss !== null).assertTrue();
try {
await ss.read();
} catch (err) {
console.info('fileio_test_stream_read_async_010 has failed for ' + err);
expect(err.message == "Number of arguments unmatched").assertTrue();
ss.closeSync();
fileio.unlinkSync(fpath);
done();
}
});
it('fileio_test_stream_read_async_010', 0, async function (done) {
let fpath = await nextFileName('fileio_test_stream_read_async_010');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
let ss = fileio.createStreamSync(fpath, 'r+');
expect(ss !== null).assertTrue();
try {
await ss.read();
} catch (err) {
console.info('fileio_test_stream_read_async_010 has failed for ' + err);
expect(err.message == "Number of arguments unmatched").assertTrue();
ss.closeSync();
fileio.unlinkSync(fpath);
done();
}
});
/**
* @tc.number SUB_DF_FILEIO_STREAM_READASYNC_1100
......@@ -330,23 +396,24 @@ describe('fileio_stream_read', function () {
* @tc.level Level 0
* @tc.require
*/
it('fileio_test_stream_read_async_011', 0, async function (done) {
let fpath = await nextFileName('fileio_test_stream_read_async_011');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
let ss = fileio.createStreamSync(fpath, 'r+');
expect(ss !== null).assertTrue();
try {
let readout = await ss.read(new ArrayBuffer(4096), {length: FILE_CONTENT.length+1});
expect(readout.bytesRead == FILE_CONTENT.length).assertTrue();
ss.closeSync();
fileio.unlinkSync(fpath);
done();
} catch (err) {
console.info('fileio_test_stream_read_async_011 has failed for ' + err);
}
});
it('fileio_test_stream_read_async_011', 0, async function (done) {
let fpath = await nextFileName('fileio_test_stream_read_async_011');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
let ss = fileio.createStreamSync(fpath, 'r+');
expect(ss !== null).assertTrue();
try {
let readout = await ss.read(new ArrayBuffer(4096), {length: FILE_CONTENT.length+1});
expect(readout.bytesRead == FILE_CONTENT.length).assertTrue();
ss.closeSync();
fileio.unlinkSync(fpath);
done();
} catch (err) {
console.info('fileio_test_stream_read_async_011 has failed for ' + err);
expect(false).assertTrue();
}
});
/**
/**
* @tc.number SUB_DF_FILEIO_STREAM_READASYNC_1200
* @tc.name fileio_test_stream_read_async_012
* @tc.desc Test read() interface, When the position is negative.
......@@ -355,7 +422,7 @@ describe('fileio_stream_read', function () {
* @tc.level Level 0
* @tc.require
*/
it('fileio_test_stream_read_async_012', 0, async function (done) {
it('fileio_test_stream_read_async_012', 0, async function (done) {
let fpath = await nextFileName('fileio_test_stream_read_async_012');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
let ss = fileio.createStreamSync(fpath, 'r+');
......@@ -364,14 +431,14 @@ describe('fileio_stream_read', function () {
await ss.read(new ArrayBuffer(4096), {position:-1});
} catch (err) {
console.info('fileio_test_stream_read_async_012 has failed for ' + err);
expect(err.message == "Failed GetReadArg").assertTrue();
expect(err.message == "option.position shall be positive number").assertTrue();
ss.closeSync();
fileio.unlinkSync(fpath);
done();
}
});
/**
/**
* @tc.number SUB_DF_FILEIO_STREAM_READASYNC_1300
* @tc.name fileio_test_stream_read_async_013
* @tc.desc Test read() interface,When the parameter type is wrong.
......@@ -380,20 +447,182 @@ describe('fileio_stream_read', function () {
* @tc.level Level 0
* @tc.require
*/
it('fileio_test_stream_read_async_013', 0, async function (done) {
let fpath = await nextFileName('fileio_test_stream_read_async_013');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
let ss = fileio.createStreamSync(fpath, 'r+');
expect(ss !== null).assertTrue();
try {
await ss.read("");
} catch (err) {
console.info('fileio_test_stream_read_async_013 has failed for ' + err);
expect(err.message == "Failed GetReadArg").assertTrue();
ss.closeSync();
fileio.unlinkSync(fpath);
done();
}
});
it('fileio_test_stream_read_async_013', 0, async function (done) {
let fpath = await nextFileName('fileio_test_stream_read_async_013');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
let ss = fileio.createStreamSync(fpath, 'r+');
expect(ss !== null).assertTrue();
try {
await ss.read("");
} catch (err) {
console.info('fileio_test_stream_read_async_013 has failed for ' + err);
expect(err.message == "Invalid read buffer, expect arraybuffer").assertTrue();
ss.closeSync();
fileio.unlinkSync(fpath);
done();
}
});
/**
* @tc.number SUB_DF_FILEIO_STREAM_READ_ASYNC_1400
* @tc.name fileio_test_stream_read_async_014
* @tc.desc Test the read() interface of class Stream. Promise.
* Undefined option arguments, use default options.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it('fileio_test_stream_read_async_014', 3, async function (done) {
let fpath = await nextFileName('fileio_test_stream_read_async_014');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
let sr = fileio.createStreamSync(fpath, 'r+');
expect(sr !== null).assertTrue();
let readRes1 = await sr.read(new ArrayBuffer(16), undefined);
expect(readRes1.bytesRead == FILE_CONTENT.length).assertTrue();
expect(readRes1.offset == 0).assertTrue();
let readRes2 = await sr.read(new ArrayBuffer(8), undefined);
expect(readRes2.bytesRead == 0).assertTrue();
expect(readRes2.offset == 0).assertTrue();
sr.closeSync();
fileio.unlinkSync(fpath);
done();
} catch (e) {
console.log('fileio_test_stream_read_async_014 has failed for ' + e);
expect(false).assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_STREAM_READ_ASYNC_1500
* @tc.name fileio_test_stream_read_async_015
* @tc.desc Test the read() interface of class Stream. Callback.
* Undefined option arguments, use default options.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it('fileio_test_stream_read_async_015', 3, async function (done) {
let fpath = await nextFileName('fileio_test_stream_read_async_015');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
let sr = fileio.createStreamSync(fpath, 'r+');
expect(sr !== null).assertTrue();
sr.read(new ArrayBuffer(16), undefined, (err, readRes1) => {
if (err) {
console.log('fileio_test_stream_read_async_015 error package1: ' + JSON.stringify(err));
expect(false).assertTrue();
}
expect(readRes1.bytesRead == FILE_CONTENT.length).assertTrue();
expect(readRes1.offset == 0).assertTrue();
sr.read(new ArrayBuffer(8), undefined, (err, readRes2) => {
if (err) {
console.log('fileio_test_stream_read_async_015 error package2: ' + JSON.stringify(err));
expect(false).assertTrue();
}
expect(readRes2.bytesRead == 0).assertTrue();
expect(readRes2.offset == 0).assertTrue();
sr.closeSync();
fileio.unlinkSync(fpath);
done();
});
});
} catch (e) {
console.log('fileio_test_stream_read_async_015 has failed for ' + e);
expect(false).assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_STREAM_READ_ASYNC_1600
* @tc.name fileio_test_stream_read_async_016
* @tc.desc Test the read() interface of class Stream. Promise.
* Undefined option arguments, use default options.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it('fileio_test_stream_read_async_016', 3, async function (done) {
let fpath = await nextFileName('fileio_test_stream_read_async_016');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
let sr = fileio.createStreamSync(fpath, 'r+');
expect(sr !== null).assertTrue();
let readRes1 = await sr.read(new ArrayBuffer(16), {
position: undefined,
offset: undefined,
length: undefined
});
expect(readRes1.bytesRead == FILE_CONTENT.length).assertTrue();
expect(readRes1.offset == 0).assertTrue();
let readRes2 = await sr.read(new ArrayBuffer(8), {
offset: undefined,
length: undefined
});
expect(readRes2.bytesRead == 0).assertTrue();
expect(readRes2.offset == 0).assertTrue();
sr.closeSync();
fileio.unlinkSync(fpath);
done();
} catch (e) {
console.log('fileio_test_stream_read_async_016 has failed for ' + e);
expect(false).assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_STREAM_READ_ASYNC_1700
* @tc.name fileio_test_stream_read_async_017
* @tc.desc Test the read() interface of class Stream. Callback.
* Undefined option arguments, use default options.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it('fileio_test_stream_read_async_017', 3, async function (done) {
let fpath = await nextFileName('fileio_test_stream_read_async_017');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
let sr = fileio.createStreamSync(fpath, 'r+');
expect(sr !== null).assertTrue();
sr.read(new ArrayBuffer(4096), {
position: undefined,
offset: undefined,
length: undefined
}, (err, readRes1) => {
if (err) {
console.log('fileio_test_stream_read_async_017 error package1: ' + JSON.stringify(err));
expect(false).assertTrue();
}
expect(readRes1.bytesRead == FILE_CONTENT.length).assertTrue();
expect(readRes1.offset == 0).assertTrue();
sr.read(new ArrayBuffer(8), {
offset: undefined,
length: undefined
}, (err, readRes2) => {
if (err) {
console.log('fileio_test_stream_read_async_017 error package2: ' + JSON.stringify(err));
expect(false).assertTrue();
}
expect(readRes2.bytesRead == 0).assertTrue();
expect(readRes2.offset == 0).assertTrue();
sr.closeSync();
fileio.unlinkSync(fpath);
done();
});
});
} catch (e) {
console.log('fileio_test_stream_read_async_017 has failed for ' + e);
expect(false).assertTrue();
}
});
});
}
......@@ -21,6 +21,76 @@ import {
export default function fileioStreamWrite() {
describe('fileio_stream_write', function () {
/**
* @tc.number SUB_DF_FILEIO_STREAM_WRITE_SYNC_0000
* @tc.name fileio_test_stream_write_sync_000
* @tc.desc Test the writeSync() interface of class Stream.
* Undefined option arguments, use default options.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it('fileio_test_stream_write_sync_000', 3, async function () {
let fpath = await nextFileName('fileio_test_stream_write_sync_000');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
let sr = fileio.createStreamSync(fpath, 'r+');
expect(sr !== null).assertTrue();
let bytesWritten1 = sr.writeSync(FILE_CONTENT, undefined);
expect(bytesWritten1 == FILE_CONTENT.length).assertTrue();
let bytesWritten2 = sr.writeSync(new ArrayBuffer(FILE_CONTENT.length), undefined);
expect(bytesWritten2 == FILE_CONTENT.length).assertTrue();
let readLen = sr.readSync(new ArrayBuffer(4096), { position: 0 });
expect(readLen == FILE_CONTENT.length * 2).assertTrue();
sr.closeSync();
fileio.unlinkSync(fpath);
} catch (e) {
console.log('fileio_test_stream_write_sync_000 has failed for ' + e);
expect(false).assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_STREAM_WRITE_SYNC_0100
* @tc.name fileio_test_stream_write_sync_001
* @tc.desc Test the writeSync() interface of class Stream.
* Undefined option arguments, use default options.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it('fileio_test_stream_write_sync_001', 3, async function () {
let fpath = await nextFileName('fileio_test_stream_write_sync_001');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
let sr = fileio.createStreamSync(fpath, 'r+');
expect(sr !== null).assertTrue();
let bytesWritten1 = sr.writeSync(FILE_CONTENT, {
offset: undefined,
length: undefined,
encoding: undefined
});
expect(bytesWritten1 == FILE_CONTENT.length).assertTrue();
let bytesWritten2 = sr.writeSync(new ArrayBuffer(FILE_CONTENT.length), {
offset: undefined,
length: undefined,
encoding: undefined
});
expect(bytesWritten2 == FILE_CONTENT.length).assertTrue();
let readLen = sr.readSync(new ArrayBuffer(4096), { position: 0 });
expect(readLen == FILE_CONTENT.length * 2).assertTrue();
sr.closeSync();
fileio.unlinkSync(fpath);
} catch (e) {
console.log('fileio_test_stream_write_sync_001 has failed for ' + e);
expect(false).assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_STREAM_WRITEASYNC_0000
* @tc.name fileio_test_stream_write_async_000
......@@ -223,7 +293,7 @@ describe('fileio_stream_write', function () {
done();
} catch (err) {
console.info('fileio_test_stream_write_async_006 has failed for ' + err);
expect(err.message == "Invalid option.length, buffer limit exceeded").assertTrue();
expect(err.message == "Invalid option.length").assertTrue();
fileio.unlinkSync(fpath);
ss.closeSync();
done();
......@@ -349,13 +419,14 @@ describe('fileio_stream_write', function () {
expect(ss !== null).assertTrue();
try {
let content = "hello, world";
let number = await ss.write(content, {offset:1 ,length:-1});
expect(number == content.length-1).assertTrue();
fileio.unlinkSync(fpath);
ss.closeSync();
done();
await ss.write(content, {offset:1 ,length:-1});
expect(false).assertTrue();
} catch (err) {
ss.closeSync();
fileio.unlinkSync(fpath);
console.info('fileio_test_stream_write_async_011 has failed for ' + err);
expect(err.message == "Invalid option.length").assertTrue();
done();
}
});
......@@ -404,7 +475,7 @@ describe('fileio_stream_write', function () {
await ss.write(new ArrayBuffer(4096), {length:4097});
} catch (err) {
console.info('fileio_test_stream_write_async_013 has failed for ' + err);
expect(err.message == "Invalid option.length, buffer limit exceeded").assertTrue();
expect(err.message == "Invalid option.length").assertTrue();
fileio.unlinkSync(fpath);
ss.closeSync();
done();
......@@ -430,7 +501,7 @@ describe('fileio_stream_write', function () {
await ss.write(content,{length:content.length+1});
} catch (err) {
console.info('fileio_test_stream_write_async_014 has failed for ' + err);
expect(err.message == "Invalid option.length, buffer limit exceeded").assertTrue();
expect(err.message == "Invalid option.length").assertTrue();
fileio.unlinkSync(fpath);
ss.closeSync();
done();
......@@ -462,5 +533,169 @@ describe('fileio_stream_write', function () {
done();
}
});
/**
* @tc.number SUB_DF_FILEIO_STREAM_WRITE_ASYNC_1600
* @tc.name fileio_test_stream_write_async_016
* @tc.desc Test the write() interface of class Stream. Promise.
* Undefined option arguments, use default options.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it('fileio_test_stream_write_async_016', 3, async function (done) {
let fpath = await nextFileName('fileio_test_stream_write_async_016');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
let sr = fileio.createStreamSync(fpath, 'r+');
expect(sr !== null).assertTrue();
let bytesWritten1 = await sr.write(FILE_CONTENT, undefined);
expect(bytesWritten1 == FILE_CONTENT.length).assertTrue();
let bytesWritten2 = await sr.write(new ArrayBuffer(FILE_CONTENT.length), undefined);
expect(bytesWritten2 == FILE_CONTENT.length).assertTrue();
let readLen = sr.readSync(new ArrayBuffer(4096), { position: 0 });
expect(readLen == FILE_CONTENT.length * 2).assertTrue();
sr.closeSync();
fileio.unlinkSync(fpath);
done();
} catch (e) {
console.log('fileio_test_stream_write_async_016 has failed for ' + e.message + ', code: ' + e.code);
expect(false).assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_STREAM_WRITE_ASYNC_1700
* @tc.name fileio_test_stream_write_async_017
* @tc.desc Test the write() interface of class Stream. Callback.
* Undefined option arguments, use default options.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it('fileio_test_stream_write_async_017', 3, async function (done) {
let fpath = await nextFileName('fileio_test_stream_write_async_017');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
let sr = fileio.createStreamSync(fpath, 'r+');
expect(sr !== null).assertTrue();
sr.write(FILE_CONTENT, undefined, (err, bytesWritten1) => {
if (err) {
console.log('fileio_test_stream_write_async_017 err package1: ' + JSON.stringify(err));
expect(false).assertTrue();
}
expect(bytesWritten1 == FILE_CONTENT.length).assertTrue();
sr.write(new ArrayBuffer(FILE_CONTENT.length), undefined, (err, bytesWritten2) => {
if (err) {
console.log('fileio_test_stream_write_async_017 err package2: ' + JSON.stringify(err));
expect(false).assertTrue();
}
expect(bytesWritten2 == FILE_CONTENT.length).assertTrue();
let readLen = sr.readSync(new ArrayBuffer(4096), { position: 0 });
expect(readLen == FILE_CONTENT.length * 2).assertTrue();
sr.closeSync();
fileio.unlinkSync(fpath);
done();
});
});
} catch (e) {
console.log('fileio_test_stream_write_async_017 has failed for ' + e);
expect(false).assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_STREAM_WRITE_ASYNC_1800
* @tc.name fileio_test_stream_write_async_018
* @tc.desc Test the write() interface of class Stream. Promise.
* Undefined option arguments, use default options.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it('fileio_test_stream_write_async_018', 3, async function (done) {
let fpath = await nextFileName('fileio_test_stream_write_async_018');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
let sr = fileio.createStreamSync(fpath, 'r+');
expect(sr !== null).assertTrue();
let bytesWritten1 = await sr.write(FILE_CONTENT, {
offset: undefined,
length: undefined,
encoding: undefined
});
expect(bytesWritten1 == FILE_CONTENT.length).assertTrue();
let bytesWritten2 = await sr.write(new ArrayBuffer(FILE_CONTENT.length), {
offset: undefined,
length: undefined,
encoding: undefined
});
expect(bytesWritten2 == FILE_CONTENT.length).assertTrue();
let readLen = sr.readSync(new ArrayBuffer(4096), { position: 0 });
expect(readLen == FILE_CONTENT.length * 2).assertTrue();
sr.closeSync();
fileio.unlinkSync(fpath);
done();
} catch (e) {
console.log('fileio_test_stream_write_async_018 has failed for ' + e);
expect(false).assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_STREAM_WRITE_ASYNC_1900
* @tc.name fileio_test_stream_write_async_019
* @tc.desc Test the write() interface of class Stream. Callback.
* Undefined option arguments, use default options.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it('fileio_test_stream_write_async_019', 3, async function (done) {
let fpath = await nextFileName('fileio_test_stream_write_async_019');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
let sr = fileio.createStreamSync(fpath, 'r+');
expect(sr !== null).assertTrue();
sr.write(FILE_CONTENT, {
offset: undefined,
length: undefined,
encoding: undefined
}, (err, bytesWritten1) => {
if (err) {
console.log('fileio_test_stream_write_async_019 err package1: ' + JSON.stringify(err));
expect(false).assertTrue();
}
expect(bytesWritten1 == FILE_CONTENT.length).assertTrue();
sr.write(new ArrayBuffer(FILE_CONTENT.length), {
offset: undefined,
length: undefined,
encoding: undefined
}, (err, bytesWritten2) => {
if (err) {
console.log('fileio_test_stream_write_async_019 err package2: ' + JSON.stringify(err));
expect(false).assertTrue();
}
expect(bytesWritten2 == FILE_CONTENT.length).assertTrue();
let readLen = sr.readSync(new ArrayBuffer(4096), { position: 0 });
expect(readLen == FILE_CONTENT.length * 2).assertTrue();
sr.closeSync();
fileio.unlinkSync(fpath);
done();
});
});
} catch (e) {
console.log('fileio_test_stream_write_async_019 has failed for ' + e);
expect(false).assertTrue();
}
});
});
}
......@@ -157,10 +157,33 @@ describe('fileio_access', function () {
}
});
/**
* @tc.number SUB_DF_FILEIO_ACCESSSYNC_0600
* @tc.name fileio_test_access_sync_006
* @tc.desc Test accessSync() interface.
* Undefined option arguments, use default mode = 0(Is file exist).
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it('fileio_test_access_sync_006', 3, async function () {
let fpath = await nextFileName('fileio_test_access_sync_006');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
fileio.accessSync(fpath, undefined);
fileio.unlinkSync(fpath);
} catch (err) {
console.info('fileio_test_access_sync_006 has failed for ' + err);
expect(false).assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_ACCESSASYNC_0000
* @tc.name fileio_test_access_async_000
* @tc.desc Test accessAsync() interface.
* @tc.desc Test access() interface. Promise.
* This interface shall work properly in normal case.
* @tc.size MEDIUM
* @tc.type Function
......@@ -184,7 +207,7 @@ describe('fileio_access', function () {
/**
* @tc.number SUB_DF_FILEIO_ACCESSASYNC_0100
* @tc.name fileio_test_access_async_001
* @tc.desc Test accessAsync() interface.
* @tc.desc Test access() interface. Promise.
* Use promise to test that the current process has read permission. Async method reads data from file.
* @tc.size MEDIUM
* @tc.type Function
......@@ -212,7 +235,7 @@ describe('fileio_access', function () {
/**
* @tc.number SUB_DF_FILEIO_ACCESSASYNC_0200
* @tc.name fileio_test_access_async_002
* @tc.desc Test accessAsync() interface.
* @tc.desc Test access() interface. Callback.
* Test file exists.
* @tc.size MEDIUM
* @tc.type Function
......@@ -237,7 +260,7 @@ describe('fileio_access', function () {
/**
* @tc.number SUB_DF_FILEIO_ACCESSASYNC_0300
* @tc.name fileio_test_access_async_003
* @tc.desc Test accessAsync() interface.
* @tc.desc Test access() interface. Callback.
* Use callback to test that the current process has read permission. Async method reads data from file.
* @tc.size MEDIUM
* @tc.type Function
......@@ -266,7 +289,7 @@ describe('fileio_access', function () {
/**
* @tc.number SUB_DF_FILEIO_ACCESSASYNC_0400
* @tc.name fileio_test_access_async_004
* @tc.desc Test accessAsync() interface.
* @tc.desc Test access() interface. Promise.
* Use promises to test that the current process has executable permissions.
* @tc.size MEDIUM
* @tc.type Function
......@@ -290,7 +313,7 @@ describe('fileio_access', function () {
/**
* @tc.number SUB_DF_FILEIO_ACCESSASYNC_0500
* @tc.name fileio_test_access_async_005
* @tc.desc Test accessAsync() interface.
* @tc.desc Test access() interface. Callback.
* Use callback to test that the current process has write permission.
* @tc.size MEDIUM
* @tc.type Function
......@@ -315,7 +338,7 @@ describe('fileio_access', function () {
/**
* @tc.number SUB_DF_FILEIO_ACCESSASYNC_0600
* @tc.name fileio_test_access_async_006
* @tc.desc Test accessAsync() interface.
* @tc.desc Test access() interface. Promise.
* Async test file does not exist.
* @tc.size MEDIUM
* @tc.type Function
......@@ -333,5 +356,58 @@ describe('fileio_access', function () {
done();
}
});
/**
* @tc.number SUB_DF_FILEIO_ACCESSASYNC_0700
* @tc.name fileio_test_access_async_007
* @tc.desc Test access() interface. Callback.
* Undefined option arguments, use default mode = 0(Is file exist).
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it('fileio_test_access_async_007', 3, async function (done) {
let fpath = await nextFileName('fileio_test_access_async_007');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
fileio.access(fpath, undefined, (error) => {
if (error) {
console.info('fileio_test_access_async_007 error: ' + err);
expect(flase).assertTrue();
}
fileio.unlinkSync(fpath);
done();
});
} catch (err) {
console.info('fileio_test_access_async_007 has failed for ' + err);
expect(flase).assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_ACCESSASYNC_0800
* @tc.name fileio_test_access_async_008
* @tc.desc Test access() interface. Promise.
* Undefined option arguments, use default mode = 0(Is file exist).
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it('fileio_test_access_async_008', 3, async function (done) {
let fpath = await nextFileName('fileio_test_access_async_008');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
await fileio.access(fpath, undefined);
fileio.unlinkSync(fpath);
done();
} catch (err) {
console.info('fileio_test_access_async_008 has failed for ' + err);
expect(flase).assertTrue();
}
});
});
}
......@@ -74,9 +74,10 @@ describe('fileio_close', function () {
it('fileio_test_close_sync_002', 0, function () {
try {
fileio.closeSync(-1);
expect(false).assertTrue();
} catch (e) {
console.info('fileio_test_close_sync_002 has failed for ' + e);
expect(e.message == 'Bad file descriptor').assertTrue();
expect(e.message == 'Invalid fd').assertTrue();
}
})
......@@ -167,9 +168,10 @@ describe('fileio_close', function () {
it('fileio_test_close_async_003', 0, async function (done) {
try {
await fileio.close(-1);
expect(false).assertTrue();
} catch (e) {
console.info('fileio_test_close_async_003 has failed for ' + e);
expect(e.message == "Bad file descriptor").assertTrue();
expect(e.message == "Invalid fd").assertTrue();
done();
}
})
......
......@@ -111,10 +111,37 @@ describe('fileio_copyfile', function () {
}
});
/**
* @tc.number SUB_DF_FILEIO_COPY_FILE_SYNC_0400
* @tc.name fileio_copy_file_sync_004
* @tc.desc Test copyFileSync() interfaces, No parameters.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it('fileio_copy_file_sync_004', 3, async function () {
let fpath = await nextFileName('fileio_copy_file_sync_004');
let fpathTarget = fpath + 'tgt';
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
fileio.copyFileSync(fpath, fpathTarget, undefined);
let stat1 = fileio.statSync(fpath);
let stat2 = fileio.statSync(fpathTarget);
expect(stat1.size == stat2.size).assertTrue();
fileio.unlinkSync(fpath);
fileio.unlinkSync(fpathTarget);
} catch (e) {
console.log('fileio_copy_file_sync_004 has failed for ' + e);
expect(false).assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_COPY_FILE_ASYNC_0000
* @tc.name fileio_copy_file_async_000
* @tc.desc Test copyFileAsync() interfaces, return in promise mode. Test file copied successfully.
* @tc.desc Test copyFile() interfaces, return in promise mode. Test file copied successfully.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
......@@ -140,7 +167,7 @@ describe('fileio_copyfile', function () {
/**
* @tc.number SUB_DF_FILEIO_COPY_FILE_ASYNC_0100
* @tc.name fileio_copy_file_async_001
* @tc.desc Test copyFileAsync() interfaces, return in callback mode. Test file copied successfully.
* @tc.desc Test copyFile() interfaces, return in callback mode. Test file copied successfully.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
......@@ -167,7 +194,7 @@ describe('fileio_copyfile', function () {
/**
* @tc.number SUB_DF_FILEIO_COPY_FILE_ASYNC_0200
* @tc.name fileio_copy_file_async_002
* @tc.desc Test copyFileAsync() interfaces, return in promise mode. Test file copied successfully.
* @tc.desc Test copyFile() interfaces, return in promise mode. Test file copied successfully.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
......@@ -194,7 +221,7 @@ describe('fileio_copyfile', function () {
/**
* @tc.number SUB_DF_FILEIO_COPY_FILE_ASYNC_0300
* @tc.name fileio_copy_file_async_003
* @tc.desc Test copyFileAsync() interfaces, Invalid path.
* @tc.desc Test copyFile() interfaces, Invalid path.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
......@@ -215,7 +242,7 @@ describe('fileio_copyfile', function () {
/**
* @tc.number SUB_DF_FILEIO_COPY_FILE_ASYNC_0400
* @tc.name fileio_copy_file_async_004
* @tc.desc Test copyFileAsync() interfaces. Invalid argument.
* @tc.desc Test copyFile() interfaces. Invalid argument fd < 0.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
......@@ -227,7 +254,7 @@ describe('fileio_copyfile', function () {
await fileio.copyFile(-1, fpath);
} catch (e) {
console.info('fileio_copy_file_async_004 has failed for ' + e);
expect(e.message == 'Invalid argument' || e.message == 'No such file or directory').assertTrue();
expect(e.message == 'The first/second argument requires filepath/fd').assertTrue();
done();
}
});
......@@ -235,7 +262,7 @@ describe('fileio_copyfile', function () {
/**
* @tc.number SUB_DF_FILEIO_COPY_FILE_ASYNC_0500
* @tc.name fileio_copy_file_async_005
* @tc.desc Test copyFileAsync() interfaces, Invalid mode.
* @tc.desc Test copyFile() interfaces, Invalid mode.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
......@@ -260,7 +287,7 @@ describe('fileio_copyfile', function () {
/**
* @tc.number SUB_DF_FILEIO_COPY_FILE_ASYNC_0600
* @tc.name fileio_copy_file_async_006
* @tc.desc Test copyFileAsync() interfaces, No parameters.
* @tc.desc Test copyFile() interfaces, No parameters.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
......@@ -275,5 +302,68 @@ describe('fileio_copyfile', function () {
done();
}
});
/**
* @tc.number SUB_DF_FILEIO_COPY_FILE_ASYNC_0700
* @tc.name fileio_copy_file_async_007
* @tc.desc Test copyFile() interfaces. Promise.
* Undefined option arguments, use default mode = 0.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it('fileio_copy_file_async_007', 3, async function (done) {
let fpath = await nextFileName('fileio_copy_file_async_007');
let fpathTarget = fpath + 'tgt';
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
await fileio.copyFile(fpath, fpathTarget, undefined);
let stat1 = fileio.statSync(fpath);
let stat2 = fileio.statSync(fpathTarget);
expect(stat1.size == stat2.size).assertTrue();
fileio.unlinkSync(fpath);
fileio.unlinkSync(fpathTarget);
done();
} catch (e) {
console.log('fileio_copy_file_async_007 has failed for ' + e);
expect(false).assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_COPY_FILE_ASYNC_0800
* @tc.name fileio_copy_file_async_008
* @tc.desc Test copyFile() interfaces. Callback.
* Undefined option arguments, use default mode = 0.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it('fileio_copy_file_async_008', 3, async function (done) {
let fpath = await nextFileName('fileio_copy_file_async_008');
let fpathTarget = fpath + 'tgt';
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
fileio.copyFile(fpath, fpathTarget, undefined, (err) => {
if (err) {
console.log('fileio_copy_file_async_008 error package: ' + JSON.stringify(err));
expect(false).assertTrue();
}
let stat1 = fileio.statSync(fpath);
let stat2 = fileio.statSync(fpathTarget);
expect(stat1.size == stat2.size).assertTrue();
fileio.unlinkSync(fpath);
fileio.unlinkSync(fpathTarget);
done();
});
} catch (e) {
console.log('fileio_copy_file_async_008 has failed for ' + e);
expect(false).assertTrue();
}
});
});
}
......@@ -51,7 +51,7 @@ describe('fileio_ftruncate', function () {
});
/**
* @tc.number SUB_DF_FILEIO_FTRUNCATE_ASYNC_0010
* @tc.number SUB_DF_FILEIO_FTRUNCATE_ASYNC_0100
* @tc.name fileio_test_ftruncate_async_001
* @tc.desc Test ftruncateAsync() interfaces.
* @tc.size MEDIUM
......@@ -85,7 +85,7 @@ describe('fileio_ftruncate', function () {
});
/**
* @tc.number SUB_DF_FILEIO_FTRUNCATE_ASYNC_0020
* @tc.number SUB_DF_FILEIO_FTRUNCATE_ASYNC_0200
* @tc.name fileio_test_ftruncate_async_002
* @tc.desc Test ftruncateAsync() interfaces.
* @tc.size MEDIUM
......@@ -107,6 +107,70 @@ describe('fileio_ftruncate', function () {
}
});
/**
* @tc.number SUB_DF_FILEIO_FTRUNCATE_ASYNC_0300
* @tc.name fileio_test_ftruncate_async_003
* @tc.desc Test ftruncate() interfaces. Promise.
* Undefined option arguments, use default length = 0.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it('fileio_test_ftruncate_async_003', 3, async function (done) {
let fpath = await nextFileName('fileio_test_ftruncate_async_003');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
let fd = fileio.openSync(fpath, 0o2);
expect(isIntNum(fd)).assertTrue();
await fileio.ftruncate(fd, undefined);
let readLen = fileio.readSync(fd, new ArrayBuffer(4096));
expect(readLen == 0).assertTrue();
fileio.closeSync(fd);
fileio.unlinkSync(fpath);
done();
} catch (e) {
console.log('fileio_test_ftruncate_async_003 has failed for ' + e);
expect(false).assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_FTRUNCATE_ASYNC_0400
* @tc.name fileio_test_ftruncate_async_004
* @tc.desc Test ftruncate() interfaces. Callback.
* Undefined option arguments, use default length = 0.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it('fileio_test_ftruncate_async_004', 3, async function (done) {
let fpath = await nextFileName('fileio_test_ftruncate_async_004');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
let fd = fileio.openSync(fpath, 0o2);
expect(isIntNum(fd)).assertTrue();
fileio.ftruncate(fd, undefined, (err) => {
if (err) {
console.log('fileio_test_ftruncate_async_004 error: ' + e);
expect(false).assertTrue();
}
let readLen = fileio.readSync(fd, new ArrayBuffer(4096));
expect(readLen == 0).assertTrue();
fileio.closeSync(fd);
fileio.unlinkSync(fpath);
done();
});
} catch (e) {
console.log('fileio_test_ftruncate_async_004 has failed for ' + e);
expect(false).assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_FTRUNCATE_SYNC_0000
* @tc.name fileio_test_ftruncate_sync_000
......@@ -135,7 +199,7 @@ describe('fileio_ftruncate', function () {
});
/**
* @tc.number SUB_DF_FILEIO_FTRUNCATE_SYNC_0010
* @tc.number SUB_DF_FILEIO_FTRUNCATE_SYNC_0100
* @tc.name fileio_test_ftruncate_sync_001
* @tc.desc Test ftruncateSync() interfaces.
* @tc.size MEDIUM
......@@ -162,7 +226,7 @@ describe('fileio_ftruncate', function () {
});
/**
* @tc.number SUB_DF_FILEIO_FTRUNCATE_SYNC_0020
* @tc.number SUB_DF_FILEIO_FTRUNCATE_SYNC_0200
* @tc.name fileio_test_ftruncate_sync_002
* @tc.desc Test ftruncateSync() interfaces.
* @tc.size MEDIUM
......@@ -180,4 +244,34 @@ describe('fileio_ftruncate', function () {
expect(!!e).assertTrue();
}
});
});}
/**
* @tc.number SUB_DF_FILEIO_FTRUNCATE_SYNC_0300
* @tc.name fileio_test_ftruncate_sync_003
* @tc.desc Test ftruncateSync() interfaces.
* Undefined option arguments, use default length = 0.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it('fileio_test_ftruncate_sync_003', 3, async function (done) {
let fpath = await nextFileName('fileio_test_ftruncate_sync_003');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
let fd = fileio.openSync(fpath, 0o2);
expect(isIntNum(fd)).assertTrue();
fileio.ftruncateSync(fd, undefined);
let readLen = fileio.readSync(fd, new ArrayBuffer(4096));
expect(readLen == 0).assertTrue();
fileio.closeSync(fd);
fileio.unlinkSync(fpath);
done();
} catch (e) {
console.log('fileio_test_ftruncate_sync_003 has failed for ' + e);
expect(false).assertTrue();
}
});
});
}
......@@ -40,7 +40,7 @@ describe('fileio_mkdir_rmdir', function () {
});
/**
* @tc.number SUB_DF_FILEIO_MKDIR_SYNC_RMDIR_SYNC_0010
* @tc.number SUB_DF_FILEIO_MKDIR_SYNC_RMDIR_SYNC_0100
* @tc.name fileio_mkdir_sync_rmdir_sync_001
* @tc.desc Test mkdirSync() interfaces.
* @tc.size MEDIUM
......@@ -58,7 +58,7 @@ describe('fileio_mkdir_rmdir', function () {
});
/**
* @tc.number SUB_DF_FILEIO_MKDIR_SYNC_RMDIR_SYNC_0020
* @tc.number SUB_DF_FILEIO_MKDIR_SYNC_RMDIR_SYNC_0200
* @tc.name fileio_mkdir_sync_rmdir_sync_002
* @tc.desc Test mkdirSync() interfaces.
* @tc.size MEDIUM
......@@ -75,10 +75,31 @@ describe('fileio_mkdir_rmdir', function () {
}
});
/**
* @tc.number SUB_DF_FILEIO_MKDIR_SYNC_RMDIR_SYNC_0300
* @tc.name fileio_mkdir_sync_rmdir_sync_003
* @tc.desc Test mkdirSync() interfaces.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
* @tc.require
*/
it('fileio_mkdir_sync_rmdir_sync_003', 0, async function () {
let dpath = await nextFileName('fileio_mkdir_sync_rmdir_sync_003');
try {
fileio.mkdirSync(dpath, undefined);
fileio.rmdirSync(dpath);
} catch (e) {
console.log('fileio_mkdir_sync_rmdir_sync_003 has failed for ' + e);
expect(false).assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_MKDIR_ASYNC_RMDIR_SYNC_0000
* @tc.name fileio_mkdir_async_rmdir_sync_000
* @tc.desc Test mkdirAsync() and rmdirSync() interfaces.
* @tc.desc Test mkdir() and rmdirSync() interfaces. Promise.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
......@@ -98,9 +119,9 @@ describe('fileio_mkdir_rmdir', function () {
});
/**
* @tc.number SUB_DF_FILEIO_MKDIR_ASYNC_RMDIR_SYNC_0010
* @tc.number SUB_DF_FILEIO_MKDIR_ASYNC_RMDIR_SYNC_0100
* @tc.name fileio_mkdir_async_rmdir_sync_001
* @tc.desc Test mkdirAsync() and rmdirSync() interfaces.
* @tc.desc Test mkdir() and rmdirSync() interfaces. Callback.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
......@@ -121,9 +142,9 @@ describe('fileio_mkdir_rmdir', function () {
});
/**
* @tc.number SUB_DF_FILEIO_MKDIR_ASYNC_RMDIR_SYNC_0020
* @tc.number SUB_DF_FILEIO_MKDIR_ASYNC_RMDIR_SYNC_0200
* @tc.name fileio_mkdir_async_rmdir_sync_002
* @tc.desc Test mkdirAsync() and rmdirSync() interfaces.
* @tc.desc Test mkdir() and rmdirSync() interfaces. Promise.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
......@@ -143,9 +164,9 @@ describe('fileio_mkdir_rmdir', function () {
});
/**
* @tc.number SUB_DF_FILEIO_MKDIR_ASYNC_RMDIR_SYNC_0030
* @tc.number SUB_DF_FILEIO_MKDIR_ASYNC_RMDIR_SYNC_0300
* @tc.name fileio_mkdir_async_rmdir_sync_003
* @tc.desc Test mkdirAsync() and rmdirSync() interfaces.
* @tc.desc Test mkdir() and rmdirSync() interfaces. Promise.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
......@@ -165,9 +186,9 @@ describe('fileio_mkdir_rmdir', function () {
});
/**
* @tc.number SUB_DF_FILEIO_MKDIR_ASYNC_RMDIR_SYNC_0040
* @tc.number SUB_DF_FILEIO_MKDIR_ASYNC_RMDIR_SYNC_0400
* @tc.name fileio_mkdir_async_rmdir_sync_004
* @tc.desc Test mkdirAsync() and interfaces.
* @tc.desc Test mkdir() and interfaces. Promise.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
......@@ -178,25 +199,60 @@ describe('fileio_mkdir_rmdir', function () {
expect(await fileio.mkdir(12) == null).assertTrue();
expect(null).assertFail();
} catch (e) {
console.log('fileio_mkdir_async_rmdir_sync_004 has failed for ' + e);
done();
}
});
/**
* @tc.number SUB_DF_FILEIO_MKDIR_ASYNC_RMDIR_SYNC_0050
* @tc.number SUB_DF_FILEIO_MKDIR_ASYNC_RMDIR_SYNC_0500
* @tc.name fileio_mkdir_async_rmdir_sync_005
* @tc.desc Test mkdirAsync()interfaces.
* @tc.desc Test mkdir() interfaces. Promise.
* Undefined option arguments, use default options.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
* @tc.require
*/
it('fileio_mkdir_async_rmdir_sync_005', 0, async function (done) {
let dpath = await nextFileName('fileio_mkdir_async_rmdir_sync_005');
try {
expect(await fileio.mkdir('/').indexOf('<pending>') > -1).assertTrue();
expect(null).assertFail();
} catch (e) {
await fileio.mkdir(dpath, undefined);
fileio.rmdirSync(dpath);
done();
} catch (e) {
console.log('fileio_mkdir_async_rmdir_sync_005 has failed for ' + e);
expect(false).assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_MKDIR_ASYNC_RMDIR_SYNC_0600
* @tc.name fileio_mkdir_async_rmdir_sync_006
* @tc.desc Test mkdir() interfaces. Callback.
* Undefined option arguments, use default options.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
* @tc.require
*/
it('fileio_mkdir_async_rmdir_sync_006', 0, async function (done) {
let dpath = await nextFileName('fileio_mkdir_async_rmdir_sync_006');
try {
fileio.mkdir(dpath, undefined, (err) => {
if (err) {
console.log('fileio_mkdir_async_rmdir_sync_006 error: ' + e);
expect(false).assertTrue();
}
fileio.rmdirSync(dpath);
done();
});
} catch (e) {
console.log('fileio_mkdir_async_rmdir_sync_006 has failed for ' + e);
expect(false).assertTrue();
}
});
});}
});
}
......@@ -14,7 +14,7 @@
*/
import {
fileio, FILE_CONTENT, prepareFile, nextFileName,
fileio, FILE_CONTENT, prepareFile, nextFileName, isIntNum,
describe, it, expect,
} from '../../Common';
......@@ -70,7 +70,7 @@ describe('fileio_open', function () {
});
/**
* @tc.number SUB_DF_FILEIO_OPEN_ASYNC_0010
* @tc.number SUB_DF_FILEIO_OPEN_ASYNC_0100
* @tc.name fileio_test_open_async_001
* @tc.desc Test openASync() interfaces.
* @tc.size MEDIUM
......@@ -98,7 +98,7 @@ describe('fileio_open', function () {
});
/**
* @tc.number SUB_DF_FILEIO_OPEN_ASYNC_0020
* @tc.number SUB_DF_FILEIO_OPEN_ASYNC_0200
* @tc.name fileio_test_open_async_002
* @tc.desc Test openASync() interfaces.
* @tc.size MEDIUM
......@@ -126,7 +126,7 @@ describe('fileio_open', function () {
});
/**
* @tc.number SUB_DF_FILEIO_OPEN_ASYNC_0030
* @tc.number SUB_DF_FILEIO_OPEN_ASYNC_0300
* @tc.name fileio_test_open_async_003
* @tc.desc Test openASync() interfaces.
* @tc.size MEDIUM
......@@ -154,7 +154,7 @@ describe('fileio_open', function () {
});
/**
* @tc.number SUB_DF_FILEIO_OPEN_ASYNC_0040
* @tc.number SUB_DF_FILEIO_OPEN_ASYNC_0400
* @tc.name fileio_test_open_async_004
* @tc.desc Test openASync() interfaces.
* @tc.size MEDIUM
......@@ -186,7 +186,7 @@ describe('fileio_open', function () {
});
/**
* @tc.number SUB_DF_FILEIO_OPEN_ASYNC_0050
* @tc.number SUB_DF_FILEIO_OPEN_ASYNC_0500
* @tc.name fileio_test_open_async_005
* @tc.desc Test openASync() interfaces.
* @tc.size MEDIUM
......@@ -217,7 +217,7 @@ describe('fileio_open', function () {
});
/**
* @tc.number SUB_DF_FILEIO_OPEN_ASYNC_0060
* @tc.number SUB_DF_FILEIO_OPEN_ASYNC_0600
* @tc.name fileio_test_open_async_006
* @tc.desc Test openASync() interfaces.
* @tc.size MEDIUM
......@@ -248,7 +248,7 @@ describe('fileio_open', function () {
});
/**
* @tc.number SUB_DF_FILEIO_OPEN_ASYNC_0070
* @tc.number SUB_DF_FILEIO_OPEN_ASYNC_0700
* @tc.name fileio_test_open_async_007
* @tc.desc Test openASync() interfaces.
* @tc.size MEDIUM
......@@ -276,7 +276,7 @@ describe('fileio_open', function () {
});
/**
* @tc.number SUB_DF_FILEIO_OPEN_ASYNC_0080
* @tc.number SUB_DF_FILEIO_OPEN_ASYNC_0800
* @tc.name fileio_test_open_async_008
* @tc.desc Test openASync() interfaces.
* @tc.size MEDIUM
......@@ -299,7 +299,7 @@ describe('fileio_open', function () {
});
/**
* @tc.number SUB_DF_FILEIO_OPEN_ASYNC_0090
* @tc.number SUB_DF_FILEIO_OPEN_ASYNC_0900
* @tc.name fileio_test_open_async_009
* @tc.desc Test openASync() interfaces.
* @tc.size MEDIUM
......@@ -332,5 +332,77 @@ describe('fileio_open', function () {
expect(null).assertFail();
}
});
/**
* @tc.number SUB_DF_FILEIO_OPEN_ASYNC_1000
* @tc.name fileio_test_open_async_010
* @tc.desc Test open() interfaces.
* Use default: flag = O_RDONLY, mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 3
* @tc.require
*/
it('fileio_test_open_async_010', 3, async function (done) {
let fpath = await nextFileName('fileio_test_open_async_010');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
fileio.open(fpath, undefined, undefined, (err, fd) => {
if (err) {
console.log('fileio_test_open_async_010 error: ' + e);
expect(false).assertTrue();
}
expect(isIntNum(fd)).assertTrue();
let readLen = fileio.readSync(fd, new ArrayBuffer(4096));
expect(readLen == FILE_CONTENT.length).assertTrue();
fileio.write(fd, FILE_CONTENT, (err, bytesWritten) => {
if (err) {
fileio.closeSync(fd);
fileio.unlinkSync(fpath);
console.log('fileIO_test_open_async_010 error package: ' + err);
expect(err.message == 'Bad file descriptor').assertTrue();
done();
} else {
expect(false).assertTrue();
}
});
});
} catch (e) {
console.log('fileio_test_open_async_010 has failed for ' + e);
expect(false).assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_OPEN_ASYNC_1100
* @tc.name fileio_test_open_async_011
* @tc.desc Test open() interfaces.
* Use default: flag = O_RDONLY, mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 3
* @tc.require
*/
it('fileio_test_open_async_011', 3, async function (done) {
let fpath = await nextFileName('fileio_test_open_async_011');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
let fd;
try {
fd = await fileio.open(fpath, undefined, undefined);
expect(isIntNum(fd)).assertTrue();
let readLen = fileio.readSync(fd, new ArrayBuffer(4096));
expect(readLen == FILE_CONTENT.length).assertTrue();
fileio.writeSync(fd, FILE_CONTENT);
expect(false).assertTrue();
} catch (e) {
fileio.closeSync(fd);
fileio.unlinkSync(fpath);
console.log('fileio_test_open_async_011 has failed for' + e);
expect(e.message == 'Bad file descriptor').assertTrue();
done();
}
});
});
}
......@@ -87,7 +87,7 @@ describe('fileio_open_close', function () {
});
/**
* @tc.number SUB_DF_FILEIO_OPEN_SYNC_0010
* @tc.number SUB_DF_FILEIO_OPEN_SYNC_0100
* @tc.name fileio_open_sync_001
* @tc.desc Test openSync() interface.
* @tc.size MEDIUM
......@@ -105,7 +105,37 @@ describe('fileio_open_close', function () {
console.log('fileio_open_sync_001 has failed for ' + e);
}
});
/**
* @tc.number SUB_DF_FILEIO_OPEN_SYNC_0200
* @tc.name fileio_open_sync_002
* @tc.desc Test openSync() interface.
* Use default: flag = O_RDONLY, mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 3
* @tc.require
*/
it('fileio_open_sync_002', 3, async function () {
let fpath = await nextFileName('fileio_open_sync_002');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
let fd;
try {
fd = fileio.openSync(fpath, undefined, undefined);
expect(isIntNum(fd)).assertTrue();
let readLen = fileio.readSync(fd, new ArrayBuffer(4096));
expect(readLen == FILE_CONTENT.length).assertTrue();
fileio.writeSync(fd, FILE_CONTENT);
expect(false).assertTrue();
} catch (e) {
fileio.closeSync(fd);
fileio.unlinkSync(fpath);
console.log('fileio_open_sync_002 has failed for ' + e);
expect(e.message == 'Bad file descriptor').assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_CLOSE_SYNC_0000
* @tc.name fileio_close_sync_000
......
......@@ -48,7 +48,7 @@ describe('fileio_read', function () {
});
/**
* @tc.number SUB_DF_FILEIO_READ_SYNC_0010
* @tc.number SUB_DF_FILEIO_READ_SYNC_0100
* @tc.name fileio_test_read_sync_001
* @tc.desc Test readSync() interfaces.
* @tc.size MEDIUM
......@@ -78,7 +78,7 @@ describe('fileio_read', function () {
});
/**
* @tc.number SUB_DF_FILEIO_READ_SYNC_0020
* @tc.number SUB_DF_FILEIO_READ_SYNC_0200
* @tc.name fileio_test_read_sync_002
* @tc.desc Test readSync() interfaces.
* @tc.size MEDIUM
......@@ -106,7 +106,7 @@ describe('fileio_read', function () {
});
/**
* @tc.number SUB_DF_FILEIO_READ_SYNC_0030
* @tc.number SUB_DF_FILEIO_READ_SYNC_0300
* @tc.name fileio_test_read_sync_003
* @tc.desc Test readSync() interfaces.
* @tc.size MEDIUM
......@@ -134,7 +134,7 @@ describe('fileio_read', function () {
});
/**
* @tc.number SUB_DF_FILEIO_READ_SYNC_0040
* @tc.number SUB_DF_FILEIO_READ_SYNC_0400
* @tc.name fileio_test_read_sync_004
* @tc.desc Test readSync() interfaces.
* @tc.size MEDIUM
......@@ -162,7 +162,7 @@ describe('fileio_read', function () {
});
/**
* @tc.number SUB_DF_FILEIO_READ_SYNC_0050
* @tc.number SUB_DF_FILEIO_READ_SYNC_0500
* @tc.name fileio_test_read_sync_005
* @tc.desc Test readSync() interfaces.
* @tc.size MEDIUM
......@@ -190,7 +190,7 @@ describe('fileio_read', function () {
});
/**
* @tc.number SUB_DF_FILEIO_READ_SYNC_0060
* @tc.number SUB_DF_FILEIO_READ_SYNC_0600
* @tc.name fileio_test_read_sync_006
* @tc.desc Test readSync() interfaces.
* @tc.size MEDIUM
......@@ -211,7 +211,7 @@ describe('fileio_read', function () {
});
/**
* @tc.number SUB_DF_FILEIO_READ_SYNC_0070
* @tc.number SUB_DF_FILEIO_READ_SYNC_0700
* @tc.name fileio_test_read_sync_007
* @tc.desc Test readSync() interfaces.
* @tc.size MEDIUM
......@@ -239,7 +239,7 @@ describe('fileio_read', function () {
});
/**
* @tc.number SUB_DF_FILEIO_READ_SYNC_0080
* @tc.number SUB_DF_FILEIO_READ_SYNC_0800
* @tc.name fileio_test_read_sync_008
* @tc.desc Test readSync() interfaces.
* @tc.size MEDIUM
......@@ -267,10 +267,76 @@ describe('fileio_read', function () {
}
});
/**
* @tc.number SUB_DF_FILEIO_READ_SYNC_0900
* @tc.name fileio_test_read_sync_009
* @tc.desc Test readSync() interfaces.
* Undefined option arguments, use default options.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 3
* @tc.require
*/
it('fileio_test_read_sync_009', 3, async function () {
let fpath = await nextFileName('fileio_test_read_sync_009');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
let fd = fileio.openSync(fpath, 0o2);
expect(isIntNum(fd)).assertTrue();
let readLen1 = fileio.readSync(fd, new ArrayBuffer(16), undefined);
expect(readLen1 == FILE_CONTENT.length).assertTrue();
let readLen2 = fileio.readSync(fd, new ArrayBuffer(8), undefined);
expect(readLen2 == 0).assertTrue();
fileio.closeSync(fd);
fileio.unlinkSync(fpath);
} catch (e) {
console.log('fileio_test_read_sync_009 has failed for ' + e);
expect(false).assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_READ_SYNC_1000
* @tc.name fileio_test_read_sync_010
* @tc.desc Test readSync() interfaces.
* Undefined option arguments, use default options.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 3
* @tc.require
*/
it('fileio_test_read_sync_010', 3, async function () {
let fpath = await nextFileName('fileio_test_read_sync_010');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
let fd = fileio.openSync(fpath, 0o2);
expect(isIntNum(fd)).assertTrue();
let readLen1 = fileio.readSync(fd, new ArrayBuffer(16), {
offset: undefined,
position: undefined,
length: undefined,
});
expect(readLen1 == FILE_CONTENT.length).assertTrue();
let readLen2 = fileio.readSync(fd, new ArrayBuffer(8), {
offset: undefined,
position: undefined,
length: undefined,
});
expect(readLen2 == 0).assertTrue();
fileio.closeSync(fd);
fileio.unlinkSync(fpath);
} catch (e) {
console.log('fileio_test_read_sync_010 has failed for ' + e);
expect(false).assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_READ_ASYNC_0000
* @tc.name fileio_test_read_async_000
* @tc.desc Test readAsync() interfaces.
* @tc.desc Test read() interfaces. Promise.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
......@@ -295,9 +361,9 @@ describe('fileio_read', function () {
});
/**
* @tc.number SUB_DF_FILEIO_READ_ASYNC_0010
* @tc.number SUB_DF_FILEIO_READ_ASYNC_0100
* @tc.name fileio_test_read_async_001
* @tc.desc Test readAsync() interfaces.
* @tc.desc Test read() interfaces. Callback.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
......@@ -323,9 +389,9 @@ describe('fileio_read', function () {
});
/**
* @tc.number SUB_DF_FILEIO_READ_ASYNC_0020
* @tc.number SUB_DF_FILEIO_READ_ASYNC_0200
* @tc.name fileio_test_read_async_002
* @tc.desc Test readAsync() interfaces.
* @tc.desc Test read() interfaces. Promise.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
......@@ -350,9 +416,9 @@ describe('fileio_read', function () {
});
/**
* @tc.number SUB_DF_FILEIO_READ_ASYNC_0030
* @tc.number SUB_DF_FILEIO_READ_ASYNC_0300
* @tc.name fileio_test_read_async_003
* @tc.desc Test readAsync() interfaces.
* @tc.desc Test read() interfaces. Promise.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
......@@ -379,9 +445,9 @@ describe('fileio_read', function () {
});
/**
* @tc.number SUB_DF_FILEIO_READ_ASYNC_0040
* @tc.number SUB_DF_FILEIO_READ_ASYNC_0400
* @tc.name fileio_test_read_async_004
* @tc.desc Test readAsync() interface.
* @tc.desc Test read() interface. Promise.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
......@@ -409,9 +475,9 @@ describe('fileio_read', function () {
});
/**
* @tc.number SUB_DF_FILEIO_READ_ASYNC_0050
* @tc.number SUB_DF_FILEIO_READ_ASYNC_0500
* @tc.name fileio_test_read_async_005
* @tc.desc Test readAsync() interfaces.
* @tc.desc Test read() interfaces. Promise.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
......@@ -438,9 +504,9 @@ describe('fileio_read', function () {
});
/**
* @tc.number SUB_DF_FILEIO_READ_ASYNC_0060
* @tc.number SUB_DF_FILEIO_READ_ASYNC_0600
* @tc.name fileio_test_read_async_006
* @tc.desc Test readAsync() interfaces.
* @tc.desc Test read() interfaces. Promise.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
......@@ -467,9 +533,9 @@ describe('fileio_read', function () {
});
/**
* @tc.number SUB_DF_FILEIO_READ_ASYNC_0070
* @tc.number SUB_DF_FILEIO_READ_ASYNC_0700
* @tc.name fileio_test_read_async_007
* @tc.desc Test readAsync() interfaces.
* @tc.desc Test read() interfaces. Promise.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
......@@ -499,9 +565,9 @@ describe('fileio_read', function () {
});
/**
* @tc.number SUB_DF_FILEIO_READ_ASYNC_0080
* @tc.number SUB_DF_FILEIO_READ_ASYNC_0800
* @tc.name fileio_test_read_async_008
* @tc.desc Test readAsync() interfaces.
* @tc.desc Test read() interfaces. Promise.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
......@@ -517,10 +583,170 @@ describe('fileio_read', function () {
}
});
/**
* @tc.number SUB_DF_FILEIO_READ_ASYNC_0900
* @tc.name fileio_test_read_async_009
* @tc.desc Test read() interfaces. Promise.
* Undefined option arguments, use default options.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 3
* @tc.require
*/
it('fileio_test_read_async_009', 3, async function (done) {
let fpath = await nextFileName('fileio_test_read_async_009');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
let fd = fileio.openSync(fpath, 0o2);
expect(isIntNum(fd)).assertTrue();
let readRes1 = await fileio.read(fd, new ArrayBuffer(16), undefined);
expect(readRes1.bytesRead == FILE_CONTENT.length).assertTrue();
expect(readRes1.offset == 0).assertTrue();
let readRes2 = await fileio.read(fd, new ArrayBuffer(8), undefined);
expect(readRes2.bytesRead == 0).assertTrue();
expect(readRes2.offset == 0).assertTrue();
fileio.closeSync(fd);
fileio.unlinkSync(fpath);
done();
} catch (e) {
console.log('fileio_test_read_async_009 has failed for ' + e);
expect(false).assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_READ_ASYNC_1000
* @tc.name fileio_test_read_async_010
* @tc.desc Test read() interfaces. Callback.
* Undefined option arguments, use default options.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 3
* @tc.require
*/
it('fileio_test_read_async_010', 3, async function (done) {
let fpath = await nextFileName('fileio_test_read_async_010');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
let fd = fileio.openSync(fpath, 0o2);
expect(isIntNum(fd)).assertTrue();
fileio.read(fd, new ArrayBuffer(16), undefined, (err, readRes1) => {
if(err) {
console.log('fileio_test_read_async_010 err package1: ' + JSON.stringify(err));
expect(false).assertTrue();
}
expect(readRes1.bytesRead == FILE_CONTENT.length).assertTrue();
expect(readRes1.offset == 0).assertTrue();
fileio.read(fd, new ArrayBuffer(8), undefined, (err, readRes2) => {
if(err) {
console.log('fileio_test_read_async_010 err package2: ' + JSON.stringify(err));
expect(false).assertTrue();
}
expect(readRes2.bytesRead == 0).assertTrue();
expect(readRes2.offset == 0).assertTrue();
fileio.closeSync(fd);
fileio.unlinkSync(fpath);
done();
});
});
} catch (e) {
console.log('fileio_test_read_async_010 has failed for ' + e);
expect(false).assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_READ_ASYNC_1100
* @tc.name fileio_test_read_async_011
* @tc.desc Test read() interfaces. Promise.
* Undefined option arguments, use default options.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 3
* @tc.require
*/
it('fileio_test_read_async_011', 3, async function (done) {
let fpath = await nextFileName('fileio_test_read_async_011');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
let fd = fileio.openSync(fpath, 0o2);
expect(isIntNum(fd)).assertTrue();
let readRes1 = await fileio.read(fd, new ArrayBuffer(4096), {
offset: undefined,
length: undefined,
});
expect(readRes1.bytesRead == FILE_CONTENT.length).assertTrue();
expect(readRes1.offset == 0).assertTrue();
let readRes2 = await fileio.read(fd, new ArrayBuffer(4096), {
offset: undefined,
length: undefined,
});
expect(readRes2.bytesRead == 0).assertTrue();
expect(readRes2.offset == 0).assertTrue();
fileio.closeSync(fd);
fileio.unlinkSync(fpath);
done();
} catch (e) {
console.log('fileio_test_read_async_011 has failed for ' + e);
expect(false).assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_READ_ASYNC_1200
* @tc.name fileio_test_read_async_012
* @tc.desc Test read() interfaces. Callback.
* Undefined option arguments, use default options.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 3
* @tc.require
*/
it('fileio_test_read_async_012', 3, async function (done) {
let fpath = await nextFileName('fileio_test_read_async_012');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
let fd = fileio.openSync(fpath, 0o2);
expect(isIntNum(fd)).assertTrue();
fileio.read(fd, new ArrayBuffer(16), {
offset: undefined,
length: undefined,
}, (err, readRes1) => {
if(err) {
console.log('fileio_test_read_async_012 err package1: ' + JSON.stringify(err));
expect(false).assertTrue();
}
expect(readRes1.bytesRead == FILE_CONTENT.length).assertTrue();
expect(readRes1.offset == 0).assertTrue();
fileio.read(fd, new ArrayBuffer(8), {
offset: undefined,
length: undefined,
}, (err, readRes2) => {
if (err) {
console.log('fileio_test_read_async_012 err package2: ' + JSON.stringify(err));
expect(false).assertTrue();
}
expect(readRes2.bytesRead == 0).assertTrue();
expect(readRes2.offset == 0).assertTrue();
fileio.closeSync(fd);
fileio.unlinkSync(fpath);
done();
});
});
} catch (e) {
console.log('fileio_test_read_async_012 has failed for ' + e);
expect(false).assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_READ_ASYNC_READOUT_OFFSET_0000
* @tc.name fileio_test_read_async_readout_offset_000
* @tc.desc Test readAsync() ReadOut.offset interfaces.
* @tc.desc Test read() ReadOut.offset interfaces. Promise.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
......
......@@ -44,7 +44,7 @@ describe('fileio_readtext', function () {
});
/**
* @tc.number SUB_DF_FILEIO_READ_TEXT_SYNC_0010
* @tc.number SUB_DF_FILEIO_READ_TEXT_SYNC_0100
* @tc.name fileio_test_readtext_sync_001
* @tc.desc Test readtextSync() interfaces.
* @tc.size MEDIUM
......@@ -69,7 +69,7 @@ describe('fileio_readtext', function () {
});
/**
* @tc.number SUB_DF_FILEIO_READ_TEXT_SYNC_0020
* @tc.number SUB_DF_FILEIO_READ_TEXT_SYNC_0200
* @tc.name fileio_test_readtext_sync_002
* @tc.desc Test readtextSync() interfaces.
* @tc.size MEDIUM
......@@ -94,7 +94,7 @@ describe('fileio_readtext', function () {
});
/**
* @tc.number SUB_DF_FILEIO_READ_TEXT_SYNC_0030
* @tc.number SUB_DF_FILEIO_READ_TEXT_SYNC_0300
* @tc.name fileio_test_readtext_sync_003
* @tc.desc Test readtextSync() interfaces.
* @tc.size MEDIUM
......@@ -112,7 +112,7 @@ describe('fileio_readtext', function () {
});
/**
* @tc.number SUB_DF_FILEIO_READ_TEXT_SYNC_0040
* @tc.number SUB_DF_FILEIO_READ_TEXT_SYNC_0400
* @tc.name fileio_test_readtext_sync_004
* @tc.desc Test readtextSync() interfaces.
* @tc.size MEDIUM
......@@ -132,7 +132,7 @@ describe('fileio_readtext', function () {
});
/**
* @tc.number SUB_DF_FILEIO_READ_TEXT_SYNC_0050
* @tc.number SUB_DF_FILEIO_READ_TEXT_SYNC_0500
* @tc.name fileio_test_readtext_sync_005
* @tc.desc Test readtextSync() interfaces.
* @tc.size MEDIUM
......@@ -141,24 +141,73 @@ describe('fileio_readtext', function () {
* @tc.require
*/
it('fileio_test_readtext_sync_005', 0, async function () {
const invalidLength = 9999;
const invalidLength = -1;
let fpath = await nextFileName('fileio_test_readtext_sync_005');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
fileio.readTextSync(fpath, {
length: invalidLength,
fileio.readTextSync(fpath, { length: invalidLength });
expect(false).assertTrue();
} catch (e) {
fileio.unlinkSync(fpath);
console.log('fileio_test_readtext_sync_005 has failed for ' + e);
}
});
/**
* @tc.number SUB_DF_FILEIO_READ_TEXT_SYNC_0600
* @tc.name fileio_test_readtext_sync_006
* @tc.desc Test readtextSync() interfaces.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 3
* @tc.require
*/
it('fileio_test_readtext_sync_006', 3, async function () {
let fpath = await nextFileName('fileio_test_readtext_sync_006');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
let str = fileio.readTextSync(fpath, undefined);
expect(str == FILE_CONTENT).assertTrue();
fileio.unlinkSync(fpath);
} catch (e) {
console.log('fileio_test_readtext_sync_006 has failed for ' + e);
expect(false).assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_READ_TEXT_SYNC_0700
* @tc.name fileio_test_readtext_sync_007
* @tc.desc Test readtextSync() interfaces.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 3
* @tc.require
*/
it('fileio_test_readtext_sync_007', 3, async function () {
let fpath = await nextFileName('fileio_test_readtext_sync_007');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
let str = fileio.readTextSync(fpath, {
position: undefined,
length: undefined,
encoding: undefined,
});
throw new Error('invalid length');
expect(str == FILE_CONTENT).assertTrue();
fileio.unlinkSync(fpath);
} catch (e) {
expect(fileio.unlinkSync(fpath) == null).assertTrue();
console.log('fileio_test_readtext_sync_007 has failed for ' + e);
expect(false).assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_READ_TEXT_ASYNC_0000
* @tc.name fileio_test_readtext_async_000
* @tc.desc Test readtextASync() interfaces.
* @tc.desc Test readtext() interfaces. Callback.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
......@@ -171,9 +220,9 @@ describe('fileio_readtext', function () {
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
fileio.readText(fpath, { position: pos, length: len, encoding: 'UTF-8' }, function (err, str) {
fileio.readText(fpath, { position: pos, length: len, encoding: 'utf-8' }, function (err, str) {
expect(str == FILE_CONTENT.substr(pos, len)).assertTrue();
expect(fileio.unlinkSync(fpath) == null).assertTrue();
fileio.unlinkSync(fpath);
done();
});
} catch (e) {
......@@ -183,9 +232,9 @@ describe('fileio_readtext', function () {
});
/**
* @tc.number SUB_DF_FILEIO_READ_TEXT_ASYNC_0010
* @tc.number SUB_DF_FILEIO_READ_TEXT_ASYNC_0100
* @tc.name fileio_test_readtext_async_001
* @tc.desc Test readtextASync() interfaces.
* @tc.desc Test readtext() interfaces. Callback.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
......@@ -210,9 +259,9 @@ describe('fileio_readtext', function () {
});
/**
* @tc.number SUB_DF_FILEIO_READ_TEXT_ASYNC_0020
* @tc.number SUB_DF_FILEIO_READ_TEXT_ASYNC_0200
* @tc.name fileio_test_readtext_async_002
* @tc.desc Test readtextASync() interfaces.
* @tc.desc Test readtext() interfaces. Callback.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
......@@ -242,5 +291,123 @@ describe('fileio_readtext', function () {
expect(null).assertFail();
}
});
/**
* @tc.number SUB_DF_FILEIO_READ_TEXT_SYNC_0300
* @tc.name fileio_test_readtext_async_003
* @tc.desc Test readtext() interfaces. Promise.
* Use default option.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 3
* @tc.require
*/
it('fileio_test_readtext_async_003', 3, async function (done) {
let fpath = await nextFileName('fileio_test_readtext_async_003');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
let str = await fileio.readText(fpath, undefined);
expect(str == FILE_CONTENT).assertTrue();
fileio.unlinkSync(fpath);
done();
} catch (e) {
console.log('fileio_test_readtext_async_003 has failed for ' + e);
expect(false).assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_READ_TEXT_SYNC_0400
* @tc.name fileio_test_readtext_async_004
* @tc.desc Test readtext() interfaces. Callback.
* Use default option.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 3
* @tc.require
*/
it('fileio_test_readtext_async_004', 3, async function (done) {
let fpath = await nextFileName('fileio_test_readtext_async_004');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
fileio.readText(fpath, undefined, (err, str) => {
if (err) {
console.log('fileio_test_readtext_async_004 error package: ' + JSON.stringify(err));
expect(false).assertTrue();
}
expect(str == FILE_CONTENT).assertTrue();
fileio.unlinkSync(fpath);
done();
});
} catch (e) {
console.log('fileio_test_readtext_async_004 has failed for ' + e);
expect(false).assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_READ_TEXT_SYNC_0500
* @tc.name fileio_test_readtext_async_005
* @tc.desc Test readtext() interfaces. Promise.
* Use default option.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 3
* @tc.require
*/
it('fileio_test_readtext_async_005', 3, async function (done) {
let fpath = await nextFileName('fileio_test_readtext_async_005');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
let str = await fileio.readText(fpath, {
position: undefined,
length: undefined,
encoding: undefined,
});
expect(str == FILE_CONTENT).assertTrue();
fileio.unlinkSync(fpath);
done();
} catch (e) {
console.log('fileio_test_readtext_async_005 has failed for ' + e);
expect(false).assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_READ_TEXT_SYNC_0600
* @tc.name fileio_test_readtext_async_006
* @tc.desc Test readtext() interfaces. Callback.
* Use default option.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 3
* @tc.require
*/
it('fileio_test_readtext_async_006', 3, async function (done) {
let fpath = await nextFileName('fileio_test_readtext_async_006');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
fileio.readText(fpath, {
position: undefined,
length: undefined,
encoding: undefined,
}, (err, str) => {
if (err) {
console.log('fileio_test_readtext_async_006 error package: ' + JSON.stringify(err));
expect(false).assertTrue();
}
expect(str == FILE_CONTENT).assertTrue();
fileio.unlinkSync(fpath);
done();
});
} catch (e) {
console.log('fileio_test_readtext_async_006 has failed for ' + e);
expect(false).assertTrue();
}
});
});
}
......@@ -24,7 +24,7 @@ describe('fileio_truncate', function () {
/**
* @tc.number SUB_DF_FILEIO_TRUNCATE_ASYNC_0000
* @tc.name fileio_truncate_async_000
* @tc.desc Test truncateAsync() interfaces.
* @tc.desc Test truncate() interfaces. Callback.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
......@@ -52,9 +52,9 @@ describe('fileio_truncate', function () {
});
/**
* @tc.number SUB_DF_FILEIO_TRUNCATE_ASYNC_0010
* @tc.number SUB_DF_FILEIO_TRUNCATE_ASYNC_0100
* @tc.name fileio_truncate_async_001
* @tc.desc Test truncateAsync() interfaces.
* @tc.desc Test truncate() interfaces. Promise.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
......@@ -88,9 +88,9 @@ describe('fileio_truncate', function () {
});
/**
* @tc.number SUB_DF_FILEIO_TRUNCATE_ASYNC_0020
* @tc.number SUB_DF_FILEIO_TRUNCATE_ASYNC_0200
* @tc.name fileio_truncate_async_002
* @tc.desc Test truncateAsync() interfaces.
* @tc.desc Test truncate() interfaces. Callback.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
......@@ -110,6 +110,69 @@ describe('fileio_truncate', function () {
}
});
/**
* @tc.number SUB_DF_FILEIO_TRUNCATE_ASYNC_0300
* @tc.name fileio_truncate_async_003
* @tc.desc Test the truncate() interface. Promise.
* Use default truncateLen = 0.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 3
* @tc.require
*/
it('fileio_truncate_async_003', 3, async function (done) {
let fpath = await nextFileName('fileio_truncate_async_003');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
await fileio.truncate(fpath, undefined);
let fd = fileio.openSync(fpath, 0o2);
expect(isIntNum(fd)).assertTrue();
let readLen = fileio.readSync(fd, new ArrayBuffer(4096));
expect(readLen == 0).assertTrue();
fileio.closeSync(fd);
fileio.unlinkSync(fpath);
done();
} catch (e) {
console.log('fileio_truncate_async_003 has failed for ' + e);
expect(false).assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_TRUNCATE_ASYNC_0400
* @tc.name fileio_truncate_async_004
* @tc.desc Test the truncate() interface. Callback.
* Use default truncateLen = 0.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 3
* @tc.require
*/
it('fileio_truncate_async_004', 3, async function (done) {
let fpath = await nextFileName('fileio_truncate_async_004');
expect(prepareFile(fpath, 'truncate')).assertTrue();
try {
fileio.truncate(fpath, undefined, (err) => {
if (err) {
console.log('fileio_truncate_async_004 error package: ' + JSON.stringify(err));
expect(false).assertTrue();
}
let fd = fileio.openSync(fpath, 0o2);
expect(isIntNum(fd)).assertTrue();
let readLen = fileio.readSync(fd, new ArrayBuffer(4096));
expect(readLen == 0).assertTrue();
fileio.closeSync(fd);
fileio.unlinkSync(fpath);
done();
});
} catch(e) {
console.log('fileio_truncate_async_004 has failed for ' + e);
expect(false).assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_TRUNCATE_SYNC_0000
* @tc.name fileio_test_truncate_sync_000
......@@ -134,7 +197,7 @@ describe('fileio_truncate', function () {
});
/**
* @tc.number SUB_DF_FILEIO_TRUNCATE_SYNC_0010
* @tc.number SUB_DF_FILEIO_TRUNCATE_SYNC_0100
* @tc.name fileio_test_truncate_sync_001
* @tc.desc Test truncateSync() interfaces.
* @tc.size MEDIUM
......@@ -154,7 +217,7 @@ describe('fileio_truncate', function () {
});
/**
* @tc.number SUB_DF_FILEIO_TRUNCATE_SYNC_0020
* @tc.number SUB_DF_FILEIO_TRUNCATE_SYNC_0200
* @tc.name fileio_test_truncate_sync_002
* @tc.desc Test truncateSync() interfaces.
* @tc.size MEDIUM
......@@ -170,5 +233,33 @@ describe('fileio_truncate', function () {
console.log('fileio_test_truncate_sync_002 has failed for ' + e);
}
});
/**
* @tc.number SUB_DF_FILEIO_TRUNCATE_SYNC_0300
* @tc.name fileio_test_truncate_sync_003
* @tc.desc Test the truncateSync() interface.
* Use default truncateLen = 0.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 3
* @tc.require
*/
it('fileio_test_truncate_sync_003', 3, async function () {
let fpath = await nextFileName('fileio_test_truncate_sync_003');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
fileio.truncateSync(fpath, undefined);
let fd = fileio.openSync(fpath, 0o2);
expect(isIntNum(fd)).assertTrue();
let readLen = fileio.readSync(fd, new ArrayBuffer(4096));
expect(readLen == 0).assertTrue();
fileio.closeSync(fd);
fileio.unlinkSync(fpath);
} catch (e) {
console.log('fileio_test_truncate_sync_003 has failed for ' + e);
expect(false).assertTrue();
}
});
});
}
......@@ -14,7 +14,7 @@
*/
import {
fileio, FILE_CONTENT, nextFileName, isIntNum,
fileio, FILE_CONTENT, nextFileName, isIntNum, prepareFile,
describe, it, expect,
} from '../../Common';
......@@ -46,7 +46,7 @@ describe('fileio_write', function () {
});
/**
* @tc.number SUB_DF_FILEIO_WRITE_SYNC_0010
* @tc.number SUB_DF_FILEIO_WRITE_SYNC_0100
* @tc.name fileio_test_write_sync_001
* @tc.desc Test writeSync() interfaces.
* @tc.size MEDIUM
......@@ -74,7 +74,7 @@ describe('fileio_write', function () {
});
/**
* @tc.number SUB_DF_FILEIO_WRITE_SYNC_0020
* @tc.number SUB_DF_FILEIO_WRITE_SYNC_0200
* @tc.name fileio_test_write_sync_002
* @tc.desc Test writeSync() interfaces.
* @tc.size MEDIUM
......@@ -102,7 +102,7 @@ describe('fileio_write', function () {
});
/**
* @tc.number SUB_DF_FILEIO_WRITE_SYNC_0030
* @tc.number SUB_DF_FILEIO_WRITE_SYNC_0300
* @tc.name fileio_test_write_sync_003
* @tc.desc Test writeSync() interfaces.
* @tc.size MEDIUM
......@@ -130,7 +130,7 @@ describe('fileio_write', function () {
});
/**
* @tc.number SUB_DF_FILEIO_WRITE_SYNC_0040
* @tc.number SUB_DF_FILEIO_WRITE_SYNC_0400
* @tc.name fileio_test_write_sync_004
* @tc.desc Test writeSync() interfaces.
* @tc.size MEDIUM
......@@ -159,7 +159,7 @@ describe('fileio_write', function () {
});
/**
* @tc.number SUB_DF_FILEIO_WRITE_SYNC_0050
* @tc.number SUB_DF_FILEIO_WRITE_SYNC_0500
* @tc.name fileio_test_write_sync_005
* @tc.desc Test writeSync() interfaces.
* @tc.size MEDIUM
......@@ -188,7 +188,7 @@ describe('fileio_write', function () {
});
/**
* @tc.number SUB_DF_FILEIO_WRITE_SYNC_0060
* @tc.number SUB_DF_FILEIO_WRITE_SYNC_0600
* @tc.name fileio_test_write_sync_006
* @tc.desc Test writeSync() interfaces.
* @tc.size MEDIUM
......@@ -217,7 +217,7 @@ describe('fileio_write', function () {
});
/**
* @tc.number SUB_DF_FILEIO_WRITE_SYNC_0070
* @tc.number SUB_DF_FILEIO_WRITE_SYNC_0700
* @tc.name fileio_test_write_sync_007
* @tc.desc Test writeSync() interfaces.
* @tc.size MEDIUM
......@@ -235,7 +235,7 @@ describe('fileio_write', function () {
});
/**
* @tc.number SUB_DF_FILEIO_WRITE_SYNC_0080
* @tc.number SUB_DF_FILEIO_WRITE_SYNC_0800
* @tc.name fileio_test_write_sync_008
* @tc.desc Test writeSync() interfaces.
* @tc.size MEDIUM
......@@ -246,14 +246,15 @@ describe('fileio_write', function () {
it('fileio_test_write_sync_008', 0, function () {
try {
fileio.writeSync(-1, FILE_CONTENT);
expect(null).assertFail();
expect(false).assertTrue();
} catch (e) {
console.log('fileio_test_write_sync_008 has failed for ' + e);
expect(e.message == 'Invalid fd').assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_WRITE_SYNC_0090
* @tc.number SUB_DF_FILEIO_WRITE_SYNC_0900
* @tc.name fileio_test_write_sync_009
* @tc.desc Test writeSync() interfaces.
* @tc.size MEDIUM
......@@ -277,10 +278,68 @@ describe('fileio_write', function () {
}
});
/**
* @tc.number SUB_DF_FILEIO_WRITE_SYNC_1000
* @tc.name fileio_test_write_sync_010
* @tc.desc Test writeSync() interfaces.
* Undefined option arguments, use default options.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 3
* @tc.require
*/
it('fileio_test_write_sync_010', 3, async function () {
let fpath = await nextFileName('fileio_test_write_sync_010');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
let fd = fileio.openSync(fpath, 0o102, 0o666);
expect(isIntNum(fd)).assertTrue();
let bytesWritten = fileio.writeSync(fd, FILE_CONTENT, undefined);
expect(bytesWritten == FILE_CONTENT.length).assertTrue();
fileio.closeSync(fd);
fileio.unlinkSync(fpath);
} catch (e) {
console.log('fileio_test_write_sync_010 has failed for ' + e);
expect(false).assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_WRITE_SYNC_1100
* @tc.name fileio_test_write_sync_011
* @tc.desc Test writeSync() interfaces.
* Undefined option arguments, use default options.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 3
* @tc.require
*/
it('fileio_test_write_sync_011', 3, async function () {
let fpath = await nextFileName('fileio_test_write_sync_011');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
let fd = fileio.openSync(fpath, 0o102, 0o666);
expect(isIntNum(fd)).assertTrue();
let bytesWritten = fileio.writeSync(fd, FILE_CONTENT, {
position: undefined,
offset: undefined,
length: undefined,
encoding: undefined,
});
expect(bytesWritten == FILE_CONTENT.length).assertTrue();
fileio.closeSync(fd);
fileio.unlinkSync(fpath);
} catch (e) {
console.log('fileio_test_write_sync_011 has failed for ' + e);
expect(false).assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_WRITE_ASYNC_0000
* @tc.name fileio_test_write_async_000
* @tc.desc Test writeAsync() interfaces.
* @tc.desc Test write() interfaces. Promise.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
......@@ -303,9 +362,9 @@ describe('fileio_write', function () {
});
/**
* @tc.number SUB_DF_FILEIO_WRITE_ASYNC_0010
* @tc.number SUB_DF_FILEIO_WRITE_ASYNC_0100
* @tc.name fileio_test_write_async_001
* @tc.desc Test writeAsync() interfaces.
* @tc.desc Test write() interfaces. Promise.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
......@@ -331,9 +390,9 @@ describe('fileio_write', function () {
});
/**
* @tc.number SUB_DF_FILEIO_WRITE_ASYNC_0020
* @tc.number SUB_DF_FILEIO_WRITE_ASYNC_0200
* @tc.name fileio_test_write_async_002
* @tc.desc Test writeAsync() interfaces.
* @tc.desc Test write() interfaces. Promise.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
......@@ -360,9 +419,9 @@ describe('fileio_write', function () {
});
/**
* @tc.number SUB_DF_FILEIO_WRITE_ASYNC_0030
* @tc.number SUB_DF_FILEIO_WRITE_ASYNC_0300
* @tc.name fileio_test_write_async_003
* @tc.desc Test writeAsync() interfaces.
* @tc.desc Test write() interfaces. Promise.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
......@@ -390,9 +449,9 @@ describe('fileio_write', function () {
});
/**
* @tc.number SUB_DF_FILEIO_WRITE_ASYNC_0040
* @tc.number SUB_DF_FILEIO_WRITE_ASYNC_0400
* @tc.name fileio_test_write_async_004
* @tc.desc Test writeAsync() interfaces.
* @tc.desc Test write() interfaces. Promise.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
......@@ -421,9 +480,9 @@ describe('fileio_write', function () {
});
/**
* @tc.number SUB_DF_FILEIO_WRITE_ASYNC_0050
* @tc.number SUB_DF_FILEIO_WRITE_ASYNC_0500
* @tc.name fileio_test_write_async_005
* @tc.desc Test writeAsync() interfaces.
* @tc.desc Test write() interfaces. Callback.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
......@@ -451,9 +510,9 @@ describe('fileio_write', function () {
});
/**
* @tc.number SUB_DF_FILEIO_WRITE_ASYNC_0060
* @tc.number SUB_DF_FILEIO_WRITE_ASYNC_0600
* @tc.name fileio_test_write_async_006
* @tc.desc Test writeAsync() interfaces.
* @tc.desc Test write() interfaces. Callback.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
......@@ -484,9 +543,9 @@ describe('fileio_write', function () {
});
/**
* @tc.number SUB_DF_FILEIO_WRITE_ASYNC_0070
* @tc.number SUB_DF_FILEIO_WRITE_ASYNC_0700
* @tc.name fileio_test_write_async_007
* @tc.desc Test writeAsync() interfaces.
* @tc.desc Test write() interfaces. Callback.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
......@@ -518,9 +577,9 @@ describe('fileio_write', function () {
});
/**
* @tc.number SUB_DF_FILEIO_WRITE_ASYNC_0080
* @tc.number SUB_DF_FILEIO_WRITE_ASYNC_0800
* @tc.name fileio_test_write_async_008
* @tc.desc Test writeAsync() interfaces.
* @tc.desc Test write() interfaces. Callback.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
......@@ -553,9 +612,9 @@ describe('fileio_write', function () {
});
/**
* @tc.number SUB_DF_FILEIO_WRITE_ASYNC_0090
* @tc.number SUB_DF_FILEIO_WRITE_ASYNC_0900
* @tc.name fileio_test_write_async_009
* @tc.desc Test writeAsync() interfaces.
* @tc.desc Test write() interfaces. Callback.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
......@@ -587,5 +646,169 @@ describe('fileio_write', function () {
expect(null).assertFail();
}
});
/**
* @tc.number SUB_DF_FILEIO_WRITE_ASYNC_1000
* @tc.name fileio_test_write_async_010
* @tc.desc Test write() interfaces. Promise.
* Undefined option arguments, use default options.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 3
* @tc.require
*/
it('fileio_test_write_async_010', 3, async function (done) {
let fpath = await nextFileName('fileio_test_write_async_010');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
let fd = fileio.openSync(fpath, 0o102, 0o666);
expect(isIntNum(fd)).assertTrue();
let bytesWritten1 = await fileio.write(fd, FILE_CONTENT, undefined);
expect(bytesWritten1 == FILE_CONTENT.length).assertTrue();
let bytesWritten2 = await fileio.write(fd, new ArrayBuffer(FILE_CONTENT.length), undefined);
expect(bytesWritten2 == FILE_CONTENT.length).assertTrue();
let readLen = fileio.readSync(fd, new ArrayBuffer(4096), { position: 0 });
expect(readLen == FILE_CONTENT.length * 2).assertTrue();
fileio.closeSync(fd);
fileio.unlinkSync(fpath);
done();
} catch (e) {
console.log('fileio_test_write_async_010 has failed for ' + e);
expect(false).assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_WRITE_ASYNC_1100
* @tc.name fileio_test_write_async_011
* @tc.desc Test write() interfaces. Callback.
* Undefined option arguments, use default options.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 3
* @tc.require
*/
it('fileio_test_write_async_011', 3, async function (done) {
let fpath = await nextFileName('fileio_test_write_async_011');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
let fd = fileio.openSync(fpath, 0o102, 0o666);
expect(isIntNum(fd)).assertTrue();
fileio.write(fd, FILE_CONTENT, undefined, (err, bytesWritten1) => {
if (err) {
console.log('fileio_test_write_async_011 err package1: ' + JSON.stringify(err));
expect(false).assertTrue();
}
expect(bytesWritten1 == FILE_CONTENT.length).assertTrue();
fileio.write(fd, new ArrayBuffer(FILE_CONTENT.length), undefined, (err, bytesWritten2) => {
if (err) {
console.log('fileio_test_write_async_011 err package2: ' + JSON.stringify(err));
expect(false).assertTrue();
}
expect(bytesWritten2 == FILE_CONTENT.length).assertTrue();
let readLen = fileio.readSync(fd, new ArrayBuffer(4096), { position: 0 });
expect(readLen == FILE_CONTENT.length * 2).assertTrue();
fileio.closeSync(fd);
fileio.unlinkSync(fpath);
done();
});
});
} catch (e) {
console.log('fileio_test_write_async_011 has failed for ' + e);
expect(false).assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_WRITE_ASYNC_1200
* @tc.name fileio_test_write_async_012
* @tc.desc Test write() interfaces. Promise.
* Undefined option arguments, use default options.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 3
* @tc.require
*/
it('fileio_test_write_async_012', 3, async function (done) {
let fpath = await nextFileName('fileio_test_write_async_012');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
let fd = fileio.openSync(fpath, 0o102, 0o666);
expect(isIntNum(fd)).assertTrue();
let bytesWritten1 = await fileio.write(fd, FILE_CONTENT, {
length: undefined,
offset: undefined,
encoding: undefined,
});
expect(bytesWritten1 == FILE_CONTENT.length).assertTrue();
let bytesWritten2 = await fileio.write(fd, new ArrayBuffer(FILE_CONTENT.length), {
length: undefined,
offset: undefined,
encoding: undefined,
});
expect(bytesWritten2 == FILE_CONTENT.length).assertTrue();
let readLen = fileio.readSync(fd, new ArrayBuffer(4096), { position: 0 });
expect(readLen == FILE_CONTENT.length * 2).assertTrue();
fileio.closeSync(fd);
fileio.unlinkSync(fpath);
done();
} catch (e) {
console.log('fileio_test_write_async_012 has failed for ' + e);
expect(false).assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_WRITE_ASYNC_1300
* @tc.name fileio_test_write_async_013
* @tc.desc Test write() interfaces. Callback.
* Undefined option arguments, use default options.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 3
* @tc.require
*/
it('fileio_test_write_async_013', 3, async function (done) {
let fpath = await nextFileName('fileio_test_write_async_013');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
let fd = fileio.openSync(fpath, 0o102, 0o666);
expect(isIntNum(fd)).assertTrue();
fileio.write(fd, FILE_CONTENT, {
length: undefined,
offset: undefined,
encoding: undefined,
}, (err, bytesWritten1) => {
if (err) {
console.log('fileio_test_write_async_013 err package1: ' + JSON.stringify(err));
expect(false).assertTrue();
}
expect(bytesWritten1 == FILE_CONTENT.length).assertTrue();
fileio.write(fd, new ArrayBuffer(FILE_CONTENT.length), {
length: undefined,
offset: undefined,
encoding: undefined,
}, (err, bytesWritten2) => {
if (err) {
console.log('fileio_test_write_async_013 err package2: ' + JSON.stringify(err));
expect(false).assertTrue();
}
expect(bytesWritten2 == FILE_CONTENT.length).assertTrue();
let readLen = fileio.readSync(fd, new ArrayBuffer(4096), { position: 0 });
expect(readLen == FILE_CONTENT.length * 2).assertTrue();
fileio.closeSync(fd);
fileio.unlinkSync(fpath);
done();
});
});
} catch (e) {
console.log('fileio_test_write_async_013 has failed for ' + e);
expect(false).assertTrue();
}
});
});
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册