• 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 <gtest/gtest.h>
17 #include "task_handler_wrap.h"
18 
19 using namespace testing;
20 using namespace testing::ext;
21 
22 namespace OHOS {
23 namespace AAFwk {
24 
25 class TaskHandlerWrapTest : public testing::Test {
26 public:
27     static void SetUpTestCase(void);
28     static void TearDownTestCase(void);
29     void SetUp() override;
30     void TearDown() override;
31 
32     std::shared_ptr<TaskHandlerWrap> queueHandler_;
33     std::shared_ptr<TaskHandlerWrap> ffrtHandler_;
34 };
35 
SetUpTestCase(void)36 void TaskHandlerWrapTest::SetUpTestCase(void)
37 {}
TearDownTestCase(void)38 void TaskHandlerWrapTest::TearDownTestCase(void)
39 {}
SetUp()40 void TaskHandlerWrapTest::SetUp()
41 {
42     queueHandler_ = TaskHandlerWrap::CreateQueueHandler("TaskHandlerWrapTest");
43     ffrtHandler_ = TaskHandlerWrap::GetFfrtHandler();
44 }
TearDown()45 void TaskHandlerWrapTest::TearDown()
46 {
47     queueHandler_.reset();
48     ffrtHandler_.reset();
49 }
50 
51 /**
52  * @tc.name: QueueTest_0010
53  * @tc.desc: SubmitTask Test
54  * @tc.type: FUNC
55  */
56 HWTEST_F(TaskHandlerWrapTest, QueueTest_0010, TestSize.Level0)
57 {
58     int input = 0;
__anonfd9888790102() 59     auto taskHandle = queueHandler_->SubmitTask([&input]() {
60         input = 1;
61         });
62     EXPECT_TRUE(taskHandle);
63     taskHandle.Sync();
64     EXPECT_TRUE(input == 1);
65 }
66 
67 /**
68  * @tc.name: QueueTest_0020
69  * @tc.desc: SubmitTask with delay Test
70  * @tc.type: FUNC
71  */
72 HWTEST_F(TaskHandlerWrapTest, QueueTest_0020, TestSize.Level0)
73 {
74     int input = 0;
__anonfd9888790202() 75     auto taskHandle = queueHandler_->SubmitTask([&input]() {
76         input = 1;
77         }, 100);
78     EXPECT_TRUE(taskHandle);
79     taskHandle.Sync();
80     EXPECT_TRUE(input == 1);
81 }
82 
83 /**
84  * @tc.name: QueueTest_0030
85  * @tc.desc: SubmitTask Test
86  * @tc.type: FUNC
87  */
88 HWTEST_F(TaskHandlerWrapTest, QueueTest_0030, TestSize.Level0)
89 {
__anonfd9888790302() 90     auto taskHandle = queueHandler_->SubmitTask([]() {});
91     EXPECT_TRUE(taskHandle);
92     auto result = taskHandle.Cancel();
93     EXPECT_TRUE(result);
94 }
95 
96 /**
97  * @tc.name: QueueTest_0040
98  * @tc.desc: SubmitTask with delay Test
99  * @tc.type: FUNC
100  */
101 HWTEST_F(TaskHandlerWrapTest, QueueTest_0040, TestSize.Level0)
102 {
__anonfd9888790402() 103     auto taskHandle = queueHandler_->SubmitTask([]() {}, 100);
104     EXPECT_TRUE(taskHandle);
105     auto result = taskHandle.Cancel();
106     EXPECT_TRUE(result);
107 }
108 
109 /**
110  * @tc.name: FfrtTest_0010
111  * @tc.desc: SubmitTask Test
112  * @tc.type: FUNC
113  */
114 HWTEST_F(TaskHandlerWrapTest, FfrtTest_0010, TestSize.Level0)
115 {
116     int input = 0;
__anonfd9888790502() 117     auto taskHandle = ffrtHandler_->SubmitTask([&input]() {
118         input = 1;
119         });
120     EXPECT_TRUE(taskHandle);
121     taskHandle.Sync();
122     EXPECT_TRUE(input == 1);
123 }
124 
125 /**
126  * @tc.name: FfrtTest_0020
127  * @tc.desc: SubmitTask with delay Test
128  * @tc.type: FUNC
129  */
130 HWTEST_F(TaskHandlerWrapTest, FfrtTest_0020, TestSize.Level0)
131 {
132     int input = 0;
__anonfd9888790602() 133     auto taskHandle = ffrtHandler_->SubmitTask([&input]() {
134         input = 1;
135         }, 100);
136     EXPECT_TRUE(taskHandle);
137     taskHandle.Sync();
138     EXPECT_TRUE(input == 1);
139 }
140 
141 /**
142  * @tc.name: FfrtTest_0030
143  * @tc.desc: SubmitTask Test
144  * @tc.type: FUNC
145  */
146 HWTEST_F(TaskHandlerWrapTest, FfrtTest_0030, TestSize.Level0)
147 {
__anonfd9888790702() 148     auto taskHandle = ffrtHandler_->SubmitTask([]() {});
149     EXPECT_TRUE(taskHandle);
150     auto result = taskHandle.Cancel();
151     EXPECT_TRUE(result);
152 }
153 
154 /**
155  * @tc.name: FfrtTest_0040
156  * @tc.desc: SubmitTask with delay Test
157  * @tc.type: FUNC
158  */
159 HWTEST_F(TaskHandlerWrapTest, FfrtTest_0040, TestSize.Level0)
160 {
__anonfd9888790802() 161     auto taskHandle = ffrtHandler_->SubmitTask([]() {}, 100);
162     EXPECT_TRUE(taskHandle);
163     auto result = taskHandle.Cancel();
164     EXPECT_TRUE(result);
165 }
166 
167 }  // namespace AAFwk
168 }  // namespace OHOS
169