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 let logTag = '[hiTraceChainJsUnitTest]'; 22 23 beforeAll(function() { 24 25 /** 26 * @tc.setup: setup invoked before all test cases 27 */ 28 console.info(logTag, 'hiTraceChainJsUnitTest beforeAll called'); 29 }) 30 31 afterAll(function() { 32 33 /** 34 * @tc.teardown: teardown invoked after all test cases 35 */ 36 console.info(logTag, 'hiTraceChainJsUnitTest afterAll called'); 37 }) 38 39 beforeEach(function() { 40 41 /** 42 * @tc.setup: setup invoked before each test case 43 */ 44 console.info(logTag, 'hiTraceChainJsUnitTest beforeEach called'); 45 }) 46 47 afterEach(function() { 48 49 /** 50 * @tc.teardown: teardown invoked after each test case 51 */ 52 console.info(logTag, 'hiTraceChainJsUnitTest afterEach called'); 53 }) 54 55 /** 56 * @tc.name: hiTraceChainJsUnitTest001 57 * @tc.desc: test hiTraceChain.begin/hiTraceChain.isValid/hiTraceChain.end 58 * @tc.type: FUNC 59 */ 60 it('hiTraceChainJsUnitTest001', 0, async function (done) { 61 let traceId = hiTraceChain.begin("hiTraceChainJsUnitTest001"); 62 expect(hiTraceChain.isValid(traceId)).assertTrue(); 63 hiTraceChain.end(traceId); 64 done(); 65 }); 66 67 /** 68 * @tc.name: hiTraceChainJsUnitTest002 69 * @tc.desc: test hiTraceChain.creadSpan 70 * @tc.type: FUNC 71 */ 72 it('hiTraceChainJsUnitTest002', 0, async function (done) { 73 let traceId = hiTraceChain.begin("hiTraceChainJsUnitTest002"); 74 traceId = hiTraceChain.createSpan(); 75 expect(hiTraceChain.isValid(traceId)).assertTrue(); 76 hiTraceChain.end(traceId); 77 done(); 78 }); 79 80 /** 81 * @tc.name: hiTraceChainJsUnitTest003 82 * @tc.desc: test hiTraceChain.tracepoint 83 * @tc.type: FUNC 84 */ 85 it('hiTraceChainJsUnitTest003', 0, async function (done) { 86 let traceId = hiTraceChain.begin("hiTraceChainJsUnitTest003"); 87 expect(hiTraceChain.isValid(traceId)).assertTrue(); 88 hiTraceChain.tracepoint(hiTraceChain.HiTraceCommunicationMode.DEFAULT, 89 hiTraceChain.HiTraceTracepointType.CS, traceId, "hiTraceChainJsUnitTest003 test case"); 90 expect(hiTraceChain.isValid(traceId)).assertTrue(); 91 hiTraceChain.end(traceId); 92 done(); 93 }); 94 95 /** 96 * @tc.name: hiTraceChainJsUnitTest004 97 * @tc.desc: test hiTraceChain.isFlagEnabled 98 * @tc.type: FUNC 99 */ 100 it('hiTraceChainJsUnitTest004', 0, async function (done) { 101 let traceId = hiTraceChain.begin("hiTraceChainJsUnitTest004") 102 expect(!hiTraceChain.isFlagEnabled(traceId, hiTraceChain.HiTraceFlag.INCLUDE_ASYNC)).assertTrue(); 103 hiTraceChain.enableFlag(traceId, hiTraceChain.HiTraceFlag.INCLUDE_ASYNC); 104 expect(hiTraceChain.isFlagEnabled(traceId, hiTraceChain.HiTraceFlag.INCLUDE_ASYNC)).assertTrue(); 105 hiTraceChain.end(traceId); 106 done(); 107 }); 108 109 /** 110 * @tc.name: hiTraceChainJsUnitTest005 111 * @tc.desc: test call begin api function with parameters of wrong number 112 * @tc.type: FUNC 113 */ 114 it('hiTraceChainJsUnitTest005', 0, async function (done) { 115 let traceId = hiTraceChain.begin("hiTraceChainJsUnitTest005", "testp1", "testp2"); 116 expect(!hiTraceChain.isValid(traceId)).assertTrue(); 117 hiTraceChain.end(traceId); 118 done(); 119 }); 120 121 /** 122 * @tc.name: hiTraceChainJsUnitTest006 123 * @tc.desc: test hiTraceChain.begin with undefined flag 124 * @tc.type: FUNC 125 */ 126 it('hiTraceChainJsUnitTest006', 0, async function (done) { 127 let traceId = hiTraceChain.begin("hiTraceChainJsUnitTest006", undefined); 128 expect(hiTraceChain.isValid(traceId)).assertTrue(); 129 hiTraceChain.end(traceId); 130 done(); 131 }); 132 133 /** 134 * @tc.name: hiTraceChainJsUnitTest007 135 * @tc.desc: test hiTraceChain.tracepoint with undefined msg 136 * @tc.type: FUNC 137 */ 138 it('hiTraceChainJsUnitTest007', 0, async function (done) { 139 let traceId = hiTraceChain.begin("hiTraceChainJsUnitTest007"); 140 expect(hiTraceChain.isValid(traceId)).assertTrue(); 141 hiTraceChain.tracepoint(hiTraceChain.HiTraceCommunicationMode.DEFAULT, 142 hiTraceChain.HiTraceTracepointType.CS, traceId, undefined); 143 expect(hiTraceChain.isValid(traceId)).assertTrue(); 144 hiTraceChain.end(traceId); 145 done(); 146 }); 147 148 /** 149 * @tc.name: hiTraceChainJsUnitTest008 150 * @tc.desc: test hiTraceChain.begin with null flag 151 * @tc.type: FUNC 152 */ 153 it('hiTraceChainJsUnitTest008', 0, async function (done) { 154 let traceId = hiTraceChain.begin("hiTraceChainJsUnitTest008", null); 155 expect(hiTraceChain.isValid(traceId)).assertTrue(); 156 hiTraceChain.end(traceId); 157 done(); 158 }); 159 160 /** 161 * @tc.name: hiTraceChainJsUnitTest009 162 * @tc.desc: test hiTraceChain.tracepoint with null msg 163 * @tc.type: FUNC 164 */ 165 it('hiTraceChainJsUnitTest009', 0, async function (done) { 166 let traceId = hiTraceChain.begin("hiTraceChainJsUnitTest009"); 167 expect(hiTraceChain.isValid(traceId)).assertTrue(); 168 hiTraceChain.tracepoint(hiTraceChain.HiTraceCommunicationMode.DEFAULT, 169 hiTraceChain.HiTraceTracepointType.CS, traceId, null); 170 expect(hiTraceChain.isValid(traceId)).assertTrue(); 171 hiTraceChain.end(traceId); 172 done(); 173 }); 174 175 /** 176 * @tc.name: hiTraceChainJsUnitTest010 177 * @tc.desc: test hiTraceChain.tracepoint with no msg 178 * @tc.type: FUNC 179 */ 180 it('hiTraceChainJsUnitTest010', 0, async function (done) { 181 let traceId = hiTraceChain.begin("hiTraceChainJsUnitTest010"); 182 expect(hiTraceChain.isValid(traceId)).assertTrue(); 183 hiTraceChain.tracepoint(hiTraceChain.HiTraceCommunicationMode.DEFAULT, 184 hiTraceChain.HiTraceTracepointType.CS, traceId); 185 expect(hiTraceChain.isValid(traceId)).assertTrue(); 186 hiTraceChain.end(traceId); 187 done(); 188 }); 189}); 190