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

!3396 update storagefileiojstest

Merge pull request !3396 from raoxian/master
...@@ -99,6 +99,15 @@ export function randomString(num) { ...@@ -99,6 +99,15 @@ export function randomString(num) {
return pwd; return pwd;
} }
export function forceRemoveDir(path, num) {
for (let i = num; i >= 0; i--) {
if (i < num) {
path = path.replace(`/d${i}`, "");
}
fileio.rmdirSync(path);
}
}
function isIntNum(val) { function isIntNum(val) {
return typeof val === 'number' && val % 1 === 0; return typeof val === 'number' && val % 1 === 0;
} }
......
...@@ -19,7 +19,8 @@ import { ...@@ -19,7 +19,8 @@ import {
FILE_CONTENT, FILE_CONTENT,
prepareFile, prepareFile,
nextFileName, nextFileName,
randomString randomString,
forceRemoveDir
} }
from './Common' from './Common'
...@@ -40,7 +41,7 @@ describe('fileIOTestDir', function () { ...@@ -40,7 +41,7 @@ describe('fileIOTestDir', function () {
fileio.rmdirSync(dpath); fileio.rmdirSync(dpath);
} }
catch (e) { catch (e) {
console.log('fileio_test_dir_open_sync_000 has failed for ' + e); console.info('fileio_test_dir_open_sync_000 has failed for ' + e);
expect(null).assertFail(); expect(null).assertFail();
} }
}); });
...@@ -56,7 +57,7 @@ describe('fileIOTestDir', function () { ...@@ -56,7 +57,7 @@ describe('fileIOTestDir', function () {
expect(null).assertFail(); expect(null).assertFail();
} }
catch (e) { catch (e) {
console.log('fileio_test_dir_open_sync_001 has failed for ' + e); console.info('fileio_test_dir_open_sync_001 has failed for ' + e);
} }
}); });
...@@ -72,7 +73,7 @@ describe('fileIOTestDir', function () { ...@@ -72,7 +73,7 @@ describe('fileIOTestDir', function () {
expect(null).assertFail(); expect(null).assertFail();
} }
catch (e) { catch (e) {
console.log('fileio_test_dir_open_sync_002 has failed for ' + e); console.info('fileio_test_dir_open_sync_002 has failed for ' + e);
expect(e.message == 'No such file or directory').assertTrue(); expect(e.message == 'No such file or directory').assertTrue();
} }
}); });
...@@ -87,14 +88,15 @@ describe('fileIOTestDir', function () { ...@@ -87,14 +88,15 @@ describe('fileIOTestDir', function () {
fileio.mkdirSync(dpath); fileio.mkdirSync(dpath);
try { try {
for (let i = 0; i < 16; i++) { for (let i = 0; i < 16; i++) {
console.log('time' + i); console.info('time' + i);
dpath = dpath + '/f' + randomString(248); dpath = dpath + '/d' + i;
fileio.mkdirSync(dpath); fileio.mkdirSync(dpath);
} }
expect(null).assertFail(); expect(null).assertFail();
} }
catch (e) { catch (e) {
console.log('fileio_test_dir_open_sync_003 has failed for ' + e); console.info('fileio_test_dir_open_sync_003 has failed for ' + e);
forceRemoveDir(dpath, 16);
} }
}); });
...@@ -110,7 +112,7 @@ describe('fileIOTestDir', function () { ...@@ -110,7 +112,7 @@ describe('fileIOTestDir', function () {
expect(null).assertFail(); expect(null).assertFail();
} }
catch (e) { catch (e) {
console.log('fileio_test_dir_open_sync_004 has failed for ' + e); console.info('fileio_test_dir_open_sync_004 has failed for ' + e);
} }
}); });
...@@ -123,15 +125,16 @@ describe('fileIOTestDir', function () { ...@@ -123,15 +125,16 @@ describe('fileIOTestDir', function () {
let dpath = await nextFileName('fileio_test_dir_open_sync_005'); let dpath = await nextFileName('fileio_test_dir_open_sync_005');
fileio.mkdirSync(dpath); fileio.mkdirSync(dpath);
try { try {
for (let i = 0; i < 1024; i++) { for (let i = 0; i < 113; i++) {
console.log('time' + i); console.info('time' + i);
dpath = dpath + '/' + i dpath = dpath + '/d' + i
fileio.mkdirSync(dpath); fileio.mkdirSync(dpath);
} }
expect(null).assertFail(); expect(null).assertFail();
} }
catch (e) { catch (e) {
console.log('fileio_test_dir_open_sync_005 has failed for ' + e); console.info('fileio_test_dir_open_sync_005 has failed for ' + e);
forceRemoveDir(dpath, 113);
} }
}); });
...@@ -147,7 +150,7 @@ describe('fileIOTestDir', function () { ...@@ -147,7 +150,7 @@ describe('fileIOTestDir', function () {
expect(null).assertFail(); expect(null).assertFail();
} }
catch (e) { catch (e) {
console.log('fileio_test_dir_open_sync_006 has failed for ' + e); console.info('fileio_test_dir_open_sync_006 has failed for ' + e);
expect(e.message == 'No such file or directory').assertTrue(); expect(e.message == 'No such file or directory').assertTrue();
} }
}); });
...@@ -157,13 +160,13 @@ describe('fileIOTestDir', function () { ...@@ -157,13 +160,13 @@ describe('fileIOTestDir', function () {
* @tc.name fileio_test_dir_open_async_001 * @tc.name fileio_test_dir_open_async_001
* @tc.desc Function of API, file name contain special character. * @tc.desc Function of API, file name contain special character.
*/ */
it('fileio_test_dir_open_async_001', 0, async function () { it('fileio_test_dir_open_async_001', 0, async function () {
let dpath = await nextFileName('fileio_test_dir_open_async_001') + 'd' let dpath = await nextFileName('fileio_test_dir_open_async_001') + 'd'
expect(fileio.mkdirSync(dpath) !== null).assertTrue(); fileio.mkdirSync(dpath);
fileio.opendir(dpath, function (err, dir) { fileio.opendir(dpath, function (err, dir) {
expect(dir !== null).assertTrue(); expect(dir !== null).assertTrue();
expect(dir.closeSync() == null).assertTrue(); dir.closeSync();
expect(fileio.rmdirSync(dpath) !== null).assertTrue(); fileio.rmdirSync(dpath);
}); });
}); });
...@@ -174,14 +177,14 @@ describe('fileIOTestDir', function () { ...@@ -174,14 +177,14 @@ describe('fileIOTestDir', function () {
*/ */
it('fileio_test_dir_open_async_002', 0, async function () { it('fileio_test_dir_open_async_002', 0, async function () {
let dpath = await nextFileName('fileio_test_dir_open_async_002') + 'd' let dpath = await nextFileName('fileio_test_dir_open_async_002') + 'd'
expect(fileio.mkdirSync(dpath) !== null).assertTrue(); fileio.mkdirSync(dpath);
let dir = await fileio.opendir(dpath).then(()=> { fileio.opendir(dpath).then((dir)=> {
expect(dir !== null).assertTrue(); expect(dir !== null).assertTrue();
expect(dir.closeSync() == null).assertTrue(); dir.closeSync();
expect(fileio.rmdirSync(dpath) !== null).assertTrue(); fileio.rmdirSync(dpath);
console.log('fileio opendir Success'); console.info('fileio opendir Success');
}).catch((err) => { }).catch((err) => {
console.log("fileio opendir err: " + JSON.stringify(err)); console.info("fileio opendir err: " + JSON.stringify(err));
}); });
}); });
...@@ -204,7 +207,7 @@ describe('fileIOTestDir', function () { ...@@ -204,7 +207,7 @@ describe('fileIOTestDir', function () {
fileio.rmdirSync(dpath); fileio.rmdirSync(dpath);
} }
catch (e) { catch (e) {
console.log('fileio_test_dir_read_sync_000 has failed for ' + e); console.info('fileio_test_dir_read_sync_000 has failed for ' + e);
expect(null).assertFail(); expect(null).assertFail();
} }
}); });
...@@ -231,7 +234,7 @@ describe('fileIOTestDir', function () { ...@@ -231,7 +234,7 @@ describe('fileIOTestDir', function () {
for (let i = 0; i < 3; i++) { for (let i = 0; i < 3; i++) {
let bool = typeof (dd.readSync()); let bool = typeof (dd.readSync());
expect(bool == 'object').assertTrue(); expect(bool == 'object').assertTrue();
console.log('---bool=' + bool); console.info('---bool=' + bool);
} }
dd.closeSync(); dd.closeSync();
for (let i = 0; i < 3; i++) { for (let i = 0; i < 3; i++) {
...@@ -244,7 +247,7 @@ describe('fileIOTestDir', function () { ...@@ -244,7 +247,7 @@ describe('fileIOTestDir', function () {
fileio.rmdirSync(dpath); fileio.rmdirSync(dpath);
} }
catch (e) { catch (e) {
console.log('fileio_test_dir_read_sync_001 has failed for ' + e); console.info('fileio_test_dir_read_sync_001 has failed for ' + e);
expect(null).assertFail(); expect(null).assertFail();
} }
}); });
...@@ -283,7 +286,7 @@ describe('fileIOTestDir', function () { ...@@ -283,7 +286,7 @@ describe('fileIOTestDir', function () {
fileio.rmdirSync(dpath); fileio.rmdirSync(dpath);
} }
catch (e) { catch (e) {
console.log('fileio_test_dir_read_sync_002 has failed for ' + e); console.info('fileio_test_dir_read_sync_002 has failed for ' + e);
expect(null).assertFail(); expect(null).assertFail();
} }
}); });
...@@ -305,7 +308,7 @@ describe('fileIOTestDir', function () { ...@@ -305,7 +308,7 @@ describe('fileIOTestDir', function () {
fileio.rmdirSync(dpath); fileio.rmdirSync(dpath);
} }
catch (e) { catch (e) {
console.log('fileio_test_dir_read_sync_003 has failed for ' + e); console.info('fileio_test_dir_read_sync_003 has failed for ' + e);
expect(null).assertFail(); expect(null).assertFail();
} }
}); });
...@@ -328,7 +331,7 @@ describe('fileIOTestDir', function () { ...@@ -328,7 +331,7 @@ describe('fileIOTestDir', function () {
expect(null).assertFail(); expect(null).assertFail();
} }
catch (e) { catch (e) {
console.log('fileio_test_dir_read_sync_004 has failed for ' + e); console.info('fileio_test_dir_read_sync_004 has failed for ' + e);
expect(e.message == 'Number of arguments unmatched').assertTrue(); expect(e.message == 'Number of arguments unmatched').assertTrue();
dd.closeSync(); dd.closeSync();
fileio.unlinkSync(fpath); fileio.unlinkSync(fpath);
...@@ -359,7 +362,7 @@ describe('fileIOTestDir', function () { ...@@ -359,7 +362,7 @@ describe('fileIOTestDir', function () {
fileio.rmdirSync(dpath); fileio.rmdirSync(dpath);
} }
catch (e) { catch (e) {
console.log('fileio_test_dir_read_sync_005 has failed for ' + e); console.info('fileio_test_dir_read_sync_005 has failed for ' + e);
expect(null).assertFail(); expect(null).assertFail();
} }
}); });
...@@ -379,7 +382,7 @@ describe('fileIOTestDir', function () { ...@@ -379,7 +382,7 @@ describe('fileIOTestDir', function () {
fileio.rmdirSync(dpath); fileio.rmdirSync(dpath);
} }
catch (e) { catch (e) {
console.log('fileio_test_dir_close_sync_000 has failed for ' + e); console.info('fileio_test_dir_close_sync_000 has failed for ' + e);
expect(null).assertFail(); expect(null).assertFail();
} }
}); });
...@@ -399,7 +402,7 @@ describe('fileIOTestDir', function () { ...@@ -399,7 +402,7 @@ describe('fileIOTestDir', function () {
expect(null).assertFail(); expect(null).assertFail();
} }
catch (e) { catch (e) {
console.log('fileio_test_dir_close_sync_001 has failed for ' + e); console.info('fileio_test_dir_close_sync_001 has failed for ' + e);
expect(e.message == 'Dir has been closed yet').assertTrue(); expect(e.message == 'Dir has been closed yet').assertTrue();
fileio.rmdirSync(dpath); fileio.rmdirSync(dpath);
} }
......
...@@ -19,7 +19,8 @@ import { ...@@ -19,7 +19,8 @@ import {
FILE_CONTENT, FILE_CONTENT,
prepareFile, prepareFile,
nextFileName, nextFileName,
randomString randomString,
forceRemoveDir
} }
from './Common' from './Common'
...@@ -86,20 +87,23 @@ describe('fileIOTestStat', function () { ...@@ -86,20 +87,23 @@ describe('fileIOTestStat', function () {
* @tc.desc Function of API, statSync. The file path is greater than 4096. * @tc.desc Function of API, statSync. The file path is greater than 4096.
*/ */
it('fileio_test_stat_stat_sync_003', 0, async function () { it('fileio_test_stat_stat_sync_003', 0, async function () {
let dpath = await nextFileName('fileio_stat1'); let dpath = await nextFileName('fileio_test_stat_stat_sync_003');
fileio.mkdirSync(dpath);
try { try {
for (let i = 0; i < 16; i++) { for (let i = 0; i < 16; i++) {
if (i == 15) { if (i == 15) {
let fpath = dpath + '/f' + randomString(252); let fpath = dpath + '/f' + i;
fileio.statSync(fpath); fileio.statSync(fpath);
} else { } else {
dpath = dpath + '/d' + randomString(252); dpath = dpath + '/d' + i;
fileio.mkdirSync(dpath);
} }
} }
expect(null).assertFail(); expect(null).assertFail();
} }
catch (e) { catch (e) {
console.log('fileio_test_stat_stat_sync_003 has failed for ' + e); console.info('fileio_test_stat_stat_sync_003 has failed for ' + e);
forceRemoveDir(dpath, 15);
} }
}); });
......
...@@ -21,7 +21,8 @@ import { ...@@ -21,7 +21,8 @@ import {
fileToReadOnly, fileToReadOnly,
fileToWriteOnly, fileToWriteOnly,
nextFileName, nextFileName,
randomString randomString,
forceRemoveDir
} }
from './Common' from './Common'
...@@ -594,22 +595,24 @@ describe('fileIOTestStream', function () { ...@@ -594,22 +595,24 @@ describe('fileIOTestStream', function () {
* @tc.desc Function of API, fpath too long. * @tc.desc Function of API, fpath too long.
*/ */
it('fileio_test_stream_create_stream_sync_026', 0, async function () { it('fileio_test_stream_create_stream_sync_026', 0, async function () {
let dpath = await nextFileName('fileio_stream'); let dpath = await nextFileName('fileio_test_stream_create_stream_sync_026');
fileio.mkdirSync(dpath); fileio.mkdirSync(dpath);
try { try {
for (let i = 0; i < 16; i++) { for (let i = 0; i < 16; i++) {
if (i == 15) { if (i == 15) {
let fpath = dpath + '/f' + randomString(248); let fpath = dpath + '/f' + i;
fileio.createStreamSync(fpath, 'w+'); fileio.createStreamSync(fpath, 'w+');
fileio.unlinkSync(fpath);
} else { } else {
dpath = dpath + '/d' + randomString(248); dpath = dpath + '/d' + i;
fileio.mkdirSync(dpath); fileio.mkdirSync(dpath);
} }
} }
expect(null).assertFail(); expect(null).assertFail();
} }
catch (e) { catch (e) {
console.log('fileio_test_stream_create_stream_sync_026 has failed for ' + e); console.info('fileio_test_stream_create_stream_sync_026 has failed for ' + e);
forceRemoveDir(dpath, 15);
} }
}); });
...@@ -634,23 +637,25 @@ describe('fileIOTestStream', function () { ...@@ -634,23 +637,25 @@ describe('fileIOTestStream', function () {
* @tc.name fileio_test_stream_create_stream_sync_028 * @tc.name fileio_test_stream_create_stream_sync_028
* @tc.desc Function of API, path too deep. * @tc.desc Function of API, path too deep.
*/ */
it('fileio_test_stream_create_stream_sync_028', 0, async function () { it('fileio_test_stream_create_stream_sync_028', 0, async function () {
let dpath = await nextFileName('stream'); let dpath = await nextFileName('fileio_test_stream_create_stream_sync_028');
fileio.mkdirSync(dpath); fileio.mkdirSync(dpath);
try { try {
for (let i = 0; i < 113; i++) { for (let i = 0; i < 113; i++) {
if (i == 112) { if (i == 112) {
let fpath = dpath + '/f' + i let fpath = dpath + '/f' + i
fileio.createStreamSync(fpath, 'w+'); fileio.createStreamSync(fpath, 'w+');
fileio.unlinkSync(fpath);
} else { } else {
dpath = dpath + '/' + i dpath = dpath + '/d' + i
fileio.mkdirSync(dpath); fileio.mkdirSync(dpath);
} }
} }
expect(null).assertFail(); expect(null).assertFail();
} }
catch (e) { catch (e) {
console.log('fileio_test_stream_create_stream_sync_028 has failed for ' + e); console.info('fileio_test_stream_create_stream_sync_028 has failed for ' + e);
forceRemoveDir(dpath, 112);
} }
}); });
......
...@@ -170,6 +170,7 @@ describe('fileio_copyfile', function () { ...@@ -170,6 +170,7 @@ describe('fileio_copyfile', function () {
fileio fileio
.copyFile(1, fpath) .copyFile(1, fpath)
.then(function (err) { .then(function (err) {
fileio.unlinkSync(fpath);
done(); done();
}) })
} catch (e) { } catch (e) {
......
...@@ -134,11 +134,12 @@ describe('fileio_createStream', function () { ...@@ -134,11 +134,12 @@ describe('fileio_createStream', function () {
try { try {
fileio.createStream(fpath, 'ohos', function (err) { fileio.createStream(fpath, 'ohos', function (err) {
fileio.unlinkSync(fpath);
done(); done();
}); });
} catch (e) { } catch (e) {
expect(!!e).assertTrue(); console.info("fileio_test_stream_create_stream_async_004 has failed for " + e);
expect(fileio.unlinkSync(fpath) == null).assertTrue(); fileio.unlinkSync(fpath);
done(); done();
} }
}); });
......
...@@ -85,17 +85,13 @@ describe('fileio_fdatasync', async function () { ...@@ -85,17 +85,13 @@ describe('fileio_fdatasync', async function () {
* @tc.require * @tc.require
*/ */
it('fileio_test_fdatasync_async_002', 0, async function (done) { it('fileio_test_fdatasync_async_002', 0, async function (done) {
let fpath = await nextFileName('fileio_test_fdatasync_async_002');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try { try {
let fd = -1; let fd = -1;
await fileio.fdatasync(fd); await fileio.fdatasync(fd);
expect(null).assertFail(); expect(null).assertFail();
done() done()
} catch (e) { } catch (e) {
expect(!!e).assertTrue(); console.info('fileio_test_fdatasync_async_002 has failed for ' + e);
console.log('fileio_test_fdatasync_async_002 has failed for ' + e);
done(); done();
} }
}); });
......
...@@ -508,18 +508,11 @@ describe('fileio_read', function () { ...@@ -508,18 +508,11 @@ describe('fileio_read', function () {
* @tc.require * @tc.require
*/ */
it('fileio_test_read_async_008', 0, async function (done) { it('fileio_test_read_async_008', 0, async function (done) {
let fpath = await nextFileName('fileio_test_read_async_008');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try { try {
let err = await fileio.read(-1, new ArrayBuffer(4096)); await fileio.read(-1, new ArrayBuffer(4096));
expect(!!err).assertTrue();
expect(fileio.unlinkSync(fpath) == null).assertTrue();
expect(null).assertFail(); expect(null).assertFail();
done();
} catch (e) { } catch (e) {
console.log('fileio_test_read_async_008 has failed for ' + e); console.info('fileio_test_read_async_008 has failed for ' + e);
expect(!!e).assertTrue();
done(); done();
} }
}); });
......
...@@ -35,11 +35,11 @@ describe('fileio_symlink', function () { ...@@ -35,11 +35,11 @@ describe('fileio_symlink', function () {
try { try {
fileio.symlinkSync(fpath, fpath + 'aaaa'); fileio.symlinkSync(fpath, fpath + 'aaaa');
expect(fileio.accessSync(fpath + 'aaaa') == null).assertTrue(); fileio.accessSync(fpath + 'aaaa');
fileio.unlinkSync(fpath + 'aaaa');
expect(null).assertFail(); expect(null).assertFail();
} catch (e) { } catch (e) {
console.log('fileio_test_symlink_sync_000 has failed for ' + e); console.info('fileio_test_symlink_sync_000 has failed for ' + e);
fileio.unlinkSync(fpath + 'aaaa');
} }
}); });
...@@ -58,18 +58,14 @@ describe('fileio_symlink', function () { ...@@ -58,18 +58,14 @@ describe('fileio_symlink', function () {
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try { try {
fileio fileio.symlink(fpath, fpath + '1067').then(function (err) {
.symlink(fpath, fpath + '1067') fileio.accessSync(fpath + '1067');
.then(function (err) { fileio.unlinkSync(fpath);
expect(fileio.accessSync(fpath + '1067') == null).assertTrue(); fileio.unlinkSync(fpath + '1067');
fileio.unlinkSync(fpath + '1067'); })
expect(err == null).assertTrue();
})
.catch(function (e) {
expect(e == null).assertTrue();
});
done(); done();
} catch (e) { } catch (e) {
console.info('fileio_test_symlink_async_000 has failed for ' + e);
expect(null).assertFail(); expect(null).assertFail();
} }
}); });
...@@ -85,16 +81,18 @@ describe('fileio_symlink', function () { ...@@ -85,16 +81,18 @@ describe('fileio_symlink', function () {
* @tc.require * @tc.require
*/ */
it('fileio_test_symlink_async_001', 0, async function (done) { it('fileio_test_symlink_async_001', 0, async function (done) {
let fpath = await nextFileName('fileio_test_symlink_async_010'); let fpath = await nextFileName('fileio_test_symlink_async_001');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try { try {
await fileio.symlink(fpath, fpath + 'pass2', function (err) { await fileio.symlink(fpath, fpath + 'pass2', function (err) {
expect(fileio.accessSync(fpath + 'pass2') == null).assertTrue(); fileio.accessSync(fpath + 'pass2');
fileio.unlinkSync(fpath);
fileio.unlinkSync(fpath + 'pass2'); fileio.unlinkSync(fpath + 'pass2');
done(); done();
}); });
} catch (e) { } catch (e) {
console.info('fileio_test_symlink_async_001 has failed for ' + e);
expect(null).assertFail(); expect(null).assertFail();
} }
}); });
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册