HiChecker.test.js 11.0 KB
Newer Older
U
uoengopen 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
/*
 * 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 hichecker from '@ohos.hichecker'
J
jiyong_sd 已提交
16
import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from '@ohos/hypium'
U
uoengopen 已提交
17

J
jiyong_sd 已提交
18
export default function HiCheckerTest() {
U
uoengopen 已提交
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
describe('HiCheckerTest', function () {

    beforeAll(function() {
        console.info('HiCheckerTest beforeAll called')
    })

    afterAll(function() {
        console.info('HiCheckerTest afterAll called')
    })

    beforeEach(function() {
        console.info('HiCheckerTest beforeEach called');
        hichecker.removeRule(hichecker.RULE_THREAD_CHECK_SLOW_PROCESS);
        hichecker.removeRule(hichecker.RULE_CHECK_SLOW_EVENT);
        hichecker.removeRule(hichecker.RULE_CHECK_ABILITY_CONNECTION_LEAK);
        hichecker.removeRule(hichecker.RULE_CAUTION_PRINT_LOG);
        hichecker.removeRule(hichecker.RULE_CAUTION_TRIGGER_CRASH);
    })

    afterEach(function() {
        console.info('HiCheckerTest afterEach called')
    })

    /**
     * @tc.number 
44
     * @tc.name DFX_DFR_Hichecker_Interface_0100
U
uoengopen 已提交
45 46
     * @tc.desc 
     */
47 48
    it('DFX_DFR_Hichecker_Interface_0100', 0, function () {
        console.info('DFX_DFR_Hichecker_Interface_0100 start');
U
uoengopen 已提交
49 50 51 52 53 54 55 56
        hichecker.addRule(hichecker.RULE_THREAD_CHECK_SLOW_PROCESS);
        let tmp = hichecker.contains(hichecker.RULE_THREAD_CHECK_SLOW_PROCESS);
        console.log('add rule success!');
        expect(tmp).assertTrue();
    })

    /**
     * @tc.number 
57
     * @tc.name DFX_DFR_Hichecker_Interface_0500
U
uoengopen 已提交
58 59
     * @tc.desc 
     */
60 61
     it('DFX_DFR_Hichecker_Interface_0500', 0, function () {
        console.info('DFX_DFR_Hichecker_Interface_0500 start');
U
uoengopen 已提交
62
        hichecker.addRule(hichecker.RULE_THREAD_CHECK_SLOW_PROCESS | hichecker.RULE_CHECK_SLOW_EVENT);
U
uoengopen 已提交
63
        hichecker.addRule(hichecker.RULE_CHECK_ABILITY_CONNECTION_LEAK | hichecker.RULE_CAUTION_PRINT_LOG);
U
uoengopen 已提交
64 65 66 67 68
        console.log('add rule success!');
        expect(hichecker.contains(hichecker.RULE_THREAD_CHECK_SLOW_PROCESS)).assertTrue();
        expect(hichecker.contains(hichecker.RULE_CHECK_SLOW_EVENT)).assertTrue();
        expect(hichecker.contains(hichecker.RULE_CHECK_ABILITY_CONNECTION_LEAK)).assertTrue();
        expect(hichecker.contains(hichecker.RULE_CAUTION_PRINT_LOG)).assertTrue();
U
uoengopen 已提交
69
        let tmp = (hichecker.RULE_THREAD_CHECK_SLOW_PROCESS | hichecker.RULE_CHECK_SLOW_EVENT | hichecker.RULE_CHECK_ABILITY_CONNECTION_LEAK | hichecker.RULE_CAUTION_PRINT_LOG);
U
uoengopen 已提交
70 71 72 73 74
        expect(hichecker.getRule() == tmp).assertTrue();
    })

    /**
     * @tc.number 
75
     * @tc.name DFX_DFR_Hichecker_Interface_0200
U
uoengopen 已提交
76 77
     * @tc.desc 
     */
78 79
     it('DFX_DFR_Hichecker_Interface_0200', 0, function () {
        console.info('DFX_DFR_Hichecker_Interface_0200 start');
U
uoengopen 已提交
80 81 82 83 84 85 86 87
        hichecker.addRule(-1);
        console.log('add wrong rule!');
        expect(hichecker.contains(-1)).assertEqual(false);
        hichecker.addRule(0);
        console.log('add wrong rule!');
        expect(hichecker.contains(0)).assertEqual(false);
        hichecker.addRule(999999);
        console.log('add wrong rule!');
C
chenxuihui 已提交
88
        expect(hichecker.contains(999999)).assertEqual(false);
U
uoengopen 已提交
89 90 91 92
    })

    /**
     * @tc.number 
93
     * @tc.name DFX_DFR_Hichecker_Interface_1200
U
uoengopen 已提交
94 95
     * @tc.desc 
     */
