• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 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_file_core.h"
17 
18 #include <gmock/gmock.h>
19 #include <gtest/gtest.h>
20 #include <sys/types.h>
21 #include <sys/xattr.h>
22 
23 #include "cloud_sync_manager.h"
24 #include "dfs_error.h"
25 #include "uri.h"
26 #include "utils_log.h"
27 
28 namespace OHOS::FileManagement::CloudDisk::Test {
29 using namespace testing;
30 using namespace testing::ext;
31 using namespace std;
32 using namespace OHOS::FileManagement::CloudSync;
33 
34 class CloudFileCoreTest : public testing::Test {
35 public:
36     static void SetUpTestCase(void);
37     static void TearDownTestCase(void);
38     void SetUp();
39     void TearDown();
40 };
41 
SetUpTestCase(void)42 void CloudFileCoreTest::SetUpTestCase(void)
43 {
44     GTEST_LOG_(INFO) << "SetUpTestCase";
45 }
46 
TearDownTestCase(void)47 void CloudFileCoreTest::TearDownTestCase(void)
48 {
49     GTEST_LOG_(INFO) << "TearDownTestCase";
50 }
51 
SetUp(void)52 void CloudFileCoreTest::SetUp(void)
53 {
54     GTEST_LOG_(INFO) << "SetUp";
55 }
56 
TearDown(void)57 void CloudFileCoreTest::TearDown(void)
58 {
59     GTEST_LOG_(INFO) << "TearDown";
60 }
61 
62 /**
63  * @tc.name: Constructor
64  * @tc.desc: Verify the CloudFileCore::Constructor function
65  * @tc.type: FUNC
66  */
67 HWTEST_F(CloudFileCoreTest, ConstructorTest1, TestSize.Level1)
68 {
69     auto data = CloudFileCore::Constructor();
70     EXPECT_TRUE(data.IsSuccess());
71 }
72 
73 /**
74  * @tc.name: DoOn
75  * @tc.desc: Verify the CloudFileCore::DoOn function
76  * @tc.type: FUNC
77  */
78 HWTEST_F(CloudFileCoreTest, DoOnTest1, TestSize.Level1)
79 {
80     CloudFileCore *download = CloudFileCore::Constructor().GetData().value();
81     auto callback = std::make_shared<CloudDownloadCallbackImplAni>();
82     std::string event = "progress";
83     auto ret = download->DoOn(event, callback);
84     EXPECT_TRUE(ret.IsSuccess());
85     const auto &err = ret.GetError();
86     int errorCode = err.GetErrNo();
87     EXPECT_EQ(errorCode, 0);
88 }
89 
90 /**
91  * @tc.name: DoOff
92  * @tc.desc: Verify the CloudFileCore::DoOff function
93  * @tc.type: FUNC
94  */
95 HWTEST_F(CloudFileCoreTest, DoOffTest1, TestSize.Level1)
96 {
97     CloudFileCore *download = CloudFileCore::Constructor().GetData().value();
98     std::string event = "progress";
99     auto ret = download->DoOff(event);
100     const auto &err = ret.GetError();
101     int errorCode = err.GetErrNo();
102     if (ret.IsSuccess()) {
103         EXPECT_EQ(errorCode, 0);
104     } else {
105         EXPECT_EQ(errorCode, OHOS::FileManagement::E_PERMISSION);
106     }
107 }
108 
109 /**
110  * @tc.name: DoStart
111  * @tc.desc: Verify the CloudFileCore::DoStart function
112  * @tc.type: FUNC
113  */
114 HWTEST_F(CloudFileCoreTest, DoStartTest1, TestSize.Level1)
115 {
116     CloudFileCore *download = CloudFileCore::Constructor().GetData().value();
117     std::string uri = "testuri";
118     auto ret = download->DoStart(uri);
119     const auto &err = ret.GetError();
120     int errorCode = err.GetErrNo();
121     if (ret.IsSuccess()) {
122         EXPECT_EQ(errorCode, 0);
123     } else {
124         EXPECT_EQ(errorCode, OHOS::FileManagement::E_PERMISSION);
125     }
126 }
127 
128 /**
129  * @tc.name: DoStop
130  * @tc.desc: Verify the CloudFileCore::DoStop function
131  * @tc.type: FUNC
132  */
133 HWTEST_F(CloudFileCoreTest, DoStopTest1, TestSize.Level1)
134 {
135     CloudFileCore *download = CloudFileCore::Constructor().GetData().value();
136     download->callback_ = std::make_shared<CloudDownloadCallbackImplAni>();
137     std::string uri = "testuri";
138     bool needClean = true;
139     auto ret = download->DoStop(uri, needClean);
140     const auto &err = ret.GetError();
141     int errorCode = err.GetErrNo();
142     if (ret.IsSuccess()) {
143         EXPECT_EQ(errorCode, 0);
144     } else {
145         EXPECT_EQ(errorCode, OHOS::FileManagement::E_PERMISSION);
146     }
147 }
148 
149 /**
150  * @tc.name: DoStop
151  * @tc.desc: Verify the CloudFileCore::DoStop function
152  * @tc.type: FUNC
153  */
154 HWTEST_F(CloudFileCoreTest, DoStopTest2, TestSize.Level1)
155 {
156     CloudFileCore *download = CloudFileCore::Constructor().GetData().value();
157     std::string uri = "testuri";
158     bool needClean = true;
159     auto ret = download->DoStop(uri, needClean);
160     EXPECT_FALSE(ret.IsSuccess());
161     const auto &err = ret.GetError();
162     int errorCode = err.GetErrNo();
163     EXPECT_EQ(errorCode, OHOS::FileManagement::FILEIO_SYS_CAP_TAG + E_INVAL_ARG);
164 }
165 } // namespace OHOS::FileManagement::CloudDisk::Test