修改获取缓存中的图片格式大小的单元测试
Signed-off-by: tyBrave <tianyong21@h-partners.com>
This commit is contained in:
parent
e31c592ee4
commit
8e55d336f9
|
@ -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 { ImageKnifeComponent, ImageKnifeOption } from '@ohos/imageknife';
|
||||
|
||||
|
|
|
@ -18,6 +18,7 @@ import ImageKnifeOptionTest from './ImageKnifeOption.test';
|
|||
import MemoryLruCacheTest from './MemoryLruCache.test';
|
||||
import ImageKnifeTest from './ImageKnife.test';
|
||||
import Transform from './transform.test';
|
||||
import imageFormatAndSize from './imageFormatAndSize.test'
|
||||
|
||||
export default function testsuite() {
|
||||
MemoryLruCacheTest();
|
||||
|
@ -26,4 +27,5 @@ export default function testsuite() {
|
|||
ImageKnifeOptionTest();
|
||||
ImageKnifeTest();
|
||||
Transform();
|
||||
imageFormatAndSize();
|
||||
}
|
|
@ -13,15 +13,10 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium';
|
||||
import {
|
||||
ImageKnifeOption,
|
||||
ImageKnife,
|
||||
ImageKnifeRequest,
|
||||
ImageKnifeRequestSource
|
||||
} from "@ohos/imageknife"
|
||||
import { ImageKnifeOption, ImageKnife, ImageKnifeRequest, ImageKnifeRequestSource } from "@ohos/imageknife"
|
||||
import { common } from '@kit.AbilityKit';
|
||||
|
||||
export default function ImageKnifeOptionTest() {
|
||||
export default function imageFormatAndSize() {
|
||||
describe('imageFormatAndSize', () => {
|
||||
// Defines a test suite. Two parameters are supported: test suite name and test suite function.
|
||||
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.
|
||||
// This API supports only one parameter: clear action function.
|
||||
});
|
||||
it('getImageSizeInCache', 0, () => {
|
||||
it('getImageSizeInCache', 0, async () => {
|
||||
let width = 0;
|
||||
let height = 0;
|
||||
let imageFormat: string = "";
|
||||
|
||||
let imageKnifeOption: ImageKnifeOption = new ImageKnifeOption({
|
||||
loadSrc: "https://q7.itc.cn/images01/20240223/ce80229bf9934dff97cdf2ad7be1dcb8.jpeg",
|
||||
onLoadListener: {
|
||||
onLoadSuccess: (data, imageknifeData) => {
|
||||
width = imageknifeData.imageWidth!
|
||||
height = imageknifeData.imageHeight!
|
||||
imageFormat = imageknifeData.type!
|
||||
return data;
|
||||
},
|
||||
},
|
||||
loadSrc: $r('app.media.icon'),
|
||||
})
|
||||
|
||||
await new Promise<string>((resolve, reject) => {
|
||||
imageKnifeOption.onLoadListener = {
|
||||
onLoadSuccess: (data, imageknifeData) => {
|
||||
width = imageknifeData.imageWidth
|
||||
height = imageknifeData.imageHeight
|
||||
imageFormat = imageknifeData.type!
|
||||
resolve("")
|
||||
},
|
||||
onLoadFailed(err) {
|
||||
reject(err)
|
||||
}
|
||||
}
|
||||
let request = new ImageKnifeRequest(
|
||||
imageKnifeOption,
|
||||
getContext() as common.UIAbilityContext,
|
||||
100,
|
||||
100,
|
||||
imageKnifeOption.context !== undefined ? imageKnifeOption.context : getContext() as common.UIAbilityContext,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
{
|
||||
showPixelMap: async (version: number, pixelMap: PixelMap | string,
|
||||
requestSource: ImageKnifeRequestSource) => {
|
||||
showPixelMap(version: number, pixelMap: PixelMap | string) {
|
||||
}
|
||||
})
|
||||
}
|
||||
)
|
||||
ImageKnife.getInstance().execute(request);
|
||||
})
|
||||
expect(width != 0).assertTrue();
|
||||
expect(height != 0).assertTrue();
|
||||
expect(imageFormat != "").assertTrue();
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue