• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 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 <functional>
17 #include <gtest/gtest.h>
18 
19 #include "conditions/timer_listener.h"
20 #include "work_scheduler_service.h"
21 #include "work_queue_manager.h"
22 
23 using namespace OHOS::AppExecFwk;
24 using namespace testing::ext;
25 
26 namespace OHOS {
27 namespace WorkScheduler {
28 
29 const std::string WORKSCHEDULER_SERVICE_NAME = "WorkSchedulerService";
30 
31 class TimerListenerTest : public testing::Test {
32 public:
33     static void SetUpTestCase();
TearDownTestCase()34     static void TearDownTestCase() {};
SetUp()35     void SetUp() {};
TearDown()36     void TearDown() {};
37     static std::shared_ptr<WorkQueueManager> workQueueManager_;
38     static std::shared_ptr<TimerListener> timerListener_;
39 };
40 
41 std::shared_ptr<WorkQueueManager> TimerListenerTest::workQueueManager_ = nullptr;
42 std::shared_ptr<TimerListener> TimerListenerTest::timerListener_ = nullptr;
43 
SetUpTestCase()44 void TimerListenerTest::SetUpTestCase()
45 {
46     std::shared_ptr<WorkSchedulerService> workSchedulerService_ = std::make_shared<WorkSchedulerService>();
47     workQueueManager_ = std::make_shared<WorkQueueManager>(workSchedulerService_);
48     std::shared_ptr<AppExecFwk::EventRunner> eventRunner_ = AppExecFwk::EventRunner::Create(WORKSCHEDULER_SERVICE_NAME,
49         AppExecFwk::ThreadMode::FFRT);
50     timerListener_ = std::make_shared<TimerListener>(workQueueManager_, eventRunner_);
51 }
52 
53 /**
54  * @tc.name: OnConditionChanged_001
55  * @tc.desc: Test TimerListener OnConditionChanged.
56  * @tc.type: FUNC
57  * @tc.require: IB7RQR
58  */
59 HWTEST_F(TimerListenerTest, OnConditionChanged_001, TestSize.Level1)
60 {
61     timerListener_->Start();
62     bool ret = timerListener_->Stop();
63     EXPECT_TRUE(ret);
64 }
65 }
66 }