Flutter Engine
stub_flutter_api.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 "flutter/shell/platform/common/cpp/client_wrapper/testing/stub_flutter_api.h"
6 
8 
9 namespace flutter {
10 namespace testing {
11 
12 // static
14  s_stub_implementation = stub;
15 }
16 
17 // static
19  return s_stub_implementation;
20 }
21 
22 ScopedStubFlutterApi::ScopedStubFlutterApi(std::unique_ptr<StubFlutterApi> stub)
23  : stub_(std::move(stub)) {
24  previous_stub_ = StubFlutterApi::GetTestStub();
25  StubFlutterApi::SetTestStub(stub_.get());
26 }
27 
29  StubFlutterApi::SetTestStub(previous_stub_);
30 }
31 
32 } // namespace testing
33 } // namespace flutter
34 
35 // Forwarding dummy implementations of the C API.
36 
39  // The stub ignores this, so just return an arbitrary non-zero value.
40  return reinterpret_cast<FlutterDesktopMessengerRef>(1);
41 }
42 
46  if (s_stub_implementation) {
47  s_stub_implementation->PluginRegistrarSetDestructionHandler(callback);
48  }
49 }
50 
52  const char* channel,
53  const uint8_t* message,
54  const size_t message_size) {
55  bool result = false;
56  if (s_stub_implementation) {
57  result =
58  s_stub_implementation->MessengerSend(channel, message, message_size);
59  }
60  return result;
61 }
62 
64  const char* channel,
65  const uint8_t* message,
66  const size_t message_size,
67  const FlutterDesktopBinaryReply reply,
68  void* user_data) {
69  bool result = false;
70  if (s_stub_implementation) {
71  result = s_stub_implementation->MessengerSendWithReply(
72  channel, message, message_size, reply, user_data);
73  }
74  return result;
75 }
76 
80  const uint8_t* data,
81  size_t data_length) {
82  if (s_stub_implementation) {
83  s_stub_implementation->MessengerSendResponse(handle, data, data_length);
84  }
85 }
86 
88  const char* channel,
90  void* user_data) {
91  if (s_stub_implementation) {
92  s_stub_implementation->MessengerSetCallback(channel, callback, user_data);
93  }
94 }
virtual void PluginRegistrarSetDestructionHandler(FlutterDesktopOnPluginRegistrarDestroyed callback)
static StubFlutterApi * GetTestStub()
FlutterDesktopMessengerRef FlutterDesktopPluginRegistrarGetMessenger(FlutterDesktopPluginRegistrarRef registrar)
virtual bool MessengerSend(const char *channel, const uint8_t *message, const size_t message_size)
Definition: ref_ptr.h:252
virtual bool MessengerSendWithReply(const char *channel, const uint8_t *message, const size_t message_size, const FlutterDesktopBinaryReply reply, void *user_data)
static void SetTestStub(StubFlutterApi *stub)
bool FlutterDesktopMessengerSendWithReply(FlutterDesktopMessengerRef messenger, const char *channel, const uint8_t *message, const size_t message_size, const FlutterDesktopBinaryReply reply, void *user_data)
G_BEGIN_DECLS FlValue gpointer user_data
void FlutterDesktopMessengerSendResponse(FlutterDesktopMessengerRef messenger, const FlutterDesktopMessageResponseHandle *handle, const uint8_t *data, size_t data_length)
void(* FlutterDesktopBinaryReply)(const uint8_t *data, size_t data_size, void *user_data)
void(* FlutterDesktopOnPluginRegistrarDestroyed)(FlutterDesktopPluginRegistrarRef)
static flutter::testing::StubFlutterApi * s_stub_implementation
virtual void MessengerSetCallback(const char *channel, FlutterDesktopMessageCallback callback, void *user_data)
void FlutterDesktopMessengerSetCallback(FlutterDesktopMessengerRef messenger, const char *channel, FlutterDesktopMessageCallback callback, void *user_data)
void(* FlutterDesktopMessageCallback)(FlutterDesktopMessengerRef, const FlutterDesktopMessage *, void *)
virtual void MessengerSendResponse(const FlutterDesktopMessageResponseHandle *handle, const uint8_t *data, size_t data_length)
void FlutterDesktopPluginRegistrarSetDestructionHandler(FlutterDesktopPluginRegistrarRef registrar, FlutterDesktopOnPluginRegistrarDestroyed callback)
ScopedStubFlutterApi(std::unique_ptr< StubFlutterApi > stub)
bool FlutterDesktopMessengerSend(FlutterDesktopMessengerRef messenger, const char *channel, const uint8_t *message, const size_t message_size)