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 <benchmark/benchmark.h>
17 #include "directory_ex.h"
18 #include <fcntl.h>
19 #include <algorithm>
20 #include <iostream>
21 #include <fstream>
22 #include <unistd.h>
23 #include "benchmark_log.h"
24 #include "benchmark_assert.h"
25 using namespace std;
26
27 namespace OHOS {
28 namespace {
29
30 class BenchmarkDirectoryTest : public benchmark::Fixture {
31 public:
SetUp(const::benchmark::State & state)32 void SetUp(const ::benchmark::State& state) override
33 {
34 }
35
TearDown(const::benchmark::State & state)36 void TearDown(const ::benchmark::State& state) override
37 {
38 }
39
BenchmarkDirectoryTest()40 BenchmarkDirectoryTest()
41 {
42 Iterations(iterations);
43 Repetitions(repetitions);
44 ReportAggregatesOnly();
45 }
46
47 ~BenchmarkDirectoryTest() override = default;
48
49 protected:
50 const int32_t repetitions = 3;
51 const int32_t iterations = 1000;
52 };
53
54 /*
55 * @tc.name: testGetCurrentProcFullFileName001
56 * @tc.desc: get the directory of directorytest
57 */
BENCHMARK_F(BenchmarkDirectoryTest,testGetCurrentProcFullFileName001)58 BENCHMARK_F(BenchmarkDirectoryTest, testGetCurrentProcFullFileName001)(benchmark::State& state)
59 {
60 BENCHMARK_LOGD("DirectoryTest testGetCurrentProcFullFileName001 start.");
61 while (state.KeepRunning()) {
62 string strBaseName = "/data/test/DirectoryTest";
63 string strFilename = GetCurrentProcFullFileName();
64 AssertEqual(strFilename, strBaseName, "strFilename did not equal strBaseName as expected.", state);
65 }
66 BENCHMARK_LOGD("DirectoryTest testGetCurrentProcFullFileName001 end.");
67 }
68
69 /*
70 * @tc.name: testGetCurrentProcPath001
71 * @tc.desc: get the path of directorytest
72 */
BENCHMARK_F(BenchmarkDirectoryTest,testGetCurrentProcPath001)73 BENCHMARK_F(BenchmarkDirectoryTest, testGetCurrentProcPath001)(benchmark::State& state)
74 {
75 BENCHMARK_LOGD("DirectoryTest testGetCurrentProcPath001 start.");
76 while (state.KeepRunning()) {
77 string strPathName = "/data/test/";
78 string strCurPathName = GetCurrentProcPath();
79 AssertEqual(strCurPathName, strPathName, "strCurPathName did not equal strPathName as expected.", state);
80 }
81 BENCHMARK_LOGD("DirectoryTest testGetCurrentProcPath001 end.");
82 }
83
84 /*
85 * @tc.name: testExtractFilePath001
86 * @tc.desc: get the filename of the path
87 */
BENCHMARK_F(BenchmarkDirectoryTest,testExtractFilePath001)88 BENCHMARK_F(BenchmarkDirectoryTest, testExtractFilePath001)(benchmark::State& state)
89 {
90 BENCHMARK_LOGD("DirectoryTest testExtractFilePath001 start.");
91 while (state.KeepRunning()) {
92 string strFilePath = "/data/test/";
93 string strPath = ExtractFilePath(GetCurrentProcFullFileName());
94 AssertEqual(strFilePath, strPath, "strFilePath did not equal strPath as expected.", state);
95 }
96 BENCHMARK_LOGD("DirectoryTest testExtractFilePath001 end.");
97 }
98
99 /*
100 * @tc.name: testExtractFileName001
101 * @tc.desc: get the filename of the path
102 */
BENCHMARK_F(BenchmarkDirectoryTest,testExtractFileName001)103 BENCHMARK_F(BenchmarkDirectoryTest, testExtractFileName001)(benchmark::State& state)
104 {
105 BENCHMARK_LOGD("DirectoryTest testExtractFileName001 start.");
106 while (state.KeepRunning()) {
107 string strBaseName = "DirectoryTest";
108 string strName = ExtractFileName(GetCurrentProcFullFileName());
109 AssertEqual(strBaseName, strName, "strBaseName did not equal strName as expected.", state);
110 }
111 BENCHMARK_LOGD("DirectoryTest testExtractFileName001 end.");
112 }
113
114 /*
115 * @tc.name: testExtractFileExt001
116 * @tc.desc: get the filename of the path
117 */
BENCHMARK_F(BenchmarkDirectoryTest,testExtractFileExt001)118 BENCHMARK_F(BenchmarkDirectoryTest, testExtractFileExt001)(benchmark::State& state)
119 {
120 BENCHMARK_LOGD("DirectoryTest testExtractFileExt001 start.");
121 while (state.KeepRunning()) {
122 string strBaseName = "test/test.txt";
123 string strTypeName = ExtractFileExt(strBaseName);
124 AssertEqual(strTypeName, "txt", "strTypeName did not equal \"txt\" as expected.", state);
125 }
126 BENCHMARK_LOGD("DirectoryTest testExtractFileExt001 end.");
127 }
128
129 /*
130 * @tc.name: testExtractFileExt002
131 * @tc.desc: get the filename of the path and test whether the filename contains "."
132 */
BENCHMARK_F(BenchmarkDirectoryTest,testExtractFileExt002)133 BENCHMARK_F(BenchmarkDirectoryTest, testExtractFileExt002)(benchmark::State& state)
134 {
135 BENCHMARK_LOGD("DirectoryTest testExtractFileExt002 start.");
136 while (state.KeepRunning()) {
137 string strBaseName = "test/test_txt";
138 string strTypeName = ExtractFileExt(strBaseName);
139 AssertEqual(strTypeName, "", "strTypeName did not equal \"\" as expected.", state);
140 }
141 BENCHMARK_LOGD("DirectoryTest testExtractFileExt002 end.");
142 }
143
144 /*
145 * @tc.name: testExcludeTrailingPathDelimiter001
146 * @tc.desc: directory unit test
147 */
BENCHMARK_F(BenchmarkDirectoryTest,testExcludeTrailingPathDelimiter001)148 BENCHMARK_F(BenchmarkDirectoryTest, testExcludeTrailingPathDelimiter001)(benchmark::State& state)
149 {
150 BENCHMARK_LOGD("DirectoryTest testExcludeTrailingPathDelimiter001 start.");
151 while (state.KeepRunning()) {
152 string strResult = "data/test/DirectoryTest";
153 string strName = ExcludeTrailingPathDelimiter("data/test/DirectoryTest/");
154 AssertEqual(strResult, strName, "strResult did not equal strName as expected.", state);
155 }
156 BENCHMARK_LOGD("DirectoryTest testExcludeTrailingPathDelimiter001 end.");
157 }
158
159 /*
160 * @tc.name: testIncludeTrailingPathDelimiter001
161 * @tc.desc: directory unit test
162 */
BENCHMARK_F(BenchmarkDirectoryTest,testIncludeTrailingPathDelimiter001)163 BENCHMARK_F(BenchmarkDirectoryTest, testIncludeTrailingPathDelimiter001)(benchmark::State& state)
164 {
165 BENCHMARK_LOGD("DirectoryTest testIncludeTrailingPathDelimiter001 start.");
166 while (state.KeepRunning()) {
167 string strResult = "data/test/DirectoryTest/";
168 string strName = IncludeTrailingPathDelimiter("data/test/DirectoryTest");
169 AssertEqual(strResult, strName, "strResult did not equal strName as expected.", state);
170 }
171 BENCHMARK_LOGD("DirectoryTest testIncludeTrailingPathDelimiter001 end.");
172 }
173
174 /*
175 * @tc.name: testGetDirFiles001
176 * @tc.desc: directory unit test
177 */
BENCHMARK_F(BenchmarkDirectoryTest,testGetDirFiles001)178 BENCHMARK_F(BenchmarkDirectoryTest, testGetDirFiles001)(benchmark::State& state)
179 {
180 BENCHMARK_LOGD("DirectoryTest testGetDirFiles001 start.");
181 while (state.KeepRunning()) {
182 string resultfile[2] = { "/data/test/TestFile.txt", "/data/test/DirectoryTest" };
183 // prepare test data
184 ofstream file(resultfile[0], fstream::out);
185
186 string dirpath = "/data/";
187 vector<string> filenames;
188 GetDirFiles(dirpath, filenames);
189 auto pos = find(filenames.begin(), filenames.end(), resultfile[0]);
190 AssertUnequal(pos, filenames.end(), "pos was not different from filenames.end() as expected.", state);
191
192 pos = find(filenames.begin(), filenames.end(), resultfile[1]);
193 AssertUnequal(pos, filenames.end(), "pos was not different from filenames.end() as expected.", state);
194
195 // delete test data
196 RemoveFile(resultfile[0]);
197 }
198 BENCHMARK_LOGD("DirectoryTest testGetDirFiles001 end.");
199 }
200
201 /*
202 * @tc.name: testForceCreateDirectory001
203 * @tc.desc: directory unit test
204 */
BENCHMARK_F(BenchmarkDirectoryTest,testForceCreateDirectory001)205 BENCHMARK_F(BenchmarkDirectoryTest, testForceCreateDirectory001)(benchmark::State& state)
206 {
207 BENCHMARK_LOGD("DirectoryTest testForceCreateDirectory001 start.");
208 while (state.KeepRunning()) {
209 string dirpath = "/data/test_dir/test2/test3";
210 bool ret = ForceCreateDirectory(dirpath);
211 AssertEqual(ret, true, "ret did not equal true as expected.", state);
212 ret = IsEmptyFolder(dirpath);
213 AssertEqual(ret, true, "ret did not equal true as expected.", state);
214 }
215 BENCHMARK_LOGD("DirectoryTest testForceCreateDirectory001 end.");
216 }
217
218 /*
219 * @tc.name: testForceRemoveDirectory001
220 * @tc.desc: directory unit test
221 */
BENCHMARK_F(BenchmarkDirectoryTest,testForceRemoveDirectory001)222 BENCHMARK_F(BenchmarkDirectoryTest, testForceRemoveDirectory001)(benchmark::State& state)
223 {
224 BENCHMARK_LOGD("DirectoryTest testForceRemoveDirectory001 start.");
225 while (state.KeepRunning()) {
226 string dirpath = "/data/test_dir";
227 bool ret = ForceCreateDirectory(dirpath);
228 AssertEqual(ret, true, "ret did not equal true as expected.", state);
229 ret = ForceRemoveDirectory(dirpath);
230 AssertEqual(ret, true, "ret did not equal true as expected.", state);
231 }
232 BENCHMARK_LOGD("DirectoryTest testForceRemoveDirectory001 end.");
233 }
234
235 /*
236 * @tc.name: testForceRemoveDirectory002
237 * @tc.desc: test whether the folder exists
238 */
BENCHMARK_F(BenchmarkDirectoryTest,testForceRemoveDirectory002)239 BENCHMARK_F(BenchmarkDirectoryTest, testForceRemoveDirectory002)(benchmark::State& state)
240 {
241 BENCHMARK_LOGD("DirectoryTest testForceRemoveDirectory002 start.");
242 while (state.KeepRunning()) {
243 string dirpath = "/data/test/utils_directory_tmp/";
244 bool ret = ForceRemoveDirectory(dirpath);
245 AssertEqual(ret, false, "ret did not equal false as expected.", state);
246 }
247 BENCHMARK_LOGD("DirectoryTest testForceRemoveDirectory002 end.");
248 }
249
250 /*
251 * @tc.name: testRemoveFile001
252 * @tc.desc: directory unit test
253 */
BENCHMARK_F(BenchmarkDirectoryTest,testRemoveFile001)254 BENCHMARK_F(BenchmarkDirectoryTest, testRemoveFile001)(benchmark::State& state)
255 {
256 BENCHMARK_LOGD("DirectoryTest testRemoveFile001 start.");
257 while (state.KeepRunning()) {
258 string dirpath = "/data/test_dir";
259 bool ret = ForceCreateDirectory(dirpath);
260 AssertEqual(ret, true, "ret did not equal true as expected.", state);
261 string filename = dirpath + "/test.txt";
262 FILE *fp = fopen(filename.c_str(), "w");
263 if (fp != nullptr) {
264 fclose(fp);
265 ret = RemoveFile(filename);
266 AssertEqual(ret, true, "ret did not equal true as expected.", state);
267 }
268 ret = ForceRemoveDirectory(dirpath);
269 AssertEqual(ret, true, "ret did not equal true as expected.", state);
270 }
271 BENCHMARK_LOGD("DirectoryTest testRemoveFile001 end.");
272 }
273
274 /*
275 * @tc.name: testRemoveFile002
276 * @tc.desc: Remove soft link file.
277 */
BENCHMARK_F(BenchmarkDirectoryTest,testRemoveFile002)278 BENCHMARK_F(BenchmarkDirectoryTest, testRemoveFile002)(benchmark::State& state)
279 {
280 BENCHMARK_LOGD("DirectoryTest testRemoveFile002 start.");
281 while (state.KeepRunning()) {
282 string dirpath = "/data/test_dir";
283 bool ret = ForceCreateDirectory(dirpath);
284 AssertEqual(ret, true, "ret did not equal true as expected.", state);
285
286 string targetname = "/data/test_target.txt";
287 FILE *fp = fopen(targetname.c_str(), "w");
288 if (fp != nullptr) {
289 fclose(fp);
290 }
291
292 // symlink to a directory
293 string linkpath = "/data/test_symlink_dir";
294 int res = symlink(dirpath.c_str(), linkpath.c_str());
295 AssertEqual(res, 0, "res did not equal 0 as expected.", state);
296
297 ret = ForceRemoveDirectory(linkpath);
298 AssertEqual(ret, true, "ret did not equal true as expected.", state);
299
300 // Target dir is not removed.
301 ret = faccessat(AT_FDCWD, dirpath.c_str(), F_OK, AT_SYMLINK_NOFOLLOW);
302 AssertEqual(ret, 0, "ret did not equal 0 as expected.", state);
303
304 // symlink to a file
305 string filename = dirpath + "/test.txt";
306 res = symlink(targetname.c_str(), filename.c_str());
307 AssertEqual(res, 0, "res did not equal 0 as expected.", state);
308
309 ret = ForceRemoveDirectory(dirpath);
310 AssertEqual(ret, true, "ret did not equal true as expected.", state);
311
312 // Target file is not removed.
313 ret = faccessat(AT_FDCWD, targetname.c_str(), F_OK, AT_SYMLINK_NOFOLLOW);
314 AssertEqual(ret, 0, "ret did not equal 0 as expected.", state);
315
316 ret = RemoveFile(targetname);
317 AssertEqual(ret, true, "ret did not equal true as expected.", state);
318 }
319 BENCHMARK_LOGD("DirectoryTest testRemoveFile002 end.");
320 }
321
322 /*
323 * @tc.name: testRemoveFile003
324 * @tc.desc: Remove dangling soft link file.
325 */
BENCHMARK_F(BenchmarkDirectoryTest,testRemoveFile003)326 BENCHMARK_F(BenchmarkDirectoryTest, testRemoveFile003)(benchmark::State& state)
327 {
328 BENCHMARK_LOGD("DirectoryTest testRemoveFile003 start.");
329 while (state.KeepRunning()) {
330 string dirpath = "/data/test_dir";
331 bool ret = ForceCreateDirectory(dirpath);
332 AssertEqual(ret, true, "ret did not equal true as expected.", state);
333
334 // symlink to a file
335 string targetname = "/data/nonexisted.txt";
336 string filename = dirpath + "/test.txt";
337 int res = symlink(targetname.c_str(), filename.c_str());
338 AssertEqual(res, 0, "res did not equal 0 as expected.", state);
339
340 ret = ForceRemoveDirectory(dirpath);
341 AssertEqual(ret, true, "ret did not equal true as expected.", state);
342
343 ret = RemoveFile(targetname);
344 AssertEqual(ret, true, "ret did not equal true as expected.", state);
345 }
346 BENCHMARK_LOGD("DirectoryTest testRemoveFile003 end.");
347 }
348
349 /*
350 * @tc.name: testGetFolderSize001
351 * @tc.desc: directory unit test
352 */
BENCHMARK_F(BenchmarkDirectoryTest,testGetFolderSize001)353 BENCHMARK_F(BenchmarkDirectoryTest, testGetFolderSize001)(benchmark::State& state)
354 {
355 BENCHMARK_LOGD("DirectoryTest testGetFolderSize001 start.");
356 while (state.KeepRunning()) {
357 string dirpath = "/data/test_folder/";
358 bool ret = ForceCreateDirectory(dirpath);
359 AssertEqual(ret, true, "ret did not equal true as expected.", state);
360 ofstream out(dirpath + "test.txt");
361 if (out.is_open()) {
362 out << "This is a line.\n";
363 out << "This is another line.\n";
364 out.close();
365 }
366 uint64_t resultsize = GetFolderSize(dirpath);
367 uint64_t resultcomp = 38;
368 AssertEqual(resultsize, resultcomp, "resultsize did not equal resultcomp as expected.", state);
369
370 mode_t mode = S_IRWXU | S_IRWXG | S_IRWXO;
371 ret = ChangeModeFile(dirpath + "test.txt", mode);
372 AssertEqual(ret, true, "ret did not equal true as expected.", state);
373
374 mode = S_IRUSR | S_IRGRP | S_IROTH;
375 ret = ChangeModeDirectory(dirpath, mode);
376 AssertEqual(ret, true, "ret did not equal true as expected.", state);
377
378 ret = ForceRemoveDirectory(dirpath);
379 AssertEqual(ret, true, "ret did not equal true as expected.", state);
380 }
381 BENCHMARK_LOGD("DirectoryTest testGetFolderSize001 end.");
382 }
383
384 /*
385 * @tc.name: testChangeModeFile001
386 * @tc.desc: test whether the folder exists
387 */
BENCHMARK_F(BenchmarkDirectoryTest,testChangeModeFile001)388 BENCHMARK_F(BenchmarkDirectoryTest, testChangeModeFile001)(benchmark::State& state)
389 {
390 BENCHMARK_LOGD("DirectoryTest testChangeModeFile001 start.");
391 while (state.KeepRunning()) {
392 string dirpath = "/data/test/utils_directory_tmp/";
393 mode_t mode = S_IRWXU | S_IRWXG | S_IRWXO;
394 bool ret = ChangeModeFile(dirpath + "test.txt", mode);
395 AssertEqual(ret, false, "ret did not equal false as expected.", state);
396 }
397 BENCHMARK_LOGD("DirectoryTest testChangeModeFile001 end.");
398 }
399
400 /*
401 * @tc.name: testChangeModeDirectory001
402 * @tc.desc: test whether the folder is empty and get the size of the folder
403 */
BENCHMARK_F(BenchmarkDirectoryTest,testChangeModeDirectory001)404 BENCHMARK_F(BenchmarkDirectoryTest, testChangeModeDirectory001)(benchmark::State& state)
405 {
406 BENCHMARK_LOGD("DirectoryTest testChangeModeDirectory001 start.");
407 while (state.KeepRunning()) {
408 string dirpath = "";
409 mode_t mode = S_IRUSR | S_IRGRP | S_IROTH;
410 bool ret = ChangeModeDirectory(dirpath, mode);
411 AssertEqual(ret, false, "ret did not equal false as expected.", state);
412
413 uint64_t resultsize = GetFolderSize(dirpath);
414 uint64_t resultcomp = 0;
415 AssertEqual(resultsize, resultcomp, "resultsize did not equal resultcomp as expected.", state);
416 }
417 BENCHMARK_LOGD("DirectoryTest testChangeModeDirectory001 end.");
418 }
419
420 /*
421 * @tc.name: testPathToRealPath001
422 * @tc.desc: directory unit test
423 */
BENCHMARK_F(BenchmarkDirectoryTest,testPathToRealPath001)424 BENCHMARK_F(BenchmarkDirectoryTest, testPathToRealPath001)(benchmark::State& state)
425 {
426 BENCHMARK_LOGD("DirectoryTest testPathToRealPath001 start.");
427 while (state.KeepRunning()) {
428 string path = "/data/test";
429 string realpath;
430 bool ret = PathToRealPath(path, realpath);
431 AssertEqual(ret, true, "ret did not equal true as expected.", state);
432 AssertEqual(path, realpath, "path did not equal realpath as expected.", state);
433 }
434 BENCHMARK_LOGD("DirectoryTest testPathToRealPath001 end.");
435 }
436
437 /*
438 * @tc.name: testPathToRealPath002
439 * @tc.desc: directory unit test
440 */
BENCHMARK_F(BenchmarkDirectoryTest,testPathToRealPath002)441 BENCHMARK_F(BenchmarkDirectoryTest, testPathToRealPath002)(benchmark::State& state)
442 {
443 BENCHMARK_LOGD("DirectoryTest testPathToRealPath002 start.");
444 while (state.KeepRunning()) {
445 string path = "/data/../data/test";
446 string realpath;
447 bool ret = PathToRealPath(path, realpath);
448 AssertEqual(ret, true, "ret did not equal true as expected.", state);
449 AssertEqual("/data/test", realpath, "\"/data/test\" did not equal realpath as expected.", state);
450 }
451 BENCHMARK_LOGD("DirectoryTest testPathToRealPath002 end.");
452 }
453
454 /*
455 * @tc.name: testPathToRealPath003
456 * @tc.desc: directory unit test
457 */
BENCHMARK_F(BenchmarkDirectoryTest,testPathToRealPath003)458 BENCHMARK_F(BenchmarkDirectoryTest, testPathToRealPath003)(benchmark::State& state)
459 {
460 BENCHMARK_LOGD("DirectoryTest testPathToRealPath003 start.");
461 while (state.KeepRunning()) {
462 string path = "./";
463 string realpath;
464 bool ret = PathToRealPath(path, realpath);
465 AssertEqual(ret, true, "ret did not equal true as expected.", state);
466 AssertEqual("/data/test", realpath, "\"/data/test\" did not equal realpath as expected.", state);
467 }
468 BENCHMARK_LOGD("DirectoryTest testPathToRealPath003 end.");
469 }
470
471 /*
472 * @tc.name: testPathToRealPath004
473 * @tc.desc: directory unit test
474 */
BENCHMARK_F(BenchmarkDirectoryTest,testPathToRealPath004)475 BENCHMARK_F(BenchmarkDirectoryTest, testPathToRealPath004)(benchmark::State& state)
476 {
477 BENCHMARK_LOGD("DirectoryTest testPathToRealPath004 start.");
478 while (state.KeepRunning()) {
479 string path = "";
480 string realpath;
481 bool ret = PathToRealPath(path, realpath);
482 AssertEqual(ret, false, "ret did not equal false as expected.", state);
483 }
484 BENCHMARK_LOGD("DirectoryTest testPathToRealPath004 end.");
485 }
486
487 /*
488 * @tc.name: testPathToRealPath005
489 * @tc.desc: directory unit test
490 */
BENCHMARK_F(BenchmarkDirectoryTest,testPathToRealPath005)491 BENCHMARK_F(BenchmarkDirectoryTest, testPathToRealPath005)(benchmark::State& state)
492 {
493 BENCHMARK_LOGD("DirectoryTest testPathToRealPath005 start.");
494 while (state.KeepRunning()) {
495 string path = "/data/test/data/test/data/test/data/test/data/test/data/ \
496 test/data/test/data/test/data/test/data/test/data/test/data/test/data/ \
497 test/data/test/data/test/data/test/data/test/data/test/data/test/data/ \
498 test/data/test/data/test/data/test/data/test/data/test/data/test/data/ \
499 test/data/test/data/test/data/test";
500 string realpath;
501 bool ret = PathToRealPath(path, realpath);
502 AssertEqual(ret, false, "ret did not equal false as expected.", state);
503 }
504 BENCHMARK_LOGD("DirectoryTest testPathToRealPath005 end.");
505 }
506
507 /*
508 * @tc.name: testPathToRealPath006
509 * @tc.desc: test whether the folder exists
510 */
BENCHMARK_F(BenchmarkDirectoryTest,testPathToRealPath006)511 BENCHMARK_F(BenchmarkDirectoryTest, testPathToRealPath006)(benchmark::State& state)
512 {
513 BENCHMARK_LOGD("DirectoryTest testPathToRealPath006 start.");
514 while (state.KeepRunning()) {
515 string path(PATH_MAX, 'x');
516 string realpath;
517 bool ret = PathToRealPath(path, realpath);
518 AssertEqual(ret, false, "ret did not equal false as expected.", state);
519 }
520 BENCHMARK_LOGD("DirectoryTest testPathToRealPath006 end.");
521 }
522
523 /*
524 * @tc.name: testTransformFileName001
525 * @tc.desc: test transform the file name
526 */
527 #if defined(IOS_PLATFORM) || defined(_WIN32)
BENCHMARK_F(BenchmarkDirectoryTest,testTransformFileName001)528 BENCHMARK_F(BenchmarkDirectoryTest, testTransformFileName001)(benchmark::State& state)
529 {
530 BENCHMARK_LOGD("DirectoryTest testTransformFileName001 start.");
531 while (state.KeepRunning()) {
532 string srcName = "test";
533 string result = TransformFileName(srcName);
534 string cmpName = srcName;
535 #ifdef _WIN32
536 cmpName = cmpName.append(".dll");
537 #elif defined IOS_PLATFORM
538 cmpName = cmpName.append(".dylib");
539 #endif
540 AssertEqual(result, cmpName, "result did not equal cmpName as expected.", state);
541
542 srcName = srcName.append(".app");
543 result = TransformFileName(srcName);
544 #ifdef _WIN32
545 cmpName = cmpName.append(".dll");
546 #elif defined IOS_PLATFORM
547 cmpName = cmpName.append(".dylib");
548 #endif
549 AssertEqual(result, cmpName, "result did not equal cmpName as expected.", state);
550 }
551 BENCHMARK_LOGD("DirectoryTest testTransformFileName001 end.");
552 }
553 #endif
554 } // namespace
555 } // namespace OHOS
556 // Run the benchmark
557 BENCHMARK_MAIN();