• 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 "comm_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 CommLogTest : public testing::Test { };
31 
32 /**
33  * @tc.name: CommLogTest001
34  * @tc.desc: Test SoftBusLogLabel is consistent with CommLogLabelEnum
35  * @tc.type: FUNC
36  * @tc.require: I8DW1W
37  */
38 HWTEST_F(CommLogTest, CommLogTest001, TestSize.Level0)
39 {
40     int32_t index = 0;
41     int32_t commDomainBase = 0xd005700;
42 
43     EXPECT_NO_FATAL_FAILURE(ExpectMatchSoftBusLogAttrs(COMM_LABELS[index], COMM_SDK, commDomainBase, "CommSdk"));
44     EXPECT_NO_FATAL_FAILURE(ExpectMatchSoftBusLogAttrs(COMM_LABELS[++index], COMM_SVC, ++commDomainBase, "CommSvc"));
45     EXPECT_NO_FATAL_FAILURE(ExpectMatchSoftBusLogAttrs(COMM_LABELS[++index], COMM_INIT, ++commDomainBase, "CommInit"));
46     EXPECT_NO_FATAL_FAILURE(ExpectMatchSoftBusLogAttrs(COMM_LABELS[++index], COMM_DFX, ++commDomainBase, "CommDfx"));
47     EXPECT_NO_FATAL_FAILURE(ExpectMatchSoftBusLogAttrs(COMM_LABELS[++index],
48         COMM_EVENT, ++commDomainBase, "CommEvent"));
49     EXPECT_NO_FATAL_FAILURE(ExpectMatchSoftBusLogAttrs(COMM_LABELS[++index],
50         COMM_VERIFY, ++commDomainBase, "CommVerify"));
51     EXPECT_NO_FATAL_FAILURE(ExpectMatchSoftBusLogAttrs(COMM_LABELS[++index], COMM_PERM, ++commDomainBase, "CommPerm"));
52     EXPECT_NO_FATAL_FAILURE(ExpectMatchSoftBusLogAttrs(COMM_LABELS[++index],
53         COMM_UTILS, ++commDomainBase, "CommUtils"));
54     EXPECT_NO_FATAL_FAILURE(ExpectMatchSoftBusLogAttrs(COMM_LABELS[++index],
55         COMM_ADAPTER, ++commDomainBase, "CommAdapter"));
56     EXPECT_NO_FATAL_FAILURE(ExpectMatchSoftBusLogAttrs(COMM_LABELS[++index], COMM_TEST, DOMAIN_ID_TEST, "CommTest"));
57 }
58 
59 /**
60  * @tc.name: CommLogTest002
61  * @tc.desc: Test COMM_LOGD
62  * @tc.type: FUNC
63  * @tc.require: I8DW1W
64  */
65 HWTEST_F(CommLogTest, CommLogTest002, TestSize.Level0)
66 {
67     SoftBusLogLabel label = COMM_LABELS[COMM_TEST];
68     HilogMock mock;
69     EXPECT_CALL(mock, HiLogPrint(Eq(LOG_CORE), Eq(LOG_DEBUG), Eq(label.domain), StrEq(label.tag), _, _)).Times(1);
70     COMM_LOGD(COMM_TEST, "test log");
71 }
72 
73 /**
74  * @tc.name: CommLogTest003
75  * @tc.desc: Test COMM_LOGI
76  * @tc.type: FUNC
77  * @tc.require: I8DW1W
78  */
79 HWTEST_F(CommLogTest, CommLogTest003, TestSize.Level0)
80 {
81     SoftBusLogLabel label = COMM_LABELS[COMM_TEST];
82     HilogMock mock;
83     EXPECT_CALL(mock, HiLogPrint(Eq(LOG_CORE), Eq(LOG_INFO), Eq(label.domain), StrEq(label.tag), _, _)).Times(1);
84     COMM_LOGI(COMM_TEST, "test log");
85 }
86 
87 /**
88  * @tc.name: CommLogTest004
89  * @tc.desc: Test COMM_LOGW
90  * @tc.type: FUNC
91  * @tc.require: I8DW1W
92  */
93 HWTEST_F(CommLogTest, CommLogTest004, TestSize.Level0)
94 {
95     SoftBusLogLabel label = COMM_LABELS[COMM_TEST];
96     HilogMock mock;
97     EXPECT_CALL(mock, HiLogPrint(Eq(LOG_CORE), Eq(LOG_WARN), Eq(label.domain), StrEq(label.tag), _, _)).Times(1);
98     COMM_LOGW(COMM_TEST, "test log");
99 }
100 
101 /**
102  * @tc.name: CommLogTest005
103  * @tc.desc: Test COMM_LOGE
104  * @tc.type: FUNC
105  * @tc.require: I8DW1W
106  */
107 HWTEST_F(CommLogTest, CommLogTest005, TestSize.Level0)
108 {
109     SoftBusLogLabel label = COMM_LABELS[COMM_TEST];
110     HilogMock mock;
111     EXPECT_CALL(mock, HiLogPrint(Eq(LOG_CORE), Eq(LOG_ERROR), Eq(label.domain), StrEq(label.tag), _, _)).Times(1);
112     COMM_LOGE(COMM_TEST, "test log");
113 }
114 
115 /**
116  * @tc.name: CommLogTest006
117  * @tc.desc: Test COMM_LOGF
118  * @tc.type: FUNC
119  * @tc.require: I8DW1W
120  */
121 HWTEST_F(CommLogTest, CommLogTest006, TestSize.Level0)
122 {
123     SoftBusLogLabel label = COMM_LABELS[COMM_TEST];
124     HilogMock mock;
125     EXPECT_CALL(mock, HiLogPrint(Eq(LOG_CORE), Eq(LOG_FATAL), Eq(label.domain), StrEq(label.tag), _, _)).Times(1);
126     COMM_LOGF(COMM_TEST, "test log");
127 }
128 } // namespace OHOS
129