1 /*
2 * Copyright (c) 2024 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 <gtest/gtest.h>
17 #include <securec.h>
18
19 #include "auth_common.h"
20 #include "auth_log.h"
21 #include "auth_normalize_request.h"
22
23 namespace OHOS {
24 using namespace testing;
25 using namespace testing::ext;
26
27 class AuthNormalizeRequestTest : public testing::Test {
28 public:
29 static void SetUpTestCase();
30 static void TearDownTestCase();
31 void SetUp();
32 void TearDown();
33 };
34
SetUpTestCase()35 void AuthNormalizeRequestTest::SetUpTestCase() { }
36
TearDownTestCase()37 void AuthNormalizeRequestTest::TearDownTestCase() { }
38
SetUp()39 void AuthNormalizeRequestTest::SetUp()
40 {
41 AUTH_LOGI(AUTH_TEST, "AuthNormalizeRequestTest start");
42 }
43
TearDown()44 void AuthNormalizeRequestTest::TearDown() { }
45
46 /*
47 * @tc.name: NOTIFY_NORMALIZE_REQUEST_SUCCESS_TEST_001
48 * @tc.desc: notify normalize request success test
49 * @tc.type: FUNC
50 * @tc.require:
51 */
52 HWTEST_F(AuthNormalizeRequestTest, NOTIFY_NORMALIZE_REQUEST_SUCCESS_TEST_001, TestSize.Level1)
53 {
54 int64_t authSeq = -1;
55 NormalizeRequest request;
56 const char *udidHash = "testudidhash";
57
58 (void)memset_s(&request, sizeof(NormalizeRequest), 0, sizeof(NormalizeRequest));
59 EXPECT_TRUE(AuthCommonInit() == SOFTBUS_OK);
60 request.authSeq = 1;
61 (void)memcpy_s(request.udidHash, SHA_256_HEX_HASH_LEN, udidHash, SHA_256_HEX_HASH_LEN);
62 uint32_t ret = AddNormalizeRequest(&request);
63 EXPECT_TRUE(ret != 0);
64 request.authSeq = 2;
65 ret = AddNormalizeRequest(&request);
66 EXPECT_TRUE(ret != 0);
67 DelAuthNormalizeRequest(request.authSeq);
68 request.authSeq = 3;
69 ret = AddNormalizeRequest(&request);
70 EXPECT_TRUE(ret != 0);
71 bool result = AuthIsRepeatedAuthRequest(request.authSeq);
72 EXPECT_TRUE(result == true);
73 NotifyNormalizeRequestSuccess(authSeq, false);
74 authSeq = 1;
75 NotifyNormalizeRequestSuccess(authSeq, false);
76 AuthCommonDeinit();
77 }
78
79 /*
80 * @tc.name: NOTIFY_NORMALIZE_REQUEST_FAIL_TEST_001
81 * @tc.desc: notify normalize request fail test
82 * @tc.type: FUNC
83 * @tc.require:
84 */
85 HWTEST_F(AuthNormalizeRequestTest, NOTIFY_NORMALIZE_REQUEST_FAIL_TEST_001, TestSize.Level1)
86 {
87 int64_t authSeq = -1;
88 NormalizeRequest request;
89 const char *udidHash = "testudidhash1";
90
91 (void)memset_s(&request, sizeof(NormalizeRequest), 0, sizeof(NormalizeRequest));
92 EXPECT_TRUE(AuthCommonInit() == SOFTBUS_OK);
93 request.authSeq = 1;
94 (void)memcpy_s(request.udidHash, SHA_256_HEX_HASH_LEN, udidHash, SHA_256_HEX_HASH_LEN);
95 uint32_t ret = AddNormalizeRequest(&request);
96 EXPECT_TRUE(ret != 0);
97 request.authSeq = 2;
98 ret = AddNormalizeRequest(&request);
99 EXPECT_TRUE(ret != 0);
100 request.authSeq = 3;
101 ret = AddNormalizeRequest(&request);
102 EXPECT_TRUE(ret != 0);
103 NotifyNormalizeRequestFail(authSeq, -1);
104 authSeq = 1;
105 NotifyNormalizeRequestFail(authSeq, -1);
106 AuthCommonDeinit();
107 }
108 } // namespace OHOS
109