11401458bSopenharmony_ci/* 21401458bSopenharmony_ci * Copyright (C) 2022 Huawei Device Co., Ltd. 31401458bSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 41401458bSopenharmony_ci * you may not use this file except in compliance with the License. 51401458bSopenharmony_ci * You may obtain a copy of the License at 61401458bSopenharmony_ci * 71401458bSopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 81401458bSopenharmony_ci * 91401458bSopenharmony_ci * Unless required by applicable law or agreed to in writing, software 101401458bSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 111401458bSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 121401458bSopenharmony_ci * See the License for the specific language governing permissions and 131401458bSopenharmony_ci * limitations under the License. 141401458bSopenharmony_ci */ 151401458bSopenharmony_ci 161401458bSopenharmony_ciimport hiSysEvent from "@ohos.hiSysEvent" 171401458bSopenharmony_ci 181401458bSopenharmony_ciimport {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index' 191401458bSopenharmony_ci 201401458bSopenharmony_cidescribe('hiSysEventPermissionJsTest', function () { 211401458bSopenharmony_ci beforeAll(function() { 221401458bSopenharmony_ci 231401458bSopenharmony_ci /** 241401458bSopenharmony_ci * @tc.setup: setup invoked before all test cases 251401458bSopenharmony_ci */ 261401458bSopenharmony_ci console.info('hiSysEventPermissionJsTest beforeAll called') 271401458bSopenharmony_ci }) 281401458bSopenharmony_ci 291401458bSopenharmony_ci afterAll(function() { 301401458bSopenharmony_ci 311401458bSopenharmony_ci /** 321401458bSopenharmony_ci * @tc.teardown: teardown invoked after all test cases 331401458bSopenharmony_ci */ 341401458bSopenharmony_ci console.info('hiSysEventPermissionJsTest afterAll called') 351401458bSopenharmony_ci }) 361401458bSopenharmony_ci 371401458bSopenharmony_ci beforeEach(function() { 381401458bSopenharmony_ci 391401458bSopenharmony_ci /** 401401458bSopenharmony_ci * @tc.setup: setup invoked before each test case 411401458bSopenharmony_ci */ 421401458bSopenharmony_ci console.info('hiSysEventPermissionJsTest beforeEach called') 431401458bSopenharmony_ci }) 441401458bSopenharmony_ci 451401458bSopenharmony_ci afterEach(function() { 461401458bSopenharmony_ci 471401458bSopenharmony_ci /** 481401458bSopenharmony_ci * @tc.teardown: teardown invoked after each test case 491401458bSopenharmony_ci */ 501401458bSopenharmony_ci console.info('hiSysEventPermissionJsTest afterEach called') 511401458bSopenharmony_ci }) 521401458bSopenharmony_ci 531401458bSopenharmony_ci /** 541401458bSopenharmony_ci * @tc.name: hiSysEventPermissionJsTest001 551401458bSopenharmony_ci * @tc.desc: Test the write interface with callbak. 561401458bSopenharmony_ci * @tc.type: FUNC 571401458bSopenharmony_ci */ 581401458bSopenharmony_ci it('hiSysEventPermissionJsTest001', 0, async function (done) { 591401458bSopenharmony_ci console.info('hiSysEventPermissionJsTest001 start') 601401458bSopenharmony_ci try { 611401458bSopenharmony_ci hiSysEvent.write({ 621401458bSopenharmony_ci domain: "RELIABILITY", 631401458bSopenharmony_ci name: "STACK", 641401458bSopenharmony_ci eventType: hiSysEvent.EventType.FAULT, 651401458bSopenharmony_ci params: {} 661401458bSopenharmony_ci }, (err) => { 671401458bSopenharmony_ci expect(false).assertTrue() 681401458bSopenharmony_ci done() 691401458bSopenharmony_ci }) 701401458bSopenharmony_ci } catch (err) { 711401458bSopenharmony_ci expect(err.code == 202).assertTrue() 721401458bSopenharmony_ci console.info('hiSysEventPermissionJsTest001 end') 731401458bSopenharmony_ci done() 741401458bSopenharmony_ci } 751401458bSopenharmony_ci }) 761401458bSopenharmony_ci 771401458bSopenharmony_ci /** 781401458bSopenharmony_ci * @tc.name: hiSysEventPermissionJsTest002 791401458bSopenharmony_ci * @tc.desc: Test the write interface with promise. 801401458bSopenharmony_ci * @tc.type: FUNC 811401458bSopenharmony_ci */ 821401458bSopenharmony_ci it('hiSysEventPermissionJsTest002', 0, async function (done) { 831401458bSopenharmony_ci console.info('hiSysEventPermissionJsTest002 start') 841401458bSopenharmony_ci try { 851401458bSopenharmony_ci hiSysEvent.write({ 861401458bSopenharmony_ci domain: "RELIABILITY", 871401458bSopenharmony_ci name: "STACK", 881401458bSopenharmony_ci eventType: hiSysEvent.EventType.FAULT, 891401458bSopenharmony_ci params: {} 901401458bSopenharmony_ci }).then( 911401458bSopenharmony_ci () => { 921401458bSopenharmony_ci expect(false).assertTrue() 931401458bSopenharmony_ci done() 941401458bSopenharmony_ci } 951401458bSopenharmony_ci ).catch( 961401458bSopenharmony_ci (err) => { 971401458bSopenharmony_ci expect(false).assertTrue() 981401458bSopenharmony_ci done() 991401458bSopenharmony_ci } 1001401458bSopenharmony_ci ); 1011401458bSopenharmony_ci } catch (err) { 1021401458bSopenharmony_ci expect(err.code == 202).assertTrue() 1031401458bSopenharmony_ci console.info('hiSysEventPermissionJsTest002 end') 1041401458bSopenharmony_ci done() 1051401458bSopenharmony_ci } 1061401458bSopenharmony_ci }) 1071401458bSopenharmony_ci 1081401458bSopenharmony_ci /** 1091401458bSopenharmony_ci * @tc.name: hiSysEventPermissionJsTest003 1101401458bSopenharmony_ci * @tc.desc: Test the addWatcher interface. 1111401458bSopenharmony_ci * @tc.type: FUNC 1121401458bSopenharmony_ci */ 1131401458bSopenharmony_ci it('hiSysEventPermissionJsTest003', 0, function () { 1141401458bSopenharmony_ci console.info('hiSysEventPermissionJsTest003 start') 1151401458bSopenharmony_ci let watcher = { 1161401458bSopenharmony_ci rules: [{ 1171401458bSopenharmony_ci domain: "RELIABILITY", 1181401458bSopenharmony_ci name: "STACK", 1191401458bSopenharmony_ci tag: "STABILITY", 1201401458bSopenharmony_ci ruleType: hiSysEvent.RuleType.WHOLE_WORD, 1211401458bSopenharmony_ci }], 1221401458bSopenharmony_ci onEvent: (info) => {}, 1231401458bSopenharmony_ci onServiceDied: () => {} 1241401458bSopenharmony_ci } 1251401458bSopenharmony_ci try { 1261401458bSopenharmony_ci hiSysEvent.addWatcher(watcher) 1271401458bSopenharmony_ci } catch (err) { 1281401458bSopenharmony_ci expect(err.code == 202).assertTrue() 1291401458bSopenharmony_ci console.info('hiSysEventPermissionJsTest003 end') 1301401458bSopenharmony_ci } 1311401458bSopenharmony_ci }) 1321401458bSopenharmony_ci 1331401458bSopenharmony_ci /** 1341401458bSopenharmony_ci * @tc.name: hiSysEventPermissionJsTest004 1351401458bSopenharmony_ci * @tc.desc: Test the removeWatcher interface. 1361401458bSopenharmony_ci * @tc.type: FUNC 1371401458bSopenharmony_ci */ 1381401458bSopenharmony_ci it('hiSysEventPermissionJsTest004', 0, function () { 1391401458bSopenharmony_ci console.info('hiSysEventPermissionJsTest004 start') 1401401458bSopenharmony_ci let watcher = { 1411401458bSopenharmony_ci rules: [{ 1421401458bSopenharmony_ci domain: "RELIABILITY", 1431401458bSopenharmony_ci name: "STACK", 1441401458bSopenharmony_ci tag: "STABILITY", 1451401458bSopenharmony_ci ruleType: hiSysEvent.RuleType.WHOLE_WORD, 1461401458bSopenharmony_ci }], 1471401458bSopenharmony_ci onEvent: (info) => {}, 1481401458bSopenharmony_ci onServiceDied: () => {} 1491401458bSopenharmony_ci } 1501401458bSopenharmony_ci try { 1511401458bSopenharmony_ci hiSysEvent.removeWatcher(watcher) 1521401458bSopenharmony_ci } catch (err) { 1531401458bSopenharmony_ci expect(err.code == 202).assertTrue() 1541401458bSopenharmony_ci console.info('hiSysEventPermissionJsTest004 end') 1551401458bSopenharmony_ci } 1561401458bSopenharmony_ci }) 1571401458bSopenharmony_ci 1581401458bSopenharmony_ci /** 1591401458bSopenharmony_ci * @tc.name: hiSysEventPermissionJsTest005 1601401458bSopenharmony_ci * @tc.desc: Test the query interface. 1611401458bSopenharmony_ci * @tc.type: FUNC 1621401458bSopenharmony_ci */ 1631401458bSopenharmony_ci it('hiSysEventPermissionJsTest005', 0, function () { 1641401458bSopenharmony_ci console.info('hiSysEventPermissionJsTest005 start') 1651401458bSopenharmony_ci try { 1661401458bSopenharmony_ci hiSysEvent.query({ 1671401458bSopenharmony_ci beginTime: 0, 1681401458bSopenharmony_ci endTime: 0, 1691401458bSopenharmony_ci maxEvents: 100, 1701401458bSopenharmony_ci }, [{ 1711401458bSopenharmony_ci domain: "RELIABILITY", 1721401458bSopenharmony_ci names: ["STACK"], 1731401458bSopenharmony_ci }], { 1741401458bSopenharmony_ci onQuery: function () {}, 1751401458bSopenharmony_ci onComplete: function() {} 1761401458bSopenharmony_ci }) 1771401458bSopenharmony_ci } catch (err) { 1781401458bSopenharmony_ci expect(err.code == 202).assertTrue() 1791401458bSopenharmony_ci console.info('hiSysEventPermissionJsTest005 end') 1801401458bSopenharmony_ci } 1811401458bSopenharmony_ci }) 1821401458bSopenharmony_ci});