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

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

    /**
    * run before testClass
    */
    beforeAll(function () {
        console.info('beforeAll called');
    })

    /**
    * run after testClass
    */
    afterAll(function () {
        console.info('afterAll called');
    })

    /**
     * @tc.number DFX_DFT_Hiview_Libhilog_Hilog_JS_0100
     * @tc.name hitrace interface test
     * @tc.desc hitrace begin interface test.
     */
    it('testHilogJsApi01', 2, function () {
        console.info('testHilogJsApi01 start');
        try{
C
chenxuihui 已提交
43
            hilog.debug(0x3200, "HILOGTEST", "%{public}s", ['hilogJs0100'])
C
chenxuihui 已提交
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
        } catch (error){
            console.log(`testHilogJsApi01 got an error: ${JSON.stringify(error)}`)
            expect().assertFail()
        }
        console.info('testHilogJsApi01 end');
    })

    /**
     * @tc.number DFX_DFT_Hiview_Libhilog_Hilog_JS_0200
     * @tc.name hitrace interface test
     * @tc.desc hitrace begin interface test.
     */
    it('testHilogJsApi02', 2, function () {
        console.info('testHilogJsApi02 start');
        try{
C
chenxuihui 已提交
59
            hilog.error(0x3200, "HILOGTEST", "%{public}s", ['hilogJs0200'])
C
chenxuihui 已提交
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
        } catch (error){
            console.log(`testHilogJsApi02 got an error: ${JSON.stringify(error)}`)
            expect().assertFail()
        }
        console.info('testHilogJsApi02 end');
    })

    /**
     * @tc.number DFX_DFT_Hiview_Libhilog_Hilog_JS_0300
     * @tc.name hitrace interface test
     * @tc.desc hitrace begin interface test.
     */
    it('testHilogJsApi03', 2, function () {
        console.info('testHilogJsApi03 start');
        try{
C
chenxuihui 已提交
75
            hilog.fatal(0x3200, "HILOGTEST", "%{public}s", ['hilogJs0300'])
C
chenxuihui 已提交
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
        } catch (error){
            console.log(`testHilogJsApi03 got an error: ${JSON.stringify(error)}`)
            expect().assertFail()
        }
        console.info('testHilogJsApi03 end');
    })

    /**
     * @tc.number DFX_DFT_Hiview_Libhilog_Hilog_JS_0400
     * @tc.name hitrace interface test
     * @tc.desc hitrace begin interface test.
     */
    it('testHilogJsApi04', 2, function () {
        console.info('testHilogJsApi04 start');
        try{
C
chenxuihui 已提交
91
            hilog.info(0x3200, "HILOGTEST", "%{public}s", ['hilogJs0400'])
C
chenxuihui 已提交
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
        } catch (error){
            console.log(`testHilogJsApi04 got an error: ${JSON.stringify(error)}`)
            expect().assertFail()
        }
        console.info('testHilogJsApi04 end');
    })

    /**
     * @tc.number DFX_DFT_Hiview_Libhilog_Hilog_JS_0500
     * @tc.name hitrace interface test
     * @tc.desc hitrace begin interface test.
     */
    it('testHilogJsApi05', 2, function () {
        console.info('testHilogJsApi04 start');
        try{
C
chenxuihui 已提交
107
            hilog.warn(0x3200, "HILOGTEST", "%{public}s", ['hilogJs0500'])
C
chenxuihui 已提交
108 109 110 111 112 113 114 115 116 117 118 119 120 121
        } catch (error){
            console.log(`testHilogJsApi05 got an error: ${JSON.stringify(error)}`)
            expect().assertFail()
        }
        console.info('testHilogJsApi05 end');
    })

    /**
     * @tc.number DFX_DFT_Hiview_Libhilog_Hilog_JS_0600
     * @tc.name hitrace interface test
     * @tc.desc hitrace begin interface test.
     */
    it('testHilogJsApi06', 2, function () {
        console.info('testHilogJsApi06 start');
C
chenxuihui 已提交
122
        const res = hilog.isLoggable(0x3200, "HILOGTEST", hilog.LogLevel.DEBUG);
C
chenxuihui 已提交
123
        expect(res).assertEqual(false);
C
chenxuihui 已提交
124 125 126 127 128 129 130 131 132 133
        console.info('testHilogJsApi06 end');
    })

    /**
     * @tc.number DFX_DFT_Hiview_Libhilog_Hilog_JS_0700
     * @tc.name hitrace interface test
     * @tc.desc hitrace begin interface test.
     */
    it('testHilogJsApi07', 2, function () {
        console.info('testHilogJsApi07 start');
C
chenxuihui 已提交
134
        const res = hilog.isLoggable(0x3200, "HILOGTEST", hilog.LogLevel.DEBUG);
C
chenxuihui 已提交
135 136 137 138
        var tag = "";
        for (var i = 0; i < 1000; i++){
            tag += "HILOGTEST"
        }
C
chenxuihui 已提交
139
        expect(res).assertEqual(false);
C
chenxuihui 已提交
140 141 142 143 144 145 146 147 148 149
        console.info('testHilogJsApi07 end');
    })

    /**
     * @tc.number DFX_DFT_Hiview_Libhilog_Hilog_JS_0800
     * @tc.name hitrace interface test
     * @tc.desc hitrace begin interface test.
     */
    it('testHilogJsApi08', 2, function () {
        console.info('testHilogJsApi08 start');
C
chenxuihui 已提交
150
        const res = hilog.isLoggable(0x3200, "", hilog.LogLevel.DEBUG);
C
chenxuihui 已提交
151
        expect(res).assertEqual(false);
C
chenxuihui 已提交
152 153 154 155 156 157 158 159 160 161
        console.info('testHilogJsApi08 end');
    })

    /**
     * @tc.number DFX_DFT_Hiview_Libhilog_Hilog_JS_1100
     * @tc.name hitrace interface test
     * @tc.desc hitrace begin interface test.
     */
    it('testHilogJsApi09', 2, function () {
        console.info('testHilogJsApi09 start');
C
chenxuihui 已提交
162
        const res = hilog.isLoggable(0x3200, "HILOGTEST", hilog.LogLevel.ERROR);
C
chenxuihui 已提交
163 164 165 166 167 168 169 170 171 172 173
        expect(res).assertEqual(true);
        console.info('testHilogJsApi09 end');
    })

    /**
     * @tc.number DFX_DFT_Hiview_Libhilog_Hilog_JS_1200
     * @tc.name hitrace interface test
     * @tc.desc hitrace begin interface test.
     */
    it('testHilogJsApi10', 2, function () {
        console.info('testHilogJsApi10 start');
C
chenxuihui 已提交
174
        const res = hilog.isLoggable(0x3200, "HILOGTEST", hilog.LogLevel.FATAL);
C
chenxuihui 已提交
175 176 177 178 179 180 181 182 183 184 185
        expect(res).assertEqual(true);
        console.info('testHilogJsApi10 end');
    })

    /**
     * @tc.number DFX_DFT_Hiview_Libhilog_Hilog_JS_1300
     * @tc.name hitrace interface test
     * @tc.desc hitrace begin interface test.
     */
    it('testHilogJsApi11', 2, function () {
        console.info('testHilogJsApi11 start');
C
chenxuihui 已提交
186
        const res = hilog.isLoggable(0x3200, "HILOGTEST", hilog.LogLevel.INFO);
C
chenxuihui 已提交
187 188 189 190 191 192 193 194 195 196 197
        expect(res).assertEqual(true);
        console.info('testHilogJsApi11 end');
    })

    /**
     * @tc.number DFX_DFT_Hiview_Libhilog_Hilog_JS_1400
     * @tc.name hitrace interface test
     * @tc.desc hitrace begin interface test.
     */
    it('testHilogJsApi12', 2, function () {
        console.info('testHilogJsApi12 start');
C
chenxuihui 已提交
198
        const res = hilog.isLoggable(0x3200, "HILOGTEST", hilog.LogLevel.WARN);
C
chenxuihui 已提交
199 200 201 202 203 204 205 206 207 208 209
        expect(res).assertEqual(true);
        console.info('testHilogJsApi12 end');
    })

    /**
     * @tc.number DFX_DFT_Hiview_Libhilog_Hilog_JS_1500
     * @tc.name hitrace interface test
     * @tc.desc hitrace begin interface test.
     */
    it('testHilogJsApi13', 2, function () {
        console.info('testHilogJsApi13 start');
C
chenxuihui 已提交
210
        const res = hilog.isLoggable(0x3200, "HILOGTEST", 100);
C
chenxuihui 已提交
211
        expect(res).assertEqual(false);
C
chenxuihui 已提交
212 213 214 215 216 217 218 219 220 221
        console.info('testHilogJsApi13 end');
    })

    /**
     * @tc.number DFX_DFT_Hiview_Libhilog_Hilog_JS_1600
     * @tc.name hitrace interface test
     * @tc.desc hitrace begin interface test.
     */
    it('testHilogJsApi14', 2, function () {
        console.info('testHilogJsApi14 start');
C
chenxuihui 已提交
222
        const res = hilog.isLoggable(0, "HILOGTEST", hilog.LogLevel.WARN);
C
chenxuihui 已提交
223 224 225 226 227 228 229 230 231 232 233
        expect(res).assertEqual(true);
        console.info('testHilogJsApi14 end');
    })

    /**
     * @tc.number DFX_DFT_Hiview_Libhilog_Hilog_JS_01700
     * @tc.name hitrace interface test
     * @tc.desc hitrace begin interface test.
     */
    it('testHilogJsApi15', 2, function () {
        console.info('testHilogJsApi15 start');
C
chenxuihui 已提交
234
        const res = hilog.isLoggable(0x3200, "HILOGTEST", hilog.LogLevel.WARN);
C
chenxuihui 已提交
235 236 237 238 239 240 241 242 243 244 245 246
        expect(res).assertEqual(true);
        console.info('testHilogJsApi15 end');
    })

    /**
     * @tc.number DFX_DFT_Hiview_Libhilog_Hilog_JS_1800
     * @tc.name hitrace interface test
     * @tc.desc hitrace begin interface test.
     */
    it('testHilogJsApi16', 2, function () {
        console.info('testHilogJsApi16 start');
        try{
C
chenxuihui 已提交
247
            hilog.debug(0x3200, "HILOGTEST", "%{public}s", ['hilogJs1800'])
C
chenxuihui 已提交
248 249 250 251 252 253 254 255 256 257 258 259 260 261 262
        }catch(error){
            console.log(`testHilogJsApi16 got an error: ${JSON.stringify(error)}`)
            expect().assertFail();
        }
        console.info('testHilogJsApi16 end');
    })

    /**
     * @tc.number DFX_DFT_Hiview_Libhilog_Hilog_JS_2100
     * @tc.name hitrace interface test
     * @tc.desc hitrace begin interface test.
     */
    it('testHilogJsApi17', 2, function () {
        console.info('testHilogJsApi17 start');
        try{
1
15929983503 已提交
263
            hilog.debug(0x3200, "HILOGTEST", "%{public}d", [2.1])
C
chenxuihui 已提交
264 265 266 267 268 269 270 271 272 273 274 275 276 277 278
        }catch(error){
            console.log(`testHilogJsApi17 got an error: ${JSON.stringify(error)}`)
            expect().assertFail();
        }
        console.info('testHilogJsApi17 end');
    })

    /**
     * @tc.number DFX_DFT_Hiview_Libhilog_Hilog_JS_2500
     * @tc.name hitrace interface test
     * @tc.desc hitrace begin interface test.
     */
    it('testHilogJsApi18', 2, function () {
        console.info('testHilogJsApi18 start');
        try{
C
chenxuihui 已提交
279
            hilog.debug(0x3200, "HILOGTEST", "%{public}d", [65535])
C
chenxuihui 已提交
280 281 282 283 284 285 286 287 288 289 290 291 292 293 294
        }catch(error){
            console.log(`testHilogJsApi18 got an error: ${JSON.stringify(error)}`)
            expect().assertFail();
        }
        console.info('testHilogJsApi18 end');
    })

    /**
     * @tc.number DFX_DFT_Hiview_Libhilog_Hilog_JS_2600
     * @tc.name hitrace interface test
     * @tc.desc hitrace begin interface test.
     */
    it('testHilogJsApi19', 2, function () {
        console.info('testHilogJsApi19 start');
        try{
C
chenxuihui 已提交
295
            hilog.debug(0x3200, "HILOGTEST", "%{public}s", ["hilog info"])
C
chenxuihui 已提交
296 297 298 299 300 301 302 303 304 305 306 307 308 309 310
        }catch(error){
            console.log(`testHilogJsApi19 got an error: ${JSON.stringify(error)}`)
            expect().assertFail();
        }
        console.info('testHilogJsApi19 end');
    })

    /**
     * @tc.number DFX_DFT_Hiview_Libhilog_Hilog_JS_2900
     * @tc.name hitrace interface test
     * @tc.desc hitrace begin interface test.
     */
    it('testHilogJsApi20', 2, function () {
        console.info('testHilogJsApi20 start');
        try{
C
chenxuihui 已提交
311
            hilog.debug(0x3200, "HILOGTEST", "%{public}d", [2147483647])
C
chenxuihui 已提交
312 313 314 315 316 317 318 319 320 321 322 323 324 325 326
        }catch(error){
            console.log(`testHilogJsApi20 got an error: ${JSON.stringify(error)}`)
            expect().assertFail();
        }
        console.info('testHilogJsApi20 end');
    })

    /**
     * @tc.number DFX_DFT_Hiview_Libhilog_Hilog_JS_3000
     * @tc.name hitrace interface test
     * @tc.desc hitrace begin interface test.
     */
    it('testHilogJsApi21', 2, function () {
        console.info('testHilogJsApi21 start');
        try{
C
chenxuihui 已提交
327
            hilog.debug(0x3200, "HILOGTEST", "%{public}s", ["100%s%d%x%f"])
C
chenxuihui 已提交
328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343
        }catch(error){
            console.log(`testHilogJsApi21 got an error: ${JSON.stringify(error)}`)
            expect().assertFail();
        }
        console.info('testHilogJsApi21 end');
    })


    /**
     * @tc.number DFX_DFT_Hiview_Libhilog_Hilog_JS_3200
     * @tc.name hitrace interface test
     * @tc.desc hitrace begin interface test.
     */
    it('testHilogJsApi22', 2, function () {
        console.info('testHilogJsApi22 start');
        try{
C
chenxuihui 已提交
344
            hilog.debug(0x3200, "HILOGTEST", "%{public}s", ["65536"])
C
chenxuihui 已提交
345 346 347 348 349 350 351 352 353 354 355 356 357 358 359
        }catch(error){
            console.log(`testHilogJsApi22 got an error: ${JSON.stringify(error)}`)
            expect().assertFail();
        }
        console.info('testHilogJsApi22 end');
    })

    /**
     * @tc.number DFX_DFT_Hiview_Libhilog_Hilog_JS_3300
     * @tc.name hitrace interface test
     * @tc.desc hitrace begin interface test.
     */
    it('testHilogJsApi23', 2, function () {
        console.info('testHilogJsApi23 start');
        try{
C
chenxuihui 已提交
360 361
            hilog.debug(0x3200, "HILOGTEST", "username:%{public}s, password:%{private}s.", ["username", "password"])
            hilog.debug(0x3200, "HILOGTEST", "username:%{public}s, password:%s.", ["username123", "password"])
C
chenxuihui 已提交
362 363 364 365 366 367 368 369 370 371 372 373 374 375 376
        }catch(error){
            console.log(`testHilogJsApi23 got an error: ${JSON.stringify(error)}`)
            expect().assertFail();
        }
        console.info('testHilogJsApi23 end');
    })

    /**
     * @tc.number DFX_DFT_Hiview_Libhilog_Hilog_JS_3400
     * @tc.name hitrace interface test
     * @tc.desc hitrace begin interface test.
     */
    it('testHilogJsApi24', 2, function () {
        console.info('testHilogJsApi24 start');
        try{
C
chenxuihui 已提交
377
            hilog.debug(0x3200, "HILOGTEST", "%{public}s", ["hilog public"])
C
chenxuihui 已提交
378 379 380 381 382 383 384 385 386 387 388 389 390 391 392
        }catch(error){
            console.log(`testHilogJsApi24 got an error: ${JSON.stringify(error)}`)
            expect().assertFail();
        }
        console.info('testHilogJsApi24 end');
    })

    /**
     * @tc.number DFX_DFT_Hiview_Libhilog_Hilog_JS_3500
     * @tc.name hitrace interface test
     * @tc.desc hitrace begin interface test.
     */
    it('testHilogJsApi25', 2, function () {
        console.info('testHilogJsApi25 start');
        try{
C
chenxuihui 已提交
393
            hilog.debug(0x3200, "HILOGTEST", "%{nopublic}s", ["Hilogtest"])
C
chenxuihui 已提交
394 395 396 397 398 399 400 401 402 403 404 405 406 407 408
        }catch(error){
            console.log(`testHilogJsApi25 got an error: ${JSON.stringify(error)}`)
            expect().assertFail();
        }
        console.info('testHilogJsApi25 end');
    })

    /**
     * @tc.number DFX_DFT_Hiview_Libhilog_Hilog_JS_3800
     * @tc.name hitrace interface test
     * @tc.desc hitrace begin interface test.
     */
    it('testHilogJsApi26', 2, function () {
        console.info('testHilogJsApi26 start');
        try{
C
chenxuihui 已提交
409 410
            hilog.info(0x3200, "HILOGTEST", "username:%{public}s, password:%{private}s.", ["username", "password"])
            hilog.info(0x3200, "HILOGTEST", "username:%{public}s, password:%s.", ["username123", "password"])
C
chenxuihui 已提交
411 412 413 414 415 416 417 418
        }catch(error){
            console.log(`testHilogJsApi26 got an error: ${JSON.stringify(error)}`)
            expect().assertFail();
        }
        console.info('testHilogJsApi26 end');
    })

})
J
jiyong_sd 已提交
419
}