提交 4f57f955 编写于 作者: 华华小仙女

添加try catch

Signed-off-by: N华华小仙女 <zhurong18@h-partners.com>
上级 51e57c30
...@@ -1009,7 +1009,7 @@ export default function windowPromiseTest(context, windowStage, abilityStorage) ...@@ -1009,7 +1009,7 @@ export default function windowPromiseTest(context, windowStage, abilityStorage)
console.log(msgStr + 'ohosWindow.create ' + tempType + ' start'); console.log(msgStr + 'ohosWindow.create ' + tempType + ' start');
let createData = null; let createData = null;
try { try {
ohosWindow.create(context, windId, tempType).then((data) => { await ohosWindow.create(context, windId, tempType).then((data) => {
createData = data createData = data
expect(!!createData).assertTrue(); expect(!!createData).assertTrue();
}).catch((err) => { }).catch((err) => {
...@@ -1146,23 +1146,27 @@ export default function windowPromiseTest(context, windowStage, abilityStorage) ...@@ -1146,23 +1146,27 @@ export default function windowPromiseTest(context, windowStage, abilityStorage)
}); });
} }
catch (err) { catch (err) {
console.log(msgStr + 'tempWnd.loadContent(null) catch err:' + JSON.stringify(err)); console.log(msgStr + 'ohosWindow.createWindow catch err:' + JSON.stringify(err));
} }
console.log(msgStr + 'tempWnd.loadContent start'); console.log(msgStr + 'tempWnd.loadContent start');
let errFlag = false; let errFlag = false;
let loadContentData = null; let loadContentData = null;
tempWnd.loadContent(null).then((data) => { try {
loadContentData = data; await tempWnd.loadContent(null).then((data) => {
}).catch((err) => { loadContentData = data;
errFlag = true; }).catch((err) => {
expectedError(err, caseName, 'tempWnd.loadContent', done, 1003); errFlag = true;
console.log(msgStr + 'tempWnd.loadContent(null)' + JSON.stringify(err)); expectedError(err, caseName, 'tempWnd.loadContent', done, 1003);
}); console.log(msgStr + 'tempWnd.loadContent(null)' + JSON.stringify(err));
console.log(msgStr + 'tempWnd.loadContent loadContentData:' + JSON.stringify(loadContentData)); });
if (!errFlag) { console.log(msgStr + 'tempWnd.loadContent loadContentData:' + JSON.stringify(loadContentData));
console.log(msgStr + 'should report err'); if (!errFlag) {
expect(TRUE_FLAG).assertFail(); console.log(msgStr + 'should report err');
done(); expect(TRUE_FLAG).assertFail();
done();
}
} catch (err) {
console.log(msgStr + 'tempWnd.loadContent(null) catch err:' + JSON.stringify(err));
} }
}) })
...@@ -1394,13 +1398,18 @@ export default function windowPromiseTest(context, windowStage, abilityStorage) ...@@ -1394,13 +1398,18 @@ export default function windowPromiseTest(context, windowStage, abilityStorage)
let msgStr = 'jsunittest ' + caseName + ' '; let msgStr = 'jsunittest ' + caseName + ' ';
console.log(msgStr + 'begin'); console.log(msgStr + 'begin');
let screens = null; let screens = null;
screenManager.getAllScreens().then((data) => { try {
screens = data await screenManager.getAllScreens().then((data) => {
}).catch(err => { screens = data
unexpectedError(err, caseName, 'screenManager.getAllScreen', done); console.log(msgStr + 'screenManager.getAllScreen' + JSON.stringify(screens));
}) expect(!!screens).assertTrue();
console.log(msgStr + 'screenManager.getAllScreen' + JSON.stringify(screens)); }).catch(err => {
expect(!!screens).assertTrue(); unexpectedError(err, caseName, 'screenManager.getAllScreen', done);
})
}
catch (err) {
console.log(msgStr + 'screenManager.getAllScreen catch err:' + JSON.stringify(err));
}
let currentDeviceDefault = null; let currentDeviceDefault = null;
await display.getDefaultDisplay().then((data) => { await display.getDefaultDisplay().then((data) => {
currentDeviceDefault = data currentDeviceDefault = data
...@@ -1621,14 +1630,20 @@ export default function windowPromiseTest(context, windowStage, abilityStorage) ...@@ -1621,14 +1630,20 @@ export default function windowPromiseTest(context, windowStage, abilityStorage)
name: wndId, windowType: baseType, ctx: context name: wndId, windowType: baseType, ctx: context
} }
let tempWnd = null; let tempWnd = null;
ohosWindow.createWindow(createWindowObj).then((data) => { try {
tempWnd = data await ohosWindow.createWindow(createWindowObj).then((data) => {
}).catch((err) => { tempWnd = data
unexpectedError(err, caseName, 'ohosWindow.create ' + baseType, done); console.log(msgStr + 'ohosWindow.create ' + baseType + ', tempWnd: ' + JSON.stringify(tempWnd));
}); expect(!!tempWnd).assertTrue();
console.log(msgStr + 'ohosWindow.create ' + baseType + ', tempWnd: ' + JSON.stringify(tempWnd)); console.info('showWithAnimationTest1 ****' + Reflect.has(tempWnd, 'showWithAnimation'))
expect(!!tempWnd).assertTrue(); }).catch((err) => {
console.info('showWithAnimationTest1 ****' + Reflect.has(tempWnd, 'showWithAnimation')) unexpectedError(err, caseName, 'ohosWindow.create ' + baseType, done);
});
}
catch (err) {
console.log(msgStr + 'ohosWindow.create catch err:' + JSON.stringify(err));
}
await tempWnd.showWithAnimation().then((data) => { await tempWnd.showWithAnimation().then((data) => {
console.info('Succeeded in showing the window with animation. Data: ' + JSON.stringify(data)); console.info('Succeeded in showing the window with animation. Data: ' + JSON.stringify(data));
done(); done();
...@@ -1651,15 +1666,21 @@ export default function windowPromiseTest(context, windowStage, abilityStorage) ...@@ -1651,15 +1666,21 @@ export default function windowPromiseTest(context, windowStage, abilityStorage)
name: wndId, windowType: baseType, ctx: context name: wndId, windowType: baseType, ctx: context
} }
let tempWnd = null; let tempWnd = null;
ohosWindow.createWindow(createWindowObj).then((data) => { try {
tempWnd = data await ohosWindow.createWindow(createWindowObj).then((data) => {
}).catch((err) => { tempWnd = data
unexpectedError(err, caseName, 'ohosWindow.create ' + baseType, done); console.log(msgStr + 'ohosWindow.create ' + baseType + ', tempWnd: ' + JSON.stringify(tempWnd));
}); expect(!!tempWnd).assertTrue();
console.log(msgStr + 'ohosWindow.create ' + baseType + ', tempWnd: ' + JSON.stringify(tempWnd)); }).catch((err) => {
expect(!!tempWnd).assertTrue(); unexpectedError(err, caseName, 'ohosWindow.create ' + baseType, done);
});
}
catch(err) {
console.log(msgStr + 'ohosWindow.create catch err:' + JSON.stringify(err));
}
let findWnd = null; let findWnd = null;
ohosWindow.find(wndId).then((data) => { await ohosWindow.find(wndId).then((data) => {
findWnd = data findWnd = data
}).catch((err) => { }).catch((err) => {
unexpectedError(err, caseName, 'ohosWindow.find', done); unexpectedError(err, caseName, 'ohosWindow.find', done);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册