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 #include <sys/stat.h>
19 #include <fcntl.h>
20 #include "cloud_daemon_manager_impl.h"
21 #include "cloud_daemon_service_proxy.h"
22 #include "dfs_error.h"
23 #include "utils_log.h"
24 
25 namespace OHOS::FileManagement::CloudFile::Test {
26 using namespace testing;
27 using namespace testing::ext;
28 using namespace std;
29 
30 class CloudDaemonManagerImplTest : public testing::Test {
31 public:
32     static void SetUpTestCase(void);
33     static void TearDownTestCase(void);
34     void SetUp();
35     void TearDown();
36     std::shared_ptr<CloudDaemonManagerImpl> cloudDaemonManagerImpl_;
37 };
38 
SetUpTestCase(void)39 void CloudDaemonManagerImplTest::SetUpTestCase(void)
40 {
41     GTEST_LOG_(INFO) << "SetUpTestCase";
42 }
43 
TearDownTestCase(void)44 void CloudDaemonManagerImplTest::TearDownTestCase(void)
45 {
46     GTEST_LOG_(INFO) << "TearDownTestCase";
47 }
48 
SetUp(void)49 void CloudDaemonManagerImplTest::SetUp(void)
50 {
51     cloudDaemonManagerImpl_ = std::make_shared<CloudDaemonManagerImpl>();
52     GTEST_LOG_(INFO) << "SetUp";
53 }
54 
TearDown(void)55 void CloudDaemonManagerImplTest::TearDown(void)
56 {
57     GTEST_LOG_(INFO) << "TearDown";
58 }
59 
60 /**
61  * @tc.name: GetInstanceTest
62  * @tc.desc: Verify the GetInstance function
63  * @tc.type: FUNC
64  * @tc.require: I6H5MH
65  */
66 HWTEST_F(CloudDaemonManagerImplTest, GetInstanceTest, TestSize.Level1)
67 {
68     GTEST_LOG_(INFO) << "GetInstanceTest Start";
69     try {
70         CloudDaemonManagerImpl::GetInstance();
71     } catch (...) {
72         EXPECT_TRUE(false);
73         GTEST_LOG_(INFO) << "GetInstanceTest  ERROR";
74     }
75     GTEST_LOG_(INFO) << "GetInstanceTest End";
76 }
77 
78 /**
79  * @tc.name: StartFuseTest
80  * @tc.desc: Verify the StartFuse function
81  * @tc.type: FUNC
82  * @tc.require: I6H5MH
83  */
84 HWTEST_F(CloudDaemonManagerImplTest, StartFuseTest, TestSize.Level1)
85 {
86     GTEST_LOG_(INFO) << "StartFuseTest Start";
87     try {
88         int32_t devFd = -1;
89         string path = "path";
90         int32_t userId = 100;
91         auto res = CloudDaemonManagerImpl::GetInstance().StartFuse(userId, devFd, path);
92         EXPECT_EQ(res, E_SA_LOAD_FAILED);
93     } catch (...) {
94         EXPECT_TRUE(false);
95         GTEST_LOG_(INFO) << "StartFuse  ERROR";
96     }
97     GTEST_LOG_(INFO) << "StartFuse End";
98 }
99 
100 } // namespace OHOS::FileManagement::CloudSync::Test