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

!7051 Modified XTS for open and truncate interface

Merge pull request !7051 from futurezhou/open
...@@ -24,7 +24,8 @@ import { ...@@ -24,7 +24,8 @@ import {
/** /**
* @tc.number SUB_DF_FILEIO_TRUNCATE_ASYNC_0000 * @tc.number SUB_DF_FILEIO_TRUNCATE_ASYNC_0000
* @tc.name fileIO_truncate_async_000 * @tc.name fileIO_truncate_async_000
* @tc.desc Test the truncate() interface that receives the fpath parameter. * @tc.desc Test the truncate() interface. Promise.
* Truncate the file with path and truncateLen = 5.
* @tc.size MEDIUM * @tc.size MEDIUM
* @tc.type Functoin * @tc.type Functoin
* @tc.level Level 0 * @tc.level Level 0
...@@ -53,7 +54,8 @@ import { ...@@ -53,7 +54,8 @@ import {
/** /**
* @tc.number SUB_DF_FILEIO_TRUNCATE_ASYNC_0100 * @tc.number SUB_DF_FILEIO_TRUNCATE_ASYNC_0100
* @tc.name fileIO_truncate_async_001 * @tc.name fileIO_truncate_async_001
* @tc.desc Test the truncate() interface that receives the fd parameter. * @tc.desc Test the truncate() interface. Callback.
* Truncate the file with fd and truncateLen = 5.
* @tc.size MEDIUM * @tc.size MEDIUM
* @tc.type Functoin * @tc.type Functoin
* @tc.level Level 0 * @tc.level Level 0
...@@ -62,13 +64,16 @@ import { ...@@ -62,13 +64,16 @@ import {
it('fileIO_truncate_async_001', 0, async function (done) { it('fileIO_truncate_async_001', 0, async function (done) {
let fpath = await nextFileName('fileIO_truncate_async_001'); let fpath = await nextFileName('fileIO_truncate_async_001');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
let file; let file = fileIO.openSync(fpath, fileIO.OpenMode.READ_WRITE);
let truncateLen = 5; let truncateLen = 5;
try { try {
file = fileIO.openSync(fpath, fileIO.OpenMode.READ_WRITE);
expect(isIntNum(file.fd)).assertTrue(); expect(isIntNum(file.fd)).assertTrue();
fileIO.truncate(file.fd, truncateLen, function (err) { fileIO.truncate(file.fd, truncateLen, (err) => {
if(err) {
console.log('fileIO_truncate_async_001 error package: ' + JSON.stringify(err));
expect(false).assertTrue();
}
let len = fileIO.readSync(file.fd, new ArrayBuffer(4096)); let len = fileIO.readSync(file.fd, new ArrayBuffer(4096));
expect(len == truncateLen).assertTrue(); expect(len == truncateLen).assertTrue();
fileio.closeSync(file.fd); fileio.closeSync(file.fd);
...@@ -84,7 +89,8 @@ import { ...@@ -84,7 +89,8 @@ import {
/** /**
* @tc.number SUB_DF_FILEIO_TRUNCATE_ASYNC_0200 * @tc.number SUB_DF_FILEIO_TRUNCATE_ASYNC_0200
* @tc.name fileIO_truncate_async_002 * @tc.name fileIO_truncate_async_002
* @tc.desc Test the truncate() interface that receives the fpath parameter. * @tc.desc Test the truncate() interface. Promise.then().catch
* Truncate the file with path and truncateLen = 2.
* @tc.size MEDIUM * @tc.size MEDIUM
* @tc.type Functoin * @tc.type Functoin
* @tc.level Level 0 * @tc.level Level 0
...@@ -96,10 +102,7 @@ import { ...@@ -96,10 +102,7 @@ import {
let truncateLen = 2; let truncateLen = 2;
try { try {
fileIO fileIO.truncate(fpath, truncateLen).then(() => {
.truncate(fpath, truncateLen)
.then(function (err) {
expect(err == null).assertTrue();
let file = fileIO.openSync(fpath, fileIO.OpenMode.READ_WRITE); let file = fileIO.openSync(fpath, fileIO.OpenMode.READ_WRITE);
expect(isIntNum(file.fd)).assertTrue(); expect(isIntNum(file.fd)).assertTrue();
let len = fileIO.readSync(file.fd, new ArrayBuffer(4096)); let len = fileIO.readSync(file.fd, new ArrayBuffer(4096));
...@@ -107,9 +110,9 @@ import { ...@@ -107,9 +110,9 @@ import {
fileio.closeSync(file.fd); fileio.closeSync(file.fd);
fileio.unlinkSync(fpath); fileio.unlinkSync(fpath);
done(); done();
}) }).catch((err) => {
.catch(function (e) { console.log('fileIO_truncate_async_002 error package: ' + JSON.stringify(err));
console.log('catch ' + e.message + ', code: ' + e.code); expect(false).assertTrue();
}); });
} catch(e) { } catch(e) {
console.log('fileIO_truncate_async_002 has failed for ' + e.message + ', code: ' + e.code); console.log('fileIO_truncate_async_002 has failed for ' + e.message + ', code: ' + e.code);
...@@ -120,7 +123,8 @@ import { ...@@ -120,7 +123,8 @@ import {
/** /**
* @tc.number SUB_DF_FILEIO_TRUNCATE_ASYNC_0300 * @tc.number SUB_DF_FILEIO_TRUNCATE_ASYNC_0300
* @tc.name fileIO_truncate_async_003 * @tc.name fileIO_truncate_async_003
* @tc.desc Test the truncate() interface that receives the fd parameter. * @tc.desc Test the truncate() interface. Promise.then().catch
* Truncate the file with fd and truncateLen = 2.
* @tc.size MEDIUM * @tc.size MEDIUM
* @tc.type Functoin * @tc.type Functoin
* @tc.level Level 0 * @tc.level Level 0
...@@ -129,23 +133,20 @@ import { ...@@ -129,23 +133,20 @@ import {
it('fileIO_truncate_async_003', 0, async function (done) { it('fileIO_truncate_async_003', 0, async function (done) {
let fpath = await nextFileName('fileIO_truncate_async_003'); let fpath = await nextFileName('fileIO_truncate_async_003');
expect(prepareFile(fpath, 'truncate')).assertTrue(); expect(prepareFile(fpath, 'truncate')).assertTrue();
let file; let file = fileIO.openSync(fpath, fileIO.OpenMode.READ_WRITE);
let truncateLen = 2; let truncateLen = 2;
try { try {
file = fileIO.openSync(fpath, fileIO.OpenMode.READ_WRITE);
expect(isIntNum(file.fd)).assertTrue(); expect(isIntNum(file.fd)).assertTrue();
fileIO.truncate(file.fd, truncateLen) fileIO.truncate(file.fd, truncateLen).then(() => {
.then(function (err) {
expect(err == null).assertTrue();
let len = fileIO.readSync(file.fd, new ArrayBuffer(4096)); let len = fileIO.readSync(file.fd, new ArrayBuffer(4096));
expect(len == truncateLen).assertTrue(); expect(len == truncateLen).assertTrue();
fileio.closeSync(file.fd); fileio.closeSync(file.fd);
fileio.unlinkSync(fpath); fileio.unlinkSync(fpath);
done(); done();
}) }).catch((err) => {
.catch(function (e) { console.log('fileIO_truncate_async_003 error package: ' + JSON.stringify(err));
console.log('catch ' + e.message + ', code: ' + e.code); expect(false).assertTrue();
}) })
} catch(e) { } catch(e) {
console.log('fileIO_truncate_async_003 has failed for ' + e.message + ', code: ' + e.code); console.log('fileIO_truncate_async_003 has failed for ' + e.message + ', code: ' + e.code);
...@@ -156,7 +157,8 @@ import { ...@@ -156,7 +157,8 @@ import {
/** /**
* @tc.number SUB_DF_FILEIO_TRUNCATE_ASYNC_0400 * @tc.number SUB_DF_FILEIO_TRUNCATE_ASYNC_0400
* @tc.name fileIO_truncate_async_004 * @tc.name fileIO_truncate_async_004
* @tc.desc Test the truncate() interface that receives the fpath parameter. * @tc.desc Test the truncate() interface. Callback.
* Truncate the file with path and truncateLen = 2.
* @tc.size MEDIUM * @tc.size MEDIUM
* @tc.type Functoin * @tc.type Functoin
* @tc.level Level 0 * @tc.level Level 0
...@@ -167,13 +169,39 @@ import { ...@@ -167,13 +169,39 @@ import {
let truncateLen = 2; let truncateLen = 2;
try { try {
fileIO.truncate(fpath, truncateLen, function (err) { fileIO.truncate(fpath, truncateLen, (err) => {
if (err) {
console.log('fileIO_truncate_async_004 error package: {' + err.message + ', code: ' + err.code + '}');
expect(err.code == 13900002 && err.message == 'No such file or directory').assertTrue();
done(); done();
}
}); });
} catch (e) { } catch (e) {
console.log('fileIO_truncate_async_004 has failed for ' + e.message + ', code: ' + e.code); console.log('fileIO_truncate_async_004 has failed for ' + e.message + ', code: ' + e.code);
expect(!!e).assertTrue(); expect(false).assertTrue();
expect(e.code == 13900020 && e.message == 'Invalid argument').assertTrue(); }
});
/**
* @tc.number SUB_DF_FILEIO_TRUNCATE_ASYNC_0500
* @tc.name fileIO_truncate_async_005
* @tc.desc Test the truncate() interface. Promise.
* Truncate the file with path and truncateLen = 2.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it('fileIO_truncate_async_005', 0, async function (done) {
let fpath = await nextFileName('fileIO_truncate_async_005');
let truncateLen = 2;
try {
await fileIO.truncate(fpath, truncateLen);
expect(false).assertTrue();
} catch (e) {
console.log('fileIO_truncate_async_005 has failed for ' + e.message + ', code: ' + e.code);
expect(e.code == 13900002 && e.message == 'No such file or directory').assertTrue();
done(); done();
} }
}); });
...@@ -181,7 +209,8 @@ import { ...@@ -181,7 +209,8 @@ import {
/** /**
* @tc.number SUB_DF_FILEIO_TRUNCATE_SYNC_0000 * @tc.number SUB_DF_FILEIO_TRUNCATE_SYNC_0000
* @tc.name fileIO_test_truncate_sync_000 * @tc.name fileIO_test_truncate_sync_000
* @tc.desc Test the truncateSync() interface that receives the fpath parameter. * @tc.desc Test the truncateSync() interface.
* Truncate the file with path.
* @tc.size MEDIUM * @tc.size MEDIUM
* @tc.type Functoin * @tc.type Functoin
* @tc.level Level 0 * @tc.level Level 0
...@@ -204,7 +233,8 @@ import { ...@@ -204,7 +233,8 @@ import {
/** /**
* @tc.number SUB_DF_FILEIO_TRUNCATE_SYNC_0100 * @tc.number SUB_DF_FILEIO_TRUNCATE_SYNC_0100
* @tc.name fileIO_test_truncate_sync_001 * @tc.name fileIO_test_truncate_sync_001
* @tc.desc Test the truncateSync() interface that receives the fd parameter. * @tc.desc Test the truncateSync() interface.
* Truncate the file with fd and truncateLen = 5.
* @tc.size MEDIUM * @tc.size MEDIUM
* @tc.type Functoin * @tc.type Functoin
* @tc.level Level 0 * @tc.level Level 0
...@@ -213,11 +243,10 @@ import { ...@@ -213,11 +243,10 @@ import {
it('fileIO_test_truncate_sync_001', 0, async function () { it('fileIO_test_truncate_sync_001', 0, async function () {
let fpath = await nextFileName('fileIO_test_truncate_sync_001'); let fpath = await nextFileName('fileIO_test_truncate_sync_001');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
let file; let file = fileIO.openSync(fpath, fileIO.OpenMode.READ_WRITE);
let truncateLen = 5; let truncateLen = 5;
try { try {
file = fileIO.openSync(fpath, fileIO.OpenMode.READ_WRITE);
expect(isIntNum(file.fd)).assertTrue(); expect(isIntNum(file.fd)).assertTrue();
fileIO.truncateSync(file.fd, truncateLen); fileIO.truncateSync(file.fd, truncateLen);
let len = fileIO.readSync(file.fd, new ArrayBuffer(4096)); let len = fileIO.readSync(file.fd, new ArrayBuffer(4096));
...@@ -233,7 +262,8 @@ import { ...@@ -233,7 +262,8 @@ import {
/** /**
* @tc.number SUB_DF_FILEIO_TRUNCATE_SYNC_0200 * @tc.number SUB_DF_FILEIO_TRUNCATE_SYNC_0200
* @tc.name fileIO_test_truncate_sync_002 * @tc.name fileIO_test_truncate_sync_002
* @tc.desc Test the truncateSync() interface that receives the fpath parameter. * @tc.desc Test the truncateSync() interface.
* The path point to nothing, no such file.
* @tc.size MEDIUM * @tc.size MEDIUM
* @tc.type Functoin * @tc.type Functoin
* @tc.level Level 0 * @tc.level Level 0
...@@ -243,10 +273,10 @@ import { ...@@ -243,10 +273,10 @@ import {
let fpath = await nextFileName('fileIO_test_truncate_sync_002'); let fpath = await nextFileName('fileIO_test_truncate_sync_002');
try { try {
let stat = fileIO.truncateSync(fpath); fileIO.truncateSync(fpath);
console.info('fileIO_test_truncate_sync_002 = ' + stat);
expect(false).assertTrue(); expect(false).assertTrue();
} catch (e) { } catch (e) {
console.log('fileIO_test_truncate_sync_002 has failed for ' + e.message + ', code: ' + e.code);
expect(e.code == 13900002 && e.message == 'No such file or directory').assertTrue(); expect(e.code == 13900002 && e.message == 'No such file or directory').assertTrue();
} }
}); });
...@@ -254,69 +284,42 @@ import { ...@@ -254,69 +284,42 @@ import {
/** /**
* @tc.number SUB_DF_FILEIO_TRUNCATE_SYNC_0300 * @tc.number SUB_DF_FILEIO_TRUNCATE_SYNC_0300
* @tc.name fileIO_test_truncate_sync_003 * @tc.name fileIO_test_truncate_sync_003
* @tc.desc Test the truncateSync() interface that receives the fd parameter. * @tc.desc Test the truncateSync() interface. Invalid parameter.
* @tc.size MEDIUM * @tc.size MEDIUM
* @tc.type Functoin * @tc.type Functoin
* @tc.level Level 0 * @tc.level Level 0
* @tc.require * @tc.require
*/ */
it('fileIO_test_truncate_sync_003', 0, async function () { it('fileIO_test_truncate_sync_003', 0, async function () {
let fpath = await nextFileName('fileIO_test_truncate_sync_003');
expect(prepareFile(fpath, 'truncate')).assertTrue();
let file;
let truncateLen = 2; let truncateLen = 2;
try { try {
file = fileIO.openSync(fpath, fileIO.OpenMode.READ_WRITE); fileIO.truncateSync(-1, truncateLen);
expect(isIntNum(file.fd)).assertTrue(); expect(false).assertTrue();
fileIO.truncateSync(file.fd, truncateLen);
let len = fileIO.readSync(file.fd, new ArrayBuffer(4096));
expect(len == truncateLen).assertTrue();
fileio.closeSync(file.fd);
fileio.unlinkSync(fpath);
} catch (e) { } catch (e) {
console.log('fileIO_test_truncate_sync_003 has failed for ' + e.message + ', code: ' + e.code); console.log('fileIO_test_truncate_sync_003 has failed for ' + e.message + ', code: ' + e.code);
expect(false).assertTrue(); expect(e.code == 13900020 && e.message == 'Invalid argument').assertTrue();
} }
}); });
/** /**
* @tc.number SUB_DF_FILEIO_TRUNCATE_SYNC_0400 * @tc.number SUB_DF_FILEIO_TRUNCATE_SYNC_0400
* @tc.name fileIO_test_truncate_sync_004 * @tc.name fileIO_test_truncate_sync_004
* @tc.desc Test truncateSync() interfaces. * @tc.desc Test truncateSync() interfaces. Missing parameters.
* @tc.size MEDIUM * @tc.size MEDIUM
* @tc.type Functoin * @tc.type Functoin
* @tc.level Level 0 * @tc.level Level 0
* @tc.require * @tc.require
*/ */
it('fileIO_test_truncate_sync_004', 0, function () { it('fileIO_test_truncate_sync_004', 0, function () {
try { try {
let stat = fileIO.truncateSync(); fileIO.truncateSync();
console.info('fileIO_test_truncate_sync_004 = ' + stat);
expect(false).assertTrue(); expect(false).assertTrue();
} catch (e) { } catch (e) {
console.log('fileIO_test_truncate_sync_004 has failed for ' + e.message + ', code: ' + e.code);
expect(e.code == 13900020 && e.message == 'Invalid argument').assertTrue(); expect(e.code == 13900020 && e.message == 'Invalid argument').assertTrue();
} }
}); });
})
/**
* @tc.number SUB_DF_FILEIO_TRUNCATE_SYNC_0500
* @tc.name fileIO_test_truncate_sync_005
* @tc.desc Test truncateSync() interfaces.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it('fileIO_test_truncate_sync_005', 0, async function () {
let fpath = await nextFileName('fileIO_test_truncate_sync_005');
let truncateLen = 2;
try {
fileIO.truncateSync(fpath, truncateLen);
} catch (e) {
console.log('fileIO_test_truncate_sync_005 has failed for ' + e.message + ', code: ' + e.code);
expect(!!e).assertTrue();
}
});
});
} }
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册