• 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 
19 #include "dfs_error.h"
20 #include "ipc/daemon.h"
21 #include "iremote_object.h"
22 #include "system_ability_definition.h"
23 #include "utils_log.h"
24 
25 namespace OHOS::Storage::DistributedFile::Test {
26 using namespace testing;
27 using namespace testing::ext;
28 using namespace std;
29 
30 class DaemonTest : 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<Daemon> daemon_;
37 };
38 
SetUpTestCase(void)39 void DaemonTest::SetUpTestCase(void)
40 {
41     GTEST_LOG_(INFO) << "SetUpTestCase";
42 }
43 
TearDownTestCase(void)44 void DaemonTest::TearDownTestCase(void)
45 {
46     GTEST_LOG_(INFO) << "TearDownTestCase";
47 }
48 
SetUp(void)49 void DaemonTest::SetUp(void)
50 {
51     int32_t saID = FILEMANAGEMENT_DISTRIBUTED_FILE_DAEMON_SA_ID;
52     bool runOnCreate = true;
53     daemon_ = std::make_shared<Daemon>(saID, runOnCreate);
54     GTEST_LOG_(INFO) << "SetUp";
55 }
56 
TearDown(void)57 void DaemonTest::TearDown(void)
58 {
59     GTEST_LOG_(INFO) << "TearDown";
60 }
61 
62 /**
63  * @tc.name: OnStopTest
64  * @tc.desc: Verify the OnStop function
65  * @tc.type: FUNC
66  * @tc.require: I7M6L1
67  */
68 HWTEST_F(DaemonTest, OnStopTest, TestSize.Level1)
69 {
70     GTEST_LOG_(INFO) << "OnStop Start";
71     try {
72         daemon_->state_ = ServiceRunningState::STATE_NOT_START;
73         daemon_->registerToService_ = false;
74         daemon_->OnStop();
75         EXPECT_TRUE(true);
76     } catch (...) {
77         EXPECT_TRUE(false);
78         GTEST_LOG_(INFO) << "OnStop  ERROR";
79     }
80     GTEST_LOG_(INFO) << "OnStop End";
81 }
82 
83 } // namespace OHOS::Storage::DistributedFile::Test