提交 96d9ac29 编写于 作者: C caochuan

Detail optimization

 - mediaLibrary_album
 - mediaLibrary_base
Signed-off-by: Ncaochuan <caochuan@huawei.com>
上级 707d9743
...@@ -62,22 +62,7 @@ export default function albumGetFileAssetsCallbackTest(abilityContext) { ...@@ -62,22 +62,7 @@ export default function albumGetFileAssetsCallbackTest(abilityContext) {
const albumCountPass = await checkAlbumsCount(done, testNum, albumList, expectAlbumCount); const albumCountPass = await checkAlbumsCount(done, testNum, albumList, expectAlbumCount);
if (!albumCountPass) return; if (!albumCountPass) return;
// one asset type // one asset type
if (expectAlbumCount == 1) {
const album = albumList[0];
album.getFileAssets(allFetchOp({ order: `date_added DESC LIMIT 0,${expectAssetsCount}` }), (error, fetchFileResult) => {
if (fetchFileResult == undefined || error) {
console.info(`${testNum} fetchFileResult undefined or error, error: ${error}`)
expect(false).assertTrue();
done();
return;
}
console.info(`${testNum}, getCount: ${fetchFileResult.getCount()}`)
console.info(`${testNum}, expectAssetsCount: ${expectAssetsCount}`)
expect(fetchFileResult.getCount()).assertEqual(expectAssetsCount);
done();
});
} else {
// more asset type
let count = 0; let count = 0;
for (const album of albumList) { for (const album of albumList) {
album.getFileAssets(allFetchOp({ order: `date_added DESC LIMIT 0,${expectAssetsCount}` }), (error, fetchFileResult) => { album.getFileAssets(allFetchOp({ order: `date_added DESC LIMIT 0,${expectAssetsCount}` }), (error, fetchFileResult) => {
...@@ -88,8 +73,8 @@ export default function albumGetFileAssetsCallbackTest(abilityContext) { ...@@ -88,8 +73,8 @@ export default function albumGetFileAssetsCallbackTest(abilityContext) {
return; return;
} }
count++; count++;
console.info(`${testNum}, getCount: ${fetchFileResult.getCount()}`) console.info(`${testNum}, expectAssetsCount: ${expectAssetsCount}
console.info(`${testNum}, expectAssetsCount: ${expectAssetsCount}`) getCount: ${fetchFileResult.getCount()}`)
expect(fetchFileResult.getCount()).assertEqual(expectAssetsCount); expect(fetchFileResult.getCount()).assertEqual(expectAssetsCount);
}); });
await sleep(500) await sleep(500)
...@@ -97,7 +82,6 @@ export default function albumGetFileAssetsCallbackTest(abilityContext) { ...@@ -97,7 +82,6 @@ export default function albumGetFileAssetsCallbackTest(abilityContext) {
await sleep(500) await sleep(500)
expect(count).assertEqual(expectAlbumCount); expect(count).assertEqual(expectAlbumCount);
done(); done();
}
} catch (error) { } catch (error) {
console.info(`${testNum}, error: ${error}`) console.info(`${testNum}, error: ${error}`)
expect(false).assertTrue(); expect(false).assertTrue();
......
...@@ -62,22 +62,6 @@ export default function albumGetFileAssetsPromiseTest(abilityContext) { ...@@ -62,22 +62,6 @@ export default function albumGetFileAssetsPromiseTest(abilityContext) {
// one asset type // one asset type
let op: mediaLibrary.MediaFetchOptions = let op: mediaLibrary.MediaFetchOptions =
allFetchOp({ order: `date_added DESC LIMIT 0,${expectAssetsCount}` }) allFetchOp({ order: `date_added DESC LIMIT 0,${expectAssetsCount}` })
if (expectAlbumCount == 1) {
const album = albumList[0];
let fetchFileResult = await album.getFileAssets(op);
if (fetchFileResult == undefined) {
console.info(`${testNum} fetchFileResult undefined`)
expect(false).assertTrue();
done();
return;
}
console.info(`${testNum}, getCount: ${fetchFileResult.getCount()}`)
console.info(`${testNum}, expectAssetsCount: ${expectAssetsCount}`)
expect(fetchFileResult.getCount()).assertEqual(expectAssetsCount);
done();
} else {
// more asset type
let count = 0; let count = 0;
for (const album of albumList) { for (const album of albumList) {
let fetchFileResult = await album.getFileAssets(op); let fetchFileResult = await album.getFileAssets(op);
...@@ -88,13 +72,12 @@ export default function albumGetFileAssetsPromiseTest(abilityContext) { ...@@ -88,13 +72,12 @@ export default function albumGetFileAssetsPromiseTest(abilityContext) {
return; return;
} }
count++; count++;
console.info(`${testNum}, getCount: ${fetchFileResult.getCount()}`) console.info(`${testNum}, expectAssetsCount: ${expectAssetsCount}
console.info(`${testNum}, expectAssetsCount: ${expectAssetsCount}`) getCount: ${fetchFileResult.getCount()}`)
expect(fetchFileResult.getCount()).assertEqual(expectAssetsCount); expect(fetchFileResult.getCount()).assertEqual(expectAssetsCount);
} }
expect(count).assertEqual(expectAlbumCount); expect(count).assertEqual(expectAlbumCount);
done(); done();
}
} catch (error) { } catch (error) {
console.info(`${testNum}, error: ${error}`) console.info(`${testNum}, error: ${error}`)
expect(false).assertTrue(); expect(false).assertTrue();
......
...@@ -51,13 +51,13 @@ export default function albumTestCallbackTest(abilityContext) { ...@@ -51,13 +51,13 @@ export default function albumTestCallbackTest(abilityContext) {
}); });
function printAlbumMessage(testNum, album) { function printAlbumMessage(testNum, album) {
console.info(`${testNum} album.albumId: ${album.albumId}`); console.info(`${testNum} album.albumId: ${album.albumId}
console.info(`${testNum} album.albumName: ${album.albumName}`); album.albumName: ${album.albumName}
console.info(`${testNum} album.albumUri: ${album.albumUri}`); album.albumUri: ${album.albumUri}
console.info(`${testNum} album.dateModified: ${album.dateModified}`); album.dateModified: ${album.dateModified}
console.info(`${testNum} album.count: ${album.count}`); album.count: ${album.count}
console.info(`${testNum} album.relativePath: ${album.relativePath}`); album.relativePath: ${album.relativePath}
console.info(`${testNum} album.coverUri: ${album.coverUri}`); album.coverUri: ${album.coverUri}`);
} }
const props = { const props = {
...@@ -148,8 +148,7 @@ export default function albumTestCallbackTest(abilityContext) { ...@@ -148,8 +148,7 @@ export default function albumTestCallbackTest(abilityContext) {
const album = albumList[0]; const album = albumList[0];
album.albumName = newName; album.albumName = newName;
album.commitModify(async (error) => { album.commitModify(async (error) => {
console.info(`${testNum}, error.message: ${error.message}`) console.info(`${testNum}, error.message: ${error.message} error.code: ${error.code}`)
console.info(`${testNum}, error.code: ${error.code}`)
expect(error.code != undefined).assertTrue(); expect(error.code != undefined).assertTrue();
done(); done();
}); });
......
...@@ -50,13 +50,13 @@ export default function albumTestPromiseTest(abilityContext) { ...@@ -50,13 +50,13 @@ export default function albumTestPromiseTest(abilityContext) {
}); });
function printAlbumMessage(testNum, album) { function printAlbumMessage(testNum, album) {
console.info(`${testNum} album.albumId: ${album.albumId}`); console.info(`${testNum} album.albumId: ${album.albumId}
console.info(`${testNum} album.albumName: ${album.albumName}`); album.albumName: ${album.albumName}
console.info(`${testNum} album.albumUri: ${album.albumUri}`); album.albumUri: ${album.albumUri}
console.info(`${testNum} album.dateModified: ${album.dateModified}`); album.dateModified: ${album.dateModified}
console.info(`${testNum} album.count: ${album.count}`); album.count: ${album.count}
console.info(`${testNum} album.relativePath: ${album.relativePath}`); album.relativePath: ${album.relativePath}
console.info(`${testNum} album.coverUri: ${album.coverUri}`); album.coverUri: ${album.coverUri}`);
} }
const props = { const props = {
...@@ -115,7 +115,6 @@ export default function albumTestPromiseTest(abilityContext) { ...@@ -115,7 +115,6 @@ export default function albumTestPromiseTest(abilityContext) {
const abnormalAlbumCount = async function (done, testNum, fetchOp) { const abnormalAlbumCount = async function (done, testNum, fetchOp) {
try { try {
const albumList = await media.getAlbums(fetchOp); const albumList = await media.getAlbums(fetchOp);
console.info(`${testNum}, albumList.length: ${albumList.length}`) console.info(`${testNum}, albumList.length: ${albumList.length}`)
expect(albumList.length).assertEqual(0); expect(albumList.length).assertEqual(0);
...@@ -139,8 +138,7 @@ export default function albumTestPromiseTest(abilityContext) { ...@@ -139,8 +138,7 @@ export default function albumTestPromiseTest(abilityContext) {
expect(false).assertTrue(); expect(false).assertTrue();
done(); done();
} catch (error) { } catch (error) {
console.info(`${testNum}, error.message: ${error.message}`) console.info(`${testNum}, error.message: ${error.message} error.code: ${error.code}`)
console.info(`${testNum}, error.code: ${error.code}`)
expect(error.code!=undefined).assertTrue(); expect(error.code!=undefined).assertTrue();
done(); done();
} }
......
...@@ -276,14 +276,14 @@ export default function mediaLibraryTestCallback(abilityContext) { ...@@ -276,14 +276,14 @@ export default function mediaLibraryTestCallback(abilityContext) {
await asset.close(fd); await asset.close(fd);
try { try {
media.createAsset(type, name, path, async (err, creatAsset) => { media.createAsset(type, name, path, async (err, creatAsset) => {
if (err || creatAsset == undefined) { if (err != undefined) {
expect(true).assertTrue(); expect(true).assertTrue();
done(); done();
return; return;
} else { }
expect(false).assertTrue(); expect(false).assertTrue();
done(); done();
}
}); });
} catch (error) { } catch (error) {
console.info(`${testNum}:: error :${error}`); console.info(`${testNum}:: error :${error}`);
......
...@@ -50,8 +50,8 @@ export default function mediaLibraryTestPromiseOnOffTest(abilityContext) { ...@@ -50,8 +50,8 @@ export default function mediaLibraryTestPromiseOnOffTest(abilityContext) {
const onTest = async (done, testNum, type, fetchOps) => { const onTest = async (done, testNum, type, fetchOps) => {
try { try {
let conut = 0; let count = 0;
media.on(type, () => { conut++; }); media.on(type, () => { count++; });
const fetchFileResult = await media.getFileAssets(fetchOps); const fetchFileResult = await media.getFileAssets(fetchOps);
let checkAssetCountPass = await checkAssetsCount(done, testNum, fetchFileResult, 1); let checkAssetCountPass = await checkAssetsCount(done, testNum, fetchFileResult, 1);
if (!checkAssetCountPass) return; if (!checkAssetCountPass) return;
...@@ -59,7 +59,7 @@ export default function mediaLibraryTestPromiseOnOffTest(abilityContext) { ...@@ -59,7 +59,7 @@ export default function mediaLibraryTestPromiseOnOffTest(abilityContext) {
asset.title = asset.title + 'changename'; asset.title = asset.title + 'changename';
await asset.commitModify(); await asset.commitModify();
await sleep(1000) await sleep(1000)
expect(conut > 0).assertTrue(); expect(count > 0).assertTrue();
done(); done();
} catch (error) { } catch (error) {
console.info(`${testNum}:: error :${error}`); console.info(`${testNum}:: error :${error}`);
...@@ -69,21 +69,19 @@ export default function mediaLibraryTestPromiseOnOffTest(abilityContext) { ...@@ -69,21 +69,19 @@ export default function mediaLibraryTestPromiseOnOffTest(abilityContext) {
} }
const offTest = async (done, testNum, type, fetchOps) => { const offTest = async (done, testNum, type, fetchOps) => {
try { try {
let conut = 0; let count = 0;
media.on(type, () => { media.on(type, () => {
conut++; count++;
}); });
await sleep(200)
const fetchFileResult = await media.getFileAssets(fetchOps); const fetchFileResult = await media.getFileAssets(fetchOps);
let checkAssetCountPass = await checkAssetsCount(done, testNum, fetchFileResult, 1); let checkAssetCountPass = await checkAssetsCount(done, testNum, fetchFileResult, 1);
if (!checkAssetCountPass) return; if (!checkAssetCountPass) return;
const asset = await fetchFileResult.getFirstObject(); const asset = await fetchFileResult.getFirstObject();
asset.title = asset.title + 'changename'; asset.title = asset.title + 'changename';
media.off(type); media.off(type);
await sleep(200)
await asset.commitModify(); await asset.commitModify();
await sleep(1000) await sleep(1000)
expect(conut).assertEqual(0); expect(count).assertEqual(0);
done(); done();
} catch (error) { } catch (error) {
console.info(`${testNum}:: error :${error}`); console.info(`${testNum}:: error :${error}`);
...@@ -162,9 +160,9 @@ export default function mediaLibraryTestPromiseOnOffTest(abilityContext) { ...@@ -162,9 +160,9 @@ export default function mediaLibraryTestPromiseOnOffTest(abilityContext) {
it('SUB_MEDIA_MEDIALIBRARY_PROMISE_ON_005', 0, async function (done) { it('SUB_MEDIA_MEDIALIBRARY_PROMISE_ON_005', 0, async function (done) {
let testNum = 'SUB_MEDIA_MEDIALIBRARY_PROMISE_ON_005' let testNum = 'SUB_MEDIA_MEDIALIBRARY_PROMISE_ON_005'
try { try {
let conut = 0; let count = 0;
media.on('albumChange', () => { media.on('albumChange', () => {
conut++; count++;
}); });
let currentFetchOps = albumFetchOps(testNum, 'Pictures/', 'OnAlbum', IMAGE_TYPE); let currentFetchOps = albumFetchOps(testNum, 'Pictures/', 'OnAlbum', IMAGE_TYPE);
const albumList = await media.getAlbums(currentFetchOps); const albumList = await media.getAlbums(currentFetchOps);
...@@ -175,7 +173,7 @@ export default function mediaLibraryTestPromiseOnOffTest(abilityContext) { ...@@ -175,7 +173,7 @@ export default function mediaLibraryTestPromiseOnOffTest(abilityContext) {
album.albumName = album.albumName + 'changename'; album.albumName = album.albumName + 'changename';
await album.commitModify(); await album.commitModify();
await sleep(1000) await sleep(1000)
expect(conut > 0).assertTrue(); expect(count > 0).assertTrue();
album.albumName = oldName; album.albumName = oldName;
await album.commitModify(); await album.commitModify();
done(); done();
...@@ -197,12 +195,12 @@ export default function mediaLibraryTestPromiseOnOffTest(abilityContext) { ...@@ -197,12 +195,12 @@ export default function mediaLibraryTestPromiseOnOffTest(abilityContext) {
it('SUB_MEDIA_MEDIALIBRARY_PROMISE_ON_006', 0, async function (done) { it('SUB_MEDIA_MEDIALIBRARY_PROMISE_ON_006', 0, async function (done) {
let testNum = 'SUB_MEDIA_MEDIALIBRARY_PROMISE_ON_006' let testNum = 'SUB_MEDIA_MEDIALIBRARY_PROMISE_ON_006'
try { try {
let conut = 0; let count = 0;
expect(true).assertTrue(); expect(true).assertTrue();
done(); done();
media.on('deviceChange', () => { media.on('deviceChange', () => {
console.info('MediaLibraryTest : on 006 callback'); console.info('MediaLibraryTest : on 006 callback');
conut++; count++;
}); });
let currentFetchOps = fetchOps(testNum, 'Documents/On/', FILE_TYPE); let currentFetchOps = fetchOps(testNum, 'Documents/On/', FILE_TYPE);
const fetchFileResult = await media.getFileAssets(currentFetchOps); const fetchFileResult = await media.getFileAssets(currentFetchOps);
...@@ -214,7 +212,7 @@ export default function mediaLibraryTestPromiseOnOffTest(abilityContext) { ...@@ -214,7 +212,7 @@ export default function mediaLibraryTestPromiseOnOffTest(abilityContext) {
res(true) res(true)
}, 1000) }, 1000)
}) })
expect(conut == 0).assertTrue(); expect(count == 0).assertTrue();
done(); done();
} catch (error) { } catch (error) {
console.info(`MediaLibraryTest : on 006 failed, error: ${error}`); console.info(`MediaLibraryTest : on 006 failed, error: ${error}`);
...@@ -235,12 +233,12 @@ export default function mediaLibraryTestPromiseOnOffTest(abilityContext) { ...@@ -235,12 +233,12 @@ export default function mediaLibraryTestPromiseOnOffTest(abilityContext) {
it('SUB_MEDIA_MEDIALIBRARY_PROMISE_ON_007', 0, async function (done) { it('SUB_MEDIA_MEDIALIBRARY_PROMISE_ON_007', 0, async function (done) {
let testNum = 'SUB_MEDIA_MEDIALIBRARY_PROMISE_ON_007' let testNum = 'SUB_MEDIA_MEDIALIBRARY_PROMISE_ON_007'
try { try {
let conut = 0; let count = 0;
expect(true).assertTrue(); expect(true).assertTrue();
done(); done();
media.on('remoteFileChange', () => { media.on('remoteFileChange', () => {
console.info('MediaLibraryTest : on 007 callback'); console.info('MediaLibraryTest : on 007 callback');
conut++; count++;
}); });
let currentFetchOps = fetchOps(testNum, 'Documents/On/', FILE_TYPE); let currentFetchOps = fetchOps(testNum, 'Documents/On/', FILE_TYPE);
...@@ -253,7 +251,7 @@ export default function mediaLibraryTestPromiseOnOffTest(abilityContext) { ...@@ -253,7 +251,7 @@ export default function mediaLibraryTestPromiseOnOffTest(abilityContext) {
res(true) res(true)
}, 1000) }, 1000)
}) })
expect(conut == 0).assertTrue(); expect(count == 0).assertTrue();
done(); done();
} catch (error) { } catch (error) {
console.info(`MediaLibraryTest : on 006 failed, error: ${error}`); console.info(`MediaLibraryTest : on 006 failed, error: ${error}`);
...@@ -334,9 +332,9 @@ export default function mediaLibraryTestPromiseOnOffTest(abilityContext) { ...@@ -334,9 +332,9 @@ export default function mediaLibraryTestPromiseOnOffTest(abilityContext) {
it('SUB_MEDIA_MEDIALIBRARY_PROMISE_OFF_005', 0, async function (done) { it('SUB_MEDIA_MEDIALIBRARY_PROMISE_OFF_005', 0, async function (done) {
let testNum = 'SUB_MEDIA_MEDIALIBRARY_PROMISE_OFF_005' let testNum = 'SUB_MEDIA_MEDIALIBRARY_PROMISE_OFF_005'
try { try {
let conut = 0; let count = 0;
media.on('albumChange', () => { media.on('albumChange', () => {
conut++; count++;
}); });
await sleep(300) await sleep(300)
media.off('albumChange'); media.off('albumChange');
...@@ -352,7 +350,7 @@ export default function mediaLibraryTestPromiseOnOffTest(abilityContext) { ...@@ -352,7 +350,7 @@ export default function mediaLibraryTestPromiseOnOffTest(abilityContext) {
await sleep(300) await sleep(300)
album.albumName = oldName; album.albumName = oldName;
await album.commitModify(); await album.commitModify();
expect(conut).assertEqual(0); expect(count).assertEqual(0);
done(); done();
} catch (error) { } catch (error) {
console.info(`${testNum}:: error :${error}`); console.info(`${testNum}:: error :${error}`);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册