1 /* 2 * Copyright (c) 2023 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 16 #include <gmock/gmock-matchers.h> 17 #include <gmock/gmock.h> 18 #include <gtest/gtest.h> 19 #include <string> 20 21 #include "disc_log.h" 22 #include "hilog_mock.h" 23 #include "softbus_log_test_utils.h" 24 25 using namespace std; 26 using namespace testing; 27 using namespace testing::ext; 28 29 namespace OHOS { 30 class DiscLogTest : public testing::Test { }; 31 32 /** 33 * @tc.name: DiscLogTest001 34 * @tc.desc: Test SoftBusLogLabel is consistent with DiscLogLabelEnum 35 * @tc.type: FUNC 36 * @tc.require: I8DW1W 37 */ 38 HWTEST_F(DiscLogTest, DiscLogTest001, TestSize.Level0) 39 { 40 int32_t index = 0; 41 int32_t discDomainBase = 0xd0057a0; 42 43 EXPECT_NO_FATAL_FAILURE(ExpectMatchSoftBusLogAttrs(DISC_LABELS[index], DISC_INIT, discDomainBase, "DiscInit")); 44 EXPECT_NO_FATAL_FAILURE(ExpectMatchSoftBusLogAttrs(DISC_LABELS[++index], 45 DISC_CONTROL, ++discDomainBase, "DiscControl")); 46 EXPECT_NO_FATAL_FAILURE(ExpectMatchSoftBusLogAttrs(DISC_LABELS[++index], DISC_LNN, ++discDomainBase, "DiscLnn")); 47 EXPECT_NO_FATAL_FAILURE(ExpectMatchSoftBusLogAttrs(DISC_LABELS[++index], DISC_BLE, ++discDomainBase, "DiscBle")); 48 EXPECT_NO_FATAL_FAILURE(ExpectMatchSoftBusLogAttrs(DISC_LABELS[++index], 49 DISC_BLE_ADAPTER, ++discDomainBase, "DiscBleAdapter")); 50 EXPECT_NO_FATAL_FAILURE(ExpectMatchSoftBusLogAttrs(DISC_LABELS[++index], DISC_COAP, ++discDomainBase, "DiscCoap")); 51 EXPECT_NO_FATAL_FAILURE(ExpectMatchSoftBusLogAttrs(DISC_LABELS[++index], 52 DISC_DFINDER, ++discDomainBase, "DiscDfinder")); 53 EXPECT_NO_FATAL_FAILURE(ExpectMatchSoftBusLogAttrs(DISC_LABELS[++index], 54 DISC_ABILITY, ++discDomainBase, "DiscAbility")); 55 EXPECT_NO_FATAL_FAILURE(ExpectMatchSoftBusLogAttrs(DISC_LABELS[++index], DISC_USB, ++discDomainBase, "DiscUsb")); 56 EXPECT_NO_FATAL_FAILURE(ExpectMatchSoftBusLogAttrs(DISC_LABELS[++index], 57 DISC_USB_ADAPTER, ++discDomainBase, "DiscUsbAdapter")); 58 EXPECT_NO_FATAL_FAILURE(ExpectMatchSoftBusLogAttrs(DISC_LABELS[++index], DISC_SDK, ++discDomainBase, "DiscSdk")); 59 EXPECT_NO_FATAL_FAILURE(ExpectMatchSoftBusLogAttrs(DISC_LABELS[++index], 60 DISC_BROADCAST, ++discDomainBase, "DiscBroadcast")); 61 EXPECT_NO_FATAL_FAILURE(ExpectMatchSoftBusLogAttrs(DISC_LABELS[++index], 62 DISC_ACTION, ++discDomainBase, "DiscAction")); 63 EXPECT_NO_FATAL_FAILURE(ExpectMatchSoftBusLogAttrs(DISC_LABELS[++index], 64 DISC_EVENT, ++discDomainBase, "DiscEvent")); 65 EXPECT_NO_FATAL_FAILURE(ExpectMatchSoftBusLogAttrs(DISC_LABELS[++index], 66 DISC_VIRLINK, ++discDomainBase, "DiscVirlink")); 67 EXPECT_NO_FATAL_FAILURE(ExpectMatchSoftBusLogAttrs(DISC_LABELS[++index], DISC_TEST, DOMAIN_ID_TEST, "DiscTest")); 68 } 69 70 /** 71 * @tc.name: DiscLogTest002 72 * @tc.desc: Test DISC_LOGD 73 * @tc.type: FUNC 74 * @tc.require: I8DW1W 75 */ 76 HWTEST_F(DiscLogTest, DiscLogTest002, TestSize.Level0) 77 { 78 SoftBusLogLabel label = DISC_LABELS[DISC_INIT]; 79 HilogMock mock; 80 EXPECT_CALL(mock, HiLogPrint(Eq(LOG_CORE), Eq(LOG_DEBUG), Eq(label.domain), StrEq(label.tag), _, _)) 81 .Times(1); 82 DISC_LOGD(DISC_INIT, "test log"); 83 } 84 85 /** 86 * @tc.name: DiscLogTest003 87 * @tc.desc: Test DISC_LOGI 88 * @tc.type: FUNC 89 * @tc.require: I8DW1W 90 */ 91 HWTEST_F(DiscLogTest, DiscLogTest003, TestSize.Level0) 92 { 93 SoftBusLogLabel label = DISC_LABELS[DISC_INIT]; 94 HilogMock mock; 95 EXPECT_CALL(mock, HiLogPrint(Eq(LOG_CORE), Eq(LOG_INFO), Eq(label.domain), StrEq(label.tag), _, _)) 96 .Times(1); 97 DISC_LOGI(DISC_INIT, "test log"); 98 } 99 100 /** 101 * @tc.name: DiscLogTest004 102 * @tc.desc: Test DISC_LOGW 103 * @tc.type: FUNC 104 * @tc.require: I8DW1W 105 */ 106 HWTEST_F(DiscLogTest, DiscLogTest004, TestSize.Level0) 107 { 108 SoftBusLogLabel label = DISC_LABELS[DISC_INIT]; 109 HilogMock mock; 110 EXPECT_CALL(mock, HiLogPrint(Eq(LOG_CORE), Eq(LOG_WARN), Eq(label.domain), StrEq(label.tag), _, _)) 111 .Times(1); 112 DISC_LOGW(DISC_INIT, "test log"); 113 } 114 115 /** 116 * @tc.name: DiscLogTest005 117 * @tc.desc: Test DISC_LOGE 118 * @tc.type: FUNC 119 * @tc.require: I8DW1W 120 */ 121 HWTEST_F(DiscLogTest, DiscLogTest005, TestSize.Level0) 122 { 123 SoftBusLogLabel label = DISC_LABELS[DISC_INIT]; 124 HilogMock mock; 125 EXPECT_CALL(mock, HiLogPrint(Eq(LOG_CORE), Eq(LOG_ERROR), Eq(label.domain), StrEq(label.tag), _, _)) 126 .Times(1); 127 DISC_LOGE(DISC_INIT, "test log"); 128 } 129 130 /** 131 * @tc.name: DiscLogTest006 132 * @tc.desc: Test DISC_LOGF 133 * @tc.type: FUNC 134 * @tc.require: I8DW1W 135 */ 136 HWTEST_F(DiscLogTest, DiscLogTest006, TestSize.Level0) 137 { 138 SoftBusLogLabel label = DISC_LABELS[DISC_INIT]; 139 HilogMock mock; 140 EXPECT_CALL(mock, HiLogPrint(Eq(LOG_CORE), Eq(LOG_FATAL), Eq(label.domain), StrEq(label.tag), _, _)) 141 .Times(1); 142 DISC_LOGF(DISC_INIT, "test log"); 143 } 144 } // namespace OHOS 145