96 97
     it('DFX_DFR_Hichecker_Interface_1200', 0, function () {
        console.info('DFX_DFR_Hichecker_Interface_1200 start');
U
uoengopen 已提交
98 99 100 101 102 103 104 105 106
        hichecker.addRule(hichecker.RULE_THREAD_CHECK_SLOW_PROCESS);
        expect(hichecker.contains(hichecker.RULE_THREAD_CHECK_SLOW_PROCESS)).assertTrue();
        console.log('add rule success!');
        hichecker.removeRule(hichecker.RULE_THREAD_CHECK_SLOW_PROCESS);
        expect(hichecker.contains(hichecker.RULE_THREAD_CHECK_SLOW_PROCESS)).assertEqual(false);
    })

    /**
     * @tc.number 
107
     * @tc.name DFX_DFR_Hichecker_Interface_0800
U
uoengopen 已提交
108 109
     * @tc.desc 
     */
110 111
     it('DFX_DFR_Hichecker_Interface_0800', 0, function () {
        console.info('DFX_DFR_Hichecker_Interface_0800 start');
U
uoengopen 已提交
112
        hichecker.addRule(hichecker.RULE_THREAD_CHECK_SLOW_PROCESS | hichecker.RULE_CHECK_SLOW_EVENT);
U
uoengopen 已提交
113
        hichecker.addRule(hichecker.RULE_CHECK_ABILITY_CONNECTION_LEAK | hichecker.RULE_CAUTION_PRINT_LOG);
U
uoengopen 已提交
114
        console.log('add rule success!');
U
uoengopen 已提交
115
        let tmp = (hichecker.RULE_CHECK_ABILITY_CONNECTION_LEAK | hichecker.RULE_CAUTION_PRINT_LOG);
U
uoengopen 已提交
116 117
        hichecker.removeRule(hichecker.RULE_THREAD_CHECK_SLOW_PROCESS | hichecker.RULE_CHECK_SLOW_EVENT);
        expect(hichecker.getRule() == tmp).assertTrue();
U
uoengopen 已提交
118
        hichecker.removeRule(hichecker.RULE_CHECK_ABILITY_CONNECTION_LEAK | hichecker.RULE_CAUTION_PRINT_LOG);
U
uoengopen 已提交
119 120 121 122 123
        expect(hichecker.getRule() == 0).assertTrue();
    })

    /**
     * @tc.number 
124
     * @tc.name DFX_DFR_Hichecker_Interface_1300
U
uoengopen 已提交
125 126
     * @tc.desc 
     */
