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 "dk_assets_downloader.h"
20
21 namespace OHOS::FileManagement::CloudSync::Test {
22 using namespace testing;
23 using namespace testing::ext;
24 using namespace std;
25 using namespace DriveKit;
26
27 class DkAssetDownloaderTest : public testing::Test {
28 public:
29 static void SetUpTestCase(void);
30 static void TearDownTestCase(void);
31 void SetUp();
32 void TearDown();
33 };
SetUpTestCase(void)34 void DkAssetDownloaderTest::SetUpTestCase(void)
35 {
36 GTEST_LOG_(INFO) << "SetUpTestCase";
37 }
38
TearDownTestCase(void)39 void DkAssetDownloaderTest::TearDownTestCase(void)
40 {
41 GTEST_LOG_(INFO) << "TearDownTestCase";
42 }
43
SetUp(void)44 void DkAssetDownloaderTest::SetUp(void)
45 {
46 GTEST_LOG_(INFO) << "SetUp";
47 }
48
TearDown(void)49 void DkAssetDownloaderTest::TearDown(void)
50 {
51 GTEST_LOG_(INFO) << "TearDown";
52 }
53
54 /**
55 * @tc.name: DownLoadAssets001
56 * @tc.desc: Verify the DKAssetsDownloader::DownLoadAssets function
57 * @tc.type: FUNC
58 * @tc.require: SR000HRKKA
59 */
60 HWTEST_F(DkAssetDownloaderTest, DownLoadAssets001, TestSize.Level1)
61 {
62 std::shared_ptr<DKDatabase> database = nullptr;
63 std::shared_ptr<DKContext> context = nullptr;
64 std::vector<DKDownloadAsset> assetsToDownload;
65 DKAssetPath downLoadPath = "";
66 DKDownloadId id = 0;
67
68 std::function<void(std::shared_ptr<DKContext>,
69 std::shared_ptr<const DKDatabase>,
70 const std::map<DKDownloadAsset, DKDownloadResult> &,
71 const DKError &)> resultCallback = nullptr;
72 std::function<void(std::shared_ptr<DKContext>,
73 DKDownloadAsset,
74 TotalSize,
75 DownloadSize)> progressCallback = nullptr;
76
77 DKAssetsDownloader mDkDownloader(database);
78 DKLocalErrorCode ret = mDkDownloader.DownLoadAssets(context, assetsToDownload,
79 downLoadPath, id, resultCallback, progressCallback);
80 EXPECT_EQ(ret, DKLocalErrorCode::NO_ERROR);
81 }
82
83 /**
84 * @tc.name: DownLoadAssets002
85 * @tc.desc: Verify the DKAssetsDownloader::DownLoadAssets function
86 * @tc.type: FUNC
87 * @tc.require: SR000HRKKA
88 */
89 HWTEST_F(DkAssetDownloaderTest, DownLoadAssets002, TestSize.Level1)
90 {
91 std::shared_ptr<DKDatabase> database = nullptr;
92 DKDownloadAsset assetsToDownload;
93 DKAssetsDownloader mDkDownloader(database);
94 DKLocalErrorCode ret = mDkDownloader.DownLoadAssets(assetsToDownload);
95 EXPECT_EQ(ret, DKLocalErrorCode::NO_ERROR);
96 }
97
98 /**
99 * @tc.name: CancelDownloadAssets
100 * @tc.desc: Verify the DKAssetsDownloader::CancelDownloadAssets function
101 * @tc.type: FUNC
102 * @tc.require: SR000HRKKA
103 */
104 HWTEST_F(DkAssetDownloaderTest, CancelDownloadAssets, TestSize.Level1)
105 {
106 std::shared_ptr<DKDatabase> database = nullptr;
107 DKDownloadId id = 0;
108 DKAssetsDownloader mDkDownloader(database);
109 DKLocalErrorCode ret = mDkDownloader.CancelDownloadAssets(id);
110 EXPECT_EQ(ret, DKLocalErrorCode::NO_ERROR);
111 }
112 } // namespace OHOS::FileManagement::CloudSync::Test
113