• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 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 <gtest/gtest.h>
17 #define private public
18 #define protected public
19 #include "background_task_observer.h"
20 #undef private
21 #undef protected
22 
23 using namespace testing::ext;
24 using namespace OHOS::BackgroundTaskMgr;
25 
26 namespace OHOS {
27 namespace AAFwk {
28 class BackgroundTaskObserverTest : public testing::Test {
29 public:
30     static void SetUpTestCase(void);
31     static void TearDownTestCase(void);
32     void SetUp();
33     void TearDown();
34     std::shared_ptr<BackgroundTaskObserver> observer_ {nullptr};
35 };
36 
SetUpTestCase(void)37 void BackgroundTaskObserverTest::SetUpTestCase(void)
38 {}
TearDownTestCase(void)39 void BackgroundTaskObserverTest::TearDownTestCase(void)
40 {}
TearDown(void)41 void BackgroundTaskObserverTest::TearDown(void)
42 {}
SetUp()43 void BackgroundTaskObserverTest::SetUp()
44 {
45     observer_ = std::make_shared<BackgroundTaskObserver>();
46 }
47 
48 /*
49  * Feature: BackgroundTaskObserver
50  * Function: OnContinuousTaskStart
51  * SubFunction: NA
52  * FunctionPoints: BackgroundTaskObserver OnContinuousTaskStart
53  * EnvConditions: NA
54  * CaseDescription: Verify OnContinuousTaskStart
55  */
56 HWTEST_F(BackgroundTaskObserverTest, OnContinuousTaskStart_001, TestSize.Level1)
57 {
58     std::shared_ptr<ContinuousTaskCallbackInfo> info = std::make_shared<ContinuousTaskCallbackInfo>();
59     observer_->OnContinuousTaskStart(info);
60 }
61 
62 /*
63  * Feature: BackgroundTaskObserver
64  * Function: OnContinuousTaskStart
65  * SubFunction: NA
66  * FunctionPoints: BackgroundTaskObserver OnContinuousTaskStart
67  * EnvConditions: NA
68  * CaseDescription: Verify OnContinuousTaskStart
69  */
70 HWTEST_F(BackgroundTaskObserverTest, OnContinuousTaskStart_002, TestSize.Level1)
71 {
72     std::shared_ptr<ContinuousTaskCallbackInfo> info = std::make_shared<ContinuousTaskCallbackInfo>();
73     observer_->GetAppManager();
74     observer_->OnContinuousTaskStart(info);
75 }
76 
77 /*
78  * Feature: BackgroundTaskObserver
79  * Function: OnContinuousTaskStop
80  * SubFunction: NA
81  * FunctionPoints: BackgroundTaskObserver OnContinuousTaskStop
82  * EnvConditions: NA
83  * CaseDescription: Verify OnContinuousTaskStop
84  */
85 HWTEST_F(BackgroundTaskObserverTest, OnContinuousTaskStop_001, TestSize.Level1)
86 {
87     std::shared_ptr<ContinuousTaskCallbackInfo> info = std::make_shared<ContinuousTaskCallbackInfo>();
88     observer_->OnContinuousTaskStop(info);
89 }
90 
91 /*
92  * Feature: BackgroundTaskObserver
93  * Function: OnContinuousTaskStop
94  * SubFunction: NA
95  * FunctionPoints: BackgroundTaskObserver OnContinuousTaskStop
96  * EnvConditions: NA
97  * CaseDescription: Verify OnContinuousTaskStop
98  */
99 HWTEST_F(BackgroundTaskObserverTest, OnContinuousTaskStop_002, TestSize.Level1)
100 {
101     std::shared_ptr<ContinuousTaskCallbackInfo> info = std::make_shared<ContinuousTaskCallbackInfo>();
102     observer_->GetAppManager();
103     observer_->OnContinuousTaskStop(info);
104 }
105 
106 /*
107  * Feature: BackgroundTaskObserver
108  * Function: OnRemoteDied
109  * SubFunction: NA
110  * FunctionPoints: BackgroundTaskObserver OnRemoteDied
111  * EnvConditions: NA
112  * CaseDescription: Verify OnRemoteDied
113  */
114 HWTEST_F(BackgroundTaskObserverTest, OnRemoteDied_001, TestSize.Level1)
115 {
116     wptr<IRemoteObject> object;
117     observer_->OnRemoteDied(object);
118 }
119 
120 /*
121  * Feature: BackgroundTaskObserver
122  * Function: IsBackgroundTaskUid
123  * SubFunction: NA
124  * FunctionPoints: BackgroundTaskObserver IsBackgroundTaskUid
125  * EnvConditions: NA
126  * CaseDescription: Verify IsBackgroundTaskUid
127  */
128 HWTEST_F(BackgroundTaskObserverTest, IsBackgroundTaskUid_001, TestSize.Level1)
129 {
130     int uid = 0;
131     bool res = observer_->IsBackgroundTaskUid(uid);
132     EXPECT_FALSE(res);
133 }
134 
135 /*
136  * Feature: BackgroundTaskObserver
137  * Function: IsBackgroundTaskUid
138  * SubFunction: NA
139  * FunctionPoints: BackgroundTaskObserver IsBackgroundTaskUid
140  * EnvConditions: NA
141  * CaseDescription: Verify IsBackgroundTaskUid
142  */
143 HWTEST_F(BackgroundTaskObserverTest, IsBackgroundTaskUid_002, TestSize.Level1)
144 {
145     int uid = 0;
146     observer_->bgTaskUids_.push_front(uid);
147     bool res = observer_->IsBackgroundTaskUid(uid);
148     EXPECT_TRUE(res);
149 }
150 }  // namespace AAFwk
151 }  // namespace OHOS
152