Pre Merge pull request !222 from zhanghanyong/master
This commit is contained in:
commit
1ecf94bc5d
|
@ -79,6 +79,8 @@ struct TestCustomDataFetchClientWithPage {
|
||||||
@State isSingleImageVisible: boolean = true;
|
@State isSingleImageVisible: boolean = true;
|
||||||
@State isAllImageVisible: boolean = false;
|
@State isAllImageVisible: boolean = false;
|
||||||
@State isCustom: boolean = false;
|
@State isCustom: boolean = false;
|
||||||
|
private isAllImageAdded: boolean = false;
|
||||||
|
private isCancelImageAdded: boolean = false;
|
||||||
private data: Array<string> = [
|
private data: Array<string> = [
|
||||||
"http://img2.xkhouse.com/bbs/hfhouse/data/attachment/forum/corebbs/2009-11/2009113011534566298.jpg",
|
"http://img2.xkhouse.com/bbs/hfhouse/data/attachment/forum/corebbs/2009-11/2009113011534566298.jpg",
|
||||||
"http://a.hiphotos.baidu.com/image/pic/item/e824b899a9014c087eb617650e7b02087af4f464.jpg"
|
"http://a.hiphotos.baidu.com/image/pic/item/e824b899a9014c087eb617650e7b02087af4f464.jpg"
|
||||||
|
@ -122,8 +124,10 @@ struct TestCustomDataFetchClientWithPage {
|
||||||
this.isAllImageVisible = true;
|
this.isAllImageVisible = true;
|
||||||
|
|
||||||
ImageKnifeGlobal.getInstance().getImageKnife()?.replaceDataFetch(new CustomDataFetchClient());
|
ImageKnifeGlobal.getInstance().getImageKnife()?.replaceDataFetch(new CustomDataFetchClient());
|
||||||
this.hotCommendList.addData(this.hotCommendList.totalCount(), this.addData)
|
if (!this.isAllImageAdded) {
|
||||||
|
this.hotCommendList.addData(this.hotCommendList.totalCount(), this.addData);
|
||||||
|
this.isAllImageAdded = true;
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
Button("取消自定义全部图片").margin(16).onClick(() => {
|
Button("取消自定义全部图片").margin(16).onClick(() => {
|
||||||
|
@ -132,7 +136,10 @@ struct TestCustomDataFetchClientWithPage {
|
||||||
this.isAllImageVisible = true;
|
this.isAllImageVisible = true;
|
||||||
|
|
||||||
ImageKnifeGlobal.getInstance().getImageKnife()?.replaceDataFetch(new DownloadClient());
|
ImageKnifeGlobal.getInstance().getImageKnife()?.replaceDataFetch(new DownloadClient());
|
||||||
this.hotCommendList.addData(this.hotCommendList.totalCount(), this.cancelData)
|
if (!this.isCancelImageAdded) {
|
||||||
|
this.hotCommendList.addData(this.hotCommendList.totalCount(), this.cancelData);
|
||||||
|
this.isCancelImageAdded = true;
|
||||||
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -21,6 +21,7 @@ import ImageKnifeTest from './imageknife.test'
|
||||||
import DiskLruCacheTest from './diskLruCache.test'
|
import DiskLruCacheTest from './diskLruCache.test'
|
||||||
import SendableDataTest from './SendableData.test'
|
import SendableDataTest from './SendableData.test'
|
||||||
import DefaultJobQueueTest from './DefaultJobQueueTest.test';
|
import DefaultJobQueueTest from './DefaultJobQueueTest.test';
|
||||||
|
import CustomDataFetchClientTest from './customdatafetchclient.test'
|
||||||
|
|
||||||
export default function testsuite() {
|
export default function testsuite() {
|
||||||
abilityTest()
|
abilityTest()
|
||||||
|
@ -32,4 +33,5 @@ export default function testsuite() {
|
||||||
ImageKnifeTest();
|
ImageKnifeTest();
|
||||||
SendableDataTest();
|
SendableDataTest();
|
||||||
DefaultJobQueueTest();
|
DefaultJobQueueTest();
|
||||||
|
CustomDataFetchClientTest();
|
||||||
}
|
}
|
|
@ -0,0 +1,104 @@
|
||||||
|
/*
|
||||||
|
* 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 { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium'
|
||||||
|
import { DownloadClient } from '@ohos/imageknife/src/main/ets/components/imageknife/networkmanage/DownloadClient';
|
||||||
|
import common from '@ohos.app.ability.common';
|
||||||
|
import { GlobalContext } from '../testability/GlobalContext';
|
||||||
|
import { CustomDataFetchClient, DataFetchResult, ImageKnifeGlobal, RequestOption } from '@ohos/imageknife';
|
||||||
|
|
||||||
|
const BASE_COUNT: number = 2000;
|
||||||
|
|
||||||
|
export default function CustomDataFetchClientTest() {
|
||||||
|
describe('CustomDataFetchClientTest', () => {
|
||||||
|
// Defines a test suite. Two parameters are supported: test suite name and test suite function.
|
||||||
|
beforeAll(() => {
|
||||||
|
// Presets an action, which is performed only once before all test cases of the test suite start.
|
||||||
|
// This API supports only one parameter: preset action function.
|
||||||
|
})
|
||||||
|
beforeEach(() => {
|
||||||
|
// Presets an action, which is performed before each unit test case starts.
|
||||||
|
// The number of execution times is the same as the number of test cases defined by **it**.
|
||||||
|
// This API supports only one parameter: preset action function.
|
||||||
|
})
|
||||||
|
afterEach(() => {
|
||||||
|
// Presets a clear action, which is performed after each unit test case ends.
|
||||||
|
// The number of execution times is the same as the number of test cases defined by **it**.
|
||||||
|
// This API supports only one parameter: clear action function.
|
||||||
|
})
|
||||||
|
afterAll(() => {
|
||||||
|
// 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('TestIsLocalLoadSrc', 0, () => {
|
||||||
|
let path = 'invalid path';
|
||||||
|
let client = new DownloadClient()
|
||||||
|
expect(client.isLocalLoadSrc(undefined, path)).assertFalse();
|
||||||
|
let context: object | undefined = GlobalContext.getInstance().getObject("hapContext");
|
||||||
|
if (context != undefined) {
|
||||||
|
let loadSrc1 = (context as common.UIAbilityContext).filesDir + 'a.jpg';
|
||||||
|
let loadSrc2 = (context as common.UIAbilityContext).cacheDir + 'b.jpg';
|
||||||
|
expect(client.isLocalLoadSrc(context, loadSrc1)).assertTrue();
|
||||||
|
expect(client.isLocalLoadSrc(context, loadSrc2)).assertTrue();
|
||||||
|
}
|
||||||
|
})
|
||||||
|
it('TestLoadData', 1, async () => {
|
||||||
|
let client = new CustomDataFetchClient();
|
||||||
|
let request = new RequestOption();
|
||||||
|
request.loadSrc = $r('app.media.icon');
|
||||||
|
let error = (await client.loadData(request) as DataFetchResult).error as String;
|
||||||
|
expect(error).assertEqual('CustomDataFetchClient request or loadSrc error.');
|
||||||
|
})
|
||||||
|
it('TestLoadData_customGetImage', 2, async () => {
|
||||||
|
let client = new CustomDataFetchClient();
|
||||||
|
let request = new RequestOption();
|
||||||
|
request.loadSrc = 'http://e.hiphotos.baidu.com/image/pic/item/4e4a20a4462309f7e41f5cfe760e0cf3d6cad6ee.jpg';
|
||||||
|
request.customGetImage = (context: Context, src: string) => {
|
||||||
|
// 这里是模拟的customGetImage逻辑
|
||||||
|
return Promise.resolve(new DataFetchResult());
|
||||||
|
}
|
||||||
|
let context: object | undefined = GlobalContext.getInstance().getObject("hapContext");
|
||||||
|
let result = await client.loadData(request);
|
||||||
|
if (context != undefined) {
|
||||||
|
expect(typeof result)
|
||||||
|
.assertEqual(typeof (await request?.customGetImage(context as common.UIAbilityContext, request.loadSrc)));
|
||||||
|
}
|
||||||
|
})
|
||||||
|
it('TestLoadData_combineArrayBuffers', 3, () => {
|
||||||
|
// 创建几个ArrayBuffer作为测试数据
|
||||||
|
const arrayBuffer1 = new ArrayBuffer(4);
|
||||||
|
const uint8Array1 = new Uint8Array(arrayBuffer1);
|
||||||
|
uint8Array1[0] = 1;
|
||||||
|
uint8Array1[1] = 2;
|
||||||
|
uint8Array1[2] = 3;
|
||||||
|
uint8Array1[3] = 4;
|
||||||
|
|
||||||
|
const arrayBuffer2 = new ArrayBuffer(2);
|
||||||
|
const uint8Array2 = new Uint8Array(arrayBuffer2);
|
||||||
|
uint8Array2[0] = 5;
|
||||||
|
uint8Array2[1] = 6;
|
||||||
|
let client = new CustomDataFetchClient();
|
||||||
|
const combinedArrayBuffer = client.combineArrayBuffers([arrayBuffer1, arrayBuffer2]);
|
||||||
|
expect(combinedArrayBuffer.byteLength).assertEqual(6);
|
||||||
|
const combinedUint8Array = new Uint8Array(combinedArrayBuffer);
|
||||||
|
for (let i = 0; i < 4; i++) {
|
||||||
|
expect(combinedUint8Array[i]).assertEqual(uint8Array1[i]);
|
||||||
|
}
|
||||||
|
for (let i = 0; i < 2; i++) {
|
||||||
|
expect(combinedUint8Array[i + 4]).assertEqual(uint8Array2[i]);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue