提交 d11b71da 编写于 作者: F fengzewu

fix receiver crash

Signed-off-by: Nfengzewu <fengzewu@huawei.com>
上级 be51d5fa
...@@ -29,20 +29,19 @@ describe('ImageReceiver', function () { ...@@ -29,20 +29,19 @@ describe('ImageReceiver', function () {
const YCBCR_422_SP = 1000; const YCBCR_422_SP = 1000;
const FORMATJPEG = 2000; const FORMATJPEG = 2000;
beforeAll(function () { beforeAll(async function () {
console.info('beforeAll case'); console.info('beforeAll case');
}) })
beforeEach(function () { beforeEach(function () {
isTimeOut = false;
console.info('beforeEach case'); console.info('beforeEach case');
}) })
afterEach(function () { afterEach(async function () {
console.info('afterEach case'); console.info('afterEach case');
}) })
afterAll(function () { afterAll(async function () {
console.info('afterAll case'); console.info('afterAll case');
}) })
...@@ -50,7 +49,7 @@ describe('ImageReceiver', function () { ...@@ -50,7 +49,7 @@ describe('ImageReceiver', function () {
await new Promise(res => setTimeout(() => { res() }, times)); await new Promise(res => setTimeout(() => { res() }, times));
} }
function createRecriver(done, testNum, wid, hei, fmt, cap) { async function createRecriver(done, testNum, wid, hei, fmt, cap) {
try { try {
image.createImageReceiver(wid, hei, fmt, cap); image.createImageReceiver(wid, hei, fmt, cap);
expect(false).assertTrue(); expect(false).assertTrue();
...@@ -63,21 +62,21 @@ describe('ImageReceiver', function () { ...@@ -63,21 +62,21 @@ describe('ImageReceiver', function () {
} }
async function getComponentProErr(done, testNum, param) { async function getComponentProErr(done, testNum, param) {
var receiver = image.createImageReceiver(WIDTH, HEIGHT, FORMAT, CAPACITY) var receiver = image.createImageReceiver(WIDTH, HEIGHT, FORMAT, CAPACITY);
let once = false;
if (receiver == undefined) { if (receiver == undefined) {
expect(false).assertTrue(); expect(false).assertTrue();
done() done();
} else { } else {
receiver.on('imageArrival', () => { receiver.on('imageArrival', () => {
expect(true).assertTrue(); if (once) {
}) return;
}
var dummy = receiver.test once = true;
receiver.readLatestImage(async (err, img) => { receiver.readLatestImage(async (err, img) => {
if (img == undefined) { if (img == undefined) {
expect(false).assertTrue(); expect(false).assertTrue();
done() done();
} else { } else {
expect(img.size.width == WIDTH).assertTrue(); expect(img.size.width == WIDTH).assertTrue();
expect(img.size.height == HEIGHT).assertTrue(); expect(img.size.height == HEIGHT).assertTrue();
...@@ -96,25 +95,70 @@ describe('ImageReceiver', function () { ...@@ -96,25 +95,70 @@ describe('ImageReceiver', function () {
} }
} }
}) })
expect(true).assertTrue();
})
var dummy = receiver.test;
} }
} }
async function getComponentCbErr(done, testNum, param) { async function getComponentCbErr(done, testNum, param) {
var receiver = image.createImageReceiver(WIDTH, HEIGHT, FORMAT, CAPACITY) var receiver = image.createImageReceiver(WIDTH, HEIGHT, FORMAT, CAPACITY);
let once = false;
if (receiver == undefined) { if (receiver == undefined) {
expect(false).assertTrue(); expect(false).assertTrue();
done() done();
} else { } else {
receiver.on('imageArrival', () => { receiver.on('imageArrival', () => {
if (once) {
return;
}
once = true;
receiver.readLatestImage(async (err, img) => {
if (img == undefined) {
expect(false).assertTrue();
done();
} else {
expect(img.size.width == WIDTH).assertTrue();
expect(img.size.height == HEIGHT).assertTrue();
expect(img.format == 12).assertTrue();
expect(img.clipRect.size.width == WIDTH).assertTrue();
expect(img.clipRect.size.height == HEIGHT).assertTrue();
expect(img.clipRect.x == 0).assertTrue();
expect(img.clipRect.y == 0).assertTrue();
try {
img.getComponent(param, (err, component) => {
expect(false).assertTrue();
})
} catch (error) {
expect(error.code == 1).assertTrue();
console.log(`${testNum} error msg: ` + error);
done();
}
}
})
expect(true).assertTrue(); expect(true).assertTrue();
}) })
var dummy = receiver.test;
}
}
var dummy = receiver.test async function getComponentP(done, testNum, param) {
var receiver = image.createImageReceiver(WIDTH, HEIGHT, FORMAT, CAPACITY);
receiver.readLatestImage(async (err, img) => { let once = false;
if (img == undefined) { if (receiver == undefined) {
expect(false).assertTrue();
done();
return;
}
receiver.on('imageArrival', () => {
if (once) {
return;
}
once = true;
receiver.readLatestImage((err, img) => {
if (err) {
expect(false).assertTrue(); expect(false).assertTrue();
done() done();
} else { } else {
expect(img.size.width == WIDTH).assertTrue(); expect(img.size.width == WIDTH).assertTrue();
expect(img.size.height == HEIGHT).assertTrue(); expect(img.size.height == HEIGHT).assertTrue();
...@@ -124,108 +168,74 @@ describe('ImageReceiver', function () { ...@@ -124,108 +168,74 @@ describe('ImageReceiver', function () {
expect(img.clipRect.x == 0).assertTrue(); expect(img.clipRect.x == 0).assertTrue();
expect(img.clipRect.y == 0).assertTrue(); expect(img.clipRect.y == 0).assertTrue();
try { img.getComponent(param).then(component => {
img.getComponent(param, (err, component) => { if (component == undefined) {
expect(false).assertTrue(); expect(false).assertTrue();
}) done();
} catch (error) { } else {
expect(error.code == 1).assertTrue(); expect(component.componentType == param).assertTrue();
console.log(`${testNum} error msg: ` + error); expect(component.byteBuffer != undefined).assertTrue();
expect(component.rowStride == 0).assertTrue();
expect(component.pixelStride == 0).assertTrue();
done();
}
}).catch(error => {
console.log(`${testNum} error:` + error)
expect(false).assertTrue();
done(); done();
} })
} }
}) })
}
}
async function getComponentP(done, testNum, param) {
var receiver = image.createImageReceiver(WIDTH, HEIGHT, FORMAT, CAPACITY)
if (receiver == undefined) {
expect(false).assertTrue();
done()
return;
}
receiver.on('imageArrival', () => {
expect(true).assertTrue(); expect(true).assertTrue();
}) })
var dummy = receiver.test;
var dummy = receiver.test
receiver.readLatestImage((err, img) => {
if (err) {
expect(false).assertTrue();
done();
} else {
expect(img.size.width == WIDTH).assertTrue();
expect(img.size.height == HEIGHT).assertTrue();
expect(img.format == 12).assertTrue();
expect(img.clipRect.size.width == WIDTH).assertTrue();
expect(img.clipRect.size.height == HEIGHT).assertTrue();
expect(img.clipRect.x == 0).assertTrue();
expect(img.clipRect.y == 0).assertTrue();
img.getComponent(param).then(component => {
if (component == undefined) {
expect(false).assertTrue();
done();
} else {
expect(component.componentType == param).assertTrue();
expect(component.byteBuffer != undefined).assertTrue();
expect(component.rowStride == 0).assertTrue();
expect(component.pixelStride == 0).assertTrue();
done();
}
}).catch(error => {
console.log(`${testNum} error:` + error)
expect(false).assertTrue();
done();
})
}
})
} }
async function getComponentCb(done, testNum, param) { async function getComponentCb(done, testNum, param) {
var receiver = image.createImageReceiver(WIDTH, HEIGHT, FORMAT, CAPACITY) var receiver = image.createImageReceiver(WIDTH, HEIGHT, FORMAT, CAPACITY);
let once = false;
if (receiver == undefined) { if (receiver == undefined) {
expect(false).assertTrue(); expect(false).assertTrue();
done() done();
return; return;
} }
receiver.on('imageArrival', () => { receiver.on('imageArrival', () => {
expect(true).assertTrue(); if (once) {
}) return;
var dummy = receiver.test
receiver.readLatestImage((err, img) => {
if (err) {
expect(false).assertTrue();
done();
} else {
expect(img.size.width == WIDTH).assertTrue();
expect(img.size.height == HEIGHT).assertTrue();
expect(img.format == 12).assertTrue();
expect(img.clipRect.size.width == WIDTH).assertTrue();
expect(img.clipRect.size.height == HEIGHT).assertTrue();
expect(img.clipRect.x == 0).assertTrue();
expect(img.clipRect.y == 0).assertTrue();
img.getComponent(param, (err, component) => {
if (err) {
expect(false).assertTrue();
console.log(`${testNum} geterror: ` + err)
} else {
expect(component != undefined).assertTrue();
expect(component.componentType == param).assertTrue();
expect(component.byteBuffer != undefined).assertTrue();
expect(component.rowStride == 0).assertTrue();
expect(component.pixelStride == 0).assertTrue();
done();
}
})
} }
once = true;
receiver.readLatestImage((err, img) => {
if (err) {
expect(false).assertTrue();
done();
} else {
expect(img.size.width == WIDTH).assertTrue();
expect(img.size.height == HEIGHT).assertTrue();
expect(img.format == 12).assertTrue();
expect(img.clipRect.size.width == WIDTH).assertTrue();
expect(img.clipRect.size.height == HEIGHT).assertTrue();
expect(img.clipRect.x == 0).assertTrue();
expect(img.clipRect.y == 0).assertTrue();
img.getComponent(param, (err, component) => {
if (err) {
expect(false).assertTrue();
console.log(`${testNum} geterror: ` + err)
} else {
expect(component != undefined).assertTrue();
expect(component.componentType == param).assertTrue();
expect(component.byteBuffer != undefined).assertTrue();
expect(component.rowStride == 0).assertTrue();
expect(component.pixelStride == 0).assertTrue();
done();
}
})
}
})
expect(true).assertTrue();
}) })
var dummy = receiver.test;
} }
async function onErr(done, testNum, param) { async function onErr(done, testNum, param) {
...@@ -244,7 +254,7 @@ describe('ImageReceiver', function () { ...@@ -244,7 +254,7 @@ describe('ImageReceiver', function () {
console.log(`${testNum} error msg: ` + error); console.log(`${testNum} error msg: ` + error);
done(); done();
} }
var dummy = receiver.test var dummy = receiver.test;
} }
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册