提交 4136e9e8 编写于 作者: O openharmony_ci 提交者: Gitee

!1259 新增storage/storagefileiojstest下fileIo测试用例

Merge pull request !1259 from 赵帅/master
...@@ -17,6 +17,11 @@ import fileio from '@ohos.fileio'; ...@@ -17,6 +17,11 @@ import fileio from '@ohos.fileio';
export const FILE_CONTENT = 'hello world'; export const FILE_CONTENT = 'hello world';
import {
describe, beforeAll, beforeEach, afterEach, afterAll, it, expect
}
from 'deccjsunit/index'
export function prepareFile(fpath, content) { export function prepareFile(fpath, content) {
try { try {
let fd = fileio.openSync(fpath, 0o102, 0o666) let fd = fileio.openSync(fpath, 0o102, 0o666)
...@@ -98,4 +103,30 @@ export function randomString(num) { ...@@ -98,4 +103,30 @@ export function randomString(num) {
pwd += $chars.charAt(Math.floor(Math.random() * maxPos)); pwd += $chars.charAt(Math.floor(Math.random() * maxPos));
} }
return pwd; return pwd;
} }
\ No newline at end of file
function isIntNum(val) {
return typeof val === 'number' && val % 1 === 0;
}
function isString(str) {
return (typeof str == 'string') && str.constructor == String;
}
function isBoolean(val) {
return typeof val == 'boolean';
}
export {
fileio,
isIntNum,
isString,
isBoolean,
describe,
beforeAll,
beforeEach,
afterEach,
afterAll,
it,
expect
};
\ No newline at end of file
...@@ -16,10 +16,6 @@ ...@@ -16,10 +16,6 @@
import fileio from '@ohos.fileio'; import fileio from '@ohos.fileio';
import { import {
describe, describe,
beforeAll,
beforeEach,
afterEach,
afterAll,
it, it,
expect expect
} }
...@@ -29,7 +25,6 @@ import { ...@@ -29,7 +25,6 @@ import {
prepareFile, prepareFile,
fileToReadOnly, fileToReadOnly,
fileToWriteOnly, fileToWriteOnly,
sleep,
nextFileName, nextFileName,
randomString randomString
} }
...@@ -1278,7 +1273,7 @@ describe('fileIOTestStream', function () { ...@@ -1278,7 +1273,7 @@ describe('fileIOTestStream', function () {
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try { try {
let fd = fileio.openSync(fpath, 0o2); let fd = fileio.openSync(fpath, 0o2);
fileio.fdopenStreamSync(fd, '') fileio.fdopenStreamSync(fd, '');
expect(null).assertFail(); expect(null).assertFail();
} }
catch (e) { catch (e) {
......
...@@ -19,3 +19,43 @@ require('./FileIODir.test.js') ...@@ -19,3 +19,43 @@ require('./FileIODir.test.js')
require('./FileIODirent.test.js') require('./FileIODirent.test.js')
require('./FileIOStat.test.js') require('./FileIOStat.test.js')
require('./FileIOStream.test.js') require('./FileIOStream.test.js')
require('./module_fileio/members/open_close.test.js');
require('./module_fileio/class_dirent/all.test.js');
require('./module_fileio/class_watcher/createWatcher.test.js');
require('./module_fileio/class_stream/flush.test.js');
require('./module_fileio/class_stream/read.test.js');
require('./module_fileio/members/access.test.js');
require('./module_fileio/members/chmod.test.js');
require('./module_fileio/members/chown.test.js');
require('./module_fileio/members/close.test.js');
require('./module_fileio/members/copyFile.test.js');
require('./module_fileio/members/createStream.test.js');
require('./module_fileio/members/fchown.test.js');
require('./module_fileio/members/fdatasync.test.js');
require('./module_fileio/members/fdopenStream.test.js');
require('./module_fileio/members/fstat.test.js');
require('./module_fileio/members/fsync.test.js');
require('./module_fileio/members/ftruncate.test.js');
require('./module_fileio/members/hash.test.js');
require('./module_fileio/members/lchown.test.js');
require('./module_fileio/members/lseek.test.js');
require('./module_fileio/members/lstat.test.js');
require('./module_fileio/members/mkdir_rmdir.test.js');
require('./module_fileio/members/mkdtemp.test.js');
require('./module_fileio/members/open.test.js');
require('./module_fileio/members/opendir_close.test.js');
require('./module_fileio/members/posix_fallocate.test.js');
require('./module_fileio/members/read.test.js');
require('./module_fileio/members/readtext.test.js');
require('./module_fileio/members/rename.test.js');
require('./module_fileio/members/rmdir.test.js');
require('./module_fileio/members/stat.test.js');
require('./module_fileio/members/symlink.test.js');
require("./module_fileio/members/truncate.test.js");
require('./module_fileio/members/unlink.test.js');
require('./module_fileio/members/write.test.js');
require('./module_fileio/class_dir/read.test.js');
require('./module_fileio/class_dir/close.test.js');
require('./module_fileio/class_stream/all.test.js');
require('./module_fileio/class_stream/close.test.js');
require('./module_fileio/class_stream/write.test.js');
/*
* Copyright (C) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the 'License');
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an 'AS IS' BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import {
fileio,
describe, it, expect,
} from '../../Common';
describe('constants', function () {
/**
* @tc.number SUB_DF_FileIO_constants
* @tc.name fileio_test_constants
* @tc.desc Test constants() interface.
*/
it('fileio_test_constants', 0, function () {
try {
expect(fileio.constants.F_OK == 0).assertTrue();
expect(fileio.constants.X_OK == 1).assertTrue();
expect(fileio.constants.W_OK == 2).assertTrue();
expect(fileio.constants.R_OK == 4).assertTrue();
expect(fileio.constants.O_RDONLY == 0o0).assertTrue();
expect(fileio.constants.O_WRONLY == 0o1).assertTrue();
expect(fileio.constants.O_RDWR == 0o2).assertTrue();
expect(fileio.constants.O_CREAT == 0o100).assertTrue();
expect(fileio.constants.O_EXCL == 0o200).assertTrue();
expect(fileio.constants.O_TRUNC == 0o1000).assertTrue();
expect(fileio.constants.O_APPEND == 0o2000).assertTrue();
expect(fileio.constants.O_NONBLOCK == 0o4000).assertTrue();
expect(fileio.constants.O_DIRECTORY == 0o200000).assertTrue();
expect(fileio.constants.O_NOFOLLOW == 0o400000).assertTrue();
expect(fileio.constants.O_SYNC == 0o4010000).assertTrue();
expect(fileio.constants.S_IFMT == 0o170000).assertTrue();
expect(fileio.constants.S_IFSOCK == 0o140000).assertTrue();
expect(fileio.constants.S_IFLNK == 0o120000).assertTrue();
expect(fileio.constants.S_IFREG == 0o100000).assertTrue();
expect(fileio.constants.S_IFBLK == 0o060000).assertTrue();
expect(fileio.constants.S_IFDIR == 0o040000).assertTrue();
expect(fileio.constants.S_IFCHR == 0o020000).assertTrue();
expect(fileio.constants.S_IFIFO == 0o010000).assertTrue();
expect(fileio.constants.S_IRWXU == 0o0700).assertTrue();
expect(fileio.constants.S_IRUSR == 0o0400).assertTrue();
expect(fileio.constants.S_IWUSR == 0o0200).assertTrue();
expect(fileio.constants.S_IXUSR == 0o0100).assertTrue();
expect(fileio.constants.S_IRWXG == 0o0070).assertTrue();
expect(fileio.constants.S_IRGRP == 0o0040).assertTrue();
expect(fileio.constants.S_IWGRP == 0o0020).assertTrue();
expect(fileio.constants.S_IXGRP == 0o0010).assertTrue();
expect(fileio.constants.S_IRWXO == 0o0007).assertTrue();
expect(fileio.constants.S_IROTH == 0o0004).assertTrue();
expect(fileio.constants.S_IWOTH == 0o0002).assertTrue();
expect(fileio.constants.S_IXOTH == 0o0001).assertTrue();
} catch (e) {
console.log('fileio_test_constants has failed for ' + e);
expect(null).assertFail();
}
});
});
\ No newline at end of file
/*
* Copyright (C) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the 'License');
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an 'AS IS' BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import {
fileio,
FILE_CONTENT,
prepareFile,
nextFileName,
isIntNum,
isString,
isBoolean,
describe,
it,
expect,
} from '../../Common';
describe('fileio_dir_close_read', function () {
/**
* @tc.number SUB_DF_FileIO_Dir_close_Async_0000
* @tc.name fileio_test_dir_close_async_000
* @tc.desc Test Dir.closeAsync() interface.
*/
it('fileio_test_dir_close_async_000', 0, async function (done) {
let dpath = nextFileName('fileio_test_dir_close_async_000') + 'd';
try {
expect(fileio.mkdirSync(dpath) == null).assertTrue();
let dd = await fileio.opendir(dpath);
expect(dd !== null).assertTrue();
expect((await dd.close()) == null).assertTrue();
expect(fileio.rmdirSync(dpath) == null).assertTrue();
done();
} catch (e) {
console.log('fileio_test_dir_close_async_000 has failed for ' + e);
expect(null).assertFail();
}
});
/**
* @tc.number SUB_DF_FileIO_Dir_close_Async_0001
* @tc.name fileio_test_dir_close_async_001
* @tc.desc Test Dir.closeAsync() interface.
*/
it('fileio_test_dir_close_async_001', 0, async function (done) {
let dpath = nextFileName('fileio_test_dir_close_async_001') + 'd';
try {
expect(fileio.mkdirSync(dpath) == null).assertTrue();
let dd = await fileio.opendir(dpath);
expect(dd !== null).assertTrue();
dd.close(function (err) {
expect(!!err).assertTrue();
});
expect(fileio.rmdirSync(dpath) == null).assertTrue();
done();
} catch (e) {
console.log('fileio_test_dir_close_async_001 has failed for ' + e);
expect(null).assertFail();
}
});
});
/*
* Copyright (C) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the 'License');
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an 'AS IS' BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import {
fileio, FILE_CONTENT, prepareFile, nextFileName, isBoolean, isString,
describe, it, expect,
} from '../../Common';
describe('fileio_dirent', function () {
/**
* @tc.number SUB_DF_FileIO_Dirent_Name_0010
* @tc.name fileio_test_dirent_name_001
* @tc.desc Test dirent interface.
*/
it('fileio_test_dirent_name_001', 0, async function (done) {
let dpath = nextFileName('fileio_test_dirent_name_001') + 'd';
let fpath = dpath + '/f2';
try {
expect(fileio.mkdirSync(dpath) == null).assertTrue();
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
let dd = fileio.opendirSync(dpath);
expect(dd !== null).assertTrue();
dd.read(function (err, dirent) {
expect(!err).assertTrue();
expect(dirent !== null).assertTrue();
expect(isString(dirent.name)).assertTrue();
expect(dd.closeSync() == null).assertTrue();
expect(fileio.unlinkSync(fpath) == null).assertTrue();
expect(fileio.rmdirSync(dpath) == null).assertTrue();
done();
})
} catch (e) {
console.log('fileio_test_dirent_name_001 has failed for ' + e);
expect(null).assertFail();
}
});
/**
* @tc.number SUB_DF_FileIO_Dirent_Name_0000
* @tc.name fileio_test_dirent_name_000
* @tc.desc Test dirent interface.
*/
it('fileio_test_dirent_name_000', 0, async function (done) {
let dpath = nextFileName('fileio_test_dirent_name_000') + 'd';
let fpath = dpath + '/f1';
try {
expect(fileio.mkdirSync(dpath) == null).assertTrue();
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
let dd = fileio.opendirSync(dpath);
expect(dd !== null).assertTrue();
let dirent = await dd.read();
expect(dirent !== null).assertTrue();
expect(isString(dirent.name)).assertTrue();
expect(dd.closeSync() == null).assertTrue();
expect(fileio.unlinkSync(fpath) == null).assertTrue();
expect(fileio.rmdirSync(dpath) == null).assertTrue();
done();
} catch (e) {
console.log('fileio_test_dirent_name_000 has failed for ' + e);
expect(null).assertFail();
}
})
/**
* @tc.number SUB_DF_FileIO_Dir_ReadSync_0000
* @tc.name fileio_test_dirent_name_000
* @tc.desc Test readSync() interface.
*/
it('fileio_test_dirent_name_000', 0, function () {
let dpath = nextFileName('fileio_test_dirent_name_000') + 'd';
let fpath = dpath + '/f1';
try {
expect(fileio.mkdirSync(dpath) == null).assertTrue();
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
let dd = fileio.opendirSync(dpath);
expect(dd !== null).assertTrue();
let dirent = dd.readSync();
expect(dirent !== null).assertTrue();
expect(isString(dirent.name)).assertTrue();
expect(dd.closeSync() == null).assertTrue();
expect(fileio.unlinkSync(fpath) == null).assertTrue();
expect(fileio.rmdirSync(dpath) == null).assertTrue();
} catch (e) {
console.log('fileio_test_dirent_name_000 has failed for ' + e);
expect(null).assertFail();
}
})
/**
* @tc.number SUB_DF_FileIO_Dir_IsBlockDevice_0000
* @tc.name fileio_test_dirent_is_block_device_000
* @tc.desc Test isBlockDevice() interface.
*/
it('fileio_test_dirent_is_block_device_000', 0, function () {
let dpath = nextFileName('fileio_test_dirent_is_block_device_000') + 'd';
let fpath = dpath + '/f1';
try {
expect(fileio.mkdirSync(dpath) == null).assertTrue();
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
let dd = fileio.opendirSync(dpath);
expect(dd !== null).assertTrue();
let dirent = dd.readSync();
expect(dirent !== null).assertTrue();
expect(isBoolean(dirent.isBlockDevice())).assertTrue();
expect(dd.closeSync() == null).assertTrue();
expect(fileio.unlinkSync(fpath) == null).assertTrue();
expect(fileio.rmdirSync(dpath) == null).assertTrue();
} catch (e) {
console.log('fileio_test_dirent_is_block_device_000 has failed for ' + e);
expect(null).assertFail();
}
})
/**
* @tc.number SUB_DF_FileIO_Dir_IsBlockDevice_0010
* @tc.name fileio_test_dirent_is_block_device_001
* @tc.desc Test isBlockDevice() interface.
*/
it('fileio_test_dirent_is_block_device_001', 0, function () {
let dpath = nextFileName('fileio_test_dirent_is_block_device_001') + 'd';
let fpath = dpath + '/f1';
let dd;
try {
expect(fileio.mkdirSync(dpath) == null).assertTrue();
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
dd = fileio.opendirSync(dpath);
expect(dd !== null).assertTrue();
let dirent = dd.readSync();
expect(dirent !== null).assertTrue();
dirent.isBlockDevice(-1);
expect(null).assertFail();
} catch (e) {
expect(dd.closeSync() == null).assertTrue();
expect(fileio.unlinkSync(fpath) == null).assertTrue();
expect(fileio.rmdirSync(dpath) == null).assertTrue();
}
})
/**
* @tc.number SUB_DF_FileIO_Dir_IsCharacterDevice_0000
* @tc.name fileio_test_dirent_is_character_device_000
* @tc.desc Test isCharacterDevice() interface.
*/
it('fileio_test_dirent_is_character_device_000', 0, function () {
let dpath = nextFileName('fileio_test_dirent_is_character_device_000') + 'd';
let fpath = dpath + '/f1';
try {
expect(fileio.mkdirSync(dpath) == null).assertTrue();
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
let dd = fileio.opendirSync(dpath);
expect(dd !== null).assertTrue();
let dirent = dd.readSync();
expect(dirent !== null).assertTrue();
expect(isBoolean(dirent.isCharacterDevice())).assertTrue();
expect(dd.closeSync() == null).assertTrue();
expect(fileio.unlinkSync(fpath) == null).assertTrue();
expect(fileio.rmdirSync(dpath) == null).assertTrue();
} catch (e) {
console.log('fileio_test_dirent_is_character_device_000 has failed for ' + e);
expect(null).assertFail();
}
})
/**
* @tc.number SUB_DF_FileIO_Dir_IsCharacterDevice_0010
* @tc.name fileio_test_dirent_is_character_device_001
* @tc.desc Test isCharacterDevice() interface.
*/
it('fileio_test_dirent_is_character_device_001', 0, function () {
let dpath = nextFileName('fileio_test_dirent_is_character_device_001') + 'd';
let fpath = dpath + '/f1';
let dd;
try {
expect(fileio.mkdirSync(dpath) == null).assertTrue();
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
dd = fileio.opendirSync(dpath);
expect(dd !== null).assertTrue();
let dirent = dd.readSync();
expect(dirent !== null).assertTrue();
dirent.isCharacterDevice(-1);
expect(null).assertFail();
} catch (e) {
expect(dd.closeSync() == null).assertTrue();
expect(fileio.unlinkSync(fpath) == null).assertTrue();
expect(fileio.rmdirSync(dpath) == null).assertTrue();
}
})
/**
* @tc.number SUB_DF_FileIO_Dir_IsDirectory_0000
* @tc.name fileio_test_dirent_is_directory_000
* @tc.desc Test isDirectory() interface.
*/
it('fileio_test_dirent_is_directory_000', 0, function () {
let dpath = nextFileName('fileio_test_dirent_is_directory_000') + 'd';
let fpath = dpath + '/f1';
try {
expect(fileio.mkdirSync(dpath) == null).assertTrue();
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
let dd = fileio.opendirSync(dpath);
expect(dd !== null).assertTrue();
let dirent = dd.readSync();
expect(dirent !== null).assertTrue();
expect(isBoolean(dirent.isDirectory())).assertTrue();
expect(dd.closeSync() == null).assertTrue();
expect(fileio.unlinkSync(fpath) == null).assertTrue();
expect(fileio.rmdirSync(dpath) == null).assertTrue();
} catch (e) {
console.log('fileio_test_dirent_is_directory_000 has failed for ' + e);
expect(null).assertFail();
}
})
/**
* @tc.number SUB_DF_FileIO_Dir_IsDirectory_0010
* @tc.name fileio_test_dirent_is_directory_001
* @tc.desc Test isDirectory() interface.
*/
it('fileio_test_dirent_is_directory_001', 0, function () {
let dpath = nextFileName('fileio_test_dirent_is_directory_001') + 'd';
let fpath = dpath + '/f1';
let dd;
try {
expect(fileio.mkdirSync(dpath) == null).assertTrue();
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
dd = fileio.opendirSync(dpath);
expect(dd !== null).assertTrue();
let dirent = dd.readSync();
expect(dirent !== null).assertTrue();
dirent.isDirectory(-1);
expect(null).assertFail();
} catch (e) {
expect(dd.closeSync() == null).assertTrue();
expect(fileio.unlinkSync(fpath) == null).assertTrue();
expect(fileio.rmdirSync(dpath) == null).assertTrue();
}
})
/**
* @tc.number SUB_DF_FileIO_Dir_IsFIFO_0000
* @tc.name fileio_test_dirent_is_fifo_000
* @tc.desc Test isFIFO() interface.
*/
it('fileio_test_dirent_is_fifo_000', 0, function () {
let dpath = nextFileName('fileio_test_dirent_is_fifo_000') + 'd';
let fpath = dpath + '/f1';
try {
expect(fileio.mkdirSync(dpath) == null).assertTrue();
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
let dd = fileio.opendirSync(dpath);
expect(dd !== null).assertTrue();
let dirent = dd.readSync();
expect(dirent !== null).assertTrue();
expect(isBoolean(dirent.isFIFO())).assertTrue()
expect(dd.closeSync() == null).assertTrue();
expect(fileio.unlinkSync(fpath) == null).assertTrue();
expect(fileio.rmdirSync(dpath) == null).assertTrue();
} catch (e) {
console.log('fileio_test_dirent_is_fifo_000 has failed for ' + e);
expect(null).assertFail()
}
})
/**
* @tc.number SUB_DF_FileIO_Dir_IsFIFO_0010
* @tc.name fileio_test_dirent_is_fifo_001
* @tc.desc Test isFIFO() interface.
*/
it('fileio_test_dirent_is_fifo_001', 0, function () {
let dpath = nextFileName('fileio_test_dirent_is_fifo_001') + 'd';
let fpath = dpath + '/f1';
let dd;
try {
expect(fileio.mkdirSync(dpath) == null).assertTrue();
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
dd = fileio.opendirSync(dpath);
expect(dd !== null).assertTrue();
let dirent = dd.readSync();
expect(dirent !== null).assertTrue();
dirent.isFIFO(-1);
expect(null).assertFail();
} catch (e) {
expect(dd.closeSync() == null).assertTrue();
expect(fileio.unlinkSync(fpath) == null).assertTrue();
expect(fileio.rmdirSync(dpath) == null).assertTrue();
}
})
/**
* @tc.number SUB_DF_FileIO_Dir_IsFILE_0000
* @tc.name fileio_test_dirent_is_file_000
* @tc.desc Test isFILE() interface.
*/
it('fileio_test_dirent_is_file_000', 0, function () {
let dpath = nextFileName('fileio_test_dirent_is_file_000') + 'd';
let fpath = dpath + '/f1';
try {
expect(fileio.mkdirSync(dpath) == null).assertTrue();
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
let dd = fileio.opendirSync(dpath);
expect(dd !== null).assertTrue();
let dirent = dd.readSync();
expect(dirent !== null).assertTrue();
expect(isBoolean(dirent.isFile())).assertTrue();
expect(dd.closeSync() == null).assertTrue();
expect(fileio.unlinkSync(fpath) == null).assertTrue();
expect(fileio.rmdirSync(dpath) == null).assertTrue();
} catch (e) {
console.log('fileio_test_dirent_is_file_000 has failed for ' + e);
expect(null).assertFail();
}
})
/**
* @tc.number SUB_DF_FileIO_Dir_IsFILE_0010
* @tc.name fileio_test_dirent_is_file_001
* @tc.desc Test isFILE() interface.
*/
it('fileio_test_dirent_is_file_001', 0, function () {
let dpath = nextFileName('fileio_test_dirent_is_file_001') + 'd';
let fpath = dpath + '/f1';
let dd;
try {
expect(fileio.mkdirSync(dpath) == null).assertTrue();
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
dd = fileio.opendirSync(dpath);
expect(dd !== null).assertTrue();
let dirent = dd.readSync();
expect(dirent !== null).assertTrue();
dirent.isFile(-1);
expect(null).assertFail();
} catch (e) {
expect(dd.closeSync() == null).assertTrue();
expect(fileio.unlinkSync(fpath) == null).assertTrue();
expect(fileio.rmdirSync(dpath) == null).assertTrue();
}
})
/**
* @tc.number SUB_DF_FileIO_Dir_IsSocket_0000
* @tc.name fileio_test_dirent_is_socket_000
* @tc.desc Test isSocket() interface.
*/
it('fileio_test_dirent_is_socket_000', 0, function () {
let dpath = nextFileName('fileio_test_dirent_is_socket_000') + 'd';
let fpath = dpath + '/f1';
try {
expect(fileio.mkdirSync(dpath) == null).assertTrue();
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
let dd = fileio.opendirSync(dpath);
expect(dd !== null).assertTrue();
let dirent = dd.readSync();
expect(dirent !== null).assertTrue();
expect(isBoolean(dirent.isSocket())).assertTrue();
expect(dd.closeSync() == null).assertTrue();
expect(fileio.unlinkSync(fpath) == null).assertTrue();
expect(fileio.rmdirSync(dpath) == null).assertTrue();
} catch (e) {
console.log('fileio_test_dirent_is_socket_000 has failed for ' + e);
expect(null).assertFail();
}
})
/**
* @tc.number SUB_DF_FileIO_Dir_IsSocket_0010
* @tc.name fileio_test_dirent_is_socket_001
* @tc.desc Test isSocket() interface.
*/
it('fileio_test_dirent_is_socket_001', 0, function () {
let dpath = nextFileName('fileio_test_dirent_is_socket_001') + 'd';
let fpath = dpath + '/f1';
let dd;
try {
expect(fileio.mkdirSync(dpath) == null).assertTrue();
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
dd = fileio.opendirSync(dpath);
expect(dd !== null).assertTrue();
let dirent = dd.readSync();
expect(dirent !== null).assertTrue()
dirent.isSocket(-1);
expect(null).assertFail();
} catch (e) {
expect(dd.closeSync() == null).assertTrue();
expect(fileio.unlinkSync(fpath) == null).assertTrue();
expect(fileio.rmdirSync(dpath) == null).assertTrue();
}
})
/**
* @tc.number SUB_DF_FileIO_Dir_IsSymbolicLink_0000
* @tc.name fileio_test_dirent_is_symbolic_link_000
* @tc.desc Test isSymbolicLink() interface.
*/
it('fileio_test_dirent_is_symbolic_link_000', 0, function () {
let dpath = nextFileName('fileio_test_dirent_is_symbolic_link_000') + 'd';
let fpath = dpath + '/f1';
try {
expect(fileio.mkdirSync(dpath) == null).assertTrue();
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
let dd = fileio.opendirSync(dpath);
expect(dd !== null).assertTrue()
let dirent = dd.readSync();
expect(dirent !== null).assertTrue();
expect(isBoolean(dirent.isSymbolicLink())).assertTrue();
expect(dd.closeSync() == null).assertTrue();
expect(fileio.unlinkSync(fpath) == null).assertTrue();
expect(fileio.rmdirSync(dpath) == null).assertTrue();
} catch (e) {
console.log('fileio_test_dirent_is_symbolic_link_000 has failed for ' + e);
expect(null).assertFail();
}
})
/**
* @tc.number SUB_DF_FileIO_Dir_IsSymbolicLink_0010
* @tc.name fileio_test_dirent_is_symbolic_link_001
* @tc.desc Test isSymbolicLink() interface.
*/
it('fileio_test_dirent_is_symbolic_link_001', 0, function () {
let dpath = nextFileName('fileio_test_dirent_is_symbolic_link_001') + 'd';
let fpath = dpath + '/f1';
let dd;
try {
expect(fileio.mkdirSync(dpath) == null).assertTrue();
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
dd = fileio.opendirSync(dpath);
expect(dd !== null).assertTrue();
let dirent = dd.readSync();
expect(dirent !== null).assertTrue();
dirent.isSymbolicLink(-1);
expect(null).assertFail();
} catch (e) {
expect(dd.closeSync() == null).assertTrue();
expect(fileio.unlinkSync(fpath) == null).assertTrue()
expect(fileio.rmdirSync(dpath) == null).assertTrue();
}
});
});
\ No newline at end of file
/*
* Copyright (C) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the 'License');
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an 'AS IS' BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import {
fileio, FILE_CONTENT, prepareFile, nextFileName,
describe, it, expect,
} from '../../Common';
describe('fileio_stream', function () {
/**
* @tc.number SUB_DF_FileIO_Stream_CreateStreamSync_0000
* @tc.name fileio_test_stream_create_stream_sync_000
* @tc.desc Test createStreamSync() interface.
*/
it('fileio_test_stream_create_stream_sync_000', 0, function () {
let fpath = nextFileName('fileio_test_stream_create_stream_sync_000');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
let ss = fileio.createStreamSync(fpath, 'r+');
expect(ss !== null).assertTrue();
expect(ss.closeSync() == null).assertTrue();
expect(fileio.unlinkSync(fpath) == null).assertTrue();
} catch (e) {
console.log('fileio_test_stream_create_stream_sync_000 has failed for ' + e);
expect(null).assertFail();
}
});
/**
* @tc.number SUB_DF_FileIO_Stream_CreateStreamSync_0010
* @tc.name fileio_test_stream_create_stream_sync_001
* @tc.desc Test createStreamSync() interface.
*/
it('fileio_test_stream_create_stream_sync_001', 0, function () {
let fpath = nextFileName('fileio_test_stream_create_stream_sync_001');
try {
fileio.createStreamSync(fpath, 'r+');
expect(null).assertFail();
} catch (e) {
}
});
/**
* @tc.number SUB_DF_FileIO_Stream_CreateStreamSync_0020
* @tc.name fileio_test_stream_create_stream_sync_002
* @tc.desc Test createStreamSync() interface.
*/
it('fileio_test_stream_create_stream_sync_002', 0, function () {
let fpath = nextFileName('fileio_test_stream_create_stream_sync_002');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
fileio.createStreamSync(fpath, 'ohos');
expect(null).assertFail();
} catch (e) {
expect(fileio.unlinkSync(fpath) == null).assertTrue();
}
});
/**
* @tc.number SUB_DF_FileIO_Stream_ReadSync_0000
* @tc.name fileio_test_stream_read_sync_000
* @tc.desc Test readSync() interface.
*/
it('fileio_test_stream_read_sync_000', 0, function () {
let fpath = nextFileName('fileio_test_stream_read_sync_000');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
let ss = fileio.createStreamSync(fpath, 'r+');
expect(ss !== null).assertTrue();
let len = ss.readSync(new ArrayBuffer(4096));
expect(len == FILE_CONTENT.length).assertTrue();
expect(ss.closeSync() == null).assertTrue();
expect(fileio.unlinkSync(fpath) == null).assertTrue();
} catch (e) {
console.log('fileio_test_stream_read_sync_000 has failed for ' + e);
expect(null).assertFail();
}
});
/**
* @tc.number SUB_DF_FileIO_Stream_ReadSync_0010
* @tc.name fileio_test_stream_read_sync_001
* @tc.desc Test the readSync method of class Stream.
*/
it('fileio_test_stream_read_sync_001', 0, function () {
let bufLen = 5;
expect(FILE_CONTENT.length > bufLen).assertTrue();
let fpath = nextFileName('fileio_test_stream_read_sync_001');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
let ss = fileio.createStreamSync(fpath, 'r+');
let len = ss.readSync(new ArrayBuffer(bufLen), {
offset: 1
});
expect(len == (bufLen - 1)).assertTrue();
expect(ss.closeSync() == null).assertTrue();
expect(fileio.unlinkSync(fpath) == null).assertTrue();
} catch (e) {
console.log('fileio_test_stream_read_sync_001 has failed for ' + e);
expect(null).assertFail();
}
});
/**
* @tc.number SUB_DF_FileIO_Stream_ReadSync_0020
* @tc.name fileio_test_stream_read_sync_002
* @tc.desc Test the readSync method of class Stream.
*/
it('fileio_test_stream_read_sync_002', 0, function () {
let fpath = nextFileName('fileio_test_stream_read_sync_002');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
let ss = fileio.createStreamSync(fpath, 'r+');
let len = ss.readSync(new ArrayBuffer(4096), {
length: 1
});
expect(len == 1).assertTrue();
expect(ss.closeSync() == null).assertTrue();
expect(fileio.unlinkSync(fpath) == null).assertTrue();
} catch (e) {
console.log('fileio_test_stream_read_sync_002 has failed for ' + e);
expect(null).assertFail();
}
});
/**
* @tc.number SUB_DF_FileIO_Stream_ReadSync_0030
* @tc.name fileio_test_stream_read_sync_003
* @tc.desc Test the readSync method of class Stream.
*/
it('fileio_test_stream_read_sync_003', 0, function () {
let fpath = nextFileName('fileio_test_stream_read_sync_003');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
let ss = fileio.createStreamSync(fpath, 'r+');
let len = ss.readSync(new ArrayBuffer(4096), {
position: 1
});
expect(len == (FILE_CONTENT.length - 1)).assertTrue();
expect(ss.closeSync() == null).assertTrue();
expect(fileio.unlinkSync(fpath) == null).assertTrue();
} catch (e) {
console.log('fileio_test_stream_read_sync_003 has failed for ' + e);
expect(null).assertFail();
}
});
/**
* @tc.number SUB_DF_FileIO_Stream_ReadSync_0040
* @tc.name fileio_test_stream_read_sync_004
* @tc.desc Test the readSync method of class Stream.
*/
it('fileio_test_stream_read_sync_004', 0, function () {
let ss;
const invalidOffset = 99999;
let fpath = nextFileName('fileio_test_stream_read_sync_004');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
ss = fileio.createStreamSync(fpath, 'r+');
ss.readSync(new ArrayBuffer(4096), {
offset: invalidOffset
});
expect(null).assertFail();
} catch (e) {
expect(ss.closeSync() == null).assertTrue();
expect(fileio.unlinkSync(fpath) == null).assertTrue();
}
});
/**
* @tc.number SUB_DF_FileIO_Stream_ReadSync_0050
* @tc.name fileio_test_stream_read_sync_005
* @tc.desc Test the readSync method of class Stream.
*/
it('fileio_test_stream_read_sync_005', 0, function () {
let ss;
const invalidLength = 9999;
let fpath = nextFileName('fileio_test_stream_read_sync_005');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
ss = fileio.createStreamSync(fpath, 'r+');
ss.readSync(new ArrayBuffer(4096), {
length: invalidLength
});
expect(null).assertFail();
} catch (e) {
expect(ss.closeSync() == null).assertTrue();
expect(fileio.unlinkSync(fpath) == null).assertTrue();
}
});
/**
* @tc.number SUB_DF_FileIO_Stream_ReadSync_0060
* @tc.name fileio_test_stream_read_sync_006
* @tc.desc Test the readSync method of class Stream.
*/
it('fileio_test_stream_read_sync_006', 0, function () {
let fpath = nextFileName('fileio_test_stream_read_sync_006');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
let ss = fileio.createStreamSync(fpath, 'r+');
let invalidPos = FILE_CONTENT.length + 1;
let len = ss.readSync(new ArrayBuffer(4096), {
position: invalidPos
});
expect(len == 0).assertTrue();
expect(ss.closeSync() == null).assertTrue();
expect(fileio.unlinkSync(fpath) == null).assertTrue();
} catch (e) {
console.log('fileio_test_stream_read_sync_006 has failed for ' + e);
expect(null).assertFail();
}
});
/**
* @tc.number SUB_DF_FileIO_Stream_WriteSync_0000
* @tc.name fileio_test_stream_write_sync_000
* @tc.desc Test writeSync() interface.
*/
it('fileio_test_stream_write_sync_000', 0, function () {
let fpath = nextFileName('fileio_test_stream_write_sync_000');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
let ss = fileio.createStreamSync(fpath, 'r+');
expect(ss !== null).assertTrue();
expect(ss.writeSync(FILE_CONTENT) == FILE_CONTENT.length).assertTrue();
expect(ss.closeSync() == null).assertTrue();
expect(fileio.unlinkSync(fpath) == null).assertTrue();
} catch (e) {
console.log('fileio_test_stream_write_sync_000 has failed for ' + e);
expect(null).assertFail();
}
});
});
\ No newline at end of file
/*
* Copyright (C) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the 'License');
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an 'AS IS' BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import {
fileio, FILE_CONTENT, prepareFile, nextFileName,
describe, it, expect,
} from '../../Common';
describe('fileio_stream', function () {
/**
* @tc.number SUB_DF_FileIO_Stream_FdopenStreamSync_0000
* @tc.name fileio_test_stream_fdopen_stream_sync_000
* @tc.desc Test fdopenStreamSync() interface.
*/
it('fileio_test_stream_fdopen_stream_sync_000', 0, function () {
let fpath = nextFileName('fileio_test_stream_fdopen_stream_sync_000');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
let fd = fileio.openSync(fpath, 0o2);
let ss = fileio.fdopenStreamSync(fd, 'r+');
expect(ss !== null).assertTrue();
expect(ss.closeSync() == null).assertTrue();
expect(fileio.unlinkSync(fpath) == null).assertTrue();
} catch (e) {
console.log('fileio_test_stream_fdopen_stream_sync_000 has failed for ' + e);
expect(null).assertFail();
}
})
/**
* @tc.number SUB_DF_FileIO_Stream_FdopenStreamSync_0010
* @tc.name fileio_test_stream_fdopen_stream_sync_001
* @tc.desc Test fdopenStreamSync() interface.
*/
it('fileio_test_stream_fdopen_stream_sync_001', 0, function () {
try {
let ss = fileio.fdopenStreamSync(-1, 'r+');
expect(null).assertFail();
} catch (e) {
}
})
/**
* @tc.number SUB_DF_FileIO_Stream_FdopenStreamAsync_0000
* @tc.name fileio_test_stream_fdopen_stream_async_000
* @tc.desc Test fdopenStreamSync() interface.
*/
it('fileio_test_stream_fdopen_stream_async_000', 0, async function (done) {
let fpath = nextFileName('fileio_test_stream_fdopen_stream_async_000');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
let fd = await fileio.openSync(fpath, 0o2);
let ss = await fileio.fdopenStreamSync(fd, 'r+');
expect(ss !== null).assertTrue();
expect(fileio.closeSync(fd) == null).assertTrue();
expect(ss.closeSync() == null).assertTrue();
expect(fileio.unlinkSync(fpath) == null).assertTrue();
done();
} catch (e) {
console.log('fileio_test_stream_fdopen_stream_async_000 has failed for ' + e);
expect(null).assertFail();
}
});
/**
* @tc.number SUB_DF_FileIO_Stream_FdopenStreamAsync_0010
* @tc.name fileio_test_stream_fdopen_stream_async_001
* @tc.desc Test fdopenStreamSync() interface.
*/
it('fileio_test_stream_fdopen_stream_async_001', 0, async function (done) {
let fpath = nextFileName('fileio_test_stream_fdopen_stream_async_001');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
let fd = await fileio.openSync(fpath, 0o2);
let ss = await fileio.fdopenStreamSync(fd, 'r+');
expect(ss !== null).assertTrue();
expect(fileio.closeSync(fd) == null).assertTrue();
ss.close(function (err, stream) {
expect(fileio.unlinkSync(fpath) == null).assertTrue();
})
done();
} catch (e) {
console.log('fileio_test_stream_fdopen_stream_async_001 has failed for ' + e);
expect(null).assertFail();
}
});
});
\ No newline at end of file
/*
* Copyright (C) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the 'License');
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an 'AS IS' BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import {
fileio, FILE_CONTENT, prepareFile, nextFileName,
describe, it, expect,
} from '../../Common';
describe('fileio_stream', function () {
/**
* @tc.number SUB_DF_FileIO_Stream_FlushSync_0000
* @tc.name fileio_test_stream_flush_sync_000
* @tc.desc Test flushSync() interface.
*/
it('fileio_test_stream_flush_sync_000', 0, function () {
let fpath = nextFileName('fileio_test_stream_flush_sync_000');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
let ss = fileio.createStreamSync(fpath, 'r+');
expect(ss !== null).assertTrue();
expect(ss.writeSync(FILE_CONTENT) == FILE_CONTENT.length).assertTrue();
expect(ss.flushSync() == null).assertTrue();
expect(ss.closeSync() == null).assertTrue();
expect(fileio.unlinkSync(fpath) == null).assertTrue();
} catch (e) {
console.log('fileio_test_stream_flush_sync_000 has failed for ' + e);
expect(null).assertFail();
}
});
/**
* @tc.number SUB_DF_FileIO_Stream_FlushAsync_0000
* @tc.name fileio_test_stream_flush_async_000
* @tc.desc Test flushSync() interface.
*/
it('fileio_test_stream_flush_async_000', 0, async function (done) {
let fpath = nextFileName('fileio_test_stream_flush_async_000');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
let ss = await fileio.createStreamSync(fpath, 'r+');
expect(ss !== null).assertTrue();
ss.flush().then(
function (err) {
expect(!err).assertTrue();
expect(ss.writeSync(FILE_CONTENT) == FILE_CONTENT.length).assertTrue();
expect(ss.closeSync() == null).assertTrue();
expect(fileio.unlinkSync(fpath) == null).assertTrue();
})
done();
} catch (e) {
console.log('fileio_test_stream_flush_async_000 has failed for ' + e);
expect(null).assertFail();
}
});
/**
* @tc.number SUB_DF_FileIO_Stream_FlushAsync_0010
* @tc.name fileio_test_stream_flush_async_001
* @tc.desc Test flushSync() interface.
*/
it('fileio_test_stream_flush_async_001', 0, async function (done) {
let fpath = nextFileName('fileio_test_stream_flush_async_001');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
let ss = await fileio.createStreamSync(fpath, 'r+');
expect(ss !== null).assertTrue();
expect(ss.writeSync(FILE_CONTENT) == FILE_CONTENT.length).assertTrue();
ss.flush(function (err) {
expect(ss.closeSync() == null).assertTrue();
expect(fileio.unlinkSync(fpath) == null).assertTrue();
done();
})
} catch (e) {
console.log('fileio_test_stream_flush_async_001 has failed for ' + e);
expect(null).assertFail();
}
});
});
/*
* Copyright (C) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the 'License');
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an 'AS IS' BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import {
fileio, FILE_CONTENT, prepareFile, nextFileName,
describe, it, expect,
} from '../../Common';
describe('fileio_stream', function () {
/**
* @tc.number SUB_DF_FileIO_Stream_ReadAsync_0000
* @tc.name fileio_test_stream_read_async_000
* @tc.desc Test readAsync() interface.
*/
it('fileio_test_stream_read_async_000', 0, async function (done) {
let fpath = nextFileName('fileio_test_stream_read_async_000');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
let ss = fileio.createStreamSync(fpath, 'r+');
expect(ss !== null).assertTrue();
let readout = await ss.read(new ArrayBuffer(4096));
expect(readout.bytesRead == FILE_CONTENT.length).assertTrue();
expect(ss.closeSync() == null).assertTrue();
expect(fileio.unlinkSync(fpath) == null).assertTrue();
done();
} catch (e) {
console.log('fileio_test_stream_read_async_000 has failed for ' + e);
expect(null).assertFail();
}
});
/**
* @tc.number SUB_DF_FileIO_Stream_ReadAsync_0010
* @tc.name fileio_test_stream_read_async_001
* @tc.desc Test readAsync() interface.
*/
it('fileio_test_stream_read_async_001', 0, function () {
let fpath = nextFileName('fileio_test_stream_read_async_001');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
let ss = fileio.createStreamSync(fpath, 'r+');
expect(ss !== null).assertTrue();
ss.read(new ArrayBuffer(4096), null, function (err, readout) {
expect(readout.bytesRead == FILE_CONTENT.length).assertTrue();
expect(ss.closeSync() == null).assertTrue();
expect(fileio.unlinkSync(fpath) == null).assertTrue();
});
} catch (e) {
console.log('fileio_test_stream_read_async_001 has failed for ' + e);
expect(null).assertFail();
}
});
});
/*
* Copyright (C) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the 'License');
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an 'AS IS' BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import {
fileio, FILE_CONTENT, prepareFile, nextFileName,
describe, it, expect,
} from '../../Common';
describe('fileio_stream', function () {
/**
* @tc.number SUB_DF_FileIO_Stream_WriteASync_0000
* @tc.name fileio_test_stream_write_async_000
* @tc.desc Test Stream.write() interface.
*/
it('fileio_test_stream_write_async_000', 0, async function (done) {
let fpath = nextFileName('fileio_test_stream_write_async_000');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
let ss = fileio.createStreamSync(fpath, 'r+');
expect(ss !== null).assertTrue();
ss.write(new ArrayBuffer(4096), {
position: 1
}).then(function (len) {
expect(len == (FILE_CONTENT.length - 1)).assertTrue();
expect(fileio.unlinkSync(fpath) == null).assertTrue();
})
done();
} catch (e) {
console.log('fileio_test_stream_write_async_000 has failed for ' + e);
expect(null).assertFail();
}
});
/**
* @tc.number SUB_DF_FileIO_Stream_WriteASync_0010
* @tc.name fileio_test_stream_write_async_001
* @tc.desc Test Stream.write() interface.
*/
it('fileio_test_stream_write_async_001', 0, async function (done) {
let fpath = nextFileName('fileio_test_stream_write_async_001');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
let ss = fileio.createStreamSync(fpath, 'r+');
expect(ss !== null).assertTrue();
ss.write(new ArrayBuffer(4096), { offset: 1, encoding: 'utf-8' }, function (err, bytesWritten) {
expect(bytesWritten == (FILE_CONTENT.length - 1)).assertTrue();
expect(fileio.unlinkSync(fpath) == null).assertTrue();
});
done();
} catch (e) {
console.log('fileio_test_stream_write_async_001 has failed for ' + e);
expect(null).assertFail();
}
});
});
/*
* Copyright (C) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the 'License');
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an 'AS IS' BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import {
fileio, FILE_CONTENT, prepareFile, nextFileName,
describe, it, expect,
} from '../../Common';
describe('fileio_createWatcher', function () {
/**
* @tc.number SUB_DF_FileIO_createWatcher_000
* @tc.name fileio_test_createWatcher_000
* @tc.desc Test createWatcher() interface. rename 1 times stopSync()
*/
it('fileio_test_createWatcher_async_000', 0, async function (done) {
let fpath = nextFileName('fileio_test_createWatcher_async_000');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
let event = 1;
let flag = 0;
let ob = await fileio.createWatcher(fpath, event, function (data) {
expect(data == event).assertTrue();
flag = 1;
});
let after = fpath + 'yjz';
await fileio.rename(fpath, after);
setTimeout(function () {
expect(flag == 1).assertTrue();
ob.stopSync();
expect(fileio.unlinkSync(after) == null).assertTrue();
done();
}, 51);
} catch (e) {
console.log('fileio_test_createWatcher_000 has failed for ' + e);
expect(null).assertFail();
}
});
/**
* @tc.number SUB_DF_FileIO_createWatcher_000
* @tc.name fileio_test_createWatcher_001
* @tc.desc Test createWatcher() interface. write 1 times stopSync()
*/
it('fileio_test_createWatcher_async_001', 0, async function (done) {
let fpath = nextFileName('fileio_test_createWatcher_async_001');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
let event = 2;
let flag = 0;
let ob = await fileio.createWatcher(fpath, event, function (data) {
flag = 1;
});
let fd = fileio.openSync(fpath, 0o2);
let ss = 'okk';
await fileio.write(fd, ss);
await fileio.write(fd, ss);
ob.stopSync();
expect(flag == 1).assertTrue();
expect(fileio.closeSync(fd) == null).assertTrue();
expect(fileio.unlinkSync(fpath) == null).assertTrue();
done();
} catch (e) {
console.log('fileio_test_createWatcher_001 has failed for ' + e);
expect(null).assertFail();
}
});
/**
* @tc.number SUB_DF_FileIO_createWatcher_000
* @tc.name fileio_test_createWatcher_002
* @tc.desc Test createWatcher() interface. rename 1 time ,stop()
*/
it('fileio_test_createWatcher_async_002', 0, async function (done) {
let fpath = nextFileName('fileio_test_createWatcher_async_002');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
let event = 1;
let flag = 0;
let ob = await fileio.createWatcher(fpath, event, function (data) {
expect(data == event).assertTrue();
flag = 1;
});
let after = fpath + 'yjz';
fileio.renameSync(fpath, after);
setTimeout(async function () {
expect(flag == 1).assertTrue();
await ob.stop();
expect(fileio.unlinkSync(after) == null).assertTrue();
done();
}, 50);
} catch (e) {
console.log('fileio_test_createWatcher_002 has failed for ' + e);
expect(null).assertFail();
}
});
/**
* @tc.number SUB_DF_FileIO_createWatcher_000
* @tc.name fileio_test_createWatcher_003
* @tc.desc Test createWatcher() interface. rename 1 time ,stop()
*/
it('fileio_test_createWatcher_async_003', 0, async function (done) {
let fpath = nextFileName('fileio_test_createWatcher_async_003');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
let event = 1;
let flag = 0;
let ob = await fileio.createWatcher(fpath, event, function (data) {
expect(data == event).assertTrue();
flag = 3;
});
let after = fpath + 'yjz';
await fileio.rename(fpath, after);
await fileio.rename(after, after);
ob.stop(function () {
expect(flag == 3).assertTrue();
expect(fileio.unlinkSync(after) == null).assertTrue();
done();
});
} catch (e) {
console.log('fileio_test_createWatcher_003 has failed for ' + e);
expect(null).assertFail();
}
});
/**
* @tc.number SUB_DF_FileIO_createWatcher_000
* @tc.name fileio_test_createWatcher_004
* @tc.desc Test createWatcher() interface.write 1 time ,stop()
*/
it('fileio_test_createWatcher_async_004', 0, async function (done) {
let fpath = nextFileName('fileio_test_createWatcher_async_004');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
let event = 2;
let flag = 0;
let ob = await fileio.createWatcher(fpath, event, function (data) {
expect(data == 2).assertTrue();
flag = 4;
});
let fd = fileio.openSync(fpath, 0o2);
let ss = 'okk';
await fileio.write(fd, ss);
await fileio.write(fd, ss);
ob.stop(function () {
expect(flag == 4).assertTrue();
expect(fileio.closeSync(fd) == null).assertTrue();
expect(fileio.unlinkSync(fpath) == null).assertTrue();
done();
});
} catch (e) {
console.log('fileio_test_createWatcher_004 has failed for ' + e);
expect(null).assertFail();
}
});
/**
* @tc.number SUB_DF_FileIO_createWatcher_000
* @tc.name fileio_test_createWatcher_005
* @tc.desc Test createWatcher() interface. rename 3 times
*/
it('fileio_test_createWatcher_async_005', 0, async function (done) {
let fpath = nextFileName('fileio_test_createWatcher_async_005');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
let event = 1;
let flag = 0;
let ob = await fileio.createWatcher(fpath, event, function (data) {
expect(data == event).assertTrue();
flag = flag + 1;
});
let after = fpath + 'yjz';
await fileio.rename(fpath, after);
await fileio.rename(after, fpath);
await fileio.rename(fpath, after);
setTimeout(function () {
ob.stopSync();
console.log('fileio_test_createWatcher_async_005 flag is ' + flag);
expect(flag == 2 || flag == 3).assertTrue();
expect(fileio.unlinkSync(after) == null).assertTrue();
done();
}, 51);
} catch (e) {
console.log('fileio_test_createWatcher_005 has failed for ' + e);
expect(null).assertFail();
}
});
/**
* @tc.number SUB_DF_FileIO_createWatcher_000
* @tc.name fileio_test_createWatcher_006
* @tc.desc Test createWatcher() interface.write 2 times, stop()
*/
it('fileio_test_createWatcher_async_006', 0, async function (done) {
let fpath = nextFileName('fileio_test_createWatcher_async_006');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
let event = 2;
let flag = 0;
let ob = await fileio.createWatcher(fpath, event, function (data) {
expect(data == 2).assertTrue();
flag = flag + 1;
});
let fd = fileio.openSync(fpath, 0o2);
let ss = 'okk';
await fileio.write(fd, ss);
await fileio.write(fd, ss);
await ob.stop();
console.log('fileio_test_createWatcher_async_006 flag is' + flag);
expect(flag == 1 || flag == 2).assertTrue();
expect(fileio.closeSync(fd) == null).assertTrue();
expect(fileio.unlinkSync(fpath) == null).assertTrue();
done();
} catch (e) {
console.log('fileio_test_createWatcher_006 has failed for ' + e);
expect(null).assertFail();
}
});
/**
* @tc.number SUB_DF_FileIO_createWatcher_000
* @tc.name fileio_test_createWatcher_007
* @tc.desc Test createWatcher() interface.rename 1 times, write 1 times, stop()
*/
it('fileio_test_createWatcher_async_007', 0, async function (done) {
let fpath = nextFileName('fileio_test_createWatcher_async_007');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
let event = 3;
let flag = 0;
let ob = await fileio.createWatcher(fpath, event, function (data) {
flag = flag + 1;
});
let fd = fileio.openSync(fpath, 0o2);
let ss = 'okk';
await fileio.write(fd, ss);
let after = fpath + 'yjz';
await fileio.rename(fpath, after);
await ob.stop();
console.log('fileio_test_createWatcher_async_007 flag is ' + flag);
expect(flag == 1 || flag == 2).assertTrue();
expect(fileio.closeSync(fd) == null).assertTrue();
expect(fileio.unlinkSync(after) == null).assertTrue();
done();
} catch (e) {
console.log('fileio_test_createWatcher_007 has failed for ' + e);
expect(null).assertFail();
}
});
/**
* @tc.number SUB_DF_FileIO_createWatcher_000
* @tc.name fileio_test_createWatcher_008
* @tc.desc Test createWatcher() interface.rename 1 times, write 1 times, stop()
*/
it('fileio_test_createWatcher_async_008', 0, async function (done) {
let fpath = nextFileName('fileio_test_createWatcher_async_007');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
let event = 3;
let flag = 0;
await fileio.createWatcher(fpath, event, function (data) {
flag = flag + 1;
});
let fd = fileio.openSync(fpath, 0o2);
let ss = 'okk';
await fileio.write(fd, ss);
let after = fpath + 'yjz';
await fileio.rename(fpath, after);
setTimeout(function () {
expect(flag == 2).assertTrue();
expect(fileio.closeSync(fd) == null).assertTrue();
expect(fileio.unlinkSync(after) == null).assertTrue();
done();
}, 50);
} catch (e) {
console.log('fileio_test_createWatcher_008 has failed for ' + e);
expect(null).assertFail();
}
});
});
/*
* Copyright (C) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the 'License');
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an 'AS IS' BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import {
fileio, FILE_CONTENT, prepareFile, nextFileName, isIntNum,
describe, it, expect,
} from '../../Common';
describe('fileio_access', function () {
/**
* @tc.number SUB_DF_FileIO_AccessSync_0000
* @tc.name fileio_test_access_sync_000
* @tc.desc Test accessSync() interface.
* This interface shall work properly in normal case.
*/
it('fileio_test_access_sync_000', 0, function () {
let fpath = nextFileName('fileio_test_access_sync_000');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
expect(fileio.accessSync(fpath) == null).assertTrue();
expect(fileio.unlinkSync(fpath) == null).assertTrue();
} catch (e) {
console.log('fileio_test_access_sync_000 has failed for ' + e);
expect(null).assertFail();
}
});
/**
* @tc.number SUB_DF_FileIO_AccessSync_0010
* @tc.name fileio_test_access_sync_001
* @tc.desc Test accessSync() interface.
* This interface shall throw an exception when the fpath is not given.
*/
it('fileio_test_access_sync_001', 0, function () {
let fpath = nextFileName('fileio_test_access_sync_001');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
expect(fileio.accessSync(fpath, 0x2) == null).assertTrue();
expect(fileio.unlinkSync(fpath) == null).assertTrue();
} catch (e) {
console.log('fileio_test_access_sync_001' + e);
expect(null).assertFail();
}
});
/**
* @tc.number SUB_DF_FileIO_AccessSync_0020
* @tc.name fileio_test_access_sync_002
* @tc.desc Test accessSync() interface.
* This interface shall throw an exception when the fpath is not given.
*/
it('fileio_test_access_sync_002', 0, function () {
let fpath = nextFileName('fileio_test_access_sync_002');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
expect(fileio.accessSync(fpath, 0x4) == null).assertTrue();
expect(fileio.unlinkSync(fpath) == null).assertTrue();
} catch (e) {
console.log('fileio_test_access_sync_002' + e);
expect(null).assertFail();
}
});
/**
* @tc.number SUB_DF_FileIO_AccessSync_0030
* @tc.name fileio_test_access_sync_003
* @tc.desc Test accessSync() interface.
* This interface shall throw an exception when the fpath is not given.
*/
it('fileio_test_access_sync_003', 0, function () {
let fpath = nextFileName('fileio_test_access_sync_003');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
expect(fileio.accessSync(fpath, 0x2 | 0x4) == null).assertTrue();
expect(fileio.unlinkSync(fpath) == null).assertTrue();
} catch (e) {
console.log('fileio_test_access_sync_003' + e);
expect(null).assertFail();
}
});
/**
* @tc.number SUB_DF_FileIO_AccessSync_0040
* @tc.name fileio_test_access_sync_004
* @tc.desc Test accessSync() interface.
* This interface shall throw an exception when the fpath is not given.
*/
it('fileio_test_access_sync_004', 0, function () {
let fpath = nextFileName('fileIOTest');
try {
fileio.accessSync(fpath);
expect(null).assertFail();
} catch (e) {
}
});
/**
* @tc.number SUB_DF_FileIO_AccessAsync_0000
* @tc.name fileio_test_access_async_000
* @tc.desc Test accessAsync() interface.
* This interface shall throw an exception when the fpath is not given.
*/
it('fileio_test_access_async_000', 0, async function (done) {
let fpath = nextFileName('fileio_test_access_async_000');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
await fileio.access(fpath);
expect(fileio.unlinkSync(fpath) == null).assertTrue();
done();
} catch (error) {
console.log('fileio_test_access_async_000 has failed for ' + error);
expect(null).assertFail();
}
});
/**
* @tc.number SUB_DF_FileIO_AccessAsync_0010
* @tc.name fileio_test_access_async_001
* @tc.desc Test accessAsync() interface.
* This interface shall throw an exception when the fpath is not given.
*/
it('fileio_test_access_async_001', 0, async function (done) {
let fpath = nextFileName('fileio_test_access_async_001');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
expect(await fileio.access(fpath, 4) == null).assertTrue();
let fd = fileio.openSync(fpath);
expect(isIntNum(fd)).assertTrue();
expect(
(await fileio.read(fd, new ArrayBuffer(4096))) != null
).assertTrue();
expect(fileio.closeSync(fd) == null).assertTrue();
expect(fileio.unlinkSync(fpath) == null).assertTrue();
done();
} catch (error) {
console.log('fileio_test_access_async_001 has failed for ' + error);
expect(null).assertFail();
}
});
/**
* @tc.number SUB_DF_FileIO_AccessAsync_0020
* @tc.name fileio_test_access_async_002
* @tc.desc Test accessAsync() interface.
* This interface shall throw an exception when the fpath is not given.
*/
it('fileio_test_access_async_002', 0, async function (done) {
let fpath = nextFileName('fileio_test_access_async_002');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
fileio.access(fpath, function (error) {
expect(fileio.unlinkSync(fpath) == null).assertTrue();
done();
});
} catch (error) {
console.log('fileio_test_access_async_002 has failed for ' + error);
expect(null).assertFail();
}
});
/**
* @tc.number SUB_DF_FileIO_AccessAsync_0030
* @tc.name fileio_test_access_async_003
* @tc.desc Test accessAsync() interface.
* This interface shall throw an exception when the fpath is not given.
*/
it('fileio_test_access_async_003', 0, async function (done) {
let fpath = nextFileName('fileio_test_access_async_003');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
fileio.access(fpath, 4, async function (error) {
let fd = fileio.openSync(fpath);
expect(isIntNum(fd)).assertTrue();
expect(
(await fileio.read(fd, new ArrayBuffer(4096))) != null
).assertTrue();
expect(fileio.closeSync(fd) == null).assertTrue();
expect(fileio.unlinkSync(fpath) == null).assertTrue();
});
done();
} catch (error) {
console.log('fileio_test_access_async_003 has failed for ' + error);
expect(null).assertFail();
}
});
/**
* @tc.number SUB_DF_FileIO_AccessAsync_0040
* @tc.name fileio_test_access_async_004
* @tc.desc Test accessAsync() interface.
* This interface shall throw an exception when the fpath is not given.
*/
it('fileio_test_access_async_004', 0, async function (done) {
let fpath = nextFileName('fileio_test_access_async_004');
try {
fileio
.access(fpath)
.then(function (err) {
expect(null).assertFail();
done();
})
.catch(function (e) {
expect(!!e).assertTrue();
done();
});
} catch (e) {
console.log('fileio_test_access_async_004 has failed for ' + e);
expect(null).assertFail();
}
});
});
/*
* Copyright (C) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the 'License');
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an 'AS IS' BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import {
fileio, FILE_CONTENT, prepareFile, nextFileName,
describe, it, expect,
} from '../../Common';
describe('fileio_chmod', function () {
/**
* @tc.number SUB_DF_FileIO_ChmodSync_0000
* @tc.name fileio_test_chmod_sync_000
* @tc.desc Test chmodSync() interfaces.
*/
it('fileio_test_chmod_sync_000', 0, function () {
let fpath = nextFileName('fileio_test_chmod_sync_000');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
expect(fileio.chmodSync(fpath, 0o660) == null).assertTrue();
expect((fileio.statSync(fpath).mode & 0o777) == 0o660).assertTrue();
expect(fileio.unlinkSync(fpath) == null).assertTrue();
} catch (e) {
console.log('fileio_test_chmod_sync_000 has failed for ' + e);
expect(null).assertFail();
}
});
/**
* @tc.number SUB_DF_FileIO_ChmodSync_0010
* @tc.name fileio_test_chmod_sync_001
* @tc.desc Test chmodSync() interfaces.
*/
it('fileio_test_chmod_sync_001', 0, function () {
let fpath = nextFileName('fileio_test_chmod_sync_001');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
expect(fileio.chmodSync(fpath, 0o0700) == null).assertTrue();
expect((fileio.statSync(fpath).mode & 0o777) == 0o0700).assertTrue();
expect(fileio.unlinkSync(fpath) == null).assertTrue();
} catch (e) {
console.log('fileio_test_chmod_sync_001 has failed for ' + e);
expect(null).assertFail();
}
});
/**
* @tc.number SUB_DF_FileIO_ChmodAsync_0000
* @tc.name fileio_test_chmod_async_000
* @tc.desc Test chmodAsync() interfaces.
*/
it('fileio_test_chmod_async_000', 0, async function (done) {
let fpath = nextFileName('fileio_test_chmod_async_001');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
fileio
.chmod(fpath, 0o660)
.then(function (err) {
expect(!err).assertTrue();
expect((fileio.statSync(fpath).mode & 0o777) == 0o660).assertTrue();
expect(fileio.unlinkSync(fpath) == null).assertTrue();
done();
})
.catch(function (e) {
console.log(e);
});
done();
} catch (e) {
console.log('fileio_test_chmod_async_000 has failed for ' + e);
expect(null).assertFail();
}
});
/**
* @tc.number SUB_DF_FileIO_ChmodAsync_0010
* @tc.name fileio_test_chmod_async_001
* @tc.desc Test chmodAsync() interfaces.
*/
it('fileio_test_chmod_async_001', 0, async function (done) {
let fpath = nextFileName('fileio_test_chmod_async_001');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
fileio
.chmod(fpath, 0o0700)
.then(function (err) {
expect(!err).assertTrue();
expect((fileio.statSync(fpath).mode & 0o777) == 0o0700).assertTrue();
expect(fileio.unlinkSync(fpath) == null).assertTrue();
done();
})
.catch(function (e) {
console.log(e);
});
done();
} catch (e) {
console.log('fileio_test_chmod_async_001 has failed for ' + e);
expect(null).assertFail();
}
});
/**
* @tc.number SUB_DF_FileIO_ChmodAsync_0020
* @tc.name fileio_test_chmod_async_002
* @tc.desc Test chmodAsync() interfaces.
*/
it('fileio_test_chmod_async_002', 0, async function (done) {
let fpath = nextFileName('fileio_test_chmod_async_000');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
await fileio.chmod(fpath, 0o660, async function () {
expect((fileio.statSync(fpath).mode & 0o777) == 0o660).assertTrue();
fileio.unlinkSync(fpath);
done();
});
} catch (e) {
console.log('fileio_test_chmod_async_002 has failed for ' + e);
expect(null).assertFail();
}
});
/**
* @tc.number SUB_DF_FileIO_ChmodAsync_0030
* @tc.name fileio_test_chmod_async_003
* @tc.desc Test chmodAsync() interfaces.
*/
it('fileio_test_chmod_async_003', 0, async function (done) {
let fpath = nextFileName('fileio_test_chmod_async_000');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
await fileio.chmod(fpath, 0o0700, async function () {
expect((fileio.statSync(fpath).mode & 0o777) == 0o0700).assertTrue();
fileio.unlinkSync(fpath);
done();
});
} catch (e) {
console.log('fileio_test_chmod_async_003 has failed for ' + e);
expect(null).assertFail();
}
});
});
/*
* Copyright (C) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the 'License');
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an 'AS IS' BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import {
fileio, FILE_CONTENT, prepareFile, nextFileName,
describe, it, expect,
} from '../../Common';
describe('fileio_chown', function () {
/**
* @tc.number SUB_DF_FileIO_ChownSync_000
* @tc.name fileio_test_chown_sync_000
* @tc.desc Test chownSync() interface.
*/
it('fileio_test_chown_sync_000', 0, function () {
let fpath = nextFileName('fileio_test_chown_sync_000');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
let stat = fileio.statSync(fpath);
expect(fileio.chownSync(fpath, stat.uid, stat.gid));
expect(fileio.unlinkSync(fpath) == null).assertTrue();
} catch (e) {
expect(null).assertFail();
}
});
/**
* @tc.number SUB_DF_FileIO_ChownASync_000
* @tc.name fileio_test_chown_async_00
* @tc.desc Test chownASync() interface.
*/
it('fileio_chown_async_000', 0, async function (done) {
let fpath = nextFileName('fileio_chown_Async_000');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
let stat = fileio.statSync(fpath);
expect(await fileio.chown(fpath, stat.uid, stat.gid) == null).assertTrue();
expect(fileio.unlinkSync(fpath) == null).assertTrue();
done();
} catch (e) {
console.log('fileio_test_chown_async_000 has failed for ' + e);
expect(null).assertFail();
}
});
/**
* @tc.number SUB_DF_FileIO_ChownASync_001
* @tc.name fileio_test_chown_async_00
* @tc.desc Test chownASync() interface.
*/
it('fileio_chown_async_001', 0, async function (done) {
let fpath = nextFileName('fileio_chown_Async_001');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
let stat = fileio.statSync(fpath);
fileio.chown(fpath, stat.uid, stat.gid, function (error) {
expect(fileio.unlinkSync(fpath) == null).assertTrue();
done();
});
} catch (e) {
console.log('fileio_chown_Async_001 has failed for ' + e);
expect(null).assertFail();
}
});
});
/*
* Copyright (C) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the 'License');
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an 'AS IS' BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import {
fileio,
describe, it, expect,
} from '../../Common';
describe('fileio_close', function () {
/**
* @tc.number SUB_DF_FileIO_CloseSync_0000
* @tc.name fileio_test_close_sync_000
* @tc.desc Test closeSync() interfaces.
*/
it('fileio_test_close_sync_000', 0, function () {
try {
fileio.closeSync();
expect(null).assertFail();
} catch (e) {
}
})
/**
* @tc.number SUB_DF_FileIO_CloseSync_0010
* @tc.name fileio_test_close_sync_001
* @tc.desc Test closeSync() interfaces.
*/
it('fileio_test_close_sync_001', 0, function () {
try {
fileio.closeSync(-1);
expect(null).assertFail();
} catch (e) {
}
})
})
/*
* Copyright (C) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the 'License');
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an 'AS IS' BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import {
fileio, FILE_CONTENT, prepareFile, nextFileName,
describe, it, expect,
} from '../../Common';
describe('fileio_copyfile', function () {
/**
* @tc.number SUB_DF_FileIO_CopyFileSync_0000
* @tc.name fileio_copy_file_sync_000
* @tc.desc Test copyFileSync() interfaces.
*/
it('fileio_copy_file_sync_000', 0, function () {
let fpath = nextFileName('fileio_copy_file_sync_000');
let fpathTarget = fpath + 'tgt';
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
expect(fileio.copyFileSync(fpath, fpathTarget) == null).assertTrue();
expect(fileio.unlinkSync(fpath) == null).assertTrue();
expect(fileio.unlinkSync(fpathTarget) == null).assertTrue();
} catch (e) {
console.log('fileio_copy_file_sync_000 has failed for ' + e);
expect(null).assertFail();
}
});
/**
* @tc.number SUB_DF_FileIO_CopyFileSync_0010
* @tc.name fileio_copy_file_sync_001
* @tc.desc Test copyFileSync() interfaces.
*/
it('fileio_copy_file_sync_001', 0, function () {
let fpath = nextFileName('fileio_copy_file_sync_001');
let fpathTarget = fpath + 'tgt';
try {
fileio.copyFileSync(fpath, fpathTarget);
expect(null).assertFail();
} catch (e) {
}
});
/**
* @tc.number SUB_DF_FileIO_CopyFileSync_0020
* @tc.name fileio_copy_file_sync_002
* @tc.desc Test copyFileSync() interfaces.
*/
it('fileio_copy_file_sync_002', 0, function () {
try {
fileio.copyFileSync();
expect(null).assertFail();
} catch (e) {
}
});
/**
* @tc.number SUB_DF_FileIO_CopyFileAsync_0000
* @tc.name fileio_copy_file_async_000
* @tc.desc Test copyFileAsync() interfaces.
*/
it('fileio_copy_file_async_000', 0, async function (done) {
let fpath = nextFileName('fileio_copy_file_async_000');
let fpathTarget = fpath + 'tgt';
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
expect(await fileio.copyFile(fpath, fpathTarget) == null).assertTrue();
expect(fileio.unlinkSync(fpath) == null).assertTrue();
expect(fileio.unlinkSync(fpathTarget) == null).assertTrue();
done();
} catch (e) {
console.log('fileio_copy_file_async_000 has failed for ' + e);
expect(null).assertFail();
}
});
/**
* @tc.number SUB_DF_FileIO_CopyFileAsync_0010
* @tc.name fileio_copy_file_async_001
* @tc.desc Test copyFileAsync() interfaces.
*/
it('fileio_copy_file_async_001', 0, async function (done) {
let fpath = nextFileName('fileio_copy_file_async_000');
let fpathTarget = fpath + 'tgt';
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
fileio.copyFile(fpath, fpathTarget, function (error) {
expect(fileio.unlinkSync(fpath) == null).assertTrue();
expect(fileio.unlinkSync(fpathTarget) == null).assertTrue();
done();
});
} catch (e) {
console.log('fileio_copy_file_async_000 has failed for ' + e);
expect(null).assertFail();
}
});
/**
* @tc.number SUB_DF_FileIO_CopyFileAsync_0020
* @tc.name fileio_copy_file_async_002
* @tc.desc Test copyFileAsync() interfaces.
*/
it('fileio_copy_file_async_002', 0, async function (done) {
let fpath = nextFileName('fileio_copy_file_async_002');
let fpathTarget = fpath + 'tgt';
try {
expect(await fileio.copyFile(fpath, fpathTarget).indexOf('<pending>') > -1).assertTrue();
expect(null).assertFail();
} catch (e) {
done();
}
});
/**
* @tc.number SUB_DF_FileIO_CopyFileAsync_0030
* @tc.name fileio_copy_file_async_003
* @tc.desc Test copyFileAsync() interfaces.
*/
it('fileio_copy_file_async_003', 0, async function (done) {
let fpath = nextFileName('fileio_copy_file_async_003');
try {
fileio
.copyFile(1, fpath)
.then(function (err) {
})
.catch(function (e) {
expect(!!e).assertTrue();
done();
});
} catch (e) {
expect(!!e).assertTrue();
done();
}
});
/**
* @tc.number SUB_DF_FileIO_CopyFileAsync_0040
* @tc.name fileio_copy_file_async_004
* @tc.desc Test copyFileAsync() interfaces.
*/
it('fileio_copy_file_async_004', 0, async function (done) {
let fpath = nextFileName('fileio_copy_file_async_004');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
expect(await fileio.copyFile(fpath, 1) == null).assertTrue();
expect(fileio.unlinkSync(fpath) == null).assertTrue();
expect(null).assertFail();
done();
} catch (e) {
done();
}
});
});
/*
* Copyright (C) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the 'License');
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an 'AS IS' BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import {
fileio, FILE_CONTENT, prepareFile, nextFileName,
describe, it, expect,
} from '../../Common';
describe('fileio_createStream', function () {
/**
* @tc.number SUB_DF_FileIO_Stream_CreateStreamAsync_0000
* @tc.name fileio_test_stream_create_stream_async_000
* @tc.desc Test createStreamAsync() interfaces.
*/
it('fileio_test_stream_create_stream_async_000', 0, async function (done) {
let fpath = nextFileName('fileio_test_stream_create_stream_async_000');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
let ss = await fileio.createStream(fpath, 'r+');
expect(ss !== null).assertTrue();
expect(ss.writeSync(FILE_CONTENT) == FILE_CONTENT.length).assertTrue();
expect(ss.closeSync() == null).assertTrue();
expect(fileio.unlinkSync(fpath) == null).assertTrue();
done();
} catch (e) {
console.log('fileio_test_stream_create_stream_async_000 has failed for ' + e);
expect(null).assertFail();
}
});
/**
* @tc.number SUB_DF_FileIO_Stream_CreateStreamAsync_0010
* @tc.name fileio_test_stream_create_stream_async_001
* @tc.desc Test createStreamAsync() interfaces.
*/
it('fileio_test_stream_create_stream_async_001', 0, async function (done) {
let fpath = nextFileName('fileio_test_stream_create_stream_async_001');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
await fileio.createStream(fpath, 'r+', function (err, stream) {
expect(!err).assertTrue();
expect(stream.closeSync() == null).assertTrue();
expect(fileio.unlinkSync(fpath) == null).assertTrue();
done();
});
} catch (e) {
console.log('fileio_test_stream_create_stream_async_001 has failed for ' + e);
expect(null).assertFail();
}
});
/**
* @tc.number SUB_DF_FileIO_Stream_CreateStreamAsync_0020
* @tc.name fileio_test_stream_create_stream_async_002
* @tc.desc Test createStreamAsync() interfaces.
*/
it('fileio_test_stream_create_stream_async_002', 0, async function (done) {
let fpath = nextFileName('fileio_test_stream_create_stream_async_002');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
await fileio.createStream(fpath, 'r+', function (err, stream) {
expect(!err).assertTrue();
expect(stream.writeSync(FILE_CONTENT) == FILE_CONTENT.length).assertTrue();
expect(stream.closeSync() == null).assertTrue();
expect(fileio.unlinkSync(fpath) == null).assertTrue();
done();
});
} catch (e) {
console.log('fileio_test_stream_create_stream_async_002 has failed for ' + e);
expect(null).assertFail();
}
});
/**
* @tc.number SUB_DF_FileIO_Stream_CreateStreamAsync_0030
* @tc.name fileio_test_stream_create_stream_async_003
* @tc.desc Test createStreamAsync() interfaces.
*/
it('fileio_test_stream_create_stream_async_003', 0, async function (done) {
let fpath = nextFileName('fileio_test_stream_create_stream_async_003');
try {
fileio.createStream(fpath, 'r+', function (err) {
done();
});
} catch (e) {
expect(!!e).assertTrue();
done();
}
});
/**
* @tc.number SUB_DF_FileIO_Stream_CreateStreamAsync_0030
* @tc.name fileio_test_stream_create_stream_async_003
* @tc.desc Test createStreamSync() interface.
*/
it('fileio_test_stream_create_stream_async_004', 0, function (done) {
let fpath = nextFileName('fileio_test_stream_create_stream_async_004');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
fileio.createStream(fpath, 'ohos', function (err) {
done();
});
} catch (e) {
expect(!!e).assertTrue();
expect(fileio.unlinkSync(fpath) == null).assertTrue();
done();
}
});
});
/*
* Copyright (C) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the 'License');
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an 'AS IS' BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import {
fileio, FILE_CONTENT, prepareFile, nextFileName,
describe, it, expect,
} from '../../Common';
describe('fileio_fchmod', function () {
/**
* @tc.number SUB_DF_FileIO_FchmodAsync_0000
* @tc.name fileio_test_fchmod_async_000
* @tc.desc Test fchmodAsync()interfaces.
*/
it('fileio_test_fchmod_async_000', 0, async function (done) {
let fpath = nextFileName('fileio_test_fchmod_async_000');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
await fileio
.open(fpath, 0o1, 0o0200)
.then(function (fd) {
fileio.fchmod(fd, 1002, function (err) {
fileio.statSync(fpath);
fileio.closeSync(fd);
fileio.unlinkSync(fpath);
done();
});
})
.catch(function (err) {
expect(err == null).assertTrue();
});
} catch (e) {
expect(null).assertFail();
}
});
/**
* @tc.number SUB_DF_FileIO_FchmodAsync_0010
* @tc.name fileio_test_fchmod_async_001
* @tc.desc Test fchmodAsync()interfaces.
*/
it('fileio_test_fchmod_async_001', 0, async function (done) {
let fpath = nextFileName('fileio_test_fchmod_async_001');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
await fileio
.open(fpath, 0o0, 0o0200)
.then(function (fd) {
fileio
.fchmod(fd, 1003)
.then(function (err) {
fileio.statSync(fpath);
fileio.closeSync(fd);
fileio.unlinkSync(fpath);
})
.catch(function (err) {
expect(err == null).assertTrue();
});
})
.catch(function (err) {
expect(err == null).assertTrue();
});
done();
} catch (e) {
expect(null).assertFail();
}
});
/**
* @tc.number SUB_DF_FileIO_FchmodSync_0000
* @tc.name fileio_test_fchmod_sync_000
* @tc.desc Test fchmodSync()interfaces.
*/
it('fileio_test_fchmod_sync_000', 0, function () {
let fpath = nextFileName('fileio_test_fchmod_sync_000');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
let fd = fileio.openSync(fpath, 0o2);
expect(fileio.fchmodSync(fd, 0o660) == null).assertTrue();
expect((fileio.statSync(fpath).mode & 0o777) == 0o660).assertTrue();
expect(fileio.closeSync(fd) == null).assertTrue();
expect(fileio.unlinkSync(fpath) == null).assertTrue();
} catch (e) {
console.log('fileio_test_fchmod_sync_000 has failed for ' + e);
expect(null).assertFail();
}
});
/**
* @tc.number SUB_DF_FileIO_FchmodSync_0010
* @tc.name fileio_test_fchmod_sync_001
* @tc.desc Test fchmodSync() interfaces.
*/
it('fileio_test_fchmod_sync_001', 0, function () {
try {
expect(fileio.fchmodSync(-1, 0o660) == null).assertTrue();
expect(null).assertFail();
} catch (e) {
}
});
/**
* @tc.number SUB_DF_FileIO_Fchmod_0020
* @tc.name fileio_test_fchmod_async_002
* @tc.desc Test fchmod() interfaces.
*/
it('fileio_test_fchmod_async_002', 0, async function (done) {
let fpath = nextFileName('fileio_test_fchmod_async_002');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
await fileio.open(fpath, 0o1, 0o020).then(function (fd) {
fileio.fchmod(fd, 0o100, function (err) {
expect(fileio.closeSync(fd) == null).assertTrue();
expect(fileio.unlinkSync(fpath) == null).assertTrue();
done();
});
});
} catch (e) {
console.log('fileio_test_fchmod_async_002 has failed for ' + e);
expect(null).assertFail();
}
});
/**
* @tc.number SUB_DF_FileIO_Fchmod_0030
* @tc.name fileio_test_fchmod_async_003
* @tc.desc Test fchmod() interfaces.
*/
it('fileio_test_fchmod_async_003', 0, async function (done) {
let fpath = nextFileName('fileio_test_fchmod_async_003');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
let fd = await fileio.open(fpath, 0o1, 0o020);
expect((await fileio.fchmod(fd, 0o400)) == null).assertTrue();
expect(fileio.closeSync(fd) == null).assertTrue();
expect(fileio.unlinkSync(fpath) == null).assertTrue();
done();
} catch (e) {
console.log('fileio_test_fchmod_async_003 has failed for ' + e);
expect(null).assertFail();
}
});
});
/*
* Copyright (C) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the 'License');
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an 'AS IS' BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import {
fileio, FILE_CONTENT, prepareFile, nextFileName, isIntNum,
describe, it, expect,
} from '../../Common';
describe('fileio_fchown', function () {
/**
* @tc.number SUB_DF_FileIO_Fchown_0010
* @tc.name fileio_test_fchown_001
* @tc.desc Test fchown() and open() and statSync() interfaces.
*/
it('fileio_test_fchown_001', 0, function (done) {
let fpath = nextFileName('fileio_test_fchown_001');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
let stat = fileio.statSync(fpath);
expect(isIntNum(stat.uid)).assertTrue();
let fd = fileio.openSync(fpath, 0o102, 0o666);
fileio.fchown(fd, stat.uid, stat.gid, function (err) {
fileio.closeSync(fd);
fileio.unlinkSync(fpath);
done();
});
} catch (e) {
expect(null).assertFail();
}
});
/**
* @tc.number SUB_DF_FileFchown_Fchown_0020
* @tc.name fileio_test_fchown_002
* @tc.desc Test fchown() and open() and statSync() interfaces.
*/
it('fileio_test_fchown_002', 0, function (done) {
let fpath = nextFileName('fileio_test_fchown_002');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
let stat = fileio.statSync(fpath);
expect(isIntNum(stat.uid)).assertTrue();
let fd = fileio.openSync(fpath, 0o102, 0o666);
fileio.fchown(fd, stat.uid, stat.gid);
expect(fileio.closeSync(fd) == null).assertTrue();
fileio.unlinkSync(fpath);
done();
} catch (e) {
expect(null).assertFail();
}
});
/**
* @tc.number SUB_DF_FileFchown_Fchown_0030
* @tc.name fileio_test_fchown_003
* @tc.desc Test fchown() and open() and statSync() interfaces.
*/
it('fileio_test_fchown_003', 0, function (done) {
let fpath = nextFileName('fileio_test_fchown_003');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
let stat = fileio.statSync(fpath);
expect(isIntNum(stat.uid)).assertTrue();
fileio.fchown(-1, stat.uid, stat.gid);
expect(null).assertFail();
done();
} catch (e) {
console.log('fileio_test_fchown_003 has failed for ' + e);
expect(!!e).assertTrue();
expect(fileio.unlinkSync(fpath) == null).assertTrue();
done();
}
});
/**
* @tc.number SUB_DF_FileIO_FchownSync_0030
* @tc.name fileio_test_fchown_sync_003
* @tc.desc Test fchownSync() interface.
*/
it('fileio_test_fchown_sync_003', 0, function () {
let fpath = nextFileName('fileio_test_fchown_sync_003');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
let stat = fileio.statSync(fpath);
expect(isIntNum(stat.uid)).assertTrue();
let fd = fileio.openSync(fpath, 0o102, 0o666);
fileio.fchownSync(fd, stat.uid, stat.gid);
expect(fileio.closeSync(fd) == null).assertTrue();
fileio.unlinkSync(fpath);
} catch (e) {
expect(null).assertFail();
}
});
});
/*
* Copyright (C) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the 'License');
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an 'AS IS' BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import {
fileio, FILE_CONTENT, prepareFile, nextFileName,
describe, it, expect,
} from '../../Common';
describe('fileio_fdatasync', function () {
/**
* @tc.number SUB_DF_FileIO_FdatasyncSync_0000
* @tc.name fileio_test_fdatasync_sync_000
* @tc.desc Test fdatasync() interfaces.
*/
it('fileio_test_fdatasync_000', 0, async function () {
let fpath = nextFileName('fileio_test_fdatasync_000');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
let fd = fileio.openSync(fpath, 0o102, 0o666);
fileio.fdatasync(fd, function (err) {
expect(fileio.closeSync(fd) == null).assertTrue();
expect(fileio.unlinkSync(fpath) == null).assertTrue();
});
} catch (e) {
console.log('fileio_test_fdatasync_000 has failed for ' + e);
expect(null).assertFail();
}
});
/**
* @tc.number SUB_DF_FileIO_FdatasyncSync_0010
* @tc.name fileio_test_fdatasync_sync_001
* @tc.desc Test fdatasyncSync() interfaces.
*/
it('fileio_test_fdatasync_001', 0, function () {
let fpath = nextFileName('fileio_test_fdatasync_001');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
let fd = fileio.openSync(fpath, 0o102, 0o666);
fileio.write(fd, FILE_CONTENT);
expect(fileio.closeSync(fd) == null).assertTrue();
expect(fileio.unlinkSync(fpath) == null).assertTrue();
} catch (e) {
expect(null).assertFail();
}
});
/**
* @tc.number SUB_DF_FileIO_FdatasyncSync_0020
* @tc.name fileio_test_fdatasync_sync_002
* @tc.desc Test fdatasync() interfaces.
*/
it('fileio_test_fdatasync_002', 0, async function () {
let fpath = nextFileName('fileio_test_fdatasync_002');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
let fd = fileio.openSync(fpath, 0o102, 0o666);
fileio
.fdatasync(fd)
.then(function (err) {
expect(fileio.closeSync(fd) == null).assertTrue();
expect(fileio.unlinkSync(fpath) == null).assertTrue();
})
.catch(function (err) {
expect(null).assertFail();
});
} catch (e) {
console.log('fileio_test_fdatasync_002 has failed for ' + e);
expect(null).assertFail();
}
});
/**
* @tc.number SUB_DF_FileIO_FdatasyncSync_0030
* @tc.name fileio_test_fdatasync_sync_003
* @tc.desc Test fdatasync() interfaces.
*/
it('fileio_test_fdatasync_003', 0, async function () {
let fpath = nextFileName('fileio_test_fdatasync_003');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
let fd = -1;
await fileio.fdatasync(fd);
expect(null).assertFail();
} catch (e) {
}
});
});
/*
* Copyright (C) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the 'License');
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an 'AS IS' BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import {
fileio, FILE_CONTENT, prepareFile, nextFileName, isIntNum,
describe, it, expect,
} from '../../Common';
describe('fileio_FdOpenStream', function () {
/**
* @tc.number SUB_DF_FileIO_FdOpenStreamSync_000
* @tc.name fileio_test_FdOpenStream_sync_000
* @tc.desc Test fdopenStreamSync() interface.
*/
it('fileio_test_fdopenStream_sync_000', 0, function () {
let fpath = nextFileName('fileio_test_fdopenStream_sync_000');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
let fd = fileio.openSync(fpath, 0o2);
let mode = 'r+';
let fp = fileio.fdopenStreamSync(fd, mode);
let buf = new ArrayBuffer(4096);
let data = fp.readSync(buf, {});
expect(data == FILE_CONTENT.length).assertTrue();
expect(fp !== null).assertTrue();
expect(fp.closeSync() == null).assertTrue();
expect(fileio.unlinkSync(fpath) == null).assertTrue();
} catch (e) {
expect(null).assertFail();
}
})
/**
* @tc.number SUB_DF_FileIO_FdOpenStreamSync_001
* @tc.name fileio_test_FdOpenStream_sync_001
* @tc.desc Test fdopenStreamSync() interface.
* This interface shall throw an exception when the fpath is not given.
*/
it('fileio_test_fdopenStream_sync_001', 0, function () {
try {
let fd = -1;
let mode = 'r+';
let fp = fileio.fdopenStreamSync(fd, mode);
expect(null).assertFail();
} catch (e) {
}
})
/**
* @tc.number SUB_DF_FileIO_FdOpenStreamASync_000
* @tc.name fileio_test_FdOpenStream_async_000
* @tc.desc Test fdopenStream() interface.
*/
it('fileio_test_fdOpenStream_async_000', 0, async function (done) {
let fpath = nextFileName('fileio_test_fdOpenStream_async_000');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
let fd = fileio.openSync(fpath, 0o2);
expect(isIntNum(fd)).assertTrue();
let mode = 'r+';
let fp = await fileio.fdopenStream(fd, mode);
fp.read(new ArrayBuffer(4096), {}, function (err, data) {
if (!err) {
expect(fp !== null).assertTrue();
expect(fp.closeSync() == null).assertTrue();
expect(data.bytesRead == FILE_CONTENT.length).assertTrue();
} else {
console.log('Cannot read from the stream ' + err);
expect(null).assertFail();
}
})
expect(fileio.unlinkSync(fpath) == null).assertTrue();
done();
} catch (e) {
console.log('fileio_test_fdopenStream_async_000 has failed for ' + e);
expect(null).assertFail();
}
})
/**
* @tc.number SUB_DF_FileIO_fdopenStreamASync_001
* @tc.name fileio_test_fdopenStream_async_001
* @tc.desc Test fdopenStream() interface.
*/
it('fileio_test_fdopenStream_async_001', 0, async function (done) {
let fpath = nextFileName('fileio_test_fdopenStream_async_001');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
let fd = fileio.openSync(fpath, 0o2);
expect(isIntNum(fd)).assertTrue();
let mode = 'r+';
fileio.fdopenStream(fd, mode, function (error, fp) {
expect(fp !== null).assertTrue();
fp.read(new ArrayBuffer(4096), {}, function (err, data) {
if (!err) {
expect(fp !== null).assertTrue();
expect(fp.closeSync() == null).assertTrue();
expect(data.bytesRead == FILE_CONTENT.length).assertTrue();
} else {
console.log('Cannot read from the stream ' + err);
expect(null).assertFail();
}
})
expect(fileio.unlinkSync(fpath) == null).assertTrue();
done();
})
} catch (e) {
console.log('fileio_test_fdopenStream_async_001 has failed for ' + e);
expect(null).assertFail();
}
})
})
\ No newline at end of file
/*
* Copyright (C) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the 'License');
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an 'AS IS' BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import {
fileio, FILE_CONTENT, prepareFile, nextFileName,
describe, it, expect,
} from '../../Common';
describe('fileio_stat_fsync', function () {
/**
* @tc.number SUB_DF_FileIO_FsyncSync_0000
* @tc.name fileio_test_fsync_sync_000
* @tc.desc Test fsyncSync() interface.
*/
it('fileio_test_fsync_sync_000', 0, function () {
let fpath = nextFileName('fileio_test_fsync_sync_000');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
let fd = fileio.openSync(fpath, 0o2);
expect(fileio.fsyncSync(fd) == null).assertTrue();
expect(fileio.closeSync(fd) == null).assertTrue();
expect(fileio.unlinkSync(fpath) == null).assertTrue();
} catch (e) {
console.log('fileio_test_fsync_sync_000 has failed for ' + e);
expect(null).assertFail();
}
});
/**
* @tc.number SUB_DF_FileIO_FsyncSync_0010
* @tc.name fileio_test_fsync_sync_001
* @tc.desc Test fsyncSync() interface.
*/
it('fileio_test_fsync_sync_001', 0, function () {
try {
fileio.fsyncSync(-1);
expect(null).assertFail();
} catch (e) {
}
});
/**
* @tc.number SUB_DF_FileIO_FsyncAsync_000
* @tc.name fileio_test_fsync_sync_000
* @tc.desc Test fsync() interface.
*/
it('fileio_test_fsync_async_000', 0, async function (done) {
let fpath = nextFileName('fileio_test_fsync_async_000');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
let fd = fileio.openSync(fpath, 0o2);
await fileio.fsync(fd);
expect(fileio.closeSync(fd) == null).assertTrue();
expect(fileio.unlinkSync(fpath) == null).assertTrue();
done();
} catch (e) {
console.log('fileio_test_fsync_async_000 has failed for ' + e);
expect(null).assertFail();
}
});
/**
* @tc.number SUB_DF_FileIO_FsyncAsync_001
* @tc.name fileio_test_fsync_sync_001
* @tc.desc Test fsync() interface.
*/
it('fileio_test_fsync_async_001', 0, async function (done) {
let fpath = nextFileName('fileio_test_fsync_sync_001');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
let fd = fileio.openSync(fpath, 0o2);
fileio.fsync(fd, function (error) {
expect(fileio.closeSync(fd) == null).assertTrue();
expect(fileio.unlinkSync(fpath) == null).assertTrue();
});
done();
} catch (e) {
console.log('fileio_test_fsync_async_001 has failed for ' + e);
expect(null).assertFail();
}
});
/**
* @tc.number SUB_DF_FileIO_FsyncAsync_002
* @tc.name fileio_test_fsync_sync_002
* @tc.desc Test fsync() interface.
*/
it('fileio_test_fsync_async_002', 0, async function (done) {
try {
let fd = -1;
await fileio.fsync(fd);
expect(null).assertFail();
done();
} catch (e) {
done();
}
})
})
\ No newline at end of file
/*
* Copyright (C) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the 'License');
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an 'AS IS' BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import {
fileio, FILE_CONTENT, prepareFile, nextFileName, isIntNum,
describe, it, expect,
} from '../../Common';
describe('fileio_ftruncate', function () {
/**
* @tc.number SUB_DF_FileIO_FtruncateAsync_0000
* @tc.name fileio_test_ftruncate_async_000
* @tc.desc Test ftruncateAsync() interfaces.
*/
it('fileio_test_ftruncate_async_000', 0, async function (done) {
let fpath = nextFileName('fileio_test_ftruncate_async_000');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
let fd = fileio.openSync(fpath, 0o2);
expect(isIntNum(fd)).assertTrue();
let truncateLen = 5;
try {
fileio.ftruncate(fd, truncateLen, async function (err) {
expect(err == null).assertTrue();
let len = fileio.readSync(fd, new ArrayBuffer(4096));
expect(len == truncateLen).assertTrue();
expect(fileio.closeSync(fd) == null).assertTrue();
expect(fileio.unlinkSync(fpath) == null).assertTrue();
done();
})
} catch (e) {
console.log('fileio_test_ftruncate_async_000 has failed for ' + e);
expect(null).assertFail();
}
});
/**
* @tc.number SUB_DF_FileIO_FtruncateAsync_0010
* @tc.name fileio_test_ftruncate_async_001
* @tc.desc Test ftruncateAsync() interfaces.
*/
it('fileio_test_ftruncate_async_001', 0, async function (done) {
let fpath = nextFileName('fileio_test_ftruncate_async_001');
expect(prepareFile(fpath, 'truncate')).assertTrue();
let fd = fileio.openSync(fpath, 0o2);
expect(isIntNum(fd)).assertTrue();
let truncateLen = 2;
try {
fileio.ftruncate(fd, truncateLen)
.then(function (err) {
expect(err == null).assertTrue();
let len = fileio.readSync(fd, new ArrayBuffer(4096));
expect(len == truncateLen).assertTrue();
expect(fileio.closeSync(fd) == null).assertTrue();
expect(fileio.unlinkSync(fpath) == null).assertTrue();
done();
})
.catch(function (e) {
console.log('catch ' + e);
})
} catch (e) {
console.log('fileio_test_ftruncate_async_001 has failed for ' + e);
expect(null).assertFail();
}
});
/**
* @tc.number SUB_DF_FileIO_FtruncateAsync_0020
* @tc.name fileio_test_ftruncate_async_002
* @tc.desc Test ftruncateAsync() interfaces.
*/
it('fileio_test_ftruncate_async_002', 0, async function (done) {
let fpath = nextFileName('fileio_test_ftruncate_async_002');
let truncateLen = 2;
try {
fileio.ftruncate(fpath, truncateLen, function (err) {
done();
})
} catch (e) {
console.log('fileio_test_ftruncate_async_002 has failed for ' + e);
expect(!!e).assertTrue();
done();
}
});
/**
* @tc.number SUB_DF_FileIO_FtruncateSync_0000
* @tc.name fileio_test_ftruncate_sync_000
* @tc.desc Test ftruncateSync() interfaces.
*/
it('fileio_test_ftruncate_sync_000', 0, function () {
let fpath = nextFileName('fileio_test_ftruncate_sync_000');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
let fd = fileio.openSync(fpath, 0o2);
expect(isIntNum(fd)).assertTrue();
let truncateLen = 5;
try {
fileio.ftruncateSync(fd, truncateLen);
let len = fileio.readSync(fd, new ArrayBuffer(4096));
expect(len == truncateLen).assertTrue();
expect(fileio.closeSync(fd) == null).assertTrue();
expect(fileio.unlinkSync(fpath) == null).assertTrue();
} catch (e) {
console.log('fileio_test_ftruncate_sync_000 has failed for ' + e);
expect(null).assertFail();
}
});
/**
* @tc.number SUB_DF_FileIO_FtruncateSync_0010
* @tc.name fileio_test_ftruncate_sync_001
* @tc.desc Test ftruncateSync() interfaces.
*/
it('fileio_test_ftruncate_sync_001', 0, function () {
let fpath = nextFileName('fileio_test_ftruncate_sync_001');
expect(prepareFile(fpath, 'truncate')).assertTrue();
let fd = fileio.openSync(fpath, 0o2);
expect(isIntNum(fd)).assertTrue();
let truncateLen = 2;
try {
fileio.ftruncateSync(fd, truncateLen);
let len = fileio.readSync(fd, new ArrayBuffer(4096));
expect(len == truncateLen).assertTrue();
expect(fileio.closeSync(fd) == null).assertTrue();
expect(fileio.unlinkSync(fpath) == null).assertTrue();
} catch (e) {
console.log('fileio_test_ftruncate_sync_001 has failed for ' + e);
expect(null).assertFail();
}
});
/**
* @tc.number SUB_DF_FileIO_FtruncateSync_0020
* @tc.name fileio_test_ftruncate_sync_002
* @tc.desc Test ftruncateSync() interfaces.
*/
it('fileio_test_ftruncate_sync_002', 0, function () {
let fpath = nextFileName('fileio_test_ftruncate_sync_002');
let truncateLen = 2;
try {
fileio.ftruncateSync(fpath, truncateLen);
} catch (e) {
console.log('fileio_test_ftruncate_sync_002 has failed for ' + e);
expect(!!e).assertTrue();
}
});
});
\ No newline at end of file
/*
* Copyright (C) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the 'License');
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an 'AS IS' BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import {
fileio, FILE_CONTENT, prepareFile, nextFileName,
describe, it, expect,
} from '../../Common';
describe('fileio_hash', function () {
/**
* @tc.number SUB_DF_FileIO_HashAsync_0000
* @tc.name fileio_test_hash_async_000
* @tc.desc Test hashAsync() interface.
*/
it('fileio_test_hash_async_000', 0, async function (done) {
let fpath = nextFileName('fileio_test_hash_async_000');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
let str = await fileio.hash(fpath,'md5');
console.log('fileio_test_hash_async_000 hash vaule is ' + str);
expect(str == '5EB63BBBE01EEED093CB22BB8F5ACDC3').assertTrue();
expect(fileio.unlinkSync(fpath) == null).assertTrue();
done();
} catch (e) {
console.log('fileio_test_hash_async_000 has failed for ' + e);
expect(null).assertFail();
}
});
});
\ No newline at end of file
/*
* Copyright (C) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the 'License');
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an 'AS IS' BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import {
fileio, FILE_CONTENT, prepareFile, nextFileName,
describe, it, expect,
} from '../../Common';
describe('fileio_lchown', function () {
/**
* @tc.number SUB_DF_FileIO_lchownSync_000
* @tc.name fileio_test_lchown_sync_000
* @tc.desc Test lchownSync() interface.
*/
it('fileio_test_lchown_sync_000', 0, function () {
let fpath = nextFileName('fileio_test_lchown_sync_000');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
let stat = fileio.statSync(fpath);
expect(fileio.lchownSync(fpath, stat.uid, stat.gid) == null).assertTrue();
expect(fileio.unlinkSync(fpath) == null).assertTrue();
} catch (e) {
expect(null).assertFail();
}
});
/**
* @tc.number SUB_DF_FileIO_lchownSync_001
* @tc.name fileio_test_lchown_sync_001
* @tc.desc Test lchownSync() interface.
*/
it('fileio_test_lchown_sync_001', 0, function () {
let fpath = nextFileName('fileio_test_lchown_sync_001');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
let stat = fileio.statSync(fpath);
expect(isIntNum(stat.uid)).assertTrue();
expect(fileio.lchownSync('/', stat.uid, stat.gid));
expect(null).assertFail();
} catch (e) {
expect(!!e).assertTrue();
expect(fileio.unlinkSync(fpath) == null).assertTrue();
}
});
/**
* @tc.number SUB_DF_FileIO_lchownASync_000
* @tc.name fileio_test_lchown_async_00
* @tc.desc Test lchownASync() interface.
*/
it('fileio_lchown_Async_000', 0, async function (done) {
let fpath = nextFileName('fileio_lchown_Async_000');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
let stat = fileio.statSync(fpath);
expect(await fileio.lchown(fpath, stat.uid, stat.gid) == null).assertTrue();
expect(fileio.unlinkSync(fpath) == null).assertTrue();
done();
} catch (e) {
console.log('fileio_test_lchown_async_000 has failed for ' + e);
expect(null).assertFail();
}
});
/**
* @tc.number SUB_DF_FileIO_lchownASync_001
* @tc.name fileio_test_lchown_async_00
* @tc.desc Test lchownASync() interface.
*/
it('fileio_lchown_Async_001', 0, async function (done) {
let fpath = nextFileName('fileio_lchown_Async_001');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
let stat = fileio.statSync(fpath);
fileio.lchown(fpath, stat.uid, stat.gid, function (error) {
expect(fileio.unlinkSync(fpath) == null).assertTrue();
done();
});
} catch (e) {
console.log('fileio_lchown_Async_001 has failed for ' + e);
expect(null).assertFail();
}
});
});
/*
* Copyright (C) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the 'License');
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an 'AS IS' BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import {
fileio, FILE_CONTENT, prepareFile, nextFileName, isIntNum,
describe, it, expect,
} from '../../Common';
describe('fileio_lseek', function () {
/**
* @tc.number SUB_DF_FileIO_LseekAsync_0000
* @tc.name fileio_test_lseek_async_000
* @tc.desc Test lseekAsync()interfaces.
*/
it('fileio_test_lseek_async_000', 0, async function (done) {
let fpath = nextFileName('fileio_test_lseek_async_000');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
let fd = fileio.openSync(fpath, 0o2);
await fileio.lseek(fd, -1, 2, function (err) {
expect(!err).assertTrue();
expect(fileio.closeSync(fd) == null).assertTrue();
expect(fileio.unlinkSync(fpath) == null).assertTrue();
done();
})
} catch (e) {
console.log('fileio_test_lseek_async_000 has failed for ' + e);
expect(null).assertFail();
}
});
/**
* @tc.number SUB_DF_FileIO_LseekAsync_0010
* @tc.name fileio_test_lseek_async_001
* @tc.desc Test lseekAsync()interfaces.
*/
it('fileio_test_lseek_async_001', 0, async function (done) {
let fpath = nextFileName('fileio_test_lseek_async_001');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
let fd = fileio.openSync(fpath, 0o2);
let num = await fileio.lseek(fd, -1, 2);
expect(isIntNum(num)).assertTrue();
expect(fileio.closeSync(fd) == null).assertTrue();
expect(fileio.unlinkSync(fpath) == null).assertTrue();
done();
} catch (e) {
console.log('fileio_test_lseek_async_001 has failed for ' + e);
expect(null).assertFail();
}
});
/**
* @tc.number SUB_DF_FileIO_lseekSync_0000
* @tc.name fileio_test_lseek_sync_000
* @tc.desc Test lseekSync()interfaces.
*/
it('fileio_test_lseek_sync_000', 0, function () {
let fpath = nextFileName('fileio_test_lseek_sync_000');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
let fd = fileio.openSync(fpath, 0o102, 0o666);
let num = fileio.lseekSync(fd, -1, 2);
expect(isIntNum(num)).assertTrue();
expect(fileio.closeSync(fd) == null).assertTrue();
expect(fileio.unlinkSync(fpath) == null).assertTrue();
} catch (e) {
console.log('fileio_test_lseek_sync_000 has failed for ' + e);
expect(null).assertFail();
}
});
/**
* @tc.number SUB_DF_FileIO_lseekSync_0010
* @tc.name fileio_test_lseek_sync_001
* @tc.desc Test lseekSync() interfaces.
*/
it('fileio_test_lseek_sync_001', 0, function () {
let fpath = nextFileName('fileio_test_lseek_sync_001');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
let fd = fileio.openSync(fpath, 0o102, 0o666);
let num = fileio.lseekSync(fd, 9, 0);
expect(isIntNum(num)).assertTrue();
expect(fileio.closeSync(fd) == null).assertTrue();
expect(fileio.unlinkSync(fpath) == null).assertTrue();
} catch (e) {
console.log('fileio_test_lseek_sync_001 has failed for ' + e);
expect(null).assertFail();
}
});
});
/*
* Copyright (C) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the 'License');
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an 'AS IS' BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { fileio, nextFileName, describe, it, expect } from '../../Common';
describe('fileio_mkdir_rmdir', function () {
/**
* @tc.number SUB_DF_FileIO_MkdirSync_0000
* @tc.name fileio_mkdir_sync_rmdir_sync_000
* @tc.desc Test mkdirSync() and rmdirSync() interfaces.
*/
it('fileio_mkdir_sync_rmdir_sync_000', 0, function () {
let dpath = nextFileName('fileio_mkdir_sync_rmdir_sync_000') + 'd';
try {
expect(fileio.mkdirSync(dpath) == null).assertTrue();
expect(fileio.rmdirSync(dpath) == null).assertTrue();
} catch (e) {
console.log('fileio_mkdir_sync_rmdir_sync_000 has failed for ' + e);
expect(null).assertFail();
}
});
/**
* @tc.number SUB_DF_FileIO_MkdirSync_0010
* @tc.name fileio_mkdir_sync_rmdir_sync_001
* @tc.desc Test mkdirSync() interfaces.
*/
it('fileio_mkdir_sync_rmdir_sync_001', 0, function () {
try {
expect(fileio.mkdirSync('/') == null).assertTrue();
expect(null).assertFail();
} catch (e) {
}
});
/**
* @tc.number SUB_DF_FileIO_MkdirSync_0020
* @tc.name fileio_mkdir_sync_rmdir_sync_002
* @tc.desc Test mkdirSync() interfaces.
*/
it('fileio_mkdir_sync_rmdir_sync_002', 0, function () {
try {
expect(fileio.mkdirSync(12) == null).assertTrue();
expect(null).assertFail();
} catch (e) {
}
});
/**
* @tc.number SUB_DF_FileIO_MkdirAsync_0000
* @tc.name fileio_mkdir_async_rmdir_sync_000
* @tc.desc Test mkdirAsync() and rmdirSync() interfaces.
*/
it('fileio_mkdir_async_rmdir_sync_000', 0, async function (done) {
let dpath = nextFileName('fileio_mkdir_async_rmdir_sync_000') + 'd';
try {
expect(await fileio.mkdir(dpath) == null).assertTrue();
expect(fileio.rmdirSync(dpath) == null).assertTrue();
done();
} catch (e) {
console.log('fileio_mkdir_async_rmdir_sync_000 has failed for ' + e);
expect(null).assertFail();
}
});
/**
* @tc.number SUB_DF_FileIO_MkdirAsync_0010
* @tc.name fileio_mkdir_async_rmdir_sync_001
* @tc.desc Test mkdirAsync() and rmdirSync() interfaces.
*/
it('fileio_mkdir_async_rmdir_sync_001', 0, async function (done) {
let dpath = nextFileName('fileio_mkdir_async_rmdir_sync_001') + 'd';
try {
fileio.mkdir(dpath, function (error) {
expect(fileio.rmdirSync(dpath) == null).assertTrue();
done();
});
} catch (e) {
console.log('fileio_mkdir_async_rmdir_sync_001 has failed for ' + e);
expect(null).assertFail();
}
});
/**
* @tc.number SUB_DF_FileIO_MkdirAsync_0020
* @tc.name fileio_mkdir_async_rmdir_sync_002
* @tc.desc Test mkdirAsync() and rmdirSync() interfaces.
*/
it('fileio_mkdir_async_rmdir_sync_002', 0, async function (done) {
let fpath = nextFileName('fileio_mkdir_async_rmdir_sync_002');
try {
expect(await fileio.mkdir(fpath, 777) == null).assertTrue();
expect(fileio.rmdirSync(fpath) == null).assertTrue();
done();
} catch (e) {
console.log('fileio_mkdir_async_rmdir_sync_002 has failed for ' + e);
expect(null).assertFail();
}
});
/**
* @tc.number SUB_DF_FileIO_MkdirAsync_0030
* @tc.name fileio_mkdir_async_rmdir_sync_003
* @tc.desc Test mkdirAsync() and rmdirSync() interfaces.
*/
it('fileio_mkdir_async_rmdir_sync_003', 0, async function (done) {
let fpath = nextFileName('fileio_mkdir_async_rmdir_sync_003');
try {
expect(await fileio.mkdir(fpath, 400) == null).assertTrue();
expect(fileio.rmdirSync(fpath) == null).assertTrue();
done();
} catch (e) {
console.log('fileio_mkdir_async_rmdir_sync_003 has failed for ' + e);
expect(null).assertFail();
}
});
/**
* @tc.number SUB_DF_FileIO_MkdirAsync_0040
* @tc.name fileio_mkdir_async_rmdir_sync_004
* @tc.desc Test mkdirAsync() and interfaces.
*/
it('fileio_mkdir_async_rmdir_sync_004', 0, async function (done) {
try {
expect(await fileio.mkdir(12) == null).assertTrue();
expect(null).assertFail();
} catch (e) {
done();
}
});
/**
* @tc.number SUB_DF_FileIO_MkdirAsync_0050
* @tc.name fileio_mkdir_async_rmdir_sync_005
* @tc.desc Test mkdirAsync()interfaces.
*/
it('fileio_mkdir_async_rmdir_sync_005', 0, async function (done) {
try {
expect(await fileio.mkdir('/').indexOf('<pending>') > -1).assertTrue();
expect(null).assertFail();
} catch (e) {
done();
}
});
});
\ No newline at end of file
/*
* Copyright (C) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the 'License');
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an 'AS IS' BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { fileio, nextFileName, describe, it, expect } from '../../Common';
describe('fileio_mkdtemp', function () {
/**
* @tc.number SUB_DF_FileIO_MkdtempSync_0000
* @tc.name fileio_test_mkdtemp_sync_000
* @tc.desc Test mkdtempSync() interface.
*/
it('fileio_test_mkdtemp_sync_000', 0, function () {
let dpath = nextFileName('fileio_test_mkdtemp_sync_000');
dpath = dpath + 'XXXX';
try {
let res = fileio.mkdtempSync(dpath);
expect(null).assertFail();
} catch (e) {
}
});
/**
* @tc.number SUB_DF_FileIO_MkdtempSync_0010
* @tc.name fileio_test_mkdtemp_sync_001
* @tc.desc Test mkdtempSync() interface.
*/
it('fileio_test_mkdtemp_sync_001', 0, function () {
let dpath = nextFileName('fileio_test_mkdtemp_sync_001');
dpath = dpath + 'XXXXXX';
try {
let res = fileio.mkdtempSync(dpath);
expect(fileio.rmdirSync(res) == null).assertTrue();
} catch (e) {
console.log('fileio_test_mkdtemp_sync_001 has failed for ' + e);
expect(null).assertFail();
}
});
/**
* @tc.number SUB_DF_FileIO_MkdtempASync_0000
* @tc.name fileio_test_mkdtemp_async_000
* @tc.desc Test mkdtempASync() interface.
*/
it('fileio_test_mkdtemp_async_000', 0, async function (done) {
let dpath = nextFileName('fileio_test_mkdtemp_async_000');
dpath = dpath + 'XXXXXX';
try {
let res = await fileio.mkdtemp(dpath);
expect(fileio.rmdirSync(res) == null).assertTrue();
done();
} catch (e) {
console.log('fileio_test_mkdtemp_async_000 has failed for ' + e);
expect(null).assertFail();
}
});
/**
* @tc.number SUB_DF_FileIO_MkdtempASync_0010
* @tc.name fileio_test_mkdtemp_async_001
* @tc.desc Test mkdtempASync() interface.
*/
it('fileio_test_mkdtemp_async_001', 0, async function (done) {
let dpath = nextFileName('fileio_test_mkdtemp_async_001');
dpath = dpath + 'XXXXXX';
try {
fileio.mkdtemp(dpath, function (err, res) {
expect(!err).assertTrue();
expect(fileio.rmdirSync(res) == null).assertTrue();
done();
});
} catch (e) {
console.log('fileio_test_mkdtemp_async_001 has failed for ' + e);
expect(null).assertFail();
}
});
});
\ No newline at end of file
/*
* Copyright (C) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the 'License');
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an 'AS IS' BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import {
fileio, FILE_CONTENT, prepareFile, nextFileName,
describe, it, expect,
} from '../../Common';
describe('fileio_open', function () {
/**
* @tc.number SUB_DF_FileIO_OpenSync_0000
* @tc.name fileio_test_open_sync_000
* @tc.desc Test openSync() interfaces.
*/
it('fileio_test_open_sync_000', 0, function () {
try {
fileio.openSync('/', 0o102, 0o666);
expect(null).assertFail();
} catch (e) {}
});
/**
* @tc.number SUB_DF_FileIO_OpenAsync_0000
* @tc.name fileio_test_open_async_000
* @tc.desc Test openASync() interfaces.
*/
it('fileio_test_open_async_000', 0, async function (done) {
let fpath = nextFileName('fileio_test_open_async_000');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
await fileio.access(fpath).then(function (err) {
fileio.open(fpath, 0, 0o0400, function (err, fd) {
fileio.read(fd, new ArrayBuffer(4096))
.then(function (res) {
expect((String.fromCharCode.apply(null, new Uint8Array(res.buffer))) == FILE_CONTENT).assertTrue;
expect(res.bytesRead == FILE_CONTENT.length).assertTrue();
fileio.closeSync(fd);
fileio.unlinkSync(fpath);
done();
});
});
});
} catch (e) {
expect(null).assertFail();
}
});
/**
* @tc.number SUB_DF_FileIO_OpenAsync_0010
* @tc.name fileio_test_open_async_001
* @tc.desc Test openASync() interfaces.
*/
it('fileio_test_open_async_001', 0, async function (done) {
let fpath = nextFileName('fileio_test_open_async_001');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
await fileio.open(fpath, 0, 0o0400, function (err, fd) {
fileio.read(fd, new ArrayBuffer(4096))
.then(function (res) {
expect((String.fromCharCode.apply(null, new Uint8Array(res.buffer))) == FILE_CONTENT).assertTrue;
expect(res.bytesRead == FILE_CONTENT.length).assertTrue();
fileio.closeSync(fd);
fileio.unlinkSync(fpath);
done();
});
});
} catch (e) {
expect(null).assertFail();
}
});
/**
* @tc.number SUB_DF_FileIO_OpenAsync_0020
* @tc.name fileio_test_open_async_002
* @tc.desc Test openASync() interfaces.
*/
it('fileio_test_open_async_002', 0, async function (done) {
let fpath = nextFileName('fileio_test_open_async_002');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
await fileio.open(fpath, 0, function (err, fd) {
fileio.read(fd, new ArrayBuffer(4096))
.then(function (res) {
expect((String.fromCharCode.apply(null, new Uint8Array(res.buffer))) == FILE_CONTENT).assertTrue;
expect(res.bytesRead == FILE_CONTENT.length).assertTrue();
fileio.closeSync(fd);
fileio.unlinkSync(fpath);
done();
});
});
} catch (e) {
expect(null).assertFail();
}
});
/**
* @tc.number SUB_DF_FileIO_OpenAsync_0030
* @tc.name fileio_test_open_async_003
* @tc.desc Test openASync() interfaces.
*/
it('fileio_test_open_async_003', 0, async function (done) {
let fpath = nextFileName('fileio_test_open_async_003');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
await fileio.open(fpath, function (err, fd) {
fileio.read(fd, new ArrayBuffer(4096))
.then(function (res) {
expect((String.fromCharCode.apply(null, new Uint8Array(res.buffer))) == FILE_CONTENT).assertTrue;
expect(res.bytesRead == FILE_CONTENT.length).assertTrue();
fileio.closeSync(fd);
fileio.unlinkSync(fpath);
done();
});
});
} catch (e) {
expect(null).assertFail();
}
});
/**
* @tc.number SUB_DF_FileIO_OpenAsync_0040
* @tc.name fileio_test_open_async_004
* @tc.desc Test openASync() interfaces.
*/
it('fileio_test_open_async_004', 0, async function (done) {
let fpath = nextFileName('fileio_test_open_async_004');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
await fileio.open(fpath)
.then(function (fd) {
fileio.read(fd, new ArrayBuffer(4096))
.then(function (res) {
expect((String.fromCharCode.apply(null, new Uint8Array(res.buffer))) == FILE_CONTENT).assertTrue;
expect(res.bytesRead == FILE_CONTENT.length).assertTrue();
fileio.closeSync(fd);
fileio.unlinkSync(fpath);
});
})
.catch(function (err) {
expect(err == null).assertTrue();
})
done();
} catch (e) {
expect(null).assertFail();
}
});
/**
* @tc.number SUB_DF_FileIO_OpenAsync_0050
* @tc.name fileio_test_open_async_005
* @tc.desc Test openASync() interfaces.
*/
it('fileio_test_open_async_005', 0, async function (done) {
let fpath = nextFileName('fileio_test_open_async_005');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
await fileio.open(fpath, 0o0)
.then(function (fd) {
fileio.read(fd, new ArrayBuffer(4096))
.then(function (res) {
expect((String.fromCharCode.apply(null, new Uint8Array(res.buffer))) == FILE_CONTENT).assertTrue;
expect(res.bytesRead == FILE_CONTENT.length).assertTrue();
fileio.closeSync(fd);
fileio.unlinkSync(fpath);
})
})
.catch(function (err) {
expect(err == null).assertTrue();
})
done();
} catch (e) {
expect(null).assertFail();
}
});
/**
* @tc.number SUB_DF_FileIO_OpenAsync_0060
* @tc.name fileio_test_open_async_006
* @tc.desc Test openASync() interfaces.
*/
it('fileio_test_open_async_006', 0, async function (done) {
let fpath = nextFileName('fileio_test_open_async_006');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
await fileio.open(fpath, 0o1, 0o0200)
.then(function (fd) {
fileio.read(fd, new ArrayBuffer(4096))
.then(function (res) {
expect((String.fromCharCode.apply(null, new Uint8Array(res.buffer))) == FILE_CONTENT).assertTrue;
expect(res.bytesRead == FILE_CONTENT.length).assertTrue();
fileio.closeSync(fd);
fileio.unlinkSync(fpath);
});
})
.catch(function (err) {
expect(err == null).assertTrue();
})
done();
} catch (e) {
expect(null).assertFail();
}
});
});
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册