• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <cstdio>
17 #include <gtest/gtest.h>
18 
19 #include "b_anony/b_anony.h"
20 
21 namespace OHOS::FileManagement::Backup {
22 class BAnonyTest : public testing::Test {
23 public:
SetUpTestCase(void)24     static void SetUpTestCase(void) {};
TearDownTestCase()25     static void TearDownTestCase() {};
SetUp()26     void SetUp() {};
TearDown()27     void TearDown() {};
28 };
29 
30 /**
31  * @tc.number: SUB_backup_b_anony_GetAnonyPath_0100
32  * @tc.name: b_anony_GetAnonyPath_0100
33  * @tc.desc: Test function of GetAnonyPath interface for SUCCESS.
34  * @tc.size: MEDIUM
35  * @tc.type: FUNC
36  * @tc.level Level 0
37  * @tc.require: I6F3GV
38  */
39 HWTEST_F(BAnonyTest, b_anony_GetAnonyPath_0100, testing::ext::TestSize.Level1)
40 {
41     GTEST_LOG_(INFO) << "BAnonyTest-begin b_anony_GetAnonyPath_0100";
42     try {
43         std::string path = "/";
44         std::string result = "/";
45         EXPECT_EQ(GetAnonyPath(path), result);
46         path = "//";
47         result = "//";
48         EXPECT_EQ(GetAnonyPath(path), result);
49         path = "test.txt";
50         result = "t******t.txt";
51         EXPECT_EQ(GetAnonyPath(path), result);
52         path = "/test.txt";
53         result = "/t******t.txt";
54         EXPECT_EQ(GetAnonyPath(path), result);
55         path = "/*/*/shfkwam/xxf/x/xdf.db.xxx.xx";
56         result = "/******/******/s******m/x******f/******/x******f.db.xxx.xx";
57         EXPECT_EQ(GetAnonyPath(path), result);
58         path = "/euxnems/ioio...xxx/sk.ppt";
59         result = "/e******s/i******x/******.ppt";
60         EXPECT_EQ(GetAnonyPath(path), result);
61         path = "/....../......";
62         result = "/.******./******......";
63         EXPECT_EQ(GetAnonyPath(path), result);
64         path = "downloads/../&^%&*#/IMGS.tar.lz4";
65         result = "d******s/******/&******#/I******S.tar.lz4";
66         EXPECT_EQ(GetAnonyPath(path), result);
67     } catch (...) {
68         EXPECT_TRUE(false);
69         GTEST_LOG_(INFO) << "BAnonyTest-an exception occurred by construction.";
70     }
71     GTEST_LOG_(INFO) << "BAnonyTest-end b_error_GetAnonyPath_0100";
72 }
73 }