From 2491ff06546248f85d8378571abcd7bc40e2b96d Mon Sep 17 00:00:00 2001 From: yangbo Date: Tue, 29 Aug 2023 10:54:39 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E8=8E=B7=E5=8F=96=E6=9D=83?= =?UTF-8?q?=E9=99=90=E5=92=8Copen=E7=94=A8=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: yangbo Change-Id: I4d7be3d67b229f2e37319d6d6490a315a3a6e153 --- .../main/ets/test/getExifNoLocation.test.ets | 5 ++ .../main/ets/test/getExifLocation.test.ets | 5 ++ .../entry/src/main/ets/test/open.ets | 79 ++++++++++++++----- 3 files changed, 70 insertions(+), 19 deletions(-) diff --git a/multimedia/medialibrary/mediaLibrary_getExifNoLocation/entry/src/main/ets/test/getExifNoLocation.test.ets b/multimedia/medialibrary/mediaLibrary_getExifNoLocation/entry/src/main/ets/test/getExifNoLocation.test.ets index d9045e9c8..652fa841f 100644 --- a/multimedia/medialibrary/mediaLibrary_getExifNoLocation/entry/src/main/ets/test/getExifNoLocation.test.ets +++ b/multimedia/medialibrary/mediaLibrary_getExifNoLocation/entry/src/main/ets/test/getExifNoLocation.test.ets @@ -26,11 +26,13 @@ export default function getExifNoLocation(abilityContext) { try { let permissions = ["ohos.permission.READ_MEDIA"]; let atManager = abilityAccessCtrl.createAtManager(); + let permissionCheck = false; atManager.requestPermissionsFromUser(abilityContext, permissions, (err, result) => { if (err) { console.info('getPermission failed: ' + JSON.stringify(err)); } else { console.info('getPermission suc: ' + JSON.stringify(result)); + permissionCheck = true; } }); @@ -38,6 +40,9 @@ export default function getExifNoLocation(abilityContext) { await sleep(500); for (let i = 0; i < 10; i++) { + if (permissionCheck) { + break; + } await sleep(500); let button = await driver.findComponent(uitest.ON.text('允许')); if (button != undefined) { diff --git a/multimedia/medialibrary/mediaLibrary_getExiflocation/entry/src/main/ets/test/getExifLocation.test.ets b/multimedia/medialibrary/mediaLibrary_getExiflocation/entry/src/main/ets/test/getExifLocation.test.ets index 7573f49ac..2317d8370 100644 --- a/multimedia/medialibrary/mediaLibrary_getExiflocation/entry/src/main/ets/test/getExifLocation.test.ets +++ b/multimedia/medialibrary/mediaLibrary_getExiflocation/entry/src/main/ets/test/getExifLocation.test.ets @@ -26,11 +26,13 @@ export default function getExifLocation(abilityContext) { try { let permissions = ["ohos.permission.MEDIA_LOCATION", "ohos.permission.READ_MEDIA"]; let atManager = abilityAccessCtrl.createAtManager(); + let permissionCheck = false; atManager.requestPermissionsFromUser(abilityContext, permissions, (err, result) => { if (err) { console.info('getPermission failed: ' + JSON.stringify(err)); } else { console.info('getPermission suc: ' + JSON.stringify(result)); + permissionCheck = true; } }); @@ -38,6 +40,9 @@ export default function getExifLocation(abilityContext) { await sleep(500); for (let i = 0; i < 10; i++) { + if (permissionCheck) { + break; + } await sleep(500); let button = await driver.findComponent(uitest.ON.text('允许')); if (button != undefined) { diff --git a/multimedia/photoAccess/photoAccessSystem/entry/src/main/ets/test/open.ets b/multimedia/photoAccess/photoAccessSystem/entry/src/main/ets/test/open.ets index 090547b6b..7478956bb 100644 --- a/multimedia/photoAccess/photoAccessSystem/entry/src/main/ets/test/open.ets +++ b/multimedia/photoAccess/photoAccessSystem/entry/src/main/ets/test/open.ets @@ -20,6 +20,7 @@ import { photoFetchOption, getFileAsset, getPermission, + sleep, } from '../../../../../../common' export default function openTest() { @@ -30,14 +31,17 @@ export default function openTest() { }) async function rwOpenCallback(done, testNum, fetchOp, assetBytes) { + let asset; + let fd; try { - const asset = await getFileAsset(testNum, fetchOp); - asset.open('rw', async (err, fd) => { + asset = await getFileAsset(testNum, fetchOp); + asset.open('rw', async (err, data) => { try { if (err) { console.info(`${testNum} err: ${err}`); expect(false).assertTrue(); } else { + fd = data; console.info(`${testNum} fd: ${fd}`); let buf = new ArrayBuffer(4096); let res = await fileio.read(fd, buf); @@ -49,72 +53,109 @@ export default function openTest() { } catch (error) { console.info(`${testNum} error: ${error}`); } - await asset.close(fd); done(); }); + await sleep(50); } catch (error) { console.info(`${testNum} failed, error: ${error}`); expect(false).assertTrue(); done(); + } finally { + if (asset) { + await asset.close(fd); + } } }; async function rOpenCallback(done, testNum, fetchOp, assetBytes) { + let asset; + let fd; try { - const asset = await getFileAsset(testNum, fetchOp); - asset.open('r', async (err, fd) => { + asset = await getFileAsset(testNum, fetchOp); + asset.open('r', async (err, data) => { try { if (err) { console.info(`${testNum} err: ${err}`); expect(false).assertTrue(); } else { + fd = data; console.info(`${testNum} fd: ${fd}`); let buf = new ArrayBuffer(4096); - let res = await fileio.read(fd, buf); - expect(res.bytesRead).assertEqual(assetBytes); - console.info(`${testNum} read suc`); - await fileio.write(fd, testNum); - expect(false).assertTrue(); + fileio.read(fd, buf).then((result) => { + expect(result.bytesRead).assertEqual(assetBytes); + }).catch((rErr) => { + console.info(`${testNum} rErr: ${rErr}`); + expect(false).assertTrue(); + }) + await sleep(50); + fileio.write(fd, testNum).then((result) => { + expect(false).assertTrue(); + }).catch((wErr) => { + console.info(`${testNum} wErr: ${wErr}`); + }) + await sleep(50); } } catch (error) { console.info(`${testNum} error: ${error}`); + expect(false).assertTrue(); } - await asset.close(fd); done(); }); + await sleep(50); } catch (error) { console.info(`${testNum} failed, error: ${error}`); expect(false).assertTrue(); done(); + } finally { + if (asset) { + await asset.close(fd); + } } }; async function wOpenCallback(done, testNum, fetchOp) { + let asset; + let fd; try { - const asset = await getFileAsset(testNum, fetchOp); - asset.open('w', async (err, fd) => { + asset = await getFileAsset(testNum, fetchOp); + asset.open('w', async (err, data) => { try { if (err) { console.info(`${testNum} err: ${err}`); expect(false).assertTrue(); } else { - let write = await fileio.write(fd, testNum); - expect(write).assertEqual(testNum.length); - + fd = data; + console.info(`${testNum} fd: ${fd}`); + fileio.write(fd, testNum).then((result) => { + expect(result).assertEqual(testNum.length); + }).catch((wErr) => { + console.info(`${testNum} wErr: ${wErr}`); + expect(false).assertTrue(); + }) + await sleep(50); let buf = new ArrayBuffer(4096); - await fileio.read(fd, buf); - expect(false).assertTrue(); + fileio.read(fd, buf).then((result) => { + expect(false).assertTrue(); + }).catch((rErr) => { + console.info(`${testNum} rErr: ${rErr}`); + }) + await sleep(50); } } catch (error) { console.info(`${testNum} error: ${error}`); + expect(false).assertTrue(); } - await asset.close(fd); done(); }); + await sleep(50); } catch (error) { console.info(`${testNum} failed, error: ${error}`); expect(false).assertTrue(); done(); + } finally { + if (asset) { + await asset.close(fd); + } } }; -- GitLab