• 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_TEST, DOMAIN_ID_TEST, "TransTest");
53     SoftBusLogLabel label = TRANS_LABELS[TRANS_TEST];
54     HilogMock mock;
55     EXPECT_CALL(mock, HiLogPrint(Eq(LOG_CORE), Eq(LOG_DEBUG), Eq(label.domain), StrEq(label.tag), _, _)).Times(1);
56     TRANS_LOGD(TRANS_TEST, "test log");
57 }
58 
59 /**
60  * @tc.name: TransLogTest002
61  * @tc.desc: Test TRANS_LOGI
62  * @tc.type: FUNC
63  * @tc.require: I8DW1W
64  */
65 HWTEST_F(TransLogTest, TransLogTest002, TestSize.Level0)
66 {
67     SoftBusLogLabel label = TRANS_LABELS[TRANS_TEST];
68     HilogMock mock;
69     EXPECT_CALL(mock, HiLogPrint(Eq(LOG_CORE), Eq(LOG_INFO), Eq(label.domain), StrEq(label.tag), _, _)).Times(1);
70     TRANS_LOGI(TRANS_TEST, "test log");
71 }
72 
73 /**
74  * @tc.name: TransLogTest003
75  * @tc.desc: Test TRANS_LOGW
76  * @tc.type: FUNC
77  * @tc.require: I8DW1W
78  */
79 HWTEST_F(TransLogTest, TransLogTest003, TestSize.Level0)
80 {
81     SoftBusLogLabel label = TRANS_LABELS[TRANS_TEST];
82     HilogMock mock;
83     EXPECT_CALL(mock, HiLogPrint(Eq(LOG_CORE), Eq(LOG_WARN), Eq(label.domain), StrEq(label.tag), _, _)).Times(1);
84     TRANS_LOGW(TRANS_TEST, "test log");
85 }
86 
87 /**
88  * @tc.name: TransLogTest004
89  * @tc.desc: Test TRANS_LOGE
90  * @tc.type: FUNC
91  * @tc.require: I8DW1W
92  */
93 HWTEST_F(TransLogTest, TransLogTest004, TestSize.Level0)
94 {
95     SoftBusLogLabel label = TRANS_LABELS[TRANS_TEST];
96     HilogMock mock;
97     EXPECT_CALL(mock, HiLogPrint(Eq(LOG_CORE), Eq(LOG_ERROR), Eq(label.domain), StrEq(label.tag), _, _)).Times(1);
98     TRANS_LOGE(TRANS_TEST, "test log");
99 }
100 
101 /**
102  * @tc.name: TransLogTest005
103  * @tc.desc: Test TRANS_LOGF
104  * @tc.type: FUNC
105  * @tc.require: I8DW1W
106  */
107 HWTEST_F(TransLogTest, TransLogTest005, TestSize.Level0)
108 {
109     SoftBusLogLabel label = TRANS_LABELS[TRANS_TEST];
110     HilogMock mock;
111     EXPECT_CALL(mock, HiLogPrint(Eq(LOG_CORE), Eq(LOG_FATAL), Eq(label.domain), StrEq(label.tag), _, _)).Times(1);
112     TRANS_LOGF(TRANS_TEST, "test log");
113 }
114 } // namespace OHOS
115