修改获取缓存中的图片格式大小的单元测试

Signed-off-by: tyBrave <tianyong21@h-partners.com>
This commit is contained in:
tyBrave 2024-10-16 17:17:02 +08:00
parent e31c592ee4
commit 8e55d336f9
3 changed files with 45 additions and 32 deletions

View File

@ -1,3 +1,18 @@
/*
* Copyright (C) 2024 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an 'AS IS' BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { drawing, common2D } from '@kit.ArkGraphics2D'; import { drawing, common2D } from '@kit.ArkGraphics2D';
import { ImageKnifeComponent, ImageKnifeOption } from '@ohos/imageknife'; import { ImageKnifeComponent, ImageKnifeOption } from '@ohos/imageknife';

View File

@ -18,6 +18,7 @@ import ImageKnifeOptionTest from './ImageKnifeOption.test';
import MemoryLruCacheTest from './MemoryLruCache.test'; import MemoryLruCacheTest from './MemoryLruCache.test';
import ImageKnifeTest from './ImageKnife.test'; import ImageKnifeTest from './ImageKnife.test';
import Transform from './transform.test'; import Transform from './transform.test';
import imageFormatAndSize from './imageFormatAndSize.test'
export default function testsuite() { export default function testsuite() {
MemoryLruCacheTest(); MemoryLruCacheTest();
@ -26,4 +27,5 @@ export default function testsuite() {
ImageKnifeOptionTest(); ImageKnifeOptionTest();
ImageKnifeTest(); ImageKnifeTest();
Transform(); Transform();
imageFormatAndSize();
} }

View File

@ -13,15 +13,10 @@
* limitations under the License. * limitations under the License.
*/ */
import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium'; import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium';
import { import { ImageKnifeOption, ImageKnife, ImageKnifeRequest, ImageKnifeRequestSource } from "@ohos/imageknife"
ImageKnifeOption,
ImageKnife,
ImageKnifeRequest,
ImageKnifeRequestSource
} from "@ohos/imageknife"
import { common } from '@kit.AbilityKit'; import { common } from '@kit.AbilityKit';
export default function ImageKnifeOptionTest() { export default function imageFormatAndSize() {
describe('imageFormatAndSize', () => { describe('imageFormatAndSize', () => {
// Defines a test suite. Two parameters are supported: test suite name and test suite function. // Defines a test suite. Two parameters are supported: test suite name and test suite function.
beforeAll(() => { beforeAll(() => {
@ -42,41 +37,42 @@ export default function ImageKnifeOptionTest() {
// Presets a clear action, which is performed after all test cases of the test suite end. // Presets a clear action, which is performed after all test cases of the test suite end.
// This API supports only one parameter: clear action function. // This API supports only one parameter: clear action function.
}); });
it('getImageSizeInCache', 0, () => { it('getImageSizeInCache', 0, async () => {
let width = 0; let width = 0;
let height = 0; let height = 0;
let imageFormat: string = ""; let imageFormat: string = "";
let imageKnifeOption: ImageKnifeOption = new ImageKnifeOption({ let imageKnifeOption: ImageKnifeOption = new ImageKnifeOption({
loadSrc: "https://q7.itc.cn/images01/20240223/ce80229bf9934dff97cdf2ad7be1dcb8.jpeg", loadSrc: $r('app.media.icon'),
onLoadListener: {
onLoadSuccess: (data, imageknifeData) => {
width = imageknifeData.imageWidth!
height = imageknifeData.imageHeight!
imageFormat = imageknifeData.type!
return data;
},
},
}) })
await new Promise<string>((resolve, reject) => {
let request = new ImageKnifeRequest( imageKnifeOption.onLoadListener = {
imageKnifeOption, onLoadSuccess: (data, imageknifeData) => {
getContext() as common.UIAbilityContext, width = imageknifeData.imageWidth
100, height = imageknifeData.imageHeight
100, imageFormat = imageknifeData.type!
0, resolve("")
{ },
showPixelMap: async (version: number, pixelMap: PixelMap | string, onLoadFailed(err) {
requestSource: ImageKnifeRequestSource) => { reject(err)
} }
}) }
ImageKnife.getInstance().execute(request); let request = new ImageKnifeRequest(
imageKnifeOption,
imageKnifeOption.context !== undefined ? imageKnifeOption.context : getContext() as common.UIAbilityContext,
0,
0,
0,
{
showPixelMap(version: number, pixelMap: PixelMap | string) {
}
}
)
ImageKnife.getInstance().execute(request);
})
expect(width != 0).assertTrue(); expect(width != 0).assertTrue();
expect(height != 0).assertTrue(); expect(height != 0).assertTrue();
expect(imageFormat != "").assertTrue(); expect(imageFormat != "").assertTrue();
}); });
}); });
} }