• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 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 <cinttypes>
17 #include <gtest/gtest.h>
18 #include "gmock/gmock.h"
19 #include <securec.h>
20 #include <sys/time.h>
21 
22 #include "auth_request.c"
23 
24 namespace OHOS {
25 using namespace testing;
26 using namespace testing::ext;
27 constexpr int32_t REQUST_ID = 1000;
28 constexpr int32_t RESULT_VAL1 = 1;
29 constexpr int32_t RESULT_VAL2 = 2;
30 
31 class AuthRequestTest : public testing::Test {
32 public:
33     static void SetUpTestCase();
34     static void TearDownTestCase();
35     void SetUp();
36     void TearDown();
37 };
38 
SetUpTestCase()39 void AuthRequestTest::SetUpTestCase()
40 {
41     GTEST_LOG_(INFO) << "AuthRequestTest start";
42     AuthCommonInit();
43 }
44 
TearDownTestCase()45 void AuthRequestTest::TearDownTestCase()
46 {
47     AuthCommonDeinit();
48     GTEST_LOG_(INFO) << "AuthRequestTest end";
49 }
50 
SetUp()51 void AuthRequestTest::SetUp() { }
52 
TearDown()53 void AuthRequestTest::TearDown() { }
54 
55 /*
56  * @tc.name:GET_AUTH_REQUEST_TEST_001
57  * @tc.desc: GetAuthRequestWaitNum test
58  * @tc.type: FUNC
59  * @tc.require:
60  */
61 HWTEST_F(AuthRequestTest, GET_AUTH_REQUEST_TEST_001, TestSize.Level1)
62 {
63     AuthRequest *request = static_cast<AuthRequest *>(SoftBusCalloc(sizeof(AuthRequest)));
64     ASSERT_TRUE(request != nullptr);
65     AuthRequest *item = static_cast<AuthRequest *>(SoftBusCalloc(sizeof(AuthRequest)));
66     if (item == nullptr) {
67         SoftBusFree(request);
68     }
69     ASSERT_TRUE(item != nullptr);
70     AuthVerifyCallback verifyCb;
71     AuthConnCallback connCb;
72     request->connCb = connCb;
73     request->verifyCb = verifyCb;
74     request->authId = 123;
75     request->type = REQUEST_TYPE_RECONNECT;
76     request->addTime = 40000;
77     request->requestId = 1;
78     request->connInfo.type = AUTH_LINK_TYPE_BLE;
79     request->node.next = NULL;
80     request->node.prev = NULL;
81     item->connCb = connCb;
82     item->verifyCb = verifyCb;
83     item->authId = 1234;
84     item->type = REQUEST_TYPE_RECONNECT;
85     item->addTime = 10;
86     item->requestId = 0;
87     item->connInfo.type = AUTH_LINK_TYPE_BLE;
88     item->node.next = NULL;
89     item->node.prev = NULL;
90     ListTailInsert(&g_authRequestList, &(*item).node);
91     ListTailInsert(&g_authRequestList, &(*request).node);
92     uint32_t ret = GetAuthRequestWaitNum((const AuthRequest *)item, &g_authRequestList);
93     ClearAuthRequest();
94     EXPECT_EQ(ret, RESULT_VAL1);
95 }
96 
97 /*
98  * @tc.name:GET_AUTH_REQUEST_TEST_002
99  * @tc.desc: GetAuthRequestWaitNum test
100  * @tc.type: FUNC
101  * @tc.require:
102  */
103 HWTEST_F(AuthRequestTest, GET_AUTH_REQUEST_TEST_002, TestSize.Level1)
104 {
105     AuthRequest *request = static_cast<AuthRequest *>(SoftBusCalloc(sizeof(AuthRequest)));
106     ASSERT_TRUE(request != nullptr);
107     AuthRequest *item = static_cast<AuthRequest *>(SoftBusCalloc(sizeof(AuthRequest)));
108     if (item == nullptr) {
109         SoftBusFree(request);
110     }
111     ASSERT_TRUE(item != nullptr);
112     AuthVerifyCallback verifyCb;
113     AuthConnCallback connCb;
114     request->connCb = connCb;
115     request->verifyCb = verifyCb;
116     request->authId = REQUST_ID;
117     request->type = REQUEST_TYPE_RECONNECT;
118     request->addTime = 3000;
119     request->requestId = 1;
120     request->connInfo.type = AUTH_LINK_TYPE_BLE;
121     request->node.next = NULL;
122     request->node.prev = NULL;
123     item->connCb = connCb;
124     item->verifyCb = verifyCb;
125     item->authId = REQUST_ID;
126     item->type = REQUEST_TYPE_RECONNECT;
127     item->addTime = 10;
128     item->requestId = 0;
129     item->connInfo.type = AUTH_LINK_TYPE_BLE;
130     item->node.next = NULL;
131     item->node.prev = NULL;
132     ListTailInsert(&g_authRequestList, &(*item).node);
133     ListTailInsert(&g_authRequestList, &(*request).node);
134     uint32_t ret = GetAuthRequestWaitNum((const AuthRequest *)request, &g_authRequestList);
135     EXPECT_EQ(ret, RESULT_VAL2);
136     ClearAuthRequest();
137 }
138 }