• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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: SetDeathRecipientTest
80  * @tc.desc: Verify the SetDeathRecipient function
81  * @tc.type: FUNC
82  * @tc.require: I6H5MH
83  */
84 HWTEST_F(CloudDaemonManagerImplTest, SetDeathRecipientTest, TestSize.Level1)
85 {
86     GTEST_LOG_(INFO) << "SetDeathRecipientTest Start";
87     try {
88         auto CloudDaemonServiceProxy = CloudDaemonServiceProxy::GetInstance();
89         EXPECT_NE(CloudDaemonServiceProxy, nullptr);
90         auto remoteObject = CloudDaemonServiceProxy->AsObject();
91         EXPECT_NE(remoteObject, nullptr);
92         cloudDaemonManagerImpl_->SetDeathRecipient(remoteObject);
93         EXPECT_EQ(cloudDaemonManagerImpl_->isFirstCall_.test_and_set(), false);
94         EXPECT_NE(cloudDaemonManagerImpl_->deathRecipient_, nullptr);
95     } catch (...) {
96         EXPECT_TRUE(false);
97         GTEST_LOG_(INFO) << "SetDeathRecipientTest  ERROR";
98     }
99     GTEST_LOG_(INFO) << "SetDeathRecipientTest End";
100 }
101 } // namespace OHOS::FileManagement::CloudSync::Test