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], DISC_TEST, DOMAIN_ID_TEST, "DiscTest")); 62 } 63 64 /** 65 * @tc.name: DiscLogTest002 66 * @tc.desc: Test DISC_LOGD 67 * @tc.type: FUNC 68 * @tc.require: I8DW1W 69 */ 70 HWTEST_F(DiscLogTest, DiscLogTest002, TestSize.Level0) 71 { 72 SoftBusLogLabel label = DISC_LABELS[DISC_INIT]; 73 HilogMock mock; 74 EXPECT_CALL(mock, HiLogPrint(Eq(LOG_CORE), Eq(LOG_DEBUG), Eq(label.domain), StrEq(label.tag), _, _)) 75 .Times(1); 76 DISC_LOGD(DISC_INIT, "test log"); 77 } 78 79 /** 80 * @tc.name: DiscLogTest003 81 * @tc.desc: Test DISC_LOGI 82 * @tc.type: FUNC 83 * @tc.require: I8DW1W 84 */ 85 HWTEST_F(DiscLogTest, DiscLogTest003, TestSize.Level0) 86 { 87 SoftBusLogLabel label = DISC_LABELS[DISC_INIT]; 88 HilogMock mock; 89 EXPECT_CALL(mock, HiLogPrint(Eq(LOG_CORE), Eq(LOG_INFO), Eq(label.domain), StrEq(label.tag), _, _)) 90 .Times(1); 91 DISC_LOGI(DISC_INIT, "test log"); 92 } 93 94 /** 95 * @tc.name: DiscLogTest004 96 * @tc.desc: Test DISC_LOGW 97 * @tc.type: FUNC 98 * @tc.require: I8DW1W 99 */ 100 HWTEST_F(DiscLogTest, DiscLogTest004, TestSize.Level0) 101 { 102 SoftBusLogLabel label = DISC_LABELS[DISC_INIT]; 103 HilogMock mock; 104 EXPECT_CALL(mock, HiLogPrint(Eq(LOG_CORE), Eq(LOG_WARN), Eq(label.domain), StrEq(label.tag), _, _)) 105 .Times(1); 106 DISC_LOGW(DISC_INIT, "test log"); 107 } 108 109 /** 110 * @tc.name: DiscLogTest005 111 * @tc.desc: Test DISC_LOGE 112 * @tc.type: FUNC 113 * @tc.require: I8DW1W 114 */ 115 HWTEST_F(DiscLogTest, DiscLogTest005, TestSize.Level0) 116 { 117 SoftBusLogLabel label = DISC_LABELS[DISC_INIT]; 118 HilogMock mock; 119 EXPECT_CALL(mock, HiLogPrint(Eq(LOG_CORE), Eq(LOG_ERROR), Eq(label.domain), StrEq(label.tag), _, _)) 120 .Times(1); 121 DISC_LOGE(DISC_INIT, "test log"); 122 } 123 124 /** 125 * @tc.name: DiscLogTest006 126 * @tc.desc: Test DISC_LOGF 127 * @tc.type: FUNC 128 * @tc.require: I8DW1W 129 */ 130 HWTEST_F(DiscLogTest, DiscLogTest006, TestSize.Level0) 131 { 132 SoftBusLogLabel label = DISC_LABELS[DISC_INIT]; 133 HilogMock mock; 134 EXPECT_CALL(mock, HiLogPrint(Eq(LOG_CORE), Eq(LOG_FATAL), Eq(label.domain), StrEq(label.tag), _, _)) 135 .Times(1); 136 DISC_LOGF(DISC_INIT, "test log"); 137 } 138 } // namespace OHOS 139