diff --git a/storage/storagefileiov9jstest/src/main/js/test/List.test.js b/storage/storagefileiov9jstest/src/main/js/test/List.test.js index 452b378a6ceb2bbf30761a7ad883fa4cd70aa88c..b09726f4ec86a54041b896adb9b5995d8a86e8ff 100644 --- a/storage/storagefileiov9jstest/src/main/js/test/List.test.js +++ b/storage/storagefileiov9jstest/src/main/js/test/List.test.js @@ -21,7 +21,6 @@ import fileIOCreateRandomAccessFile from './members/createRandomAccessFile.test. import fileIOCreateStream from './members/createStream.test.js' import fileIOFdatasync from './members/fdatasync.test.js' import fileIOFdOpenStream from './members/fdopenStream.test.js' -import fileIOFileLock from './members/fileLock.test.js' import fileIOFsync from './members/fsync.test.js' import fileIOHash from './members/hash.test.js' import fileIOListfile from './members/listFile.test.js' @@ -40,6 +39,8 @@ import fileIOReadtext from './members/readtext.test.js' import fileIORename from './members/rename.test.js' import fileIORmdir from './members/rmdir.test' import fileIOStat from './members/stat.test.js' +import fileIOFileLock from './class_file/fileLock.test.js' +import fileIOFileProperties from './class_file/file.test.js' import fileIOStreamClose from './class_stream/close.test.js' import fileIOStreamFlush from './class_stream/flush.test.js' import fileIOStreamRead from './class_stream/read.test.js' @@ -60,6 +61,7 @@ export default function testsuite() { fileIOFdatasync() fileIOFdOpenStream() fileIOFileLock() + fileIOFileProperties() fileIOFsync() fileIOHash() fileIOListfile() diff --git a/storage/storagefileiov9jstest/src/main/js/test/class_file/file.test.js b/storage/storagefileiov9jstest/src/main/js/test/class_file/file.test.js new file mode 100644 index 0000000000000000000000000000000000000000..50aac0e521e729f89996368c97f9e23bd1f842c3 --- /dev/null +++ b/storage/storagefileiov9jstest/src/main/js/test/class_file/file.test.js @@ -0,0 +1,82 @@ +/* + * Copyright (C) 2023 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 featureAbility from '@ohos.ability.featureAbility'; +import { + fileIO, FILE_CONTENT, prepareFile, isIntNum, describe, it, expect, +} from '../Common'; + +export default function fileIOFileProperties() { + describe('fileIO_file_properties', function () { + + /** + * @tc.number SUB_DF_FILEIO_FILE_0000 + * @tc.name fileIO_test_open_file_000 + * @tc.desc Test the properties of the File object. + * The File object is obtained through the open interface. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileIO_test_open_file_000', 0, async function () { + let filesDir = await featureAbility.getContext().getFilesDir(); + let fpath = filesDir + '/fileIO_test_open_file_000'; + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let file = fileIO.openSync(fpath, fileIO.OpenMode.READ_ONLY); + expect(isIntNum(file.fd)).assertTrue(); + expect(file.path === fpath).assertTrue(); + expect(file.name === 'fileIO_test_open_file_000').assertTrue(); + fileIO.closeSync(file); + fileIO.unlinkSync(fpath); + } catch (e) { + console.log('fileIO_test_open_file_000 has failed for ' + e.message + ', code: ' + e.code); + expect(false).assertTrue(); + } + }); + + /** + * @tc.number SUB_DF_FILEIO_FILE_0100 + * @tc.name fileIO_test_dup_file_001 + * @tc.desc Test the properties of the File object. + * The File object is obtained through the dup interface. + * @tc.size MEDIUM + * @tc.type Functoin + * @tc.level Level 0 + * @tc.require + */ + it('fileIO_test_dup_file_001', 0, async function () { + let filesDir = await featureAbility.getContext().getFilesDir(); + let fpath = filesDir + '/fileIO_test_dup_file_001'; + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + + try { + let file = fileIO.openSync(fpath, fileIO.OpenMode.READ_ONLY); + let newFile = fileIO.dup(file.fd); + expect(isIntNum(newFile.fd)).assertTrue(); + expect(newFile.path == fpath).assertTrue(); + expect(file.name === 'fileIO_test_dup_file_001').assertTrue(); + fileIO.closeSync(file); + fileIO.closeSync(newFile); + fileIO.unlinkSync(fpath); + } catch (e) { + console.log('fileIO_test_dup_file_001 has failed for ' + e.message + ', code: ' + e.code); + expect(false).assertTrue(); + } + }); +}); +} diff --git a/storage/storagefileiov9jstest/src/main/js/test/members/fileLock.test.js b/storage/storagefileiov9jstest/src/main/js/test/class_file/fileLock.test.js similarity index 100% rename from storage/storagefileiov9jstest/src/main/js/test/members/fileLock.test.js rename to storage/storagefileiov9jstest/src/main/js/test/class_file/fileLock.test.js