diff --git a/storage/storagefileiojstest/src/main/js/test/module_fileio/class_randomAccessFile/close.test.js b/storage/storagefileiojstest/src/main/js/test/module_fileio/class_randomAccessFile/close.test.js index 116d80acc4887f81398dc5f8a293a913822de90e..b3d8a5fb5a029b816fe52611543c4db594c5c9b7 100644 --- a/storage/storagefileiojstest/src/main/js/test/module_fileio/class_randomAccessFile/close.test.js +++ b/storage/storagefileiojstest/src/main/js/test/module_fileio/class_randomAccessFile/close.test.js @@ -1,5 +1,5 @@ /* - * Copyright (C) 2021 Huawei Device Co., Ltd. + * Copyright (C) 2022 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 @@ -58,6 +58,7 @@ describe('fileio_randomAccessFile_close', function () { try { randomaccessfile.closeSync(1); + expect(false).assertTrue(); } catch(err) { console.info('fileio_randomaccessfile_close_sync_001 has failed for ' + err); expect(err.message == "Number of arguments unmatched").assertTrue(); diff --git a/storage/storagefileiojstest/src/main/js/test/module_fileio/class_randomAccessFile/read.test.js b/storage/storagefileiojstest/src/main/js/test/module_fileio/class_randomAccessFile/read.test.js index e38c6e8d489af85b18a8228f9959989af7e4dc10..f0c41cc7cdef2b07841eb81c50fd189724671023 100644 --- a/storage/storagefileiojstest/src/main/js/test/module_fileio/class_randomAccessFile/read.test.js +++ b/storage/storagefileiojstest/src/main/js/test/module_fileio/class_randomAccessFile/read.test.js @@ -1,5 +1,5 @@ /* - * Copyright (C) 2021 Huawei Device Co., Ltd. + * Copyright (C) 2022 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 @@ -64,7 +64,7 @@ describe('fileio_randomAccessFile_read', function () { try { let randomaccessfile = fileio.createRandomAccessFileSync(fpath, 0, 0o102); - let length = 4096; + let length = 20; let num = randomaccessfile.writeSync(new ArrayBuffer(length)); expect(num == length).assertTrue(); randomaccessfile.setFilePointerSync(0); @@ -92,7 +92,7 @@ describe('fileio_randomAccessFile_read', function () { try { let randomaccessfile = fileio.createRandomAccessFileSync(fpath, 0, 0o102); - let length = 4096; + let length = 20; let num = randomaccessfile.writeSync(new ArrayBuffer(length)); expect(num == length).assertTrue(); randomaccessfile.setFilePointerSync(0); @@ -120,7 +120,7 @@ describe('fileio_randomAccessFile_read', function () { try { let randomaccessfile = fileio.createRandomAccessFileSync(fpath, 0, 0o102); - let length = 4096; + let length = 20; let num = randomaccessfile.writeSync(new ArrayBuffer(length)); expect(num == length).assertTrue(); randomaccessfile.setFilePointerSync(0); @@ -177,7 +177,7 @@ describe('fileio_randomAccessFile_read', function () { try { let randomaccessfile = fileio.createRandomAccessFileSync(fpath, 0, 0o102); - let length = 4096; + let length = 20; let number = randomaccessfile.readSync(new ArrayBuffer(length), { offset: 1, position: 6 }); expect(number == FILE_CONTENT.length - 6).assertTrue(); randomaccessfile.closeSync(); @@ -204,6 +204,7 @@ describe('fileio_randomAccessFile_read', function () { try { randomaccessfile.readSync(new ArrayBuffer(4096), { offset: -1 }); + expect(false).assertTrue(); } catch (err) { console.info('fileio_randomaccessfile_read_sync_006 has failed for ' + err); expect(err.message == "Invalid buffer/options").assertTrue(); @@ -227,6 +228,7 @@ describe('fileio_randomAccessFile_read', function () { try { randomaccessfile.readSync(new ArrayBuffer(4096), { offset: 1, length: 4096 }); + expect(false).assertTrue(); } catch (err) { console.info('fileio_randomaccessfile_read_sync_007 has failed for ' + err); expect(err.message == "Invalid buffer/options").assertTrue(); @@ -251,6 +253,7 @@ describe('fileio_randomAccessFile_read', function () { try { let length = 4096; randomaccessfile.readSync(new ArrayBuffer(length), { offset: length + 1 }); + expect(false).assertTrue(); } catch (err) { console.info('fileio_randomaccessfile_read_sync_008 has failed for ' + err); expect(err.message == "Invalid buffer/options").assertTrue(); @@ -275,6 +278,7 @@ describe('fileio_randomAccessFile_read', function () { try { let length = 4096; randomaccessfile.readSync(new ArrayBuffer(length), { length: length + 1 }); + expect(false).assertTrue(); } catch (err) { console.info('fileio_randomaccessfile_read_sync_009 has failed for ' + err); expect(err.message == "Invalid buffer/options").assertTrue(); @@ -326,6 +330,7 @@ describe('fileio_randomAccessFile_read', function () { try { randomaccessfile.readSync(); + expect(false).assertTrue(); } catch (err) { console.info('fileio_randomaccessfile_read_sync_011 has failed for ' + err); expect(err.message == "Number of arguments unmatched").assertTrue(); @@ -349,6 +354,7 @@ describe('fileio_randomAccessFile_read', function () { try { randomaccessfile.readSync(new ArrayBuffer(4096), { position: -1 }); + expect(false).assertTrue(); } catch (err) { console.info('fileio_randomaccessfile_read_sync_012 has failed for ' + err); expect(err.message == "Invalid buffer/options").assertTrue(); @@ -358,8 +364,8 @@ describe('fileio_randomAccessFile_read', function () { }); /** - * @tc.number SUB_STORAGE_FILEIO_RANDOMACCESSFILE_READ_SYNC_1200 - * @tc.name fileio_randomaccessfile_read_sync_012 + * @tc.number SUB_STORAGE_FILEIO_RANDOMACCESSFILE_READ_SYNC_1300 + * @tc.name fileio_randomaccessfile_read_sync_013 * @tc.desc Test readSync() interface. When the parameter type is wrong. * @tc.size MEDIUM * @tc.type Function @@ -372,6 +378,7 @@ describe('fileio_randomAccessFile_read', function () { try { randomaccessfile.readSync(''); + expect(false).assertTrue(); } catch (err) { console.info('fileio_randomaccessfile_read_sync_013 has failed for ' + err); expect(err.message == "Invalid buffer/options").assertTrue(); @@ -424,7 +431,7 @@ describe('fileio_randomAccessFile_read', function () { try { fileio.createRandomAccessFile(fpath, 0, 0o102, async function (err, randomaccessfile) { - let length = 4096; + let length = 20; let num = await randomaccessfile.write(new ArrayBuffer(length)); expect(num == length).assertTrue(); randomaccessfile.setFilePointerSync(0); @@ -455,7 +462,7 @@ describe('fileio_randomAccessFile_read', function () { try { let fd = fileio.openSync(fpath, 0o102, 0o666); let randomaccessfile = await fileio.createRandomAccessFile(fd, 0); - let length = 4096; + let length = 20; let num = await randomaccessfile.write(new ArrayBuffer(length)); expect(num == length).assertTrue(); randomaccessfile.setFilePointerSync(0); @@ -485,7 +492,7 @@ describe('fileio_randomAccessFile_read', function () { try { let randomaccessfile = await fileio.createRandomAccessFile(fpath, 0, 0o102); - let length = 4096; + let length = 20; let num = await randomaccessfile.write(new ArrayBuffer(length)); expect(num == length).assertTrue(); randomaccessfile.setFilePointerSync(0); @@ -547,7 +554,7 @@ describe('fileio_randomAccessFile_read', function () { try { let randomaccessfile = await fileio.createRandomAccessFile(fpath, 0, 0o102); - let length = 4096; + let length = 20; let readOut = await randomaccessfile.read(new ArrayBuffer(length), { offset: 1, position: 6 }); expect(readOut.bytesRead == FILE_CONTENT.length - 6).assertTrue(); expect(readOut.offset == 1).assertTrue(); diff --git a/storage/storagefileiojstest/src/main/js/test/module_fileio/class_randomAccessFile/setFilePointer.test.js b/storage/storagefileiojstest/src/main/js/test/module_fileio/class_randomAccessFile/setFilePointer.test.js index a99b3d4badf0872fe2f9ccb674e68b0f43d99bcd..9de6f6f0f332241c3c078acf11755d436ef18ba9 100644 --- a/storage/storagefileiojstest/src/main/js/test/module_fileio/class_randomAccessFile/setFilePointer.test.js +++ b/storage/storagefileiojstest/src/main/js/test/module_fileio/class_randomAccessFile/setFilePointer.test.js @@ -1,5 +1,5 @@ /* - * Copyright (C) 2021 Huawei Device Co., Ltd. + * Copyright (C) 2022 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 @@ -60,6 +60,7 @@ describe('fileio_randomAccessFile_setFilePointer', function () { try { randomaccessfile.setFilePointerSync('5'); + expect(false).assertTrue(); } catch(err) { console.info('fileio_randomaccessfile_set_file_pointer_sync_001 has failed for ' + err); expect(err.message == "Invalid fpointer").assertTrue(); @@ -83,6 +84,7 @@ describe('fileio_randomAccessFile_setFilePointer', function () { try { randomaccessfile.setFilePointerSync(); + expect(false).assertTrue(); } catch(err) { console.info('fileio_randomaccessfile_set_file_pointer_sync_002 has failed for ' + err); expect(err.message == "Number of arguments unmatched").assertTrue(); diff --git a/storage/storagefileiojstest/src/main/js/test/module_fileio/class_randomAccessFile/write.test.js b/storage/storagefileiojstest/src/main/js/test/module_fileio/class_randomAccessFile/write.test.js index c90b93b9ca7ef8e3d8e93f7e8329ff754054bf2b..96f97263bb7e9f06fbf73f107430063fdc0aa76f 100644 --- a/storage/storagefileiojstest/src/main/js/test/module_fileio/class_randomAccessFile/write.test.js +++ b/storage/storagefileiojstest/src/main/js/test/module_fileio/class_randomAccessFile/write.test.js @@ -1,5 +1,5 @@ /* - * Copyright (C) 2021 Huawei Device Co., Ltd. + * Copyright (C) 2022 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 @@ -60,7 +60,7 @@ describe('fileio_randomAccessFile_write', function () { try { let randomaccessfile = fileio.createRandomAccessFileSync(fpath, 0, 0o102); - let length = 4096; + let length = 20; let num = randomaccessfile.writeSync(new ArrayBuffer(length), { offset: 1 }); expect(num == length - 1).assertTrue(); randomaccessfile.closeSync(); @@ -86,7 +86,7 @@ describe('fileio_randomAccessFile_write', function () { try { let fd = fileio.openSync(fpath, 0o102, 0o666); let randomaccessfile = fileio.createRandomAccessFileSync(fd, 0); - let length = 4096; + let length = 20; let num = randomaccessfile.writeSync(new ArrayBuffer(length), { position: 1 }); expect(num == length).assertTrue(); randomaccessfile.closeSync(); @@ -111,7 +111,7 @@ describe('fileio_randomAccessFile_write', function () { try { let randomaccessfile = fileio.createRandomAccessFileSync(fpath, 0, 0o102); - let length = 4096; + let length = 20; let num = randomaccessfile.writeSync(new ArrayBuffer(length), { offset: 1, length: 10 }); expect(num == 10).assertTrue(); randomaccessfile.closeSync(); @@ -196,6 +196,7 @@ describe('fileio_randomAccessFile_write', function () { try { randomaccessfile.writeSync(new ArrayBuffer(4096), { offset: 5, length: 4095 }); + expect(false).assertTrue(); } catch(err) { console.info('fileio_randomaccessfile_write_sync_006 has failed for ' + err); expect(err.message == "Invalid buffer/options").assertTrue(); @@ -220,6 +221,7 @@ describe('fileio_randomAccessFile_write', function () { try { let length = 4096; randomaccessfile.writeSync(new ArrayBuffer(length), { offset: length + 1 }); + expect(false).assertTrue(); } catch(err) { console.info('fileio_randomaccessfile_write_sync_007 has failed for ' + err); expect(err.message == "Invalid buffer/options").assertTrue(); @@ -243,6 +245,7 @@ describe('fileio_randomAccessFile_write', function () { try { randomaccessfile.writeSync(); + expect(false).assertTrue(); } catch(err) { console.info('fileio_randomaccessfile_write_sync_008 has failed for ' + err); expect(err.message == "Number of arguments unmatched").assertTrue(); @@ -267,6 +270,7 @@ describe('fileio_randomAccessFile_write', function () { try { randomaccessfile.writeSync(new ArrayBuffer(4096), { offset: -1 }); + expect(false).assertTrue(); } catch(err) { console.info('fileio_randomaccessfile_write_sync_009 has failed for ' + err); expect(err.message == "Invalid buffer/options").assertTrue(); @@ -315,6 +319,7 @@ describe('fileio_randomAccessFile_write', function () { try { randomaccessfile.writeSync(10, { length: -1 }); + expect(false).assertTrue(); } catch(err) { console.info('fileio_randomaccessfile_write_sync_011 has failed for ' + err); expect(err.message == "Invalid buffer/options").assertTrue(); @@ -339,6 +344,7 @@ describe('fileio_randomAccessFile_write', function () { try { let length = 4096; randomaccessfile.writeSync(new ArrayBuffer(length), { length: length + 1 }); + expect(false).assertTrue(); } catch(err) { console.info('fileio_randomaccessfile_write_sync_012 has failed for ' + err); expect(err.message == "Invalid buffer/options").assertTrue(); @@ -362,6 +368,7 @@ describe('fileio_randomAccessFile_write', function () { try { randomaccessfile.writeSync(new ArrayBuffer(4096), { position: -1 }); + expect(false).assertTrue(); } catch(err) { console.info('fileio_randomaccessfile_write_sync_013 has failed for ' + err); expect(err.message == "Invalid buffer/options").assertTrue(); @@ -412,7 +419,7 @@ describe('fileio_randomAccessFile_write', function () { try { let fd = fileio.openSync(fpath, 0o102, 0o666); let randomaccessfile = await fileio.createRandomAccessFile(fd, 0); - let length = 4096; + let length = 20; randomaccessfile.write(new ArrayBuffer(length), { offset: 1 }, function(err, bytesWritten) { expect(bytesWritten == length - 1).assertTrue(); randomaccessfile.closeSync(); @@ -439,7 +446,7 @@ describe('fileio_randomAccessFile_write', function () { try { let randomaccessfile = await fileio.createRandomAccessFile(fpath, 0, 0o102); - let length = 4096; + let length = 20; let num = await randomaccessfile.write(new ArrayBuffer(length), { position: 1 }); expect(num == length).assertTrue(); randomaccessfile.closeSync(); @@ -465,7 +472,7 @@ describe('fileio_randomAccessFile_write', function () { try { let randomaccessfile = await fileio.createRandomAccessFile(fpath, 0, 0o102); - let length = 4096; + let length = 20; let num = await randomaccessfile.write(new ArrayBuffer(length), { offset: 1, length: 10 }); expect(num == 10).assertTrue(); randomaccessfile.closeSync(); diff --git a/storage/storagefileiojstest/src/main/js/test/module_fileio/members/createRandomAccessFile.test.js b/storage/storagefileiojstest/src/main/js/test/module_fileio/members/createRandomAccessFile.test.js index f3c520c821856861b3b9f06809b97c21b0381ba4..e886c522509ca5261c309110fb9f6e246284a5bf 100644 --- a/storage/storagefileiojstest/src/main/js/test/module_fileio/members/createRandomAccessFile.test.js +++ b/storage/storagefileiojstest/src/main/js/test/module_fileio/members/createRandomAccessFile.test.js @@ -1,5 +1,5 @@ /* - * Copyright (C) 2021 Huawei Device Co., Ltd. + * Copyright (C) 2022 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 @@ -136,6 +136,7 @@ describe('fileio_create_randomAccessFile', function () { try { fileio.createRandomAccessFileSync(fpath, 0, 0o2); + expect(false).assertTrue(); } catch(err) { console.info('fileio_create_randomaccessfile_sync_004 has failed for ' + err); expect(err.message == "No such file or directory").assertTrue(); @@ -154,6 +155,7 @@ describe('fileio_create_randomAccessFile', function () { it('fileio_create_randomaccessfile_sync_005', 0, async function () { try { fileio.createRandomAccessFileSync(-1, 0); + expect(false).assertTrue(); } catch(err) { console.info('fileio_create_randomaccessfile_sync_005 has failed for ' + err); expect(err.message == "Invalid fd").assertTrue(); @@ -175,6 +177,7 @@ describe('fileio_create_randomAccessFile', function () { try { fileio.createRandomAccessFileSync(fd, '1'); + expect(false).assertTrue(); } catch(err) { console.info('fileio_create_randomaccessfile_sync_006 has failed for ' + err); expect(err.message == "Invalid fp").assertTrue(); @@ -198,6 +201,7 @@ describe('fileio_create_randomAccessFile', function () { try { fileio.createRandomAccessFileSync(fd); + expect(false).assertTrue(); } catch(err) { console.info('fileio_create_randomaccessfile_sync_007 has failed for ' + err); expect(err.message == "Number of arguments unmatched").assertTrue(); @@ -246,6 +250,7 @@ describe('fileio_create_randomAccessFile', function () { try { fileio.createRandomAccessFileSync(fpath, 0, 0o302); + expect(false).assertTrue(); } catch(err) { console.info('fileio_create_randomaccessfile_sync_009 has failed for ' + err); expect(err.message == "File exists").assertTrue(); @@ -324,6 +329,7 @@ describe('fileio_create_randomAccessFile', function () { try { fileio.createRandomAccessFileSync(fpath, 0, 0o200002); + expect(false).assertTrue(); } catch(err) { console.info('fileio_create_randomaccessfile_sync_012 has failed for ' + err); expect(err.message == "Not a directory").assertTrue();