• 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_error_code.h"
21 #include "softbus_log.h"
22 #include "softbus_utils.h"
23 
24 using namespace std;
25 using namespace testing::ext;
26 
27 namespace OHOS {
28 class SoftBusLogTest : public testing::Test {
29 public:
30     static void SetUpTestCase();
31     static void TearDownTestCase();
32     void SetUp();
33     void TearDown();
34 };
35 
SetUpTestCase(void)36 void SoftBusLogTest::SetUpTestCase(void)
37 {
38 }
39 
TearDownTestCase(void)40 void SoftBusLogTest::TearDownTestCase(void)
41 {
42 }
43 
SetUp(void)44 void SoftBusLogTest::SetUp(void)
45 {
46 }
47 
TearDown(void)48 void SoftBusLogTest::TearDown(void)
49 {
50 }
51 
52 /**
53  * @tc.name: AnonymizesTest001
54  * @tc.desc: Anonymize.
55  * @tc.type: FUNC
56  * @tc.require: I60DWN
57  */
58 HWTEST_F(SoftBusLogTest, AnonymizesTest001, TestSize.Level1)
59 {
60     const char *target = nullptr;
61     uint8_t expectAnonymizedLength = 0;
62     const char *expected = "NULL";
63     const char *actual = Anonymizes(target, expectAnonymizedLength);
64     EXPECT_STREQ(expected, actual);
65 
66     const char *target1 = "target";
67     uint8_t expectAnonymizedLength1 = 0;
68     const char *expected1 = "BADLENGTH";
69     const char *actual1 = Anonymizes(target1, expectAnonymizedLength1);
70     EXPECT_STREQ(expected1, actual1);
71 
72     const char *target2 = "target";
73     uint8_t expectAnonymizedLength2 = 6;
74     const char *expected2 = "TOOSHORT";
75     const char *actual2 = Anonymizes(target2, expectAnonymizedLength2);
76     EXPECT_STREQ(expected2, actual2);
77 }
78 
79 /**
80  * @tc.name: AnonyDevIdTest001
81  * @tc.desc: Anonymize devid.
82  * @tc.type: FUNC
83  * @tc.require: I60DWN
84  */
85 HWTEST_F(SoftBusLogTest, AnonyDevIdTest001, TestSize.Level1)
86 {
87     char *outName = nullptr;
88     const char *inName = nullptr;
89     const char *expected = "null";
90     const char *actual = AnonyDevId(&outName, inName);
91     EXPECT_STREQ(expected, actual);
92 
93     char *outName2 = nullptr;
94     const char *inName2 = "abcdeg";
95     const char *expected2 = "abcdeg";
96     const char *actual2 = AnonyDevId(&outName2, inName2);
97     EXPECT_STREQ(expected2, actual2);
98 }
99 
100 } // namespace OHOS