diff --git a/storage/storagefileiojstest/src/main/js/default/test/Common.js b/storage/storagefileiojstest/src/main/js/default/test/Common.js index 1eaffc60ad8efe637cd32d2db63ff97a1899069a..d1b7f8f6b03a242b187ee3aab819182da08e6ac9 100644 --- a/storage/storagefileiojstest/src/main/js/default/test/Common.js +++ b/storage/storagefileiojstest/src/main/js/default/test/Common.js @@ -17,6 +17,11 @@ import fileio from '@ohos.fileio'; export const FILE_CONTENT = 'hello world'; +import { + describe, beforeAll, beforeEach, afterEach, afterAll, it, expect +} +from 'deccjsunit/index' + export function prepareFile(fpath, content) { try { let fd = fileio.openSync(fpath, 0o102, 0o666) @@ -98,4 +103,30 @@ export function randomString(num) { pwd += $chars.charAt(Math.floor(Math.random() * maxPos)); } 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 diff --git a/storage/storagefileiojstest/src/main/js/default/test/FileIOStream.test.js b/storage/storagefileiojstest/src/main/js/default/test/FileIOStream.test.js index bc4b42575f59132f3169e2af63654d7e2c0ba374..2d100094e7b4d36c1c9b86f24b3aab6e832a1a47 100644 --- a/storage/storagefileiojstest/src/main/js/default/test/FileIOStream.test.js +++ b/storage/storagefileiojstest/src/main/js/default/test/FileIOStream.test.js @@ -16,10 +16,6 @@ import fileio from '@ohos.fileio'; import { describe, - beforeAll, - beforeEach, - afterEach, - afterAll, it, expect } @@ -29,7 +25,6 @@ import { prepareFile, fileToReadOnly, fileToWriteOnly, - sleep, nextFileName, randomString } @@ -1278,7 +1273,7 @@ describe('fileIOTestStream', function () { expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); try { let fd = fileio.openSync(fpath, 0o2); - fileio.fdopenStreamSync(fd, '') + fileio.fdopenStreamSync(fd, ''); expect(null).assertFail(); } catch (e) { diff --git a/storage/storagefileiojstest/src/main/js/default/test/List.test.js b/storage/storagefileiojstest/src/main/js/default/test/List.test.js index 57ae4964dd88c49806a29228a631113db7c35ae6..287193bdb89dbff0e87a92bc4859ec8ef2c24e2f 100644 --- a/storage/storagefileiojstest/src/main/js/default/test/List.test.js +++ b/storage/storagefileiojstest/src/main/js/default/test/List.test.js @@ -19,3 +19,43 @@ require('./FileIODir.test.js') require('./FileIODirent.test.js') require('./FileIOStat.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'); diff --git a/storage/storagefileiojstest/src/main/js/default/test/module_fileio/class_constants/constants.test.js b/storage/storagefileiojstest/src/main/js/default/test/module_fileio/class_constants/constants.test.js new file mode 100644 index 0000000000000000000000000000000000000000..36124d459eb6ffd4bd565b9957eeaee19446b5c7 --- /dev/null +++ b/storage/storagefileiojstest/src/main/js/default/test/module_fileio/class_constants/constants.test.js @@ -0,0 +1,70 @@ +/* + * 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 diff --git a/storage/storagefileiojstest/src/main/js/default/test/module_fileio/class_dir/close.test.js b/storage/storagefileiojstest/src/main/js/default/test/module_fileio/class_dir/close.test.js new file mode 100644 index 0000000000000000000000000000000000000000..1ae5917b07a27627eb8f13e5ad8e3abfab6c50c9 --- /dev/null +++ b/storage/storagefileiojstest/src/main/js/default/test/module_fileio/class_dir/close.test.js @@ -0,0 +1,74 @@ +/* + * 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(); + } + }); +}); diff --git a/storage/storagefileiojstest/src/main/js/default/test/module_fileio/class_dir/read.test.js b/storage/storagefileiojstest/src/main/js/default/test/module_fileio/class_dir/read.test.js new file mode 100644 index 0000000000000000000000000000000000000000..98afc228bb71a84d11948dacd4143501688cec88 --- /dev/null +++ b/storage/storagefileiojstest/src/main/js/default/test/module_fileio/class_dir/read.test.js @@ -0,0 +1,1038 @@ +/* + * 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_read', function () { + + /** + * @tc.number SUB_DF_FileIO_ReadSync_0000 + * @tc.name fileio_test_dir_read_file_sync_000 + * @tc.desc Test Dir.readSync() interface. + */ + it('fileio_test_dir_read_file_sync_000', 0, function () { + let fpath = nextFileName('fileio_test_dir_read_file_sync_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = fileio.statSync(fpath); + expect(isIntNum(stat.size)).assertTrue(); + let fd = fileio.openSync(fpath, 0o2); + expect(isIntNum(fd)).assertTrue(); + let len = fileio.readSync(fd, new ArrayBuffer(stat.size)); + expect(len == FILE_CONTENT.length).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_test_dir_read_file_sync_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_Dir_open_close_ASync_0000 + * @tc.name fileio_test_dir_open_close_async_000 + * @tc.desc Test Dir.readSync() interface. + */ + it('fileio_test_dir_open_close_async_000', 0, async function (done) { + let dpath = nextFileName('fileio_test_dir_open_close_async_000') + 'd'; + + try { + expect(fileio.mkdirSync(dpath) == null).assertTrue(); + let dd = await fileio.opendir(dpath); + expect(dd !== null).assertTrue(); + expect(dd.closeSync() == null).assertTrue(); + expect(fileio.rmdirSync(dpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_test_dir_open_close_async_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_Dir_open_close_ASync_0010 + * @tc.name fileio_test_dir_open_close_async_001 + * @tc.desc Test Dir.readSync() interface. + */ + it('fileio_test_dir_open_close_async_001', 0, async function (done) { + let dpath = nextFileName('fileio_test_dir_open_close_async_001') + 'd'; + + try { + expect(fileio.mkdirSync(dpath) == null).assertTrue(); + fileio.opendir(dpath, function (error, dd) { + expect(dd !== null).assertTrue(); + expect(dd.closeSync() == null).assertTrue(); + expect(fileio.rmdirSync(dpath) == null).assertTrue(); + done(); + }); + } catch (e) { + console.log('fileio_test_dir_open_close_async_001 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_Dir_open_close_ASync_0000 + * @tc.name fileio_test_dir_open_close_async_000 + * @tc.desc Test Dir.readSync() interface. + */ + it('fileio_test_dir_read_async_000', 0, async function (done) { + let dpath = nextFileName('fileio_test_dir_read_async_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(); + expect(await dd.read() != null).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_dir_read_async_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_Dir_open_close_ASync_0010 + * @tc.name fileio_test_dir_open_close_async_001 + * @tc.desc Test Dir.readSync() interface. + */ + it('fileio_test_dir_read_async_001', 0, async function (done) { + let dpath = nextFileName('fileio_test_dir_read_async_001') + '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(); + dd.read(function (err, dirent) { + expect(dd.closeSync() == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + expect(fileio.rmdirSync(dpath) == null).assertTrue(); + done(); + }); + } catch (e) { + console.log('fileio_test_dir_read_async_001 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_Dir_ReadSync_0000 + * @tc.name fileio_dir_read_sync_000 + * @tc.desc Test Dir.readSync() interface. + */ + it('fileio_dir_read_sync_000', 0, function () { + let dpath = nextFileName('fileio_dir_read_sync_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(); + expect(dd.readSync() != null).assertTrue(); + expect(dd.closeSync() == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + expect(fileio.rmdirSync(dpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_dir_read_sync_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_Dir_ReadSync_0010 + * @tc.name fileio_dir_read_sync_001 + * @tc.desc Test Dir.readSync() interface. + */ + it('fileio_dir_read_sync_001', 0, function () { + let dpath = nextFileName('fileio_dir_read_sync_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(); + expect(dd.readSync(-1) != null).assertTrue(); + 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_ReadSync_Name_0000 + * @tc.name fileio_dir_read_sync_name_000 + * @tc.desc Test Dir.readSync() interface. + */ + it('fileio_dir_read_sync_name_000', 0, async function (done) { + let dpath = nextFileName('fileio_dir_read_sync_name_000') + 'd'; + let fpath = dpath + '/f1'; + try { + expect(fileio.mkdirSync(dpath) == null).assertTrue(); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + let dd = await fileio.opendir(dpath); + expect(dd !== null).assertTrue(); + let dir = dd.readSync(); + expect(dir != null).assertTrue(); + expect(isString(dir.name)).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + expect(fileio.rmdirSync(dpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_dir_read_sync_name_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_Dir_ReadSync_Name_0010 + * @tc.name fileio_dir_read_sync_name_001 + * @tc.desc Test Dir.readSync() interface. + */ + it('fileio_dir_read_sync_name_001', 0, async function (done) { + let dpath = nextFileName('fileio_dir_read_sync_name_001') + 'd'; + let fpath = dpath + '/f1'; + try { + expect(fileio.mkdirSync(dpath) == null).assertTrue(); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + let dd = await fileio.opendir(dpath); + expect(dd !== null).assertTrue(); + let dir = dd.readSync(); + expect(dir != null).assertTrue(); + expect(fpath.indexOf(dir.name) > -1).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + expect(fileio.rmdirSync(dpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_dir_read_sync_name_001 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_Dir_ReadSync_isBlockDevice_0000 + * @tc.name fileio_dir_read_sync_isBlockDevice_000 + * @tc.desc Test Dir.readSync() interface. + */ + it('fileio_dir_read_sync_isBlockDevice_000', 0, async function (done) { + let dpath = nextFileName('fileio_dir_read_sync_isBlockDevice_000') + 'd'; + let fpath = dpath + '/f1'; + try { + expect(fileio.mkdirSync(dpath) == null).assertTrue(); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + let dd = await fileio.opendir(dpath); + expect(dd !== null).assertTrue(); + let dir = dd.readSync(); + expect(dir != null).assertTrue(); + expect(isBoolean(dir.isBlockDevice())).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + expect(fileio.rmdirSync(dpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_dir_read_sync_isBlockDevice_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_Dir_ReadSync_isBlockDevice_0010 + * @tc.name fileio_dir_read_sync_isBlockDevice_001 + * @tc.desc Test Dir.readSync() interface. + */ + it('fileio_dir_read_sync_isBlockDevice_001', 0, async function (done) { + let dpath = nextFileName('fileio_dir_read_sync_isBlockDevice_001') + 'd'; + let fpath = dpath + '/f1'; + try { + expect(fileio.mkdirSync(dpath) == null).assertTrue(); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + let dd = await fileio.opendir(dpath); + expect(dd !== null).assertTrue(); + let dir = dd.readSync(); + expect(dir != null).assertTrue(); + expect(dir.isBlockDevice() === false).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + expect(fileio.rmdirSync(dpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_dir_read_sync_isBlockDevice_001 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_Dir_ReadSync_isCharacterDevice_0000 + * @tc.name fileio_dir_read_sync_isCharacterDevice_000 + * @tc.desc Test Dir.readSync() interface. + */ + it('fileio_dir_read_sync_isCharacterDevice_000', 0, async function (done) { + let dpath = nextFileName('fileio_dir_read_sync_isCharacterDevice_000') + 'd'; + let fpath = dpath + '/f1'; + try { + expect(fileio.mkdirSync(dpath) == null).assertTrue(); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + let dd = await fileio.opendir(dpath); + expect(dd !== null).assertTrue(); + let dir = dd.readSync(); + expect(dir != null).assertTrue(); + expect(isBoolean(dir.isCharacterDevice())).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + expect(fileio.rmdirSync(dpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_dir_read_sync_isCharacterDevice_000 has failed for ' + e); + } + }); + + /** + * @tc.number SUB_DF_FileIO_Dir_ReadSync_isCharacterDevice_0010 + * @tc.name fileio_dir_read_sync_isCharacterDevice_001 + * @tc.desc Test Dir.readSync() interface. + */ + it('fileio_dir_read_sync_isCharacterDevice_001', 0, async function (done) { + let dpath = nextFileName('fileio_dir_read_sync_isCharacterDevice_001') + 'd'; + let fpath = dpath + '/f1'; + try { + expect(fileio.mkdirSync(dpath) == null).assertTrue(); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + let dd = await fileio.opendir(dpath); + expect(dd !== null).assertTrue(); + let dir = dd.readSync(); + expect(dir != null).assertTrue(); + expect(dir.isCharacterDevice() === false).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + expect(fileio.rmdirSync(dpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_dir_read_sync_isCharacterDevice_001 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_Dir_ReadSync_isDirectory_0000 + * @tc.name fileio_dir_read_sync_isDirectory_000 + * @tc.desc Test Dir.readSync() interface. + */ + it('fileio_dir_read_sync_isDirectory_000', 0, async function (done) { + let dpath = nextFileName('fileio_dir_read_sync_isDirectory_000') + 'd'; + let fpath = dpath + '/f1'; + try { + expect(fileio.mkdirSync(dpath) == null).assertTrue(); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + let dd = await fileio.opendir(dpath); + expect(dd !== null).assertTrue(); + let dir = dd.readSync(); + expect(dir != null).assertTrue(); + expect(isBoolean(dir.isDirectory())).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + expect(fileio.rmdirSync(dpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_dir_read_sync_isDirectory_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_Dir_ReadSync_isDirectory_0010 + * @tc.name fileio_dir_read_sync_isDirectory_001 + * @tc.desc Test Dir.readSync() interface. + */ + it('fileio_dir_read_sync_isDirectory_001', 0, async function (done) { + let dpath = nextFileName('fileio_dir_read_sync_isDirectory_001') + 'd'; + let fpath = dpath + '/f1'; + try { + expect(fileio.mkdirSync(dpath) == null).assertTrue(); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + let dd = await fileio.opendir(dpath); + expect(dd !== null).assertTrue(); + let dir = dd.readSync(); + expect(dir != null).assertTrue(); + expect(dir.isDirectory() === false).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + expect(fileio.rmdirSync(dpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_dir_read_sync_isDirectory_001 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_Dir_ReadSync_isFIFO_0000 + * @tc.name fileio_dir_read_sync_isFIFO_000 + * @tc.desc Test Dir.readSync() interface. + */ + it('fileio_dir_read_sync_isFIFO_000', 0, async function (done) { + let dpath = nextFileName('fileio_dir_read_sync_isFIFO_000') + 'd'; + let fpath = dpath + '/f1'; + try { + expect(fileio.mkdirSync(dpath) == null).assertTrue(); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + let dd = await fileio.opendir(dpath); + expect(dd !== null).assertTrue(); + let dir = dd.readSync(); + expect(dir != null).assertTrue(); + expect(isBoolean(dir.isFIFO())).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + expect(fileio.rmdirSync(dpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_dir_read_sync_isFIFO_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_Dir_ReadSync_isFIFO_0010 + * @tc.name fileio_dir_read_sync_isFIFO_001 + * @tc.desc Test Dir.readSync() interface. + */ + it('fileio_dir_read_sync_isFIFO_001', 0, async function (done) { + let dpath = nextFileName('fileio_dir_read_sync_isFIFO_001') + 'd'; + let fpath = dpath + '/f1'; + try { + expect(fileio.mkdirSync(dpath) == null).assertTrue(); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + let dd = await fileio.opendir(dpath); + expect(dd !== null).assertTrue(); + let dir = dd.readSync(); + expect(dir != null).assertTrue(); + expect(dir.isFIFO() === false).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + expect(fileio.rmdirSync(dpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_dir_read_sync_isFIFO_001 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_Dir_ReadSync_isFile_0000 + * @tc.name fileio_dir_read_sync_isFile_000 + * @tc.desc Test Dir.readSync() interface. + */ + it('fileio_dir_read_sync_isFile_000', 0, async function (done) { + let dpath = nextFileName('fileio_dir_read_sync_isFile_000') + 'd'; + let fpath = dpath + '/f1'; + try { + expect(fileio.mkdirSync(dpath) == null).assertTrue(); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + let dd = await fileio.opendir(dpath); + expect(dd !== null).assertTrue(); + let dir = dd.readSync(); + expect(dir != null).assertTrue(); + expect(isBoolean(dir.isFile())).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + expect(fileio.rmdirSync(dpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_dir_read_sync_isFile_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_Dir_ReadSync_isFile_0010 + * @tc.name fileio_dir_read_sync_isFile_001 + * @tc.desc Test Dir.readSync() interface. + */ + it('fileio_dir_read_sync_isFile_001', 0, async function (done) { + let dpath = nextFileName('fileio_dir_read_sync_isFile_001') + 'd'; + let fpath = dpath + '/f1'; + try { + expect(fileio.mkdirSync(dpath) == null).assertTrue(); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + let dd = await fileio.opendir(dpath); + expect(dd !== null).assertTrue(); + let dir = dd.readSync(); + expect(dir != null).assertTrue(); + expect(dir.isFile()).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + expect(fileio.rmdirSync(dpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_dir_read_sync_isFile_001 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_Dir_ReadSync_isSocket_0000 + * @tc.name fileio_dir_read_sync_isSocket_000 + * @tc.desc Test Dir.readSync() interface. + */ + it('fileio_dir_read_sync_isSocket_000', 0, async function (done) { + let dpath = nextFileName('fileio_dir_read_sync_isSocket_000') + 'd'; + let fpath = dpath + '/f1'; + try { + expect(fileio.mkdirSync(dpath) == null).assertTrue(); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + let dd = await fileio.opendir(dpath); + expect(dd !== null).assertTrue(); + let dir = dd.readSync(); + expect(dir != null).assertTrue(); + expect(isBoolean(dir.isSocket())).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + expect(fileio.rmdirSync(dpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_dir_read_sync_isSocket_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_Dir_ReadSync_isSocket_0010 + * @tc.name fileio_dir_read_sync_isSocket_001 + * @tc.desc Test Dir.readSync() interface. + */ + it('fileio_dir_read_sync_isSocket_001', 0, async function (done) { + let dpath = nextFileName('fileio_dir_read_sync_isSocket_001') + 'd'; + let fpath = dpath + '/f1'; + try { + expect(fileio.mkdirSync(dpath) == null).assertTrue(); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + let dd = await fileio.opendir(dpath); + expect(dd !== null).assertTrue(); + let dir = dd.readSync(); + expect(dir != null).assertTrue(); + expect(dir.isSocket() === false).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + expect(fileio.rmdirSync(dpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_dir_read_sync_isSocket_001 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_Dir_ReadSync_isSymbolicLink_0000 + * @tc.name fileio_dir_read_sync_isSymbolicLink_000 + * @tc.desc Test Dir.readSync() interface. + */ + it('fileio_dir_read_sync_isSymbolicLink_000', 0, async function (done) { + let dpath = nextFileName('fileio_dir_read_sync_isSymbolicLink_000') + 'd'; + let fpath = dpath + '/f1'; + try { + expect(fileio.mkdirSync(dpath) == null).assertTrue(); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + let dd = await fileio.opendir(dpath); + expect(dd !== null).assertTrue(); + let dir = dd.readSync(); + expect(dir != null).assertTrue(); + expect(isBoolean(dir.isSymbolicLink())).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + expect(fileio.rmdirSync(dpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_dir_read_sync_isSymbolicLink_000 has failed for ' + e); + expect(null); + } + }); + + /** + * @tc.number SUB_DF_FileIO_Dir_ReadSync_isSymbolicLink_0010 + * @tc.name fileio_dir_read_sync_isSymbolicLink_001 + * @tc.desc Test Dir.readSync() interface. + */ + it('fileio_dir_read_sync_isSymbolicLink_001', 0, async function (done) { + let dpath = nextFileName('fileio_dir_read_sync_isSymbolicLink_001') + 'd'; + let fpath = dpath + '/f1'; + try { + expect(fileio.mkdirSync(dpath) == null).assertTrue(); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + let dd = await fileio.opendir(dpath); + expect(dd !== null).assertTrue(); + let dir = dd.readSync(); + expect(dir != null).assertTrue(); + expect(dir.isSymbolicLink() === false).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + expect(fileio.rmdirSync(dpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_dir_read_sync_isSymbolicLink_001 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_Dir_ReadAsync_0000 + * @tc.name fileio_dir_read_async_000 + * @tc.desc Test Dir.readAsync() interface. + */ + it('fileio_dir_read_async_000', 0, async function (done) { + let dpath = nextFileName('fileio_dir_read_async_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(); + expect(await dd.read() != null).assertTrue(); + expect(dd.closeSync() == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + expect(fileio.rmdirSync(dpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_dir_read_async_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_Dir_ReadAsync_0010 + * @tc.name fileio_dir_read_async_001 + * @tc.desc Test Dir.readAsync() interface. + */ + it('fileio_dir_read_async_001', 0, async function (done) { + let dpath = nextFileName('fileio_dir_read_async_001') + '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(); + dd.read(function (err, dirent) { + expect(dd.closeSync() == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + expect(fileio.rmdirSync(dpath) == null).assertTrue(); + done(); + }) + } catch (e) { + console.log('fileio_dir_read_async_001 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_Dir_ReadAsync_Name_0000 + * @tc.name fileio_dir_read_async_name_000 + * @tc.desc Test Dir.readAsync() interface. + */ + it('fileio_dir_read_async_name_000', 0, async function (done) { + let dpath = nextFileName('fileio_dir_read_async_name_000') + 'd'; + let fpath = dpath + '/f1'; + try { + expect(fileio.mkdirSync(dpath) == null).assertTrue(); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + let dd = await fileio.opendir(dpath); + expect(dd !== null).assertTrue(); + let dir = await dd.read(); + expect(dir != null).assertTrue(); + expect(isString(dir.name)).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + expect(fileio.rmdirSync(dpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_dir_read_async_name_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_Dir_ReadAsync_Name_0010 + * @tc.name fileio_dir_read_async_name_001 + * @tc.desc Test Dir.readAsync() interface. + */ + it('fileio_dir_read_async_name_001', 0, async function (done) { + let dpath = nextFileName('fileio_dir_read_async_name_001') + 'd'; + let fpath = dpath + '/f1'; + try { + expect(fileio.mkdirSync(dpath) == null).assertTrue(); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + let dd = await fileio.opendir(dpath); + expect(dd !== null).assertTrue(); + let dir = await dd.read(); + expect(dir != null).assertTrue(); + expect(fpath.indexOf(dir.name) > -1).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + expect(fileio.rmdirSync(dpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_dir_read_async_name_001 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_Dir_ReadAsync_IsBlockDevice_0000 + * @tc.name fileio_dir_read_async_isBlockDevice_000 + * @tc.desc Test Dir.readAsync() interface. + */ + it('fileio_dir_read_async_isBlockDevice_000', 0, async function (done) { + let dpath = nextFileName('fileio_dir_read_async_isBlockDevice_000') + 'd'; + let fpath = dpath + '/f1'; + try { + expect(fileio.mkdirSync(dpath) == null).assertTrue(); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + let dd = await fileio.opendir(dpath); + expect(dd !== null).assertTrue(); + let dir = await dd.read(); + expect(dir != null).assertTrue(); + expect(isBoolean(dir.isBlockDevice())).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + expect(fileio.rmdirSync(dpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_dir_read_async_isBlockDevice_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_Dir_ReadAsync_IsBlockDevice_0010 + * @tc.name fileio_dir_read_async_isBlockDevice_001 + * @tc.desc Test Dir.readAsync() interface. + */ + it('fileio_dir_read_async_isBlockDevice_001', 0, async function (done) { + let dpath = nextFileName('fileio_dir_read_async_isBlockDevice_001') + 'd'; + let fpath = dpath + '/f1'; + try { + expect(fileio.mkdirSync(dpath) == null).assertTrue(); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + let dd = await fileio.opendir(dpath); + expect(dd !== null).assertTrue(); + let dir = await dd.read(); + expect(dir != null).assertTrue(); + expect(dir.isBlockDevice() === false).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + expect(fileio.rmdirSync(dpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_dir_read_async_isBlockDevice_001 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_Dir_ReadAsync_IsCharacterDevice_0000 + * @tc.name fileio_dir_read_async_isCharacterDevice_000 + * @tc.desc Test Dir.readAsync() interface. + */ + + it('fileio_dir_read_async_isCharacterDevice_000', 0, async function (done) { + let dpath = nextFileName('fileio_dir_read_async_isCharacterDevice_000') + 'd'; + let fpath = dpath + '/f1'; + try { + expect(fileio.mkdirSync(dpath) == null).assertTrue(); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + let dd = await fileio.opendir(dpath); + expect(dd !== null).assertTrue(); + let dir = await dd.read(); + expect(dir != null).assertTrue(); + expect(isBoolean(dir.isCharacterDevice())).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + expect(fileio.rmdirSync(dpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_dir_read_async_isCharacterDevice_000 has failed for ' + e); + } + }); + + /** + * @tc.number SUB_DF_FileIO_Dir_ReadAsync_IsCharacterDevice_0010 + * @tc.name fileio_dir_read_async_isCharacterDevice_001 + * @tc.desc Test Dir.readAsync() interface. + */ + it('fileio_dir_read_async_isCharacterDevice_001', 0, async function (done) { + let dpath = nextFileName('fileio_dir_read_async_isCharacterDevice_001') + 'd'; + let fpath = dpath + '/f1'; + try { + expect(fileio.mkdirSync(dpath) == null).assertTrue(); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + let dd = await fileio.opendir(dpath); + expect(dd !== null).assertTrue(); + let dir = await dd.read(); + expect(dir != null).assertTrue(); + expect(dir.isCharacterDevice() === false).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + expect(fileio.rmdirSync(dpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_dir_read_async_isCharacterDevice_001 has failed for ' + e); + } + }); + + /** + * @tc.number SUB_DF_FileIO_Dir_ReadAsync_IsDirectory_0000 + * @tc.name fileio_dir_read_async_isDirectory_000 + * @tc.desc Test Dir.readAsync() interface. + */ + it('fileio_dir_read_async_isDirectory_000', 0, async function (done) { + let dpath = nextFileName('fileio_dir_read_async_isDirectory_000') + 'd'; + let fpath = dpath + '/f1'; + try { + expect(fileio.mkdirSync(dpath) == null).assertTrue(); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + let dd = await fileio.opendir(dpath); + expect(dd !== null).assertTrue(); + let dir = await dd.read(); + expect(dir != null).assertTrue(); + expect(isBoolean(dir.isDirectory())).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + expect(fileio.rmdirSync(dpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_dir_read_async_isDirectory_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_Dir_ReadAsync_IsDirectory_0010 + * @tc.name fileio_dir_read_async_isDirectory_001 + * @tc.desc Test Dir.readAsync() interface. + */ + it('fileio_dir_read_async_isDirectory_001', 0, async function (done) { + let dpath = nextFileName('fileio_dir_read_async_isDirectory_001') + 'd'; + let fpath = dpath + '/f1'; + try { + expect(fileio.mkdirSync(dpath) == null).assertTrue(); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + let dd = await fileio.opendir(dpath); + expect(dd !== null).assertTrue(); + let dir = await dd.read(); + expect(dir != null).assertTrue(); + expect(dir.isDirectory() === false).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + expect(fileio.rmdirSync(dpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_dir_read_async_isDirectory_001 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_Dir_ReadAsync_IsFIFO_0000 + * @tc.name fileio_dir_read_async_isFIFO_000 + * @tc.desc Test Dir.readAsync() interface. + */ + it('fileio_dir_read_async_isFIFO_000', 0, async function (done) { + let dpath = nextFileName('fileio_dir_read_async_isFIFO_000') + 'd'; + let fpath = dpath + '/f1'; + try { + expect(fileio.mkdirSync(dpath) == null).assertTrue(); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + let dd = await fileio.opendir(dpath); + expect(dd !== null).assertTrue(); + let dir = await dd.read(); + expect(dir != null).assertTrue(); + expect(isBoolean(dir.isFIFO())).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + expect(fileio.rmdirSync(dpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_dir_read_async_isFIFO_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_Dir_ReadAsync_IsFIFO_0010 + * @tc.name fileio_dir_read_async_isFIFO_001 + * @tc.desc Test Dir.readAsync() interface. + */ + it('fileio_dir_read_async_isFIFO_001', 0, async function (done) { + let dpath = nextFileName('fileio_dir_read_async_isFIFO_001') + 'd'; + let fpath = dpath + '/f1'; + try { + expect(fileio.mkdirSync(dpath) == null).assertTrue(); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + let dd = await fileio.opendir(dpath); + expect(dd !== null).assertTrue(); + let dir = await dd.read(); + expect(dir != null).assertTrue(); + expect(dir.isFIFO() === false).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + expect(fileio.rmdirSync(dpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_dir_read_async_isFIFO_001 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_Dir_ReadAsync_IsFile_0000 + * @tc.name fileio_dir_read_async_isDirectory_000 + * @tc.desc Test Dir.readAsync() interface. + */ + it('fileio_dir_read_async_isDirectory_000', 0, async function (done) { + let dpath = nextFileName('fileio_dir_read_async_isDirectory_000') + 'd'; + let fpath = dpath + '/f1'; + try { + expect(fileio.mkdirSync(dpath) == null).assertTrue(); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + let dd = await fileio.opendir(dpath); + expect(dd !== null).assertTrue(); + let dir = await dd.read(); + expect(dir != null).assertTrue(); + expect(isBoolean(dir.isFile())).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + expect(fileio.rmdirSync(dpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_dir_read_async_isDirectory_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_Dir_ReadAsync_IsFile_0010 + * @tc.name fileio_dir_read_async_isDirectory_001 + * @tc.desc Test Dir.readAsync() interface. + */ + it('fileio_dir_read_async_isDirectory_001', 0, async function (done) { + let dpath = nextFileName('fileio_dir_read_async_isDirectory_001') + 'd'; + let fpath = dpath + '/f1'; + try { + expect(fileio.mkdirSync(dpath) == null).assertTrue(); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + let dd = await fileio.opendir(dpath); + expect(dd !== null).assertTrue(); + let dir = await dd.read(); + expect(dir != null).assertTrue(); + expect(dir.isFile()).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + expect(fileio.rmdirSync(dpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_dir_read_async_isDirectory_001 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_Dir_ReadAsync_IsSocket_0000 + * @tc.name fileio_dir_read_async_isDirectory_000 + * @tc.desc Test Dir.readAsync() interface. + */ + it('fileio_dir_read_async_isDirectory_000', 0, async function (done) { + let dpath = nextFileName('fileio_dir_read_async_isDirectory_000') + 'd'; + let fpath = dpath + '/f1'; + try { + expect(fileio.mkdirSync(dpath) == null).assertTrue(); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + let dd = await fileio.opendir(dpath); + expect(dd !== null).assertTrue(); + let dir = await dd.read(); + expect(dir != null).assertTrue(); + expect(isBoolean(dir.isSocket())).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + expect(fileio.rmdirSync(dpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_dir_read_async_isDirectory_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_Dir_ReadAsync_IsSocket_0010 + * @tc.name fileio_dir_read_async_isDirectory_001 + * @tc.desc Test Dir.readAsync() interface. + */ + it('fileio_dir_read_async_isDirectory_001', 0, async function (done) { + let dpath = nextFileName('fileio_dir_read_async_isDirectory_001') + 'd'; + let fpath = dpath + '/f1'; + try { + expect(fileio.mkdirSync(dpath) == null).assertTrue(); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + let dd = await fileio.opendir(dpath); + expect(dd !== null).assertTrue(); + let dir = await dd.read(); + expect(dir != null).assertTrue(); + expect(dir.isSocket() === false).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + expect(fileio.rmdirSync(dpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_dir_read_async_isDirectory_001 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_Dir_ReadAsync_IsSymbolicLink_0000 + * @tc.name fileio_dir_read_async_isDirectory_000 + * @tc.desc Test Dir.readAsync() interface. + */ + it('fileio_dir_read_async_isDirectory_000', 0, async function (done) { + let dpath = nextFileName('fileio_dir_read_async_isDirectory_000') + 'd'; + let fpath = dpath + '/f1'; + try { + expect(fileio.mkdirSync(dpath) == null).assertTrue(); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + let dd = await fileio.opendir(dpath); + expect(dd !== null).assertTrue(); + let dir = await dd.read(); + expect(dir != null).assertTrue(); + expect(isBoolean(dir.isSymbolicLink())).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + expect(fileio.rmdirSync(dpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_dir_read_async_isDirectory_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_Dir_ReadAsync_IsSymbolicLink_0010 + * @tc.name fileio_dir_read_async_isDirectory_001 + * @tc.desc Test Dir.readAsync() interface. + */ + it('fileio_dir_read_async_isDirectory_001', 0, async function (done) { + let dpath = nextFileName('fileio_dir_read_async_isDirectory_001') + 'd'; + let fpath = dpath + '/f1'; + try { + expect(fileio.mkdirSync(dpath) == null).assertTrue(); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + let dd = await fileio.opendir(dpath); + expect(dd !== null).assertTrue(); + let dir = await dd.read(); + expect(dir != null).assertTrue(); + expect(dir.isSymbolicLink() === false).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + expect(fileio.rmdirSync(dpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_dir_read_async_isDirectory_001 has failed for ' + e); + expect(null).assertFail(); + } + }); +}) \ No newline at end of file diff --git a/storage/storagefileiojstest/src/main/js/default/test/module_fileio/class_dirent/all.test.js b/storage/storagefileiojstest/src/main/js/default/test/module_fileio/class_dirent/all.test.js new file mode 100644 index 0000000000000000000000000000000000000000..9715da326cab36409a8b637d66c472287410fed5 --- /dev/null +++ b/storage/storagefileiojstest/src/main/js/default/test/module_fileio/class_dirent/all.test.js @@ -0,0 +1,468 @@ +/* + * 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 diff --git a/storage/storagefileiojstest/src/main/js/default/test/module_fileio/class_stream/all.test.js b/storage/storagefileiojstest/src/main/js/default/test/module_fileio/class_stream/all.test.js new file mode 100644 index 0000000000000000000000000000000000000000..d075bb0ceb00afd3e4590b01010cd57663e98455 --- /dev/null +++ b/storage/storagefileiojstest/src/main/js/default/test/module_fileio/class_stream/all.test.js @@ -0,0 +1,258 @@ +/* + * 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 diff --git a/storage/storagefileiojstest/src/main/js/default/test/module_fileio/class_stream/close.test.js b/storage/storagefileiojstest/src/main/js/default/test/module_fileio/class_stream/close.test.js new file mode 100644 index 0000000000000000000000000000000000000000..9c72e4f2fc83c47cb8c9f88a11bdf3128f6e7bdc --- /dev/null +++ b/storage/storagefileiojstest/src/main/js/default/test/module_fileio/class_stream/close.test.js @@ -0,0 +1,104 @@ +/* + * 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 diff --git a/storage/storagefileiojstest/src/main/js/default/test/module_fileio/class_stream/flush.test.js b/storage/storagefileiojstest/src/main/js/default/test/module_fileio/class_stream/flush.test.js new file mode 100644 index 0000000000000000000000000000000000000000..bf7c0c0913bd8740f2023ef0d4926ed2ffe5f38a --- /dev/null +++ b/storage/storagefileiojstest/src/main/js/default/test/module_fileio/class_stream/flush.test.js @@ -0,0 +1,94 @@ +/* + * 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(); + } + }); +}); diff --git a/storage/storagefileiojstest/src/main/js/default/test/module_fileio/class_stream/read.test.js b/storage/storagefileiojstest/src/main/js/default/test/module_fileio/class_stream/read.test.js new file mode 100644 index 0000000000000000000000000000000000000000..3541035d088c7d69befacc6d8b4b6464dbd19251 --- /dev/null +++ b/storage/storagefileiojstest/src/main/js/default/test/module_fileio/class_stream/read.test.js @@ -0,0 +1,68 @@ +/* + * 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(); + } + }); +}); diff --git a/storage/storagefileiojstest/src/main/js/default/test/module_fileio/class_stream/write.test.js b/storage/storagefileiojstest/src/main/js/default/test/module_fileio/class_stream/write.test.js new file mode 100644 index 0000000000000000000000000000000000000000..3e76a12cd06b553836a797b3f2784f6ce8a02f8d --- /dev/null +++ b/storage/storagefileiojstest/src/main/js/default/test/module_fileio/class_stream/write.test.js @@ -0,0 +1,70 @@ +/* + * 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(); + } + }); +}); diff --git a/storage/storagefileiojstest/src/main/js/default/test/module_fileio/class_watcher/createWatcher.test.js b/storage/storagefileiojstest/src/main/js/default/test/module_fileio/class_watcher/createWatcher.test.js new file mode 100644 index 0000000000000000000000000000000000000000..a22da2a361ebcf7343e125464d1cb4bd1124d636 --- /dev/null +++ b/storage/storagefileiojstest/src/main/js/default/test/module_fileio/class_watcher/createWatcher.test.js @@ -0,0 +1,295 @@ +/* + * 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(); + } + }); +}); diff --git a/storage/storagefileiojstest/src/main/js/default/test/module_fileio/members/access.test.js b/storage/storagefileiojstest/src/main/js/default/test/module_fileio/members/access.test.js new file mode 100644 index 0000000000000000000000000000000000000000..7cdad1d56995ddb2609dc38f6abb466e7842fe48 --- /dev/null +++ b/storage/storagefileiojstest/src/main/js/default/test/module_fileio/members/access.test.js @@ -0,0 +1,234 @@ +/* + * 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(); + } + }); +}); diff --git a/storage/storagefileiojstest/src/main/js/default/test/module_fileio/members/chmod.test.js b/storage/storagefileiojstest/src/main/js/default/test/module_fileio/members/chmod.test.js new file mode 100644 index 0000000000000000000000000000000000000000..a6e5508460738c424b67f049ae994bfaa162c385 --- /dev/null +++ b/storage/storagefileiojstest/src/main/js/default/test/module_fileio/members/chmod.test.js @@ -0,0 +1,158 @@ +/* + * 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(); + } + }); +}); diff --git a/storage/storagefileiojstest/src/main/js/default/test/module_fileio/members/chown.test.js b/storage/storagefileiojstest/src/main/js/default/test/module_fileio/members/chown.test.js new file mode 100644 index 0000000000000000000000000000000000000000..703cf38b61d3d7fe7cbfa6ffb2eda61e63e4585b --- /dev/null +++ b/storage/storagefileiojstest/src/main/js/default/test/module_fileio/members/chown.test.js @@ -0,0 +1,78 @@ +/* + * 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(); + } + }); +}); diff --git a/storage/storagefileiojstest/src/main/js/default/test/module_fileio/members/close.test.js b/storage/storagefileiojstest/src/main/js/default/test/module_fileio/members/close.test.js new file mode 100644 index 0000000000000000000000000000000000000000..b94e1414c4f960f1697e0841bb18d15ebb00c219 --- /dev/null +++ b/storage/storagefileiojstest/src/main/js/default/test/module_fileio/members/close.test.js @@ -0,0 +1,48 @@ +/* + * 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) { + } + }) +}) diff --git a/storage/storagefileiojstest/src/main/js/default/test/module_fileio/members/copyFile.test.js b/storage/storagefileiojstest/src/main/js/default/test/module_fileio/members/copyFile.test.js new file mode 100644 index 0000000000000000000000000000000000000000..50b31c6f6b3d4e5da79489699f19adde381dbf89 --- /dev/null +++ b/storage/storagefileiojstest/src/main/js/default/test/module_fileio/members/copyFile.test.js @@ -0,0 +1,170 @@ +/* + * 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('') > -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(); + } + }); +}); diff --git a/storage/storagefileiojstest/src/main/js/default/test/module_fileio/members/createStream.test.js b/storage/storagefileiojstest/src/main/js/default/test/module_fileio/members/createStream.test.js new file mode 100644 index 0000000000000000000000000000000000000000..80670e175b3cf7baef38fa63e651032985bbd316 --- /dev/null +++ b/storage/storagefileiojstest/src/main/js/default/test/module_fileio/members/createStream.test.js @@ -0,0 +1,127 @@ +/* + * 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(); + } + }); +}); diff --git a/storage/storagefileiojstest/src/main/js/default/test/module_fileio/members/fchmod.test.js b/storage/storagefileiojstest/src/main/js/default/test/module_fileio/members/fchmod.test.js new file mode 100644 index 0000000000000000000000000000000000000000..23c79188cf29a77f0c6e39e511dfac6f27bed852 --- /dev/null +++ b/storage/storagefileiojstest/src/main/js/default/test/module_fileio/members/fchmod.test.js @@ -0,0 +1,162 @@ +/* + * 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(); + } + }); + +}); diff --git a/storage/storagefileiojstest/src/main/js/default/test/module_fileio/members/fchown.test.js b/storage/storagefileiojstest/src/main/js/default/test/module_fileio/members/fchown.test.js new file mode 100644 index 0000000000000000000000000000000000000000..47e065deb868754e607488705f04584161fb0de0 --- /dev/null +++ b/storage/storagefileiojstest/src/main/js/default/test/module_fileio/members/fchown.test.js @@ -0,0 +1,107 @@ +/* + * 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(); + } + }); +}); diff --git a/storage/storagefileiojstest/src/main/js/default/test/module_fileio/members/fdatasync.test.js b/storage/storagefileiojstest/src/main/js/default/test/module_fileio/members/fdatasync.test.js new file mode 100644 index 0000000000000000000000000000000000000000..26f0d309e43978ab08686653c1639df753b9e637 --- /dev/null +++ b/storage/storagefileiojstest/src/main/js/default/test/module_fileio/members/fdatasync.test.js @@ -0,0 +1,106 @@ +/* + * 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) { + } + }); +}); diff --git a/storage/storagefileiojstest/src/main/js/default/test/module_fileio/members/fdopenStream.test.js b/storage/storagefileiojstest/src/main/js/default/test/module_fileio/members/fdopenStream.test.js new file mode 100644 index 0000000000000000000000000000000000000000..c2e969c9e00c2ecfa6252d7b67c458d1f5ff9cc1 --- /dev/null +++ b/storage/storagefileiojstest/src/main/js/default/test/module_fileio/members/fdopenStream.test.js @@ -0,0 +1,126 @@ +/* + * 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 diff --git a/storage/storagefileiojstest/src/main/js/default/test/module_fileio/members/fstat.test.js b/storage/storagefileiojstest/src/main/js/default/test/module_fileio/members/fstat.test.js new file mode 100644 index 0000000000000000000000000000000000000000..7413b8cb067a3ec0e5dfca2cba03b5ea0ce640a0 --- /dev/null +++ b/storage/storagefileiojstest/src/main/js/default/test/module_fileio/members/fstat.test.js @@ -0,0 +1,1480 @@ +/* + * 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, isBoolean, + describe, beforeAll, beforeEach, afterEach, afterAll, it, expect, +} from '../../Common'; + +describe('fileio_stat_fstat', function () { + + /** + * @tc.number SUB_DF_FileIO_Stat_FstatSync_0000 + * @tc.name fileio_stat_fstat_sync_000 + * @tc.desc Test fileio.fstatSync() interfaces. + */ + it('fileio_stat_fstat_sync_000', 0, function () { + let fpath = nextFileName('fileio_stat_fstat_sync_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let fd = fileio.openSync(fpath, 0o2); + expect(isIntNum(fd)).assertTrue(); + let stat = fileio.fstatSync(fd); + expect(stat !== null).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_stat_fstat_sync_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_Stat_FstatSync_0010 + * @tc.name fileio_test_stat_fstat_sync_001 + * @tc.desc Test fstatSync() interfaces. + */ + it('fileio_test_stat_fstat_sync_001', 0, function () { + try { + let invalidFD = -1; + fileio.fstatSync(invalidFD); + expect(null).assertFail(); + } catch (e) { + } + }); + + /** + * @tc.number SUB_DF_FileIO_Fstat_Dev_0000 + * @tc.name fileio_fstat_dev_000 + * @tc.desc Test the dev member of class Fstat. + */ + it('fileio_fstat_dev_000', 0, function () { + let fpath = nextFileName('fileio_fstat_dev_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let fd = fileio.openSync(fpath); + let stat = fileio.fstatSync(fd); + expect(isIntNum(stat.dev)).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_fstat_dev_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_fstat_Ino_0000 + * @tc.name fileio_fstat_ino_000 + * @tc.desc Test the ino member of class Fstat + */ + it('fileio_fstat_ino_000', 0, function () { + let fpath = nextFileName('fileio_fstat_ino_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let fd = fileio.openSync(fpath); + let stat = fileio.fstatSync(fd); + expect(isIntNum(stat.ino)).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_fstat_ino_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_Fstat_Mode_0000 + * @tc.name fileio_fstat_mode_000 + * @tc.desc Test the mode member of class Fstat + */ + it('fileio_fstat_mode_000', 0, function () { + let fpath = nextFileName('fileio_fstat_mode_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let fd = fileio.openSync(fpath); + let stat = fileio.fstatSync(fd); + expect(isIntNum(stat.mode)).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_fstat_mode_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_Fstat_Nlink_0000 + * @tc.name fileio_fstat_nlink_000 + * @tc.desc Test the nlink member of class Fstat + */ + it('fileio_fstat_nlink_000', 0, function () { + let fpath = nextFileName('fileio_fstat_nlink_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let fd = fileio.openSync(fpath); + let stat = fileio.fstatSync(fd); + expect(isIntNum(stat.nlink)).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_fstat_nlink_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_Fstat_Uid_0000 + * @tc.name fileio_fstat_uid_000 + * @tc.desc Test the uid member of class Fstat + */ + it('fileio_fstat_uid_000', 0, function () { + let fpath = nextFileName('fileio_fstat_uid_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let fd = fileio.openSync(fpath); + let stat = fileio.fstatSync(fd); + expect(isIntNum(stat.uid)).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_fstat_uid_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_Fstat_Gid_0000 + * @tc.name fileio_fstat_gid_000 + * @tc.desc Test the gid member of class Fstat + */ + it('fileio_fstat_gid_000', 0, function () { + let fpath = nextFileName('fileio_fstat_gid_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let fd = fileio.openSync(fpath); + let stat = fileio.fstatSync(fd); + expect(isIntNum(stat.gid)).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_fstat_gid_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_Fstat_Rdev_0000 + * @tc.name fileio_lstat_rdev_000 + * @tc.desc Test the rdev member of class Fstat + */ + it('fileio_fstat_rdev_000', 0, function () { + let fpath = nextFileName('fileio_fstat_rdev_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let fd = fileio.openSync(fpath); + let stat = fileio.fstatSync(fd); + expect(isIntNum(stat.rdev)).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_fstat_rdev_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_Fstat_Size_0000 + * @tc.name fileio_fstat_size_000 + * @tc.desc Test the size member of class Fstat + */ + it('fileio_fstat_size_000', 0, function () { + let fpath = nextFileName('fileio_fstat_size_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let fd = fileio.openSync(fpath); + let stat = fileio.fstatSync(fd); + expect(isIntNum(stat.size)).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_fstat_size_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_Fstat_Blocks_0000 + * @tc.name fileio_fstat_blocks_000 + * @tc.desc Test the blocks member of class Fstat + */ + it('fileio_fstat_blocks_000', 0, function () { + let fpath = nextFileName('fileio_fstat_blocks_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let fd = fileio.openSync(fpath); + let stat = fileio.fstatSync(fd); + expect(isIntNum(stat.blocks)).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_fstat_blocks_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_Fstat_Atime_0000 + * @tc.name fileio_fstat_atime_000 + * @tc.desc Test the atime member of class Fstat + */ + it('fileio_fstat_atime_000', 0, function () { + let fpath = nextFileName('fileio_fstat_atime_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let fd = fileio.openSync(fpath); + let stat = fileio.fstatSync(fd); + expect(isIntNum(stat.atime)).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_fstat_atime_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_Fstat_Mtime_0000 + * @tc.name fileio_fstat_mtime_000 + * @tc.desc Test the mtime member of class Fstat + */ + it('fileio_fstat_mtime_000', 0, function () { + let fpath = nextFileName('fileio_fstat_mtime_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let fd = fileio.openSync(fpath); + let stat = fileio.fstatSync(fd); + expect(isIntNum(stat.mtime)).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_fstat_mtime_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_Fstat_Ctime_0000 + * @tc.name fileio_fstat_ctime_000 + * @tc.desc Test the ctime member of class Fstat + */ + it('fileio_fstat_ctime_000', 0, function () { + let fpath = nextFileName('fileio_fstat_ctime_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let fd = fileio.openSync(fpath); + let stat = fileio.fstatSync(fd); + expect(isIntNum(stat.ctime)).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_lstat_ctime_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_Fstat_IsBlockDevice_0000 + * @tc.name fileio_fstat_is_block_device_000 + * @tc.desc Test the isBlockDevice() method of class Fstat. + * This interface shall return a boolean variable. + */ + it('fileio_fstat_is_block_device_000', 0, function () { + let fpath = nextFileName('fileio_fstat_is_block_device_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let fd = fileio.openSync(fpath); + let stat = fileio.fstatSync(fd); + expect(isBoolean(stat.isBlockDevice())).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_fstat_is_block_device_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_Fstat_IsBlockDevice_0010 + * @tc.name fileio_fstat_is_block_device_001 + * @tc.desc Test the isBlockDevice() method of class Fstat. + * This interface shall not treat a normal file as a block special device. + */ + it('fileio_fstat_is_block_device_001', 0, function () { + let fpath = nextFileName('fileio_fstat_is_block_device_001'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let fd = fileio.openSync(fpath); + let stat = fileio.fstatSync(fd); + expect(stat.isBlockDevice() === false).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_fstat_is_block_device_001 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_Fstat_IsBlockDevice_0020 + * @tc.name fileio_test_fstat_is_block_device_002 + * @tc.desc Test Fstat.isBlockDevice() interface. + */ + it('fileio_test_fstat_is_block_device_002', 0, function () { + let fpath = nextFileName('fileio_test_fstat_is_block_device_002'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let fd = fileio.openSync(fpath); + let stat = fileio.fstatSync(fd); + expect(stat.isBlockDevice(-1) === false).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(null).assertFail(); + } catch (e) { + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_Fstat_IsCharacterDevice_0000 + * @tc.name fileio_fstat_is_character_device_000 + * @tc.desc Test Fstat.isCharacterDevice() interface. + * This interface shall return a boolean variable. + */ + it('fileio_fstat_is_character_device_000', 0, function () { + let fpath = nextFileName('fileio_fstat_is_character_device_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + let fd = fileio.openSync(fpath); + let stat = fileio.fstatSync(fd); + expect(isBoolean(stat.isCharacterDevice())).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_fstat_is_character_device_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_Fstat_IsCharacterDevice_0010 + * @tc.name fileio_fstat_is_character_device_001 + * @tc.desc Test Fstat.isCharacterDevice() interface. + * This interface shall not treat a normal file as a character special device. + */ + it('fileio_fstat_is_character_device_001', 0, function () { + let fpath = nextFileName('fileio_fstat_is_character_device_001'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let fd = fileio.openSync(fpath); + let stat = fileio.fstatSync(fd); + expect(stat.isCharacterDevice() === false).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_fstat_is_character_device_001 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_Fstat_IsCharacterDevice_0020 + * @tc.name fileio_test_fstat_is_character_device_002 + * @tc.desc Test Fstat.isCharacterDevice() interface. + */ + it('fileio_test_fstat_is_character_device_002', 0, function () { + let fpath = nextFileName('fileio_test_fstat_is_character_device_002'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let fd = fileio.openSync(fpath); + let stat = fileio.fstatSync(fd); + expect(stat.isCharacterDevice(-1) === false).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(null).assertFail(); + } catch (e) { + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_Fstat_IsDirectory_0000 + * @tc.name fileio_fstat_is_directory_000 + * @tc.desc Test Fstat.isDirectory() interface. + * This interface shall return a boolean variable. + */ + it('fileio_fstat_is_directory_000', 0, function () { + let fpath = nextFileName('fileio_fstat_is_directory_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let fd = fileio.openSync(fpath); + let stat = fileio.fstatSync(fd); + expect(isBoolean(stat.isDirectory())).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_fstat_is_directory_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_Fstat_IsDirectory_0010 + * @tc.name fileio_fstat_is_directory_001 + * @tc.desc Test Fstat.isDirectory() interface. + * This interface shall not treat a normal file as a directory. + */ + it('fileio_fstat_is_directory_001', 0, function () { + let fpath = nextFileName('fileio_fstat_is_directory_001'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let fd = fileio.openSync(fpath); + let stat = fileio.fstatSync(fd); + expect(stat.isDirectory() === false).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_fstat_is_directory_001 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_Fstat_IsDirectory_0020 + * @tc.name fileio_fstat_is_directory_002 + * @tc.desc Test Fstat.isDirectory() interface. + * This interface shall treat a directory as a directory. + */ + it('fileio_fstat_is_directory_002', 0, function () { + let dpath = nextFileName('fileio_fstat_is_directory_002') + 'dd'; + + try { + expect(fileio.mkdirSync(dpath) == null).assertTrue(); + let fd = fileio.openSync(dpath); + let stat = fileio.fstatSync(fd); + expect(stat.isDirectory()).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.rmdirSync(dpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_fstat_is_directory_002 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_Fstat_IsDirectory_0030 + * @tc.name fileio_test_fstat_is_directory_003 + * @tc.desc Test Fstat.isDirectory() interface. + */ + it('fileio_test_fstat_is_directory_003', 0, function () { + let dpath = nextFileName('fileio_test_fstat_is_directory_003') + 'd'; + + try { + expect(fileio.mkdirSync(dpath) == null).assertTrue(); + let fd = fileio.openSync(dpath); + let stat = fileio.fstatSync(fd); + expect(stat.isDirectory(-1)).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(null).assertFail(); + } catch (e) { + expect(fileio.rmdirSync(dpath) == null).assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_Fstat_IsFIFO_0000 + * @tc.name fileio_fstat_is_fifo_000 + * @tc.desc Test Fstat.isFIFO() interface. + * This interface shall return a boolean variable. + */ + it('fileio_fstat_is_fifo_000', 0, function () { + let fpath = nextFileName('fileio_fstat_is_fifo_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let fd = fileio.openSync(fpath); + let stat = fileio.fstatSync(fd); + expect(isBoolean(stat.isFIFO())).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_fstat_is_fifo_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_Fstat_IsFIFO_0010 + * @tc.name fileio_fstat_is_fifo_001 + * @tc.desc Test Fstat.isFIFO() interface. + * This interface shall not treat a normal file as a FIFO. + */ + it('fileio_fstat_is_fifo_001', 0, function () { + let fpath = nextFileName('fileio_fstat_is_fifo_001'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let fd = fileio.openSync(fpath); + let stat = fileio.fstatSync(fd); + expect(stat.isFIFO() === false).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_fstat_is_fifo_001 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_Fstat_IsFIFO_0020 + * @tc.name fileio_test_fstat_is_fifo_002 + * @tc.desc Test Fstat.isFIFO() interface. + */ + it('fileio_test_fstat_is_fifo_002', 0, function () { + let fpath = nextFileName('fileio_test_fstat_is_fifo_002'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let fd = fileio.openSync(fpath); + let stat = fileio.fstatSync(fd); + expect(stat.isFIFO(-1) === false).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(null).assertFail(); + } catch (e) { + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_Fstat_IsFILE_0000 + * @tc.name fileio_fstat_is_file_000 + * @tc.desc Test Fstat.isFile() interface. + * This interface shall return a boolean variable. + */ + it('fileio_fstat_is_file_000', 0, function () { + let fpath = nextFileName('fileio_fstat_is_file_000'); + expect(isBoolean(prepareFile(fpath, FILE_CONTENT))).assertTrue(); + + try { + let fd = fileio.openSync(fpath); + let stat = fileio.fstatSync(fd); + expect(isBoolean(stat.isFile())).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_fstat_is_file_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_Fstat_IsFILE_0010 + * @tc.name fileio_fstat_is_file_001 + * @tc.desc Test Fstat.isFile() interface. + * This interface shall treat a normal file as a normal file. + */ + it('fileio_fstat_is_file_001', 0, function () { + let fpath = nextFileName('fileio_fstat_is_file_001'); + expect(isBoolean(prepareFile(fpath, FILE_CONTENT))).assertTrue(); + + try { + let fd = fileio.openSync(fpath); + let stat = fileio.fstatSync(fd); + expect(stat.isFile()).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_fstat_is_file_001 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_Fstat_IsFILE_0020 + * @tc.name fileio_fstat_is_file_002 + * @tc.desc Test Fstat.isFile() interface. + * This interface shall not treat a directory as a normal file. + */ + it('fileio_fstat_is_file_002', 0, function () { + let dpath = nextFileName('fileio_fstat_is_file_002') + 'aa'; + + try { + expect(fileio.mkdirSync(dpath) == null).assertTrue(); + let fd = fileio.openSync(dpath); + let stat = fileio.fstatSync(fd); + expect(stat.isFile() === false).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.rmdirSync(dpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_fstat_is_file_002 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_Fstat_IsFILE_0030 + * @tc.name fileio_test_fstat_is_file_003 + * @tc.desc Test Fstat.isFile() interface. + */ + it('fileio_test_fstat_is_file_003', 0, function () { + let dpath = nextFileName('fileio_test_fstat_is_file_003') + 'ab'; + + try { + expect(fileio.mkdirSync(dpath) == null).assertTrue(); + let fd = fileio.openSync(dpath); + let stat = fileio.fstatSync(fd); + expect(stat.isFile(-1) === false).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(null).assertFail(); + } catch (e) { + expect(fileio.rmdirSync(dpath) == null).assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_Fstat_IsSocket_0000 + * @tc.name fileio_fstat_is_socket_000 + * @tc.desc Test Fstat.isSocket() interface. + * This interface shall return a boolean variable. + */ + it('fileio_fstat_is_socket_000', 0, function () { + let fpath = nextFileName('fileio_fstat_is_socket_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let fd = fileio.openSync(fpath); + let stat = fileio.fstatSync(fd); + expect(isBoolean(stat.isSocket())).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_fstat_is_socket_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_Fstat_IsSocket_0010 + * @tc.name fileio_fstat_is_socket_001 + * @tc.desc Test Fstat.isSocket() interface. + * This interface shall not treat a file as a socket. + */ + it('fileio_fstat_is_socket_001', 0, function () { + let fpath = nextFileName('fileio_fstat_is_socket_001'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let fd = fileio.openSync(fpath); + let stat = fileio.fstatSync(fd); + expect(stat.isSocket() === false).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_fstat_is_socket_001 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_Fstat_IsSocket_0020 + * @tc.name fileio_test_fstat_is_socket_002 + * @tc.desc Test Fstat.isSocket() interface. + */ + it('fileio_test_fstat_is_socket_002', 0, function () { + let fpath = nextFileName('fileio_test_fstat_is_socket_002'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + let fd = fileio.openSync(fpath); + let stat = fileio.fstatSync(fd); + expect(stat.isSocket(-1) === false).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(null).assertFail(); + } catch (e) { + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_Fstat_IsSymbolicLink_0000 + * @tc.name fileio_fstat_is_symbolic_link_000 + * @tc.desc Test Fstat.isSymbolicLink() interface. + * This interface shall return a boolean variable. + */ + it('fileio_fstat_is_symbolic_link_000', 0, function () { + let fpath = nextFileName('fileio_fstat_is_symbolic_link_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let fd = fileio.openSync(fpath); + let stat = fileio.fstatSync(fd); + expect(isBoolean(stat.isSymbolicLink())).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_fstat_is_symbolic_link_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_Fstat_IsSymbolicLink_0010 + * @tc.name fileio_fstat_is_symbolic_link_001 + * @tc.desc Test Fstat.isSymbolicLink() interface. + * This interface shall not treat a normal file as a symbolic link. + */ + it('fileio_fstat_is_symbolic_link_001', 0, function () { + let fpath = nextFileName('fileio_fstat_is_symbolic_link_001'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let fd = fileio.openSync(fpath); + let stat = fileio.fstatSync(fd); + expect(stat.isSymbolicLink() === false).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_fstat_is_symbolic_link_001 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_Fstat_IsSymbolicLink_0020 + * @tc.name fileio_test_fstat_is_symbolic_link_002 + * @tc.desc Test Fstat.isSymbolicLink() interface. + */ + it('fileio_test_fstat_is_symbolic_link_002', 0, function () { + let fpath = nextFileName('fileio_test_fstat_is_symbolic_link_002'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let fd = fileio.openSync(fpath); + let stat = fileio.fstatSync(fd); + expect(stat.isSymbolicLink(-1) === false).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(null).assertFail(); + } catch (e) { + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_FstatAsync_0000 + * @tc.name fileio_fstat_async_000 + * @tc.desc Test Stat.FstatAsync() interface. + * This interface shall work properly in normal case when providing the promise async model. + */ + it('fileio_fstat_async_000', 0, async function (done) { + let fpath = nextFileName('fileio_fstat_async_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let fd = fileio.openSync(fpath); + fileio.fstat(fd).then((stat) => { + expect(stat !== null).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + }); + done(); + } catch (e) { + console.log('fileio_fstat_async_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_FstatAsync_0000 + * @tc.name fileio_fstat_async_001 + * @tc.desc Test Stat.FstatAsync() interface. + * This interface shall work properly in normal case when providing the callback async model. + */ + it('fileio_fstat_async_001', 0, async function (done) { + let fpath = nextFileName('fileio_fstat_async_001'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let fd = fileio.openSync(fpath); + fileio.fstat(fd, function (error) { + expect(!error).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + }); + } catch (e) { + console.log('fileio_fstat_async_001 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_FstatAsync_Dev_0000 + * @tc.name fileio_fstat_async_dev_000 + * @tc.desc Test the dev member of class Lstat. + */ + it('fileio_fstat_async_dev_000', 0, async function (done) { + let fpath = nextFileName('fileio_fstat_async_dev_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + let fd = fileio.openSync(fpath); + let stat = await fileio.fstat(fd); + expect(isIntNum(stat.dev)).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_fstat_async_dev_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_FstatAsync_Ino_0000 + * @tc.name fileio_fstat_async_ino_000 + * @tc.desc Test the ino member of class Lstat. + */ + it('fileio_fstat_async_ino_000', 0, async function (done) { + let fpath = nextFileName('fileio_fstat_async_ino_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + let fd = fileio.openSync(fpath); + let stat = await fileio.fstat(fd); + expect(isIntNum(stat.ino)).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_fstat_async_ino_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_FstatAsync_Mode_0000 + * @tc.name fileio_fstat_async_mode_000 + * @tc.desc Test the mode member of class Lstat. + */ + it('fileio_fstat_async_mode_000', 0, async function (done) { + let fpath = nextFileName('fileio_fstat_async_mode_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + let fd = fileio.openSync(fpath); + let stat = await fileio.fstat(fd); + expect(isIntNum(stat.mode)).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_fstat_async_mode_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_FstatAsync_Nlink_0000 + * @tc.name fileio_fstat_async_nlink_000 + * @tc.desc Test the nlink member of class Lstat. + */ + it('fileio_fstat_async_nlink_000', 0, async function (done) { + let fpath = nextFileName('fileio_fstat_async_nlink_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + let fd = fileio.openSync(fpath); + let stat = await fileio.fstat(fd); + expect(isIntNum(stat.nlink)).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_fstat_async_nlink_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_FstatAsync_Uid_0000 + * @tc.name fileio_fstat_async_uid_000 + * @tc.desc Test the uid member of class Lstat. + */ + it('fileio_fstat_async_uid_000', 0, async function (done) { + let fpath = nextFileName('fileio_fstat_async_uid_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + let fd = fileio.openSync(fpath); + let stat = await fileio.fstat(fd); + expect(isIntNum(stat.uid)).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_fstat_async_uid_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_FstatAsync_Gid_0000 + * @tc.name fileio_fstat_async_gid_000 + * @tc.desc Test the gid member of class Lstat. + */ + it('fileio_fstat_async_gid_000', 0, async function (done) { + let fpath = nextFileName('fileio_fstat_async_gid_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + let fd = fileio.openSync(fpath); + let stat = await fileio.fstat(fd); + expect(isIntNum(stat.gid)).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_fstat_async_gid_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_FstatAsync_Rdev_0000 + * @tc.name fileio_fstat_async_rdev_000 + * @tc.desc Test the rdev member of class Lstat. + */ + it('fileio_fstat_async_rdev_000', 0, async function (done) { + let fpath = nextFileName('fileio_fstat_async_rdev_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + let fd = fileio.openSync(fpath); + let stat = await fileio.fstat(fd); + expect(isIntNum(stat.rdev)).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_fstat_async_rdev_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_FstatAsync_Size_0000 + * @tc.name fileio_fstat_async_size_000 + * @tc.desc Test the size member of class lstat. + */ + it('fileio_fstat_async_size_000', 0, async function (done) { + let fpath = nextFileName('fileio_fstat_async_size_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + let fd = fileio.openSync(fpath); + let stat = await fileio.fstat(fd); + expect(isIntNum(stat.size)).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_fstat_async_size_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_FstatAsync_Blocks_0000 + * @tc.name fileio_fstat_async_blocks_000 + * @tc.desc Test Fstat.blocks() interface. + * @tc.desc Test the blocks member of class lstat. + */ + it('fileio_fstat_async_blocks_000', 0, async function (done) { + let fpath = nextFileName('fileio_fstat_async_blocks_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + let fd = fileio.openSync(fpath); + let stat = await fileio.fstat(fd); + expect(isIntNum(stat.blocks)).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_fstat_async_blocks_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_FstatAsync_Atime_0000 + * @tc.name fileio_fstat_async_atime_000 + * @tc.desc Test Fstat.atime() interface. + * @tc.desc Test the atime member of class lstat. + */ + it('fileio_fstat_async_atime_000', 0, async function (done) { + let fpath = nextFileName('fileio_fstat_async_atime_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + let fd = fileio.openSync(fpath); + let stat = await fileio.fstat(fd); + expect(isIntNum(stat.atime)).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_fstat_async_atime_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_FstatAsync_Mtime_0000 + * @tc.name fileio_fstat_async_mtime_000 + * @tc.desc Test Fstat.mtime() interface. + * @tc.desc Test the mtime member of class lstat. + */ + it('fileio_fstat_async_mtime_000', 0, async function (done) { + let fpath = nextFileName('fileio_fstat_async_mtime_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + let fd = fileio.openSync(fpath); + let stat = await fileio.fstat(fd); + expect(isIntNum(stat.mtime)).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_fstat_async_mtime_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_FstatAsync_Ctime_0000 + * @tc.name fileio_fstat_async_ctime_000 + * @tc.desc Test the ctime member of class lstat. + */ + it('fileio_fstat_async_ctime_000', 0, async function (done) { + let fpath = nextFileName('fileio_fstat_async_ctime_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let fd = fileio.openSync(fpath); + let stat = await fileio.fstat(fd); + expect(isIntNum(stat.ctime)).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_fstat_async_ctime_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_FstatAsync_IsBlockDevice_0000 + * @tc.name fileio_fstat_async_is_block_device_000 + * @tc.desc Test the isBlockDevice method of class lstat. + */ + it('fileio_fstat_async_is_block_device_000', 0, async function (done) { + let fpath = nextFileName('fileio_fstat_async_is_block_device_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let fd = fileio.openSync(fpath); + let stat = await fileio.fstat(fd); + expect(isBoolean(stat.isBlockDevice())).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_fstat_async_is_block_device_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_FstatAsync_IsBlockDevice_0010 + * @tc.name fileio_fstat_async_is_block_device_001 + * @tc.desc Test the isBlockDevice method of class lstat. + */ + it('fileio_fstat_async_is_block_device_001', 0, async function (done) { + let fpath = nextFileName('fileio_fstat_async_is_block_device_001'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let fd = fileio.openSync(fpath); + let stat = await fileio.fstat(fd); + expect(stat.isBlockDevice() === false).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_fstat_async_is_block_device_001 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_FstatAsync_IsCharacterDevice_0000 + * @tc.name fileio_fstat_async_is_character_device_000 + * @tc.desc Test the isCharacterDevice method of class lstat. + */ + it('fileio_fstat_async_is_character_device_000', 0, async function (done) { + let fpath = nextFileName('fileio_fstat_async_is_character_device_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let fd = fileio.openSync(fpath); + let stat = await fileio.fstat(fd); + expect(isBoolean(stat.isCharacterDevice())).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_fstat_async_is_character_device_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_FstatAsync_IsCharacterDevice_0010 + * @tc.name fileio_fstat_async_is_character_device_001 + * @tc.desc Test the isCharacterDevice method of class lstat. + */ + it('fileio_fstat_async_is_character_device_001', 0, async function (done) { + let fpath = nextFileName('fileio_fstat_async_is_character_device_001'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let fd = fileio.openSync(fpath); + let stat = await fileio.fstat(fd); + expect(stat.isCharacterDevice() === false).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_fstat_async_is_character_device_001 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_FstatAsync_IsDirectory_0000 + * @tc.name fileio_fstat_async_is_directory_000 + * @tc.desc Test lstat.isDirectory() interface. + */ + it('fileio_fstat_async_is_directory_000', 0, async function (done) { + let fpath = nextFileName('fileio_fstat_async_is_directory_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let fd = fileio.openSync(fpath); + let stat = await fileio.fstat(fd); + expect(isBoolean(stat.isDirectory())).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_fstat_async_is_directory_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_FstatAsync_IsDirectory_0010 + * @tc.name fileio_fstat_async_is_directory_001 + * @tc.desc Test lstat.isDirectory() interface. + */ + it('fileio_fstat_async_is_directory_001', 0, async function (done) { + let fpath = nextFileName('fileio_fstat_async_is_directory_001'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let fd = fileio.openSync(fpath); + let stat = await fileio.fstat(fd); + expect(stat.isDirectory() === false).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_fstat_async_is_directory_001 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_FstatAsync_IsDirectory_0020 + * @tc.name fileio_fstat_async_is_directory_002 + * @tc.desc Test lstat.isDirectory() interface. + */ + it('fileio_fstat_async_is_directory_002', 0, async function (done) { + let dpath = nextFileName('fileio_fstat_async_is_directory_002') + 'da'; + + try { + expect(fileio.mkdirSync(dpath) == null).assertTrue(); + let fd = fileio.openSync(dpath); + let stat = await fileio.fstat(fd); + expect(stat.isDirectory()).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.rmdirSync(dpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_fstat_async_is_directory_002 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_FstatAsync_IsFIFO_0000 + * @tc.name fileio_fstat_async_is_fifo_000 + * @tc.desc Test lstat.isFIFO() interface. + */ + it('fileio_fstat_async_is_fifo_000', 0, async function (done) { + let fpath = nextFileName('fileio_fstat_async_is_fifo_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let fd = fileio.openSync(fpath); + let stat = await fileio.fstat(fd); + expect(isBoolean(stat.isFIFO())).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_fstat_async_is_fifo_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_FstatAsync_IsFIFO_0010 + * @tc.name fileio_fstat_async_is_fifo_001 + * @tc.desc Test lstat.isFIFO() interface. + */ + it('fileio_fstat_async_is_fifo_001', 0, async function (done) { + let fpath = nextFileName('fileio_fstat_async_is_fifo_001'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let fd = fileio.openSync(fpath); + let stat = await fileio.fstat(fd); + expect(stat.isFIFO() === false).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_fstat_async_is_fifo_001 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_FstatAsync_IsFILE_0000 + * @tc.name fileio_fstat_async_is_file_000 + * @tc.desc Test lstat.isFile() interface. + */ + it('fileio_fstat_async_is_file_000', 0, async function (done) { + let fpath = nextFileName('fileio_fstat_async_is_file_000'); + expect(isBoolean(prepareFile(fpath, FILE_CONTENT))).assertTrue(); + + try { + let fd = fileio.openSync(fpath); + let stat = await fileio.fstat(fd); + expect(isBoolean(stat.isFile())).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_fstat_async_is_file_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_FstatAsync_IsFILE_0010 + * @tc.name fileio_fstat_async_is_file_001 + * @tc.desc Test lstat.isFile() interface. + */ + it('fileio_fstat_async_is_file_001', 0, async function (done) { + let fpath = nextFileName('fileio_fstat_async_is_file_001'); + expect(isBoolean(prepareFile(fpath, FILE_CONTENT))).assertTrue(); + + try { + let fd = fileio.openSync(fpath); + let stat = await fileio.fstat(fd); + expect(stat.isFile()).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_fstat_async_is_file_001 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_FstatAsync_IsFILE_0020 + * @tc.name fileio_fstat_async_is_file_002 + * @tc.desc Test lstat.isFile() interface. + */ + it('fileio_fstat_async_is_file_002', 0, async function (done) { + let dpath = nextFileName('fileio_fstat_async_is_file_002'); + + try { + expect(fileio.mkdirSync(dpath) == null).assertTrue(); + let fd = fileio.openSync(dpath); + let stat = await fileio.fstat(fd); + expect(stat.isFile() === false).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.rmdirSync(dpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_fstat_async_is_file_002 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_FstatAsync_IsSocket_0000 + * @tc.name fileio_fstat_async_is_socket_000 + * @tc.desc Test lstat.isSocket() interface. + */ + it('fileio_fstat_async_is_socket_000', 0, async function (done) { + let fpath = nextFileName('fileio_fstat_async_is_socket_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let fd = fileio.openSync(fpath); + let stat = await fileio.fstat(fd); + expect(isBoolean(stat.isSocket())).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_fstat_async_is_socket_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_FstatAsync_IsSocket_0010 + * @tc.name fileio_fstat_async_is_socket_001 + * @tc.desc Test lstat.isSocket() interface. + */ + it('fileio_fstat_async_is_socket_001', 0, async function (done) { + let fpath = nextFileName('fileio_fstat_async_is_socket_001'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let fd = fileio.openSync(fpath); + let stat = await fileio.fstat(fd); + expect(stat.isSocket() === false).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_fstat_async_is_socket_001 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_FstatAsync_IsSymbolicLink_0000 + * @tc.name fileio_fstat_async_is_symbolic_link_000 + * @tc.desc Test fstat.isSymbolicLink() interface. + */ + it('fileio_fstat_async_is_symbolic_link_000', 0, async function (done) { + let fpath = nextFileName('fileio_fstat_async_is_symbolic_link_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + let fd = fileio.openSync(fpath); + let stat = await fileio.fstat(fd); + expect(isBoolean(stat.isSymbolicLink())).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_fstat_async_is_symbolic_link_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_FstatAsync_IsSymbolicLink_0010 + * @tc.name fileio_fstat_async_is_symbolic_link_001 + * @tc.desc Test lstat.isSymbolicLink() interface. + */ + it('fileio_fstat_async_is_symbolic_link_001', 0, async function (done) { + let fpath = nextFileName('fileio_fstat_async_is_symbolic_link_001'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let fd = fileio.openSync(fpath); + let stat = await fileio.fstat(fd); + expect(stat.isSymbolicLink() === false).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_fstat_async_is_symbolic_link_001 has failed for ' + e); + expect(null).assertFail(); + } + }); + + it('fileio_test_append_file_sync_000', 0, function (done) { + let fpath = nextFileName('fileio_test_append_file_sync_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let fd = fileio.openSync(fpath, 0o2002); + let stat = fileio.fstatSync(fd); + expect(isIntNum(stat.size)).assertTrue(); + expect(isIntNum(fd)).assertTrue(); + expect(fileio.writeSync(fd, FILE_CONTENT) == FILE_CONTENT.length).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + + let fd2 = fileio.openSync(fpath, 0o2002); + stat = fileio.fstatSync(fd2); + expect(stat.size == FILE_CONTENT.length * 2).assertTrue(); + expect(fileio.closeSync(fd2) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_test_append_file_sync_000 has failed for ' + e); + expect(null).assertFail(); + } + done(); + }); + +}); \ No newline at end of file diff --git a/storage/storagefileiojstest/src/main/js/default/test/module_fileio/members/fsync.test.js b/storage/storagefileiojstest/src/main/js/default/test/module_fileio/members/fsync.test.js new file mode 100644 index 0000000000000000000000000000000000000000..43c945d294df82c32fd338060e18cd7227b4501a --- /dev/null +++ b/storage/storagefileiojstest/src/main/js/default/test/module_fileio/members/fsync.test.js @@ -0,0 +1,114 @@ +/* + * 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 diff --git a/storage/storagefileiojstest/src/main/js/default/test/module_fileio/members/ftruncate.test.js b/storage/storagefileiojstest/src/main/js/default/test/module_fileio/members/ftruncate.test.js new file mode 100644 index 0000000000000000000000000000000000000000..919ddee14fe87d783067f96dc8cf03717077ebca --- /dev/null +++ b/storage/storagefileiojstest/src/main/js/default/test/module_fileio/members/ftruncate.test.js @@ -0,0 +1,159 @@ +/* + * 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 diff --git a/storage/storagefileiojstest/src/main/js/default/test/module_fileio/members/hash.test.js b/storage/storagefileiojstest/src/main/js/default/test/module_fileio/members/hash.test.js new file mode 100644 index 0000000000000000000000000000000000000000..8f9c91cd15472cbb143d2c8116c1e37b9b7abca0 --- /dev/null +++ b/storage/storagefileiojstest/src/main/js/default/test/module_fileio/members/hash.test.js @@ -0,0 +1,43 @@ +/* + * 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 diff --git a/storage/storagefileiojstest/src/main/js/default/test/module_fileio/members/lchown.test.js b/storage/storagefileiojstest/src/main/js/default/test/module_fileio/members/lchown.test.js new file mode 100644 index 0000000000000000000000000000000000000000..4af9fa12b125b9aac23ee730afdbc862225ff99c --- /dev/null +++ b/storage/storagefileiojstest/src/main/js/default/test/module_fileio/members/lchown.test.js @@ -0,0 +1,100 @@ +/* + * 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(); + } + }); + +}); diff --git a/storage/storagefileiojstest/src/main/js/default/test/module_fileio/members/lseek.test.js b/storage/storagefileiojstest/src/main/js/default/test/module_fileio/members/lseek.test.js new file mode 100644 index 0000000000000000000000000000000000000000..4dee1d6506926f19dbc1b22d36adcc8594f30e06 --- /dev/null +++ b/storage/storagefileiojstest/src/main/js/default/test/module_fileio/members/lseek.test.js @@ -0,0 +1,107 @@ +/* + * 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(); + } + }); +}); diff --git a/storage/storagefileiojstest/src/main/js/default/test/module_fileio/members/lstat.test.js b/storage/storagefileiojstest/src/main/js/default/test/module_fileio/members/lstat.test.js new file mode 100644 index 0000000000000000000000000000000000000000..e0c2583020d5e2ddb87a7b17a9f1b65e2a454062 --- /dev/null +++ b/storage/storagefileiojstest/src/main/js/default/test/module_fileio/members/lstat.test.js @@ -0,0 +1,1381 @@ +/* + * 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, isBoolean, + describe, beforeAll, beforeEach, afterEach, afterAll, it, expect, +} from '../../Common'; + +describe('fileio_lstat', function () { + + /** + * @tc.number SUB_DF_FileIO_lstatSync_0000 + * @tc.name fileio_lstat_sync_000 + * @tc.desc Test Lstat.lstatSync() interface. + * This interface shall work properly in normal case. + */ + it('fileio_lstat_sync_000', 0, function () { + let fpath = nextFileName('fileio_lstat_sync_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = fileio.lstatSync(fpath); + expect(stat !== null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_lstat_sync_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_lstatSync_0010 + * @tc.name fileio_lstat_sync_001 + * @tc.desc Test Lstat.lstatSync() interface. + * This interface shall throw an exception when the file isnt's exist. + */ + it('fileio_lstat_sync_001', 0, function () { + let fpath = nextFileName('fileio_lstat_sync_001'); + + try { + fileio.lstatSync(fpath); + expect(null).assertFail(); + } catch (e) { + } + }); + + /** + * @tc.number SUB_DF_FileIO_Lstat_Dev_0000 + * @tc.name fileio_lstat_dev_000 + * @tc.desc Test the dev member of class Lstat. + */ + it('fileio_lstat_dev_000', 0, function () { + let fpath = nextFileName('fileio_lstat_dev_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = fileio.lstatSync(fpath); + expect(isIntNum(stat.dev)).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_lstat_dev_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_lstat_Ino_0000 + * @tc.name fileio_lstat_ino_000 + * @tc.desc Test the ino member of class Lstat + */ + it('fileio_lstat_ino_000', 0, function () { + let fpath = nextFileName('fileio_lstat_ino_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + let stat = fileio.lstatSync(fpath); + expect(isIntNum(stat.ino)).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_lstat_ino_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_Lstat_Mode_0000 + * @tc.name fileio_lstat_mode_000 + * @tc.desc Test the mode member of class Lstat + */ + it('fileio_lstat_mode_000', 0, function () { + let fpath = nextFileName('fileio_lstat_mode_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = fileio.lstatSync(fpath); + expect(isIntNum(stat.mode)).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_lstat_mode_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_Lstat_Nlink_0000 + * @tc.name fileio_lstat_nlink_000 + * @tc.desc Test the nlink member of class Lstat + */ + it('fileio_lstat_nlink_000', 0, function () { + let fpath = nextFileName('fileio_lstat_nlink_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = fileio.lstatSync(fpath); + expect(isIntNum(stat.nlink)).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_lstat_nlink_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_Lstat_Uid_0000 + * @tc.name fileio_lstat_uid_000 + * @tc.desc Test the uid member of class Lstat + */ + it('fileio_lstat_uid_000', 0, function () { + let fpath = nextFileName('fileio_lstat_uid_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = fileio.lstatSync(fpath); + expect(isIntNum(stat.uid)).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_lstat_uid_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_Lstat_Gid_0000 + * @tc.name fileio_lstat_gid_000 + * @tc.desc Test the gid member of class Lstat + */ + it('fileio_lstat_gid_000', 0, function () { + let fpath = nextFileName('fileio_lstat_gid_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = fileio.lstatSync(fpath); + expect(isIntNum(stat.gid)).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_lstat_gid_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_Lstat_Rdev_0000 + * @tc.name fileio_lstat_rdev_000 + * @tc.desc Test the rdev member of class Lstat + */ + it('fileio_lstat_rdev_000', 0, function () { + let fpath = nextFileName('fileio_lstat_rdev_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = fileio.lstatSync(fpath); + expect(isIntNum(stat.rdev)).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_lstat_rdev_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_Lstat_Size_0000 + * @tc.name fileio_lstat_size_000 + * @tc.desc Test the size member of class Lstat + */ + it('fileio_lstat_size_000', 0, function () { + let fpath = nextFileName('fileio_lstat_size_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = fileio.lstatSync(fpath); + expect(isIntNum(stat.size)).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_lstat_size_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_Lstat_Blocks_0000 + * @tc.name fileio_lstat_blocks_000 + * @tc.desc Test the blocks member of class Lstat + */ + it('fileio_lstat_blocks_000', 0, function () { + let fpath = nextFileName('fileio_lstat_blocks_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = fileio.lstatSync(fpath); + expect(isIntNum(stat.blocks)).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_lstat_blocks_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_Lstat_Atime_0000 + * @tc.name fileio_lstat_atime_000 + * @tc.desc Test the atime member of class Lstat + */ + it('fileio_lstat_atime_000', 0, function () { + let fpath = nextFileName('fileio_lstat_atime_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = fileio.lstatSync(fpath); + expect(isIntNum(stat.atime)).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_lstat_atime_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_Lstat_Mtime_0000 + * @tc.name fileio_lstat_mtime_000 + * @tc.desc Test the mtime member of class Lstat + */ + it('fileio_lstat_mtime_000', 0, function () { + let fpath = nextFileName('fileio_lstat_mtime_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = fileio.lstatSync(fpath); + expect(isIntNum(stat.mtime)).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_lstat_mtime_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_Lstat_Ctime_0000 + * @tc.name fileio_lstat_ctime_000 + * @tc.desc Test the ctime member of class Lstat + */ + it('fileio_lstat_ctime_000', 0, function () { + let fpath = nextFileName('fileio_lstat_ctime_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = fileio.lstatSync(fpath); + expect(isIntNum(stat.ctime)).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_lstat_ctime_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_Lstat_IsBlockDevice_0000 + * @tc.name fileio_lstat_is_block_device_000 + * @tc.desc Test the isBlockDevice() method of class Lstat. + * This interface shall return a boolean variable. + */ + it('fileio_lstat_is_block_device_000', 0, function () { + let fpath = nextFileName('fileio_lstat_is_block_device_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = fileio.lstatSync(fpath); + expect(isBoolean(stat.isBlockDevice())).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_lstat_is_block_device_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_Lstat_IsBlockDevice_0010 + * @tc.name fileio_lstat_is_block_device_001 + * @tc.desc Test the isBlockDevice() method of class Lstat. + * This interface shall not treat a normal file as a block special device. + */ + it('fileio_lstat_is_block_device_001', 0, function () { + let fpath = nextFileName('fileio_lstat_is_block_device_001'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = fileio.lstatSync(fpath); + expect(stat.isBlockDevice() === false).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_lstat_is_block_device_001 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_Lstat_IsBlockDevice_0020 + * @tc.name fileio_test_lstat_is_block_device_002 + * @tc.desc Test Lstat.isBlockDevice() interface. + */ + it('fileio_test_lstat_is_block_device_002', 0, function () { + let fpath = nextFileName('fileio_test_lstat_is_block_device_002'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = fileio.lstatSync(fpath); + expect(stat.isBlockDevice(-1) === false).assertTrue(); + expect(null).assertFail(); + } catch (e) { + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_Lstat_IsCharacterDevice_0000 + * @tc.name fileio_lstat_is_character_device_000 + * @tc.desc Test Lstat.isCharacterDevice() interface. + * This interface shall return a boolean variable. + */ + it('fileio_lstat_is_character_device_000', 0, function () { + let fpath = nextFileName('fileio_lstat_is_character_device_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = fileio.lstatSync(fpath); + expect(isBoolean(stat.isCharacterDevice())).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_lstat_is_character_device_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_Lstat_IsCharacterDevice_0010 + * @tc.name fileio_lstat_is_character_device_001 + * @tc.desc Test Lstat.isCharacterDevice() interface. + * This interface shall not treat a normal file as a character special device. + */ + it('fileio_lstat_is_character_device_001', 0, function () { + let fpath = nextFileName('fileio_lstat_is_character_device_001'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = fileio.lstatSync(fpath); + expect(stat.isCharacterDevice() === false).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_lstat_is_character_device_001 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_Lstat_IsCharacterDevice_0020 + * @tc.name fileio_test_lstat_is_character_device_002 + * @tc.desc Test Lstat.isCharacterDevice() interface. + */ + it('fileio_test_lstat_is_character_device_002', 0, function () { + let fpath = nextFileName('fileio_test_lstat_is_character_device_002'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = fileio.lstatSync(fpath); + expect(stat.isCharacterDevice(-1) === false).assertTrue(); + expect(null).assertFail(); + } catch (e) { + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_Lstat_IsDirectory_0000 + * @tc.name fileio_lstat_is_directory_000 + * @tc.desc Test Lstat.isDirectory() interface. + * This interface shall return a boolean variable. + */ + it('fileio_lstat_is_directory_000', 0, function () { + let fpath = nextFileName('fileio_lstat_is_directory_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = fileio.lstatSync(fpath); + expect(isBoolean(stat.isDirectory())).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_lstat_is_directory_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_Lstat_IsDirectory_0010 + * @tc.name fileio_lstat_is_directory_001 + * @tc.desc Test Lstat.isDirectory() interface. + * This interface shall not treat a normal file as a directory. + */ + it('fileio_lstat_is_directory_001', 0, function () { + let fpath = nextFileName('fileio_lstat_is_directory_001'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = fileio.lstatSync(fpath); + expect(stat.isDirectory() === false).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_lstat_is_directory_001 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_Lstat_IsDirectory_0020 + * @tc.name fileio_lstat_is_directory_002 + * @tc.desc Test Lstat.isDirectory() interface. + * This interface shall not treat a normal file as a directory. + */ + it('fileio_lstat_is_directory_002', 0, function () { + let dpath = nextFileName('fileio_lstat_is_directory_002') + 'd'; + + try { + expect(fileio.mkdirSync(dpath) == null).assertTrue(); + let stat = fileio.lstatSync(dpath); + expect(stat.isDirectory()).assertTrue(); + expect(fileio.rmdirSync(dpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_lstat_is_directory_002 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_Lstat_IsDirectory_0030 + * @tc.name fileio_lstat_is_directory_003 + * @tc.desc Test Lstat.isDirectory() interface. + */ + it('fileio_lstat_is_directory_003', 0, function () { + let dpath = nextFileName('fileio_lstat_is_directory_003') + 'd'; + + try { + expect(fileio.mkdirSync(dpath) == null).assertTrue(); + let stat = fileio.lstatSync(dpath); + expect(stat.isDirectory(-1)).assertTrue(); + expect(null).assertFail(); + } catch (e) { + expect(fileio.rmdirSync(dpath) == null).assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_Lstat_IsFIFO_0000 + * @tc.name fileio_lstat_is_fifo_000 + * @tc.desc Test Lstat.isFIFO() interface. + * This interface shall return a boolean variable. + */ + it('fileio_lstat_is_fifo_000', 0, function () { + let fpath = nextFileName('fileio_lstat_is_fifo_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = fileio.lstatSync(fpath); + expect(isBoolean(stat.isFIFO())).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_lstat_is_fifo_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_Lstat_IsFIFO_0010 + * @tc.name fileio_lstat_is_fifo_001 + * @tc.desc Test Lstat.isFIFO() interface. + * This interface shall not treat a normal file as a FIFO. + */ + it('fileio_lstat_is_fifo_001', 0, function () { + let fpath = nextFileName('fileio_lstat_is_fifo_001'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = fileio.lstatSync(fpath); + expect(stat.isFIFO() === false).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_lstat_is_fifo_001 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_Lstat_IsFIFO_0020 + * @tc.name fileio_test_stat_is_fifo_002 + * @tc.desc Test Lstat.isFIFO() interface. + */ + it('fileio_test_lstat_is_fifo_002', 0, function () { + let fpath = nextFileName('fileio_test_lstat_is_fifo_002'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = fileio.lstatSync(fpath); + expect(stat.isFIFO(-1) === false).assertTrue(); + expect(null).assertFail(); + } catch (e) { + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_Lstat_IsFILE_0000 + * @tc.name fileio_lstat_is_file_000 + * @tc.desc Test Lstat.isFile() interface. + * This interface shall return a boolean variable. + */ + it('fileio_lstat_is_file_000', 0, function () { + let fpath = nextFileName('fileio_lstat_is_file_000'); + expect(isBoolean(prepareFile(fpath, FILE_CONTENT))).assertTrue(); + + try { + let stat = fileio.lstatSync(fpath); + expect(isBoolean(stat.isFile())).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_lstat_is_file_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_Lstat_IsFILE_0010 + * @tc.name fileio_lstat_is_file_001 + * @tc.desc Test Lstat.isFile() interface. + * This interface shall treat a normal file as a normal file. + */ + it('fileio_lstat_is_file_001', 0, function () { + let fpath = nextFileName('fileio_lstat_is_file_001'); + expect(isBoolean(prepareFile(fpath, FILE_CONTENT))).assertTrue(); + + try { + let stat = fileio.lstatSync(fpath); + expect(stat.isFile()).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_lstat_is_file_001 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_Lstat_IsFILE_0020 + * @tc.name fileio_lstat_is_file_002 + * @tc.desc Test Lstat.isFile() interface. + * This interface shall not treat a directory as a normal file. + */ + it('fileio_lstat_is_file_002', 0, function () { + let dpath = nextFileName('fileio_lstat_is_file_002'); + + try { + expect(fileio.mkdirSync(dpath) == null).assertTrue(); + let stat = fileio.lstatSync(dpath); + expect(stat.isFile() === false).assertTrue(); + expect(fileio.rmdirSync(dpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_lstat_is_file_002 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_Lstat_IsFILE_0030 + * @tc.name fileio_test_lstat_is_file_003 + * @tc.desc Test Lstat.isFile() interface. + */ + it('fileio_test_lstat_is_file_003', 0, function () { + let dpath = nextFileName('fileio_test_lstat_is_file_003'); + + try { + expect(fileio.mkdirSync(dpath) == null).assertTrue(); + let stat = fileio.lstatSync(dpath); + expect(stat.isFile(-1) === false).assertTrue(); + expect(null).assertFail(); + } catch (e) { + expect(fileio.rmdirSync(dpath) == null).assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_Lstat_IsSocket_0000 + * @tc.name fileio_lstat_is_socket_000 + * @tc.desc Test Lstat.isSocket() interface. + * This interface shall return a boolean variable. + */ + it('fileio_lstat_is_socket_000', 0, function () { + let fpath = nextFileName('fileio_lstat_is_socket_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = fileio.lstatSync(fpath); + expect(isBoolean(stat.isSocket())).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_lstat_is_socket_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_Lstat_IsSocket_0010 + * @tc.name fileio_lstat_is_socket_001 + * @tc.desc Test Lstat.isSocket() interface. + * This interface shall not treat a file as a socket. + */ + it('fileio_lstat_is_socket_001', 0, function () { + let fpath = nextFileName('fileio_lstat_is_socket_001'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = fileio.lstatSync(fpath); + expect(stat.isSocket() === false).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_lstat_is_socket_001 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_Lstat_IsSocket_0020 + * @tc.name fileio_test_lstat_is_socket_002 + * @tc.desc Test Lstat.isSocket() interface. + */ + it('fileio_test_lstat_is_socket_002', 0, function () { + let fpath = nextFileName('fileio_test_lstat_is_socket_002'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = fileio.lstatSync(fpath); + expect(stat.isSocket(-1) === false).assertTrue(); + expect(null).assertFail(); + } catch (e) { + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_Lstat_IsSymbolicLink_0000 + * @tc.name fileio_lstat_is_symbolic_link_000 + * @tc.desc Test Lstat.isSymbolicLink() interface. + * This interface shall return a boolean variable. + */ + it('fileio_lstat_is_symbolic_link_000', 0, function () { + let fpath = nextFileName('fileio_lstat_is_symbolic_link_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = fileio.lstatSync(fpath); + expect(isBoolean(stat.isSymbolicLink())).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_lstat_is_symbolic_link_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_Lstat_IsSymbolicLink_0010 + * @tc.name fileio_lstat_is_symbolic_link_001 + * @tc.desc Test Lstat.isSymbolicLink() interface. + * This interface shall not treat a normal file as a symbolic link. + */ + it('fileio_lstat_is_symbolic_link_001', 0, function () { + let fpath = nextFileName('fileio_lstat_is_symbolic_link_001'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = fileio.lstatSync(fpath); + expect(stat.isSymbolicLink() === false).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_lstat_is_symbolic_link_001 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_Lstat_IsSymbolicLink_0020 + * @tc.name fileio_test_lstat_is_symbolic_link_002 + * @tc.desc Test Lstat.isSymbolicLink() interface. + */ + it('fileio_test_lstat_is_symbolic_link_002', 0, function () { + let fpath = nextFileName('fileio_test_lstat_is_symbolic_link_002'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = fileio.lstatSync(fpath); + expect(stat.isSymbolicLink(-1) === false).assertTrue(); + expect(null).assertFail(); + } catch (e) { + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_lstatAsync_0000 + * @tc.name fileio_lstat_async_000 + * @tc.desc Test Stat.lstatAsync() interface. + * This interface shall work properly in normal case when providing the promise async model. + */ + it('fileio_lstat_async_000', 0, async function (done) { + let fpath = nextFileName('fileio_lstat_async_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + fileio.lstat(fpath).then((stat) => { + expect(stat !== null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + }); + done(); + } catch (e) { + console.log('fileio_lstat_async_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_lstatAsync_0000 + * @tc.name fileio_lstat_async_001 + * @tc.desc Test Stat.lstatAsync() interface. + * This interface shall work properly in normal case when providing the callback async model. + */ + it('fileio_lstat_async_001', 0, async function (done) { + let fpath = nextFileName('fileio_lstat_async_001'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + fileio.lstat(fpath, function (error) { + expect(!error).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + }); + } catch (e) { + console.log('fileio_lstat_async_001 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_lstatAsync_0020 + * @tc.name fileio_lstat_async_002 + * @tc.desc Test Stat.lstatAsync() interface. + */ + it('fileio_lstat_async_002', 0, async function (done) { + let fpath = nextFileName('fileio_lstat_async_002'); + + try { + fileio.truncate(fpath, truncateLen, function (err) { + done(); + }); + } catch (e) { + console.log('fileio_lstat_async_002 has failed for ' + e); + expect(!!e).assertTrue(); + done(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_LstatAsync_Dev_0000 + * @tc.name fileio_lstat_async_dev_000 + * @tc.desc Test the dev member of class Lstat. + */ + it('fileio_lstat_async_dev_000', 0, async function (done) { + let fpath = nextFileName('fileio_lstat_async_dev_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = await fileio.lstat(fpath); + expect(isIntNum(stat.dev)).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_lstat_async_dev_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_LstatAsync_Ino_0000 + * @tc.name fileio_lstat_async_ino_000 + * @tc.desc Test the ino member of class Lstat. + */ + it('fileio_lstat_async_ino_000', 0, async function (done) { + let fpath = nextFileName('fileio_lstat_async_ino_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = await fileio.lstat(fpath); + expect(isIntNum(stat.ino)).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_lstat_async_ino_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_lstatAsync_Mode_0000 + * @tc.name fileio_lstat_async_mode_000 + * @tc.desc Test the mode member of class Lstat. + */ + it('fileio_lstat_async_mode_000', 0, async function (done) { + let fpath = nextFileName('fileio_lstat_async_mode_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = await fileio.lstat(fpath); + expect(isIntNum(stat.mode)).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_lstat_async_mode_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_lstatAsync_Nlink_0000 + * @tc.name fileio_lstat_async_nlink_000 + * @tc.desc Test the nlink member of class Lstat. + */ + it('fileio_lstat_async_nlink_000', 0, async function (done) { + let fpath = nextFileName('fileio_lstat_async_nlink_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = await fileio.lstat(fpath); + expect(isIntNum(stat.nlink)).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_lstat_async_nlink_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_lstatAsync_Uid_0000 + * @tc.name fileio_lstat_async_uid_000 + * @tc.desc Test the uid member of class Lstat. + */ + it('fileio_lstat_async_uid_000', 0, async function (done) { + let fpath = nextFileName('fileio_lstat_async_uid_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = await fileio.lstat(fpath); + expect(isIntNum(stat.uid)).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_lstat_async_uid_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_lstatAsync_Gid_0000 + * @tc.name fileio_lstat_async_gid_000 + * @tc.desc Test the gid member of class Lstat. + */ + it('fileio_lstat_async_gid_000', 0, async function (done) { + let fpath = nextFileName('fileio_lstat_async_gid_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = await fileio.lstat(fpath); + expect(isIntNum(stat.gid)).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_lstat_async_gid_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_lstatAsync_Rdev_0000 + * @tc.name fileio_lstat_async_rdev_000 + * @tc.desc Test the rdev member of class Lstat. + */ + it('fileio_lstat_async_rdev_000', 0, async function (done) { + let fpath = nextFileName('fileio_lstat_async_rdev_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = await fileio.lstat(fpath); + expect(isIntNum(stat.rdev)).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_lstat_async_rdev_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_lstatAsync_Size_0000 + * @tc.name fileio_lstat_async_size_000 + * @tc.desc Test the size member of class lstat. + */ + it('fileio_lstat_async_size_000', 0, async function (done) { + let fpath = nextFileName('fileio_lstat_async_size_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = await fileio.lstat(fpath); + expect(isIntNum(stat.size)).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_lstat_async_size_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_lstatAsync_Blocks_0000 + * @tc.name fileio_lstat_async_blocks_000 + * @tc.desc Test lstat.blocks() interface. + * @tc.desc Test the blocks member of class lstat. + */ + it('fileio_lstat_async_blocks_000', 0, async function (done) { + let fpath = nextFileName('fileio_lstat_async_blocks_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = await fileio.lstat(fpath); + expect(isIntNum(stat.blocks)).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_lstat_async_blocks_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_lstatAsync_Atime_0000 + * @tc.name fileio_lstat_async_atime_000 + * @tc.desc Test lstat.atime() interface. + * @tc.desc Test the atime member of class lstat. + */ + it('fileio_lstat_async_atime_000', 0, async function (done) { + let fpath = nextFileName('fileio_lstat_async_atime_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = await fileio.lstat(fpath); + expect(isIntNum(stat.atime)).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_lstat_async_atime_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_lstatAsync_Mtime_0000 + * @tc.name fileio_lstat_async_mtime_000 + * @tc.desc Test lstat.mtime() interface. + * @tc.desc Test the mtime member of class lstat. + */ + it('fileio_lstat_async_mtime_000', 0, async function (done) { + let fpath = nextFileName('fileio_lstat_async_mtime_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = await fileio.lstat(fpath); + expect(isIntNum(stat.mtime)).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_lstat_async_mtime_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_lstatAsync_Ctime_0000 + * @tc.name fileio_lstat_async_ctime_000 + * @tc.desc Test the ctime member of class lstat. + */ + it('fileio_lstat_async_ctime_000', 0, async function (done) { + let fpath = nextFileName('fileio_lstat_async_ctime_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = await fileio.lstat(fpath); + expect(isIntNum(stat.ctime)).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_lstat_async_ctime_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_lstatAsync_IsBlockDevice_0000 + * @tc.name fileio_lstat_async_is_block_device_000 + * @tc.desc Test the isBlockDevice method of class lstat. + */ + it('fileio_lstat_async_is_block_device_000', 0, async function (done) { + let fpath = nextFileName('fileio_lstat_async_is_block_device_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = await fileio.lstat(fpath); + expect(isBoolean(stat.isBlockDevice())).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_lstat_async_is_block_device_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_lstatAsync_IsBlockDevice_0010 + * @tc.name fileio_lstat_async_is_block_device_001 + * @tc.desc Test the isBlockDevice method of class lstat. + */ + it('fileio_lstat_async_is_block_device_001', 0, async function (done) { + let fpath = nextFileName('fileio_lstat_async_is_block_device_001'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = await fileio.lstat(fpath); + expect(stat.isBlockDevice() === false).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_lstat_async_is_block_device_001 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_lstatAsync_IsCharacterDevice_0000 + * @tc.name fileio_lstat_async_is_character_device_000 + * @tc.desc Test the isCharacterDevice method of class lstat. + */ + it('fileio_lstat_async_is_character_device_000', 0, async function (done) { + let fpath = nextFileName('fileio_lstat_async_is_character_device_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = await fileio.lstat(fpath); + expect(isBoolean(stat.isCharacterDevice())).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_lstat_async_is_character_device_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_lstatAsync_IsCharacterDevice_0010 + * @tc.name fileio_lstat_async_is_character_device_001 + * @tc.desc Test the isCharacterDevice method of class lstat. + */ + it('fileio_lstat_async_is_character_device_001', 0, async function (done) { + let fpath = nextFileName('fileio_lstat_async_is_character_device_001'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = await fileio.lstat(fpath); + expect(stat.isCharacterDevice() === false).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_lstat_async_is_character_device_001 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_lstatAsync_IsDirectory_0000 + * @tc.name fileio_lstat_async_is_directory_000 + * @tc.desc Test lstat.isDirectory() interface. + */ + it('fileio_lstat_async_is_directory_000', 0, async function (done) { + let fpath = nextFileName('fileio_lstat_async_is_directory_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = await fileio.lstat(fpath); + expect(isBoolean(stat.isDirectory())).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_lstat_async_is_directory_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_lstatAsync_IsDirectory_0010 + * @tc.name fileio_lstat_async_is_directory_001 + * @tc.desc Test lstat.isDirectory() interface. + */ + it('fileio_lstat_async_is_directory_001', 0, async function (done) { + let fpath = nextFileName('fileio_lstat_async_is_directory_001'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = await fileio.lstat(fpath); + expect(stat.isDirectory() === false).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_lstat_async_is_directory_001 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_lstatAsync_IsDirectory_0020 + * @tc.name fileio_lstat_async_is_directory_002 + * @tc.desc Test lstat.isDirectory() interface. + */ + it('fileio_lstat_async_is_directory_002', 0, async function (done) { + let dpath = nextFileName('fileio_lstat_async_is_directory_002') + 'd'; + + try { + expect(fileio.mkdirSync(dpath) == null).assertTrue(); + let stat = await fileio.lstat(dpath); + expect(stat.isDirectory()).assertTrue(); + expect(fileio.rmdirSync(dpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_lstat_async_is_directory_002 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_lstatAsync_IsFIFO_0000 + * @tc.name fileio_lstat_async_is_fifo_000 + * @tc.desc Test lstat.isFIFO() interface. + */ + it('fileio_lstat_async_is_fifo_000', 0, async function (done) { + let fpath = nextFileName('fileio_lstat_async_is_fifo_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = await fileio.lstat(fpath); + expect(isBoolean(stat.isFIFO())).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_lstat_async_is_fifo_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_lstatAsync_IsFIFO_0010 + * @tc.name fileio_lstat_async_is_fifo_001 + * @tc.desc Test lstat.isFIFO() interface. + */ + it('fileio_lstat_async_is_fifo_001', 0, async function (done) { + let fpath = nextFileName('fileio_lstat_async_is_fifo_001'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = await fileio.lstat(fpath); + expect(stat.isFIFO() === false).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_lstat_async_is_fifo_001 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_lstatAsync_IsFILE_0000 + * @tc.name fileio_lstat_async_is_file_000 + * @tc.desc Test lstat.isFile() interface. + */ + it('fileio_lstat_async_is_file_000', 0, async function (done) { + let fpath = nextFileName('fileio_lstat_async_is_file_000'); + expect(isBoolean(prepareFile(fpath, FILE_CONTENT))).assertTrue(); + + try { + let stat = await fileio.lstat(fpath); + expect(isBoolean(stat.isFile())).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_lstat_async_is_file_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_lstatAsync_IsFILE_0010 + * @tc.name fileio_lstat_async_is_file_001 + * @tc.desc Test lstat.isFile() interface. + */ + it('fileio_lstat_async_is_file_001', 0, async function (done) { + let fpath = nextFileName('fileio_lstat_async_is_file_001'); + expect(isBoolean(prepareFile(fpath, FILE_CONTENT))).assertTrue(); + + try { + let stat = await fileio.lstat(fpath); + expect(stat.isFile()).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_lstat_async_is_file_001 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_lstatAsync_IsFILE_0020 + * @tc.name fileio_lstat_async_is_file_002 + * @tc.desc Test lstat.isFile() interface. + */ + it('fileio_lstat_async_is_file_002', 0, async function (done) { + let dpath = nextFileName('fileio_lstat_async_is_file_002'); + + try { + expect(fileio.mkdirSync(dpath) == null).assertTrue(); + let stat = await fileio.lstat(dpath); + expect(stat.isFile() === false).assertTrue(); + expect(fileio.rmdirSync(dpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_lstat_async_is_file_002 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_lstatAsync_IsSocket_0000 + * @tc.name fileio_lstat_async_is_socket_000 + * @tc.desc Test lstat.isSocket() interface. + */ + it('fileio_lstat_async_is_socket_000', 0, async function (done) { + let fpath = nextFileName('fileio_lstat_async_is_socket_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = await fileio.lstat(fpath); + expect(isBoolean(stat.isSocket())).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_lstat_async_is_socket_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_lstatAsync_IsSocket_0010 + * @tc.name fileio_lstat_async_is_socket_001 + * @tc.desc Test lstat.isSocket() interface. + */ + it('fileio_lstat_async_is_socket_001', 0, async function (done) { + let fpath = nextFileName('fileio_lstat_async_is_socket_001'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = await fileio.lstat(fpath); + expect(stat.isSocket() === false).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_lstat_async_is_socket_001 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_lstatAsync_IsSymbolicLink_0000 + * @tc.name fileio_lstat_async_is_symbolic_link_000 + * @tc.desc Test lstat.isSymbolicLink() interface. + */ + it('fileio_lstat_async_is_symbolic_link_000', 0, async function (done) { + let fpath = nextFileName('fileio_lstat_async_is_symbolic_link_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = await fileio.lstat(fpath); + expect(isBoolean(stat.isSymbolicLink())).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_lstat_async_is_symbolic_link_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_lstatAsync_IsSymbolicLink_0010 + * @tc.name fileio_lstat_async_is_symbolic_link_001 + * @tc.desc Test lstat.isSymbolicLink() interface. + */ + it('fileio_lstat_async_is_symbolic_link_001', 0, async function (done) { + let fpath = nextFileName('fileio_lstat_async_is_symbolic_link_001'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = await fileio.lstat(fpath); + expect(stat.isSymbolicLink() === false).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_lstat_async_is_symbolic_link_001 has failed for ' + e); + expect(null).assertFail(); + } + }); + + it('fileio_test_append_file_sync_000', 0, function (done) { + let fpath = nextFileName('fileio_test_append_file_sync_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = fileio.lstatSync(fpath); + expect(isIntNum(stat.size)).assertTrue(); + + let fd = fileio.openSync(fpath, 0o2002); + expect(isIntNum(fd)).assertTrue(); + + expect(fileio.writeSync(fd, FILE_CONTENT) == FILE_CONTENT.length).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + + stat = fileio.lstatSync(fpath); + expect(stat.size == FILE_CONTENT.length * 2).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_test_append_file_sync_000 has failed for ' + e); + expect(null).assertFail(); + } + done(); + }); +}); \ No newline at end of file diff --git a/storage/storagefileiojstest/src/main/js/default/test/module_fileio/members/mkdir_rmdir.test.js b/storage/storagefileiojstest/src/main/js/default/test/module_fileio/members/mkdir_rmdir.test.js new file mode 100644 index 0000000000000000000000000000000000000000..eb6a5cd5d3741de1dc6a09ee4b956dfc5db52ae0 --- /dev/null +++ b/storage/storagefileiojstest/src/main/js/default/test/module_fileio/members/mkdir_rmdir.test.js @@ -0,0 +1,163 @@ +/* + * 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('') > -1).assertTrue(); + expect(null).assertFail(); + } catch (e) { + done(); + } + }); +}); \ No newline at end of file diff --git a/storage/storagefileiojstest/src/main/js/default/test/module_fileio/members/mkdtemp.test.js b/storage/storagefileiojstest/src/main/js/default/test/module_fileio/members/mkdtemp.test.js new file mode 100644 index 0000000000000000000000000000000000000000..b502b078dfba789d2f2a26c5ef88f5641238f14d --- /dev/null +++ b/storage/storagefileiojstest/src/main/js/default/test/module_fileio/members/mkdtemp.test.js @@ -0,0 +1,92 @@ +/* + * 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 diff --git a/storage/storagefileiojstest/src/main/js/default/test/module_fileio/members/open.test.js b/storage/storagefileiojstest/src/main/js/default/test/module_fileio/members/open.test.js new file mode 100644 index 0000000000000000000000000000000000000000..ffdd0ac0ce5c7a494c7c759be1d8e861159ed5cf --- /dev/null +++ b/storage/storagefileiojstest/src/main/js/default/test/module_fileio/members/open.test.js @@ -0,0 +1,221 @@ +/* + * 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(); + } + }); +}); diff --git a/storage/storagefileiojstest/src/main/js/default/test/module_fileio/members/open_close.test.js b/storage/storagefileiojstest/src/main/js/default/test/module_fileio/members/open_close.test.js new file mode 100644 index 0000000000000000000000000000000000000000..d20772241c36a5f058567a2be22d3923736b4dcb --- /dev/null +++ b/storage/storagefileiojstest/src/main/js/default/test/module_fileio/members/open_close.test.js @@ -0,0 +1,115 @@ +/* + * 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_open_close', function () { + + /** + * @tc.number SUB_DF_FileIO_OpenCloseSync_0000 + * @tc.name fileio_open_close_sync_000 + * @tc.desc Test openSync() and closeSync() interfaces. + */ + it('fileio_open_close_sync_000', 0, function () { + let fpath = nextFileName('fileio_open_close_sync_000'); + + try { + let fd = fileio.openSync(fpath, 0o102, 0o666); + expect(isIntNum(fd)).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_open_close_sync_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_OpenCloseSync_0010 + * @tc.name fileio_open_close_sync_001 + * @tc.desc Test openSync() and closeSync() interfaces. + */ + it('fileio_open_close_sync_001', 0, function () { + let fpath = nextFileName('fileio_open_close_sync_001'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let fd = fileio.openSync(fpath); + expect(isIntNum(fd)).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_open_close_sync_001 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_OpenSync_0000 + * @tc.name fileio_open_sync_000 + * @tc.desc Test openSync() interface. + */ + it('fileio_open_sync_000', 0, function () { + try { + fileio.openSync('/', 0o102, 0o666); + expect(null).assertFail(); + } catch (e) { + } + }); + + /** + * @tc.number SUB_DF_FileIO_OpenSync_0010 + * @tc.name fileio_open_sync_001 + * @tc.desc Test openSync() interface. + */ + it('fileio_open_sync_001', 0, function () { + let fpath = nextFileName('fileio_open_sync_001'); + + try { + fileio.openSync(fpath, 0o102); + expect(null).assertFail(); + } catch (e) { + } + }); + + /** + * @tc.number SUB_DF_FileIO_CloseSync_0000 + * @tc.name fileio_close_sync_000 + * @tc.desc Test closeSync() interface. + */ + it('fileio_close_sync_000', 0, function () { + try { + fileio.closeSync(); + expect(null).assertFail(); + } catch (e) { + } + }); + + /** + * @tc.number SUB_DF_FileIO_CloseSync_0010 + * @tc.name fileio_close_sync_001 + * @tc.desc Test closeSync() interface. + */ + it('fileio_close_sync_001', 0, function () { + try { + fileio.closeSync(-1); + expect(null).assertFail(); + } catch (e) { + } + }); +}); \ No newline at end of file diff --git a/storage/storagefileiojstest/src/main/js/default/test/module_fileio/members/opendir_close.test.js b/storage/storagefileiojstest/src/main/js/default/test/module_fileio/members/opendir_close.test.js new file mode 100644 index 0000000000000000000000000000000000000000..ef455f7cbe7a0c15b184f75bdf318dc0df69b351 --- /dev/null +++ b/storage/storagefileiojstest/src/main/js/default/test/module_fileio/members/opendir_close.test.js @@ -0,0 +1,97 @@ +/* + * 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_dir_opendir_close', function () { + + /** + * @tc.number SUB_DF_FileIO_OpenClosedirSync_0000 + * @tc.name fileio_dir_open_close_sync_000 + * @tc.desc Test opendirSync() and Dir.closeSync() interfaces. + */ + it('fileio_dir_open_close_sync_000', 0, function () { + let dpath = nextFileName('fileio_dir_open_close_sync_000') + 'd'; + + try { + expect(fileio.mkdirSync(dpath) == null).assertTrue(); + let dd = fileio.opendirSync(dpath); + expect(dd !== null).assertTrue(); + expect(dd.closeSync() == null).assertTrue(); + expect(fileio.rmdirSync(dpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_dir_open_close_sync_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_OpenClosedirSync_0010 + * @tc.name fileio_dir_open_close_sync_001 + * @tc.desc Test opendirSync() interface. + */ + it('fileio_dir_open_close_sync_001', 0, function () { + let dpath = nextFileName('fileio_dir_open_close_sync_001') + 'd'; + + try { + fileio.opendirSync(dpath); + expect(null).assertFail(); + } catch (e) { + } + }); + + /** + * @tc.number SUB_DF_FileIO_OpenClosedirAsync_0000 + * @tc.name fileio_dir_open_close_async_000 + * @tc.desc Test opendirAsync() and Dir.closeSync() interfaces. + */ + it('fileio_dir_open_close_async_000', 0, async function (done) { + let dpath = nextFileName('fileio_dir_open_close_async_000') + 'd'; + + try { + expect(fileio.mkdirSync(dpath) == null).assertTrue(); + let dd = await fileio.opendir(dpath); + expect(dd !== null).assertTrue(); + expect(dd.closeSync() == null).assertTrue(); + expect(fileio.rmdirSync(dpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_dir_open_close_async_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_OpenClosedirAsync_0010 + * @tc.name fileio_dir_open_close_async_001 + * @tc.desc Test opendirAsync() and Dir.closeSync() interfaces. + */ + it('fileio_dir_open_close_async_001', 0, async function (done) { + let dpath = nextFileName('fileio_dir_open_close_async_001') + 'd'; + + try { + expect(fileio.mkdirSync(dpath) == null).assertTrue(); + fileio.opendir(dpath, function (error, dd) { + expect(dd !== null).assertTrue(); + expect(dd.closeSync() == null).assertTrue(); + expect(fileio.rmdirSync(dpath) == null).assertTrue(); + done(); + }); + } catch (e) { + console.log('fileio_dir_open_close_async_001 has failed for ' + e); + expect(null).assertFail(); + } + }); +}); diff --git a/storage/storagefileiojstest/src/main/js/default/test/module_fileio/members/posix_fallocate.test.js b/storage/storagefileiojstest/src/main/js/default/test/module_fileio/members/posix_fallocate.test.js new file mode 100644 index 0000000000000000000000000000000000000000..3bb5071752febb7c29b46e5ded2078ab07341fb4 --- /dev/null +++ b/storage/storagefileiojstest/src/main/js/default/test/module_fileio/members/posix_fallocate.test.js @@ -0,0 +1,86 @@ +/* + * 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_posix_fallocate', function () { + + /** + * @tc.number SUB_DF_FileIO_PosixFallocateSync_0000 + * @tc.name fileio_test_posix_fallocate_sync_000 + * @tc.desc Test fsyncSync() interface. + */ + it('fileio_test_posix_fallocate_sync_000', 0, function () { + let fpath = nextFileName('fileio_test_posix_fallocate_sync_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + let fd = fileio.openSync(fpath, 0o102, 0o666); + expect(isIntNum(fd)).assertTrue(); + fileio.posixFallocateSync(fd, 100, 999); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_test_posix_fallocate_sync_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_PosixFallocateAsync_0000 + * @tc.name fileio_test_posix_fallocate_async_000 + * @tc.desc Test fsyncASync() interface. + */ + it('fileio_test_posix_fallocate_async_000', 0, async function (done) { + let fpath = nextFileName('fileio_test_posix_fallocate_async_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + let fd = fileio.openSync(fpath, 0o2); + expect(isIntNum(fd)).assertTrue(); + await fileio.posixFallocate(fd, 100, 999, function (err) { + expect(!err).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + }); + } catch (e) { + console.log('fileio_test_posix_fallocate_async_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_PosixFallocateAsync_0010 + * @tc.name fileio_test_posix_fallocate_async_001 + * @tc.desc Test lseekAsync()interfaces. + */ + it('fileio_test_posix_fallocate_async_001', 0, async function (done) { + let fpath = nextFileName('fileio_test_posix_fallocate_async_001'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + let fd = fileio.openSync(fpath, 0o2); + expect(isIntNum(fd)).assertTrue(); + await fileio.posixFallocate(fd, 100, 999); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_test_posix_fallocate_async_001 has failed for ' + e); + expect(null).assertFail(); + } + }); +}); diff --git a/storage/storagefileiojstest/src/main/js/default/test/module_fileio/members/read.test.js b/storage/storagefileiojstest/src/main/js/default/test/module_fileio/members/read.test.js new file mode 100644 index 0000000000000000000000000000000000000000..4e2b49b9968ca06091707619c9fb1d03b0afa844 --- /dev/null +++ b/storage/storagefileiojstest/src/main/js/default/test/module_fileio/members/read.test.js @@ -0,0 +1,478 @@ +/* + * 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_read', function () { + + /** + * @tc.number SUB_DF_FileIO_ReadSync_0000 + * @tc.name fileio_test_read_sync_000 + * @tc.desc Test readSync() interfaces. + */ + it('fileio_test_read_sync_000', 0, function () { + let fpath = nextFileName('fileio_test_read_sync_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let fd = fileio.openSync(fpath, 0o2); + expect(isIntNum(fd)).assertTrue(); + let len = fileio.readSync(fd, new ArrayBuffer(4096)); + expect(len == FILE_CONTENT.length).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_test_read_sync_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_ReadSync_0010 + * @tc.name fileio_test_read_sync_001 + * @tc.desc Test readSync() interfaces. + */ + it('fileio_test_read_sync_001', 0, function () { + let bufLen = 5; + expect(FILE_CONTENT.length > bufLen).assertTrue(); + let fpath = nextFileName('fileio_test_read_sync_001'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let fd = fileio.openSync(fpath, 0o2); + expect(isIntNum(fd)).assertTrue(); + let len = fileio.readSync(fd, new ArrayBuffer(bufLen), { + offset: 1, + }); + expect(len == bufLen - 1).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_test_read_sync_001 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_ReadSync_0020 + * @tc.name fileio_test_read_sync_002 + * @tc.desc Test readSync() interfaces. + */ + it('fileio_test_read_sync_002', 0, function () { + let fpath = nextFileName('fileio_test_read_sync_002'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let fd = fileio.openSync(fpath, 0o2); + expect(isIntNum(fd)).assertTrue(); + let len = fileio.readSync(fd, new ArrayBuffer(4096), { + length: 1, + }); + expect(len == 1).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_test_read_sync_002 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_ReadSync_0030 + * @tc.name fileio_test_read_sync_003 + * @tc.desc Test readSync() interfaces. + */ + it('fileio_test_read_sync_003', 0, function () { + let fpath = nextFileName('fileio_test_read_sync_003'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let fd = fileio.openSync(fpath, 0o2); + expect(isIntNum(fd)).assertTrue(); + let len = fileio.readSync(fd, new ArrayBuffer(4096), { + position: 1, + }); + expect(len == FILE_CONTENT.length - 1).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_test_read_sync_003 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_ReadSync_0040 + * @tc.name fileio_test_read_sync_004 + * @tc.desc Test readSync() interfaces. + */ + it('fileio_test_read_sync_004', 0, function () { + let fd; + const invalidOffset = 99999; + let fpath = nextFileName('fileio_test_read_sync_004'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + fd = fileio.openSync(fpath, 0o2); + expect(isIntNum(fd)).assertTrue(); + fileio.readSync(fd, new ArrayBuffer(4096), { + offset: invalidOffset, + }); + expect(null).assertFail(); + } catch (e) { + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_ReadSync_0050 + * @tc.name fileio_test_read_sync_005 + * @tc.desc Test readSync() interfaces. + */ + it('fileio_test_read_sync_005', 0, function () { + let fd; + const invalidLength = 9999; + let fpath = nextFileName('fileio_test_read_sync_005'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + fd = fileio.openSync(fpath, 0o2); + expect(isIntNum(fd)).assertTrue(); + fileio.readSync(fd, new ArrayBuffer(4096), { + length: invalidLength, + }); + expect(null).assertFail(); + } catch (e) { + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_ReadSync_0060 + * @tc.name fileio_test_read_sync_006 + * @tc.desc Test readSync() interfaces. + */ + it('fileio_test_read_sync_006', 0, function () { + let fpath = nextFileName('fileio_test_read_sync_006'); + let fd; + + try { + fileio.readSync(-1, new ArrayBuffer(4096)); + expect(null).assertFail(); + } catch (e) { + } + }); + + /** + * @tc.number SUB_DF_FileIO_ReadSync_0070 + * @tc.name fileio_test_read_sync_007 + * @tc.desc Test readSync() interfaces. + */ + it('fileio_test_read_sync_007', 0, function () { + let fpath = nextFileName('fileio_test_read_sync_007'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let fd = fileio.openSync(fpath, 0o2); + expect(isIntNum(fd)).assertTrue(); + let len = fileio.readSync(fd, new ArrayBuffer(4096), { + position: 1, + }); + expect(len == FILE_CONTENT.length - 1).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_test_read_sync_007 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_ReadSync_0080 + * @tc.name fileio_test_read_sync_008 + * @tc.desc Test readSync() interfaces. + */ + it('fileio_test_read_sync_008', 0, function () { + let fpath = nextFileName('fileio_test_read_sync_008'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let fd = fileio.openSync(fpath, 0o2); + expect(isIntNum(fd)).assertTrue(); + let invalidPos = FILE_CONTENT.length + 1; + let len = fileio.readSync(fd, new ArrayBuffer(4096), { + position: invalidPos, + }); + expect(len == 0).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_test_read_sync_008 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_ReadAsync_0000 + * @tc.name fileio_test_read_async_000 + * @tc.desc Test readAsync() interfaces. + */ + it('fileio_test_read_async_000', 0, async function (done) { + let fpath = nextFileName('fileio_test_read_async_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let fd = fileio.openSync(fpath, 0o2); + expect(isIntNum(fd)).assertTrue(); + let res = await fileio.read(fd, new ArrayBuffer(4096)); + expect(res.bytesRead == FILE_CONTENT.length).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_test_read_async_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_ReadAsync_0010 + * @tc.name fileio_test_read_async_001 + * @tc.desc Test readAsync() interfaces. + */ + it('fileio_test_read_async_001', 0, async function (done) { + let fpath = nextFileName('fileio_test_read_async_001'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let fd = fileio.openSync(fpath, 0o2); + expect(isIntNum(fd)).assertTrue(); + fileio.read(fd, new ArrayBuffer(4096), function (err, data) { + expect(!err).assertTrue(); + expect(data.bytesRead == FILE_CONTENT.length).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + }); + } catch (e) { + console.log('fileio_test_read_async_001 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_ReadAsync_0020 + * @tc.name fileio_test_read_async_002 + * @tc.desc Test readAsync() interfaces. + */ + it('fileio_test_read_async_002', 0, async function (done) { + let fpath = nextFileName('fileio_test_read_async_002'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let fd = fileio.openSync(fpath); + expect(isIntNum(fd)).assertTrue(); + let readout = await fileio.read(fd, new ArrayBuffer(4096)); + expect(readout.buffer.byteLength == 4096).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_test_read_async_002 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_ReadAsync_0030 + * @tc.name fileio_test_read_async_003 + * @tc.desc Test readAsync() interfaces. + */ + it('fileio_test_read_async_003', 0, async function (done) { + let fpath = nextFileName('fileio_test_read_async_003'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let fd = fileio.openSync(fpath); + expect(isIntNum(fd)).assertTrue(); + let readout = await fileio.read(fd, new ArrayBuffer(4096), { + offset: 1, + }); + expect(readout.bytesRead == FILE_CONTENT.length).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_test_read_async_003 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_ReadAsync_0040 + * @tc.name fileio_test_read_async_004 + * @tc.desc Test readAsync() interface. + */ + it('fileio_test_read_async_004', 0, async function (done) { + let fpath = nextFileName('fileio_test_read_async_004'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let fd = fileio.openSync(fpath); + expect(isIntNum(fd)).assertTrue(); + let readout = await fileio.read(fd, new ArrayBuffer(4096), { + offset: 1, + length: 3, + }); + expect(readout.bytesRead == 3).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_test_read_async_004 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_ReadAsync_0050 + * @tc.name fileio_test_read_async_005 + * @tc.desc Test readAsync() interfaces. + */ + it('fileio_test_read_async_005', 0, async function (done) { + let fpath = nextFileName('fileio_test_read_async_005'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let fd = fileio.openSync(fpath); + expect(isIntNum(fd)).assertTrue(); + let readout = await fileio.read(fd, new ArrayBuffer(5), { + offset: 1, + }); + expect(readout.bytesRead == 4).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_test_read_async_005 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_ReadAsync_0060 + * @tc.name fileio_test_read_async_006 + * @tc.desc Test readAsync() interfaces. + */ + it('fileio_test_read_async_006', 0, async function (done) { + let fd; + const invalidOffset = 99999; + let fpath = nextFileName('fileio_test_read_async_006'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + fd = fileio.openSync(fpath, 0o2); + expect(isIntNum(fd)).assertTrue(); + await fileio.read(fd, new ArrayBuffer(4096), { + offset: invalidOffset, + }); + expect(null).assertFail(); + } catch (e) { + } + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + }); + + /** + * @tc.number SUB_DF_FileIO_ReadAsync_0070 + * @tc.name fileio_test_read_async_007 + * @tc.desc Test readAsync() interfaces. + */ + it('fileio_test_read_async_007', 0, async function (done) { + let fpath = nextFileName('fileio_test_read_async_007'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + let fd; + + try { + fd = fileio.openSync(fpath, 0o2); + expect(isIntNum(fd)).assertTrue(); + let invalidPos = FILE_CONTENT.length + 1; + let err = await fileio.read(fd, new ArrayBuffer(4096), { + offset: 1, + position: invalidPos, + }); + expect(!!err).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_test_read_async_007 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_ReadAsync_0080 + * @tc.name fileio_test_read_async_008 + * @tc.desc Test readAsync() interfaces. + */ + it('fileio_test_read_async_008', 0, async function (done) { + let fpath = nextFileName('fileio_test_read_async_008'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let err = await fileio.read(-1, new ArrayBuffer(4096)); + expect(!!err).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + expect(null).assertFail(); + done(); + } catch (e) { + console.log('fileio_test_read_async_008 has failed for ' + e); + expect(!!e).assertTrue(); + done(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_ReadAsync_Readout_offset_0000 + * @tc.name fileio_test_read_async_readout_offset_000 + * @tc.desc Test readAsync() ReadOut.offset interfaces. + */ + it('fileio_test_read_async_readout_offset_000', 0, async function (done) { + let fpath = nextFileName('fileio_test_read_async_readout_offset_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let fd = fileio.openSync(fpath); + expect(isIntNum(fd)).assertTrue(); + let readout = await fileio.read(fd, new ArrayBuffer(4096), { + offset: 1, + }); + expect(readout.offset == 1).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_test_read_async_readout_offset_000 has failed for ' + e); + expect(null).assertFail(); + } + }); +}); diff --git a/storage/storagefileiojstest/src/main/js/default/test/module_fileio/members/readtext.test.js b/storage/storagefileiojstest/src/main/js/default/test/module_fileio/members/readtext.test.js new file mode 100644 index 0000000000000000000000000000000000000000..ad2a0aba04f35f5c3cc7f14ea99d6e473f7654fb --- /dev/null +++ b/storage/storagefileiojstest/src/main/js/default/test/module_fileio/members/readtext.test.js @@ -0,0 +1,207 @@ +/* + * 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_readtext', function () { + + /** + * @tc.number SUB_DF_FileIO_ReadtextSync_0000 + * @tc.name fileio_test_readtext_sync_000 + * @tc.desc Test readtextSync() interfaces. + */ + it('fileio_test_readtext_sync_000', 0, function () { + let fpath = nextFileName('fileio_test_readtext_sync_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + let str = fileio.readTextSync(fpath); + expect(str == FILE_CONTENT).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_test_readtext_sync_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_ReadtextSync_0010 + * @tc.name fileio_test_readtext_sync_001 + * @tc.desc Test readtextSync() interfaces. + */ + it('fileio_test_readtext_sync_001', 0, function () { + let fpath = nextFileName('fileio_test_readtext_sync_001'); + let pos = 1; + let len = 0; + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let str = fileio.readTextSync(fpath, { position: pos }); + console.log(str); + expect(str == FILE_CONTENT.substr(pos, FILE_CONTENT.length)).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_test_readtext_sync_001 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_ReadtextSync_0020 + * @tc.name fileio_test_readtext_sync_002 + * @tc.desc Test readtextSync() interfaces. + */ + it('fileio_test_readtext_sync_002', 0, function () { + let fpath = nextFileName('fileio_test_readtext_sync_002'); + let pos = 1; + let len = FILE_CONTENT.length; + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let str = fileio.readTextSync(fpath, { position: pos, length: len }); + expect(str == FILE_CONTENT.substr(pos, len)).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_test_readtext_sync_002 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_ReadtextSync_0030 + * @tc.name fileio_test_readtext_sync_003 + * @tc.desc Test readtextSync() interfaces. + */ + it('fileio_test_readtext_sync_003', 0, function () { + try { + fileio.readTextSync(); + expect(null).assertFail(); + } catch (e) { + } + }); + + /** + * @tc.number SUB_DF_FileIO_ReadtextSync_0040 + * @tc.name fileio_test_readtext_sync_004 + * @tc.desc Test readtextSync() interfaces. + */ + it('fileio_test_readtext_sync_004', 0, function () { + let fpath = nextFileName('fileio_test_readtext_sync_004'); + + try { + fileio.readTextSync(fpath); + expect(null).assertFail(); + } catch (e) { + } + }); + + /** + * @tc.number SUB_DF_FileIO_ReadtextSync_0050 + * @tc.name fileio_test_readtext_sync_005 + * @tc.desc Test readtextSync() interfaces. + */ + it('fileio_test_readtext_sync_005', 0, function () { + const invalidLength = 9999; + let fpath = nextFileName('fileio_test_readtext_sync_005'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + fileio.readTextSync(fpath, { + length: invalidLength, + }); + expect(null).assertFail(); + } catch (e) { + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_ReadtextAsync_0000 + * @tc.name fileio_test_readtext_async_000 + * @tc.desc Test readtextASync() interfaces. + */ + it('fileio_test_readtext_async_000', 0, async function (done) { + let fpath = nextFileName('fileio_test_readtext_async_000'); + let pos = 1; + let len = FILE_CONTENT.length; + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + await fileio.readText(fpath, { position: pos, length: len, encoding: 'UTF-8' }, function (err, str) { + expect(str == FILE_CONTENT.substr(pos, len)).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + }); + } catch (e) { + console.log('fileio_test_readtext_async_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_ReadtextAsync_0010 + * @tc.name fileio_test_readtext_async_001 + * @tc.desc Test readtextASync() interfaces. + */ + it('fileio_test_readtext_async_001', 0, async function (done) { + let fpath = nextFileName('fileio_test_readtext_async_001'); + let pos = 1; + let len = FILE_CONTENT.length; + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + await fileio.readText(fpath, { position: 1 }, function (err, str) { + expect(str == FILE_CONTENT.substr(pos, len)).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + }); + } catch (e) { + console.log('fileio_test_readtext_async_001 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_ReadtextAsync_0020 + * @tc.name fileio_test_readtext_async_002 + * @tc.desc Test readtextASync() interfaces. + */ + it('fileio_test_readtext_async_002', 0, async function (done) { + let fpath = nextFileName('fileio_test_readtext_async_002'); + let pos = 1; + let len = FILE_CONTENT.length; + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + await fileio.readText(fpath, { position: 1 }, function (err, str) { + expect(str == FILE_CONTENT.substr(pos, len)).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + }); + fileio.readText(fpath, { position: 1 }) + .then(function (str) { + expect(str == FILE_CONTENT.substr(pos, len)).assertTrue(); + }) + .catch(function (e) { + expect(e == null).assertTrue(); + }); + done(); + } catch (e) { + console.log('fileio_test_readtext_async_002 has failed for ' + e); + expect(null).assertFail(); + } + }); +}); diff --git a/storage/storagefileiojstest/src/main/js/default/test/module_fileio/members/rename.test.js b/storage/storagefileiojstest/src/main/js/default/test/module_fileio/members/rename.test.js new file mode 100644 index 0000000000000000000000000000000000000000..4935b478e4cb6cd7ed4e73561d8cd2735d652ee5 --- /dev/null +++ b/storage/storagefileiojstest/src/main/js/default/test/module_fileio/members/rename.test.js @@ -0,0 +1,97 @@ +/* + * 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_rename', function () { + + /** + * @tc.number SUB_DF_FileIO_RenameAsync_0000 + * @tc.name fileio_test_rename_async_000 + * @tc.desc Test renameAsync() interfaces. + */ + it('fileio_test_rename_async_000', 0, async function (done) { + let fpath = nextFileName('fileio_test_rename_async_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let newf = fpath + '123'; + await fileio.rename(fpath, newf) + .then(function (err) { + expect(fileio.accessSync(newf) == null).assertTrue(); + expect(err == null).assertTrue(); + expect(fileio.unlinkSync(newf) == null).assertTrue(); + }) + .catch(function (e) { + expect(e == null).assertTrue(); + }) + done(); + } catch (e) { + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_RenameAsync_0010 + * @tc.name fileio_test_rename_async_001 + * @tc.desc Test renameAsync() interfaces. + */ + it('fileio_test_rename_async_001', 0, async function (done) { + let fpath = nextFileName('fileio_test_rename_async_001'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let newf = fpath + 'aaa'; + await fileio.rename(fpath, newf, function (err) { + expect(fileio.accessSync(newf) == null).assertTrue(); + expect(err == null).assertTrue(); + expect(fileio.unlinkSync(newf) == null).assertTrue(); + done(); + }) + } catch (e) { + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_RenameAsync_0020 + * @tc.name fileio_test_rename_async_002 + * @tc.desc Test renameAsync() interfaces. + */ + it('fileio_test_rename_async_002', 0, async function (done) { + let fpath = nextFileName('fileio_test_rename_async_002'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + await fileio.access(fpath).then(function (err) { + let newf = fpath + '123'; + fileio.rename(fpath, newf) + .then(function (err) { + expect(fileio.accessSync(newf) == null).assertTrue(); + expect(err == null).assertTrue(); + expect(fileio.unlinkSync(newf) == null).assertTrue(); + }) + }) + .catch(function (e) { + expect(e == null).assertTrue(); + }) + done(); + } catch (e) { + expect(null).assertFail(); + } + }); +}); \ No newline at end of file diff --git a/storage/storagefileiojstest/src/main/js/default/test/module_fileio/members/rmdir.test.js b/storage/storagefileiojstest/src/main/js/default/test/module_fileio/members/rmdir.test.js new file mode 100644 index 0000000000000000000000000000000000000000..c92ba68a158ca2da178b6b04c2783ba528571b98 --- /dev/null +++ b/storage/storagefileiojstest/src/main/js/default/test/module_fileio/members/rmdir.test.js @@ -0,0 +1,134 @@ +/* + * 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_rmdir', function () { + + /** + * @tc.number SUB_DF_FileIO_RmdirAsync_0000 + * @tc.name fileio_test_rmdir_async_000 + * @tc.desc Test rmdirAsync() interfaces. + */ + it('fileio_test_rmdir_async_000', 0, async function (done) { + let dpath = nextFileName('fileio_test_rmdir_async_000') + 'd'; + + try { + expect(fileio.mkdirSync(dpath) == null).assertTrue(); + expect(await fileio.rmdir(dpath) == null).assertTrue(); + fileio + .access(dpath) + .then(function () { + expect(null).assertFail(); + done(); + }) + .catch((err) => { + expect(!!err).assertTrue(); + done(); + }); + } catch (e) { + console.log('fileio_test_rmdir_async_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_RmdirAsync_0010 + * @tc.name fileio_test_rmdir_async_001 + * @tc.desc Test rmdirAsync() interfaces. + */ + it('fileio_test_rmdir_async_001', 0, async function (done) { + let dpath = nextFileName('fileio_test_rmdir_async_001') + 'd'; + + try { + expect(fileio.mkdirSync(dpath) == null).assertTrue(); + fileio.rmdir(dpath, async function (err) { + expect(!err).assertTrue(); + fileio + .access(dpath) + .then(function () { + expect(null).assertFail(); + done(); + }) + .catch((err) => { + expect(!!err).assertTrue(); + done(); + }); + }); + } catch (e) { + console.log('fileio_test_rmdir_async_001 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_RmdirAsync_0020 + * @tc.name fileio_test_rmdir_async_002 + * @tc.desc Test rmdirAsync() interfaces. + */ + it('fileio_test_rmdir_async_002', 0, async function (done) { + let dpath = nextFileName('fileio_test_rmdir_async_002') + 'd'; + expect(prepareFile(dpath, FILE_CONTENT)).assertTrue(); + + try { + fileio.rmdir(dpath, async function (err) { + expect(!!err).assertTrue(); + expect(await fileio.access(dpath) == null).assertTrue(); + await fileio.unlink(dpath); + done(); + }); + } catch (e) { + console.log('fileio_test_rmdir_async_002 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_RmdirAsync_0030 + * @tc.name fileio_test_rmdir_async_003 + * @tc.desc Test rmdirAsync() interfaces. + */ + it('fileio_test_rmdir_async_003', 0, async function (done) { + try { + fileio.rmdir('1.js', async function (err) { + expect(!!err).assertTrue(); + done(); + }); + } catch (e) { + console.log('fileio_test_rmdir_async_003 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_RmdirSync_0000 + * @tc.name fileio_test_rmdir_sync_000 + * @tc.desc Test rmdirSync() interfaces. + */ + it('fileio_test_rmdir_sync_000', 0, function () { + let dpath = nextFileName('fileio_test_rmdir_sync_000') + 'd'; + + try { + expect(fileio.mkdirSync(dpath) == null).assertTrue(); + expect(fileio.rmdirSync(dpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_test_rmdir_sync_000 has failed for ' + e); + expect(null).assertFail(); + } + }); +}); diff --git a/storage/storagefileiojstest/src/main/js/default/test/module_fileio/members/stat.test.js b/storage/storagefileiojstest/src/main/js/default/test/module_fileio/members/stat.test.js new file mode 100644 index 0000000000000000000000000000000000000000..9305e4d34e1669df098f331794a6335d950ed539 --- /dev/null +++ b/storage/storagefileiojstest/src/main/js/default/test/module_fileio/members/stat.test.js @@ -0,0 +1,1378 @@ +/* + * 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, isBoolean, + describe, beforeAll, beforeEach, afterEach, afterAll, it, expect, +} from '../../Common'; + +describe('fileio_stat', function () { + + /** + * @tc.number SUB_DF_FileIO_statSync_0000 + * @tc.name fileio_stat_sync_000 + * @tc.desc Test Stat.statSync() interfaces. + * This interface shall work properly in normal case. + */ + it('fileio_stat_sync_000', 0, function () { + let fpath = nextFileName('fileio_stat_sync_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = fileio.statSync(fpath); + expect(stat !== null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_stat_sync_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_statSync_0010 + * @tc.name fileio_stat_sync_001 + * @tc.desc Test Stat.statSync() interfaces. + * This interface shall throw an exception when the file isnt's exist. + */ + it('fileio_stat_sync_001', 0, function () { + let fpath = nextFileName('fileio_stat_sync_001'); + + try { + fileio.statSync(fpath); + expect(null).assertFail(); + } catch (e) { + } + }); + + /** + * @tc.number SUB_DF_FileIO_Stat_Sync_Dev_0000 + * @tc.name fileio_stat_sync_dev_000 + * @tc.desc Test Stat.statSync_Dev() interfaces. + * @tc.desc Test the dev member of class Stat. + */ + it('fileio_stat_sync_dev_000', 0, function () { + let fpath = nextFileName('fileio_stat_sync_dev_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = fileio.statSync(fpath); + expect(isIntNum(stat.dev)).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_stat_sync_dev_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_Stat_Ino_0000 + * @tc.name fileio_stat_sync_ino_000 + * @tc.desc Test Stat.statSync_Ino() interfaces. + * @tc.desc Test the ino member of class Stat + */ + it('fileio_stat_sync_ino_000', 0, function () { + let fpath = nextFileName('fileio_stat_sync_ino_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = fileio.statSync(fpath); + expect(isIntNum(stat.ino)).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_stat_sync_ino_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_Stat_Mode_0000 + * @tc.name fileio_stat_sync_mode_000 + * @tc.desc Test Stat.statSync_Mode() interfaces. + * @tc.desc Test the mode member of class Stat + */ + it('fileio_stat_sync_mode_000', 0, function () { + let fpath = nextFileName('fileio_stat_sync_mode_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = fileio.statSync(fpath); + expect(isIntNum(stat.mode)).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_stat_sync_mode_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_Stat_Nlink_0000 + * @tc.name fileio_stat_sync_nlink_000 + * @tc.desc Test Stat.statSync_Nlink() interfaces. + * @tc.desc Test the nlink member of class Stat + */ + it('fileio_stat_sync_nlink_000', 0, function () { + let fpath = nextFileName('fileio_stat_sync_nlink_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = fileio.statSync(fpath); + expect(isIntNum(stat.nlink)).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_stat_sync_nlink_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_Stat_Uid_0000 + * @tc.name fileio_stat_sync_uid_000 + * @tc.desc Test Stat.statSync_Uid() interfaces. + * @tc.desc Test the uid member of class Stat + */ + it('fileio_stat_sync_uid_000', 0, function () { + let fpath = nextFileName('fileio_stat_sync_uid_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = fileio.statSync(fpath); + expect(isIntNum(stat.uid)).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_stat_sync_uid_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_StatSync_Gid_0000 + * @tc.name fileio_stat_sync_gid_000 + * @tc.desc Test Stat.statSync_Gid() interfaces. + * @tc.desc Test the gid member of class Stat + */ + it('fileio_stat_sync_gid_000', 0, function () { + let fpath = nextFileName('fileio_stat_sync_gid_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = fileio.statSync(fpath); + expect(isIntNum(stat.gid)).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_stat_sync_gid_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_StatSync_Rdev_0000 + * @tc.name fileio_stat_sync_rdev_000 + * @tc.desc Test Stat.statSync_Rdev() interfaces. + * @tc.desc Test the rdev member of class Stat + */ + it('fileio_stat_sync_rdev_000', 0, function () { + let fpath = nextFileName('fileio_stat_sync_rdev_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = fileio.statSync(fpath); + expect(isIntNum(stat.rdev)).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_stat_sync_rdev_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_StatSync_Size_0000 + * @tc.name fileio_stat_sync_size_000 + * @tc.desc Test Stat.statSync_Size() interfaces. + * @tc.desc Test the size member of class Stat + */ + it('fileio_stat_sync_size_000', 0, function () { + let fpath = nextFileName('fileio_stat_sync_size_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = fileio.statSync(fpath); + expect(isIntNum(stat.size)).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_stat_sync_size_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_StatSync_Blocks_0000 + * @tc.name fileio_stat_sync_blocks_000 + * @tc.desc Test Stat.statSync_Block() interfaces. + * @tc.desc Test the blocks member of class Stat + */ + it('fileio_stat_sync_blocks_000', 0, function () { + let fpath = nextFileName('fileio_stat_sync_blocks_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = fileio.statSync(fpath); + expect(isIntNum(stat.blocks)).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_stat_sync_blocks_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_StatSync_Atime_0000 + * @tc.name fileio_stat_sync_atime_000 + * @tc.desc Test Stat.statSync_Atime() interfaces. + * @tc.desc Test the atime member of class Stat + */ + it('fileio_stat_sync_atime_000', 0, function () { + let fpath = nextFileName('fileio_stat_sync_atime_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = fileio.statSync(fpath); + expect(isIntNum(stat.atime)).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_stat_sync_atime_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_StatSync_Mtime_0000 + * @tc.name fileio_stat_sync_mtime_000 + * @tc.desc Test Stat.statSync_Mtime() interfaces. + * @tc.desc Test the mtime member of class Stat + */ + it('fileio_stat_sync_mtime_000', 0, function () { + let fpath = nextFileName('fileio_stat_sync_mtime_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = fileio.statSync(fpath); + expect(isIntNum(stat.mtime)).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_stat_sync_mtime_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_StatSync_Ctime_0000 + * @tc.name fileio_stat_sync_ctime_000 + * @tc.desc Test Stat.statSync_Ctime() interfaces. + * @tc.desc Test the ctime member of class Stat + */ + it('fileio_stat_sync_ctime_000', 0, function () { + let fpath = nextFileName('fileio_stat_sync_ctime_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = fileio.statSync(fpath); + expect(isIntNum(stat.ctime)).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_stat_sync_ctime_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_StatSync_IsBlockDevice_0000 + * @tc.name fileio_stat_sync_is_block_device_000 + * @tc.desc Test Stat.statSync_IsBlockDevice() interfaces. + * @tc.desc Test the isBlockDevice() method of class Stat. + * This interface shall return a boolean variable. + */ + it('fileio_stat_sync_is_block_device_000', 0, function () { + let fpath = nextFileName('fileio_stat_sync_is_block_device_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = fileio.statSync(fpath); + expect(isBoolean(stat.isBlockDevice())).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_stat_sync_is_block_device_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_StatSync_IsBlockDevice_0010 + * @tc.name fileio_stat_sync_is_block_device_001 + * @tc.desc Test Stat.statSync_IsBlockDevice() interfaces. + * @tc.desc Test the isBlockDevice() method of class Stat. + * This interface shall not treat a normal file as a block special device. + */ + it('fileio_stat_sync_is_block_device_001', 0, function () { + let fpath = nextFileName('fileio_stat_sync_is_block_device_001'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = fileio.statSync(fpath); + expect(stat.isBlockDevice() === false).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_stat_sync_is_block_device_001 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_StatSync_IsBlockDevice_0020 + * @tc.name fileio_stat_sync_is_block_device_002 + * @tc.desc Test Stat.statSync_IsBlockDevice() interfaces. + * @tc.desc Test the isBlockDevice() method of class Stat. + */ + it('fileio_stat_sync_is_block_device_002', 0, function () { + let fpath = nextFileName('fileio_stat_sync_is_block_device_002'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = fileio.statSync(fpath); + expect(stat.isBlockDevice(-1) === false).assertTrue(); + expect(null).assertFail(); + } catch (e) { + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_StatSync_IsCharacterDevice_0000 + * @tc.name fileio_stat_sync_is_character_device_000 + * @tc.desc Test Stat.statsync_IsCharacterDevice() interfaces. + * This interface shall return a boolean variable. + */ + it('fileio_stat_sync_is_character_device_000', 0, function () { + let fpath = nextFileName('fileio_stat_sync_is_character_device_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = fileio.statSync(fpath); + expect(isBoolean(stat.isCharacterDevice())).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_stat_sync_is_character_device_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_StatSync_IsCharacterDevice_0010 + * @tc.name fileio_stat_sync_is_character_device_001 + * @tc.desc Test Stat.statsync_IsCharacterDevice() interfaces. + * This interface shall not treat a normal file as a character special device. + */ + it('fileio_stat_sync_is_character_device_001', 0, function () { + let fpath = nextFileName('fileio_stat_sync_is_character_device_001'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = fileio.statSync(fpath); + expect(stat.isCharacterDevice() === false).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_stat_sync_is_character_device_001 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_StatSync_IsCharacterDevice_0020 + * @tc.name fileio_stat_sync_is_character_device_002 + * @tc.desc Test Stat.statsync_IsCharacterDevice() interfaces. + */ + it('fileio_stat_sync_is_character_device_002', 0, function () { + let fpath = nextFileName('fileio_stat_sync_is_character_device_002'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = fileio.statSync(fpath); + expect(stat.isCharacterDevice(-1) === false).assertTrue(); + expect(null).assertFail(); + } catch (e) { + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_StatSync_IsDirectory_0000 + * @tc.name fileio_stat_sync_is_directory_000 + * @tc.desc Test Stat.statsync_isDirectory() interfaces. + * This interface shall return a boolean variable. + */ + it('fileio_stat_sync_is_directory_000', 0, function () { + let fpath = nextFileName('fileio_stat_sync_is_directory_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = fileio.statSync(fpath); + expect(isBoolean(stat.isDirectory())).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_stat_sync_is_directory_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_StatSync_IsDirectory_0010 + * @tc.name fileio_stat_sync_is_directory_001 + * @tc.desc Test Stat.statsync_isDirectory() interfaces. + * This interface shall not treat a normal file as a directory. + */ + it('fileio_stat_sync_is_directory_001', 0, function () { + let fpath = nextFileName('fileio_stat_sync_is_directory_001'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = fileio.statSync(fpath); + expect(stat.isDirectory() === false).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_stat_sync_is_directory_001 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_StatSync_IsDirectory_0020 + * @tc.name fileio_stat_sync_is_directory_002 + * @tc.desc Test Stat.statsync_isDirectory() interfaces. + * This interface shall treat a directory as a directory. + */ + it('fileio_stat_sync_is_directory_002', 0, function () { + let dpath = nextFileName('fileio_stat_sync_is_directory_002') + 'd'; + + try { + expect(fileio.mkdirSync(dpath) == null).assertTrue(); + let stat = fileio.statSync(dpath); + expect(stat.isDirectory()).assertTrue(); + expect(fileio.rmdirSync(dpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_stat_sync_is_directory_002 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_StatSync_IsDirectory_0030 + * @tc.name fileio_stat_sync_is_directory_003 + * @tc.desc Test Stat.statsync_isDirectory() interfaces. + */ + it('fileio_stat_sync_is_directory_003', 0, function () { + let dpath = nextFileName('fileio_stat_sync_is_directory_003') + 'd'; + + try { + expect(fileio.mkdirSync(dpath) == null).assertTrue(); + let stat = fileio.statSync(dpath); + expect(stat.isDirectory(-1)).assertTrue(); + expect(null).assertFail(); + } catch (e) { + expect(fileio.rmdirSync(dpath) == null).assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_StatSync_IsFIFO_0000 + * @tc.name fileio_stat_sync_is_fifo_000 + * @tc.desc Test Stat.statsync_isFIFO() interfaces. + * This interface shall return a boolean variable. + */ + it('fileio_stat_sync_is_fifo_000', 0, function () { + let fpath = nextFileName('fileio_stat_sync_is_fifo_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = fileio.statSync(fpath); + expect(isBoolean(stat.isFIFO())).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_stat_sync_is_fifo_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_StatSync_IsFIFO_0010 + * @tc.name fileio_stat_sync_is_fifo_001 + * @tc.desc Test Stat.statsync_isFIFO() interfaces. + * This interface shall not treat a normal file as a FIFO. + */ + it('fileio_stat_sync_is_fifo_001', 0, function () { + let fpath = nextFileName('fileio_stat_sync_is_fifo_001'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = fileio.statSync(fpath); + expect(stat.isFIFO() === false).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_stat_sync_is_fifo_001 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_StatSync_IsFIFO_0020 + * @tc.name fileio_stat_sync_is_fifo_002 + * @tc.desc Test Stat.statsync_isFIFO() interfaces. + */ + it('fileio_stat_sync_is_fifo_002', 0, function () { + let fpath = nextFileName('fileio_stat_sync_is_fifo_002'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = fileio.statSync(fpath); + expect(stat.isFIFO(-1) === false).assertTrue(); + expect(null).assertFail(); + } catch (e) { + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_StatSync_IsFILE_0000 + * @tc.name fileio_stat_sync_is_file_000 + * @tc.desc Test Stat.statsync_isFile() interfaces. + * This interface shall return a boolean variable. + */ + it('fileio_stat_sync_is_file_000', 0, function () { + let fpath = nextFileName('fileio_stat_sync_is_file_000'); + expect(isBoolean(prepareFile(fpath, FILE_CONTENT))).assertTrue(); + + try { + let stat = fileio.statSync(fpath); + expect(isBoolean(stat.isFile())).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_stat_sync_is_file_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_StatSync_IsFILE_0010 + * @tc.name fileio_stat_sync_is_file_001 + * @tc.desc Test Stat.statsync_isFile() interfaces. + * This interface shall treat a normal file as a normal file. + */ + it('fileio_stat_sync_is_file_001', 0, function () { + let fpath = nextFileName('fileio_stat_sync_is_file_001'); + expect(isBoolean(prepareFile(fpath, FILE_CONTENT))).assertTrue(); + + try { + let stat = fileio.statSync(fpath); + expect(stat.isFile()).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_stat_sync_is_file_001 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_StatSync_IsFILE_0020 + * @tc.name fileio_stat_sync_is_file_002 + * @tc.desc Test Stat.statsync_isFile() interfaces. + * This interface shall not treat a directory as a normal file. + */ + it('fileio_stat_sync_is_file_002', 0, function () { + let dpath = nextFileName('fileio_stat_sync_is_file_002'); + + try { + expect(fileio.mkdirSync(dpath) == null).assertTrue(); + let stat = fileio.statSync(dpath); + expect(stat.isFile() === false).assertTrue(); + expect(fileio.rmdirSync(dpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_stat_sync_is_file_002 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_StatSync_IsFILE_0030 + * @tc.name fileio_stat_sync_is_file_003 + * @tc.desc Test Stat.statsync_isFile() interfaces. + */ + it('fileio_stat_sync_is_file_003', 0, function () { + let dpath = nextFileName('fileio_stat_sync_is_file_003'); + + try { + expect(fileio.mkdirSync(dpath) == null).assertTrue(); + let stat = fileio.statSync(dpath); + expect(stat.isFile(-1) === false).assertTrue(); + expect(null).assertFail(); + } catch (e) { + expect(fileio.rmdirSync(dpath) == null).assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_StatSync_IsSocket_0000 + * @tc.name fileio_stat_sync_is_socket_000 + * @tc.desc Test Stat.statsync_isSocket() interfaces. + * This interface shall return a boolean variable. + */ + it('fileio_stat_sync_is_socket_000', 0, function () { + let fpath = nextFileName('fileio_stat_sync_is_socket_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = fileio.statSync(fpath); + expect(isBoolean(stat.isSocket())).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_stat_sync_is_socket_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_StatSync_IsSocket_0010 + * @tc.name fileio_stat_sync_is_socket_001 + * @tc.desc Test Stat.statsync_isSocket() interfaces. + * This interface shall not treat a file as a socket. + */ + it('fileio_stat_sync_is_socket_001', 0, function () { + let fpath = nextFileName('fileio_stat_sync_is_socket_001'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = fileio.statSync(fpath); + expect(stat.isSocket() === false).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_stat_sync_is_socket_001 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_StatSync_IsSocket_0020 + * @tc.name fileio_stat_sync_is_socket_002 + * @tc.desc Test Stat.statsync_isSocket() interfaces. + */ + it('fileio_stat_sync_is_socket_002', 0, function () { + let fpath = nextFileName('fileio_stat_sync_is_socket_002'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = fileio.statSync(fpath); + expect(stat.isSocket(-1) === false).assertTrue(); + expect(null).assertFail(); + } catch (e) { + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_StatSync_IsSymbolicLink_0000 + * @tc.name fileio_stat_sync_is_symbolic_link_000 + * @tc.desc Test Stat.statasync_isSymbolicLink() interfaces. + * This interface shall return a boolean variable. + */ + it('fileio_stat_sync_is_symbolic_link_000', 0, function () { + let fpath = nextFileName('fileio_stat_sync_is_symbolic_link_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = fileio.statSync(fpath); + expect(isBoolean(stat.isSymbolicLink())).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_stat_sync_is_symbolic_link_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_StatSync_IsSymbolicLink_0010 + * @tc.name fileio_stat_sync_is_symbolic_link_001 + * @tc.desc Test Stat.statasync_isSymbolicLink() interfaces. + * This interface shall not treat a normal file as a symbolic link. + */ + it('fileio_stat_sync_is_symbolic_link_001', 0, function () { + let fpath = nextFileName('fileio_stat_sync_is_symbolic_link_001'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = fileio.statSync(fpath); + expect(stat.isSymbolicLink() === false).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_stat_is_symbolic_link_001 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_StatSync_IsSymbolicLink_0020 + * @tc.name fileio_stat_sync_is_symbolic_link_002 + * @tc.desc Test Stat.isSymbolicLink() interfaces. + */ + it('fileio_stat_sync_is_symbolic_link_002', 0, function () { + let fpath = nextFileName('fileio_stat_sync_is_symbolic_link_002'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = fileio.statSync(fpath); + expect(stat.isSymbolicLink(-1) === false).assertTrue(); + expect(null).assertFail(); + } catch (e) { + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_statAsync_0000 + * @tc.name fileio_stat_async_000 + * @tc.desc Test Stat.statAsync() interface. + * This interface shall work properly in normal case when providing the promise async model. + */ + it('fileio_stat_async_000', 0, async function (done) { + let fpath = nextFileName('fileio_stat_async_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + fileio.stat(fpath).then((stat) => { + expect(stat !== null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + }); + done(); + } catch (e) { + console.log('fileio_stat_async_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_statAsync_0000 + * @tc.name fileio_stat_async_001 + * @tc.desc Test Stat.statAsync() interface. + * This interface shall work properly in normal case when providing the callback async model. + */ + it('fileio_stat_async_001', 0, async function (done) { + let fpath = nextFileName('fileio_stat_async_001'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + fileio.stat(fpath, function (error) { + expect(!error).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + }); + } catch (e) { + console.log('fileio_stat_async_001 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_StatAsync_Dev_0000 + * @tc.name fileio_stat_async_dev_000 + * @tc.desc Test the dev member of class Stat. + */ + it('fileio_stat_async_dev_000', 0, async function (done) { + let fpath = nextFileName('fileio_stat_async_dev_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = await fileio.stat(fpath); + expect(isIntNum(stat.dev)).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_stat_async_dev_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_StatAsync_Ino_0000 + * @tc.name fileio_stat_async_ino_000 + * @tc.desc Test the ino member of class Stat. + */ + it('fileio_stat_async_ino_000', 0, async function (done) { + let fpath = nextFileName('fileio_stat_async_ino_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = await fileio.stat(fpath); + expect(isIntNum(stat.ino)).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_stat_async_ino_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_StatAsync_Mode_0000 + * @tc.name fileio_stat_async_mode_000 + * @tc.desc Test the mode member of class Stat. + */ + it('fileio_stat_async_mode_000', 0, async function (done) { + let fpath = nextFileName('fileio_stat_async_mode_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = await fileio.stat(fpath); + expect(isIntNum(stat.mode)).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_stat_async_mode_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_StatAsync_Nlink_0000 + * @tc.name fileio_stat_async_nlink_000 + * @tc.desc Test the nlink member of class Stat. + */ + it('fileio_stat_async_nlink_000', 0, async function (done) { + let fpath = nextFileName('fileio_stat_async_nlink_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = await fileio.stat(fpath); + expect(isIntNum(stat.nlink)).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_stat_async_nlink_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_StatAsync_Uid_0000 + * @tc.name fileio_stat_async_uid_000 + * @tc.desc Test the uid member of class Stat. + */ + it('fileio_stat_async_uid_000', 0, async function (done) { + let fpath = nextFileName('fileio_stat_async_uid_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = await fileio.stat(fpath); + expect(isIntNum(stat.uid)).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_stat_async_uid_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_StatAsync_Gid_0000 + * @tc.name fileio_stat_async_gid_000 + * @tc.desc Test the gid member of class Stat. + */ + it('fileio_stat_async_gid_000', 0, async function (done) { + let fpath = nextFileName('fileio_stat_async_gid_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = await fileio.stat(fpath); + expect(isIntNum(stat.gid)).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_stat_async_gid_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_StatAsync_Rdev_0000 + * @tc.name fileio_stat_async_rdev_000 + * @tc.desc Test the rdev member of class Stat. + */ + it('fileio_stat_async_rdev_000', 0, async function (done) { + let fpath = nextFileName('fileio_stat_async_rdev_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = await fileio.stat(fpath); + expect(isIntNum(stat.rdev)).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_stat_async_rdev_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_StatAsync_Size_0000 + * @tc.name fileio_stat_async_size_000 + * @tc.desc Test the size member of class Stat. + */ + it('fileio_stat_async_size_000', 0, async function (done) { + let fpath = nextFileName('fileio_stat_async_size_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = await fileio.stat(fpath); + expect(isIntNum(stat.size)).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_stat_async_size_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_StatAsync_Blocks_0000 + * @tc.name fileio_stat_async_blocks_000 + * @tc.desc Test Stat.blocks() interface. + * @tc.desc Test the blocks member of class Stat. + */ + it('fileio_stat_async_blocks_000', 0, async function (done) { + let fpath = nextFileName('fileio_stat_async_blocks_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = await fileio.stat(fpath); + expect(isIntNum(stat.blocks)).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_stat_async_blocks_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_StatAsync_Atime_0000 + * @tc.name fileio_stat_async_atime_000 + * @tc.desc Test Stat.atime() interface. + * @tc.desc Test the atime member of class Stat. + */ + it('fileio_stat_async_atime_000', 0, async function (done) { + let fpath = nextFileName('fileio_stat_async_atime_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = await fileio.stat(fpath); + expect(isIntNum(stat.atime)).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_stat_async_atime_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_StatAsync_Mtime_0000 + * @tc.name fileio_stat_async_mtime_000 + * @tc.desc Test Stat.mtime() interface. + * @tc.desc Test the mtime member of class Stat. + */ + it('fileio_stat_async_mtime_000', 0, async function (done) { + let fpath = nextFileName('fileio_stat_async_mtime_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = await fileio.stat(fpath); + expect(isIntNum(stat.mtime)).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_stat_async_mtime_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_StatAsync_Ctime_0000 + * @tc.name fileio_stat_async_ctime_000 + * @tc.desc Test the ctime member of class Stat. + */ + it('fileio_stat_async_ctime_000', 0, async function (done) { + let fpath = nextFileName('fileio_stat_async_ctime_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = await fileio.stat(fpath); + expect(isIntNum(stat.ctime)).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_stat_async_ctime_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_StatAsync_IsBlockDevice_0000 + * @tc.name fileio_stat_async_is_block_device_000 + * @tc.desc Test the isBlockDevice method of class Stat. + */ + it('fileio_stat_async_is_block_device_000', 0, async function (done) { + let fpath = nextFileName('fileio_stat_async_is_block_device_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = await fileio.stat(fpath); + expect(isBoolean(stat.isBlockDevice())).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_stat_async_is_block_device_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_StatAsync_IsBlockDevice_0010 + * @tc.name fileio_stat_async_is_block_device_001 + * @tc.desc Test the isBlockDevice method of class Stat. + */ + it('fileio_stat_async_is_block_device_001', 0, async function (done) { + let fpath = nextFileName('fileio_stat_async_is_block_device_001'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = await fileio.stat(fpath); + expect(stat.isBlockDevice() === false).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_stat_async_is_block_device_001 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_StatAsync_IsCharacterDevice_0000 + * @tc.name fileio_stat_async_is_character_device_000 + * @tc.desc Test the isCharacterDevice method of class Stat. + */ + it('fileio_stat_async_is_character_device_000', 0, async function (done) { + let fpath = nextFileName('fileio_stat_async_is_character_device_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = await fileio.stat(fpath); + expect(isBoolean(stat.isCharacterDevice())).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_stat_async_is_character_device_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_StatAsync_IsCharacterDevice_0010 + * @tc.name fileio_stat_async_is_character_device_001 + * @tc.desc Test the isCharacterDevice method of class Stat. + */ + it('fileio_stat_async_is_character_device_001', 0, async function (done) { + let fpath = nextFileName('fileio_stat_async_is_character_device_001'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = await fileio.stat(fpath); + expect(stat.isCharacterDevice() === false).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_stat_async_is_character_device_001 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_StatAsync_IsDirectory_0000 + * @tc.name fileio_stat_async_is_directory_000 + * @tc.desc Test Stat.isDirectory() interface. + */ + it('fileio_stat_async_is_directory_000', 0, async function (done) { + let fpath = nextFileName('fileio_stat_async_is_directory_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = await fileio.stat(fpath); + expect(isBoolean(stat.isDirectory())).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_stat_async_is_directory_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_StatAsync_IsDirectory_0010 + * @tc.name fileio_stat_async_is_directory_001 + * @tc.desc Test Stat.isDirectory() interface. + */ + it('fileio_stat_async_is_directory_001', 0, async function (done) { + let fpath = nextFileName('fileio_stat_async_is_directory_001'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = await fileio.stat(fpath); + expect(stat.isDirectory() === false).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_stat_async_is_directory_001 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_StatAsync_IsDirectory_0020 + * @tc.name fileio_stat_async_is_directory_002 + * @tc.desc Test Stat.isDirectory() interface. + */ + it('fileio_stat_async_is_directory_002', 0, async function (done) { + let dpath = nextFileName('fileio_stat_async_is_directory_002') + 'd'; + + try { + expect(fileio.mkdirSync(dpath) == null).assertTrue(); + let stat = await fileio.stat(dpath); + expect(stat.isDirectory()).assertTrue(); + expect(fileio.rmdirSync(dpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_stat_async_is_directory_002 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_StatAsync_IsFIFO_0000 + * @tc.name fileio_stat_async_is_fifo_000 + * @tc.desc Test Stat.isFIFO() interface. + */ + it('fileio_stat_async_is_fifo_000', 0, async function (done) { + let fpath = nextFileName('fileio_stat_async_is_fifo_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = await fileio.stat(fpath); + expect(isBoolean(stat.isFIFO())).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_stat_async_is_fifo_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_StatAsync_IsFIFO_0010 + * @tc.name fileio_stat_async_is_fifo_001 + * @tc.desc Test Stat.isFIFO() interface. + */ + it('fileio_stat_async_is_fifo_001', 0, async function (done) { + let fpath = nextFileName('fileio_stat_async_is_fifo_001'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = await fileio.stat(fpath); + expect(stat.isFIFO() === false).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_stat_async_is_fifo_001 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_StatAsync_IsFILE_0000 + * @tc.name fileio_stat_async_is_file_000 + * @tc.desc Test Stat.isFile() interface. + */ + it('fileio_stat_async_is_file_000', 0, async function (done) { + let fpath = nextFileName('fileio_stat_async_is_file_000'); + expect(isBoolean(prepareFile(fpath, FILE_CONTENT))).assertTrue(); + + try { + let stat = await fileio.stat(fpath); + expect(isBoolean(stat.isFile())).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_stat_async_is_file_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_StatAsync_IsFILE_0010 + * @tc.name fileio_stat_async_is_file_001 + * @tc.desc Test Stat.isFile() interface. + */ + it('fileio_stat_async_is_file_001', 0, async function (done) { + let fpath = nextFileName('fileio_stat_async_is_file_001'); + expect(isBoolean(prepareFile(fpath, FILE_CONTENT))).assertTrue(); + + try { + let stat = await fileio.stat(fpath); + expect(stat.isFile()).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_stat_async_is_file_001 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_StatAsync_IsFILE_0020 + * @tc.name fileio_stat_async_is_file_002 + * @tc.desc Test Stat.isFile() interface. + */ + it('fileio_stat_async_is_file_002', 0, async function (done) { + let dpath = nextFileName('fileio_stat_async_is_file_002'); + + try { + expect(fileio.mkdirSync(dpath) == null).assertTrue(); + let stat = await fileio.stat(dpath); + expect(stat.isFile() === false).assertTrue(); + expect(fileio.rmdirSync(dpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_stat_async_is_file_002 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_StatAsync_IsSocket_0000 + * @tc.name fileio_stat_async_is_socket_000 + * @tc.desc Test Stat.isSocket() interface. + */ + it('fileio_stat_async_is_socket_000', 0, async function (done) { + let fpath = nextFileName('fileio_stat_async_is_socket_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = await fileio.stat(fpath); + expect(isBoolean(stat.isSocket())).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_stat_async_is_socket_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_StatAsync_IsSocket_0010 + * @tc.name fileio_stat_async_is_socket_001 + * @tc.desc Test Stat.isSocket() interface. + */ + it('fileio_stat_async_is_socket_001', 0, async function (done) { + let fpath = nextFileName('fileio_stat_async_is_socket_001'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = await fileio.stat(fpath); + expect(stat.isSocket() === false).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_stat_async_is_socket_001 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_StatAsync_IsSymbolicLink_0000 + * @tc.name fileio_stat_async_is_symbolic_link_000 + * @tc.desc Test Stat.isSymbolicLink() interface. + */ + it('fileio_stat_async_is_symbolic_link_000', 0, async function (done) { + let fpath = nextFileName('fileio_stat_async_is_symbolic_link_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = await fileio.stat(fpath); + expect(isBoolean(stat.isSymbolicLink())).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_stat_async_is_symbolic_link_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_StatAsync_IsSymbolicLink_0010 + * @tc.name fileio_stat_async_is_symbolic_link_001 + * @tc.desc Test Stat.isSymbolicLink() interface. + */ + it('fileio_stat_async_is_symbolic_link_001', 0, async function (done) { + let fpath = nextFileName('fileio_stat_async_is_symbolic_link_001'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = await fileio.stat(fpath); + expect(stat.isSymbolicLink() === false).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_stat_async_is_symbolic_link_001 has failed for ' + e); + expect(null).assertFail(); + } + }); + + it('fileio_test_append_file_sync_000', 0, function (done) { + let fpath = nextFileName('fileio_test_append_file_sync_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let stat = fileio.statSync(fpath); + expect(isIntNum(stat.size)).assertTrue(); + + let fd = fileio.openSync(fpath, 0o2002); + expect(isIntNum(fd)).assertTrue(); + + expect(fileio.writeSync(fd, FILE_CONTENT) == FILE_CONTENT.length).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + + stat = fileio.statSync(fpath); + expect(stat.size == FILE_CONTENT.length * 2).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_test_append_file_sync_000 has failed for ' + e); + expect(null).assertFail(); + } + done(); + }); +}); \ No newline at end of file diff --git a/storage/storagefileiojstest/src/main/js/default/test/module_fileio/members/symlink.test.js b/storage/storagefileiojstest/src/main/js/default/test/module_fileio/members/symlink.test.js new file mode 100644 index 0000000000000000000000000000000000000000..6e590a5af2ade897f25d7998ac5de2e62147dc41 --- /dev/null +++ b/storage/storagefileiojstest/src/main/js/default/test/module_fileio/members/symlink.test.js @@ -0,0 +1,89 @@ +/* + * 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_symlink', function () { + + /** + * @tc.number SUB_DF_FileIO_Fdatasync_SymlinkSync_0000 + * @tc.name fileio_test_symlink_sync_000 + * @tc.desc Test SymlinkSync interfaces. + * This interface shall not treat a normal file as a directory. + */ + it('fileio_test_symlink_sync_000', 0, function () { + let fpath = nextFileName('fileio_test_symlink_sync_000'); + + try { + fileio.symlinkSync(fpath, fpath + 'aaaa'); + expect(fileio.accessSync(fpath + 'aaaa') == null).assertTrue(); + fileio.unlinkSync(fpath + 'aaaa'); + expect(null).assertFail(); + } catch (e) { + } + }); + + /** + * @tc.number SUB_DF_FileIO_Fdatasync_SymlinkAsync_0000 + * @tc.name fileio_test_symlink_async_000 + * @tc.desc Test SymlinkAsync interfaces. + * This interface shall not treat a normal file as a directory. + */ + it('fileio_test_symlink_async_000', 0, async function (done) { + let fpath = nextFileName('fileio_test_symlink_async_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + fileio + .symlink(fpath, fpath + '1067') + .then(function (err) { + expect(fileio.accessSync(fpath + '1067') == null).assertTrue(); + fileio.unlinkSync(fpath + '1067'); + expect(err == null).assertTrue(); + }) + .catch(function (e) { + expect(e == null).assertTrue(); + }); + done(); + } catch (e) { + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_Fdatasync_SymlinkAsync_0010 + * @tc.name fileio_test_symlink_async_001 + * @tc.desc Test SymlinkAsync interfaces. + * This interface shall not treat a normal file as a directory. + */ + it('fileio_test_symlink_async_001', 0, async function (done) { + let fpath = nextFileName('fileio_test_symlink_async_010'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + await fileio.symlink(fpath, fpath + 'pass2', function (err) { + expect(fileio.accessSync(fpath + 'pass2') == null).assertTrue(); + fileio.unlinkSync(fpath + 'pass2'); + expect(err == null).assertTrue(); + done(); + }); + } catch (e) { + expect(null).assertFail(); + } + }); +}); diff --git a/storage/storagefileiojstest/src/main/js/default/test/module_fileio/members/truncate.test.js b/storage/storagefileiojstest/src/main/js/default/test/module_fileio/members/truncate.test.js new file mode 100644 index 0000000000000000000000000000000000000000..3f33980a9698a6ce820a82c171dc5e87f4951165 --- /dev/null +++ b/storage/storagefileiojstest/src/main/js/default/test/module_fileio/members/truncate.test.js @@ -0,0 +1,145 @@ +/* + * 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_truncate', function () { + + /** + * @tc.number SUB_DF_FileIO_TruncateAsync_0000 + * @tc.name fileio_truncate_async_000 + * @tc.desc Test truncateAsync() interfaces. + */ + it('fileio_truncate_async_000', 0, async function (done) { + let fpath = nextFileName('fileio_truncate_async_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + let truncateLen = 5; + + try { + fileio.truncate(fpath, truncateLen, function (err) { + expect(err == null).assertTrue(); + let fd = fileio.openSync(fpath, 0o2); + expect(isIntNum(fd)).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_truncate_async_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_TruncateAsync_0010 + * @tc.name fileio_truncate_async_001 + * @tc.desc Test truncateAsync() interfaces. + */ + it('fileio_truncate_async_001', 0, async function (done) { + let fpath = nextFileName('fileio_truncate_async_001'); + expect(prepareFile(fpath, 'truncate')).assertTrue(); + let truncateLen = 2; + + try { + fileio + .truncate(fpath, truncateLen) + .then(function (err) { + expect(err == null).assertTrue(); + let fd = fileio.openSync(fpath, 0o2); + expect(isIntNum(fd)).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_truncate_async_001 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_TruncateAsync_0020 + * @tc.name fileio_truncate_async_002 + * @tc.desc Test truncateAsync() interfaces. + */ + it('fileio_truncate_async_002', 0, async function (done) { + let fpath = nextFileName('fileio_truncate_async_002'); + let truncateLen = 2; + + try { + fileio.truncate(fpath, truncateLen, function (err) { + done(); + }); + } catch (e) { + expect(!!e).assertTrue(); + done(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_TruncateSync_0000 + * @tc.name fileio_test_truncate_sync_000 + * @tc.desc Test truncateSync() interfaces. + */ + it('fileio_test_truncate_sync_000', 0, function () { + let fpath = nextFileName('fileio_test_truncate_sync_000'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + expect(fileio.truncateSync(fpath) == null).assertTrue(); + expect(fileio.statSync(fpath).size == 0).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_test_truncate_sync_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_TruncateSync_0010 + * @tc.name fileio_test_truncate_sync_001 + * @tc.desc Test truncateSync() interfaces. + */ + it('fileio_test_truncate_sync_001', 0, function () { + let fpath = nextFileName('fileio_test_truncate_sync_001'); + + try { + fileio.truncateSync(fpath); + expect(null).assertFail(); + } catch (e) {} + }); + + /** + * @tc.number SUB_DF_FileIO_TruncateSync_0020 + * @tc.name fileio_test_truncate_sync_002 + * @tc.desc Test truncateSync() interfaces. + */ + it('fileio_test_truncate_sync_002', 0, function () { + try { + fileio.truncateSync(); + expect(null).assertFail(); + } catch (e) {} + }); +}); diff --git a/storage/storagefileiojstest/src/main/js/default/test/module_fileio/members/unlink.test.js b/storage/storagefileiojstest/src/main/js/default/test/module_fileio/members/unlink.test.js new file mode 100644 index 0000000000000000000000000000000000000000..7ee250a89bbff7567fca1e38237df514821e53ae --- /dev/null +++ b/storage/storagefileiojstest/src/main/js/default/test/module_fileio/members/unlink.test.js @@ -0,0 +1,145 @@ +/* + * 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_unlink', function () { + + /** + * @tc.number SUB_DF_FileIO_UnlinkSync_0000 + * @tc.name fileio_test_unlink_sync_000 + * @tc.desc Test unlinkSync() interfaces. + */ + it('fileio_test_unlink_sync_000', 0, function () { + try { + fileio.unlinkSync(); + expect(null).assertFail(); + } catch (e) { + } + }); + + /** + * @tc.number SUB_DF_FileIO_UnlinkSync_0010 + * @tc.name fileio_test_unlink_sync_001 + * @tc.desc Test unlinkSync() interfaces. + */ + it('fileio_test_unlink_sync_001', 0, function () { + let fpath = nextFileName('fileIOTest'); + + try { + fileio.unlinkSync(fpath); + expect(null).assertFail(); + } catch (e) { + } + }); + + /** + * @tc.number SUB_DF_FileIO_UnlinkSync_0020 + * @tc.name fileio_test_unlink_sync_002 + * @tc.desc Test unlinkSync() interfaces. + */ + it('fileio_test_unlink_sync_002', 0, function () { + let fpath = nextFileName('fileio_test_unlink_sync_002'); + 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_unlink_sync_002 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_UnlinkAync_0000 + * @tc.name fileio_test_unlink_async_000 + * @tc.desc Test unlinkAsync() interfaces. + */ + it('fileio_test_unlink_async_000', 0, async function (done) { + let fpath = nextFileName('fileIOTest'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + expect(await fileio.unlink(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_test_unlink_async_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_UnlinkAync_0010 + * @tc.name fileio_test_unlink_async_001 + * @tc.desc Test unlinkAsync() interfaces. + */ + it('fileio_test_unlink_async_001', 0, async function (done) { + let fpath = nextFileName('fileIOTest'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + fileio.unlink(fpath, function (error) { + done(); + }); + } catch (e) { + console.log('fileio_test_unlink_async_001 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_UnlinkSync_0020 + * @tc.name fileio_test_unlink_sync_002 + * @tc.desc Test unlink() interfaces. + */ + it('fileio_test_unlink_async_002', 0, async function (done) { + let fpath = nextFileName('fileio_test_unlink_async_002'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + fileio.unlink(fpath, function (err) { + if (!err) { + done(); + } + }); + } catch (e) { + console.log('fileio_test_unlink_async_002 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_UnlinkSync_0030 + * @tc.name fileio_test_unlink_sync_003 + * @tc.desc Test unlink() interfaces. + */ + it('fileio_test_unlink_async_003', 0, async function (done) { + let fpath = nextFileName('fileio_test_unlink_async_003'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + fileio.unlink(fpath).then(function (err) { + done(); + }); + } catch (e) { + console.log('fileio_test_unlink_async_003 has failed for ' + e); + expect(null).assertFail(); + } + }); +}); diff --git a/storage/storagefileiojstest/src/main/js/default/test/module_fileio/members/write.test.js b/storage/storagefileiojstest/src/main/js/default/test/module_fileio/members/write.test.js new file mode 100644 index 0000000000000000000000000000000000000000..6b0677b2c8ed94cb5a482acdf43dc17b3d044b7c --- /dev/null +++ b/storage/storagefileiojstest/src/main/js/default/test/module_fileio/members/write.test.js @@ -0,0 +1,511 @@ +/* + * 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, nextFileName, isIntNum, + describe, it, expect, +} from '../../Common'; + +describe('fileio_write', function () { + + /** + * @tc.number SUB_DF_FileIO_WriteSync_0000 + * @tc.name fileio_test_write_sync_000 + * @tc.desc Test writeSync() interfaces. + */ + it('fileio_test_write_sync_000', 0, function () { + let fpath = nextFileName('fileio_test_write_sync_000'); + + try { + let fd = fileio.openSync(fpath, 0o102, 0o666); + expect(isIntNum(fd)).assertTrue(); + expect(fileio.writeSync(fd, FILE_CONTENT) == FILE_CONTENT.length).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_test_write_sync_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_WriteSync_0010 + * @tc.name fileio_test_write_sync_001 + * @tc.desc Test writeSync() interfaces. + */ + it('fileio_test_write_sync_001', 0, function () { + let fpath = nextFileName('fileio_test_write_sync_001'); + + try { + let fd = fileio.openSync(fpath, 0o102, 0o666); + expect(isIntNum(fd)).assertTrue(); + expect( + fileio.writeSync(fd, FILE_CONTENT, { + encoding: 'utf-8', + }) + == FILE_CONTENT.length).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_test_write_sync_001 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_WriteSync_0020 + * @tc.name fileio_test_write_sync_002 + * @tc.desc Test writeSync() interfaces. + */ + it('fileio_test_write_sync_002', 0, function () { + let fpath = nextFileName('fileio_test_write_sync_002'); + + try { + let fd = fileio.openSync(fpath, 0o102, 0o666); + expect(isIntNum(fd)).assertTrue(); + expect( + fileio.writeSync(fd, FILE_CONTENT, { + offset: 1, + }) + == FILE_CONTENT.length - 1).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_test_write_sync_002 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_WriteSync_0030 + * @tc.name fileio_test_write_sync_003 + * @tc.desc Test writeSync() interfaces. + */ + it('fileio_test_write_sync_003', 0, function () { + let fpath = nextFileName('fileio_test_write_sync_003'); + + try { + let fd = fileio.openSync(fpath, 0o102, 0o666); + expect(isIntNum(fd)).assertTrue(); + expect( + fileio.writeSync(fd, FILE_CONTENT, { + length: FILE_CONTENT.length - 1, + }) + == FILE_CONTENT.length - 1).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_test_write_sync_003 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_WriteSync_0040 + * @tc.name fileio_test_write_sync_004 + * @tc.desc Test writeSync() interfaces. + */ + it('fileio_test_write_sync_004', 0, function () { + let fpath = nextFileName('fileio_test_write_sync_004'); + + try { + let fd = fileio.openSync(fpath, 0o102, 0o666); + expect(isIntNum(fd)).assertTrue(); + expect( + fileio.writeSync(fd, FILE_CONTENT, { + offset: 1, + length: 1, + }) + == 1).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_test_write_sync_004 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_WriteSync_0050 + * @tc.name fileio_test_write_sync_005 + * @tc.desc Test writeSync() interfaces. + */ + it('fileio_test_write_sync_005', 0, function () { + let fpath = nextFileName('fileio_test_write_sync_005'); + const invalidOffset = 999; + let fd; + + try { + fd = fileio.openSync(fpath, 0o102, 0o666); + expect(isIntNum(fd)).assertTrue(); + expect( + fileio.writeSync(fd, FILE_CONTENT, { + offset: invalidOffset, + }) + == 1).assertTrue(); + expect(null).assertFail(); + } catch (e) { + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_WriteSync_0060 + * @tc.name fileio_test_write_sync_006 + * @tc.desc Test writeSync() interfaces. + */ + it('fileio_test_write_sync_006', 0, function () { + let fpath = nextFileName('fileio_test_write_sync_006'); + const invalidLength = 999; + let fd; + + try { + fd = fileio.openSync(fpath, 0o102, 0o666); + expect(isIntNum(fd)).assertTrue(); + expect( + fileio.writeSync(fd, FILE_CONTENT, { + length: invalidLength, + }) + == 1).assertTrue(); + expect(null).assertFail(); + } catch (e) { + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_WriteSync_0070 + * @tc.name fileio_test_write_sync_007 + * @tc.desc Test writeSync() interfaces. + */ + it('fileio_test_write_sync_007', 0, function () { + try { + fileio.writeSync(); + expect(null).assertFail(); + } catch (e) { + } + }); + + /** + * @tc.number SUB_DF_FileIO_WriteSync_0080 + * @tc.name fileio_test_write_sync_008 + * @tc.desc Test writeSync() interfaces. + */ + it('fileio_test_write_sync_008', 0, function () { + try { + fileio.writeSync(-1, FILE_CONTENT); + expect(null).assertFail(); + } catch (e) { + } + }); + + /** + * @tc.number SUB_DF_FileIO_WriteSync_0090 + * @tc.name fileio_test_write_sync_009 + * @tc.desc Test writeSync() interfaces. + */ + it('fileio_test_write_sync_009', 0, function () { + let fpath = nextFileName('fileio_test_write_sync_009'); + + try { + let fd = fileio.openSync(fpath, 0o102, 0o666); + expect(isIntNum(fd)).assertTrue(); + let writeNum = fileio.writeSync(fd, new ArrayBuffer(4096)); + expect(writeNum == 4096).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + } catch (e) { + console.log('fileio_test_write_sync_009 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_WriteAsync_0000 + * @tc.name fileio_test_write_async_000 + * @tc.desc Test writeAsync() interfaces. + */ + it('fileio_write_async_000', 0, async function (done) { + let fpath = nextFileName('fileio_write_async_000'); + + try { + let fd = fileio.openSync(fpath, 0o102, 0o666); + expect(isIntNum(fd)).assertTrue(); + expect(await fileio.write(fd, FILE_CONTENT) == FILE_CONTENT.length).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_write_async_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_WriteAsync_0010 + * @tc.name fileio_test_write_async_001 + * @tc.desc Test writeAsync() interfaces. + */ + it('fileio_test_write_async_001', 0, async function (done) { + let fpath = nextFileName('fileio_test_write_async_001'); + + try { + let fd = fileio.openSync(fpath, 0o102, 0o666); + expect(isIntNum(fd)).assertTrue(); + let writeNum = await fileio.write(fd, FILE_CONTENT, { + offset: 1, + }); + expect(writeNum == FILE_CONTENT.length - 1).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_test_write_async_001 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_WriteAsync_0020 + * @tc.name fileio_test_write_async_002 + * @tc.desc Test writeAsync() interfaces. + */ + it('fileio_test_write_async_002', 0, async function (done) { + let fpath = nextFileName('fileio_test_write_async_002'); + + try { + let fd = fileio.openSync(fpath, 0o102, 0o666); + expect(isIntNum(fd)).assertTrue(); + let writeNum = await fileio.write(fd, FILE_CONTENT, { + offset: 1, + length: 3, + }); + expect(writeNum == 3).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_test_write_async_002 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_WriteAsync_0030 + * @tc.name fileio_test_write_async_003 + * @tc.desc Test writeAsync() interfaces. + */ + it('fileio_test_write_async_003', 0, async function (done) { + let fpath = nextFileName('fileio_test_write_async_003'); + + try { + let fd = fileio.openSync(fpath, 0o102, 0o666); + expect(isIntNum(fd)).assertTrue(); + let writeNum = await fileio.write(fd, FILE_CONTENT, { + offset: 1, + length: 3, + position: 5, + }); + expect(writeNum == 3).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_test_write_async_003 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_WriteAsync_0040 + * @tc.name fileio_test_write_async_004 + * @tc.desc Test writeAsync() interfaces. + */ + it('fileio_test_write_async_004', 0, async function (done) { + let fpath = nextFileName('fileio_test_write_async_004'); + + try { + let fd = fileio.openSync(fpath, 0o102, 0o666); + expect(isIntNum(fd)).assertTrue(); + let writeNum = await fileio.write(fd, FILE_CONTENT, { + offset: 0, + length: 4, + position: 5, + encoding: 'utf-8', + }); + expect(writeNum == 4).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('fileio_test_write_async_004 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_WriteAsync_0050 + * @tc.name fileio_test_write_async_005 + * @tc.desc Test writeAsync() interfaces. + */ + it('fileio_test_write_async_005', 0, async function (done) { + let fpath = nextFileName('fileio_test_write_async_005'); + + try { + let fd = fileio.openSync(fpath, 0o102, 0o666); + expect(isIntNum(fd)).assertTrue(); + await fileio.write(fd, new ArrayBuffer(4096), function ( + error, + bytesWritten + ) { + expect(bytesWritten == 4096).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + }); + done(); + } catch (e) { + console.log('fileio_test_write_async_005 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_WriteAsync_0060 + * @tc.name fileio_test_write_async_006 + * @tc.desc Test writeAsync() interfaces. + */ + it('fileio_test_write_async_006', 0, async function (done) { + let fpath = nextFileName('fileio_test_write_async_006'); + + try { + let fd = fileio.openSync(fpath, 0o102, 0o666); + expect(isIntNum(fd)).assertTrue(); + await fileio.write( + fd, + FILE_CONTENT, + { + offset: 1, + }, + function (error, bytesWritten) { + expect(bytesWritten == FILE_CONTENT.length - 1).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } + ); + } catch (e) { + console.log('fileio_test_write_async_006 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_WriteAsync_0070 + * @tc.name fileio_test_write_async_007 + * @tc.desc Test writeAsync() interfaces. + */ + it('fileio_test_write_async_007', 0, async function (done) { + let fpath = nextFileName('fileio_test_write_async_007'); + + try { + let fd = fileio.openSync(fpath, 0o102, 0o666); + expect(isIntNum(fd)).assertTrue(); + await fileio.write( + fd, + FILE_CONTENT, + { + offset: 1, + length: 5, + }, + function (error, bytesWritten) { + expect(bytesWritten == 5).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } + ); + } catch (e) { + console.log('fileio_test_write_async_007 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_WriteAsync_0080 + * @tc.name fileio_test_write_async_008 + * @tc.desc Test writeAsync() interfaces. + */ + it('fileio_test_write_async_008', 0, async function (done) { + let fpath = nextFileName('fileio_test_write_async_008'); + + try { + let fd = fileio.openSync(fpath, 0o102, 0o666); + expect(isIntNum(fd)).assertTrue(); + await fileio.write( + fd, + FILE_CONTENT, + { + offset: 1, + length: 5, + position: 5, + }, + function (error, bytesWritten) { + expect(bytesWritten == 5).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } + ); + } catch (e) { + console.log('fileio_test_write_async_008 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_FileIO_WriteAsync_0090 + * @tc.name fileio_test_write_async_009 + * @tc.desc Test writeAsync() interfaces. + */ + it('fileio_test_write_async_009', 0, async function (done) { + let fpath = nextFileName('fileio_test_write_async_009'); + + try { + let fd = fileio.openSync(fpath, 0o102, 0o666); + expect(isIntNum(fd)).assertTrue(); + await fileio.write( + fd, + FILE_CONTENT, + { + offset: 1, + length: 5, + position: 5, + encoding: 'utf-8', + }, + function (error, bytesWritten) { + expect(bytesWritten == 5).assertTrue(); + expect(fileio.closeSync(fd) == null).assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } + ); + } catch (e) { + console.log('fileio_test_write_async_009 has failed for ' + e); + expect(null).assertFail(); + } + }); +});