• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "conn_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 ConnLogTest : public testing::Test { };
31 
32 /**
33  * @tc.name: ConnLogTest001
34  * @tc.desc: Test SoftBusLogLabel is consistent with ConnLogLabelEnum
35  * @tc.type: FUNC
36  * @tc.require: I8DW1W
37  */
38 HWTEST_F(ConnLogTest, ConnLogTest001, TestSize.Level0)
39 {
40     int32_t index = 0;
41     int32_t connDomainBase = 0xd005760;
42 
43     EXPECT_NO_FATAL_FAILURE(ExpectMatchSoftBusLogAttrs(CONN_LABELS[index], CONN_INIT, connDomainBase, "ConnInit"));
44     EXPECT_NO_FATAL_FAILURE(ExpectMatchSoftBusLogAttrs(CONN_LABELS[++index], CONN_BLE, ++connDomainBase, "ConnBle"));
45     EXPECT_NO_FATAL_FAILURE(ExpectMatchSoftBusLogAttrs(CONN_LABELS[++index], CONN_BR, ++connDomainBase, "ConnBr"));
46     EXPECT_NO_FATAL_FAILURE(ExpectMatchSoftBusLogAttrs(CONN_LABELS[++index], CONN_COMMON, ++connDomainBase,
47         "ConnCommon"));
48     EXPECT_NO_FATAL_FAILURE(ExpectMatchSoftBusLogAttrs(CONN_LABELS[++index], CONN_WIFI_DIRECT, ++connDomainBase,
49         "ConnWD"));
50     EXPECT_NO_FATAL_FAILURE(ExpectMatchSoftBusLogAttrs(CONN_LABELS[++index], CONN_NEARBY, ++connDomainBase,
51         "ConnNearby"));
52     EXPECT_NO_FATAL_FAILURE(ExpectMatchSoftBusLogAttrs(CONN_LABELS[++index], CONN_BLE_DIRECT, ++connDomainBase,
53         "ConnBD"));
54     EXPECT_NO_FATAL_FAILURE(ExpectMatchSoftBusLogAttrs(CONN_LABELS[++index], CONN_BROADCAST, ++connDomainBase,
55         "ConnBC"));
56     EXPECT_NO_FATAL_FAILURE(ExpectMatchSoftBusLogAttrs(CONN_LABELS[++index], CONN_NEWIP, ++connDomainBase,
57         "ConnNewIp"));
58     EXPECT_NO_FATAL_FAILURE(ExpectMatchSoftBusLogAttrs(CONN_LABELS[++index], CONN_ACTION, ++connDomainBase,
59         "ConnAction"));
60     EXPECT_NO_FATAL_FAILURE(ExpectMatchSoftBusLogAttrs(CONN_LABELS[++index], CONN_TEST, DOMAIN_ID_TEST, "ConnTest"));
61 }
62 
63 /**
64  * @tc.name: ConnLogTest002
65  * @tc.desc: Test CONN_LOGD
66  * @tc.type: FUNC
67  * @tc.require: I8DW1W
68  */
69 HWTEST_F(ConnLogTest, ConnLogTest002, TestSize.Level0)
70 {
71     SoftBusLogLabel label = CONN_LABELS[CONN_TEST];
72     HilogMock mock;
73     EXPECT_CALL(mock, HiLogPrint(Eq(LOG_CORE), Eq(LOG_DEBUG), Eq(label.domain), StrEq(label.tag), _, _))
74         .Times(1);
75     CONN_LOGD(CONN_TEST, "test log");
76 }
77 
78 /**
79  * @tc.name: ConnLogTest003
80  * @tc.desc: Test CONN_LOGI
81  * @tc.type: FUNC
82  * @tc.require: I8DW1W
83  */
84 HWTEST_F(ConnLogTest, ConnLogTest003, TestSize.Level0)
85 {
86     SoftBusLogLabel label = CONN_LABELS[CONN_TEST];
87     HilogMock mock;
88     EXPECT_CALL(mock, HiLogPrint(Eq(LOG_CORE), Eq(LOG_INFO), Eq(label.domain), StrEq(label.tag), _, _))
89         .Times(1);
90     CONN_LOGI(CONN_TEST, "test log");
91 }
92 
93 /**
94  * @tc.name: ConnLogTest004
95  * @tc.desc: Test CONN_LOGW
96  * @tc.type: FUNC
97  * @tc.require: I8DW1W
98  */
99 HWTEST_F(ConnLogTest, ConnLogTest004, TestSize.Level0)
100 {
101     SoftBusLogLabel label = CONN_LABELS[CONN_TEST];
102     HilogMock mock;
103     EXPECT_CALL(mock, HiLogPrint(Eq(LOG_CORE), Eq(LOG_WARN), Eq(label.domain), StrEq(label.tag), _, _))
104         .Times(1);
105     CONN_LOGW(CONN_TEST, "test log");
106 }
107 
108 /**
109  * @tc.name: ConnLogTest005
110  * @tc.desc: Test CONN_LOGE
111  * @tc.type: FUNC
112  * @tc.require: I8DW1W
113  */
114 HWTEST_F(ConnLogTest, ConnLogTest005, TestSize.Level0)
115 {
116     SoftBusLogLabel label = CONN_LABELS[CONN_TEST];
117     HilogMock mock;
118     EXPECT_CALL(mock, HiLogPrint(Eq(LOG_CORE), Eq(LOG_ERROR), Eq(label.domain), StrEq(label.tag), _, _))
119         .Times(1);
120     CONN_LOGE(CONN_TEST, "test log");
121 }
122 
123 /**
124  * @tc.name: ConnLogTest006
125  * @tc.desc: Test CONN_LOGF
126  * @tc.type: FUNC
127  * @tc.require: I8DW1W
128  */
129 HWTEST_F(ConnLogTest, ConnLogTest006, TestSize.Level0)
130 {
131     SoftBusLogLabel label = CONN_LABELS[CONN_TEST];
132     HilogMock mock;
133     EXPECT_CALL(mock, HiLogPrint(Eq(LOG_CORE), Eq(LOG_FATAL), Eq(label.domain), StrEq(label.tag), _, _))
134         .Times(1);
135     CONN_LOGF(CONN_TEST, "test log");
136 }
137 } // namespace OHOS
138