diff --git a/hiviewdfx/hiappeventtest/hiappeventsubjstest/src/main/js/test/HiAppEventSubSecond.test.js b/hiviewdfx/hiappeventtest/hiappeventsubjstest/src/main/js/test/HiAppEventSubSecond.test.js new file mode 100644 index 0000000000000000000000000000000000000000..68d67823bbc0c3af09ec2a35216dbde66022cbad --- /dev/null +++ b/hiviewdfx/hiappeventtest/hiappeventsubjstest/src/main/js/test/HiAppEventSubSecond.test.js @@ -0,0 +1,1163 @@ +/* + * Copyright (C) 2021-2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import HiAppEventV9 from '@ohos.hiviewdfx.hiAppEvent' +import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from '@ohos/hypium' +import Constant from 'deccjsunit/src/Constant' + +export default function HiAppEventSubSecondTest() { +describe('HiAppEventSubSecondTest', function () { + + /** + * @tc.number DFX_DFT_HiAppEvent_Sub_3000 + * @tc.name 验证调用write接口,缺少write参数,无法打点,错误码401。 + * @tc.desc HiAppEvent write interface test. + */ + it('HiAppEventSub30', 3, async function (done) { + console.info('testHiAppEventSub30 start') + try{ + HiAppEventV9.write( (err) => { + if (err) { + console.error(`HiAppEventSub30 >code: ${err.code}, message: ${err.message}`); + return; + } + console.log(`success to write event`); + }); + } catch (err) { + console.error(`HiAppEventSub30 delay > error code: ${err.code}, error msg: ${err.message}`) + expect(err.code == 401).assertTrue() + console.info('HiAppEventSub30 end') + done() + } + }) + + /** + * @tc.number DFX_DFT_HiAppEvent_Sub_3100 + * @tc.name 验证调用addWatcher接口,缺少name参数,订阅失败,错误码401。 + * @tc.desc HiAppEvent write interface test. + */ + it('HiAppEventSub31', 3, async function (done) { + console.info('testHiAppEventSub31 start') + try{ + let result = HiAppEventV9.addWatcher({ + appEventFilters: [ + { + domain: "test_domain" + } + ], + triggerCondition: { + row: 1, + }, + onTrigger: function (curRow, curSize, holder) { + } + }) + expect(result == null).assertTrue(); + } catch (err) { + console.error(`HiAppEventSub31 delay > error code: ${err.code}, error msg: ${err.message}`) + expect(err.code == 401).assertTrue() + console.info('HiAppEventSub31 end') + done() + } + }) + + /** + * @tc.number DFX_DFT_HiAppEvent_Sub_3200 + * @tc.name 验证调用write接口,打点功能被关闭,打点错误,返回错误码11100001 + * @tc.desc HiAppEvent write interface test. + */ + it('HiAppEventSub32', 3, async function (done) { + console.info('testHiAppEventSub32 start') + try{ + HiAppEventV9.configure({ + disable: true + }); + HiAppEventV9.write({ + domain: "test_domain", + name: "test_event", + eventType: HiAppEventV9.EventType.FAULT, + params: { + int_data: 100, + str_data: "strValue" + } + }, (err) => { + if (err) { + console.error(`HiAppEventSub32 > code: ${err.code}, message: ${err.message}`); + expect(err.code == 11100001).assertTrue() + done() + return; + } + console.log(`success to write event`); + }); + HiAppEventV9.configure({ + disable: false + }); + + } catch (err) { + console.error(`HiAppEventSub32 delay > error code: ${err.code}, error msg: ${err.message}`) + expect(false).assertTrue() + console.info('HiAppEventSub32 end') + done() + } + }) + + /** + * @tc.number DFX_DFT_HiAppEvent_Sub_3300 + * @tc.name 验证调用write接口,事件领域名称包含特殊字符,打点错误,返回错误码11101001 + * @tc.desc HiAppEvent write interface test. + */ + it('HiAppEventSub33', 3, async function (done) { + console.info('testHiAppEventSub33 start') + try{ + HiAppEventV9.write({ + domain: "test_?domain", + name: "test_event", + eventType: HiAppEventV9.EventType.FAULT, + params: { + int_data: 100, + str_data: "strValue" + } + }, (err) => { + if (err) { + console.error(`HiAppEventSub33 > code: ${err.code}, message: ${err.message}`); + expect(err.code == 11101001).assertTrue() + done() + return; + } + console.log(`success to write event`); + }); + } catch (err) { + console.error(`HiAppEventSub33 delay > error code: ${err.code}, error msg: ${err.message}`) + expect(false).assertTrue() + console.info('HiAppEventSub33 end') + done() + } + }) + + /** + * @tc.number DFX_DFT_HiAppEvent_Sub_3400 + * @tc.name 验证调用write接口,事件领域名称以下划线结尾,打点错误,返回错误码11101001 + * @tc.desc HiAppEvent write interface test. + */ + it('HiAppEventSub34', 3, async function (done) { + console.info('testHiAppEventSub34 start') + try{ + HiAppEventV9.write({ + domain: "test_domain_", + name: "test_event", + eventType: HiAppEventV9.EventType.FAULT, + params: { + int_data: 100, + str_data: "strValue" + } + }, (err) => { + if (err) { + console.error(`HiAppEventSub34 > code: ${err.code}, message: ${err.message}`); + expect(err.code == 11101001).assertTrue() + done() + return; + } + console.log(`success to write event`); + }); + } catch (err) { + console.error(`HiAppEventSub34 delay > error code: ${err.code}, error msg: ${err.message}`) + expect(false).assertTrue() + console.info('HiAppEventSub34 end') + done() + } + }) + + /** + * @tc.number DFX_DFT_HiAppEvent_Sub_3500 + * @tc.name 验证调用write接口,事件领域名称为空,打点错误,返回错误码11101001 + * @tc.desc HiAppEvent write interface test. + */ + it('HiAppEventSub35', 3, async function (done) { + console.info('testHiAppEventSub35 start') + try{ + HiAppEventV9.write({ + domain: "", + name: "test_event", + eventType: HiAppEventV9.EventType.FAULT, + params: { + int_data: 100, + str_data: "strValue" + } + }, (err) => { + if (err) { + console.error(`HiAppEventSub35 > code: ${err.code}, message: ${err.message}`); + expect(err.code == 11101001).assertTrue() + done() + return; + } + console.log(`success to write event`); + }); + } catch (err) { + console.error(`HiAppEventSub35 delay > error code: ${err.code}, error msg: ${err.message}`) + expect(false).assertTrue() + console.info('HiAppEventSub35 end') + done() + } + }) + + /** + * @tc.number DFX_DFT_HiAppEvent_Sub_3600 + * @tc.name 验证调用write接口,事件领域名称超长,打点错误,返回错误码11101001 + * @tc.desc HiAppEvent write interface test. + */ + it('HiAppEventSub36', 3, async function (done) { + console.info('testHiAppEventSub36 start') + try{ + HiAppEventV9.write({ + domain: "test_domain_test_domain_test_domain_test_domain", + name: "test_event", + eventType: HiAppEventV9.EventType.FAULT, + params: { + int_data: 100, + str_data: "strValue" + } + }, (err) => { + if (err) { + console.error(`HiAppEventSub36 > code: ${err.code}, message: ${err.message}`); + expect(err.code == 11101001).assertTrue() + done() + return; + } + console.log(`success to write event`); + }); + } catch (err) { + console.error(`HiAppEventSub36 delay > error code: ${err.code}, error msg: ${err.message}`) + expect(false).assertTrue() + console.info('HiAppEventSub36 end') + done() + } + }) + + /** + * @tc.number DFX_DFT_HiAppEvent_Sub_3700 + * @tc.name 验证调用write接口,事件领域名称大写字母开头,打点错误,返回错误码11101001 + * @tc.desc HiAppEvent write interface test. + */ + it('HiAppEventSub37', 3, async function (done) { + console.info('testHiAppEventSub37 start') + try{ + HiAppEventV9.write({ + domain: "Test_domain", + name: "test_event", + eventType: HiAppEventV9.EventType.FAULT, + params: { + int_data: 100, + str_data: "strValue" + } + }, (err) => { + if (err) { + console.error(`HiAppEventSub37 > code: ${err.code}, message: ${err.message}`); + expect(err.code == 11101001).assertTrue() + done() + return; + } + console.log(`success to write event`); + }); + } catch (err) { + console.error(`HiAppEventSub37 delay > error code: ${err.code}, error msg: ${err.message}`) + expect(false).assertTrue() + console.info('HiAppEventSub37 end') + done() + } + }) + + /** + * @tc.number DFX_DFT_HiAppEvent_Sub_3800 + * @tc.name 验证调用write接口,事件名称包含特殊字符,打点错误,返回错误码11101002 + * @tc.desc HiAppEvent write interface test. + */ + it('HiAppEventSub38', 3, async function (done) { + console.info('testHiAppEventSub38 start') + try{ + HiAppEventV9.write({ + domain: "test_domain", + name: "test_?event", + eventType: HiAppEventV9.EventType.FAULT, + params: { + int_data: 100, + str_data: "strValue" + } + }, (err) => { + if (err) { + console.error(`HiAppEventSub38 > code: ${err.code}, message: ${err.message}`); + expect(err.code == 11101002).assertTrue() + done() + return; + } + console.log(`success to write event`); + }); + } catch (err) { + console.error(`HiAppEventSub38 delay > error code: ${err.code}, error msg: ${err.message}`) + expect(false).assertTrue() + console.info('HiAppEventSub38 end') + done() + } + }) + + /** + * @tc.number DFX_DFT_HiAppEvent_Sub_3900 + * @tc.name 验证调用write接口,事件名称以下划线结尾,打点错误,返回错误码11101002 + * @tc.desc HiAppEvent write interface test. + */ + it('HiAppEventSub39', 3, async function (done) { + console.info('testHiAppEventSub39 start') + try{ + HiAppEventV9.write({ + domain: "test_domain", + name: "test_event_", + eventType: HiAppEventV9.EventType.FAULT, + params: { + int_data: 100, + str_data: "strValue" + } + }, (err) => { + if (err) { + console.error(`HiAppEventSub39 > code: ${err.code}, message: ${err.message}`); + expect(err.code == 11101002).assertTrue() + done() + return; + } + console.log(`success to write event`); + }); + } catch (err) { + console.error(`HiAppEventSub39 delay > error code: ${err.code}, error msg: ${err.message}`) + expect(false).assertTrue() + console.info('HiAppEventSub39 end') + done() + } + }) + + /** + * @tc.number DFX_DFT_HiAppEvent_Sub_4000 + * @tc.name 验证调用write接口,事件名称为空,打点错误,返回错误码11101002 + * @tc.desc HiAppEvent write interface test. + */ + it('HiAppEventSub40', 3, async function (done) { + console.info('testHiAppEventSub40 start') + try{ + HiAppEventV9.write({ + domain: "test_domain", + name: "", + eventType: HiAppEventV9.EventType.FAULT, + params: { + int_data: 100, + str_data: "strValue" + } + }, (err) => { + if (err) { + console.error(`HiAppEventSub40 > code: ${err.code}, message: ${err.message}`); + expect(err.code == 11101002).assertTrue() + done() + return; + } + console.log(`success to write event`); + }); + } catch (err) { + console.error(`HiAppEventSub40 delay > error code: ${err.code}, error msg: ${err.message}`) + expect(false).assertTrue() + console.info('HiAppEventSub40 end') + done() + } + }) + + /** + * @tc.number DFX_DFT_HiAppEvent_Sub_4100 + * @tc.name 验证调用write接口,事件名称超长,打点错误,返回错误码11101002 + * @tc.desc HiAppEvent write interface test. + */ + it('HiAppEventSub41', 3, async function (done) { + console.info('testHiAppEventSub41 start') + try{ + HiAppEventV9.write({ + domain: "test_domain", + name: "test_event_test_event_test_event_test_event_test_event", + eventType: HiAppEventV9.EventType.FAULT, + params: { + int_data: 100, + str_data: "strValue" + } + }, (err) => { + if (err) { + console.error(`HiAppEventSub41 > code: ${err.code}, message: ${err.message}`); + expect(err.code == 11101002).assertTrue() + done() + return; + } + console.log(`success to write event`); + }); + } catch (err) { + console.error(`HiAppEventSub41 delay > error code: ${err.code}, error msg: ${err.message}`) + expect(false).assertTrue() + console.info('HiAppEventSub41 end') + done() + } + }) + + /** + * @tc.number DFX_DFT_HiAppEvent_Sub_4200 + * @tc.name 验证调用write接口,事件名称大写字母开头,打点错误,返回错误码11101002 + * @tc.desc HiAppEvent write interface test. + */ + it('HiAppEventSub42', 3, async function (done) { + console.info('testHiAppEventSub42 start') + try{ + HiAppEventV9.write({ + domain: "test_domain", + name: "Test_event", + eventType: HiAppEventV9.EventType.FAULT, + params: { + int_data: 100, + str_data: "strValue" + } + }, (err) => { + if (err) { + console.error(`HiAppEventSub42 > code: ${err.code}, message: ${err.message}`); + expect(err.code == 11101002).assertTrue() + done() + return; + } + console.log(`success to write event`); + }); + } catch (err) { + console.error(`HiAppEventSub42 delay > error code: ${err.code}, error msg: ${err.message}`) + expect(false).assertTrue() + console.info('HiAppEventSub42 end') + done() + } + }) + + /** + * @tc.number DFX_DFT_HiAppEvent_Sub_4300 + * @tc.name 验证调用write接口,参数数量非法,丢弃额外事件,返回错误码11101003 + * @tc.desc HiAppEvent write interface test. + */ + it('HiAppEventSub43', 3, async function (done) { + console.info('testHiAppEventSub43 start') + try{ + let largeParams = {} + for (let i = 0; i <33 ; i++) { + largeParams["name" + i] = i + } + HiAppEventV9.write({ + domain: "test_domain", + name: "test_event", + eventType: HiAppEventV9.EventType.FAULT, + params: largeParams + }, (err) => { + if (err) { + console.error(`HiAppEventSub43 > code: ${err.code}, message: ${err.message}`); + expect(err.code == 11101003).assertTrue() + done() + return; + } + console.log(`success to write event`); + }); + } catch (err) { + console.error(`HiAppEventSub43 delay > error code: ${err.code}, error msg: ${err.message}`) + expect(false).assertTrue() + console.info('HiAppEventSub43 end') + done() + } + }) + + /** + * @tc.number DFX_DFT_HiAppEvent_Sub_4400 + * @tc.name 验证调用write接口,事件参数值传入了超长的字符串,丢弃额外字符,返回错误码11101004 + * @tc.desc HiAppEvent write interface test. + */ + it('HiAppEventSub44', 3, async function (done) { + console.info('testHiAppEventSub44 start') + try{ + let longStr = "a".repeat(8*1024 + 1); + HiAppEventV9.write({ + domain: "test_domain", + name: "test_event", + eventType: HiAppEventV9.EventType.FAULT, + params: { + int_data: 100, + str_data:longStr + } + }, (err) => { + if (err) { + console.error(`HiAppEventSub44 > code: ${err.code}, message: ${err.message}`); + expect(err.code == 11101004).assertTrue() + done() + return; + } + console.log(`success to write event`); + }); + } catch (err) { + console.error(`HiAppEventSub44 delay > error code: ${err.code}, error msg: ${err.message}`) + expect(false).assertTrue() + console.info('HiAppEventSub44 end') + done() + } + }) + + /** + * @tc.number DFX_DFT_HiAppEvent_Sub_4500 + * @tc.name 验证调用write接口,事件参数名称以下划线结尾,忽略相关事件参数,返回错误码11101005 + * @tc.desc HiAppEvent write interface test. + */ + it('HiAppEventSub45', 3, async function (done) { + console.info('testHiAppEventSub45 start') + try{ + HiAppEventV9.write({ + domain: "test_domain", + name: "test_event", + eventType: HiAppEventV9.EventType.FAULT, + params: { + "int_?data": 100, + str_data: "strValue" + } + }, (err) => { + if (err) { + console.error(`HiAppEventSub45 > code: ${err.code}, message: ${err.message}`); + expect(err.code == 11101005).assertTrue() + done() + return; + } + console.log(`success to write event`); + }); + } catch (err) { + console.error(`HiAppEventSub45 delay > error code: ${err.code}, error msg: ${err.message}`) + expect(false).assertTrue() + console.info('HiAppEventSub45 end') + done() + } + }) + + /** + * @tc.number DFX_DFT_HiAppEvent_Sub_4600 + * @tc.name 验证调用write接口,事件参数名称以下划线结尾,忽略相关事件参数,返回错误码11101005 + * @tc.desc HiAppEvent write interface test. + */ + it('HiAppEventSub46', 3, async function (done) { + console.info('testHiAppEventSub46 start') + try{ + HiAppEventV9.write({ + domain: "test_domain", + name: "test_event", + eventType: HiAppEventV9.EventType.FAULT, + params: { + int_data_: 100, + str_data: "strValue" + } + }, (err) => { + if (err) { + console.error(`HiAppEventSub46 > code: ${err.code}, message: ${err.message}`); + expect(err.code == 11101005).assertTrue() + done() + return; + } + console.log(`success to write event`); + }); + } catch (err) { + console.error(`HiAppEventSub46 delay > error code: ${err.code}, error msg: ${err.message}`) + expect(false).assertTrue() + console.info('HiAppEventSub46 end') + done() + } + }) + + /** + * @tc.number DFX_DFT_HiAppEvent_Sub_4700 + * @tc.name 验证调用write接口,事件参数名称为空,忽略相关事件参数,返回错误码11101005 + * @tc.desc HiAppEvent write interface test. + */ + it('HiAppEventSub47', 3, async function (done) { + console.info('testHiAppEventSub47 start') + try{ + HiAppEventV9.write({ + domain: "test_domain", + name: "test_event", + eventType: HiAppEventV9.EventType.FAULT, + params: { + "": 100, + str_data: "strValue" + } + }, (err) => { + if (err) { + console.error(`HiAppEventSub47 > code: ${err.code}, message: ${err.message}`); + expect(err.code == 11101005).assertTrue() + done() + return; + } + console.log(`success to write event`); + }); + } catch (err) { + console.error(`HiAppEventSub47 delay > error code: ${err.code}, error msg: ${err.message}`) + expect(false).assertTrue() + console.info('HiAppEventSub47 end') + done() + } + }) + + /** + * @tc.number DFX_DFT_HiAppEvent_Sub_4800 + * @tc.name 验证调用write接口,事件参数名称超长,忽略相关事件参数,返回错误码11101005 + * @tc.desc HiAppEvent write interface test. + */ + it('HiAppEventSub48', 3, async function (done) { + console.info('testHiAppEventSub48 start') + try{ + HiAppEventV9.write({ + domain: "test_domain", + name: "test_event", + eventType: HiAppEventV9.EventType.FAULT, + params: { + int_data_int_data_int_data_int_data: 100, + str_data: "strValue" + } + }, (err) => { + if (err) { + console.error(`HiAppEventSub48 > code: ${err.code}, message: ${err.message}`); + expect(err.code == 11101005).assertTrue() + done() + return; + } + console.log(`success to write event`); + }); + } catch (err) { + console.error(`HiAppEventSub48 delay > error code: ${err.code}, error msg: ${err.message}`) + expect(false).assertTrue() + console.info('HiAppEventSub48 end') + done() + } + }) + + /** + * @tc.number DFX_DFT_HiAppEvent_Sub_4900 + * @tc.name 验证调用write接口,事件参数名称大写字母开头,忽略相关事件参数,返回错误码11101005 + * @tc.desc HiAppEvent write interface test. + */ + it('HiAppEventSub49', 3, async function (done) { + console.info('testHiAppEventSub49 start') + try{ + HiAppEventV9.write({ + domain: "test_domain", + name: "test_event", + eventType: HiAppEventV9.EventType.FAULT, + params: { + Int_data: 100, + str_data: "strValue" + } + }, (err) => { + if (err) { + console.error(`HiAppEventSub49 > code: ${err.code}, message: ${err.message}`); + expect(err.code == 11101005).assertTrue() + done() + return; + } + console.log(`success to write event`); + }); + } catch (err) { + console.error(`HiAppEventSub49 delay > error code: ${err.code}, error msg: ${err.message}`) + expect(false).assertTrue() + console.info('HiAppEventSub49 end') + done() + } + }) + + /** + * @tc.number DFX_DFT_HiAppEvent_Sub_5000 + * @tc.name 验证调用write接口,事件参数值传入了超出长度的数组,丢弃额外数组元素,返回错误码11101006 + * @tc.desc HiAppEvent write interface test. + */ + it('HiAppEventSub50', 3, async function (done) { + console.info('testHiAppEventSub50 start') + try{ + let msgArray = [] + for (let i = 0; i < 101; i++) { + msgArray[i] = i + } + HiAppEventV9.write({ + domain: "test_domain", + name: "test_event", + eventType: HiAppEventV9.EventType.FAULT, + params: { + int_data: 100, + str_data: "strValue", + msg: msgArray + } + }, (err) => { + if (err) { + console.error(`HiAppEventSub50 > code: ${err.code}, message: ${err.message}`); + expect(err.code == 11101006).assertTrue() + done() + return; + } + console.log(`success to write event`); + }); + } catch (err) { + console.error(`HiAppEventSub50 delay > error code: ${err.code}, error msg: ${err.message}`) + expect(false).assertTrue() + console.info('HiAppEventSub50 end') + done() + } + }) + + /** + * @tc.number DFX_DFT_HiAppEvent_Sub_5100 + * @tc.name 验证调用addWatcher接口,watcher名称包含特殊字符,忽略忽略此次订阅,返回错误码11102001 + * @tc.desc HiAppEvent write interface test. + */ + it('HiAppEventSub51', 3, async function (done) { + console.info('testHiAppEventSub11 start') + try{ + let result = HiAppEventV9.addWatcher({ + name: "watcher1?", + appEventFilters: [ + { + domain: "test_domain" + } + ], + triggerCondition: { + row: 1, + }, + onTrigger: function (curRow, curSize, holder) { + } + }) + expect(result == null).assertTrue(); + } catch (err) { + console.error(`HiAppEventSub51 delay > error code: ${err.code}, error msg: ${err.message}`) + expect(err.code == 11102001).assertTrue() + console.info('HiAppEventSub51 end') + done() + } + }) + + /** + * @tc.number DFX_DFT_HiAppEvent_Sub_5200 + * @tc.name 验证调用addWatcher接口,watcher名称以下划线结尾,忽略忽略此次订阅,返回错误码11102001 + * @tc.desc HiAppEvent write interface test. + */ + it('HiAppEventSub52', 3, async function (done) { + console.info('testHiAppEventSub11 start') + try{ + let result = HiAppEventV9.addWatcher({ + name: "watcher_", + appEventFilters: [ + { + domain: "test_domain" + } + ], + triggerCondition: { + row: 1, + }, + onTrigger: function (curRow, curSize, holder) { + } + }) + expect(result == null).assertTrue(); + } catch (err) { + console.error(`HiAppEventSub52 delay > error code: ${err.code}, error msg: ${err.message}`) + expect(err.code == 11102001).assertTrue() + console.info('HiAppEventSub52 end') + done() + } + }) + + /** + * @tc.number DFX_DFT_HiAppEvent_Sub_5300 + * @tc.name 验证调用addWatcher接口,watcher名称为空,忽略忽略此次订阅,返回错误码11102001 + * @tc.desc HiAppEvent write interface test. + */ + it('HiAppEventSub53', 3, async function (done) { + console.info('testHiAppEventSub53 start') + try{ + let result = HiAppEventV9.addWatcher({ + name: "", + appEventFilters: [ + { + domain: "test_domain" + } + ], + triggerCondition: { + row: 1, + }, + onTrigger: function (curRow, curSize, holder) { + } + }) + expect(result == null).assertTrue(); + } catch (err) { + console.error(`HiAppEventSub53 delay > error code: ${err.code}, error msg: ${err.message}`) + expect(err.code == 11102001).assertTrue() + console.info('HiAppEventSub53 end') + done() + } + }) + + /** + * @tc.number DFX_DFT_HiAppEvent_Sub_5400 + * @tc.name 验证调用addWatcher接口,watcher名称超长,忽略忽略此次订阅,返回错误码11102001 + * @tc.desc HiAppEvent write interface test. + */ + it('HiAppEventSub54', 3, async function (done) { + console.info('testHiAppEventSub54 start') + try{ + let result = HiAppEventV9.addWatcher({ + name: "watcher1watcher2watcher3watcher4watcher5", + appEventFilters: [ + { + domain: "test_domain" + } + ], + triggerCondition: { + row: 1, + }, + onTrigger: function (curRow, curSize, holder) { + } + }) + expect(result == null).assertTrue(); + } catch (err) { + console.error(`HiAppEventSub54 delay > error code: ${err.code}, error msg: ${err.message}`) + expect(err.code == 11102001).assertTrue() + console.info('HiAppEventSub54 end') + done() + } + }) + + /** + * @tc.number DFX_DFT_HiAppEvent_Sub_5500 + * @tc.name 验证调用addWatcher接口,watcher名称以大写字母开头,忽略忽略此次订阅,返回错误码11102001 + * @tc.desc HiAppEvent write interface test. + */ + it('HiAppEventSub55', 3, async function (done) { + console.info('testHiAppEventSub55 start') + try{ + let result = HiAppEventV9.addWatcher({ + name: "Watcher1", + appEventFilters: [ + { + domain: "test_domain" + } + ], + triggerCondition: { + row: 1, + }, + onTrigger: function (curRow, curSize, holder) { + } + }) + expect(result == null).assertTrue(); + } catch (err) { + console.error(`HiAppEventSub55 delay > error code: ${err.code}, error msg: ${err.message}`) + expect(err.code == 11102001).assertTrue() + console.info('HiAppEventSub55 end') + done() + } + }) + + /** + * @tc.number DFX_DFT_HiAppEvent_Sub_5600 + * @tc.name 验证调用addWatcher接口,过滤事件领域名称包含特殊字符,忽略忽略此次订阅,返回错误码11102002 + * @tc.desc HiAppEvent write interface test. + */ + it('HiAppEventSub56', 3, async function (done) { + console.info('testHiAppEventSub56 start') + try{ + let result = HiAppEventV9.addWatcher({ + name: "watcher1", + appEventFilters: [ + { + domain: "test_?domain" + } + ], + triggerCondition: { + row: 1, + }, + onTrigger: function (curRow, curSize, holder) { + } + }) + expect(result == null).assertTrue(); + } catch (err) { + console.error(`HiAppEventSub56 delay > error code: ${err.code}, error msg: ${err.message}`) + expect(err.code == 11102002).assertTrue() + console.info('HiAppEventSub56 end') + done() + } + }) + + /** + * @tc.number DFX_DFT_HiAppEvent_Sub_5700 + * @tc.name 验证调用addWatcher接口,过滤事件领域名称以下划线结尾,忽略忽略此次订阅,返回错误码11102002 + * @tc.desc HiAppEvent write interface test. + */ + it('HiAppEventSub57', 3, async function (done) { + console.info('testHiAppEventSub57 start') + try{ + let result = HiAppEventV9.addWatcher({ + name: "watcher1", + appEventFilters: [ + { + domain: "test_domain_" + } + ], + triggerCondition: { + row: 1, + }, + onTrigger: function (curRow, curSize, holder) { + } + }) + expect(result == null).assertTrue(); + } catch (err) { + console.error(`HiAppEventSub57 delay > error code: ${err.code}, error msg: ${err.message}`) + expect(err.code == 11102002).assertTrue() + console.info('HiAppEventSub57 end') + done() + } + }) + + /** + * @tc.number DFX_DFT_HiAppEvent_Sub_5800 + * @tc.name 验证调用addWatcher接口,过滤事件领域名称为空,忽略忽略此次订阅,返回错误码11102002 + * @tc.desc HiAppEvent write interface test. + */ + it('HiAppEventSub58', 3, async function (done) { + console.info('testHiAppEventSub58 start') + try{ + let result = HiAppEventV9.addWatcher({ + name: "watcher1", + appEventFilters: [ + { + domain: "" + } + ], + triggerCondition: { + row: 1, + }, + onTrigger: function (curRow, curSize, holder) { + } + }) + expect(result == null).assertTrue(); + } catch (err) { + console.error(`HiAppEventSub58 delay > error code: ${err.code}, error msg: ${err.message}`) + expect(err.code == 11102002).assertTrue() + console.info('HiAppEventSub58 end') + done() + } + }) + + /** + * @tc.number DFX_DFT_HiAppEvent_Sub_5900 + * @tc.name 验证调用addWatcher接口,过滤事件领域名称超长,忽略忽略此次订阅,返回错误码11102002 + * @tc.desc HiAppEvent write interface test. + */ + it('HiAppEventSub59', 3, async function (done) { + console.info('testHiAppEventSub59 start') + try{ + let result = HiAppEventV9.addWatcher({ + name: "watcher1", + appEventFilters: [ + { + domain: "test_domain_test_domain_test_domain_test_domain" + } + ], + triggerCondition: { + row: 1, + }, + onTrigger: function (curRow, curSize, holder) { + } + }) + expect(result == null).assertTrue(); + } catch (err) { + console.error(`HiAppEventSub59 delay > error code: ${err.code}, error msg: ${err.message}`) + expect(err.code == 11102002).assertTrue() + console.info('HiAppEventSub59 end') + done() + } + }) + + /** + * @tc.number DFX_DFT_HiAppEvent_Sub_6000 + * @tc.name 验证调用addWatcher接口,过滤事件领域名称以大写字母开头,忽略忽略此次订阅,返回错误码11102002 + * @tc.desc HiAppEvent write interface test. + */ + it('HiAppEventSub60', 3, async function (done) { + console.info('testHiAppEventSub60 start') + try{ + let result = HiAppEventV9.addWatcher({ + name: "watcher1", + appEventFilters: [ + { + domain: "Test_domain" + } + ], + triggerCondition: { + row: 1, + }, + onTrigger: function (curRow, curSize, holder) { + } + }) + expect(result == null).assertTrue(); + } catch (err) { + console.error(`HiAppEventSub60 delay > error code: ${err.code}, error msg: ${err.message}`) + expect(err.code == 11102002).assertTrue() + console.info('HiAppEventSub60 end') + done() + } + }) + + /** + * @tc.number DFX_DFT_HiAppEvent_Sub_6100 + * @tc.name 验证调用addWatcher接口,传入了非法的事件个数值,忽略忽略此次订阅,返回错误码11102003 + * @tc.desc HiAppEvent write interface test. + */ + it('HiAppEventSub61', 3, async function (done) { + console.info('testHiAppEventSub61 start') + try{ + let result = HiAppEventV9.addWatcher({ + name: "watcher1", + appEventFilters: [ + { + domain: "test_domain" + } + ], + triggerCondition: { + row: -1, + }, + onTrigger: function (curRow, curSize, holder) { + } + }) + expect(result == null).assertTrue(); + } catch (err) { + console.error(`HiAppEventSub61 delay > error code: ${err.code}, error msg: ${err.message}`) + expect(err.code == 11102003).assertTrue() + console.info('HiAppEventSub61 end') + done() + } + }) + + /** + * @tc.number DFX_DFT_HiAppEvent_Sub_6200 + * @tc.name 验证调用addWatcher接口,传入了非法的事件大小值,忽略忽略此次订阅,返回错误码11102004 + * @tc.desc HiAppEvent write interface test. + */ + it('HiAppEventSub62', 3, async function (done) { + console.info('testHiAppEventSub11 start') + try{ + let result = HiAppEventV9.addWatcher({ + name: "watcher1", + appEventFilters: [ + { + domain: "test_domain" + } + ], + triggerCondition: { + size: -1, + }, + onTrigger: function (curRow, curSize, holder) { + } + }) + expect(result == null).assertTrue(); + } catch (err) { + console.error(`HiAppEventSub62 delay > error code: ${err.code}, error msg: ${err.message}`) + expect(err.code == 11102004).assertTrue() + console.info('HiAppEventSub62 end') + done() + } + }) + + /** + * @tc.number DFX_DFT_HiAppEvent_Sub_6300 + * @tc.name 验证调用addWatcher接口,传入了非法的超时值,忽略忽略此次订阅,返回错误码11102005 + * @tc.desc HiAppEvent write interface test. + */ + it('HiAppEventSub63', 3, async function (done) { + console.info('testHiAppEventSub63 start') + try{ + let result = HiAppEventV9.addWatcher({ + name: "watcher1", + appEventFilters: [ + { + domain: "test_domain" + } + ], + triggerCondition: { + timeOut: -1, + }, + onTrigger: function (curRow, curSize, holder) { + } + }) + expect(result == null).assertTrue(); + } catch (err) { + console.error(`HiAppEventSub63 delay > error code: ${err.code}, error msg: ${err.message}`) + expect(err.code == 11102005).assertTrue() + console.info('HiAppEventSub63 end') + done() + } + }) + + /** + * @tc.number DFX_DFT_HiAppEvent_Sub_6400 + * @tc.name 验证调用configure接口,存储配额值含特殊字符,系统将忽略此次配置,返回错误码11103001 + * @tc.desc HiAppEvent write interface test. + */ + it('HiAppEventSub64', 3, async function (done) { + console.info('testHiAppEventSub64 start') + try{ + HiAppEventV9.configure({ + maxStorage: '100M?' + }); + } catch (err) { + console.error(`HiAppEventSub64 delay > error code: ${err.code}, error msg: ${err.message}`) + expect(err.code == 11103001).assertTrue() + console.info('HiAppEventSub64 end') + done() + } + }) + + /** + * @tc.number DFX_DFT_HiAppEvent_Sub_6500 + * @tc.name 验证调用configure接口,存储配额值无单位,系统将忽略此次配置,返回错误码11103001 + * @tc.desc HiAppEvent write interface test. + */ + it('HiAppEventSub65', 3, async function (done) { + console.info('testHiAppEventSub65 start') + try{ + HiAppEventV9.configure({ + maxStorage: '100A' + }); + } catch (err) { + console.error(`HiAppEventSub65 delay > error code: ${err.code}, error msg: ${err.message}`) + expect(err.code == 11103001).assertTrue() + console.info('HiAppEventSub65 end') + done() + } + }) + + /** + * @tc.number DFX_DFT_HiAppEvent_Sub_6600 + * @tc.name 验证调用setSize接口,事件包大小值为负,系统将忽略此次配置,返回错误码11104001 + * @tc.desc HiAppEvent write interface test. + */ + it('HiAppEventSub66', 3, async function (done) { + console.info('testHiAppEventSub66 start') + try{ + let holder = HiAppEventV9.addWatcher({ + name: "watcher", + }); + holder.setSize(-1000); + } catch (err) { + console.error(`HiAppEventSub66 delay > error code: ${err.code}, error msg: ${err.message}`) + expect(err.code == 11104001).assertTrue() + console.info('HiAppEventSub66 end') + done() + } + }) +}) +} \ No newline at end of file diff --git a/hiviewdfx/hiappeventtest/hiappeventsubjstest/src/main/js/test/List.test.js b/hiviewdfx/hiappeventtest/hiappeventsubjstest/src/main/js/test/List.test.js index 54d8f5ec188ada4642f0a8c59211bc0526949cff..47fd0c7f5e9b68159fb5a65510c2a6684e477c69 100755 --- a/hiviewdfx/hiappeventtest/hiappeventsubjstest/src/main/js/test/List.test.js +++ b/hiviewdfx/hiappeventtest/hiappeventsubjstest/src/main/js/test/List.test.js @@ -13,6 +13,8 @@ * limitations under the License. */ import HiAppEventSubTest from './HiAppEventSub.test.js' +import HiAppEventSubSecondTest from './HiAppEventSubSecond.test.js' export default function testsuite() { HiAppEventSubTest() +HiAppEventSubSecondTest() } diff --git a/hiviewdfx/hisyseventtest/hisyseventjstest/src/main/js/test/HiSysEventSecond.test.js b/hiviewdfx/hisyseventtest/hisyseventjstest/src/main/js/test/HiSysEventSecond.test.js new file mode 100644 index 0000000000000000000000000000000000000000..98d9607136131493e7f4a21188844c5859d1a20f --- /dev/null +++ b/hiviewdfx/hisyseventtest/hisyseventjstest/src/main/js/test/HiSysEventSecond.test.js @@ -0,0 +1,1357 @@ +/* + * Copyright (C) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import hiSysEvent from '@ohos.hiSysEvent' +import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from '@ohos/hypium' + +export default function hiSysEventJsSecondTest() { +describe('hiSysEventJsSecondTest', function () { + beforeAll(function() { + console.info('hiSysEventJsTest beforeAll called') + }) + + afterAll(function() { + console.info('hiSysEventJsTest afterAll called') + }) + + beforeEach(function() { + console.info('hiSysEventJsTest beforeEach called') + }) + + afterEach(function() { + console.info('hiSysEventJsTest afterEach called') + }) + + /** + * @tc.number DFX_DFT_HiSysEvent_JS_2700 + * @tc.name testHiSysEventApi27 + * @tc.desc 验证调用write接口系统事件打点,领域名称长度超16个字符,忽略事件打点,错误码11200001 + */ + it('testHiSysEventApi27', 1, async function (done) { + console.info('testHiSysEventApi27 start') + try { + hiSysEvent.write({ + domain: "RELIABILITY_RELIABILITY", + name: "STACK", + eventType: hiSysEvent.EventType.FAULT, + params: { + PID: 487, + UID: 103, + PACKAGE_NAME: "com.ohos.hisysevent.test", + PROCESS_NAME: "syseventservice", + MSG: "no msg." + } + }, (err, val) => { + if (err) { + console.error(`in testHiSysEventApi27 test callback: err.code = ${err.code}, error msg is ${err.message}`) + expect(err.code == 11200001).assertTrue() + } else { + console.info(`in testHiSysEventApi27 test callback: result = ${val}`) + expect(false).assertTrue() + } + console.info('testHiSysEventApi27 end') + done() + }) + } catch (error) { + console.error(`error code: ${error.code}, error msg: ${error.message}`); + expect(false).assertTrue() + console.info('testHiSysEventApi27 end') + done() + } + }) + + /** + * @tc.number DFX_DFT_HiSysEvent_JS_2800 + * @tc.name testHiSysEventApi28 + * @tc.desc 验证调用write接口系统事件打点,领域名称包含特殊字符,忽略事件打点,错误码11200001 + */ + it('testHiSysEventApi28', 1, async function (done) { + console.info('testHiSysEventApi28 start') + try { + hiSysEvent.write({ + domain: "RELIABILITY#?", + name: "STACK", + eventType: hiSysEvent.EventType.FAULT, + params: { + PID: 487, + UID: 103, + PACKAGE_NAME: "com.ohos.hisysevent.test", + PROCESS_NAME: "syseventservice", + MSG: "no msg." + } + }, (err, val) => { + if (err) { + console.error(`in testHiSysEventApi28 test callback: err.code = ${err.code}, error msg is ${err.message}`) + expect(err.code == 11200001).assertTrue() + } else { + console.info(`in testHiSysEventApi28 test callback: result = ${val}`) + expect(false).assertTrue() + } + console.info('testHiSysEventApi28 end') + done() + }) + } catch (error) { + console.error(`error code: ${error.code}, error msg: ${error.message}`); + expect(false).assertTrue() + console.info('testHiSysEventApi28 end') + done() + } + }) + + /** + * @tc.number DFX_DFT_HiSysEvent_JS_2900 + * @tc.name testHiSysEventApi29 + * @tc.desc 验证调用write接口系统事件打点,领域名称为空,忽略事件打点,错误码11200001。 + */ + it('testHiSysEventApi29', 1, async function (done) { + console.info('testHiSysEventApi29 start') + try { + hiSysEvent.write({ + domain: "", + name: "STACK", + eventType: hiSysEvent.EventType.FAULT, + params: { + PID: 487, + UID: 103, + PACKAGE_NAME: "com.ohos.hisysevent.test", + PROCESS_NAME: "syseventservice", + MSG: "no msg." + } + }, (err, val) => { + if (err) { + console.error(`in testHiSysEventApi29 test callback: err.code = ${err.code}, error msg is ${err.message}`) + expect(err.code == 11200001).assertTrue() + } else { + console.info(`in testHiSysEventApi29 test callback: result = ${val}`) + expect(false).assertTrue() + } + console.info('testHiSysEventApi29 end') + done() + }) + } catch (error) { + console.error(`error code: ${error.code}, error msg: ${error.message}`); + expect(false).assertTrue() + console.info('testHiSysEventApi29 end') + done() + } + }) + + /** + * @tc.number DFX_DFT_HiSysEvent_JS_3000 + * @tc.name testHiSysEventApi30 + * @tc.desc 验证调用write接口系统事件打点,系统事件名称长度超32个字符,忽略事件打点,错误码11200002。 + */ + it('testHiSysEventApi30', 1, async function (done) { + console.info('testHiSysEventApi30 start') + try { + hiSysEvent.write({ + domain: "RELIABILITY", + name: "STACK_STACK_STACK_STACK_STACK_STACK", + eventType: hiSysEvent.EventType.FAULT, + params: { + PID: 1, + UID: 1, + PACKAGE_NAME: "com.ohos.hisysevent.test", + PROCESS_NAME: "hiview js test suite", + MSG: "no msg." + } + }, (err, val) => { + if (err) { + console.error(`in testHiSysEventApi30 test callback: err.code = ${err.code}, error msg is ${err.message}`) + expect(err.code == 11200002).assertTrue() + } else { + console.info(`in testHiSysEventApi30 test callback: result = ${val}`) + expect(false).assertTrue() + } + console.info('testHiSysEventApi30 end') + done() + }) + } catch (err) { + console.error(`testHiSysEventApi30 > error code: ${err.code}, error msg: ${err.message}`) + expect(false).assertTrue() + console.info('testHiSysEventApi30 end') + done() + } + }) + + /** + * @tc.number DFX_DFT_HiSysEvent_JS_3100 + * @tc.name testHiSysEventApi31 + * @tc.desc 验证调用write接口系统事件打点,系统事件名称包含特殊字符,忽略事件打点,错误码11200002。 + */ + it('testHiSysEventApi31', 1, async function (done) { + console.info('testHiSysEventApi31 start') + try { + hiSysEvent.write({ + domain: "RELIABILITY", + name: "STACK#?", + eventType: hiSysEvent.EventType.FAULT, + params: { + PID: 1, + UID: 1, + PACKAGE_NAME: "com.ohos.hisysevent.test", + PROCESS_NAME: "hiview js test suite", + MSG: "no msg." + } + }, (err, val) => { + if (err) { + console.error(`in testHiSysEventApi31 test callback: err.code = ${err.code}, error msg is ${err.message}`) + expect(err.code == 11200002).assertTrue() + } else { + console.info(`in testHiSysEventApi31 test callback: result = ${val}`) + expect(false).assertTrue() + } + console.info('testHiSysEventApi31 end') + done() + }) + } catch (err) { + console.error(`testHiSysEventApi31 > error code: ${err.code}, error msg: ${err.message}`) + expect(false).assertTrue() + console.info('testHiSysEventApi31 end') + done() + } + }) + + /** + * @tc.number DFX_DFT_HiSysEvent_JS_3200 + * @tc.name testHiSysEventApi32 + * @tc.desc 验证调用write接口系统事件打点,系统事件名称为空,忽略事件打点,错误码11200002。 + */ + it('testHiSysEventApi32', 1, async function (done) { + console.info('testHiSysEventApi32 start') + try { + hiSysEvent.write({ + domain: "RELIABILITY", + name: "", + eventType: hiSysEvent.EventType.FAULT, + params: { + PID: 1, + UID: 1, + PACKAGE_NAME: "com.ohos.hisysevent.test", + PROCESS_NAME: "hiview js test suite", + MSG: "no msg." + } + }, (err, val) => { + if (err) { + console.error(`in testHiSysEventApi32 test callback: err.code = ${err.code}, error msg is ${err.message}`) + expect(err.code == 11200002).assertTrue() + } else { + console.info(`in testHiSysEventApi32 test callback: result = ${val}`) + expect(false).assertTrue() + } + console.info('testHiSysEventApi32 end') + done() + }) + } catch (err) { + console.error(`testHiSysEventApi32 > error code: ${err.code}, error msg: ${err.message}`) + expect(false).assertTrue() + console.info('testHiSysEventApi32 end') + done() + } + }) + + /** + * @tc.number DFX_DFT_HiSysEvent_JS_3500 + * @tc.name testHiSysEventApi35 + * @tc.desc 验证调用write接口系统事件打点,系统事件总长度超过384K,忽略事件打点,错误码11200004。 + */ + it('testHiSysEventApi35', 3, async function (done) { + console.info('testHiSysEventApi35 start') + try { + let params = { + PID: 1, + UID: 1, + PACKAGE_NAME: "com.ohos.hisysevent.test", + PROCESS_NAME: "just a testcase", + MSG: "no msg." + } + for (let i = 0; i < 40; i++) { + params[`bundle${i}`] = Array.from({length: 10 * 1024}).join("ohos") + } + hiSysEvent.write({ + domain: "RELIABILITY", + name: "STACK", + eventType: hiSysEvent.EventType.FAULT, + params:params + }, (err, val) => { + if (err) { + console.error(`in testHiSysEventApi35 test callback: err.code = ${err.code}, error msg is ${err.message}`) + expect(err.code == 11200004).assertTrue() + } else { + console.info(`in testHiSysEventApi35 test callback: result = ${val}`) + expect(false).assertTrue() + } + console.info('testHiSysEventApi35 end') + done() + }) + } catch (err) { + console.error(`testHiSysEventApi35 > error code: ${err.code}, error msg: ${err.message}`) + expect(false).assertTrue() + console.info('testHiSysEventApi35 end') + done() + } + }) + + /** + * @tc.number DFX_DFT_HiSysEvent_JS_3600 + * @tc.name testHiSysEventApi36 + * @tc.desc 验证调用write接口系统事件打点,领系统事件参数名称长度超32个字符,忽略事件打点,错误码11200051。 + */ + it('testHiSysEventApi36', 3, async function (done) { + console.info('testHiSysEventApi36 start') + try { + hiSysEvent.write({ + domain: "RELIABILITY", + name: "STACK", + eventType: hiSysEvent.EventType.FAULT, + params: { + PID: 1, + UID: 1, + STACK_STACK_STACK_STACK_STACK_STACK_STACK_STACK_STACK_STACK_STACK_STACK: "com.ohos.hisysevent.test", + PROCESS_NAME: "hiview js test suite", + MSG: "no msg." + } + }, (err, val) => { + if (err) { + console.error(`in testHiSysEventApi36 test callback: err.code = ${err.code}, error msg is ${err.message}`) + expect(err.code == 11200051).assertTrue() + } else { + console.info(`in testHiSysEventApi36 test callback: result = ${val}`) + expect(false).assertTrue() + } + console.info('testHiSysEventApi36 end') + done() + }) + } catch (err) { + console.error(`testHiSysEventApi36 > error code: ${err.code}, error msg: ${err.message}`) + expect(false).assertTrue() + console.info('testHiSysEventApi36 end') + done() + } + }) + + /** + * @tc.number DFX_DFT_HiSysEvent_JS_3700 + * @tc.name testHiSysEventApi37 + * @tc.desc 验证调用write接口系统事件打点,系统事件参数名称包含特殊字符,忽略事件打点,错误码11200051。 + */ + it('testHiSysEventApi37', 3, async function (done) { + console.info('testHiSysEventApi37 start') + try { + hiSysEvent.write({ + domain: "RELIABILITY", + name: "STACK", + eventType: hiSysEvent.EventType.FAULT, + params: { + PID: 1, + UID: 1, + "STACK#?": "com.ohos.hisysevent.test", + PROCESS_NAME: "hiview js test suite", + MSG: "no msg." + } + }, (err, val) => { + if (err) { + console.error(`in testHiSysEventApi37 test callback: err.code = ${err.code}, error msg is ${err.message}`) + expect(err.code == 11200051).assertTrue() + } else { + console.info(`in testHiSysEventApi37 test callback: result = ${val}`) + expect(false).assertTrue() + } + console.info('testHiSysEventApi37 end') + done() + }) + } catch (err) { + console.error(`testHiSysEventApi37 > error code: ${err.code}, error msg: ${err.message}`) + expect(false).assertTrue() + console.info('testHiSysEventApi37 end') + done() + } + }) + + /** + * @tc.number DFX_DFT_HiSysEvent_JS_3800 + * @tc.name testHiSysEventApi38 + * @tc.desc 验证调用write接口系统事件打点,系统事件参数名称为空,忽略事件打点,错误码11200051。 + */ + it('testHiSysEventApi38', 3, async function (done) { + console.info('testHiSysEventApi38 start') + try { + hiSysEvent.write({ + domain: "RELIABILITY", + name: "STACK", + eventType: hiSysEvent.EventType.FAULT, + params: { + PID: 1, + UID: 1, + "": "com.ohos.hisysevent.test", + PROCESS_NAME: "hiview js test suite", + MSG: "no msg." + } + }, (err, val) => { + if (err) { + console.error(`in testHiSysEventApi38 test callback: err.code = ${err.code}, error msg is ${err.message}`) + expect(err.code == 11200051).assertTrue() + } else { + console.info(`in testHiSysEventApi38 test callback: result = ${val}`) + expect(false).assertTrue() + } + console.info('testHiSysEventApi38 end') + done() + }) + } catch (err) { + console.error(`testHiSysEventApi38 > error code: ${err.code}, error msg: ${err.message}`) + expect(false).assertTrue() + console.info('testHiSysEventApi38 end') + done() + } + }) + + /** + * @tc.number DFX_DFT_HiSysEvent_JS_3900 + * @tc.name testHiSysEventApi39 + * @tc.desc 验证调用write接口系统事件打点,字符串类型的参数值的长度超过10K,忽略事件打点,错误码11200052。 + */ + it('testHiSysEventApi39', 3, async function (done) { + console.info('testHiSysEventApi39 start') + try { + hiSysEvent.write({ + domain: "RELIABILITY", + name: "STACK", + eventType: hiSysEvent.EventType.FAULT, + params: { + PID: 1, + UID: 1, + PACKAGE_NAME: "com.ohos.hisysevent.test", + PROCESS_NAME: Array.from({length: 10 * 1024 + 10}).join("ohos"), + MSG: "no msg." + } + }, (err, val) => { + if (err) { + console.error(`in testHiSysEventApi39 test callback: err.code = ${err.code}, error msg is ${err.message}`) + expect(err.code == 11200052).assertTrue() + } else { + console.info(`in testHiSysEventApi39 test callback: result = ${val}`) + expect(false).assertTrue() + } + console.info('testHiSysEventApi39 end') + done() + }) + } catch (err) { + console.error(`testHiSysEventApi39 > error code: ${err.code}, error msg: ${err.message}`) + expect(false).assertTrue() + console.info('testHiSysEventApi39 end') + done() + } + }) + + /** + * @tc.number DFX_DFT_HiSysEvent_JS_4000 + * @tc.name testHiSysEventApi40 + * @tc.desc 验证调用write接口系统事件打点,系统事件的参数数量超过128个,忽略事件打点,错误码11200053。 + */ + it('testHiSysEventApi40', 3, async function (done) { + console.info('testHiSysEventApi40 start') + let largeParams = {} + for (let i = 0; i < 200; i++) { + largeParams["name" + i] = i + } + try { + hiSysEvent.write({ + domain: "RELIABILITY", + name: "STACK", + eventType: hiSysEvent.EventType.FAULT, + params: largeParams + }, (err, val) => { + if (err) { + console.error(`in testHiSysEventApi40 test callback: err.code = ${err.code}, error msg is ${err.message}`) + expect(err.code == 11200053).assertTrue() + } else { + console.info(`in testHiSysEventApi40 test callback: result = ${val}`) + expect(false).assertTrue() + } + console.info('testHiSysEventApi40 end') + done() + }) + } catch (err) { + console.error(`testHiSysEventApi40 > error code: ${err.code}, error msg: ${err.message}`) + expect(false).assertTrue() + console.info('testHiSysEventApi40 end') + done() + } + }) + + /** + * @tc.number DFX_DFT_HiSysEvent_JS_4100 + * @tc.name testHiSysEventApi41 + * @tc.desc 验证调用write接口系统事件打点,系统事件中有数组类型的参数值的长度超过100,忽略事件打点,错误码11200054。 + */ + it('testHiSysEventApi41', 3, async function (done) { + console.info('testHiSysEventApi41 start') + let msgArray = [] + for (let i = 0; i < 200; i++) { + msgArray[i] = i + } + try { + hiSysEvent.write({ + domain: "RELIABILITY", + name: "STACK", + eventType: hiSysEvent.EventType.FAULT, + params: { + PID: 1, + UID: 1, + PACKAGE_NAME: "com.ohos.hisysevent.test", + PROCESS_NAME: "hiview js test suite", + MSG: msgArray + } + }, (err, val) => { + if (err) { + console.error(`in testHiSysEventApi41 test callback: err.code = ${err.code}, error msg is ${err.message}`) + expect(err.code == 11200054).assertTrue() + } else { + console.info(`in testHiSysEventApi41 test callback: result = ${val}`) + expect(false).assertTrue() + } + console.info('testHiSysEventApi41 end') + done() + }) + } catch (err) { + console.error(`testHiSysEventApi41 > error code: ${err.code}, error msg: ${err.message}`) + expect(false).assertTrue() + console.info('testHiSysEventApi41 end') + done() + } + }) + /** + * @tc.number DFX_DFT_HiSysEvent_JS_4200 + * @tc.name testHiSysEventApi42 + * @tc.desc 验证调用addWatcher接口添加系统事件监听者,监听者数量超过限制,拒绝添加此监听者,错误码11200101。 + */ + it('testHiSysEventApi42', 3, async function (done) { + console.info('testHiSysEventApi42 start') + try { + var watcher = [] + for (var i = 0; i < 30; i++) { + watcher[i] = { + rules: [{ + domain: "RELIABILITY" + i, + name: "STACK", + ruleType: hiSysEvent.RuleType.WHOLE_WORD, + }], + onEvent: (info) => { + }, + onServiceDied: () => { + } + } + hiSysEvent.addWatcher(watcher[i]) + } + setTimeout(() => { + var watcher = [] + for (var i = 0; i < 30; i++) { + hiSysEvent.removeWatcher(watcher[i]) + } + }, 5000) + done() + }catch (err) { + console.error(`testHiSysEventApi42 > error code: ${err.code}, error msg: ${err.message}`) + expect(err.code == 11200101).assertTrue() + console.info('testHiSysEventApi42 end') + done() + } + }) + + /** + * @tc.number DFX_DFT_HiSysEvent_JS_4300 + * @tc.name testHiSysEventApi43 + * @tc.desc 验证调用addWatcher接口添加系统事件监听者,监听规则数量超过限制,拒绝添加此监听者,错误码11200102。 + */ + it('testHiSysEventApi43', 3, async function (done) { + console.info('testHiSysEventApi43 start') + let msgArray = [] + for (let i = 0; i < 21; i++) { + msgArray[i] = { + domain: "RELIABILITY" + i, + name: "STACK", + ruleType: hiSysEvent.RuleType.WHOLE_WORD, + } + } + try { + let watcher = { + rules: msgArray, + onEvent: (info) => { + }, + onServiceDied: () => { + } + } + hiSysEvent.addWatcher(watcher) + done() + }catch (err) { + console.error(`testHiSysEventApi43 > error code: ${err.code}, error msg: ${err.message}`) + expect(err.code == 11200102).assertTrue() + console.info('testHiSysEventApi43 end') + done() + } + }) + + /** + * @tc.number DFX_DFT_HiSysEvent_JS_4400 + * @tc.name testHiSysEventApi44 + * @tc.desc 验证调用removeWatcher接口删除系统事件监听者,事件监听者为空,拒绝移除此监听者,错误码11200201。 + */ + it('testHiSysEventApi44', 3, async function (done) { + console.info('testHiSysEventApi44 start') + let watcher11 = { + rules: [{ + domain: "RELIABILITY" , + name: "STACK", + ruleType: hiSysEvent.RuleType.WHOLE_WORD, + }], + onEvent: (info) => { + }, + onServiceDied: () => { + } + } + setTimeout(() => { + try { + hiSysEvent.removeWatcher("") + expect(true).assertTrue() + console.info('testHiSysEventApi44 end') + done() + }catch (err) { + console.error(`testHiSysEventApi44 > error code: ${err.code}, error msg: ${err.message}`) + expect(err.code == 11200201).assertTrue() + console.info('testHiSysEventApi44 end') + done() + } + }, 1000) + }) + + /** + * @tc.number DFX_DFT_HiSysEvent_JS_4500 + * @tc.name testHiSysEventApi45 + * @tc.desc 验证调用removeWatcher接口删除系统事件监听者,事件监听者不在监听队列,拒绝移除此监听者,错误码11200201。 + */ + it('testHiSysEventApi45', 3, async function (done) { + console.info('testHiSysEventApi45 start') + let watcher11 = { + rules: [{ + domain: "RELIABILITY" , + name: "STACK", + ruleType: hiSysEvent.RuleType.WHOLE_WORD, + }], + onEvent: (info) => { + }, + onServiceDied: () => { + } + } + setTimeout(() => { + try { + hiSysEvent.removeWatcher(watcher11) + expect(true).assertTrue() + console.info('testHiSysEventApi45 end') + done() + }catch (err) { + console.error(`testHiSysEventApi45 > error code: ${err.code}, error msg: ${err.message}`) + expect(err.code == 11200201).assertTrue() + console.info('testHiSysEventApi45 end') + done() + } + }, 1000) + }) + + /** + * @tc.number DFX_DFT_HiSysEvent_JS_4600 + * @tc.name testHiSysEventApi46 + * @tc.desc 验证调用query接口查询系统事件,查询规则个数超过10个,忽略此次系统事件的查询,错误码11200301。 + */ + it('testHiSysEventApi46', 3, async function (done) { + console.info('testHiSysEventApi46 start') + try { + hiSysEvent.write({ + domain: "RELIABILITY", + name: "STACK", + eventType: hiSysEvent.EventType.FAULT, + params: { + PID: 1, + UID: 1, + PACKAGE_NAME: "com.ohos.hisysevent.test", + PROCESS_NAME: "hiview napi test suite", + MSG: "no msg." + } + }, (err, val) => { + if (err) { + console.error('in testHiSysEventApi46 test callback: err.code = ' + err.code) + } else { + console.info('in testHiSysEventApi46 test callback: result = ' + val) + } + }) + setTimeout(() => { + try { + let msgArray = [] + for (let i = 0; i < 11; i++) { + msgArray[i] = { + domain: "RELIABILITY" + i, + names: ["STACK"], + } + } + hiSysEvent.query({ + beginTime: -1, + endTime: -1, + maxEvents: 2, + }, msgArray, { + onQuery: function (infos) { + console.info(`testHiSysEventApi46: onQuery...`) + expect(infos.length >= 0).assertTrue() + console.info(`testHiSysEventApi46: infos.size is ${infos.length}`) + if (infos instanceof Array) { + for (let i = 0; i < infos.length; i++) { + let item = infos[i]; + console.info(`testHiSysEventApi46: domain is ${item.domain}, name is ${item.name}, eventType is ${item.eventType}`) + if (item.params instanceof Object) { + for (const key in item.params) { + console.info(`testHiSysEventApi46: ${key}: ${item.params[key]}`) + } + } + } + } + }, + onComplete: function(reason, total) { + console.info(`testHiSysEventApi46: onComplete...`) + console.info(`testHiSysEventApi46: reason is ${reason}, total is ${total}`) + expect(true).assertTrue() + console.info(`testHiSysEventApi46 end`) + done() + } + }) + } catch (err) { + console.error(`testHiSysEventApi46 delay > error code: ${err.code}, error msg: ${err.message}`) + expect(err.code == 11200301).assertTrue() + console.info('hiSysEventJsUnitTest006 end') + done() + } + }, 1000); + } catch (err) { + console.error(`testHiSysEventApi46 > error code: ${err.code}, error msg: ${err.message}`) + expect(false).assertTrue() + console.info('testHiSysEventApi46 end') + done() + } + }) + + /** + * @tc.number DFX_DFT_HiSysEvent_JS_4700 + * @tc.name testHiSysEventApi47 + * @tc.desc 验证调用query接口查询系统事件,事件领域名称长度超过16个字符,忽略此次系统事件的查询,错误码11200302。 + */ + it('testHiSysEventApi47', 3, async function (done) { + console.info('testHiSysEventApi47 start') + try { + hiSysEvent.write({ + domain: "RELIABILITY", + name: "STACK", + eventType: hiSysEvent.EventType.FAULT, + params: { + PID: 1, + UID: 1, + PACKAGE_NAME: "com.ohos.hisysevent.test", + PROCESS_NAME: "hiview napi test suite", + MSG: "no msg." + } + }, (err, val) => { + if (err) { + console.error('in testHiSysEventApi47 test callback: err.code = ' + err.code) + } else { + console.info('in testHiSysEventApi47 test callback: result = ' + val) + } + }) + setTimeout(() => { + try { + hiSysEvent.query({ + beginTime: -1, + endTime: -1, + maxEvents: 2, + }, [{ + domain: "RELIABILITY_RELIABILITY" , + names: ["STACK"], + }], { + onQuery: function (infos) { + console.info(`testHiSysEventApi47: onQuery...`) + expect(infos.length >= 0).assertTrue() + console.info(`testHiSysEventApi47: infos.size is ${infos.length}`) + if (infos instanceof Array) { + for (let i = 0; i < infos.length; i++) { + let item = infos[i]; + console.info(`testHiSysEventApi47: domain is ${item.domain}, name is ${item.name}, eventType is ${item.eventType}`) + if (item.params instanceof Object) { + for (const key in item.params) { + console.info(`testHiSysEventApi47: ${key}: ${item.params[key]}`) + } + } + } + } + }, + onComplete: function(reason, total) { + console.info(`testHiSysEventApi47: onComplete...`) + console.info(`testHiSysEventApi47: reason is ${reason}, total is ${total}`) + expect(true).assertTrue() + console.info(`testHiSysEventApi47 end`) + done() + } + }) + } catch (err) { + console.error(`testHiSysEventApi47 delay > error code: ${err.code}, error msg: ${err.message}`) + expect(err.code == 11200302 || err.code == 11200304).assertTrue() + console.info('testHiSysEventApi47 end') + done() + } + }, 2000); + } catch (err) { + console.error(`testHiSysEventApi47 > error code: ${err.code}, error msg: ${err.message}`) + expect(false).assertTrue() + console.info('testHiSysEventApi47 end') + done() + } + }) + + /** + * @tc.number DFX_DFT_HiSysEvent_JS_4800 + * @tc.name testHiSysEventApi48 + * @tc.desc 验证调用query接口查询系统事件,事件名称长度超过32个字符,忽略此次系统事件的查询,错误码11200302。 + */ + it('testHiSysEventApi48', 3, async function (done) { + console.info('testHiSysEventApi48 start') + try { + hiSysEvent.write({ + domain: "RELIABILITY", + name: "STACK", + eventType: hiSysEvent.EventType.FAULT, + params: { + PID: 1, + UID: 1, + PACKAGE_NAME: "com.ohos.hisysevent.test", + PROCESS_NAME: "hiview napi test suite", + MSG: "no msg." + } + }, (err, val) => { + if (err) { + console.error('in testHiSysEventApi48 test callback: err.code = ' + err.code) + } else { + console.info('in testHiSysEventApi48 test callback: result = ' + val) + } + }) + setTimeout(() => { + try { + hiSysEvent.query({ + beginTime: -1, + endTime: -1, + maxEvents: 2, + }, [{ + domain: "RELIABILITY" , + names: ["STACK_STACK_STACK_STACK_STACK_STACK"], + }], { + onQuery: function (infos) { + console.info(`testHiSysEventApi48: onQuery...`) + expect(infos.length >= 0).assertTrue() + console.info(`testHiSysEventApi48: infos.size is ${infos.length}`) + if (infos instanceof Array) { + for (let i = 0; i < infos.length; i++) { + let item = infos[i]; + console.info(`testHiSysEventApi48: domain is ${item.domain}, name is ${item.name}, eventType is ${item.eventType}`) + if (item.params instanceof Object) { + for (const key in item.params) { + console.info(`testHiSysEventApi48: ${key}: ${item.params[key]}`) + } + } + } + } + }, + onComplete: function(reason, total) { + console.info(`testHiSysEventApi48: onComplete...`) + console.info(`testHiSysEventApi48: reason is ${reason}, total is ${total}`) + expect(true).assertTrue() + console.info(`testHiSysEventApi48 end`) + done() + } + }) + } catch (err) { + console.error(`testHiSysEventApi48 delay > error code: ${err.code}, error msg: ${err.message}`) + expect(err.code == 11200302 || err.code == 11200304).assertTrue() + console.info('testHiSysEventApi48 end') + done() + } + }, 2000); + } catch (err) { + console.error(`testHiSysEventApi48 > error code: ${err.code}, error msg: ${err.message}`) + expect(false).assertTrue() + console.info('testHiSysEventApi48 end') + done() + } + }) + + /** + * @tc.number DFX_DFT_HiSysEvent_JS_4900 + * @tc.name testHiSysEventApi49 + * @tc.desc 验证调用query接口查询系统事件,事件领域名称包含特殊字符,忽略此次系统事件的查询,错误码11200302。 + */ + it('testHiSysEventApi49', 3, async function (done) { + console.info('testHiSysEventApi49 start') + try { + hiSysEvent.write({ + domain: "RELIABILITY", + name: "STACK", + eventType: hiSysEvent.EventType.FAULT, + params: { + PID: 1, + UID: 1, + PACKAGE_NAME: "com.ohos.hisysevent.test", + PROCESS_NAME: "hiview napi test suite", + MSG: "no msg." + } + }, (err, val) => { + if (err) { + console.error('in testHiSysEventApi49 test callback: err.code = ' + err.code) + } else { + console.info('in testHiSysEventApi49 test callback: result = ' + val) + } + }) + setTimeout(() => { + try { + hiSysEvent.query({ + beginTime: -1, + endTime: -1, + maxEvents: 2, + }, [{ + domain: "RELIABILITY?#" , + names: ["STACK"], + }], { + onQuery: function (infos) { + console.info(`testHiSysEventApi49: onQuery...`) + expect(infos.length >= 0).assertTrue() + console.info(`testHiSysEventApi49: infos.size is ${infos.length}`) + if (infos instanceof Array) { + for (let i = 0; i < infos.length; i++) { + let item = infos[i]; + console.info(`testHiSysEventApi49: domain is ${item.domain}, name is ${item.name}, eventType is ${item.eventType}`) + if (item.params instanceof Object) { + for (const key in item.params) { + console.info(`testHiSysEventApi49: ${key}: ${item.params[key]}`) + } + } + } + } + }, + onComplete: function(reason, total) { + console.info(`testHiSysEventApi49: onComplete...`) + console.info(`testHiSysEventApi49: reason is ${reason}, total is ${total}`) + expect(true).assertTrue() + console.info(`testHiSysEventApi49 end`) + done() + } + }) + } catch (err) { + console.error(`testHiSysEventApi49 delay > error code: ${err.code}, error msg: ${err.message}`) + expect(err.code == 11200302 || err.code == 11200304).assertTrue() + console.info('testHiSysEventApi49 end') + done() + } + }, 2000); + } catch (err) { + console.error(`testHiSysEventApi49 > error code: ${err.code}, error msg: ${err.message}`) + expect(false).assertTrue() + console.info('testHiSysEventApi49 end') + done() + } + }) + + /** + * @tc.number DFX_DFT_HiSysEvent_JS_5000 + * @tc.name testHiSysEventApi50 + * @tc.desc 验证调用query接口查询系统事件,事件名称包含特殊字符,忽略此次系统事件的查询,错误码11200302。 + */ + it('testHiSysEventApi50', 3, async function (done) { + console.info('testHiSysEventApi50 start') + try { + hiSysEvent.write({ + domain: "RELIABILITY", + name: "STACK", + eventType: hiSysEvent.EventType.FAULT, + params: { + PID: 1, + UID: 1, + PACKAGE_NAME: "com.ohos.hisysevent.test", + PROCESS_NAME: "hiview napi test suite", + MSG: "no msg." + } + }, (err, val) => { + if (err) { + console.error('in testHiSysEventApi50 test callback: err.code = ' + err.code) + } else { + console.info('in testHiSysEventApi50 test callback: result = ' + val) + } + }) + setTimeout(() => { + try { + hiSysEvent.query({ + beginTime: -1, + endTime: -1, + maxEvents: 2, + }, [{ + domain: "RELIABILITY" , + names: ["STACK?#"], + }], { + onQuery: function (infos) { + console.info(`testHiSysEventApi50: onQuery...`) + expect(infos.length >= 0).assertTrue() + console.info(`testHiSysEventApi50: infos.size is ${infos.length}`) + if (infos instanceof Array) { + for (let i = 0; i < infos.length; i++) { + let item = infos[i]; + console.info(`testHiSysEventApi50: domain is ${item.domain}, name is ${item.name}, eventType is ${item.eventType}`) + if (item.params instanceof Object) { + for (const key in item.params) { + console.info(`testHiSysEventApi50: ${key}: ${item.params[key]}`) + } + } + } + } + }, + onComplete: function(reason, total) { + console.info(`testHiSysEventApi50: onComplete...`) + console.info(`testHiSysEventApi50: reason is ${reason}, total is ${total}`) + expect(true).assertTrue() + console.info(`testHiSysEventApi50 end`) + done() + } + }) + } catch (err) { + console.error(`testHiSysEventApi50 delay > error code: ${err.code}, error msg: ${err.message}`) + expect(err.code == 11200302 || err.code == 11200304).assertTrue() + console.info('testHiSysEventApi50 end') + done() + } + }, 2000); + } catch (err) { + console.error(`testHiSysEventApi50 > error code: ${err.code}, error msg: ${err.message}`) + expect(false).assertTrue() + console.info('testHiSysEventApi50 end') + done() + } + }) + + /** + * @tc.number DFX_DFT_HiSysEvent_JS_5100 + * @tc.name testHiSysEventApi51 + * @tc.desc 验证调用query接口查询系统事件,事件领域名称为空,忽略此次系统事件的查询,错误码11200302。 + */ + it('testHiSysEventApi51', 3, async function (done) { + console.info('testHiSysEventApi51 start') + try { + hiSysEvent.write({ + domain: "RELIABILITY", + name: "STACK", + eventType: hiSysEvent.EventType.FAULT, + params: { + PID: 1, + UID: 1, + PACKAGE_NAME: "com.ohos.hisysevent.test", + PROCESS_NAME: "hiview napi test suite", + MSG: "no msg." + } + }, (err, val) => { + if (err) { + console.error('in testHiSysEventApi51 test callback: err.code = ' + err.code) + } else { + console.info('in testHiSysEventApi51 test callback: result = ' + val) + } + }) + setTimeout(() => { + try { + hiSysEvent.query({ + beginTime: -1, + endTime: -1, + maxEvents: 2, + }, [{ + domain: "" , + names: ["STACK"], + }], { + onQuery: function (infos) { + console.info(`testHiSysEventApi51: onQuery...`) + expect(infos.length >= 0).assertTrue() + console.info(`testHiSysEventApi51: infos.size is ${infos.length}`) + if (infos instanceof Array) { + for (let i = 0; i < infos.length; i++) { + let item = infos[i]; + console.info(`testHiSysEventApi51: domain is ${item.domain}, name is ${item.name}, eventType is ${item.eventType}`) + if (item.params instanceof Object) { + for (const key in item.params) { + console.info(`testHiSysEventApi51: ${key}: ${item.params[key]}`) + } + } + } + } + }, + onComplete: function(reason, total) { + console.info(`testHiSysEventApi51: onComplete...`) + console.info(`testHiSysEventApi51: reason is ${reason}, total is ${total}`) + expect(true).assertTrue() + console.info(`testHiSysEventApi51 end`) + done() + } + }) + } catch (err) { + console.error(`testHiSysEventApi51 delay > error code: ${err.code}, error msg: ${err.message}`) + expect(err.code == 11200302 || err.code == 11200304).assertTrue() + console.info('testHiSysEventApi51 end') + done() + } + }, 2000); + } catch (err) { + console.error(`testHiSysEventApi51 > error code: ${err.code}, error msg: ${err.message}`) + expect(false).assertTrue() + console.info('testHiSysEventApi51 end') + done() + } + }) + + /** + * @tc.number DFX_DFT_HiSysEvent_JS_5200 + * @tc.name testHiSysEventApi52 + * @tc.desc 验证调用query接口查询系统事件,事件名称为空,忽略此次系统事件的查询,错误码11200302。 + */ + it('testHiSysEventApi52', 3, async function (done) { + console.info('testHiSysEventApi52 start') + try { + hiSysEvent.write({ + domain: "RELIABILITY", + name: "STACK", + eventType: hiSysEvent.EventType.FAULT, + params: { + PID: 1, + UID: 1, + PACKAGE_NAME: "com.ohos.hisysevent.test", + PROCESS_NAME: "hiview napi test suite", + MSG: "no msg." + } + }, (err, val) => { + if (err) { + console.error('in testHiSysEventApi52 test callback: err.code = ' + err.code) + } else { + console.info('in testHiSysEventApi52 test callback: result = ' + val) + } + }) + setTimeout(() => { + try { + hiSysEvent.query({ + beginTime: -1, + endTime: -1, + maxEvents: 2, + }, [{ + domain: "RELIABILITY" , + names: [], + }], { + onQuery: function (infos) { + console.info(`testHiSysEventApi52: onQuery...`) + expect(infos.length >= 0).assertTrue() + console.info(`testHiSysEventApi52: infos.size is ${infos.length}`) + if (infos instanceof Array) { + for (let i = 0; i < infos.length; i++) { + let item = infos[i]; + console.info(`testHiSysEventApi52: domain is ${item.domain}, name is ${item.name}, eventType is ${item.eventType}`) + if (item.params instanceof Object) { + for (const key in item.params) { + console.info(`testHiSysEventApi52: ${key}: ${item.params[key]}`) + } + } + } + } + }, + onComplete: function(reason, total) { + console.info(`testHiSysEventApi52: onComplete...`) + console.info(`testHiSysEventApi52: reason is ${reason}, total is ${total}`) + expect(true).assertTrue() + console.info(`testHiSysEventApi52 end`) + done() + } + }) + } catch (err) { + console.error(`testHiSysEventApi52 delay > error code: ${err.code}, error msg: ${err.message}`) + expect(err.code == 11200302 || err.code == 11200304).assertTrue() + console.info('testHiSysEventApi52 end') + done() + } + }, 2000); + } catch (err) { + console.error(`testHiSysEventApi52 > error code: ${err.code}, error msg: ${err.message}`) + expect(false).assertTrue() + console.info('testHiSysEventApi52 end') + done() + } + }) + + /** + * @tc.number DFX_DFT_HiSysEvent_JS_5300 + * @tc.name testHiSysEventApi53 + * @tc.desc 验证调用write接口,缺少write参数,无法打点,错误码401。 + */ + it('testHiSysEventApi53', 3, async function (done) { + console.info('testHiSysEventApi53 start') + try { + hiSysEvent.write((err, val) => { + if (err) { + console.error('in testHiSysEventApi53 test callback: err.code = ' + err.code) + } else { + console.info('in testHiSysEventApi53 test callback: result = ' + val) + } + }) + } catch (err) { + console.error(`testHiSysEventApi53 > error code: ${err.code}, error msg: ${err.message}`) + expect(err.code == 401).assertTrue() + console.info('testHiSysEventApi53 end') + done() + } + }) + + /** + * @tc.number DFX_DFT_HiSysEvent_JS_5400 + * @tc.name testHiSysEventApi54 + * @tc.desc 验证调用query接口,缺少订阅规则,错误码401。 + */ + it('testHiSysEventApi54', 3, async function (done) { + console.info('testHiSysEventApi54 start') + try { + hiSysEvent.write({ + domain: "RELIABILITY", + name: "STACK", + eventType: hiSysEvent.EventType.FAULT, + params: { + PID: 1, + UID: 1, + PACKAGE_NAME: "com.ohos.hisysevent.test", + PROCESS_NAME: "hiview napi test suite", + MSG: "no msg." + } + }, (err, val) => { + if (err) { + console.error('in testHiSysEventApi54 test callback: err.code = ' + err.code) + } else { + console.info('in testHiSysEventApi54 test callback: result = ' + val) + } + }) + setTimeout(() => { + try { + hiSysEvent.query( { + onQuery: function (infos) { + console.info(`testHiSysEventApi54: onQuery...`) + expect(infos.length >= 0).assertTrue() + console.info(`testHiSysEventApi54: infos.size is ${infos.length}`) + if (infos instanceof Array) { + for (let i = 0; i < infos.length; i++) { + let item = infos[i]; + console.info(`testHiSysEventApi54: domain is ${item.domain}, name is ${item.name}, eventType is ${item.eventType}`) + if (item.params instanceof Object) { + for (const key in item.params) { + console.info(`testHiSysEventApi54: ${key}: ${item.params[key]}`) + } + } + } + } + }, + onComplete: function(reason, total) { + console.info(`testHiSysEventApi54: onComplete...`) + console.info(`testHiSysEventApi54: reason is ${reason}, total is ${total}`) + expect(true).assertTrue() + console.info(`testHiSysEventApi54 end`) + done() + } + }) + } catch (err) { + console.error(`testHiSysEventApi54 delay > error code: ${err.code}, error msg: ${err.message}`) + expect(err.code == 401).assertTrue() + console.info('testHiSysEventApi54 end') + done() + } + }, 1000); + } catch (err) { + console.error(`testHiSysEventApi54 > error code: ${err.code}, error msg: ${err.message}`) + expect(false).assertTrue() + console.info('testHiSysEventApi54 end') + done() + } + }) + + /** + * @tc.number DFX_DFT_HiSysEvent_JS_5500 + * @tc.name testHiSysEventApi55 + * @tc.desc 验证调用addwatcher接口,缺少watcher参数,错误码401。 + */ + it('testHiSysEventApi55', 3, async function (done) { + console.info('testHiSysEventApi55 start') + try { + let watcher = { + onEvent: (info) => { + console.info(`testHiSysEventApi12: OnEvent...`) + expect(Object.keys(info).length > 0).assertTrue() + console.info(`testHiSysEventApi12: domain is : ${info.domain}, name is ${info.name}, + eventType is ${info.eventType}`) + if (info.params instanceof Object) { + for (const key in info.params) { + console.info(`testHiSysEventApi12: ${key}: ${info.params[key]}`) + } + } + }, + onServiceDied: () => { + console.info(`testHiSysEventApi12 Onservice died`); + } + } + hiSysEvent.addWatcher(watcher) + } catch (err) { + console.error(`testHiSysEventApi55 > error code: ${err.code}, error msg: ${err.message}`) + expect(err.code == 401).assertTrue() + console.info('testHiSysEventApi55 end') + done() + } + }) + + /** + * @tc.number DFX_DFT_HiSysEvent_JS_5700 + * @tc.name testHiSysEventApi57 + * @tc.desc 验证调用query接口,查询频率超过限制,忽略此次查询,错误码11200304。。 + */ + it('testHiSysEventApi57', 3, async function (done) { + console.info('testHiSysEventApi57 start') + try { + for (let i = 0; i < 5; i++) { + hiSysEvent.query({ + beginTime: -1, + endTime: -1, + maxEvents: 500000, + }, [{ + domain: "RELIABILITY" , + names: ["STACK"], + }], { + onQuery: function (infos) { + }, + onComplete: function(reason, total) { + done() + } + }) + } + } catch (err) { + console.error(`testHiSysEventApi57 delay > error code: ${err.code}, error msg: ${err.message}`) + expect(err.code == 11200304).assertTrue() + console.info('testHiSysEventApi57 end') + done() + } + }) +}) +} diff --git a/hiviewdfx/hisyseventtest/hisyseventjstest/src/main/js/test/List.test.js b/hiviewdfx/hisyseventtest/hisyseventjstest/src/main/js/test/List.test.js index 8c665e9481dfe28c8061a6373798088e92d7a63a..5d46409943d778dbb96c358605b02bafca42636e 100644 --- a/hiviewdfx/hisyseventtest/hisyseventjstest/src/main/js/test/List.test.js +++ b/hiviewdfx/hisyseventtest/hisyseventjstest/src/main/js/test/List.test.js @@ -13,6 +13,8 @@ * limitations under the License. */ import hiSysEventJsTest from './HiSysEvent.test.js' +import hiSysEventJsSecondTest from './HiSysEventSecond.test.js' export default function testsuite() { hiSysEventJsTest() +hiSysEventJsSecondTest() }