From 11a927376daf855eb74cda78743fa98dea89b1e3 Mon Sep 17 00:00:00 2001 From: WOSHIMAHAIFENG Date: Fri, 19 Apr 2024 11:50:05 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9file=E6=B5=8B=E8=AF=95?= =?UTF-8?q?=E7=94=A8=E4=BE=8B=EF=BC=8C=E9=98=B2=E6=AD=A2ios=E6=B5=8B?= =?UTF-8?q?=E8=AF=95=E5=A4=B1=E8=B4=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../get-file-system-manager.test.js | 66 +++++++++--- .../get-file-system-manager.uvue | 102 ++++++------------ 2 files changed, 84 insertions(+), 84 deletions(-) diff --git a/pages/API/get-file-system-manager/get-file-system-manager.test.js b/pages/API/get-file-system-manager/get-file-system-manager.test.js index de35737a..20e49fb9 100644 --- a/pages/API/get-file-system-manager/get-file-system-manager.test.js +++ b/pages/API/get-file-system-manager/get-file-system-manager.test.js @@ -1137,15 +1137,11 @@ describe('ExtApi-FileManagerTest', () => { function isAndroid() { if (process.env.uniTestPlatformInfo.indexOf('web') > -1 || process.env.UNI_AUTOMATOR_APP_WEBVIEW === 'true') { - it('web', () => { - expect(1).toBe(1) - }) + expect(1).toBe(1) return false } if (process.env.uniTestPlatformInfo.toLocaleLowerCase().startsWith('ios')) { - it('ios', () => { - expect(1).toBe(1) - }) + expect(1).toBe(1) return false } return true @@ -1247,7 +1243,7 @@ describe('ExtApi-FileManagerTest', () => { logAble: false, basePath: basePath }) - await clearDir('') + // await clearDir('') await page.setData({ logAble: false, basePath: globalTempPath, @@ -1341,7 +1337,7 @@ describe('ExtApi-FileManagerTest', () => { if (!isAndroid()) { return } - + console.log('writeTest', 'start') // await clearDir('') await page.setData({ logAble: false, @@ -1351,13 +1347,13 @@ describe('ExtApi-FileManagerTest', () => { writeData: '我是一只小小鸟' }) await createFile() - + console.log('writeTest', '1') let btnWrite = await page.$('#btn-write') await btnWrite.tap() await isDone() let bytesWritten = await getData("bytesWritten") expect(bytesWritten).toEqual(7) - + console.log('writeTest', '2') //writeSyncTest await page.setData({ writeFile: 'fd/1.txt', @@ -1365,18 +1361,19 @@ describe('ExtApi-FileManagerTest', () => { writeData: '我是' }) - btnWrite = await page.$('#btn-write') + btnWrite = await page.$('#btn-write-sync') await btnWrite.tap() await isDone() bytesWritten = await getData("bytesWritten") expect(bytesWritten).toEqual(2) - + console.log('writeTest', '3') //fstatTest let btnFstat = await page.$('#btn-fstat-file') await btnFstat.tap() await isDone() let fstat = await getData("fstat") expect(fstat.size > 0).toBe(true) + console.log('writeTest', '4') //fstatSyncTest btnFstat = await page.$('#btn-fstat-file-sync') @@ -1384,6 +1381,7 @@ describe('ExtApi-FileManagerTest', () => { await isDone() fstat = await getData("fstat") expect(fstat.size > 0).toBe(true) + console.log('writeTest', '5') //ftruncateFileTest let btnFTruncateFile = await page.$('#btn-ftruncate-file') @@ -1394,15 +1392,57 @@ describe('ExtApi-FileManagerTest', () => { await page.setData({ ftruncate: '', }) + console.log('writeTest', '6') + //ftruncateFileSyncTest btnFTruncateFile = await page.$('#btn-ftruncate-file-sync') await btnFTruncateFile.tap() await isDone() ftruncateRet = await getData("ftruncateRet") expect(fstat).not.toEqual('ftruncate:ok') - + console.log('writeTest', '7') }); + //writeTest writeSyncTest + it('ftruncateFileTest', async () => { + if (!isAndroid()) { + return + } + console.log('ftruncateFileTest', 'start') + // await clearDir('') + await page.setData({ + logAble: false, + mkdirFile: 'fd', + writeFile: 'fd/1.txt', + readFile: 'fd/1.txt', + writeData: '我是一只小小鸟我是' + }) + await createFile() + console.log('ftruncateFileTest', '1') + btnWrite = await page.$('#btn-write-sync') + await btnWrite.tap() + await isDone() + bytesWritten = await getData("bytesWritten") + expect(bytesWritten).toEqual(9) + console.log('ftruncateFileTest', '3') + //ftruncateFileTest + let btnFTruncateFile = await page.$('#btn-ftruncate-file') + await btnFTruncateFile.tap() + await isDone() + let ftruncateRet = await getData("ftruncateRet") + expect(ftruncateRet).toEqual('ftruncate:ok') + await page.setData({ + ftruncate: '', + }) + console.log('ftruncateFileTest', '6') + //ftruncateFileSyncTest + btnFTruncateFile = await page.$('#btn-ftruncate-file-sync') + await btnFTruncateFile.tap() + await isDone() + ftruncateRet = await getData("ftruncateRet") + expect(ftruncateRet).toEqual('ftruncate:ok') + console.log('ftruncateFileTest', '7') + }); //saveFileTest saveFileSyncTest getSavedFileListTest removeSavedFileTest it('savefile test', async () => { diff --git a/pages/API/get-file-system-manager/get-file-system-manager.uvue b/pages/API/get-file-system-manager/get-file-system-manager.uvue index d1b1e0b5..96976677 100644 --- a/pages/API/get-file-system-manager/get-file-system-manager.uvue +++ b/pages/API/get-file-system-manager/get-file-system-manager.uvue @@ -66,7 +66,7 @@ - + @@ -135,7 +135,7 @@ fstat: null as Stats | null, ftruncateRet: '', readZipFile: 'to.zip', - getSavedFileListRet:'', + getSavedFileListRet: '', /** * 待测试的全局环境变量 */ @@ -1007,87 +1007,47 @@ closeSyncTest() { console.log('closeSyncTest') const fileManager = uni.getFileSystemManager() - fileManager.open({ - filePath: `${this.basePath}${this.readFile}`, - flag: "r+", - success: (res : OpenFileSuccessResult) => { - console.log("success", res) - if (res.fd.length <= 0) { - this.done = true - return - } - try { - console.log('closeSync') - fileManager.closeSync({ - fd: res.fd - } as CloseSyncOptions) - if (this.logAble) { - this.log += 'closeSyncTest success:' + '\n\n' - } - this.done = true - this.closeFileRet = "close:ok" - } catch (e) { - if (this.logAble) { - this.log += 'closeSyncTest fail:' + JSON.stringify(e) + '\n\n' - } - console.log('fail', e) - this.done = true - } - - }, - fail: (res : UniError) => { - if (this.logAble) { - this.log += 'openFileTest fail:' + JSON.stringify(res) + '\n\n' - } - console.log('fail', res) - this.lastFailError = res - this.done = true + try { + console.log('closeSync') + fileManager.closeSync({ + fd: this.openFileSyncTest() + } as CloseSyncOptions) + if (this.logAble) { + this.log += 'closeSyncTest success:' + '\n\n' } - } as OpenFileOptions) - + this.done = true + this.closeFileRet = "close:ok" + } catch (e) { + if (this.logAble) { + this.log += 'closeSyncTest fail:' + JSON.stringify(e) + '\n\n' + } + console.log('fail', e) + this.done = true + } }, closeTest() { const fileManager = uni.getFileSystemManager() - fileManager.open({ - filePath: `${this.basePath}${this.readFile}`, - flag: "r+", - success: (res : OpenFileSuccessResult) => { - console.log("success", res) - if (res.fd.length <= 0) { - this.done = true - return + fileManager.close({ + fd: this.openFileSyncTest(), + success: (res : FileManagerSuccessResult) => { + if (this.logAble) { + this.log += 'closeTest success:' + JSON.stringify(res) + '\n\n' } - fileManager.close({ - fd: res.fd, - success: (res : FileManagerSuccessResult) => { - if (this.logAble) { - this.log += 'closeTest success:' + JSON.stringify(res) + '\n\n' - } - this.closeFileRet = res.errMsg - console.log("success", res) - }, - fail: (res : UniError) => { - if (this.logAble) { - this.log += 'closeTest fail:' + JSON.stringify(res) + '\n\n' - } - console.log('fail', res) - this.lastFailError = res - }, - complete: (_) => { - this.done = true - } - - } as CloseOptions) + this.closeFileRet = res.errMsg + console.log("success", res) }, fail: (res : UniError) => { if (this.logAble) { - this.log += 'openFileTest fail:' + JSON.stringify(res) + '\n\n' + this.log += 'closeTest fail:' + JSON.stringify(res) + '\n\n' } console.log('fail', res) this.lastFailError = res + }, + complete: (_) => { this.done = true } - } as OpenFileOptions) + + } as CloseOptions) }, writeTest() { const fileManager = uni.getFileSystemManager() @@ -1257,7 +1217,7 @@ this.log += 'ftruncateFileSyncTest success:' + '\n\n' } this.done = true - this.ftruncateRet = '' + this.ftruncateRet = 'ftruncate:ok' } catch (e) { if (this.logAble) { this.log += 'ftruncateFileSyncTest fail:' + JSON.stringify(e) + '\n\n' -- GitLab