提交 10062de0 编写于 作者: F futurezhou

Modified XTS for open and truncate interface

Signed-off-by: Nfuturezhou <zhouweilai@huawei.com>
上级 eb82e5a8
......@@ -24,7 +24,8 @@ import {
/**
* @tc.number SUB_DF_FILEIO_TRUNCATE_ASYNC_0000
* @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.type Functoin
* @tc.level Level 0
......@@ -53,7 +54,8 @@ import {
/**
* @tc.number SUB_DF_FILEIO_TRUNCATE_ASYNC_0100
* @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.type Functoin
* @tc.level Level 0
......@@ -62,13 +64,16 @@ import {
it('fileIO_truncate_async_001', 0, async function (done) {
let fpath = await nextFileName('fileIO_truncate_async_001');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
let file;
let file = fileIO.openSync(fpath, fileIO.OpenMode.READ_WRITE);
let truncateLen = 5;
try {
file = fileIO.openSync(fpath, fileIO.OpenMode.READ_WRITE);
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));
expect(len == truncateLen).assertTrue();
fileio.closeSync(file.fd);
......@@ -84,7 +89,8 @@ import {
/**
* @tc.number SUB_DF_FILEIO_TRUNCATE_ASYNC_0200
* @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.type Functoin
* @tc.level Level 0
......@@ -96,23 +102,20 @@ import {
let truncateLen = 2;
try {
fileIO
.truncate(fpath, truncateLen)
.then(function (err) {
expect(err == null).assertTrue();
let file = fileIO.openSync(fpath, fileIO.OpenMode.READ_WRITE);
expect(isIntNum(file.fd)).assertTrue();
let len = fileIO.readSync(file.fd, new ArrayBuffer(4096));
expect(len == truncateLen).assertTrue();
fileio.closeSync(file.fd);
fileio.unlinkSync(fpath);
done();
})
.catch(function (e) {
console.log('catch ' + e.message + ', code: ' + e.code);
});
fileIO.truncate(fpath, truncateLen).then(() => {
let file = fileIO.openSync(fpath, fileIO.OpenMode.READ_WRITE);
expect(isIntNum(file.fd)).assertTrue();
let len = fileIO.readSync(file.fd, new ArrayBuffer(4096));
expect(len == truncateLen).assertTrue();
fileio.closeSync(file.fd);
fileio.unlinkSync(fpath);
done();
}).catch((err) => {
console.log('fileIO_truncate_async_002 error package: ' + JSON.stringify(err));
expect(false).assertTrue();
});
} 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);
expect(false).assertTrue();
}
});
......@@ -120,7 +123,8 @@ import {
/**
* @tc.number SUB_DF_FILEIO_TRUNCATE_ASYNC_0300
* @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.type Functoin
* @tc.level Level 0
......@@ -129,26 +133,23 @@ import {
it('fileIO_truncate_async_003', 0, async function (done) {
let fpath = await nextFileName('fileIO_truncate_async_003');
expect(prepareFile(fpath, 'truncate')).assertTrue();
let file;
let file = fileIO.openSync(fpath, fileIO.OpenMode.READ_WRITE);
let truncateLen = 2;
try {
file = fileIO.openSync(fpath, fileIO.OpenMode.READ_WRITE);
expect(isIntNum(file.fd)).assertTrue();
fileIO.truncate(file.fd, truncateLen)
.then(function (err) {
expect(err == null).assertTrue();
let len = fileIO.readSync(file.fd, new ArrayBuffer(4096));
expect(len == truncateLen).assertTrue();
fileio.closeSync(file.fd);
fileio.unlinkSync(fpath);
done();
})
.catch(function (e) {
console.log('catch ' + e.message + ', code: ' + e.code);
})
fileIO.truncate(file.fd, truncateLen).then(() => {
let len = fileIO.readSync(file.fd, new ArrayBuffer(4096));
expect(len == truncateLen).assertTrue();
fileio.closeSync(file.fd);
fileio.unlinkSync(fpath);
done();
}).catch((err) => {
console.log('fileIO_truncate_async_003 error package: ' + JSON.stringify(err));
expect(false).assertTrue();
})
} 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);
expect(false).assertTrue();
}
});
......@@ -156,7 +157,8 @@ import {
/**
* @tc.number SUB_DF_FILEIO_TRUNCATE_ASYNC_0400
* @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.type Functoin
* @tc.level Level 0
......@@ -167,13 +169,39 @@ import {
let truncateLen = 2;
try {
fileIO.truncate(fpath, truncateLen, function (err) {
done();
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();
}
});
} catch (e) {
console.log('fileIO_truncate_async_004 has failed for ' + e.message + ', code: ' + e.code);
expect(!!e).assertTrue();
expect(e.code == 13900020 && e.message == 'Invalid argument').assertTrue();
console.log('fileIO_truncate_async_004 has failed for ' + e.message + ', code: ' + e.code);
expect(false).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();
}
});
......@@ -181,7 +209,8 @@ import {
/**
* @tc.number SUB_DF_FILEIO_TRUNCATE_SYNC_0000
* @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.type Functoin
* @tc.level Level 0
......@@ -196,7 +225,7 @@ import {
expect(fileIO.statSync(fpath).size == 0).assertTrue();
fileio.unlinkSync(fpath);
} catch (e) {
console.log('fileIO_test_truncate_sync_000 has failed for ' + e.message + ', code: ' + e.code);
console.log('fileIO_test_truncate_sync_000 has failed for ' + e.message + ', code: ' + e.code);
expect(false).assertTrue();
}
});
......@@ -204,7 +233,8 @@ import {
/**
* @tc.number SUB_DF_FILEIO_TRUNCATE_SYNC_0100
* @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.type Functoin
* @tc.level Level 0
......@@ -213,11 +243,10 @@ import {
it('fileIO_test_truncate_sync_001', 0, async function () {
let fpath = await nextFileName('fileIO_test_truncate_sync_001');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
let file;
let file = fileIO.openSync(fpath, fileIO.OpenMode.READ_WRITE);
let truncateLen = 5;
try {
file = fileIO.openSync(fpath, fileIO.OpenMode.READ_WRITE);
expect(isIntNum(file.fd)).assertTrue();
fileIO.truncateSync(file.fd, truncateLen);
let len = fileIO.readSync(file.fd, new ArrayBuffer(4096));
......@@ -225,7 +254,7 @@ import {
fileio.closeSync(file.fd);
fileio.unlinkSync(fpath);
} catch (e) {
console.log('fileIO_test_truncate_sync_001 has failed for ' + e.message + ', code: ' + e.code);
console.log('fileIO_test_truncate_sync_001 has failed for ' + e.message + ', code: ' + e.code);
expect(false).assertTrue();
}
});
......@@ -233,7 +262,8 @@ import {
/**
* @tc.number SUB_DF_FILEIO_TRUNCATE_SYNC_0200
* @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.type Functoin
* @tc.level Level 0
......@@ -243,10 +273,10 @@ import {
let fpath = await nextFileName('fileIO_test_truncate_sync_002');
try {
let stat = fileIO.truncateSync(fpath);
console.info('fileIO_test_truncate_sync_002 = ' + stat);
fileIO.truncateSync(fpath);
expect(false).assertTrue();
} 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();
}
});
......@@ -254,69 +284,42 @@ import {
/**
* @tc.number SUB_DF_FILEIO_TRUNCATE_SYNC_0300
* @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.type Functoin
* @tc.level Level 0
* @tc.require
*/
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;
try {
file = fileIO.openSync(fpath, fileIO.OpenMode.READ_WRITE);
expect(isIntNum(file.fd)).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) {
console.log('fileIO_test_truncate_sync_003 has failed for ' + e.message + ', code: ' + e.code);
fileIO.truncateSync(-1, truncateLen);
expect(false).assertTrue();
} catch (e) {
console.log('fileIO_test_truncate_sync_003 has failed for ' + e.message + ', code: ' + e.code);
expect(e.code == 13900020 && e.message == 'Invalid argument').assertTrue();
}
});
/**
* @tc.number SUB_DF_FILEIO_TRUNCATE_SYNC_0400
* @tc.name fileIO_test_truncate_sync_004
* @tc.desc Test truncateSync() interfaces.
* @tc.desc Test truncateSync() interfaces. Missing parameters.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it('fileIO_test_truncate_sync_004', 0, function () {
try {
let stat = fileIO.truncateSync();
console.info('fileIO_test_truncate_sync_004 = ' + stat);
fileIO.truncateSync();
expect(false).assertTrue();
} 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();
}
});
/**
* @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.
先完成此消息的编辑!
想要评论请 注册