chromium/base/message_loop/message_pump_glib_unittest.cc

// Copyright 2012 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifdef UNSAFE_BUFFERS_BUILD
// TODO(crbug.com/40284755): Remove this and spanify to fix the errors.
#pragma allow_unsafe_buffers
#endif

#include "base/message_loop/message_pump_glib.h"

#include <glib.h>
#include <math.h>

#include <algorithm>
#include <string_view>
#include <vector>

#include "base/files/file_util.h"
#include "base/functional/bind.h"
#include "base/functional/callback.h"
#include "base/functional/callback_helpers.h"
#include "base/logging.h"
#include "base/memory/ptr_util.h"
#include "base/memory/raw_ptr.h"
#include "base/memory/ref_counted.h"
#include "base/message_loop/message_pump_type.h"
#include "base/posix/eintr_wrapper.h"
#include "base/run_loop.h"
#include "base/synchronization/waitable_event.h"
#include "base/synchronization/waitable_event_watcher.h"
#include "base/task/current_thread.h"
#include "base/task/single_thread_task_executor.h"
#include "base/task/single_thread_task_runner.h"
#include "base/test/task_environment.h"
#include "base/test/trace_event_analyzer.h"
#include "base/threading/thread.h"
#include "build/build_config.h"
#include "testing/gtest/include/gtest/gtest.h"

namespace base {
namespace {

// This class injects dummy "events" into the GLib loop. When "handled" these
// events can run tasks. This is intended to mock gtk events (the corresponding
// GLib source runs at the same priority).
class EventInjector {};

GSourceFuncs EventInjector::SourceFuncs =;

void IncrementInt(int *value) {}

// Checks how many events have been processed by the injector.
void ExpectProcessedEvents(EventInjector* injector, int count) {}

// Posts a task on the current message loop.
void PostMessageLoopTask(const Location& from_here, OnceClosure task) {}

// Test fixture.
class MessagePumpGLibTest : public testing::Test {};

}  // namespace

TEST_F(MessagePumpGLibTest, TestQuit) {}

TEST_F(MessagePumpGLibTest, TestEventTaskInterleave) {}

TEST_F(MessagePumpGLibTest, TestWorkWhileWaitingForEvents) {}

TEST_F(MessagePumpGLibTest, TestEventsWhileWaitingForWork) {}

namespace {

// This class is a helper for the concurrent events / posted tasks test below.
// It will quit the main loop once enough tasks and events have been processed,
// while making sure there is always work to do and events in the queue.
class ConcurrentHelper : public RefCounted<ConcurrentHelper>  {};

}  // namespace

TEST_F(MessagePumpGLibTest, TestConcurrentEventPostedTask) {}

namespace {

void AddEventsAndDrainGLib(EventInjector* injector, OnceClosure on_drained) {}

}  // namespace

TEST_F(MessagePumpGLibTest, TestDrainingGLib) {}

namespace {

// Helper class that lets us run the GLib message loop.
class GLibLoopRunner : public RefCounted<GLibLoopRunner> {};

void TestGLibLoopInternal(EventInjector* injector, OnceClosure done) {}

void TestGtkLoopInternal(EventInjector* injector, OnceClosure done) {}

}  // namespace

TEST_F(MessagePumpGLibTest, TestGLibLoop) {}

TEST_F(MessagePumpGLibTest, TestGtkLoop) {}

namespace {

class NestedEventAnalyzer {};

}  // namespace

TEST_F(MessagePumpGLibTest, TestNativeNestedLoopWithoutDoWork) {}

// Tests for WatchFileDescriptor API
class MessagePumpGLibFdWatchTest : public testing::Test {};

namespace {

class BaseWatcher : public MessagePumpGlib::FdWatcher {};

class DeleteWatcher : public BaseWatcher {};

class StopWatcher : public BaseWatcher {};

void QuitMessageLoopAndStart(OnceClosure quit_closure) {}

class NestedPumpWatcher : public MessagePumpGlib::FdWatcher {};

class QuitWatcher : public DeleteWatcher {};

void WriteFDWrapper(const int fd,
                    const char* buf,
                    int size,
                    WaitableEvent* event) {}

}  // namespace

// Tests that MessagePumpGlib::FdWatcher::OnFileCanReadWithoutBlocking is not
// called for a READ_WRITE event, and that the controller is destroyed in
// OnFileCanWriteWithoutBlocking callback.
TEST_F(MessagePumpGLibFdWatchTest, DeleteWatcher) {}

// Tests that MessagePumpGlib::FdWatcher::OnFileCanReadWithoutBlocking is not
// called for a READ_WRITE event, when the watcher calls
// StopWatchingFileDescriptor in OnFileCanWriteWithoutBlocking callback.
TEST_F(MessagePumpGLibFdWatchTest, StopWatcher) {}

// Tests that FdWatcher works properly with nested loops.
TEST_F(MessagePumpGLibFdWatchTest, NestedPumpWatcher) {}

// Tests that MessagePumpGlib quits immediately when it is quit from
// libevent's event_base_loop().
TEST_F(MessagePumpGLibFdWatchTest, QuitWatcher) {}

}  // namespace base