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

Detail optimization

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