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 #include <gmock/gmock.h>
16 #include <gtest/gtest.h>
17
18 #include "cloud_file_utils.h"
19
20 namespace OHOS::FileManagement::CloudDisk::Test {
21 using namespace std;
22 using namespace OHOS;
23 using namespace testing::ext;
24
25 class CloudFileUtilsTest : public testing::Test {
26 public:
27 static void SetUpTestCase(void);
28 static void TearDownTestCase(void);
29 void SetUp();
30 void TearDown();
31 };
32
SetUpTestCase(void)33 void CloudFileUtilsTest::SetUpTestCase(void) {}
34
TearDownTestCase(void)35 void CloudFileUtilsTest::TearDownTestCase(void) {}
36
SetUp(void)37 void CloudFileUtilsTest::SetUp(void) {}
38
TearDown(void)39 void CloudFileUtilsTest::TearDown(void) {}
40
41 /**
42 * @tc.name: DfsService_CloudDisk_GetCloudId_001
43 * @tc.desc: Verify the sub function.
44 * @tc.type: FUNC
45 * @tc.require: issueNumber
46 */
47 HWTEST_F(CloudFileUtilsTest, DfsService_CloudDisk_GetCloudId_001, TestSize.Level1)
48 {
49 string cloudId = CloudFileUtils::GetCloudId("");
50 EXPECT_EQ((cloudId == ""), true);
51
52 cloudId = CloudFileUtils::GetCloudId("test");
53 EXPECT_EQ((cloudId == ""), true);
54 }
55
56 HWTEST_F(CloudFileUtilsTest, DfsService_CloudDisk_GetLocalBucketPath_002, TestSize.Level1)
57 {
58 string cloudId;
59 string bundleName;
60 int32_t userId = -1;
61 string bucketPath = CloudFileUtils::GetLocalBucketPath(cloudId, bundleName, userId);
62 EXPECT_EQ((cloudId == ""), true);
63 }
64
65 HWTEST_F(CloudFileUtilsTest, DfsService_CloudDisk_GetLocalBucketPath_003, TestSize.Level1)
66 {
67 string cloudId = "testId";
68 string bundleName = "testBundleName";
69 int32_t userId = -1;
70 string bucketPath = CloudFileUtils::GetLocalBucketPath(cloudId, bundleName, userId);
71 EXPECT_EQ((cloudId == ""), false);
72 }
73
74 HWTEST_F(CloudFileUtilsTest, DfsService_CloudDisk_CheckIsCloud_004, TestSize.Level1)
75 {
76 string key;
77 EXPECT_EQ(CloudFileUtils::CheckIsCloud(key), false);
78
79 key = CLOUD_CLOUD_ID_XATTR;
80 EXPECT_EQ(CloudFileUtils::CheckIsCloud(key), true);
81 }
82
83 HWTEST_F(CloudFileUtilsTest, DfsService_CloudDisk_CheckIsCloudLocation_005, TestSize.Level1)
84 {
85 string key;
86 EXPECT_EQ(CloudFileUtils::CheckIsCloudLocation(key), false);
87
88 key = CLOUD_FILE_LOCATION;
89 EXPECT_EQ(CloudFileUtils::CheckIsCloudLocation(key), true);
90 }
91
92 HWTEST_F(CloudFileUtilsTest, DfsService_CloudDisk_CheckIsHmdfsPermission_006, TestSize.Level1)
93 {
94 string key;
95 EXPECT_EQ(CloudFileUtils::CheckIsHmdfsPermission(key), false);
96
97 key = HMDFS_PERMISSION_XATTR;
98 EXPECT_EQ(CloudFileUtils::CheckIsHmdfsPermission(key), true);
99 }
100
101 HWTEST_F(CloudFileUtilsTest, DfsService_CloudDisk_GetLocalFilePath_007, TestSize.Level1)
102 {
103 string cloudId;
104 string bundleName;
105 int32_t userId = 0;
106 string ret = CloudFileUtils::GetLocalFilePath(cloudId, bundleName, userId);
107 EXPECT_EQ((ret == ""), false);
108
109 userId = -1;
110 ret = CloudFileUtils::GetLocalFilePath(cloudId, bundleName, userId);
111 EXPECT_EQ((ret == ""), false);
112 }
113
114 HWTEST_F(CloudFileUtilsTest, DfsService_CloudDisk_GetPathWithoutTmp_008, TestSize.Level1)
115 {
116 string path;
117 string ret = CloudFileUtils::GetPathWithoutTmp(path);
118 EXPECT_EQ(ret, path);
119
120 path = "path/test";
121 ret = CloudFileUtils::GetPathWithoutTmp(path);
122 EXPECT_EQ(ret, path);
123 }
124
125 HWTEST_F(CloudFileUtilsTest, DfsService_CloudDisk_LocalWriteOpen_009, TestSize.Level1)
126 {
127 string dfsPath;
128 EXPECT_EQ(CloudFileUtils::LocalWriteOpen(dfsPath), false);
129
130 dfsPath = "testPath";
131 EXPECT_EQ(CloudFileUtils::LocalWriteOpen(dfsPath), false);
132 }
133
134 HWTEST_F(CloudFileUtilsTest, DfsService_CloudDisk_EndsWith_010, TestSize.Level1)
135 {
136 string fullString;
137 string ending;
138 EXPECT_EQ(CloudFileUtils::EndsWith(fullString, ending), true);
139
140 fullString = "testPath";
141 EXPECT_EQ(CloudFileUtils::EndsWith(fullString, ending), true);
142 }
143
144 HWTEST_F(CloudFileUtilsTest, DfsService_CloudDisk_EndsWith_011, TestSize.Level1)
145 {
146 string fullString = "testPath";
147 string ending = "test@@text##";
148 EXPECT_EQ(CloudFileUtils::EndsWith(fullString, ending), false);
149 }
150
151 HWTEST_F(CloudFileUtilsTest, DfsService_CloudDisk_DentryHash_012, TestSize.Level1)
152 {
153 try {
154 string inputStr = ".";
155 EXPECT_EQ(CloudFileUtils::DentryHash(inputStr), 0);
156
157 inputStr = "..";
158 EXPECT_EQ(CloudFileUtils::DentryHash(inputStr), 0);
159 } catch (...) {
160 EXPECT_FALSE(false);
161 GTEST_LOG_(INFO) << " DfsService_CloudDisk_DentryHash_012 ERROR";
162 }
163 }
164
165 HWTEST_F(CloudFileUtilsTest, DfsService_CloudDisk_LocalWriteOpen_013, TestSize.Level1)
166 {
167 string dfsPath = "./";
168 EXPECT_EQ(CloudFileUtils::LocalWriteOpen(dfsPath), false);
169
170 dfsPath = "testPath";
171 EXPECT_EQ(CloudFileUtils::LocalWriteOpen(dfsPath), false);
172 }
173
174 HWTEST_F(CloudFileUtilsTest, DfsService_CloudDisk_GetCloudId_014, TestSize.Level1)
175 {
176 string dfsPath = "/data/service/el1/public/cloudfile";
177 string cloudId = CloudFileUtils::GetCloudId(dfsPath);
178 EXPECT_EQ((cloudId == ""), true);
179
180 dfsPath = "/data/service/el1/public/cloudfile/cloud_data_statistic";
181 cloudId = CloudFileUtils::GetCloudId(dfsPath);
182 EXPECT_EQ((cloudId == ""), true);
183 }
184 } // OHOS