1 /*
2 * Copyright (c) 2024 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 #include <copy/file_copy_manager.h>
16 #include <copy/file_size_utils.h>
17 #include <gtest/gtest.h>
18 #include "dfs_error.h"
19
20 namespace OHOS::Storage::DistributedFile::Test {
21 using namespace OHOS::FileManagement;
22 using namespace testing;
23 using namespace testing::ext;
24 using namespace std;
25
26 class FileSizeUtilsTest : public testing::Test {
27 public:
28 static void SetUpTestCase(void);
29 static void TearDownTestCase(void);
30 void SetUp();
31 void TearDown();
32
33 uint64_t process = 0;
34 uint64_t fileSize = 0;
35 using callBack = std::function<void(uint64_t processSize, uint64_t totalFileSize)>;
__anon90ff2f580102(uint64_t processSize, uint64_t totalFileSize) 36 callBack listener = [&](uint64_t processSize, uint64_t totalFileSize) {
37 process = processSize;
38 fileSize = totalFileSize;
39 };
40 };
41
SetUpTestCase(void)42 void FileSizeUtilsTest::SetUpTestCase(void)
43 {
44 GTEST_LOG_(INFO) << "SetUpTestCase";
45 }
46
TearDownTestCase(void)47 void FileSizeUtilsTest::TearDownTestCase(void)
48 {
49 GTEST_LOG_(INFO) << "TearDownTestCase";
50 }
51
SetUp(void)52 void FileSizeUtilsTest::SetUp(void)
53 {
54 GTEST_LOG_(INFO) << "SetUp";
55 }
56
TearDown(void)57 void FileSizeUtilsTest::TearDown(void)
58 {
59 GTEST_LOG_(INFO) << "TearDown";
60 }
61
62 /**
63 * @tc.name: FileSizeUtils_0001
64 * @tc.desc: The execution of the GetSize failed.
65 * @tc.type: FUNC
66 * @tc.require: I7TDJK
67 */
68 HWTEST_F(FileSizeUtilsTest, FileSizeUtils_0001, TestSize.Level1)
69 {
70 GTEST_LOG_(INFO) << "FileSizeUtils_0001 Start";
71 string srcuri = "file://docs/storage/media/100/local/files/Docs/aa/";
72 string desturi = "file://docs/storage/media/100/local/files/Docs/aa1/";
73 bool isSrcUri = true;
74 auto ptr = std::make_shared<FileSizeUtils>();
75 int32_t ret = ptr->GetSize(srcuri, isSrcUri, fileSize);
76 EXPECT_EQ(ret, 2);
77 GTEST_LOG_(INFO) << "FileSizeUtils_0001 End";
78 }
79 }
80