• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/callback.h>
20 
21 #include <map>
22 
23 #include "osi/include/log.h"
24 
25 std::queue<base::OnceClosure> do_in_jni_thread_task_queue;
26 
run_one_jni_thread_task()27 void run_one_jni_thread_task() {
28   ASSERT_LOG(do_in_jni_thread_task_queue.size(),
29              "JNI thread has no closures to execute");
30   base::OnceCallback callback = std::move(do_in_jni_thread_task_queue.front());
31   do_in_jni_thread_task_queue.pop();
32   std::move(callback).Run();
33 }
34 
run_all_jni_thread_task()35 void run_all_jni_thread_task() {
36   while (do_in_jni_thread_task_queue.size()) run_one_jni_thread_task();
37 }
38 
reset_mock_jni_thread_queue()39 void reset_mock_jni_thread_queue() {
40   while (do_in_jni_thread_task_queue.size()) do_in_jni_thread_task_queue.pop();
41 }
42