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 cloudDaemonManagerImpl_ = nullptr;
59 }
60
61 /**
62 * @tc.name: GetInstanceTest
63 * @tc.desc: Verify the GetInstance function
64 * @tc.type: FUNC
65 * @tc.require: I6H5MH
66 */
67 HWTEST_F(CloudDaemonManagerImplTest, GetInstanceTest, TestSize.Level0)
68 {
69 GTEST_LOG_(INFO) << "GetInstanceTest Start";
70 try {
71 CloudDaemonManagerImpl::GetInstance();
72 } catch (...) {
73 EXPECT_TRUE(false);
74 GTEST_LOG_(INFO) << "GetInstanceTest ERROR";
75 }
76 GTEST_LOG_(INFO) << "GetInstanceTest End";
77 }
78
79 /**
80 * @tc.name: StartFuseTest
81 * @tc.desc: Verify the StartFuse function
82 * @tc.type: FUNC
83 * @tc.require: I6H5MH
84 */
85 HWTEST_F(CloudDaemonManagerImplTest, StartFuseTest, TestSize.Level1)
86 {
87 GTEST_LOG_(INFO) << "StartFuseTest Start";
88 try {
89 int32_t devFd = -1;
90 string path = "path";
91 int32_t userId = 100;
92 auto res = CloudDaemonManagerImpl::GetInstance().StartFuse(userId, devFd, path);
93 #if CLOUD_ADAPTER_ENABLED
94 EXPECT_EQ(res, E_INVAL_ARG);
95 #else
96 EXPECT_EQ(res, E_SA_LOAD_FAILED);
97 #endif
98 } catch (...) {
99 EXPECT_TRUE(false);
100 GTEST_LOG_(INFO) << "StartFuse ERROR";
101 }
102 GTEST_LOG_(INFO) << "StartFuse End";
103 }
104
105 /**
106 * @tc.name: SetDeathRecipientTest
107 * @tc.desc: Verify the SetDeathRecipient function
108 * @tc.type: FUNC
109 * @tc.require: I6H5MH
110 */
111 HWTEST_F(CloudDaemonManagerImplTest, SetDeathRecipientTest, TestSize.Level1)
112 {
113 GTEST_LOG_(INFO) << "SetDeathRecipientTest Start";
114 try {
115 auto CloudDaemonServiceProxy = CloudDaemonServiceProxy::GetInstance();
116 #if CLOUD_ADAPTER_ENABLED
117 EXPECT_NE(CloudDaemonServiceProxy, nullptr);
118 auto remoteObject = CloudDaemonServiceProxy->AsObject();
119 EXPECT_NE(remoteObject, nullptr);
120 cloudDaemonManagerImpl_->SetDeathRecipient(remoteObject);
121 EXPECT_EQ(cloudDaemonManagerImpl_->isFirstCall_.test_and_set(), false);
122 EXPECT_NE(cloudDaemonManagerImpl_->deathRecipient_, nullptr);
123 #else
124 EXPECT_EQ(CloudDaemonServiceProxy, nullptr);
125 #endif
126 } catch (...) {
127 EXPECT_TRUE(false);
128 GTEST_LOG_(INFO) << "SetDeathRecipientTest ERROR";
129 }
130 GTEST_LOG_(INFO) << "SetDeathRecipientTest End";
131 }
132 } // namespace OHOS::FileManagement::CloudSync::Test