5#include <fidl/fuchsia.diagnostics/cpp/fidl.h>
6#include <fidl/fuchsia.logger/cpp/fidl.h>
7#include <lib/async-loop/cpp/loop.h>
8#include <lib/async-loop/default.h>
9#include <lib/async-loop/testing/cpp/real_loop.h>
10#include <lib/async/dispatcher.h>
11#include <lib/component/incoming/cpp/protocol.h>
12#include <lib/fidl/cpp/client.h>
13#include <lib/fidl/cpp/wire/channel.h>
14#include <lib/fidl/cpp/wire/connect_service.h>
15#include <lib/fit/defer.h>
16#include <lib/fit/result.h>
17#include <lib/sys/component/cpp/testing/realm_builder.h>
18#include <lib/sys/component/cpp/testing/realm_builder_types.h>
19#include <zircon/errors.h>
21#include "flutter/fml/log_settings.h"
22#include "flutter/fml/platform/fuchsia/log_interest_listener.h"
23#include "gtest/gtest.h"
31 public ::testing::Test {};
36 ::fuchsia_diagnostics::Interest interest;
37 interest.min_severity(::fuchsia_diagnostics::Severity::kTrace);
42 ::fuchsia_diagnostics::Interest interest;
48 ::fuchsia_diagnostics::Interest interest;
56class MockLogSink :
public component_testing::LocalComponentImpl,
57 public fidl::Server<fuchsia_logger::LogSink> {
60 : quit_loop_(
std::move(quitLoop)), dispatcher_(dispatcher) {}
63 WaitForInterestChangeCompleter::Sync& completer)
override {
66 fuchsia_logger::LogSinkWaitForInterestChangeResponse response = {
67 {.data = {{.min_severity = fuchsia_diagnostics::Severity::kWarn}}}};
68 completer.Reply(
fit::ok(response));
72 completer_.emplace(completer.ToAsync());
77 void Connect(fuchsia_logger::LogSinkConnectRequest& request,
78 ConnectCompleter::Sync& completer)
override {}
81 fuchsia_logger::LogSinkConnectStructuredRequest& request,
82 ConnectStructuredCompleter::Sync& completer)
override {}
85 ASSERT_EQ(outgoing()->AddProtocol<fuchsia_logger::LogSink>(
86 bindings_.CreateHandler(
this, dispatcher_,
87 fidl::kIgnoreBindingClosure)),
92 bool first_call_ =
true;
94 async_dispatcher_t* dispatcher_;
95 fidl::ServerBindingGroup<fuchsia_logger::LogSink> bindings_;
96 std::optional<WaitForInterestChangeCompleter::Async> completer_;
102 realm_builder.AddLocalChild(
kLogSink, [&]() {
103 return std::make_unique<MockLogSink>(QuitLoopClosure(), dispatcher());
105 realm_builder.AddRoute(component_testing::Route{
106 .capabilities = {component_testing::Protocol{
107 fidl::DiscoverableProtocolName<fuchsia_logger::LogSink>}},
108 .source = component_testing::ChildRef{
kLogSink},
109 .targets = {component_testing::ParentRef()}});
111 auto realm = realm_builder.Build(dispatcher());
112 auto cleanup = fit::defer([&]() {
113 bool complete =
false;
114 realm.Teardown([&](
auto result) { complete =
true; });
115 RunLoopUntil([&]() {
return complete; });
117 auto client_end = realm.component().Connect<fuchsia_logger::LogSink>();
118 ASSERT_TRUE(client_end.is_ok());
static sk_sp< Effect > Create()
static bool ok(int result)
static void HandleInterestChange(const fuchsia_diagnostics::Interest &interest)
void AsyncWaitForInterestChanged()
void Connect(fuchsia_logger::LogSinkConnectRequest &request, ConnectCompleter::Sync &completer) override
MockLogSink(fit::closure quitLoop, async_dispatcher_t *dispatcher)
void ConnectStructured(fuchsia_logger::LogSinkConnectStructuredRequest &request, ConnectStructuredCompleter::Sync &completer) override
void WaitForInterestChange(WaitForInterestChangeCompleter::Sync &completer) override
TEST_F(LogInterestListenerFuchsia, SeverityChanges)
static constexpr char kLogSink[]
constexpr LogSeverity kLogError
constexpr LogSeverity kLogInfo
std::function< void()> closure
constexpr LogSeverity kLogWarning