Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit d762e857 authored by Treehugger Robot's avatar Treehugger Robot Committed by Automerger Merge Worker
Browse files

Merge "mockcify: Introduce TestCommonJniThread" am: b55263a2 am: 178c526e am: b6a66510

Original change: https://android-review.googlesource.com/c/platform/packages/modules/Bluetooth/+/1966108

Change-Id: Ibba9e54e5b5f032ddd4c12825f1ca83ba5e540a0
parents 0ec5489c b6a66510
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -286,6 +286,7 @@ filegroup {
filegroup {
  name: "TestMockBtif",
  srcs: [
      ":TestCommonJniThread",
      "mock/mock_btif*.cc",
  ],
}
@@ -402,6 +403,13 @@ filegroup {
  ],
}

filegroup {
  name: "TestCommonJniThread",
  srcs: [
      "common/jni_thread.cc",
  ],
}

filegroup {
  name: "TestCommonMainHandler",
  srcs: [
+41 −0
Original line number Diff line number Diff line
/*
 * Copyright 2022 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include "test/common/jni_thread.h"

#include <base/callback.h>

#include <map>

#include "osi/include/log.h"

std::queue<base::OnceClosure> do_in_jni_thread_task_queue;

void run_one_jni_thread_task() {
  ASSERT_LOG(do_in_jni_thread_task_queue.size(),
             "JNI thread has no closures to execute");
  base::OnceCallback callback = std::move(do_in_jni_thread_task_queue.front());
  do_in_jni_thread_task_queue.pop();
  std::move(callback).Run();
}

void run_all_jni_thread_task() {
  while (do_in_jni_thread_task_queue.size()) run_one_jni_thread_task();
}

void reset_mock_jni_thread_queue() {
  while (do_in_jni_thread_task_queue.size()) do_in_jni_thread_task_queue.pop();
}
+27 −0
Original line number Diff line number Diff line
/*
 * Copyright 2022 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#pragma once

#include <base/callback.h>

#include <queue>

extern std::queue<base::OnceClosure> do_in_jni_thread_task_queue;

void run_one_jni_thread_task();
void run_all_jni_thread_task();
void reset_mock_jni_thread_task_queue();
+3 −0
Original line number Diff line number Diff line
@@ -49,6 +49,7 @@ extern std::map<std::string, int> mock_function_count_map;
#include "stack/include/a2dp_api.h"
#include "stack/include/btm_api.h"
#include "stack/include/btm_ble_api.h"
#include "test/common/jni_thread.h"
#include "types/bluetooth/uuid.h"
#include "types/raw_address.h"

@@ -88,11 +89,13 @@ bt_status_t btif_transfer_context(tBTIF_CBACK* p_cback, uint16_t event,
}
bt_status_t do_in_jni_thread(base::OnceClosure task) {
  mock_function_count_map[__func__]++;
  do_in_jni_thread_task_queue.push(std::move(task));
  return BT_STATUS_SUCCESS;
}
bt_status_t do_in_jni_thread(const base::Location& from_here,
                             base::OnceClosure task) {
  mock_function_count_map[__func__]++;
  do_in_jni_thread_task_queue.push(std::move(task));
  return BT_STATUS_SUCCESS;
}
btbase::AbstractMessageLoop* get_jni_message_loop() {