1 /* 2 * Copyright (c) 2020 The WebRTC project authors. All Rights Reserved. 3 * 4 * Use of this source code is governed by a BSD-style license 5 * that can be found in the LICENSE file in the root of the source 6 * tree. An additional intellectual property rights grant can be found 7 * in the file PATENTS. All contributing project authors may 8 * be found in the AUTHORS file in the root of the source tree. 9 */ 10 11 #ifndef AUDIO_VOIP_TEST_MOCK_TASK_QUEUE_H_ 12 #define AUDIO_VOIP_TEST_MOCK_TASK_QUEUE_H_ 13 14 #include <memory> 15 16 #include "api/task_queue/task_queue_factory.h" 17 #include "api/task_queue/test/mock_task_queue_base.h" 18 #include "test/gmock.h" 19 20 namespace webrtc { 21 22 // MockTaskQueue enables immediate task run from global TaskQueueBase. 23 // It's necessary for some tests depending on TaskQueueBase internally. 24 class MockTaskQueue : public MockTaskQueueBase { 25 public: MockTaskQueue()26 MockTaskQueue() : current_(this) {} 27 28 // Delete is deliberately defined as no-op as MockTaskQueue is expected to 29 // hold onto current global TaskQueueBase throughout the testing. Delete()30 void Delete() override {} 31 32 private: 33 CurrentTaskQueueSetter current_; 34 }; 35 36 class MockTaskQueueFactory : public TaskQueueFactory { 37 public: MockTaskQueueFactory(MockTaskQueue * task_queue)38 explicit MockTaskQueueFactory(MockTaskQueue* task_queue) 39 : task_queue_(task_queue) {} 40 CreateTaskQueue(absl::string_view name,Priority priority)41 std::unique_ptr<TaskQueueBase, TaskQueueDeleter> CreateTaskQueue( 42 absl::string_view name, 43 Priority priority) const override { 44 // Default MockTaskQueue::Delete is no-op, therefore it's safe to pass the 45 // raw pointer. 46 return std::unique_ptr<TaskQueueBase, TaskQueueDeleter>(task_queue_); 47 } 48 49 private: 50 MockTaskQueue* task_queue_; 51 }; 52 53 } // namespace webrtc 54 55 #endif // AUDIO_VOIP_TEST_MOCK_TASK_QUEUE_H_ 56