• 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 "lnn_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 LnnLogTest : public testing::Test { };
31 
32 /**
33  * @tc.name: LnnLogTest001
34  * @tc.desc: Test SoftBusLogLabel is consistent with TransLogLabelEnum
35  * @tc.type: FUNC
36  * @tc.require: I8DW1W
37  */
38 HWTEST_F(LnnLogTest, LnnLogTest001, TestSize.Level0)
39 {
40     int32_t index = 0;
41     int32_t lnnDomainBase = 0xd005780;
42 
43     EXPECT_NO_FATAL_FAILURE(
44         ExpectMatchSoftBusLogAttrs(LNN_LABELS[index], LNN_INIT, lnnDomainBase, "LnnInit"));
45     EXPECT_NO_FATAL_FAILURE(
46         ExpectMatchSoftBusLogAttrs(LNN_LABELS[++index], LNN_HEART_BEAT, ++lnnDomainBase, "LnnHeartBeat"));
47     EXPECT_NO_FATAL_FAILURE(
48         ExpectMatchSoftBusLogAttrs(LNN_LABELS[++index], LNN_LEDGER, ++lnnDomainBase, "LnnLedger"));
49     EXPECT_NO_FATAL_FAILURE(
50         ExpectMatchSoftBusLogAttrs(LNN_LABELS[++index], LNN_BUILDER, ++lnnDomainBase, "LnnBuilder"));
51     EXPECT_NO_FATAL_FAILURE(
52         ExpectMatchSoftBusLogAttrs(LNN_LABELS[++index], LNN_LANE, ++lnnDomainBase, "LnnLane"));
53     EXPECT_NO_FATAL_FAILURE(
54         ExpectMatchSoftBusLogAttrs(LNN_LABELS[++index], LNN_QOS, ++lnnDomainBase, "LnnQos"));
55     EXPECT_NO_FATAL_FAILURE(
56         ExpectMatchSoftBusLogAttrs(LNN_LABELS[++index], LNN_EVENT, ++lnnDomainBase, "LnnEvent"));
57     EXPECT_NO_FATAL_FAILURE(
58         ExpectMatchSoftBusLogAttrs(LNN_LABELS[++index], LNN_STATE, ++lnnDomainBase, "LnnState"));
59     EXPECT_NO_FATAL_FAILURE(
60         ExpectMatchSoftBusLogAttrs(LNN_LABELS[++index], LNN_META_NODE, ++lnnDomainBase, "LnnMetaNode"));
61     EXPECT_NO_FATAL_FAILURE(
62         ExpectMatchSoftBusLogAttrs(LNN_LABELS[++index], LNN_CLOCK, ++lnnDomainBase, "LnnClock"));
63     EXPECT_NO_FATAL_FAILURE(
64         ExpectMatchSoftBusLogAttrs(LNN_LABELS[++index], LNN_TEST, DOMAIN_ID_TEST, "LnnTest"));
65 }
66 
67 /**
68  * @tc.name: LnnLogTest002
69  * @tc.desc: Test LNN_LOGD
70  * @tc.type: FUNC
71  * @tc.require: I8DW1W
72  */
73 HWTEST_F(LnnLogTest, LnnLogTest002, TestSize.Level0)
74 {
75     SoftBusLogLabel label = LNN_LABELS[LNN_TEST];
76     HilogMock mock;
77     EXPECT_CALL(mock, HiLogPrint(Eq(LOG_CORE), Eq(LOG_DEBUG), Eq(label.domain), StrEq(label.tag), _, _))
78         .Times(1);
79     LNN_LOGD(LNN_TEST, "test log");
80 }
81 
82 /**
83  * @tc.name: LnnLogTest003
84  * @tc.desc: Test LNN_LOGI
85  * @tc.type: FUNC
86  * @tc.require: I8DW1W
87  */
88 HWTEST_F(LnnLogTest, LnnLogTest003, TestSize.Level0)
89 {
90     SoftBusLogLabel label = LNN_LABELS[LNN_TEST];
91     HilogMock mock;
92     EXPECT_CALL(mock, HiLogPrint(Eq(LOG_CORE), Eq(LOG_INFO), Eq(label.domain), StrEq(label.tag), _, _))
93         .Times(1);
94     LNN_LOGI(LNN_TEST, "test log");
95 }
96 
97 /**
98  * @tc.name: LnnLogTest004
99  * @tc.desc: Test LNN_LOGW
100  * @tc.type: FUNC
101  * @tc.require: I8DW1W
102  */
103 HWTEST_F(LnnLogTest, LnnLogTest004, TestSize.Level0)
104 {
105     SoftBusLogLabel label = LNN_LABELS[LNN_TEST];
106     HilogMock mock;
107     EXPECT_CALL(mock, HiLogPrint(Eq(LOG_CORE), Eq(LOG_WARN), Eq(label.domain), StrEq(label.tag), _, _))
108         .Times(1);
109     LNN_LOGW(LNN_TEST, "test log");
110 }
111 
112 /**
113  * @tc.name: LnnLogTest005
114  * @tc.desc: Test LNN_LOGE
115  * @tc.type: FUNC
116  * @tc.require: I8DW1W
117  */
118 HWTEST_F(LnnLogTest, LnnLogTest005, TestSize.Level0)
119 {
120     SoftBusLogLabel label = LNN_LABELS[LNN_TEST];
121     HilogMock mock;
122     EXPECT_CALL(mock, HiLogPrint(Eq(LOG_CORE), Eq(LOG_ERROR), Eq(label.domain), StrEq(label.tag), _, _))
123         .Times(1);
124     LNN_LOGE(LNN_TEST, "test log");
125 }
126 
127 /**
128  * @tc.name: LnnLogTest006
129  * @tc.desc: Test LNN_LOGF
130  * @tc.type: FUNC
131  * @tc.require: I8DW1W
132  */
133 HWTEST_F(LnnLogTest, LnnLogTest006, TestSize.Level0)
134 {
135     SoftBusLogLabel label = LNN_LABELS[LNN_TEST];
136     HilogMock mock;
137     EXPECT_CALL(mock, HiLogPrint(Eq(LOG_CORE), Eq(LOG_FATAL), Eq(label.domain), StrEq(label.tag), _, _))
138         .Times(1);
139     LNN_LOGF(LNN_TEST, "test log");
140 }
141 } // namespace OHOS
142