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
19 #include "utils_directory.h"
20
21 #include <sys/types.h>
22 #include <unistd.h>
23 #include <system_error>
24
25 #include "directory_ex.h"
26
27 namespace OHOS {
28 namespace Storage {
29 namespace DistributedFile {
30 namespace Utils {
31 using namespace testing;
32 using namespace testing::ext;
33 using namespace std;
34
35 class UtilsDirectoryTest : public testing::Test {
36 public:
37 static void SetUpTestCase(void);
38 static void TearDownTestCase(void);
39 void SetUp();
40 void TearDown();
41 };
42
SetUpTestCase(void)43 void UtilsDirectoryTest::SetUpTestCase(void)
44 {
45 GTEST_LOG_(INFO) << "SetUpTestCase";
46 }
47
TearDownTestCase(void)48 void UtilsDirectoryTest::TearDownTestCase(void)
49 {
50 GTEST_LOG_(INFO) << "TearDownTestCase";
51 }
52
SetUp(void)53 void UtilsDirectoryTest::SetUp(void)
54 {
55 GTEST_LOG_(INFO) << "SetUp";
56 }
57
TearDown(void)58 void UtilsDirectoryTest::TearDown(void)
59 {
60 GTEST_LOG_(INFO) << "TearDown";
61 }
62
63 /**
64 * @tc.name: ForceCreateDirectoryTest001
65 * @tc.desc: Verify the ForceCreateDirectory function
66 * @tc.type: FUNC
67 * @tc.require: I6H5MH
68 */
69 HWTEST_F(UtilsDirectoryTest, ForceCreateDirectoryTest001, TestSize.Level1)
70 {
71 GTEST_LOG_(INFO) << "ForceCreateDirectoryTest001 Start";
72 try {
73 string path = "/data/tdd";
74 ForceCreateDirectory(path);
75 } catch (...) {
76 EXPECT_FALSE(false);
77 GTEST_LOG_(INFO) << " ForceCreateDirectoryTest001 ERROR";
78 }
79 GTEST_LOG_(INFO) << "ForceCreateDirectoryTest001 End";
80 }
81
82 /**
83 * @tc.name: ForceCreateDirectoryTest002
84 * @tc.desc: Verify the ForceCreateDirectoryTest002 function
85 * @tc.type: FUNC
86 * @tc.require: I6H5MH
87 */
88 HWTEST_F(UtilsDirectoryTest, ForceCreateDirectoryTest002, TestSize.Level1)
89 {
90 GTEST_LOG_(INFO) << "ForceCreateDirectoryTest002 Start";
91 try {
92 string path = "/data/tdd";
93 mode_t mode = (S_IRWXU | S_IRWXG | S_IRWXO); // 00777
94 ForceCreateDirectory(path, mode);
95 } catch (...) {
96 EXPECT_TRUE(false);
97 GTEST_LOG_(INFO) << " ForceCreateDirectoryTest002 ERROR";
98 }
99 GTEST_LOG_(INFO) << "ForceCreateDirectoryTest002 End";
100 }
101
102 /**
103 * @tc.name: ForceCreateDirectoryTest003
104 * @tc.desc: Verify the ForceCreateDirectoryTest003 function
105 * @tc.type: FUNC
106 * @tc.require: I6H5MH
107 */
108 HWTEST_F(UtilsDirectoryTest, ForceCreateDirectoryTest003, TestSize.Level1)
109 {
110 GTEST_LOG_(INFO) << "ForceCreateDirectoryTest003 Start";
111 try {
112 string path = "/data/tdd";
113 mode_t mode = (S_IRWXU | S_IRWXG | S_IRWXO);
114 uid_t uid = UID_ROOT;
115 gid_t gid = 0; // root
116 ForceCreateDirectory(path, mode, uid, gid);
117 } catch (...) {
118 EXPECT_TRUE(false);
119 GTEST_LOG_(INFO) << " ForceCreateDirectoryTest003 ERROR";
120 }
121 GTEST_LOG_(INFO) << "ForceCreateDirectoryTest003 End";
122 }
123
124 /**
125 * @tc.name: ForceRemoveDirectoryTest001
126 * @tc.desc: Verify the ForceRemoveDirectory function
127 * @tc.type: FUNC
128 * @tc.require: I6H5MH
129 */
130 HWTEST_F(UtilsDirectoryTest, ForceRemoveDirectoryTest001, TestSize.Level1)
131 {
132 GTEST_LOG_(INFO) << "ForceRemoveDirectory001 Start";
133 try {
134 string path = "/data/tdd";
135 ForceRemoveDirectory(path);
136 } catch (...) {
137 EXPECT_TRUE(false);
138 GTEST_LOG_(INFO) << " ForceRemoveDirectoryTest001 ERROR";
139 }
140 GTEST_LOG_(INFO) << "ForceRemoveDirectoryTest001 End";
141 }
142 } // namespace Utils
143 } // namespace DistributedFile
144 } // namespace Storage
145 } // namespace OHOS