Flutter Engine
 
Loading...
Searching...
No Matches
fl_test_gtk_logs.cc
Go to the documentation of this file.
1// Copyright 2013 The Flutter Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "fl_test_gtk_logs.h"
6#include "gtest/gtest.h"
7
8namespace flutter {
9namespace testing {
10
11namespace {
12
13bool gtk_initialized = false;
14GLogWriterFunc log_writer_cb = nullptr;
15GLogLevelFlags fl_received_log_levels = static_cast<GLogLevelFlags>(0x0);
16
17GLogWriterOutput log_writer(GLogLevelFlags log_level,
18 const GLogField* fields,
19 gsize n_fields,
20 gpointer user_data) {
21 fl_received_log_levels =
22 static_cast<GLogLevelFlags>(log_level | fl_received_log_levels);
23 if (log_writer_cb == nullptr) {
24 return g_log_writer_default(log_level, fields, n_fields, user_data);
25 }
26 GLogWriterOutput result =
27 log_writer_cb(log_level, fields, n_fields, user_data);
28 if (result != G_LOG_WRITER_HANDLED) {
29 return g_log_writer_default(log_level, fields, n_fields, user_data);
30 }
31 return result;
32}
33
34} // namespace
35
36void fl_ensure_gtk_init(GLogWriterFunc writer) {
37 if (!gtk_initialized) {
38 gtk_init(0, nullptr);
39 g_log_set_writer_func(log_writer, nullptr, nullptr);
40 gtk_initialized = true;
41 }
43 log_writer_cb = writer;
44}
45
47 fl_received_log_levels = static_cast<GLogLevelFlags>(0x0);
48}
49
51 return fl_received_log_levels;
52}
53
54} // namespace testing
55} // namespace flutter
GLogLevelFlags fl_get_received_gtk_log_levels()
Returns the recorded log levels.
void fl_ensure_gtk_init(GLogWriterFunc writer)
Ensures that GTK has been initialized and starts monitoring logs.
void fl_reset_received_gtk_log_levels()
Resets the recorded log levels.