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)41void CloudDaemonTest::SetUpTestCase(void) 42 { 43 GTEST_LOG_(INFO) << "SetUpTestCase"; 44 } 45 TearDownTestCase(void)46void CloudDaemonTest::TearDownTestCase(void) 47 { 48 GTEST_LOG_(INFO) << "TearDownTestCase"; 49 } 50 SetUp(void)51void 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)59void 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 } // namespace OHOS::FileManagement::CloudSync::Test