• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "data_sync_manager.h"
20 #include "dfs_error.h"
21 #include "dk_record.h"
22 #include "gallery_data_syncer.h"
23 #include "sdk_helper.h"
24 
25 /* template link */
26 namespace OHOS::FileManagement::CloudSync {
27 template<typename T, typename RET, typename... ARGS>
AsyncCallback(RET (T::* f)(ARGS...))28 std::function<RET(ARGS...)> DataSyncer::AsyncCallback(RET (T::*f)(ARGS...))
29 {
30     return taskRunner_->AsyncCallback<DataSyncer>(f, this);
31 }
32 } // namespace OHOS::FileManagement::CloudSync
33 
34 namespace OHOS::FileManagement::CloudSync::Test {
35 using namespace testing;
36 using namespace testing::ext;
37 using namespace std;
38 
39 class SdkHelperTest : public testing::Test {
40 public:
41     static void SetUpTestCase(void);
42     static void TearDownTestCase(void);
43     void SetUp();
44     void TearDown();
45     static inline shared_ptr<SdkHelper> sdkHelper_;
46 };
SetUpTestCase(void)47 void SdkHelperTest::SetUpTestCase(void)
48 {
49     GTEST_LOG_(INFO) << "SetUpTestCase";
50     sdkHelper_ = std::make_shared<SdkHelper>();
51 }
52 
TearDownTestCase(void)53 void SdkHelperTest::TearDownTestCase(void)
54 {
55     GTEST_LOG_(INFO) << "TearDownTestCase";
56     sdkHelper_ = nullptr;
57 }
58 
59 #undef LOGI
LOGI(string content)60 void LOGI(string content)
61 {
62     GTEST_LOG_(INFO) << content;
63 }
64 
SetUp(void)65 void SdkHelperTest::SetUp(void) {}
66 
TearDown(void)67 void SdkHelperTest::TearDown(void) {}
68 
69 /**
70  * @tc.name: GetAssetReadSessionErrTest,
71  * @tc.desc: Verify the GetAssetReadSession function
72  * @tc.type: FUNC
73  * @tc.require: I6JPKG
74  */
75 HWTEST_F(SdkHelperTest, GetAssetReadSessionErrTest, TestSize.Level1)
76 {
77     auto ret = sdkHelper_->GetAssetReadSession({}, {}, {}, {});
78     EXPECT_EQ(ret, nullptr);
79 }
80 
81 /**
82  * @tc.name: InitDriveKitInstanceFailTest
83  * @tc.desc: Verify the Init function
84  * @tc.type: FUNC
85  * @tc.require: I6JPKG
86  */
87 HWTEST_F(SdkHelperTest, InitDriveKitInstanceFailTest, TestSize.Level1)
88 {
89     int32_t userId = -1;
90     string appBundleName = "com.ohos.test";
91     auto ret = sdkHelper_->Init(userId, appBundleName);
92     EXPECT_EQ(E_CLOUD_SDK, ret);
93 }
94 
95 /**
96  * @tc.name: InitContainerFailTest
97  * @tc.desc: Verify the Init function
98  * @tc.type: FUNC
99  * @tc.require: I6JPKG
100  */
101 HWTEST_F(SdkHelperTest, InitContainerFailTest, TestSize.Level1)
102 {
103     int32_t userId = 100;
104     string appBundleName = "com.ohos.test.mock";
105     auto ret = sdkHelper_->Init(userId, appBundleName);
106     EXPECT_EQ(E_CLOUD_SDK, ret);
107 }
108 
109 /**
110  * @tc.name: InitPrivateDatabaseFailTest
111  * @tc.desc: Verify the Init function
112  * @tc.type: FUNC
113  * @tc.require: I6JPKG
114  */
115 HWTEST_F(SdkHelperTest, InitPrivateDatabaseFailTest, TestSize.Level1)
116 {
117     int32_t userId = 100;
118     string appBundleName = "com.ohos.test";
119     auto ret = sdkHelper_->Init(userId, appBundleName);
120     EXPECT_EQ(E_CLOUD_SDK, ret);
121 }
122 
123 /**
124  * @tc.name: InitOKTest
125  * @tc.desc: Verify the Init function
126  * @tc.type: FUNC
127  * @tc.require: I6JPKG
128  */
129 HWTEST_F(SdkHelperTest, InitOKTest, TestSize.Level1)
130 {
131     int32_t userId = 100;
132     string appBundleName = "com.ohos.test12312";
133     auto ret = sdkHelper_->Init(userId, appBundleName);
134     EXPECT_EQ(E_OK, ret);
135 }
136 
137 /**
138  * @tc.name: GetLockOKTest
139  * @tc.desc: Verify the GetLock function
140  * @tc.type: FUNC
141  * @tc.require: I6JPKG
142  */
143 HWTEST_F(SdkHelperTest, GetLockOKTest, TestSize.Level1)
144 {
145     DriveKit::DKLock lock_;
146     auto ret = sdkHelper_->GetLock(lock_);
147     EXPECT_EQ(E_OK, ret);
148     sdkHelper_->DeleteLock(lock_);
149 }
150 
151 /**
152  * @tc.name: GetLockErrTest
153  * @tc.desc: Verify the GetLock function
154  * @tc.type: FUNC
155  * @tc.require: I6JPKG
156  */
157 HWTEST_F(SdkHelperTest, GetLockErrTest, TestSize.Level1)
158 {
159     DriveKit::DKLock lock_;
160     lock_.lockInterval = -1;
161     auto ret = sdkHelper_->GetLock(lock_);
162     EXPECT_NE(E_OK, ret);
163 }
164 
165 /**
166  * @tc.name: FetchRecordsOKTest
167  * @tc.desc: Verify the FetchRecords function
168  * @tc.type: FUNC
169  * @tc.require: I6JPKG
170  */
171 HWTEST_F(SdkHelperTest, FetchRecordsOKTest, TestSize.Level1)
172 {
173     FetchCondition cond;
174     int32_t ret = sdkHelper_->FetchRecords(nullptr, cond, "", nullptr);
175     EXPECT_EQ(E_OK, ret);
176 }
177 
178 /**
179  * @tc.name: FetchRecordsErrTest
180  * @tc.desc: Verify the FetchRecords function
181  * @tc.type: FUNC
182  * @tc.require: I6JPKG
183  */
184 HWTEST_F(SdkHelperTest, FetchRecordsErrTest, TestSize.Level1)
185 {
186     FetchCondition cond;
187     int32_t ret = sdkHelper_->FetchRecords(nullptr, cond, "err", nullptr);
188     EXPECT_NE(E_OK, ret);
189 }
190 
191 /**
192  * @tc.name: GetStartCursorOKTest
193  * @tc.desc: Verify the GetStartCursor function
194  * @tc.type: FUNC
195  * @tc.require: I6JPKG
196  */
197 HWTEST_F(SdkHelperTest, GetStartCursorOKTest, TestSize.Level1)
198 {
199     std::string tempStartCursor;
200     int32_t ret = sdkHelper_->GetStartCursor("", tempStartCursor);
201     EXPECT_EQ(E_OK, ret);
202 }
203 
204 /**
205  * @tc.name: GetStartCursorErrTest
206  * @tc.desc: Verify the GetStartCursor function
207  * @tc.type: FUNC
208  * @tc.require: I6JPKG
209  */
210 HWTEST_F(SdkHelperTest, GetStartCursorErrTest, TestSize.Level1)
211 {
212     std::string tempStartCursor;
213     int32_t ret = sdkHelper_->GetStartCursor("err", tempStartCursor);
214     EXPECT_NE(E_OK, ret);
215 }
216 
217 /**
218  * @tc.name: GetAssetReadSessionOKTest,
219  * @tc.desc: Verify the GetAssetReadSession function
220  * @tc.type: FUNC
221  * @tc.require: I6JPKG
222  */
223 HWTEST_F(SdkHelperTest, GetAssetReadSessionOKTest, TestSize.Level1)
224 {
225     auto ret = sdkHelper_->GetAssetReadSession({}, {}, {}, {});
226     EXPECT_NE(ret, nullptr);
227 }
228 
229 /**
230  * @tc.name: SaveSubscriptionOKTest,
231  * @tc.desc: Verify the SaveSubscription function
232  * @tc.type: FUNC
233  * @tc.require: I6JPKG
234  */
235 HWTEST_F(SdkHelperTest, SaveSubscriptionOKTest, TestSize.Level1)
236 {
237     auto ret = sdkHelper_->SaveSubscription(nullptr);
238     EXPECT_EQ(E_OK, ret);
239 }
240 
241 /**
242  * @tc.name: SaveSubscriptionErrTest,
243  * @tc.desc: Verify the SaveSubscription function
244  * @tc.type: FUNC
245  * @tc.require: I6JPKG
246  */
247 HWTEST_F(SdkHelperTest, SaveSubscriptionErrTest, TestSize.Level1)
248 {
249     auto ret = sdkHelper_->SaveSubscription(
__anon4c772e750102(auto, shared_ptr<DriveKit::DKContainer>, DriveKit::DKSubscriptionResult &res) 250         [](auto, shared_ptr<DriveKit::DKContainer>, DriveKit::DKSubscriptionResult &res) {});
251     EXPECT_NE(E_OK, ret);
252 }
253 
254 /**
255  * @tc.name: DeleteSubscriptionOKTest,
256  * @tc.desc: Verify the DeleteSubscription function
257  * @tc.type: FUNC
258  * @tc.require: I6JPKG
259  */
260 HWTEST_F(SdkHelperTest, DeleteSubscriptionOKTest, TestSize.Level1)
261 {
262     auto ret = sdkHelper_->DeleteSubscription(nullptr);
263     EXPECT_EQ(E_OK, ret);
264 }
265 
266 /**
267  * @tc.name: DeleteSubscriptionErrTest,
268  * @tc.desc: Verify the DeleteSubscription function
269  * @tc.type: FUNC
270  * @tc.require: I6JPKG
271  */
272 HWTEST_F(SdkHelperTest, DeleteSubscriptionErrTest, TestSize.Level1)
273 {
__anon4c772e750202(auto, DriveKit::DKError err) 274     auto ret = sdkHelper_->DeleteSubscription([](auto, DriveKit::DKError err) {});
275     EXPECT_NE(E_OK, ret);
276 }
277 
278 /**
279  * @tc.name: FetchRecordWithIdOKTest
280  * @tc.desc: Verify the FetchRecordWithId function
281  * @tc.type: FUNC
282  * @tc.require: I6JPKG
283  */
284 HWTEST_F(SdkHelperTest, FetchRecordWithIdOKTest, TestSize.Level1)
285 {
286     FetchCondition cond;
287     int32_t ret = sdkHelper_->FetchRecordWithId(nullptr, cond, "", nullptr);
288     EXPECT_EQ(E_OK, ret);
289 }
290 
291 /**
292  * @tc.name: FetchRecordWithIdErrTest
293  * @tc.desc: Verify the FetchRecordWithId function
294  * @tc.type: FUNC
295  * @tc.require: I6JPKG
296  */
297 HWTEST_F(SdkHelperTest, FetchRecordWithIdErrTest, TestSize.Level1)
298 {
299     FetchCondition cond;
300     int32_t ret = sdkHelper_->FetchRecordWithId(nullptr, cond, "err", nullptr);
301     EXPECT_NE(E_OK, ret);
302 }
303 
304 /**
305  * @tc.name: CancelDownloadAssetsOKTest
306  * @tc.desc: Verify the CancelDownloadAssets function
307  * @tc.type: FUNC
308  * @tc.require: I6JPKG
309  */
310 HWTEST_F(SdkHelperTest, CancelDownloadAssetsOKTest, TestSize.Level1)
311 {
312     int32_t id = 0;
313     int32_t ret = sdkHelper_->CancelDownloadAssets(id);
314     EXPECT_EQ(E_OK, ret);
315 }
316 } // namespace OHOS::FileManagement::CloudSync::Test