• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 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 <string>
17 #include <gtest/gtest.h>
18 
19 #include "softbus_adapter_mem.h"
20 #include "softbus_log.h"
21 
22 using namespace std;
23 using namespace testing::ext;
24 
25 namespace OHOS {
26 const char *g_originPacket = "\"DEVICE_ID\":\"18f3b221c8661b51eaf6520c223f48afe211111113ab9c6a4f03b7c719eb60d1\"";
27 const char *g_anonymizedPacket = "\"DEVICE_ID\":\"18f3******60d1\"";
28 const char *g_shortPacket = "\"DEVICE_ID\":\"18f3b221c8661b5111111111111111b7c719eb60d1\"";
29 const char *g_testSessionName = "test.ohos.abc60272D6C226F0E08021F07AAAAAAAAAABBBBBBBB9A0111111111169A5342784D2EB\
30 123456789ABCCCCCCCCCCCCCD57A4Cam_Cam123";
31 const char *g_testAnonySessionName = "test.ohos.abc6027******57A4Cam_Cam123";
32 
33 class AnonymizePacketTest : public testing::Test {
34 public:
35     static void SetUpTestCase();
36     static void TearDownTestCase();
37     void SetUp();
38     void TearDown();
39 };
40 
SetUpTestCase(void)41 void AnonymizePacketTest::SetUpTestCase(void) {}
42 
TearDownTestCase(void)43 void AnonymizePacketTest::TearDownTestCase(void) {}
44 
SetUp(void)45 void AnonymizePacketTest::SetUp(void) {}
46 
TearDown(void)47 void AnonymizePacketTest::TearDown(void) {}
48 
49 /**
50  * @tc.name: AnonymizePacketNormalTest001
51  * @tc.desc: Verify AnonymizePacket function, use the normal parameter.
52  * @tc.type: FUNC
53  * @tc.require:
54  */
55 HWTEST_F(AnonymizePacketTest, AnonymizePacketNormalTest001, TestSize.Level0)
56 {
57     AnonyPacketPrintout(SOFTBUS_LOG_COMM, "AnonymizePacketNormalTest001: ", g_originPacket, strlen(g_originPacket));
58 }
59 
60 /**
61  * @tc.name: AnonymizePacketNormalTest002
62  * @tc.desc: Verify AnonymizePacket function, use the normal parameter.
63  * @tc.type: FUNC
64  * @tc.require:
65  */
66 HWTEST_F(AnonymizePacketTest, AnonymizePacketNormalTest002, TestSize.Level0)
67 {
68     AnonyPacketPrintout(SOFTBUS_LOG_COMM, "AnonymizePacketNormalTest002: ", g_shortPacket, strlen(g_shortPacket));
69 }
70 
71 /**
72  * @tc.name: AnonymizePacketWrongTest001
73  * @tc.desc: Verify AnonymizePacket function, use the wrong parameter.
74  * @tc.type: FUNC
75  * @tc.require:
76  */
77 HWTEST_F(AnonymizePacketTest, AnonymizePacketWrongTest001, TestSize.Level0)
78 {
79     AnonyPacketPrintout(SOFTBUS_LOG_COMM, "AnonymizePacketWrongTest001: ", NULL, strlen(g_originPacket));
80 }
81 
82 /**
83  * @tc.name: AnonySessionNameNormalTest001
84  * @tc.desc: Verify AnonyDevId function, use the normal parameter.
85  * @tc.type: FUNC
86  * @tc.require:
87  */
88 HWTEST_F(AnonymizePacketTest, AnonySessionNameNormalTest001, TestSize.Level0)
89 {
90     char *anonymizedOut = nullptr;
91     const char *res = AnonyDevId(&anonymizedOut, g_testSessionName);
92     EXPECT_STREQ(g_testAnonySessionName, res);
93 
94     SoftBusFree(anonymizedOut);
95 }
96 }; // namespace OHOS
97