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 <gtest/gtest.h>
17 #include <fstream>
18 #include <dirent.h>
19 #include <iostream>
20 #include <sys/stat.h>
21 #include "unistd.h"
22 #include "directory_ex.h"
23 
24 using namespace testing::ext;
25 namespace OHOS {
26 namespace Multimedia {
27 class MockDirectoryExTest : public testing::Test {
28 public:
MockDirectoryExTest()29     MockDirectoryExTest() {}
~MockDirectoryExTest()30     ~MockDirectoryExTest() {}
31 };
32 
33 /**
34  * @tc.name: ExtractFilePath001
35  * @tc.desc: test ExtractFilePath
36  * @tc.type: FUNC
37  */
38 HWTEST_F(MockDirectoryExTest, ExtractFilePath001, TestSize.Level3)
39 {
40     GTEST_LOG_(INFO) << "MockDirectoryExTest: ExtractFilePath001 start";
41     const string fileFullName = "a";
42     string expath = ExtractFilePath(fileFullName);
43     ASSERT_EQ(expath, "");
44     GTEST_LOG_(INFO) << "MockDirectoryExTest: ExtractFilePath001 end";
45 }
46 
47 /**
48  * @tc.name: ExtractFileName001
49  * @tc.desc: test ExtractFileName
50  * @tc.type: FUNC
51  */
52 HWTEST_F(MockDirectoryExTest, ExtractFileName001, TestSize.Level3)
53 {
54     GTEST_LOG_(INFO) << "MockDirectoryExTest: ExtractFileName001 start";
55     const std::string fileFullName = "a";
56     string exfile = ExtractFileName(fileFullName);
57     ASSERT_EQ(exfile, "a");
58     GTEST_LOG_(INFO) << "MockDirectoryExTest: ExtractFileName001 end";
59 }
60 
61 /**
62  * @tc.name: ExtractFileExt001
63  * @tc.desc: test ExtractFileExt
64  * @tc.type: FUNC
65  */
66 HWTEST_F(MockDirectoryExTest, ExtractFileExt001, TestSize.Level3)
67 {
68     GTEST_LOG_(INFO) << "MockDirectoryExTest: ExtractFileExt001 start";
69     const string fileName = "a";
70     string exFile = ExtractFilePath(fileName);
71     ASSERT_EQ(exFile, "");
72     GTEST_LOG_(INFO) << "MockDirectoryExTest: ExtractFileExt001 end";
73 }
74 
75 /**
76  * @tc.name: IncludeTrailingPathDelimiter001
77  * @tc.desc: test IncludeTrailingPathDelimiter
78  * @tc.type: FUNC
79  */
80 HWTEST_F(MockDirectoryExTest, IncludeTrailingPathDelimiter001, TestSize.Level3)
81 {
82     GTEST_LOG_(INFO) << "MockDirectoryExTest: IncludeTrailingPathDelimiter001 start";
83     const std::string path = "";
84     string includetra = IncludeTrailingPathDelimiter(path);
85     ASSERT_EQ(includetra, "");
86     GTEST_LOG_(INFO) << "MockDirectoryExTest: IncludeTrailingPathDelimiter001 end";
87 }
88 
89 /**
90  * @tc.name: GetDirFiles001
91  * @tc.desc: test GetDirFiles
92  * @tc.type: FUNC
93  */
94 HWTEST_F(MockDirectoryExTest, GetDirFiles001, TestSize.Level3)
95 {
96     GTEST_LOG_(INFO) << "MockDirectoryExTest: GetDirFiles001 start";
97     const string canonicalPath = "a";
98     vector<string> strFiles;
99     GetDirFiles(canonicalPath, strFiles);
100     ASSERT_EQ(strFiles.empty(), true);
101     GTEST_LOG_(INFO) << "MockDirectoryExTest: GetDirFiles001 end";
102 }
103 
104 /**
105  * @tc.name: PathToRealPath001
106  * @tc.desc: test PathToRealPath
107  * @tc.type: FUNC
108  */
109 HWTEST_F(MockDirectoryExTest, PathToRealPath001, TestSize.Level3)
110 {
111     GTEST_LOG_(INFO) << "MockDirectoryExTest: PathToRealPath001 start";
112     const string path = "a";
113     string realPath = "";
114     bool ptr = PathToRealPath(path, realPath);
115     ASSERT_EQ(ptr, true);
116     GTEST_LOG_(INFO) << "MockDirectoryExTest: PathToRealPath001 end";
117 }
118 } // namespace Multimedia
119 } // namespace OHOS