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 "cloud_sync_asset_manager_impl.h"
17 #include "cloud_sync_service_proxy.h"
18 #include "dfs_error.h"
19 #include "utils_log.h"
20 
21 #include <gmock/gmock.h>
22 #include <gtest/gtest.h>
23 
24 namespace OHOS {
25 namespace FileManagement::CloudSync {
26 namespace Test {
27 using namespace testing;
28 using namespace testing::ext;
29 using namespace std;
30 
31 class CloudSyncAssetManagerImplTest : public testing::Test {
32 public:
33     static void SetUpTestCase(void);
34     static void TearDownTestCase(void);
35     void SetUp();
36     void TearDown();
37 };
38 
SetUpTestCase(void)39 void CloudSyncAssetManagerImplTest::SetUpTestCase(void)
40 {
41     std::cout << "SetUpTestCase" << std::endl;
42 }
43 
TearDownTestCase(void)44 void CloudSyncAssetManagerImplTest::TearDownTestCase(void)
45 {
46     std::cout << "TearDownTestCase" << std::endl;
47 }
48 
SetUp(void)49 void CloudSyncAssetManagerImplTest::SetUp(void)
50 {
51     std::cout << "SetUp" << std::endl;
52 }
53 
TearDown(void)54 void CloudSyncAssetManagerImplTest::TearDown(void)
55 {
56     std::cout << "TearDown" << std::endl;
57 }
58 
59 /*
60  * @tc.name: UploadAssetTest
61  * @tc.desc: Verify the UploadAsset function.
62  * @tc.type: FUNC
63  * @tc.require: I6H5MH
64  */
65 HWTEST_F(CloudSyncAssetManagerImplTest, UploadAssetTest, TestSize.Level1)
66 {
67     GTEST_LOG_(INFO) << "UploadAssetTest Start";
68     try {
69         int32_t userId = 100;
70         std::string request = "";
71         std::string result = "";
72         int32_t res = CloudSyncAssetManagerImpl::GetInstance().UploadAsset(userId, request, result);
73         EXPECT_EQ(res, E_BROKEN_IPC);
74     } catch (...) {
75         EXPECT_TRUE(false);
76         GTEST_LOG_(INFO) << "UploadAsseteTest FAILED";
77     }
78     GTEST_LOG_(INFO) << "UploadAssetTest End";
79 }
80 
81 /*
82  * @tc.name: DownloadFileTest001
83  * @tc.desc: Verify the DownloadFile function.
84  * @tc.type: FUNC
85  * @tc.require: I6H5MH
86  */
87 HWTEST_F(CloudSyncAssetManagerImplTest, DownloadFileTest001, TestSize.Level1)
88 {
89     GTEST_LOG_(INFO) << "DownloadFileTest Start";
90     try {
91         int32_t userId = 100;
92         std::string bundleName = "com.ohos.photos";
93         AssetInfo assetInfo;
94         int32_t res = CloudSyncAssetManagerImpl::GetInstance().DownloadFile(userId, bundleName, assetInfo);
95         EXPECT_EQ(res, E_BROKEN_IPC);
96     } catch (...) {
97         EXPECT_TRUE(false);
98         GTEST_LOG_(INFO) << "DownloadFileTest FAILED";
99     }
100     GTEST_LOG_(INFO) << "DownloadFileTest End";
101 }
102 
103 /*
104  * @tc.name: DownloadFileTest002
105  * @tc.desc: Verify the DownloadFile function.
106  * @tc.type: FUNC
107  * @tc.require: I6H5MH
108  */
109 HWTEST_F(CloudSyncAssetManagerImplTest, DownloadFileTest002, TestSize.Level1)
110 {
111     GTEST_LOG_(INFO) << "DownloadFileTest Start";
112     try {
113         int32_t userId = 100;
114         std::string bundleName = "com.ohos.photos";
115         std::string networkId = "";
116         AssetInfo assetInfo;
117         CloudSyncAssetManager::ResultCallback resultCallback;
118         int32_t res = CloudSyncAssetManagerImpl::GetInstance().DownloadFile(userId,
119                                             bundleName, networkId, assetInfo, resultCallback);
120         EXPECT_EQ(res, E_BROKEN_IPC);
121     } catch (...) {
122         EXPECT_TRUE(false);
123         GTEST_LOG_(INFO) << "DownloadFileTest FAILED";
124     }
125     GTEST_LOG_(INFO) << "DownloadFileTest End";
126 }
127 
128 /*
129  * @tc.name: DownloadFilesTest
130  * @tc.desc: Verify the DownloadFiles function.
131  * @tc.type: FUNC
132  * @tc.require: I6H5MH
133  */
134 HWTEST_F(CloudSyncAssetManagerImplTest, DownloadFilesTest, TestSize.Level1)
135 {
136     GTEST_LOG_(INFO) << "DownloadFilesTest Start";
137     try {
138         int32_t userId = 100;
139         std::string bundleName = "com.ohos.photos";
140         std::vector<AssetInfo> assetInfo;
141         std::vector<bool> assetResultMap;
142         int32_t res = CloudSyncAssetManagerImpl::GetInstance().DownloadFiles(userId,
143                                                     bundleName, assetInfo, assetResultMap);
144         EXPECT_EQ(res, E_INVAL_ARG);
145     } catch (...) {
146         EXPECT_TRUE(false);
147         GTEST_LOG_(INFO) << "DownloadFilesTest FAILED";
148     }
149     GTEST_LOG_(INFO) << "DownloadFilesTest End";
150 }
151 
152 /*
153  * @tc.name: DeleteAssetTest
154  * @tc.desc: Verify the DeleteAsset function.
155  * @tc.type: FUNC
156  * @tc.require: I6H5MH
157  */
158 HWTEST_F(CloudSyncAssetManagerImplTest, DeleteAssetTest, TestSize.Level1)
159 {
160     GTEST_LOG_(INFO) << "DeleteAssetTest Start";
161     try {
162         int32_t userId = 100;
163         std::string uri = "uri";
164         int32_t res = CloudSyncAssetManagerImpl::GetInstance().DeleteAsset(userId, uri);
165         EXPECT_EQ(res, E_BROKEN_IPC);
166     } catch (...) {
167         EXPECT_TRUE(false);
168         GTEST_LOG_(INFO) << "DeleteAssetTest FAILED";
169     }
170     GTEST_LOG_(INFO) << "DeleteAssetTest End";
171 }
172 
173 /*
174  * @tc.name: SetDeathRecipientTest
175  * @tc.desc: Verify the SetDeathRecipient function.
176  * @tc.type: FUNC
177  * @tc.require: I6H5MH
178  */
179 HWTEST_F(CloudSyncAssetManagerImplTest, SetDeathRecipientTest, TestSize.Level1)
180 {
181     GTEST_LOG_(INFO) << "NotifyDataChangeTest Start";
182     try {
183         auto CloudSyncServiceProxy = CloudSyncServiceProxy::GetInstance();
184         CloudSyncAssetManagerImpl::GetInstance().SetDeathRecipient(CloudSyncServiceProxy->AsObject());
185         EXPECT_TRUE(true);
186     } catch (...) {
187         EXPECT_TRUE(false);
188         GTEST_LOG_(INFO) << " SetDeathRecipientTest FAILED";
189     }
190     GTEST_LOG_(INFO) << "SetDeathRecipientTest End";
191 }
192 
193 } // namespace Test
194 } // namespace FileManagement::CloudSync
195 } // namespace OHOS