diff --git a/entry/src/main/ets/pages/TestChangeColorPage.ets b/entry/src/main/ets/pages/TestChangeColorPage.ets index 87349bb..665386d 100644 --- a/entry/src/main/ets/pages/TestChangeColorPage.ets +++ b/entry/src/main/ets/pages/TestChangeColorPage.ets @@ -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'; diff --git a/entry/src/ohosTest/ets/test/List.test.ets b/entry/src/ohosTest/ets/test/List.test.ets index 8c04309..1b17e5f 100644 --- a/entry/src/ohosTest/ets/test/List.test.ets +++ b/entry/src/ohosTest/ets/test/List.test.ets @@ -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(); } \ No newline at end of file diff --git a/entry/src/ohosTest/ets/test/imageFormatAndSize.test.ets b/entry/src/ohosTest/ets/test/imageFormatAndSize.test.ets index 0f00344..3faa0a6 100644 --- a/entry/src/ohosTest/ets/test/imageFormatAndSize.test.ets +++ b/entry/src/ohosTest/ets/test/imageFormatAndSize.test.ets @@ -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'), }) - - let request = new ImageKnifeRequest( - imageKnifeOption, - getContext() as common.UIAbilityContext, - 100, - 100, - 0, - { - showPixelMap: async (version: number, pixelMap: PixelMap | string, - requestSource: ImageKnifeRequestSource) => { + await new Promise((resolve, reject) => { + imageKnifeOption.onLoadListener = { + onLoadSuccess: (data, imageknifeData) => { + width = imageknifeData.imageWidth + height = imageknifeData.imageHeight + imageFormat = imageknifeData.type! + resolve("") + }, + onLoadFailed(err) { + 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(height != 0).assertTrue(); expect(imageFormat != "").assertTrue(); }); }); - - } -