master分支代码合并taskpool分支代码

Signed-off-by: zenggaofeng <zenggaofeng2@h-partners.com>
This commit is contained in:
zenggaofeng
2024-03-22 09:40:10 +08:00
54 changed files with 2208 additions and 700 deletions

View File

@@ -109,18 +109,13 @@ struct basicTestFileIOPage {
this.imageHint2 = 'appFilePath未取到值,请按顺序从上往下,从左往右依次测试'
return
}
try {
let filePath1 = this.appFilePath + '/Folder1/jpgSample.gif';
let filePath2 = this.appFilePath + '/Folder2/jpgSample.gif';
FileUtils.getInstance().createFolder(this.appFilePath + '/Folder1')
FileUtils.getInstance().createFolder(this.appFilePath + '/Folder2')
FileUtils.getInstance().copyFile(filePath1, filePath2);
this.imageFile = 'file://' + this.appFilePath + '/Folder2/jpgSample.gif'
console.log('Folder2 imaeFile =' + this.imageFile)
} catch (e) {
console.log('appFilePath未取到值,请按顺序从上往下,从左往右依次测试:'+JSON.stringify(e))
}
let filePath1 = this.appFilePath + '/Folder1/jpgSample.gif';
let filePath2 = this.appFilePath + '/Folder2/jpgSample.gif';
FileUtils.getInstance().createFolder(this.appFilePath + '/Folder1')
FileUtils.getInstance().createFolder(this.appFilePath + '/Folder2')
FileUtils.getInstance().copyFile(filePath1, filePath2);
this.imageFile = 'file://' + this.appFilePath + '/Folder2/jpgSample.gif'
console.log('Folder2 imaeFile =' + this.imageFile)
})
Flex({ direction: FlexDirection.Row, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
Button('显示空PixelMap')

View File

@@ -290,6 +290,10 @@ struct IndexFunctionDemo {
.onClick(() => {
router.pushUrl({ url: "pages/testManyNetImageLoadWithPage" });
}).margin({ top: 5, left: 3 })
Button("多线程加载大量网络图片加载速度")
.onClick(() => {
router.pushUrl({ url: "pages/testManyNetImageLoadWithPage2" });
}).margin({ top: 5, left: 3 })
Button("测试多张gif加载位置")
.onClick(() => {
router.pushUrl({ url: "pages/testManyGifLoadWithPage" });

View File

@@ -18,9 +18,8 @@ import {ImageKnifeGlobal} from '@ohos/libraryimageknife'
import {RotateImageTransformation} from '@ohos/libraryimageknife'
import {Material} from './model/Material'
import {TestDataSource} from './model/TestDataSource'
import {DiskLruCache} from '@ohos/disklrucache'
import ArkWorker from '@ohos.worker'
import Prompt from '@system.prompt'
@Entry
@Component
struct photosPausedResumedPage {

View File

@@ -0,0 +1,65 @@
/*
* Copyright (C) 2023 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 { ScaleType, ImageKnifeComponent, NONE, DiskStrategy } from "@ohos/libraryimageknife"
import { Material } from './model/Material';
import { TestDataSource } from './model/TestDataSource';
@Entry
@Component
struct TestManyNetImageLoadWithPage2 {
private data: TestDataSource = new TestDataSource();
private setting: DiskStrategy = new NONE();
private scroller: Scroller = new Scroller()
build() {
Scroll() {
Column() {
Grid(this.scroller) {
LazyForEach(this.data, (item: Material, index) => {
GridItem() {
Stack({ alignContent: Alignment.BottomEnd }) {
ImageKnifeComponent({
imageKnifeOption: {
loadSrc: item.thumbnail,
placeholderSrc: $r('app.media.icon_loading'),
mainScaleType: ScaleType.CENTER_CROP,
placeholderScaleType: ScaleType.CENTER_CROP,
isCacheable: false,
strategy: this.setting
}
}).width('100%').height('100%')
Text(index + "." + item.name)
.fontSize(10)
.maxLines(1)
.fontColor(Color.White)
.textAlign(TextAlign.Center)
.layoutWeight(1)
.width('100%')
.backgroundColor(Color.Orange)
}
}.width('45%').height(200)
}, (item: Material) => item.material_id)
}
.columnsTemplate('1fr 1fr')
.columnsGap(8)
.rowsGap(10)
.width('100%')
.cachedCount(1)
.height('100%')
}.margin({ top: 5 })
}
}
}

View File

@@ -34,6 +34,7 @@
"pages/hspCacheTestPage",
"pages/multiHspTestPage",
"pages/testManyNetImageLoadWithPage",
"pages/testManyNetImageLoadWithPage2",
"pages/testManyGifLoadWithPage",
"pages/testImageAntiAliasingWithPage",
"pages/testImageKnifeRouter1",

View File

@@ -18,10 +18,12 @@ import LogUtilTest from './logutil.test'
import Transform from './transfrom.test'
import RequestOptionTest from './requestoption.test'
import ImageKnifeTest from './imageknife.test'
import DiskLruCacheTest from './diskLruCache.test'
export default function testsuite() {
abilityTest()
lruCacheTest()
DiskLruCacheTest()
LogUtilTest()
Transform()
RequestOptionTest()

View File

@@ -0,0 +1,162 @@
/*
* 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 { DiskLruCache, DiskCacheEntry } from '@ohos/imageknife'
import { common } from '@kit.AbilityKit';
import fs from '@ohos.file.fs';
import { GlobalContext } from '../testability/GlobalContext'
const BASE_COUNT: number = 2000;
export default function DiskLruCacheTest() {
describe('DiskLruCacheTest', () => {
// Defines a test suite. Two parameters are supported: test suite name and test suite function.
beforeAll(() => {
//ImageKnife.with(this.context.createModuleContext("entry_test"));
// 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('testSetCahe', 0, () => {
let context: object | undefined = GlobalContext.getInstance().getObject("hapContext");
let disLruCache: DiskLruCache = DiskLruCache.create(context as common.UIAbilityContext, 1024);
let startTime = new Date().getTime();
disLruCache.set('test', "Hello World Simple Example.");
disLruCache.set('testABC', "Hello World ABC");
disLruCache.set('testDE', "Hello World Simple DE");
expect(String.fromCharCode(...new Uint8Array(disLruCache.get('test') as ArrayBufferLike)) == "Hello World Simple Example.")
.assertTrue()
expect(String.fromCharCode(...new Uint8Array(disLruCache.get('testABC') as ArrayBufferLike)) == "Hello World ABC")
.assertTrue()
expect(String.fromCharCode(...new Uint8Array(disLruCache.get('testDE') as ArrayBufferLike)) == "Hello World Simple DE")
.assertTrue()
let str: string = 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa';
for (let index = 0; index < 100; index++) {
str += index;
disLruCache.set('test' + index, str);
}
expect(disLruCache.getSize() <= 1024).assertTrue()
endTime(startTime, 'testSetCahe');
disLruCache.cleanCacheData();
})
it('testGetCacheAsync', 1, () => {
let context: object | undefined = GlobalContext.getInstance().getObject("hapContext");
let filesDir: object | undefined = GlobalContext.getInstance().getObject("filesDir");
let cache: DiskLruCache = DiskLruCache.create(context as common.UIAbilityContext, 1024);
let startTime = new Date().getTime();
let path = filesDir + '/testFile.txt';
let file = fs.openSync(path, 0o102);
fs.writeSync(file.fd, "hello, world!");
let length = fs.statSync(path).size;
let dataArr = new ArrayBuffer(length);
fs.readSync(file.fd, dataArr);
cache.set('testFile', dataArr);
expect(cache.get('testFile')?.byteLength == 13).assertTrue()
endTime(startTime, 'testGetCacheAsync');
cache.cleanCacheData();
})
it('testDeleteCacheDataByKey', 2, () => {
let context: object | undefined = GlobalContext.getInstance().getObject("hapContext");
let cache: DiskLruCache = DiskLruCache.create(context as common.UIAbilityContext, 1024);
let startTime = new Date().getTime();
cache.set('test', "Hello World Simple Example.");
cache.set('testABC', "Hello World ABC");
expect(String.fromCharCode(...new Uint8Array(cache.get('test') as ArrayBufferLike)))
.assertEqual("Hello World Simple Example.");
expect(String.fromCharCode(...new Uint8Array(cache.get('testABC') as ArrayBufferLike)))
.assertEqual("Hello World ABC");
cache.deleteCacheDataByKey('test');
cache.deleteCacheDataByKey('testABC');
expect(String.fromCharCode(...new Uint8Array(cache.get('test') as ArrayBufferLike))).assertEqual('');
expect(String.fromCharCode(...new Uint8Array(cache.get('testABC') as ArrayBufferLike))).assertEqual('');
endTime(startTime, 'testDeleteCacheDataByKey');
cache.cleanCacheData();
})
it('testGetPath', 3, () => {
let context: object | undefined = GlobalContext.getInstance().getObject("hapContext");
let cache: DiskLruCache = DiskLruCache.create(context as common.UIAbilityContext, 1024);
let startTime = new Date().getTime();
cache.set('test', "Hello World Simple Example.");
let path: string = cache.getFileToPath('test');
expect(String.fromCharCode(...new Uint8Array(cache.get('test') as ArrayBufferLike)) == "Hello World Simple Example.")
.assertTrue()
expect(cache.getFileToPath('test') == path).assertTrue()
expect(cache.getPath() + cache.getCacheMap().getFirstKey() == path).assertTrue()
endTime(startTime, 'testGetPath');
cache.cleanCacheData();
})
it('testGetCacheMap', 6, () => {
let context: object | undefined = GlobalContext.getInstance().getObject("hapContext");
let cache: DiskLruCache = DiskLruCache.create(context as common.UIAbilityContext, 1024);
let startTime = new Date().getTime();
cache.set('test', "Hello World Simple Example.");
expect(cache.getCacheMap().getFirstKey() == '098f6bcd4621d373cade4e832627b4f6').assertTrue()
expect(cache.getCacheMap().hasKey('098f6bcd4621d373cade4e832627b4f6') == true).assertTrue()
endTime(startTime, 'testGetCacheMap');
cache.cleanCacheData();
})
it('testGetSize', 7, () => {
let context: object | undefined = GlobalContext.getInstance().getObject("hapContext");
let cache: DiskLruCache = DiskLruCache.create(context as common.UIAbilityContext, 1024);
let startTime = new Date().getTime();
cache.set('test', "Hello World Simple Example.");
expect(String.fromCharCode(...new Uint8Array(cache.get('test') as ArrayBufferLike)) == "Hello World Simple Example.")
.assertTrue()
expect(cache.getSize() == 27).assertTrue()
endTime(startTime, 'testGetSize');
cache.cleanCacheData();
})
it('testDiskCacheEntry', 8, () => {
let startTime = new Date().getTime();
let dentry = new DiskCacheEntry('test', 30 * 1024 * 1024)
expect(dentry.getKey() == 'test').assertTrue()
dentry.setKey('newtest')
expect(dentry.getKey() == 'newtest').assertTrue()
expect(dentry.getLength() == 30 * 1024 * 1024).assertTrue()
dentry.setLength(12 * 1024 * 1024)
expect(dentry.getLength() == 12 * 1024 * 1024).assertTrue()
expect(dentry.toString() == dentry.getKey() + ' - ' + dentry.getLength()).assertTrue()
endTime(startTime, 'testDiskCacheEntry');
})
})
}
function endTime(startTime: number, tag: string) {
let endTime: number = new Date().getTime();
let averageTime = ((endTime - startTime) * 1000 / BASE_COUNT)
console.info(tag + " startTime: " + endTime)
console.info(tag + " endTime: " + endTime)
console.log(tag + " averageTime: " + averageTime + "μs");
}

View File

@@ -0,0 +1,37 @@
/*
* 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.
*/
export class GlobalContext {
private constructor() {
}
private static instance: GlobalContext;
private _objects = new Map<string, Object>();
public static getInstance(): GlobalContext {
if (!GlobalContext.instance) {
GlobalContext.instance = new GlobalContext();
}
return GlobalContext.instance;
}
getObject(value: string): Object | undefined {
return this._objects.get(value);
}
setObject(key: string, objectClass: Object): void {
this._objects.set(key, objectClass);
}
}

View File

@@ -22,6 +22,7 @@ import {ImageKnife,ImageKnifeDrawFactory,ImageKnifeGlobal} from '@ohos/libraryim
import AbilityConstant from '@ohos.app.ability.AbilityConstant';
import Want from '@ohos.app.ability.Want';
import { BusinessError } from '@ohos.base'
import {GlobalContext } from './GlobalContext'
export default class TestAbility extends UIAbility {
onCreate(want: Want, param: AbilityConstant.LaunchParam) {
@@ -33,6 +34,8 @@ export default class TestAbility extends UIAbility {
Hypium.hypiumTest(abilityDelegator, abilityDelegatorArguments, testsuite)
// 初始化xts的ImageKnife
ImageKnife.with(this.context.createModuleContext("entry_test"));
GlobalContext.getInstance().setObject("hapContext",this.context.createModuleContext("entry_test"));
GlobalContext.getInstance().setObject("filesDir",this.context.createModuleContext("entry_test").filesDir);
}
onDestroy() {