• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2022 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 "safe_keeper.h"
17 #include <gtest/gtest.h>
18 
19 namespace {
20 using namespace testing::ext;
21 using namespace OHOS::MMI;
22 
23 class SafeKeeperTest : public testing::Test {
24 public:
SetUpTestCase(void)25     static void SetUpTestCase(void) {}
TearDownTestCase(void)26     static void TearDownTestCase(void) {}
27 };
28 
29 class SafeKeeperUnitTest : public SafeKeeper {
30 public:
IsExistUnitTest(uint64_t tid) const31     bool IsExistUnitTest(uint64_t tid) const
32     {
33         return IsExist(tid);
34     }
GetEventUnitTest(uint64_t tid)35     SafeEvent *GetEventUnitTest(uint64_t tid)
36     {
37         return GetEvent(tid);
38     }
39 };
40 
Fun(uint32_t kId,uint64_t tId,const std::string & strId)41 void Fun(uint32_t kId, uint64_t tId, const std::string& strId)
42 {
43 }
44 
45 HWTEST_F(SafeKeeperTest, Single_RegisterEvent_001, TestSize.Level1)
46 {
47     SafeKpr->Init(Fun);
48     bool retResult = SafeKpr->RegisterEvent(1, "123");
49     ASSERT_TRUE(retResult);
50 }
51 
52 HWTEST_F(SafeKeeperTest, Single_RegisterEvent_002, TestSize.Level1)
53 {
54     SafeKpr->Init(Fun);
55     bool retResult = SafeKpr->RegisterEvent(0, "777");
56     ASSERT_TRUE(retResult);
57 }
58 
59 HWTEST_F(SafeKeeperTest, Single_ReportHealthStatus_001, TestSize.Level1)
60 {
61     SafeKpr->ReportHealthStatus(1001);
62 }
63 
64 HWTEST_F(SafeKeeperTest, Single_ReportHealthStatus_002, TestSize.Level1)
65 {
66     SafeKpr->ReportHealthStatus(-1001);
67 }
68 
69 HWTEST_F(SafeKeeperTest, Single_ProcessEvents, TestSize.Level1)
70 {
71     SafeKpr->ProcessEvents();
72 }
73 
74 HWTEST_F(SafeKeeperTest, Single_ClearAll, TestSize.Level1)
75 {
76     SafeKpr->ClearAll();
77 }
78 
79 HWTEST_F(SafeKeeperTest, Init, TestSize.Level1)
80 {
81     SafeKeeperUnitTest safObj;
82     safObj.Init(Fun);
83 }
84 
85 HWTEST_F(SafeKeeperTest, RegisterEvent_001, TestSize.Level1)
86 {
87     SafeKeeperUnitTest safObj;
88     safObj.Init(Fun);
89     bool retResult = safObj.RegisterEvent(1, "333");
90     EXPECT_TRUE(retResult);
91 }
92 
93 HWTEST_F(SafeKeeperTest, RegisterEvent_002, TestSize.Level1)
94 {
95     SafeKeeperUnitTest safObj;
96     safObj.Init(Fun);
97     bool retResult = safObj.RegisterEvent(0, "#$2111");
98     EXPECT_TRUE(retResult);
99 }
100 
101 HWTEST_F(SafeKeeperTest, ReportHealthStatus_001, TestSize.Level1)
102 {
103     SafeKeeperUnitTest safObj;
104     safObj.Init(Fun);
105     safObj.ReportHealthStatus(1);
106 }
107 
108 HWTEST_F(SafeKeeperTest, ReportHealthStatus_002, TestSize.Level1)
109 {
110     SafeKeeperUnitTest safObj;
111     safObj.Init(Fun);
112     safObj.ReportHealthStatus(-1001);
113 }
114 
115 HWTEST_F(SafeKeeperTest, ProcessEvents, TestSize.Level1)
116 {
117     SafeKeeperUnitTest safObj;
118     safObj.Init(Fun);
119     safObj.ProcessEvents();
120 }
121 
122 HWTEST_F(SafeKeeperTest, IsExist_001, TestSize.Level1)
123 {
124     SafeKeeperUnitTest safObj;
125     safObj.Init(Fun);
126     bool retResult = safObj.IsExistUnitTest(1001);
127     EXPECT_FALSE(retResult);
128 }
129 
130 HWTEST_F(SafeKeeperTest, IsExist_002, TestSize.Level1)
131 {
132     SafeKeeperUnitTest safObj;
133     safObj.Init(Fun);
134     bool retResult = safObj.IsExistUnitTest(-1001);
135     EXPECT_FALSE(retResult);
136 }
137 
138 HWTEST_F(SafeKeeperTest, GetEvent_001, TestSize.Level1)
139 {
140     SafeKeeperUnitTest safObj;
141     safObj.Init(Fun);
142     auto retResult = safObj.GetEventUnitTest(1);
143     EXPECT_TRUE(retResult == nullptr);
144 }
145 
146 HWTEST_F(SafeKeeperTest, GetEvent_002, TestSize.Level1)
147 {
148     SafeKeeperUnitTest safObj;
149     safObj.Init(Fun);
150     auto retResult = safObj.GetEventUnitTest(-1001);
151     EXPECT_TRUE(retResult == nullptr);
152 }
153 } // namespace
154