提交 c6836dba 编写于 作者: C caochuan

add CreateIncrementalSource testcase

Signed-off-by: Ncaochuan <caochuan@huawei.com>
上级 95855074
...@@ -13,42 +13,43 @@ ...@@ -13,42 +13,43 @@
* limitations under the License. * limitations under the License.
*/ */
import image from '@ohos.multimedia.image' import image from "@ohos.multimedia.image";
import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from 'deccjsunit/index' import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from "deccjsunit/index";
import { testPng } from './testImg' import { testPng } from "./testImg";
export default function addImage() { export default function addImage() {
describe('addImage', function () { describe("addImage", function () {
const RGBA_8888 = image.PixelMapFormat.RGBA_8888;
beforeAll(async function () { beforeAll(async function () {
console.info('beforeAll case'); console.info("beforeAll case");
}) });
beforeEach(function () { beforeEach(function () {
console.info('beforeEach case'); console.info("beforeEach case");
}) });
afterEach(async function () { afterEach(async function () {
console.info('afterEach case'); console.info("afterEach case");
}) });
afterAll(async function () { afterAll(async function () {
console.info('afterAll case'); console.info("afterAll case");
}) });
function createPixMapPromise(done, testNum, opts) { function createPixMapPromise(done, testNum, opts) {
const Color = new ArrayBuffer(96); const Color = new ArrayBuffer(96);
image.createPixelMap(Color, opts) image
.then(pixelmap => { .createPixelMap(Color, opts)
.then((pixelmap) => {
expect(pixelmap != undefined).assertTrue(); expect(pixelmap != undefined).assertTrue();
console.info(`${testNum} success`); console.info(`${testNum} success`);
done(); done();
}) })
.catch(error => { .catch((error) => {
console.log(`${testNum} error: ` + error); console.log(`${testNum} error: ` + error);
expect(false).assertTrue(); expect(false).assertTrue();
done(); done();
}) });
} }
function createPixMapCb(done, testNum, opts) { function createPixMapCb(done, testNum, opts) {
...@@ -57,7 +58,114 @@ export default function addImage() { ...@@ -57,7 +58,114 @@ export default function addImage() {
expect(pixelmap != undefined).assertTrue(); expect(pixelmap != undefined).assertTrue();
console.info(`${testNum} success`); console.info(`${testNum} success`);
done(); done();
}) });
}
async function createIncrementalSourcePromise(done, testNum, type, opts) {
let testimagebuffer = testPng;
let incSouce;
console.info(`${testNum} 0001 ` + testimagebuffer.length);
let bufferSize = 5000;
let offset = 0;
if (type == "sourceOpts") {
console.info(`${testNum} have sourceopts`);
incSouce = image.createIncrementalSource(new ArrayBuffer(1), opts);
} else {
console.info(`${testNum} no sourceopts`);
incSouce = image.createIncrementalSource(new ArrayBuffer(1));
}
let ret;
let isFinished = false;
while (offset < testimagebuffer.length) {
var oneStep = testimagebuffer.slice(offset, offset + bufferSize);
console.info(`${testNum} 0002 ` + oneStep.length);
if (oneStep.length < bufferSize) {
isFinished = true;
}
ret = await incSouce.updateData(oneStep, isFinished, 0, oneStep.length);
if (!ret) {
console.info(`${testNum} updateData failed`);
expect(ret).assertTrue();
break;
}
offset = offset + oneStep.length;
console.info(`${testNum} 0003 ` + offset);
}
if (ret) {
console.info(`${testNum} updateData success `);
let decodingOptions = {
sampleSize: 1,
};
incSouce.createPixelMap(decodingOptions, (err, pixelmap) => {
if (err) {
console.info(`${testNum} createPixelMap err: ` + err);
expect(false).assertTrue();
done();
return;
}
console.info(`${testNum} 0004` + pixelmap);
expect(pixelmap != undefined).assertTrue();
done();
});
} else {
expect(false).assertTrue();
done();
}
}
async function createIncrementalSourceCb(done, testNum, type, opts) {
let testimagebuffer = testPng;
let incSouce;
console.info(`${testNum} 0001 ` + testimagebuffer.length);
let bufferSize = 5000;
let offset = 0;
if (type == "sourceOpts") {
incSouce = image.createIncrementalSource(new ArrayBuffer(1), opts);
} else {
incSouce = image.createIncrementalSource(new ArrayBuffer(1));
}
let ret;
let isFinished = false;
while (offset < testimagebuffer.length) {
var oneStep = testimagebuffer.slice(offset, offset + bufferSize);
console.info(`${testNum} 0002 ` + oneStep.length);
if (oneStep.length < bufferSize) {
isFinished = true;
}
ret = await new Promise((res) => {
incSouce.updateData(oneStep, isFinished, 0, oneStep.length, (err, ret) => {
res(ret);
});
});
if (!ret) {
console.info(`${testNum} updateData failed`);
expect(ret).assertTrue();
break;
}
offset = offset + oneStep.length;
console.info(`${testNum} 0003 ` + offset);
}
if (ret) {
console.info(`${testNum} updateData success `);
let decodingOptions = {
sampleSize: 1,
};
incSouce.createPixelMap(decodingOptions, (err, pixelmap) => {
if (err) {
console.info(`${testNum} createPixelMap err: ` + err);
expect(false).assertTrue();
done();
return;
}
console.info(`${testNum} 0004` + pixelmap);
expect(pixelmap != undefined).assertTrue();
done();
});
} else {
expect(false).assertTrue();
done();
}
} }
/** /**
...@@ -71,10 +179,10 @@ export default function addImage() { ...@@ -71,10 +179,10 @@ export default function addImage() {
* @tc.type : Functional * @tc.type : Functional
* @tc.level : Level 0 * @tc.level : Level 0
*/ */
it('SUB_GRAPHIC_IMAGE_CREATEPIXELMAP_PROMISE_0100', 0, async function (done) { it("SUB_GRAPHIC_IMAGE_CREATEPIXELMAP_PROMISE_0100", 0, async function (done) {
let opts = { editable: true, pixelFormat: 3, size: { height: 4, width: 6 }, scaleMode: 1, alphaType: 0 } let opts = { editable: true, pixelFormat: 3, size: { height: 4, width: 6 }, scaleMode: 1, alphaType: 0 };
createPixMapPromise(done, 'SUB_GRAPHIC_IMAGE_CREATEPIXELMAP_PROMISE_0100', opts); createPixMapPromise(done, "SUB_GRAPHIC_IMAGE_CREATEPIXELMAP_PROMISE_0100", opts);
}) });
/** /**
* @tc.number : SUB_GRAPHIC_IMAGE_CREATEPIXELMAP_PROMISE_0200 * @tc.number : SUB_GRAPHIC_IMAGE_CREATEPIXELMAP_PROMISE_0200
...@@ -87,10 +195,10 @@ export default function addImage() { ...@@ -87,10 +195,10 @@ export default function addImage() {
* @tc.type : Functional * @tc.type : Functional
* @tc.level : Level 0 * @tc.level : Level 0
*/ */
it('SUB_GRAPHIC_IMAGE_CREATEPIXELMAP_PROMISE_0200', 0, async function (done) { it("SUB_GRAPHIC_IMAGE_CREATEPIXELMAP_PROMISE_0200", 0, async function (done) {
let opts = { editable: true, pixelFormat: 3, size: { height: 4, width: 6 }, scaleMode: 1, alphaType: 1 } let opts = { editable: true, pixelFormat: 3, size: { height: 4, width: 6 }, scaleMode: 1, alphaType: 1 };
createPixMapPromise(done, 'SUB_GRAPHIC_IMAGE_CREATEPIXELMAP_PROMISE_0200', opts); createPixMapPromise(done, "SUB_GRAPHIC_IMAGE_CREATEPIXELMAP_PROMISE_0200", opts);
}) });
/** /**
* @tc.number : SUB_GRAPHIC_IMAGE_CREATEPIXELMAP_PROMISE_0300 * @tc.number : SUB_GRAPHIC_IMAGE_CREATEPIXELMAP_PROMISE_0300
...@@ -103,10 +211,10 @@ export default function addImage() { ...@@ -103,10 +211,10 @@ export default function addImage() {
* @tc.type : Functional * @tc.type : Functional
* @tc.level : Level 0 * @tc.level : Level 0
*/ */
it('SUB_GRAPHIC_IMAGE_CREATEPIXELMAP_PROMISE_0300', 0, async function (done) { it("SUB_GRAPHIC_IMAGE_CREATEPIXELMAP_PROMISE_0300", 0, async function (done) {
let opts = { editable: true, pixelFormat: 3, size: { height: 4, width: 6 }, scaleMode: 0, alphaType: 2 } let opts = { editable: true, pixelFormat: 3, size: { height: 4, width: 6 }, scaleMode: 0, alphaType: 2 };
createPixMapPromise(done, 'SUB_GRAPHIC_IMAGE_CREATEPIXELMAP_PROMISE_0300', opts); createPixMapPromise(done, "SUB_GRAPHIC_IMAGE_CREATEPIXELMAP_PROMISE_0300", opts);
}) });
/** /**
* @tc.number : SUB_GRAPHIC_IMAGE_CREATEPIXELMAP_PROMISE_0400 * @tc.number : SUB_GRAPHIC_IMAGE_CREATEPIXELMAP_PROMISE_0400
...@@ -119,10 +227,10 @@ export default function addImage() { ...@@ -119,10 +227,10 @@ export default function addImage() {
* @tc.type : Functional * @tc.type : Functional
* @tc.level : Level 0 * @tc.level : Level 0
*/ */
it('SUB_GRAPHIC_IMAGE_CREATEPIXELMAP_PROMISE_0400', 0, async function (done) { it("SUB_GRAPHIC_IMAGE_CREATEPIXELMAP_PROMISE_0400", 0, async function (done) {
let opts = { editable: true, pixelFormat: 3, size: { height: 4, width: 6 }, scaleMode: 0, alphaType: 3 } let opts = { editable: true, pixelFormat: 3, size: { height: 4, width: 6 }, scaleMode: 0, alphaType: 3 };
createPixMapPromise(done, 'SUB_GRAPHIC_IMAGE_CREATEPIXELMAP_PROMISE_0400', opts); createPixMapPromise(done, "SUB_GRAPHIC_IMAGE_CREATEPIXELMAP_PROMISE_0400", opts);
}) });
/** /**
* @tc.number : SUB_GRAPHIC_IMAGE_CREATEPIXELMAP_CALLBACK_0100 * @tc.number : SUB_GRAPHIC_IMAGE_CREATEPIXELMAP_CALLBACK_0100
...@@ -135,10 +243,10 @@ export default function addImage() { ...@@ -135,10 +243,10 @@ export default function addImage() {
* @tc.type : Functional * @tc.type : Functional
* @tc.level : Level 0 * @tc.level : Level 0
*/ */
it('SUB_GRAPHIC_IMAGE_CREATEPIXELMAP_CALLBACK_0100', 0, async function (done) { it("SUB_GRAPHIC_IMAGE_CREATEPIXELMAP_CALLBACK_0100", 0, async function (done) {
let opts = { editable: true, pixelFormat: 3, size: { height: 4, width: 6 }, scaleMode: 0, alphaType: 0 } let opts = { editable: true, pixelFormat: 3, size: { height: 4, width: 6 }, scaleMode: 0, alphaType: 0 };
createPixMapCb(done, 'SUB_GRAPHIC_IMAGE_CREATEPIXELMAP_CALLBACK_0100', opts); createPixMapCb(done, "SUB_GRAPHIC_IMAGE_CREATEPIXELMAP_CALLBACK_0100", opts);
}) });
/** /**
* @tc.number : SUB_GRAPHIC_IMAGE_CREATEPIXELMAP_CALLBACK_0200 * @tc.number : SUB_GRAPHIC_IMAGE_CREATEPIXELMAP_CALLBACK_0200
...@@ -151,10 +259,10 @@ export default function addImage() { ...@@ -151,10 +259,10 @@ export default function addImage() {
* @tc.type : Functional * @tc.type : Functional
* @tc.level : Level 0 * @tc.level : Level 0
*/ */
it('SUB_GRAPHIC_IMAGE_CREATEPIXELMAP_CALLBACK_0200', 0, async function (done) { it("SUB_GRAPHIC_IMAGE_CREATEPIXELMAP_CALLBACK_0200", 0, async function (done) {
let opts = { editable: true, pixelFormat: 3, size: { height: 4, width: 6 }, scaleMode: 0, alphaType: 1 } let opts = { editable: true, pixelFormat: 3, size: { height: 4, width: 6 }, scaleMode: 0, alphaType: 1 };
createPixMapCb(done, 'SUB_GRAPHIC_IMAGE_CREATEPIXELMAP_CALLBACK_0200', opts); createPixMapCb(done, "SUB_GRAPHIC_IMAGE_CREATEPIXELMAP_CALLBACK_0200", opts);
}) });
/** /**
* @tc.number : SUB_GRAPHIC_IMAGE_CREATEPIXELMAP_CALLBACK_0300 * @tc.number : SUB_GRAPHIC_IMAGE_CREATEPIXELMAP_CALLBACK_0300
...@@ -167,10 +275,10 @@ export default function addImage() { ...@@ -167,10 +275,10 @@ export default function addImage() {
* @tc.type : Functional * @tc.type : Functional
* @tc.level : Level 0 * @tc.level : Level 0
*/ */
it('SUB_GRAPHIC_IMAGE_CREATEPIXELMAP_CALLBACK_0300', 0, async function (done) { it("SUB_GRAPHIC_IMAGE_CREATEPIXELMAP_CALLBACK_0300", 0, async function (done) {
let opts = { editable: true, pixelFormat: 3, size: { height: 4, width: 6 }, scaleMode: 1, alphaType: 2 } let opts = { editable: true, pixelFormat: 3, size: { height: 4, width: 6 }, scaleMode: 1, alphaType: 2 };
createPixMapCb(done, 'SUB_GRAPHIC_IMAGE_CREATEPIXELMAP_CALLBACK_0300', opts); createPixMapCb(done, "SUB_GRAPHIC_IMAGE_CREATEPIXELMAP_CALLBACK_0300", opts);
}) });
/** /**
* @tc.number : SUB_GRAPHIC_IMAGE_CREATEPIXELMAP_CALLBACK_0400 * @tc.number : SUB_GRAPHIC_IMAGE_CREATEPIXELMAP_CALLBACK_0400
...@@ -183,10 +291,10 @@ export default function addImage() { ...@@ -183,10 +291,10 @@ export default function addImage() {
* @tc.type : Functional * @tc.type : Functional
* @tc.level : Level 0 * @tc.level : Level 0
*/ */
it('SUB_GRAPHIC_IMAGE_CREATEPIXELMAP_CALLBACK_0400', 0, async function (done) { it("SUB_GRAPHIC_IMAGE_CREATEPIXELMAP_CALLBACK_0400", 0, async function (done) {
let opts = { editable: true, pixelFormat: 3, size: { height: 4, width: 6 }, scaleMode: 1, alphaType: 3 } let opts = { editable: true, pixelFormat: 3, size: { height: 4, width: 6 }, scaleMode: 1, alphaType: 3 };
createPixMapCb(done, 'SUB_GRAPHIC_IMAGE_CREATEPIXELMAP_CALLBACK_0400', opts); createPixMapCb(done, "SUB_GRAPHIC_IMAGE_CREATEPIXELMAP_CALLBACK_0400", opts);
}) });
/** /**
* @tc.number : SUB_GRAPHIC_IMAGE_CREATEINCREMENTALSOURCE_UPDATEDATA_PNG_PROMISE_0100 * @tc.number : SUB_GRAPHIC_IMAGE_CREATEINCREMENTALSOURCE_UPDATEDATA_PNG_PROMISE_0100
...@@ -194,54 +302,17 @@ export default function addImage() { ...@@ -194,54 +302,17 @@ export default function addImage() {
* @tc.desc : 1.create imagesource * @tc.desc : 1.create imagesource
* 2.update data * 2.update data
* 3.create pixelmap * 3.create pixelmap
* @tc.size : MEDIUM * @tc.size : MEDIUM
* @tc.type : Functional * @tc.type : Functional
* @tc.level : Level 1 * @tc.level : Level 1
*/ */
it('SUB_GRAPHIC_IMAGE_CREATEINCREMENTALSOURCE_UPDATEDATA_PNG_PROMISE_0100', 0, async function (done) { it("SUB_GRAPHIC_IMAGE_CREATEINCREMENTALSOURCE_UPDATEDATA_PNG_PROMISE_0100", 0, async function (done) {
try { createIncrementalSourcePromise(
let testimagebuffer = testPng; done,
console.info('SUB_GRAPHIC_IMAGE_CREATEINCREMENTALSOURCE_UPDATEDATA_PNG_PROMISE_0100 0003 ' + testimagebuffer.length); "SUB_GRAPHIC_IMAGE_CREATEINCREMENTALSOURCE_UPDATEDATA_PNG_PROMISE_0100",
let bufferSize = 5000; "noSourceOpts"
let offset = 0; );
const incSouce = image.createIncrementalSource(new ArrayBuffer(1)); });
let ret;
let isFinished = false;
while (offset < testimagebuffer.length) {
console.info('SUB_GRAPHIC_IMAGE_CREATEINCREMENTALSOURCE_UPDATEDATA_PNG_PROMISE_0100 0006 ' + testimagebuffer.length);
var oneStep = testimagebuffer.slice(offset, offset + bufferSize);
console.info('SUB_GRAPHIC_IMAGE_CREATEINCREMENTALSOURCE_UPDATEDATA_PNG_PROMISE_0100 0007 ' + oneStep.length);
if (oneStep.length < bufferSize) {
isFinished = true;
}
ret = await incSouce.updateData(oneStep, isFinished, 0, oneStep.length);
if (!ret) {
console.info('SUB_GRAPHIC_IMAGE_CREATEINCREMENTALSOURCE_UPDATEDATA_PNG_PROMISE_0100 updateData failed');
expect(ret).assertTrue();
break;
}
offset = offset + oneStep.length;
console.info('SUB_GRAPHIC_IMAGE_CREATEINCREMENTALSOURCE_UPDATEDATA_PNG_PROMISE_0100 0011 ' + offset);
}
if (ret) {
console.info('SUB_GRAPHIC_IMAGE_CREATEINCREMENTALSOURCE_UPDATEDATA_PNG_PROMISE_0100 updateData success ');
let decodingOptions = {
sampleSize: 1
};
incSouce.createPixelMap(decodingOptions, (err, pixelmap) => {
console.info('SUB_GRAPHIC_IMAGE_CREATEINCREMENTALSOURCE_UPDATEDATA_PNG_PROMISE_0100 0014' + pixelmap);
expect(pixelmap != undefined).assertTrue();
done();
})
} else {
expect(false).assertTrue();
done();
}
} catch (error) {
expect(false).assertTrue();
console.info('SUB_GRAPHIC_IMAGE_CREATEINCREMENTALSOURCE_UPDATEDATA_PNG_PROMISE_0100 updateData failed ' + error);
}
})
/** /**
* @tc.number : SUB_GRAPHIC_IMAGE_CREATEINCREMENTALSOURCE_UPDATEDATA_PNG_PROMISE_0200 * @tc.number : SUB_GRAPHIC_IMAGE_CREATEINCREMENTALSOURCE_UPDATEDATA_PNG_PROMISE_0200
...@@ -249,56 +320,56 @@ export default function addImage() { ...@@ -249,56 +320,56 @@ export default function addImage() {
* @tc.desc : 1.create imagesource * @tc.desc : 1.create imagesource
* 2.update data * 2.update data
* 3.create pixelmap * 3.create pixelmap
* @tc.size : MEDIUM * @tc.size : MEDIUM
* @tc.type : Functional * @tc.type : Functional
* @tc.level : Level 1 * @tc.level : Level 1
*/ */
it('SUB_GRAPHIC_IMAGE_CREATEINCREMENTALSOURCE_UPDATEDATA_PNG_PROMISE_0200', 0, async function (done) { it("SUB_GRAPHIC_IMAGE_CREATEINCREMENTALSOURCE_UPDATEDATA_PNG_PROMISE_0200", 0, async function (done) {
try { let opts = { sourceDensity: 240, pixelFormat: RGBA_8888, size: { height: 4, width: 6 } };
let testimagebuffer = testPng; createIncrementalSourcePromise(
console.info('SUB_GRAPHIC_IMAGE_CREATEINCREMENTALSOURCE_UPDATEDATA_PNG_PROMISE_0200 0001 ' + testimagebuffer.length); done,
let bufferSize = 5000; "SUB_GRAPHIC_IMAGE_CREATEINCREMENTALSOURCE_UPDATEDATA_PNG_PROMISE_0200",
let offset = 0; "sourceOpts",
const incSouce = image.createIncrementalSource(new ArrayBuffer(1)); opts
let ret; );
let isFinished = false; });
while (offset < testimagebuffer.length) {
var oneStep = testimagebuffer.slice(offset, offset + bufferSize); /**
console.info('SUB_GRAPHIC_IMAGE_CREATEINCREMENTALSOURCE_UPDATEDATA_PNG_PROMISE_0200 0002 ' + oneStep.length); * @tc.number : SUB_GRAPHIC_IMAGE_CREATEINCREMENTALSOURCE_UPDATEDATA_PNG_CALLBACK_0100
if (oneStep.length < bufferSize) { * @tc.name : createIncrementalSource-updateData-png-callback
isFinished = true; * @tc.desc : 1.create imagesource
} * 2.update data
ret = await new Promise(res => { * 3.create pixelmap
incSouce.updateData(oneStep, isFinished, 0, oneStep.length, (err, ret) => { * @tc.size : MEDIUM
res(ret); * @tc.type : Functional
}) * @tc.level : Level 1
}) */
if (!ret) { it("SUB_GRAPHIC_IMAGE_CREATEINCREMENTALSOURCE_UPDATEDATA_PNG_CALLBACK_0100", 0, async function (done) {
console.info('SUB_GRAPHIC_IMAGE_CREATEINCREMENTALSOURCE_UPDATEDATA_PNG_PROMISE_0200 updateData failed'); createIncrementalSourceCb(
expect(ret).assertTrue(); done,
break; "SUB_GRAPHIC_IMAGE_CREATEINCREMENTALSOURCE_UPDATEDATA_PNG_CALLBACK_0100",
} "noSourceOpts"
offset = offset + oneStep.length; );
console.info('SUB_GRAPHIC_IMAGE_CREATEINCREMENTALSOURCE_UPDATEDATA_PNG_PROMISE_0200 0003 ' + offset); });
}
if (ret) { /**
console.info('SUB_GRAPHIC_IMAGE_CREATEINCREMENTALSOURCE_UPDATEDATA_PNG_PROMISE_0200 updateData success '); * @tc.number : SUB_GRAPHIC_IMAGE_CREATEINCREMENTALSOURCE_UPDATEDATA_PNG_CALLBACK_0200
let decodingOptions = { * @tc.name : createIncrementalSource-updateData-png-callback
sampleSize: 1 * @tc.desc : 1.create imagesource
}; * 2.update data
incSouce.createPixelMap(decodingOptions, (err, pixelmap) => { * 3.create pixelmap
console.info('SUB_GRAPHIC_IMAGE_CREATEINCREMENTALSOURCE_UPDATEDATA_PNG_PROMISE_0200 0004' + pixelmap); * @tc.size : MEDIUM
expect(pixelmap != undefined).assertTrue(); * @tc.type : Functional
done(); * @tc.level : Level 1
}) */
} else { it("SUB_GRAPHIC_IMAGE_CREATEINCREMENTALSOURCE_UPDATEDATA_PNG_CALLBACK_0200", 0, async function (done) {
expect(false).assertTrue(); let opts = { sourceDensity: 240, pixelFormat: RGBA_8888, size: { height: 4, width: 6 } };
done(); createIncrementalSourceCb(
} done,
} catch (error) { "SUB_GRAPHIC_IMAGE_CREATEINCREMENTALSOURCE_UPDATEDATA_PNG_CALLBACK_0200",
expect(false).assertTrue(); "sourceOpts",
console.info('SUB_GRAPHIC_IMAGE_CREATEINCREMENTALSOURCE_UPDATEDATA_PNG_PROMISE_0200 updateData failed ' + error); opts
} );
}) });
}) });
} }
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册