• 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 "auth_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 AuthLogTest : public testing::Test { };
31 
32 /**
33  * @tc.name: AuthLogTest001
34  * @tc.desc: Test SoftBusLogLabel is consistent with TransLogLabel
35  * @tc.type: FUNC
36  * @tc.require: I8DW1W
37  */
38 HWTEST_F(AuthLogTest, AuthLogTest001, TestSize.Level0)
39 {
40     int32_t index = 0;
41     int32_t authDomainBase = 0xd005720;
42 
43     EXPECT_NO_FATAL_FAILURE(ExpectMatchSoftBusLogAttrs(AUTH_LABELS[index], AUTH_INIT, authDomainBase, "AuthInit"));
44     EXPECT_NO_FATAL_FAILURE(ExpectMatchSoftBusLogAttrs(AUTH_LABELS[++index], AUTH_HICHAIN, ++authDomainBase,
45         "AuthHiChain"));
46     EXPECT_NO_FATAL_FAILURE(ExpectMatchSoftBusLogAttrs(AUTH_LABELS[++index], AUTH_CONN, ++authDomainBase, "AuthConn"));
47     EXPECT_NO_FATAL_FAILURE(ExpectMatchSoftBusLogAttrs(AUTH_LABELS[++index], AUTH_FSM, ++authDomainBase, "AuthFsm"));
48     EXPECT_NO_FATAL_FAILURE(ExpectMatchSoftBusLogAttrs(AUTH_LABELS[++index], AUTH_KEY, ++authDomainBase, "AuthKey"));
49     EXPECT_NO_FATAL_FAILURE(ExpectMatchSoftBusLogAttrs(AUTH_LABELS[++index], AUTH_TEST, DOMAIN_ID_TEST, "AuthTest"));
50 }
51 
52 /**
53  * @tc.name: AuthLogTest002
54  * @tc.desc: Test AUTH_LOGD
55  * @tc.type: FUNC
56  * @tc.require: I8DW1W
57  */
58 HWTEST_F(AuthLogTest, AuthLogTest002, TestSize.Level0)
59 {
60     SoftBusLogLabel label = AUTH_LABELS[AUTH_TEST];
61     HilogMock mock;
62     EXPECT_CALL(mock, HiLogPrint(Eq(LOG_CORE), Eq(LOG_DEBUG), Eq(label.domain), StrEq(label.tag), _, _))
63         .Times(1);
64     AUTH_LOGD(AUTH_TEST, "test log");
65 }
66 
67 /**
68  * @tc.name: AuthLogTest003
69  * @tc.desc: Test AUTH_LOGI
70  * @tc.type: FUNC
71  * @tc.require: I8DW1W
72  */
73 HWTEST_F(AuthLogTest, AuthLogTest003, TestSize.Level0)
74 {
75     SoftBusLogLabel label = AUTH_LABELS[AUTH_TEST];
76     HilogMock mock;
77     EXPECT_CALL(mock, HiLogPrint(Eq(LOG_CORE), Eq(LOG_INFO), Eq(label.domain), StrEq(label.tag), _, _))
78         .Times(1);
79     AUTH_LOGI(AUTH_TEST, "test log");
80 }
81 
82 /**
83  * @tc.name: AuthLogTest004
84  * @tc.desc: Test AUTH_LOGW
85  * @tc.type: FUNC
86  * @tc.require: I8DW1W
87  */
88 HWTEST_F(AuthLogTest, AuthLogTest004, TestSize.Level0)
89 {
90     SoftBusLogLabel label = AUTH_LABELS[AUTH_TEST];
91     HilogMock mock;
92     EXPECT_CALL(mock, HiLogPrint(Eq(LOG_CORE), Eq(LOG_WARN), Eq(label.domain), StrEq(label.tag), _, _))
93         .Times(1);
94     AUTH_LOGW(AUTH_TEST, "test log");
95 }
96 
97 /**
98  * @tc.name: AuthLogTest005
99  * @tc.desc: Test AUTH_LOGE
100  * @tc.type: FUNC
101  * @tc.require: I8DW1W
102  */
103 HWTEST_F(AuthLogTest, AuthLogTest005, TestSize.Level0)
104 {
105     SoftBusLogLabel label = AUTH_LABELS[AUTH_TEST];
106     HilogMock mock;
107     EXPECT_CALL(mock, HiLogPrint(Eq(LOG_CORE), Eq(LOG_ERROR), Eq(label.domain), StrEq(label.tag), _, _))
108         .Times(1);
109     AUTH_LOGE(AUTH_TEST, "test log");
110 }
111 
112 /**
113  * @tc.name: AuthLogTest006
114  * @tc.desc: Test AUTH_LOGF
115  * @tc.type: FUNC
116  * @tc.require: I8DW1W
117  */
118 HWTEST_F(AuthLogTest, AuthLogTest006, TestSize.Level0)
119 {
120     SoftBusLogLabel label = AUTH_LABELS[AUTH_TEST];
121     HilogMock mock;
122     EXPECT_CALL(mock, HiLogPrint(Eq(LOG_CORE), Eq(LOG_FATAL), Eq(label.domain), StrEq(label.tag), _, _))
123         .Times(1);
124     AUTH_LOGF(AUTH_TEST, "test log");
125 }
126 } // namespace OHOS
127