1 /* 2 * Copyright 2022 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #include "test/common/jni_thread.h" 18 19 #include <base/functional/callback.h> 20 #include <bluetooth/log.h> 21 22 #include <map> 23 24 #include "os/log.h" 25 26 std::queue<base::OnceClosure> do_in_jni_thread_task_queue; 27 run_one_jni_thread_task()28void run_one_jni_thread_task() { 29 bluetooth::log::assert_that(do_in_jni_thread_task_queue.size(), 30 "JNI thread has no closures to execute"); 31 base::OnceCallback callback = std::move(do_in_jni_thread_task_queue.front()); 32 do_in_jni_thread_task_queue.pop(); 33 std::move(callback).Run(); 34 } 35 run_all_jni_thread_task()36void run_all_jni_thread_task() { 37 while (do_in_jni_thread_task_queue.size()) run_one_jni_thread_task(); 38 } 39 reset_mock_jni_thread_queue()40void reset_mock_jni_thread_queue() { 41 while (do_in_jni_thread_task_queue.size()) do_in_jni_thread_task_queue.pop(); 42 } 43