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 <gmock/gmock.h>
18
19 #include "cloud_download_uri_manager.h"
20 #include "dfs_error.h"
21
22 namespace OHOS {
23 namespace FileManagement::CloudSync {
24 namespace Test {
25 using namespace testing;
26 using namespace testing::ext;
27 using namespace std;
28
29 class CloudDownloadUriManagerTest : public testing::Test {
30 public:
31 static void SetUpTestCase(void);
32 static void TearDownTestCase(void);
33 void SetUp();
34 void TearDown();
35 };
36
SetUpTestCase(void)37 void CloudDownloadUriManagerTest::SetUpTestCase(void)
38 {
39 std::cout << "SetUpTestCase" << std::endl;
40 }
41
TearDownTestCase(void)42 void CloudDownloadUriManagerTest::TearDownTestCase(void)
43 {
44 std::cout << "TearDownTestCase" << std::endl;
45 }
46
SetUp(void)47 void CloudDownloadUriManagerTest::SetUp(void)
48 {
49 std::cout << "SetUp" << std::endl;
50 }
51
TearDown(void)52 void CloudDownloadUriManagerTest::TearDown(void)
53 {
54 std::cout << "TearDown" << std::endl;
55 }
56
57 /**
58 * @tc.name: GetInstanceTest
59 * @tc.desc: Verify the GetInstance function.
60 * @tc.type: FUNC
61 * @tc.require: I6H5MH
62 */
63 HWTEST_F(CloudDownloadUriManagerTest, GetInstanceTest, TestSize.Level1)
64 {
65 try {
66 CloudDownloadUriManager::GetInstance();
67 } catch (...) {
68 EXPECT_TRUE(false);
69 }
70 }
71
72 /**
73 * @tc.name: AddPathToUriTest001
74 * @tc.desc: Verify the AddPathToUri function.
75 * @tc.type: FUNC
76 * @tc.require: I6H5MH
77 */
78 HWTEST_F(CloudDownloadUriManagerTest, AddPathToUriTest001, TestSize.Level1)
79 {
80 const std::string path = "file://data/file";
81 const std::string uri = "file://data/file/test";
82 CloudDownloadUriManager mUriMgr;
83 mUriMgr.AddPathToUri(path, uri);
84 EXPECT_EQ(mUriMgr.pathUriMap_[path], uri);
85 }
86
87 /**
88 * @tc.name: AddPathToUriTest002
89 * @tc.desc: Verify the AddPathToUri function.
90 * @tc.type: FUNC
91 * @tc.require: issueI7UYAL
92 */
93 HWTEST_F(CloudDownloadUriManagerTest, AddPathToUriTest002, TestSize.Level1)
94 {
95 const std::string path = "file://data/file";
96 const std::string uri = "file://data/file/test";
97 CloudDownloadUriManager mUriMgr;
98 mUriMgr.pathUriMap_[path] = uri;
99 auto ret = mUriMgr.AddPathToUri(path, uri);
100 EXPECT_EQ(ret, E_STOP);
101 }
102
103 /**
104 * @tc.name: RemoveUriTest001
105 * @tc.desc: Verify the RemoveUri function.
106 * @tc.type: FUNC
107 * @tc.require: I6H5MH
108 */
109 HWTEST_F(CloudDownloadUriManagerTest, RemoveUriTest001, TestSize.Level1)
110 {
111 const std::string path = "file://data/file";
112 const std::string uri = "file://data/file/test1";
113 CloudDownloadUriManager mUriMgr;
114 mUriMgr.AddPathToUri(path, uri);
115 EXPECT_EQ(mUriMgr.pathUriMap_[path], uri);
116 mUriMgr.RemoveUri(path);
117 auto ret = mUriMgr.pathUriMap_.find(path);
118 EXPECT_EQ(ret, mUriMgr.pathUriMap_.end());
119 }
120
121 /**
122 * @tc.name: RemoveUriTest002
123 * @tc.desc: Verify the RemoveUri function.
124 * @tc.type: FUNC
125 * @tc.require: issueI7UYAL
126 */
127 HWTEST_F(CloudDownloadUriManagerTest, RemoveUriTest002, TestSize.Level1)
128 {
129 const std::string path = "file://data/file";
130 CloudDownloadUriManager mUriMgr;
131 mUriMgr.RemoveUri(path);
132 auto ret = mUriMgr.pathUriMap_.find(path);
133 EXPECT_EQ(ret, mUriMgr.pathUriMap_.end());
134 }
135
136 /**
137 * @tc.name: GetUriTest001
138 * @tc.desc: Verify the GetUri function.
139 * @tc.type: FUNC
140 * @tc.require: I6H5MH
141 */
142 HWTEST_F(CloudDownloadUriManagerTest, GetUriTest001, TestSize.Level1)
143 {
144 const std::string path = "";
145 const std::string uri = "";
146 CloudDownloadUriManager mUriMgr;
147 string uriStr = mUriMgr.GetUri(path);
148 EXPECT_EQ(uriStr, uri);
149 }
150
151 /**
152 * @tc.name: GetUriTest002
153 * @tc.desc: Verify the GetUri function.
154 * @tc.type: FUNC
155 * @tc.require: I6H5MH
156 */
157 HWTEST_F(CloudDownloadUriManagerTest, GetUriTest002, TestSize.Level1)
158 {
159 const std::string path = "file://data/file";
160 const std::string uri = "file://data/file/test2";
161 CloudDownloadUriManager mUriMgr;
162 mUriMgr.AddPathToUri(path, uri);
163 EXPECT_EQ(mUriMgr.pathUriMap_[path], uri);
164 string uriStr = mUriMgr.GetUri(path);
165 EXPECT_EQ(uriStr, uri);
166 }
167 } // namespace Test
168 } // namespace FileManagement::CloudSync {
169 } // namespace OHOS
170