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 #ifndef BUNDLE_ACTIVE_TEST_UTIL_H 17 #define BUNDLE_ACTIVE_TEST_UTIL_H 18 19 #include <thread> 20 #include <gtest/gtest.h> 21 22 #include "bundle_active_core.h" 23 #include "bundle_active_report_controller.h" 24 #include "bundle_active_group_controller.h" 25 26 namespace OHOS { 27 namespace DeviceUsageStats { 28 namespace BundleActiveTestUtil { TestInit()29std::shared_ptr<BundleActiveCore> TestInit() 30 { 31 std::shared_ptr<BundleActiveCore> bundleActiveCore = std::make_shared<BundleActiveCore>(); 32 bundleActiveCore->Init(); 33 bundleActiveCore->InitBundleGroupController(); 34 BundleActiveGroupController::GetInstance().Init(false); 35 return bundleActiveCore; 36 }; 37 TestDeInit()38void TestDeInit() 39 { 40 BundleActiveReportController::GetInstance().DeInit(); 41 BundleActiveGroupController::GetInstance().DeInit(); 42 auto activeGroupHandler = BundleActiveGroupController::GetInstance().activeGroupHandler_; 43 if (activeGroupHandler && activeGroupHandler->ffrtQueue_) { 44 auto handle = activeGroupHandler->ffrtQueue_->submit_h([]() {}); 45 activeGroupHandler->ffrtQueue_->wait(handle); 46 activeGroupHandler->ffrtQueue_.reset(); 47 } 48 auto activeReportHandler = BundleActiveReportController::GetInstance().activeReportHandler_; 49 if (activeReportHandler && activeReportHandler->ffrtQueue_) { 50 auto handle = activeReportHandler->ffrtQueue_->submit_h([]() {}); 51 activeReportHandler->ffrtQueue_->wait(handle); 52 activeReportHandler->ffrtQueue_.reset(); 53 } 54 int64_t sleepTimeEnd = 1; 55 std::this_thread::sleep_for(std::chrono::seconds(sleepTimeEnd)); 56 } 57 }; 58 59 60 } // namespace DeviceUsageStats 61 } 62 #endif // BUNDLE_ACTIVE_TEST_UTIL_H 63