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