From d4efb5c43facbebf5c7fb059cb490ee010504539 Mon Sep 17 00:00:00 2001 From: 15929983503 Date: Sat, 29 Oct 2022 15:38:25 +0800 Subject: [PATCH] hisysevent8.2modify Signed-off-by: 15929983503 --- .../hisyseventtest/hisyseventjstest/Test.json | 11 +- .../signature/openharmony_sx.p7b | Bin 3521 -> 3522 bytes .../src/main/js/test/HiSysEvent.test.js | 465 +++++++++++------- 3 files changed, 276 insertions(+), 200 deletions(-) diff --git a/hiviewdfx/hisyseventtest/hisyseventjstest/Test.json b/hiviewdfx/hisyseventtest/hisyseventjstest/Test.json index 6a37f9119..a3a7a6047 100755 --- a/hiviewdfx/hisyseventtest/hisyseventjstest/Test.json +++ b/hiviewdfx/hisyseventtest/hisyseventjstest/Test.json @@ -14,15 +14,6 @@ ], "type": "AppInstallKit", "cleanup-apps": true - }, - { - "type": "ShellKit", - "run-command": [ - "setenforce 0" - ], - "teardown-command": [ - "setenforce 1" - ] } ] -} \ No newline at end of file +} diff --git a/hiviewdfx/hisyseventtest/hisyseventjstest/signature/openharmony_sx.p7b b/hiviewdfx/hisyseventtest/hisyseventjstest/signature/openharmony_sx.p7b index b680e12086abe2ab4783e5e09bfe414839b18803..e80f3d33fb7f453c5b80d7501394f8dcceb9dbc4 100755 GIT binary patch delta 229 zcmX>oeMs8Dpow=M8>d#AN85K^Ms}tJO}y)YLaUh=84Y<2xY;-p+B_IjnOT?^4VqZv z5egX>G_eM-G_m?@bXds3nv__anY{Tai!VpLk%fV!iIIs(lz~26H7ARq5{p9qq-BTp zoVeP+GC5wyNra=)_Nv~=ru#?!ajs<9sPyX5asw_l4xl^E*|IP*vA7$!GAYPqbF(qs z)oz>+C|=UFZRwBwe~!LpEqFMowN&nnovam delta 228 zcmX>keNfuLpow=c8>d#AN85K^Ms}tJO}y)XLaUe<84Y<2xY;-p+B_IjnOT?^4VqZv z5DFO=G_m@#G_iVbbXds3lAK?Zy7?K4FGszhrGdGLxrt$vfj(R@CySvHi-MMG@29)L z3X#Q9jVsRG>SE1Xx#iRZ#jL{?oQ$D{9X7oNTx=XbXPmQTVP;}+H*jTA5VBhT`}4Zh zzD+k@Hq5@U`+K7oql)_JNuL^)dhp9HGInE9WSErrW#;~EL1EcuPa+Ms%Pta_?5K6$ Q{%+C7-iF9R { @@ -349,10 +350,18 @@ describe('hiSysEventJsTest', function () { console.info(`testHiSysEventApi12 Onservice died`); } } - let result = hiSysEvent.addWatcher(watcher) - expect(result).assertEqual(0) - console.info('testHiSysEventApi12 end') - done(); + try { + hiSysEvent.addWatcher(watcher) + expect(true).assertTrue() + console.info('testHiSysEventApi12 end') + done(); + } catch (err) { + console.error(`testHiSysEventApi12 > error code: ${err.code}, error msg: ${err.message}`) + expect(err.code == 201).assertTrue() + console.info('testHiSysEventApi12 end') + done() + } + hiSysEvent.removeWatcher(watcher) }) /** @@ -383,10 +392,18 @@ describe('hiSysEventJsTest', function () { console.info(`testHiSysEventApi13 Onservice died`); } } - let result = hiSysEvent.addWatcher(watcher) - expect(result).assertEqual(0) - console.info('testHiSysEventApi13 end') - done(); + try { + hiSysEvent.addWatcher(watcher) + expect(true).assertTrue() + console.info('testHiSysEventApi13 end') + done(); + } catch (err) { + console.error(`testHiSysEventApi13 > error code: ${err.code}, error msg: ${err.message}`) + expect(err.code == 201).assertTrue() + console.info('testHiSysEventApi13 end') + done() + } + hiSysEvent.removeWatcher(watcher) }) /** @@ -417,10 +434,18 @@ describe('hiSysEventJsTest', function () { console.info(`testHiSysEventApi14 Onservice died`); } } - let result = hiSysEvent.addWatcher(watcher) - expect(result).assertEqual(0) - console.info('testHiSysEventApi14 end') - done(); + try { + hiSysEvent.addWatcher(watcher) + expect(true).assertTrue() + console.info('testHiSysEventApi14 end') + done(); + } catch (err) { + console.error(`testHiSysEventApi14 > error code: ${err.code}, error msg: ${err.message}`) + expect(err.code == 201) + console.info('testHiSysEventApi14 end') + done() + } + hiSysEvent.removeWatcher(watcher) }) /** @@ -452,10 +477,18 @@ describe('hiSysEventJsTest', function () { console.info(`testHiSysEventApi15 Onservice died`); } } - let result = hiSysEvent.addWatcher(watcher) - expect(result).assertEqual(0) - console.info('testHiSysEventApi15 end') - done(); + try { + hiSysEvent.addWatcher(watcher) + expect(true).assertTrue() + console.info('testHiSysEventApi15 end') + done(); + } catch (err) { + console.error(`testHiSysEventApi15 > error code: ${err.code}, error msg: ${err.message}`) + expect(err.code == 201).assertTrue() + console.info('testHiSysEventApi15 end') + done() + } + hiSysEvent.removeWatcher(watcher) }) /** @@ -487,10 +520,18 @@ describe('hiSysEventJsTest', function () { console.info(`testHiSysEventApi16 Onservice died`); } } - let result = hiSysEvent.addWatcher(watcher) - expect(result).assertEqual(0) - console.info('testHiSysEventApi16 end') - done(); + try { + hiSysEvent.addWatcher(watcher) + expect(true).assertTrue() + console.info('testHiSysEventApi16 end') + done(); + } catch (err) { + console.error(`testHiSysEventApi16 > error code: ${err.code}, error msg: ${err.message}`) + expect(err.code == 201).assertTrue() + console.info('testHiSysEventApi16 end') + done() + } + hiSysEvent.removeWatcher(watcher) }) /** @@ -522,10 +563,18 @@ describe('hiSysEventJsTest', function () { console.info(`testHiSysEventApi17 Onservice died`); } } - let result = hiSysEvent.addWatcher(watcher) - expect(result).assertEqual(0) - console.info('testHiSysEventApi17 end') - done(); + try { + hiSysEvent.addWatcher(watcher) + expect(true).assertTrue() + console.info('testHiSysEventApi17 end') + done(); + } catch (err) { + console.error(`testHiSysEventApi17 > error code: ${err.code}, error msg: ${err.message}`) + expect(err.code == 201).assertTrue() + console.info('testHiSysEventApi17 end') + done() + } + hiSysEvent.removeWatcher(watcher) }) /** @@ -556,15 +605,20 @@ describe('hiSysEventJsTest', function () { console.info(`testHiSysEventApi18 Onservice died`); } } - let result = hiSysEvent.addWatcher(watcher) - expect(result).assertEqual(0) + hiSysEvent.addWatcher(watcher) setTimeout(() => { - result = hiSysEvent.removeWatcher(watcher) - expect(result).assertEqual(0) - done() - console.info('testHiSysEventApi18 end') + try { + hiSysEvent.removeWatcher(watcher) + expect(true).assertTrue() + console.info('testHiSysEventApi18 end') + done(); + } catch (err) { + console.error(`testHiSysEventApi18 > error code: ${err.code}, error msg: ${err.message}`) + expect(err.code == 201).assertTrue() + console.info('testHiSysEventApi18 end') + done() + } }, 1000) - done(); }) /** @@ -595,15 +649,20 @@ describe('hiSysEventJsTest', function () { console.info(`testHiSysEventApi19 Onservice died`); } } - let result = hiSysEvent.addWatcher(watcher) - expect(result).assertEqual(0) + hiSysEvent.addWatcher(watcher) setTimeout(() => { - result = hiSysEvent.removeWatcher(watcher) - expect(result).assertEqual(0) - done() - console.info('testHiSysEventApi19 end') + try { + hiSysEvent.removeWatcher(watcher) + expect(true).assertTrue() + console.info('testHiSysEventApi19 end') + done(); + } catch (err) { + console.error(`testHiSysEventApi19 > error code: ${err.code}, error msg: ${err.message}`) + expect(err.code == 201).assertTrue() + console.info('testHiSysEventApi19 end') + done() + } }, 1000) - done(); }) /** @@ -634,15 +693,20 @@ describe('hiSysEventJsTest', function () { console.info(`testHiSysEventApi20 Onservice died`); } } - let result = hiSysEvent.addWatcher(watcher) - expect(result).assertEqual(0) + hiSysEvent.addWatcher(watcher) setTimeout(() => { - result = hiSysEvent.removeWatcher(watcher) - expect(result).assertEqual(0) - done() - console.info('testHiSysEventApi20 end') + try { + hiSysEvent.removeWatcher(watcher) + expect(true).assertTrue() + console.info('testHiSysEventApi20 end') + done(); + } catch (err) { + console.error(`testHiSysEventApi20 > error code: ${err.code}, error msg: ${err.message}`) + expect(err.code == 201).assertTrue() + console.info('testHiSysEventApi20 end') + done() + } }, 1000) - done(); }) /** @@ -674,15 +738,20 @@ describe('hiSysEventJsTest', function () { console.info(`testHiSysEventApi21 Onservice died`); } } - let result = hiSysEvent.addWatcher(watcher) - expect(result).assertEqual(0) + hiSysEvent.addWatcher(watcher) setTimeout(() => { - result = hiSysEvent.removeWatcher(watcher) - expect(result).assertEqual(0) - done() - console.info('testHiSysEventApi21 end') + try { + hiSysEvent.removeWatcher(watcher) + expect(true).assertTrue() + console.info('testHiSysEventApi21 end') + done(); + } catch (err) { + console.error(`testHiSysEventApi21 > error code: ${err.code}, error msg: ${err.message}`) + expect(err.code == 201).assertTrue() + console.info('testHiSysEventApi21 end') + done() + } }, 1000) - done(); }) /** @@ -714,15 +783,20 @@ describe('hiSysEventJsTest', function () { console.info(`testHiSysEventApi22 Onservice died`); } } - let result = hiSysEvent.addWatcher(watcher) - expect(result).assertEqual(0) + hiSysEvent.addWatcher(watcher) setTimeout(() => { - result = hiSysEvent.removeWatcher(watcher) - expect(result).assertEqual(0) - done() - console.info('testHiSysEventApi22 end') + try { + hiSysEvent.removeWatcher(watcher) + expect(true).assertTrue() + console.info('testHiSysEventApi22 end') + done(); + } catch (err) { + console.error(`testHiSysEventApi22 > error code: ${err.code}, error msg: ${err.message}`) + expect(err.code == 201).assertTrue() + console.info('testHiSysEventApi22 end') + done() + } }, 1000) - done(); }) /** @@ -754,15 +828,20 @@ describe('hiSysEventJsTest', function () { console.info(`testHiSysEventApi23 Onservice died`); } } - let result = hiSysEvent.addWatcher(watcher) - expect(result).assertEqual(0) + hiSysEvent.addWatcher(watcher) setTimeout(() => { - result = hiSysEvent.removeWatcher(watcher) - expect(result).assertEqual(0) - done() - console.info('testHiSysEventApi23 end') + try { + hiSysEvent.removeWatcher(watcher) + expect(true).assertTrue() + console.info('testHiSysEventApi23 end') + done(); + } catch (err) { + console.error(`testHiSysEventApi23 > error code: ${err.code}, error msg: ${err.message}`) + expect(err.code == 201).assertTrue() + console.info('testHiSysEventApi23 end') + done() + } }, 1000) - done(); }) /** @@ -772,69 +851,72 @@ describe('hiSysEventJsTest', function () { */ it('testHiSysEventApi24', 1, async function (done) { console.info('testHiSysEventApi24 start') - hiSysEvent.write({ - domain: "ACCOUNT", - name: "PERMISSION_EXCEPTION", - eventType: hiSysEvent.EventType.SECURITY, - params: { - PID: 487, - UID: 103, - PACKAGE_NAME: "com.ohos.hisysevent.test", - PROCESS_NAME: "syseventservice", - MSG: "no msg." - } - },(err, value) => { - console.log('testHiSysEventApi24 into json-callback'); - if (err) { - console.error('in testHiSysEventApi24 test callback: err.code = ' + err.code) - result = err.code - } else { - console.info('in testHiSysEventApi24 test callback: result = ' + value) - result = value; - } - }); - setTimeout(() => { - let ret = hiSysEvent.query({ - beginTime: -1, - endTime: -1, - maxEvents: 1, - }, [{ - domain: "ACCOUNT", - names: ["PERMISSION_EXCEPTION"], - }], { - onQuery: function (infos, seqs) { - console.info(`testHiSysEventApi24: onQuery...`) - expect(infos.length >= 0).assertTrue() - expect(seqs.length >= 0).assertTrue() - console.info(`testHiSysEventApi24: infos.size is ${infos.length}, seqs.length is ${seqs.length}`) - if (infos instanceof Array) { - for (let i = 0; i < infos.length; i++) { - let item = infos[i]; - console.info(`testHiSysEventApi24: 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(`testHiSysEventApi24: ${key}: ${item.params[key]}`) - } - } - } - } - if (seqs instanceof Array) { - for (let i = 0; i < seqs.length; i++) { - let item = seqs[i]; - console.info(`testHiSysEventApi24: seq${i}: ${item}`) - } - } - }, - onComplete: function(reason, total) { - console.info(`testHiSysEventApi24: onComplete...`) - console.info(`testHiSysEventApi24: reason is ${reason}, total is ${total}`) - done() - console.info(`testHiSysEventApi24 end`) - } - }) - expect(ret).assertEqual(0) - }, 1000); + try { + hiSysEvent.write({ + domain: "ACCOUNT", + name: "PERMISSION_EXCEPTION", + eventType: hiSysEvent.EventType.SECURITY, + params: { + PID: 487, + UID: 103, + PACKAGE_NAME: "com.ohos.hisysevent.test", + PROCESS_NAME: "syseventservice", + MSG: "no msg." + } + },(err, value) => { + console.log('testHiSysEventApi24 into json-callback'); + if (err) { + console.error('in testHiSysEventApi24 test callback: err.code = ' + err.code) + result = err.code + } else { + console.info('in testHiSysEventApi24 test callback: result = ' + value) + result = value; + } + }); + setTimeout(() => { + hiSysEvent.query({ + beginTime: -1, + endTime: -1, + maxEvents: 1, + }, [{ + domain: "ACCOUNT", + names: ["PERMISSION_EXCEPTION"], + }], { + onQuery: function (infos, seqs) { + console.info(`testHiSysEventApi24: onQuery...`) + expect(infos.length >= 0).assertTrue() + expect(seqs.length >= 0).assertTrue() + console.info(`testHiSysEventApi24: infos.size is ${infos.length}, seqs.length is ${seqs.length}`) + if (infos instanceof Array) { + for (let i = 0; i < infos.length; i++) { + let item = infos[i]; + console.info(`testHiSysEventApi24: 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(`testHiSysEventApi24: ${key}: ${item.params[key]}`) + } + } + } + } + if (seqs instanceof Array) { + for (let i = 0; i < seqs.length; i++) { + let item = seqs[i]; + console.info(`testHiSysEventApi24: seq${i}: ${item}`) + } + } + }, + onComplete: function(reason, total) { + console.info(`testHiSysEventApi24: onComplete...`) + console.info(`testHiSysEventApi24: reason is ${reason}, total is ${total}`) + done() + console.info(`testHiSysEventApi24 end`) + } + }) + }, 1000); + } catch (error) { + console.error(`error code: ${error.code}, error msg: ${error.message}`); + } }) /** @@ -844,25 +926,10 @@ describe('hiSysEventJsTest', function () { */ it('testHiSysEventApi25', 1, async function (done) { console.info('testHiSysEventApi25 start') - hiSysEvent.write({ - domain: "HIVIEWDFX", - name: "SYS_USAGE", - eventType: hiSysEvent.EventType.STATISTIC, - },(err, value) => { - console.log('testHiSysEventApi25 into json-callback'); - if (err) { - console.error('in testHiSysEventApi25 test callback: err.code = ' + err.code) - result = err.code - } else { - console.info('in testHiSysEventApi25 test callback: result = ' + value) - result = value; - } - }); - console.info('add second..') - setTimeout(() => { + try { hiSysEvent.write({ domain: "HIVIEWDFX", - name: "PLUGIN_STATS", + name: "SYS_USAGE", eventType: hiSysEvent.EventType.STATISTIC, },(err, value) => { console.log('testHiSysEventApi25 into json-callback'); @@ -873,50 +940,68 @@ describe('hiSysEventJsTest', function () { console.info('in testHiSysEventApi25 test callback: result = ' + value) result = value; } - }) - },1000) - setTimeout(() => { - let ret = hiSysEvent.query({ - beginTime: -1, - endTime: -1, - maxEvents: 5, - }, [{ - domain: "HIVIEWDFX", - names: ["SYS_USAGE","PLUGIN_STATS"], - }], { - onQuery: function (infos, seqs) { - console.info(`testHiSysEventApi25: onQuery...`) - expect(infos.length >= 0).assertTrue() - expect(seqs.length >= 0).assertTrue() - console.info(`testHiSysEventApi25: infos.size is ${infos.length}, seqs.length is ${seqs.length}`) - if (infos instanceof Array) { - for (let i = 0; i < infos.length; i++) { - let item = infos[i]; - console.info(`testHiSysEventApi25: 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(`testHiSysEventApi25: ${key}: ${item.params[key]}`) - } - } - } - } - if (seqs instanceof Array) { - for (let i = 0; i < seqs.length; i++) { - let item = seqs[i]; - console.info(`testHiSysEventApi25: seq${i}: ${item}`) - } - } - }, - onComplete: function(reason, total) { - console.info(`testHiSysEventApi25: onComplete...`) - console.info(`testHiSysEventApi25: reason is ${reason}, total is ${total}`) - done() - console.info(`testHiSysEventApi25 end`) - } - }) - expect(ret).assertEqual(0) - }, 1000); + }); + console.info('add second..') + setTimeout(() => { + hiSysEvent.write({ + domain: "HIVIEWDFX", + name: "PLUGIN_STATS", + eventType: hiSysEvent.EventType.STATISTIC, + },(err, value) => { + console.log('testHiSysEventApi25 into json-callback'); + if (err) { + console.error('in testHiSysEventApi25 test callback: err.code = ' + err.code) + result = err.code + } else { + console.info('in testHiSysEventApi25 test callback: result = ' + value) + result = value; + } + }) + },1000) + setTimeout(() => { + hiSysEvent.query({ + beginTime: -1, + endTime: -1, + maxEvents: 5, + }, [{ + domain: "HIVIEWDFX", + names: ["SYS_USAGE","PLUGIN_STATS"], + }], { + onQuery: function (infos, seqs) { + console.info(`testHiSysEventApi25: onQuery...`) + expect(infos.length >= 0).assertTrue() + expect(seqs.length >= 0).assertTrue() + console.info(`testHiSysEventApi25: infos.size is ${infos.length}, seqs.length is ${seqs.length}`) + if (infos instanceof Array) { + for (let i = 0; i < infos.length; i++) { + let item = infos[i]; + console.info(`testHiSysEventApi25: 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(`testHiSysEventApi25: ${key}: ${item.params[key]}`) + } + } + } + } + if (seqs instanceof Array) { + for (let i = 0; i < seqs.length; i++) { + let item = seqs[i]; + console.info(`testHiSysEventApi25: seq${i}: ${item}`) + } + } + }, + onComplete: function(reason, total) { + console.info(`testHiSysEventApi25: onComplete...`) + console.info(`testHiSysEventApi25: reason is ${reason}, total is ${total}`) + done() + console.info(`testHiSysEventApi25 end`) + } + }) + }, 2000); + } catch (error) { + console.error(`error code: ${error.code}, error msg: ${error.message}`); + } }) }) } -- GitLab