1 /*
2 * Copyright (c) 2023 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 <gmock/gmock.h>
17 #include <gtest/gtest.h>
18 #include <sstream>
19 #include <sys/mount.h>
20
21 #include "dfsu_mount_argument_descriptors.h"
22
23 namespace OHOS::Storage::DistributedFile::Utils::Test {
24 using namespace testing;
25 using namespace testing::ext;
26 using namespace std;
27 class MountArgumentTest : public testing::Test {
28 public:
29 static void SetUpTestCase(void);
30 static void TearDownTestCase(void);
31 void SetUp();
32 void TearDown();
33 shared_ptr<MountArgument> mountArgument_ = nullptr;
34 };
35
SetUpTestCase(void)36 void MountArgumentTest::SetUpTestCase(void)
37 {
38 GTEST_LOG_(INFO) << "SetUpTestCase";
39 }
40
TearDownTestCase(void)41 void MountArgumentTest::TearDownTestCase(void)
42 {
43 GTEST_LOG_(INFO) << "TearDownTestCase";
44 }
45
SetUp(void)46 void MountArgumentTest::SetUp(void)
47 {
48 mountArgument_ = make_shared<MountArgument>();
49 GTEST_LOG_(INFO) << "SetUp";
50 }
51
TearDown(void)52 void MountArgumentTest::TearDown(void)
53 {
54 mountArgument_ = nullptr;
55 GTEST_LOG_(INFO) << "TearDown";
56 }
57
58 /**
59 * @tc.name: GetFullSrcTest
60 * @tc.desc: Verify the GetFullSrc function
61 * @tc.type: FUNC
62 * @tc.require: I6JPKG
63 */
64 HWTEST_F(MountArgumentTest, GetFullSrcTest, TestSize.Level1)
65 {
66 GTEST_LOG_(INFO) << "GetFullSrcTest Begin";
67 try {
68 std::string out = "/data/service/el2/0/hmdfs/";
69 std::string ret = mountArgument_->GetFullSrc();
70 EXPECT_STREQ(ret.c_str(), out.c_str());
71 } catch (...) {
72 EXPECT_TRUE(false);
73 GTEST_LOG_(INFO) << "GetFullSrcTest ERROR";
74 }
75 GTEST_LOG_(INFO) << "GetFullSrcTest End";
76 }
77
78 /**
79 * @tc.name: GetFullDstTest
80 * @tc.desc: Verify the GetFullDst function
81 * @tc.type: FUNC
82 * @tc.require: I6JPKG
83 */
84 HWTEST_F(MountArgumentTest, GetFullDstTest, TestSize.Level1)
85 {
86 GTEST_LOG_(INFO) << "GetFullDstTest Begin";
87 try {
88 std::string out = "/mnt/hmdfs/0/";
89 std::string ret = mountArgument_->GetFullDst();
90 EXPECT_STREQ(ret.c_str(), out.c_str());
91 } catch (...) {
92 EXPECT_TRUE(false);
93 GTEST_LOG_(INFO) << "GetFullDstTest ERROR";
94 }
95 GTEST_LOG_(INFO) << "GetFullDstTest End";
96 }
97
98 /**
99 * @tc.name: GetCachePathTest
100 * @tc.desc: Verify the GetCachePath function
101 * @tc.type: FUNC
102 * @tc.require: I6JPKG
103 */
104 HWTEST_F(MountArgumentTest, GetCachePathTest, TestSize.Level1)
105 {
106 GTEST_LOG_(INFO) << "GetCachePathTest Begin";
107 try {
108 std::string out = "/data/service/el2/0/hmdfs//cache/";
109 std::string ret = mountArgument_->GetCachePath();
110 EXPECT_STREQ(ret.c_str(), out.c_str());
111 } catch (...) {
112 EXPECT_TRUE(false);
113 GTEST_LOG_(INFO) << "GetCachePathTest ERROR";
114 }
115 GTEST_LOG_(INFO) << "GetCachePathTest End";
116 }
117
118 /**
119 * @tc.name: GetCtrlPathTest
120 * @tc.desc: Verify the GetCtrlPath function
121 * @tc.type: FUNC
122 * @tc.require: I6JPKG
123 */
124 HWTEST_F(MountArgumentTest, GetCtrlPathTest, TestSize.Level1)
125 {
126 GTEST_LOG_(INFO) << "GetCtrlPathTest Begin";
127 try {
128 std::string out = "/sys/fs/hmdfs/2989455826978503469/cmd";
129 std::string ret = mountArgument_->GetCtrlPath();
130 EXPECT_STREQ(ret.c_str(), out.c_str());
131 } catch (...) {
132 EXPECT_TRUE(false);
133 GTEST_LOG_(INFO) << "GetCtrlPathTest ERROR";
134 }
135 GTEST_LOG_(INFO) << "GetCtrlPathTest End";
136 }
137
138 /**
139 * @tc.name: OptionsToStringTest001
140 * @tc.desc: Verify the OptionsToString function
141 * @tc.type: FUNC
142 * @tc.require: I6JPKG
143 */
144 HWTEST_F(MountArgumentTest, OptionsToStringTest001, TestSize.Level1)
145 {
146 GTEST_LOG_(INFO) << "OptionsToStringTest001 Begin";
147 try {
148 std::string out = "local_dst=/mnt/hmdfs/0/";
149 std::string ret = mountArgument_->OptionsToString();
150 EXPECT_STREQ(ret.c_str(), out.c_str());
151 } catch (...) {
152 EXPECT_TRUE(false);
153 GTEST_LOG_(INFO) << "OptionsToStringTest001 ERROR";
154 }
155 GTEST_LOG_(INFO) << "OptionsToStringTest001 End";
156 }
157
158 /**
159 * @tc.name: OptionsToStringTest002
160 * @tc.desc: Verify the OptionsToString function
161 * @tc.type: FUNC
162 * @tc.require: I6JPKG
163 */
164 HWTEST_F(MountArgumentTest, OptionsToStringTest002, TestSize.Level1)
165 {
166 GTEST_LOG_(INFO) << "OptionsToStringTest002 Begin";
167 try {
168 std::string out = "local_dst=/mnt/hmdfs/0/,cache_dir=/data/service/el2/0/hmdfs//cache/";
169 mountArgument_->useCache_ = true;
170 std::string ret = mountArgument_->OptionsToString();
171 EXPECT_STREQ(ret.c_str(), out.c_str());
172 } catch (...) {
173 EXPECT_TRUE(false);
174 GTEST_LOG_(INFO) << "OptionsToStringTest002 ERROR";
175 }
176 GTEST_LOG_(INFO) << "OptionsToStringTest002 End";
177 }
178
179 /**
180 * @tc.name: OptionsToStringTest003
181 * @tc.desc: Verify the OptionsToString function
182 * @tc.type: FUNC
183 * @tc.require: I6JPKG
184 */
185 HWTEST_F(MountArgumentTest, OptionsToStringTest003, TestSize.Level1)
186 {
187 GTEST_LOG_(INFO) << "OptionsToStringTest003 Begin";
188 try {
189 std::string out = "local_dst=/mnt/hmdfs/0/,sensitive";
190 mountArgument_->caseSensitive_ = true;
191 std::string ret = mountArgument_->OptionsToString();
192 EXPECT_STREQ(ret.c_str(), out.c_str());
193 } catch (...) {
194 EXPECT_TRUE(false);
195 GTEST_LOG_(INFO) << "OptionsToStringTest003 ERROR";
196 }
197 GTEST_LOG_(INFO) << "OptionsToStringTest003 End";
198 }
199
200 /**
201 * @tc.name: OptionsToStringTest004
202 * @tc.desc: Verify the OptionsToString function
203 * @tc.type: FUNC
204 * @tc.require: I6JPKG
205 */
206 HWTEST_F(MountArgumentTest, OptionsToStringTest004, TestSize.Level1)
207 {
208 GTEST_LOG_(INFO) << "OptionsToStringTest004 Begin";
209 try {
210 std::string out = "local_dst=/mnt/hmdfs/0/,merge";
211 mountArgument_->enableMergeView_ = true;
212 std::string ret = mountArgument_->OptionsToString();
213 EXPECT_STREQ(ret.c_str(), out.c_str());
214 } catch (...) {
215 EXPECT_TRUE(false);
216 GTEST_LOG_(INFO) << "OptionsToStringTest004 ERROR";
217 }
218 GTEST_LOG_(INFO) << "OptionsToStringTest004 End";
219 }
220
221 /**
222 * @tc.name: OptionsToStringTest005
223 * @tc.desc: Verify the OptionsToString function
224 * @tc.type: FUNC
225 * @tc.require: I6JPKG
226 */
227 HWTEST_F(MountArgumentTest, OptionsToStringTest005, TestSize.Level1)
228 {
229 GTEST_LOG_(INFO) << "OptionsToStringTest005 Begin";
230 try {
231 std::string out = "local_dst=/mnt/hmdfs/0/,fixupownership";
232 mountArgument_->enableFixupOwnerShip_ = true;
233 std::string ret = mountArgument_->OptionsToString();
234 EXPECT_STREQ(ret.c_str(), out.c_str());
235 } catch (...) {
236 EXPECT_TRUE(false);
237 GTEST_LOG_(INFO) << "OptionsToStringTest005 ERROR";
238 }
239 GTEST_LOG_(INFO) << "OptionsToStringTest005 End";
240 }
241
242 /**
243 * @tc.name: OptionsToStringTest006
244 * @tc.desc: Verify the OptionsToString function
245 * @tc.type: FUNC
246 * @tc.require: I6JPKG
247 */
248 HWTEST_F(MountArgumentTest, OptionsToStringTest006, TestSize.Level1)
249 {
250 GTEST_LOG_(INFO) << "OptionsToStringTest006 Begin";
251 try {
252 std::string out = "local_dst=/mnt/hmdfs/0/,no_offline_stash";
253 mountArgument_->enableOfflineStash_ = false;
254 std::string ret = mountArgument_->OptionsToString();
255 EXPECT_STREQ(ret.c_str(), out.c_str());
256 } catch (...) {
257 EXPECT_TRUE(false);
258 GTEST_LOG_(INFO) << "OptionsToStringTest006 ERROR";
259 }
260 GTEST_LOG_(INFO) << "OptionsToStringTest006 End";
261 }
262
263 /**
264 * @tc.name: OptionsToStringTest007
265 * @tc.desc: Verify the OptionsToString function
266 * @tc.type: FUNC
267 * @tc.require: I6JPKG
268 */
269 HWTEST_F(MountArgumentTest, OptionsToStringTest007, TestSize.Level1)
270 {
271 GTEST_LOG_(INFO) << "OptionsToStringTest006 Begin";
272 try {
273 std::string out = "local_dst=/mnt/hmdfs/0/,external_fs";
274 mountArgument_->externalFS_ = true;
275 std::string ret = mountArgument_->OptionsToString();
276 EXPECT_STREQ(ret.c_str(), out.c_str());
277 } catch (...) {
278 EXPECT_TRUE(false);
279 GTEST_LOG_(INFO) << "OptionsToStringTest007 ERROR";
280 }
281 GTEST_LOG_(INFO) << "OptionsToStringTest007 End";
282 }
283
284 /**
285 * @tc.name: GetFlagsTest
286 * @tc.desc: Verify the GetFlags function
287 * @tc.type: FUNC
288 * @tc.require: I6JPKG
289 */
290 HWTEST_F(MountArgumentTest, GetFlagsTest, TestSize.Level1)
291 {
292 GTEST_LOG_(INFO) << "GetFlagsTest Begin";
293 try {
294 auto ret = mountArgument_->GetFlags();
295 EXPECT_EQ(ret, MS_NODEV);
296 } catch (...) {
297 EXPECT_TRUE(false);
298 GTEST_LOG_(INFO) << "GetFlagsTest ERROR";
299 }
300 GTEST_LOG_(INFO) << "GetFlagsTest End";
301 }
302 } // namespace OHOS::Storage::DistributedFile::Utils::Test
303