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 "ipc/cloud_daemon.h"
17
18 #include "iremote_object.h"
19 #include "system_ability_definition.h"
20
21 #include "dfs_error.h"
22 #include "fuse_manager/fuse_manager.h"
23 #include "utils_log.h"
24 #include <gmock/gmock.h>
25 #include <gtest/gtest.h>
26
27 namespace OHOS::FileManagement::CloudFile::Test {
28 using namespace testing;
29 using namespace testing::ext;
30 using namespace std;
31
32 class CloudDaemonTest : public testing::Test {
33 public:
34 static void SetUpTestCase(void);
35 static void TearDownTestCase(void);
36 void SetUp();
37 void TearDown();
38 std::shared_ptr<CloudDaemon> cloudDaemon_;
39 };
40
SetUpTestCase(void)41 void CloudDaemonTest::SetUpTestCase(void)
42 {
43 GTEST_LOG_(INFO) << "SetUpTestCase";
44 }
45
TearDownTestCase(void)46 void CloudDaemonTest::TearDownTestCase(void)
47 {
48 GTEST_LOG_(INFO) << "TearDownTestCase";
49 }
50
SetUp(void)51 void CloudDaemonTest::SetUp(void)
52 {
53 int32_t saID = FILEMANAGEMENT_CLOUD_DAEMON_SERVICE_SA_ID;
54 bool runOnCreate = true;
55 cloudDaemon_ = std::make_shared<CloudDaemon>(saID, runOnCreate);
56 GTEST_LOG_(INFO) << "SetUp";
57 }
58
TearDown(void)59 void CloudDaemonTest::TearDown(void)
60 {
61 GTEST_LOG_(INFO) << "TearDown";
62 }
63
64 /**
65 * @tc.name: OnStopTest
66 * @tc.desc: Verify the OnStop function
67 * @tc.type: FUNC
68 * @tc.require: I6H5MH
69 */
70 HWTEST_F(CloudDaemonTest, OnStopTest, TestSize.Level1)
71 {
72 GTEST_LOG_(INFO) << "OnStop Start";
73 try {
74 cloudDaemon_->state_ = ServiceRunningState::STATE_NOT_START;
75 cloudDaemon_->registerToService_ = false;
76 cloudDaemon_->OnStop();
77 EXPECT_TRUE(true);
78 } catch (...) {
79 EXPECT_TRUE(false);
80 GTEST_LOG_(INFO) << "OnStop ERROR";
81 }
82 GTEST_LOG_(INFO) << "OnStop End";
83 }
84
85 /**
86 * @tc.name: OnStartTest1
87 * @tc.desc: Verify the OnStart function
88 * @tc.type: FUNC
89 * @tc.require: I6H5MH
90 */
91 HWTEST_F(CloudDaemonTest, OnStartTest1, TestSize.Level1)
92 {
93 GTEST_LOG_(INFO) << "OnStart1 Start";
94 try {
95 cloudDaemon_->state_ = ServiceRunningState::STATE_RUNNING;
96 cloudDaemon_->OnStart();
97 EXPECT_TRUE(true);
98 } catch (...) {
99 EXPECT_TRUE(false);
100 GTEST_LOG_(INFO) << "OnStart1 ERROR";
101 }
102 GTEST_LOG_(INFO) << "OnStart1 End";
103 }
104
105 /**
106 * @tc.name: OnStartTest2
107 * @tc.desc: Verify the OnStart function
108 * @tc.type: FUNC
109 * @tc.require: I6H5MH
110 */
111 HWTEST_F(CloudDaemonTest, OnStartTest2, TestSize.Level1)
112 {
113 GTEST_LOG_(INFO) << "OnStart2 Start";
114 try {
115 cloudDaemon_->state_ = ServiceRunningState::STATE_NOT_START;
116 cloudDaemon_->OnStart();
117 EXPECT_TRUE(true);
118 } catch (...) {
119 EXPECT_TRUE(false);
120 GTEST_LOG_(INFO) << "OnStart2 ERROR";
121 }
122 GTEST_LOG_(INFO) << "OnStart2 End";
123 }
124 } // namespace OHOS::FileManagement::CloudSync::Test