56class MockLogSink :
public component_testing::LocalComponentImpl,
57 public fidl::Server<fuchsia_logger::LogSink> {
59 MockLogSink(fit::closure quitLoop, async_dispatcher_t* dispatcher)
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;
93 fit::closure quit_loop_;
94 async_dispatcher_t* dispatcher_;
95 fidl::ServerBindingGroup<fuchsia_logger::LogSink> bindings_;
96 std::optional<WaitForInterestChangeCompleter::Async> completer_;
101 auto realm_builder = component_testing::RealmBuilder::Create();
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());