• 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 "hilog_mock.h"
22 #include "trans_log.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 TransLogTest : public testing::Test { };
31 
32 /**
33  * @tc.name: TransLogTest001
34  * @tc.desc: Test TRANS_LOGD
35  * @tc.type: FUNC
36  * @tc.require: I8DW1W
37  */
38 HWTEST_F(TransLogTest, TransLogTest001, TestSize.Level0)
39 {
40     int32_t index = 0;
41     int32_t transDomainBase = 0xd005740;
42 
43     ExpectMatchSoftBusLogAttrs(TRANS_LABELS[index], TRANS_SDK, transDomainBase, "TransSdk");
44     ExpectMatchSoftBusLogAttrs(TRANS_LABELS[++index], TRANS_SVC, ++transDomainBase, "TransSvc");
45     ExpectMatchSoftBusLogAttrs(TRANS_LABELS[++index], TRANS_INIT, ++transDomainBase, "TransInit");
46     ExpectMatchSoftBusLogAttrs(TRANS_LABELS[++index], TRANS_CTRL, ++transDomainBase, "TransCtrl");
47     ExpectMatchSoftBusLogAttrs(TRANS_LABELS[++index], TRANS_BYTES, ++transDomainBase, "TransBytes");
48     ExpectMatchSoftBusLogAttrs(TRANS_LABELS[++index], TRANS_FILE, ++transDomainBase, "TransFile");
49     ExpectMatchSoftBusLogAttrs(TRANS_LABELS[++index], TRANS_MSG, ++transDomainBase, "TransMsg");
50     ExpectMatchSoftBusLogAttrs(TRANS_LABELS[++index], TRANS_STREAM, ++transDomainBase, "TransStream");
51     ExpectMatchSoftBusLogAttrs(TRANS_LABELS[++index], TRANS_QOS, ++transDomainBase, "TransQos");
52     ExpectMatchSoftBusLogAttrs(TRANS_LABELS[++index], TRANS_EVENT, ++transDomainBase, "TransEvent");
53     ExpectMatchSoftBusLogAttrs(TRANS_LABELS[++index], TRANS_TEST, DOMAIN_ID_TEST, "TransTest");
54     SoftBusLogLabel label = TRANS_LABELS[TRANS_TEST];
55     HilogMock mock;
56     EXPECT_CALL(mock, HiLogPrint(Eq(LOG_CORE), Eq(LOG_DEBUG), Eq(label.domain), StrEq(label.tag), _, _)).Times(1);
57     TRANS_LOGD(TRANS_TEST, "test log");
58 }
59 
60 /**
61  * @tc.name: TransLogTest002
62  * @tc.desc: Test TRANS_LOGI
63  * @tc.type: FUNC
64  * @tc.require: I8DW1W
65  */
66 HWTEST_F(TransLogTest, TransLogTest002, TestSize.Level0)
67 {
68     SoftBusLogLabel label = TRANS_LABELS[TRANS_TEST];
69     HilogMock mock;
70     EXPECT_CALL(mock, HiLogPrint(Eq(LOG_CORE), Eq(LOG_INFO), Eq(label.domain), StrEq(label.tag), _, _)).Times(1);
71     TRANS_LOGI(TRANS_TEST, "test log");
72 }
73 
74 /**
75  * @tc.name: TransLogTest003
76  * @tc.desc: Test TRANS_LOGW
77  * @tc.type: FUNC
78  * @tc.require: I8DW1W
79  */
80 HWTEST_F(TransLogTest, TransLogTest003, TestSize.Level0)
81 {
82     SoftBusLogLabel label = TRANS_LABELS[TRANS_TEST];
83     HilogMock mock;
84     EXPECT_CALL(mock, HiLogPrint(Eq(LOG_CORE), Eq(LOG_WARN), Eq(label.domain), StrEq(label.tag), _, _)).Times(1);
85     TRANS_LOGW(TRANS_TEST, "test log");
86 }
87 
88 /**
89  * @tc.name: TransLogTest004
90  * @tc.desc: Test TRANS_LOGE
91  * @tc.type: FUNC
92  * @tc.require: I8DW1W
93  */
94 HWTEST_F(TransLogTest, TransLogTest004, TestSize.Level0)
95 {
96     SoftBusLogLabel label = TRANS_LABELS[TRANS_TEST];
97     HilogMock mock;
98     EXPECT_CALL(mock, HiLogPrint(Eq(LOG_CORE), Eq(LOG_ERROR), Eq(label.domain), StrEq(label.tag), _, _)).Times(1);
99     TRANS_LOGE(TRANS_TEST, "test log");
100 }
101 
102 /**
103  * @tc.name: TransLogTest005
104  * @tc.desc: Test TRANS_LOGF
105  * @tc.type: FUNC
106  * @tc.require: I8DW1W
107  */
108 HWTEST_F(TransLogTest, TransLogTest005, TestSize.Level0)
109 {
110     SoftBusLogLabel label = TRANS_LABELS[TRANS_TEST];
111     HilogMock mock;
112     EXPECT_CALL(mock, HiLogPrint(Eq(LOG_CORE), Eq(LOG_FATAL), Eq(label.domain), StrEq(label.tag), _, _)).Times(1);
113     TRANS_LOGF(TRANS_TEST, "test log");
114 }
115 } // namespace OHOS
116