127 128
     it('DFX_DFR_Hichecker_Interface_1300', 0, function () {
        console.info('DFX_DFR_Hichecker_Interface_1300 start');
U
uoengopen 已提交
129
        hichecker.addRule(hichecker.RULE_THREAD_CHECK_SLOW_PROCESS | hichecker.RULE_CHECK_SLOW_EVENT);
U
uoengopen 已提交
130
        hichecker.addRule(hichecker.RULE_CHECK_ABILITY_CONNECTION_LEAK | hichecker.RULE_CAUTION_PRINT_LOG);
U
uoengopen 已提交
131
        console.log('add rule success!');
U
uoengopen 已提交
132
        let tmp = (hichecker.RULE_THREAD_CHECK_SLOW_PROCESS | hichecker.RULE_CHECK_SLOW_EVENT | hichecker.RULE_CHECK_ABILITY_CONNECTION_LEAK | hichecker.RULE_CAUTION_PRINT_LOG);
U
uoengopen 已提交
133 134 135 136 137 138 139
        hichecker.removeRule(-1);
        expect(hichecker.getRule() == tmp).assertTrue();
        hichecker.removeRule(0);
        expect(hichecker.getRule() == tmp).assertTrue();
        hichecker.removeRule(999999);
        expect(hichecker.getRule() == tmp).assertTrue();
    })
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257

    /**
     * @tc.number DFX_DFR_Hichecker_Interface_2200
     * @tc.name   addCheckRule with normal parameter
     * @tc.desc
     */
     it('DFX_DFR_Hichecker_Interface_2200', 0, function () {
        console.info('DFX_DFR_Hichecker_Interface_2200 start');
        try {
            hichecker.addCheckRule(hichecker.RULE_THREAD_CHECK_SLOW_PROCESS | hichecker.RULE_CHECK_SLOW_EVENT);
            hichecker.addCheckRule(hichecker.RULE_CHECK_ABILITY_CONNECTION_LEAK | hichecker.RULE_CAUTION_PRINT_LOG);
            console.log('add rule success!');
            expect(hichecker.containsCheckRule(hichecker.RULE_THREAD_CHECK_SLOW_PROCESS)).assertTrue();
            expect(hichecker.containsCheckRule(hichecker.RULE_CHECK_SLOW_EVENT)).assertTrue();
            expect(hichecker.containsCheckRule(hichecker.RULE_CHECK_ABILITY_CONNECTION_LEAK)).assertTrue();
            expect(hichecker.containsCheckRule(hichecker.RULE_CAUTION_PRINT_LOG)).assertTrue();
        } catch (error) {
            console.info(error.code)
            console.info(error.message)
            expect(error.code == 401).assertTrue();
        }
    })

    /**
     * @tc.number DFX_DFR_Hichecker_Interface_2300
     * @tc.name   removeCheckRule with normal parameter
     * @tc.desc
     */
     it('DFX_DFR_Hichecker_Interface_2300', 0, function () {
        console.info('DFX_DFR_Hichecker_Interface_2300 start');
        try {
            hichecker.addCheckRule(hichecker.RULE_THREAD_CHECK_SLOW_PROCESS | hichecker.RULE_CHECK_SLOW_EVENT);
            hichecker.addCheckRule(hichecker.RULE_CHECK_ABILITY_CONNECTION_LEAK | hichecker.RULE_CAUTION_PRINT_LOG);
            console.log('add rule success!');
            let tmp = (hichecker.RULE_CHECK_ABILITY_CONNECTION_LEAK | hichecker.RULE_CAUTION_PRINT_LOG);
            hichecker.removeCheckRule(hichecker.RULE_THREAD_CHECK_SLOW_PROCESS | hichecker.RULE_CHECK_SLOW_EVENT);
            expect(hichecker.getRule() == tmp).assertTrue();
            hichecker.removeCheckRule(hichecker.RULE_CHECK_ABILITY_CONNECTION_LEAK | hichecker.RULE_CAUTION_PRINT_LOG);
            expect(hichecker.getRule() == 0).assertTrue();
        } catch (error) {
            console.info(error.code)
            console.info(error.message)
            expect(error.code == 401).assertTrue();
        }
    })

    /**
     * @tc.number DFX_DFR_Hichecker_Interface_2400
     * @tc.name   containsCheckRule with normal parameter
     * @tc.desc
     */
     it('DFX_DFR_Hichecker_Interface_2400', 0, function () {
        console.info('DFX_DFR_Hichecker_Interface_2400 start');
        try {
            hichecker.addCheckRule(hichecker.RULE_THREAD_CHECK_SLOW_PROCESS | hichecker.RULE_CHECK_SLOW_EVENT);
            hichecker.addCheckRule(hichecker.RULE_CHECK_ABILITY_CONNECTION_LEAK | hichecker.RULE_CAUTION_PRINT_LOG);
            console.log('add rule success!');
            expect(hichecker.containsCheckRule(hichecker.RULE_THREAD_CHECK_SLOW_PROCESS)).assertTrue();
            expect(hichecker.containsCheckRule(hichecker.RULE_CHECK_SLOW_EVENT)).assertTrue();
            expect(hichecker.containsCheckRule(hichecker.RULE_CHECK_ABILITY_CONNECTION_LEAK)).assertTrue();
            expect(hichecker.containsCheckRule(hichecker.RULE_CAUTION_PRINT_LOG)).assertTrue();
        } catch (error) {
            console.info(error.code)
            console.info(error.message)
            expect(error.code == 401).assertTrue();
        }
    })

    /**
     * @tc.number DFX_DFR_Hichecker_Interface_2500
     * @tc.name   addCheckRule with abnormal parameter
     * @tc.desc
     */
     it('DFX_DFR_Hichecker_Interface_2500', 0, function () {
        console.info('DFX_DFR_Hichecker_Interface_2500 start');
        try {
            hichecker.addCheckRule();
        } catch (error) {
            console.info(error.code)
            console.info(error.message)
            expect(error.code == 401).assertTrue();
        }
    })

    /**
     * @tc.number DFX_DFR_Hichecker_Interface_2600
     * @tc.name   removeCheckRule with abnormal parameter
     * @tc.desc
     */
     it('DFX_DFR_Hichecker_Interface_2600', 0, function () {
        console.info('DFX_DFR_Hichecker_Interface_2600 start');
        try {
            hichecker.removeCheckRule();
        } catch (error) {
            console.info(error.code)
            console.info(error.message)
            expect(error.code == 401).assertTrue();
        }
    })

    /**
     * @tc.number DFX_DFR_Hichecker_Interface_2700
     * @tc.name   containsCheckRule with abnormal parameter
     * @tc.desc
     */
     it('DFX_DFR_Hichecker_Interface_2700', 0, function () {
        console.info('DFX_DFR_Hichecker_Interface_2700 start');
        try {
            hichecker.addCheckRule(hichecker.RULE_THREAD_CHECK_SLOW_PROCESS | hichecker.RULE_CHECK_SLOW_EVENT);
            console.log('add rule success!');
            hichecker.containsCheckRule();
        } catch (error) {
            console.info(error.code)
            console.info(error.message)
            expect(error.code == 401).assertTrue();
        }
    })

U
uoengopen 已提交
258
})
J
jiyong_sd 已提交
259
}