commit
569cac5b93
|
@ -16,6 +16,8 @@ import hilog from '@ohos.hilog';
|
|||
import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium'
|
||||
import {ImageKnife,ImageKnifeDrawFactory,ImageKnifeGlobal} from '@ohos/imageknife'
|
||||
|
||||
const BASE_COUNT: number = 2000;
|
||||
|
||||
export default function ImageKnifeTest() {
|
||||
describe('ImageKnifeTest', ()=> {
|
||||
// Defines a test suite. Two parameters are supported: test suite name and test suite function.
|
||||
|
@ -42,6 +44,11 @@ export default function ImageKnifeTest() {
|
|||
it('TestGlobalImageKnife',0, ()=> {
|
||||
let context:Object|undefined = ImageKnifeGlobal.getInstance().getHapContext();
|
||||
if(context != undefined) {
|
||||
let startTime = new Date().getTime();
|
||||
for (let index = 0; index < BASE_COUNT; index++) {
|
||||
ImageKnife.with(context);
|
||||
}
|
||||
endTime(startTime, 'TestGlobalImageKnife');
|
||||
let global: ImageKnifeGlobal = ImageKnife.with(context)
|
||||
expect(global.getImageKnife()).not().assertUndefined()
|
||||
}
|
||||
|
@ -51,17 +58,29 @@ export default function ImageKnifeTest() {
|
|||
it('TestGlobalDefaultLifeCycle',1, ()=> {
|
||||
let imageKnife:ImageKnife|undefined = ImageKnifeGlobal.getInstance().getImageKnife()
|
||||
if(imageKnife != undefined){
|
||||
let startTime = new Date().getTime();
|
||||
for (let index = 0; index < BASE_COUNT; index++) {
|
||||
imageKnife.setDefaultLifeCycle(ImageKnifeDrawFactory.createProgressLifeCycle("#10a5ff", 0.5))
|
||||
}
|
||||
endTime(startTime, 'setDefaultLifeCycle');
|
||||
let startTime1 = new Date().getTime();
|
||||
for (let index = 0; index < BASE_COUNT; index++) {
|
||||
imageKnife.getDefaultLifeCycle();
|
||||
}
|
||||
endTime(startTime1, 'getDefaultLifeCycle');
|
||||
imageKnife.setDefaultLifeCycle(ImageKnifeDrawFactory.createProgressLifeCycle("#10a5ff", 0.5))
|
||||
let globalLifeCycle = imageKnife.getDefaultLifeCycle();
|
||||
expect(globalLifeCycle).not().assertUndefined()
|
||||
}
|
||||
|
||||
})
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
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");
|
||||
}
|
|
@ -16,6 +16,8 @@ import hilog from '@ohos.hilog';
|
|||
import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium'
|
||||
import {LruCache} from '@ohos/imageknife' // DiskLruCache用例由DiskLruCache三方库提供
|
||||
|
||||
const BASE_COUNT: number = 2000;
|
||||
|
||||
export default function lruCacheTest() {
|
||||
describe('lruCacheTest', ()=> {
|
||||
// Defines a test suite. Two parameters are supported: test suite name and test suite function.
|
||||
|
@ -39,6 +41,11 @@ export default function lruCacheTest() {
|
|||
})
|
||||
it('testLruCacheSize',0, ()=> {
|
||||
// Defines a test case. This API supports three parameters: test case name, filter parameter, and test case function.
|
||||
let startTime = new Date().getTime();
|
||||
for (let index = 0; index < BASE_COUNT; index++) {
|
||||
new LruCache<string, string>(100);
|
||||
}
|
||||
endTime(startTime, 'testLruCacheSize');
|
||||
let memoryCache = new LruCache<string, string>(100);
|
||||
expect(memoryCache.size).assertEqual(0);
|
||||
expect(memoryCache.maxsize).assertEqual(100)
|
||||
|
@ -52,6 +59,11 @@ export default function lruCacheTest() {
|
|||
memoryCache.put("4","4");
|
||||
memoryCache.put("5","5");
|
||||
memoryCache.put("6","6");
|
||||
let startTime = new Date().getTime();
|
||||
for (let index = 0; index < BASE_COUNT; index++) {
|
||||
memoryCache.put("7","7");
|
||||
}
|
||||
endTime(startTime, 'testLruCachePut');
|
||||
|
||||
expect(memoryCache.maxsize).assertEqual(5)
|
||||
let result = memoryCache.get("1")
|
||||
|
@ -68,6 +80,11 @@ export default function lruCacheTest() {
|
|||
memoryCache.put("6","6");
|
||||
|
||||
expect(memoryCache.maxsize).assertEqual(5)
|
||||
let startTime = new Date().getTime();
|
||||
for (let index = 0; index < BASE_COUNT; index++) {
|
||||
memoryCache.get("2");
|
||||
}
|
||||
endTime(startTime, 'testLruCacheGet');
|
||||
let result = memoryCache.get("2")
|
||||
expect(result).assertEqual("2")
|
||||
})
|
||||
|
@ -94,6 +111,13 @@ export default function lruCacheTest() {
|
|||
memoryCache.foreachLruCache( (value:string, key:string, map:Map<string,string>)=> {
|
||||
callback(key,value)
|
||||
})
|
||||
let startTime = new Date().getTime();
|
||||
for (let index = 0; index < BASE_COUNT; index++) {
|
||||
memoryCache.foreachLruCache( (value:string, key:string, map:Map<string,string>)=> {
|
||||
callback(key,value)
|
||||
})
|
||||
}
|
||||
endTime(startTime, 'testLruCacheAlgorithm');
|
||||
expect(memoryCache.size).assertEqual(5)
|
||||
|
||||
})
|
||||
|
@ -110,7 +134,11 @@ export default function lruCacheTest() {
|
|||
memoryCache.get("2");
|
||||
|
||||
memoryCache.remove("2");
|
||||
|
||||
let startTime = new Date().getTime();
|
||||
for (let index = 0; index < BASE_COUNT; index++) {
|
||||
memoryCache.remove("2");
|
||||
}
|
||||
endTime(startTime, 'testLruCacheRemove');
|
||||
let count:number = 1
|
||||
let callback =(key:string,value:string)=>{
|
||||
if(count == 4){
|
||||
|
@ -136,6 +164,12 @@ export default function lruCacheTest() {
|
|||
|
||||
memoryCache.resize(4);
|
||||
|
||||
let startTime = new Date().getTime();
|
||||
for (let index = 0; index < BASE_COUNT; index++) {
|
||||
memoryCache.resize(4);
|
||||
}
|
||||
endTime(startTime, 'testLruCacheResize');
|
||||
|
||||
let result1 = memoryCache.get("1");
|
||||
expect(result1).assertEqual(undefined);
|
||||
let result2 = memoryCache.get("2");
|
||||
|
@ -143,4 +177,12 @@ export default function lruCacheTest() {
|
|||
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
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");
|
||||
}
|
|
@ -17,6 +17,8 @@ import hilog from '@ohos.hilog';
|
|||
import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium'
|
||||
import {RequestOption,Size} from '@ohos/imageknife'
|
||||
|
||||
const BASE_COUNT: number = 2000;
|
||||
|
||||
export default function RequestOptionTest() {
|
||||
describe('RequestOptionTest', ()=> {
|
||||
// Defines a test suite. Two parameters are supported: test suite name and test suite function.
|
||||
|
@ -39,6 +41,11 @@ export default function RequestOptionTest() {
|
|||
// This API supports only one parameter: clear action function.
|
||||
})
|
||||
it('TestRequestOption',0, ()=> {
|
||||
let startTime = new Date().getTime();
|
||||
for (let index = 0; index < BASE_COUNT; index++) {
|
||||
new RequestOption();
|
||||
}
|
||||
endTime(startTime, 'TestRequestOption');
|
||||
let option = new RequestOption();
|
||||
if(option.requestListeners != undefined) {
|
||||
expect(option.requestListeners.length == 0).assertTrue()
|
||||
|
@ -48,6 +55,11 @@ export default function RequestOptionTest() {
|
|||
let option = new RequestOption();
|
||||
expect(option.loadSrc).assertEqual('')
|
||||
option.loadSrc = $r('app.media.icon')
|
||||
let startTime = new Date().getTime();
|
||||
for (let index = 0; index < BASE_COUNT; index++) {
|
||||
option.loadSrc = $r('app.media.icon');
|
||||
}
|
||||
endTime(startTime, 'TestConfigLoadSrc');
|
||||
expect(JSON.stringify(option.loadSrc)).assertEqual(JSON.stringify($r('app.media.icon')))
|
||||
})
|
||||
it('TestConfigViewSize',2, ()=> {
|
||||
|
@ -55,6 +67,11 @@ export default function RequestOptionTest() {
|
|||
option.loadSrc = ''
|
||||
let size:Size = {width:100,height:100}
|
||||
option.setImageViewSize(size)
|
||||
let startTime = new Date().getTime();
|
||||
for (let index = 0; index < BASE_COUNT; index++) {
|
||||
option.setImageViewSize(size);
|
||||
}
|
||||
endTime(startTime, 'TestConfigViewSize');
|
||||
expect(JSON.stringify(option.size)).assertEqual(JSON.stringify(size))
|
||||
})
|
||||
it('TestNormalConfigInfo',3, ()=>{
|
||||
|
@ -75,4 +92,12 @@ export default function RequestOptionTest() {
|
|||
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
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");
|
||||
}
|
|
@ -38,6 +38,8 @@ import {
|
|||
|
||||
} from '@ohos/imageknife'
|
||||
|
||||
const BASE_COUNT: number = 2000;
|
||||
|
||||
export default function Transform() {
|
||||
describe('Transform', ()=>{
|
||||
// Defines a test suite. Two parameters are supported: test suite name and test suite function.
|
||||
|
@ -60,18 +62,38 @@ export default function Transform() {
|
|||
// This API supports only one parameter: clear action function.
|
||||
})
|
||||
it('TestBlurTransformation', 0, ()=>{
|
||||
let startTime = new Date().getTime();
|
||||
for (let index = 0; index < BASE_COUNT; index++) {
|
||||
new BlurTransformation(15);
|
||||
}
|
||||
endTime(startTime, 'TestBlurTransformation');
|
||||
let blur = new BlurTransformation(15);
|
||||
expect(blur.getName()).assertEqual('BlurTransformation _mRadius:15')
|
||||
})
|
||||
it('TestBrightnessFilterTransformation', 1, ()=>{
|
||||
let startTime = new Date().getTime();
|
||||
for (let index = 0; index < BASE_COUNT; index++) {
|
||||
new BrightnessFilterTransformation(20);
|
||||
}
|
||||
endTime(startTime, 'TestBrightnessFilterTransformation');
|
||||
let bright = new BrightnessFilterTransformation(20);
|
||||
expect(bright.getName()).assertEqual("BrightnessFilterTransformation:20")
|
||||
})
|
||||
it('TestContrastFilterTransformation', 2, ()=>{
|
||||
let startTime = new Date().getTime();
|
||||
for (let index = 0; index < BASE_COUNT; index++) {
|
||||
new ContrastFilterTransformation(30);
|
||||
}
|
||||
endTime(startTime, 'TestContrastFilterTransformation');
|
||||
let constrast = new ContrastFilterTransformation(30);
|
||||
expect(constrast.getName()).assertEqual("ContrastFilterTransformation:30")
|
||||
})
|
||||
it('TestCropCircleTransformation', 3, ()=>{
|
||||
let startTime = new Date().getTime();
|
||||
for (let index = 0; index < BASE_COUNT; index++) {
|
||||
new CropCircleTransformation();
|
||||
}
|
||||
endTime(startTime, 'TestCropCircleTransformation');
|
||||
let cropCircle = new CropCircleTransformation();
|
||||
expect(cropCircle.getName()).assertContain("CropCircleTransformation")
|
||||
expect(cropCircle.getName()).assertContain(";mCenterX:")
|
||||
|
@ -79,6 +101,11 @@ export default function Transform() {
|
|||
expect(cropCircle.getName()).assertContain(";mRadius:")
|
||||
})
|
||||
it('TestCropCircleWithBorderTransformation', 4, ()=>{
|
||||
let startTime = new Date().getTime();
|
||||
for (let index = 0; index < BASE_COUNT; index++) {
|
||||
new CropCircleWithBorderTransformation(10,{r_color:100,g_color:100,b_color:100 });
|
||||
}
|
||||
endTime(startTime, 'TestCropCircleWithBorderTransformation');
|
||||
let CropCircleWithBorder = new CropCircleWithBorderTransformation(10,{r_color:100,g_color:100,b_color:100 });
|
||||
expect(CropCircleWithBorder.getName()).assertContain("CropCircleTransformation")
|
||||
expect(CropCircleWithBorder.getName()).assertContain(";mCenterX:")
|
||||
|
@ -90,30 +117,65 @@ export default function Transform() {
|
|||
expect(CropCircleWithBorder.getName()).assertContain(";mBColor:")
|
||||
})
|
||||
it('TestCropSquareTransformation', 5, ()=>{
|
||||
let startTime = new Date().getTime();
|
||||
for (let index = 0; index < BASE_COUNT; index++) {
|
||||
new CropSquareTransformation();
|
||||
}
|
||||
endTime(startTime, 'TestCropSquareTransformation');
|
||||
let CropSquare = new CropSquareTransformation();
|
||||
expect(CropSquare.getName()).assertContain("CropSquareTransformation")
|
||||
})
|
||||
it('TestCropTransformation', 6, ()=>{
|
||||
let startTime = new Date().getTime();
|
||||
for (let index = 0; index < BASE_COUNT; index++) {
|
||||
new CropTransformation(10,10,CropType.CENTER);
|
||||
}
|
||||
endTime(startTime, 'TestCropTransformation');
|
||||
let crop = new CropTransformation(10,10,CropType.CENTER);
|
||||
expect(crop.getName()).assertContain("CropCircleTransformation"+ ";mWidth:10" + ";mHeight:10" + ";mCropType:1" )
|
||||
})
|
||||
it('TestGrayscaleTransformation', 7, ()=>{
|
||||
let startTime = new Date().getTime();
|
||||
for (let index = 0; index < BASE_COUNT; index++) {
|
||||
new GrayscaleTransformation();
|
||||
}
|
||||
endTime(startTime, 'TestGrayscaleTransformation');
|
||||
let grayscale = new GrayscaleTransformation();
|
||||
expect(grayscale.getName()).assertContain("GrayscaleTransformation" )
|
||||
})
|
||||
it('TestInvertFilterTransformation', 8, ()=>{
|
||||
let startTime = new Date().getTime();
|
||||
for (let index = 0; index < BASE_COUNT; index++) {
|
||||
new InvertFilterTransformation();
|
||||
}
|
||||
endTime(startTime, 'TestInvertFilterTransformation');
|
||||
let invert = new InvertFilterTransformation();
|
||||
expect(invert.getName()).assertContain("InvertFilterTransformation" )
|
||||
})
|
||||
it('TestPixelationFilterTransformation', 9, ()=>{
|
||||
let startTime = new Date().getTime();
|
||||
for (let index = 0; index < BASE_COUNT; index++) {
|
||||
new PixelationFilterTransformation();
|
||||
}
|
||||
endTime(startTime, 'TestPixelationFilterTransformation');
|
||||
let pixelation = new PixelationFilterTransformation();
|
||||
expect(pixelation.getName()).assertContain("PixelationFilterTransformation" )
|
||||
})
|
||||
it('TestRotateImageTransformation', 10, ()=>{
|
||||
let startTime = new Date().getTime();
|
||||
for (let index = 0; index < BASE_COUNT; index++) {
|
||||
new RotateImageTransformation(180);
|
||||
}
|
||||
endTime(startTime, 'TestRotateImageTransformation');
|
||||
let rotateImage = new RotateImageTransformation(180);
|
||||
expect(rotateImage.getName()).assertContain("RotateImageTransformation" + ";degreesToRotate:180")
|
||||
})
|
||||
it('TestRoundedCornersTransformation', 11, ()=>{
|
||||
let startTime = new Date().getTime();
|
||||
for (let index = 0; index < BASE_COUNT; index++) {
|
||||
new RoundedCornersTransformation({top_left:5,bottom_left:5,top_right:5,bottom_right:5});
|
||||
}
|
||||
endTime(startTime, 'TestRoundedCornersTransformation');
|
||||
let roundConer = new RoundedCornersTransformation({top_left:5,bottom_left:5,top_right:5,bottom_right:5});
|
||||
expect(roundConer.getName()).assertContain("RoundedCornersTransformation" + ";mTop_left:" + 5
|
||||
+ ";mTop_right:" + 5
|
||||
|
@ -121,31 +183,66 @@ export default function Transform() {
|
|||
+ ";mBottom_right:" + 5)
|
||||
})
|
||||
it('TestSepiaFilterTransformation', 12, ()=>{
|
||||
let startTime = new Date().getTime();
|
||||
for (let index = 0; index < BASE_COUNT; index++) {
|
||||
new SepiaFilterTransformation();
|
||||
}
|
||||
endTime(startTime, 'TestSepiaFilterTransformation');
|
||||
let speia = new SepiaFilterTransformation();
|
||||
expect(speia.getName()).assertContain("SepiaFilterTransformation")
|
||||
})
|
||||
it('TestSketchFilterTransformation', 13, ()=>{
|
||||
let startTime = new Date().getTime();
|
||||
for (let index = 0; index < BASE_COUNT; index++) {
|
||||
new SketchFilterTransformation();
|
||||
}
|
||||
endTime(startTime, 'TestSketchFilterTransformation');
|
||||
let Sketch = new SketchFilterTransformation();
|
||||
expect(Sketch.getName()).assertContain("SketchFilterTransformation")
|
||||
})
|
||||
it('TestMaskTransformation', 14, ()=>{
|
||||
let startTime = new Date().getTime();
|
||||
for (let index = 0; index < BASE_COUNT; index++) {
|
||||
new MaskTransformation($r('app.media.icon'));
|
||||
}
|
||||
endTime(startTime, 'TestMaskTransformation');
|
||||
let mask = new MaskTransformation($r('app.media.icon'));
|
||||
expect(mask.getName()).assertContain("MaskTransformation")
|
||||
})
|
||||
it('TestSwirlFilterTransformation', 15, ()=>{
|
||||
let startTime = new Date().getTime();
|
||||
for (let index = 0; index < BASE_COUNT; index++) {
|
||||
new SwirlFilterTransformation(10,180,[10,10]);
|
||||
}
|
||||
endTime(startTime, 'TestSwirlFilterTransformation');
|
||||
let swirl = new SwirlFilterTransformation(10,180,[10,10]);
|
||||
expect(swirl.getName()).assertContain("SwirlFilterTransformation")
|
||||
})
|
||||
it('TestKuwaharaFilterTransform', 16, ()=>{
|
||||
let startTime = new Date().getTime();
|
||||
for (let index = 0; index < BASE_COUNT; index++) {
|
||||
new KuwaharaFilterTransform(10);
|
||||
}
|
||||
endTime(startTime, 'TestKuwaharaFilterTransform');
|
||||
let kuwahara = new KuwaharaFilterTransform(10);
|
||||
expect(kuwahara.getName()).assertContain("KuwaharaFilterTransform _mRadius:10")
|
||||
})
|
||||
it('TestToonFilterTransform', 17, ()=>{
|
||||
let startTime = new Date().getTime();
|
||||
for (let index = 0; index < BASE_COUNT; index++) {
|
||||
new ToonFilterTransform(10);
|
||||
}
|
||||
endTime(startTime, 'TestToonFilterTransform');
|
||||
let toon = new ToonFilterTransform(10);
|
||||
expect(toon.getName()).assertContain("ToonFilterTransform threshold:")
|
||||
expect(toon.getName()).assertContain(";quantizationLevels:")
|
||||
})
|
||||
it('TestVignetteFilterTransform', 18, ()=>{
|
||||
let startTime = new Date().getTime();
|
||||
for (let index = 0; index < BASE_COUNT; index++) {
|
||||
new VignetteFilterTransform([0.5, 0.5],[0.0, 0.0, 0.0],[0.3, 0.75]);
|
||||
}
|
||||
endTime(startTime, 'TestVignetteFilterTransform');
|
||||
let vignette = new VignetteFilterTransform([0.5, 0.5],[0.0, 0.0, 0.0],[0.3, 0.75]);
|
||||
expect(vignette.getName()).assertContain("VignetteFilterTransform centerPoint:")
|
||||
expect(vignette.getName()).assertContain(";vignetteColor:")
|
||||
|
@ -153,4 +250,12 @@ export default function Transform() {
|
|||
})
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
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");
|
||||
}
|
Loading…
Reference in New Issue