• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (C) 2021-2022 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 *     http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16import hiTraceChain from "@ohos.hiTraceChain"
17
18import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index'
19
20describe('hiTraceChainJsUnitTest', function () {
21    beforeAll(function() {
22
23        /**
24         * @tc.setup: setup invoked before all test cases
25         */
26        console.info('hiTraceChainJsUnitTest beforeAll called')
27    })
28
29    afterAll(function() {
30
31        /**
32         * @tc.teardown: teardown invoked after all test cases
33         */
34        console.info('hiTraceChainJsUnitTest afterAll called')
35    })
36
37    beforeEach(function() {
38
39        /**
40         * @tc.setup: setup invoked before each test case
41         */
42        console.info('hiTraceChainJsUnitTest beforeEach called')
43    })
44
45    afterEach(function() {
46
47        /**
48         * @tc.teardown: teardown invoked after each test case
49         */
50        console.info('hiTraceChainJsUnitTest afterEach called')
51    })
52
53    /**
54     * @tc.name: hiTraceChainJsUnitTest001
55     * @tc.desc: test hiTraceChain.begin/hiTraceChain.isValid/hiTraceChain.end
56     * @tc.type: FUNC
57     */
58    it('hiTraceChainJsUnitTest001', 0, async function (done) {
59        let traceId = hiTraceChain.begin("hiTraceChainJsUnitTest001")
60        expect(hiTraceChain.isValid(traceId)).assertTrue()
61        hiTraceChain.end(traceId)
62        done()
63    });
64
65    /**
66     * @tc.name: hiTraceChainJsUnitTest002
67     * @tc.desc: test hiTraceChain.creadSpan
68     * @tc.type: FUNC
69     */
70    it('hiTraceChainJsUnitTest002', 0, async function (done) {
71        let traceId = hiTraceChain.begin("hiTraceChainJsUnitTest002")
72        traceId = hiTraceChain.createSpan()
73        expect(hiTraceChain.isValid(traceId)).assertTrue()
74        hiTraceChain.end(traceId)
75        done()
76    });
77
78    /**
79     * @tc.name: hiTraceChainJsUnitTest003
80     * @tc.desc: test hiTraceChain.tracepoint
81     * @tc.type: FUNC
82     */
83     it('hiTraceChainJsUnitTest003', 0, async function (done) {
84        let traceId = hiTraceChain.begin("hiTraceChainJsUnitTest003")
85        hiTraceChain.tracepoint(hiTraceChain.HiTraceCommunicationMode.DEFAULT,
86            hiTraceChain.HiTraceTracepointType.CS, traceId, "hiTraceChainJsUnitTest003 test case")
87        hiTraceChain.end(traceId);
88        done();
89    });
90
91    /**
92     * @tc.name: hiTraceChainJsUnitTest004
93     * @tc.desc: test hiTraceChain.isFlagEnabled
94     * @tc.type: FUNC
95     */
96    it('hiTraceChainJsUnitTest004', 0, async function (done) {
97        let traceId = hiTraceChain.begin("hiTraceChainJsUnitTest004")
98        expect(!hiTraceChain.isFlagEnabled(traceId, hiTraceChain.HiTraceFlag.INCLUDE_ASYNC)).assertTrue()
99        hiTraceChain.enableFlag(traceId, hiTraceChain.HiTraceFlag.INCLUDE_ASYNC)
100        expect(hiTraceChain.isFlagEnabled(traceId, hiTraceChain.HiTraceFlag.INCLUDE_ASYNC)).assertTrue()
101        hiTraceChain.end(traceId)
102        done();
103    });
104
105    /**
106     * @tc.name: hiTraceChainJsUnitTest005
107     * @tc.desc: test call begin api function with parameters of wrong number
108     * @tc.type: FUNC
109     */
110    it('hiTraceChainJsUnitTest005', 0, async function (done) {
111        let traceId = hiTraceChain.begin("hiTraceChainJsUnitTest005", "testp1", "testp2")
112        expect(!hiTraceChain.isValid(traceId)).assertTrue()
113        hiTraceChain.end(traceId)
114        done();
115    });
116});