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/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 }
95 
98  return reinterpret_cast<FlutterDesktopTextureRegistrarRef>(1);
99 }
100 
102  FlutterDesktopTextureRegistrarRef texture_registrar,
103  const FlutterDesktopTextureInfo* info) {
104  uint64_t result = -1;
105  if (s_stub_implementation) {
106  result =
107  s_stub_implementation->TextureRegistrarRegisterExternalTexture(info);
108  }
109  return result;
110 }
111 
113  FlutterDesktopTextureRegistrarRef texture_registrar,
114  int64_t texture_id) {
115  bool result = false;
116  if (s_stub_implementation) {
117  result = s_stub_implementation->TextureRegistrarUnregisterExternalTexture(
118  texture_id);
119  }
120  return result;
121 }
122 
124  FlutterDesktopTextureRegistrarRef texture_registrar,
125  int64_t texture_id) {
126  bool result = false;
127  if (s_stub_implementation) {
128  result = s_stub_implementation->TextureRegistrarMarkTextureFrameAvailable(
129  texture_id);
130  }
131  return result;
132 }
int64_t FlutterDesktopTextureRegistrarRegisterExternalTexture(FlutterDesktopTextureRegistrarRef texture_registrar, const FlutterDesktopTextureInfo *info)
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)
bool FlutterDesktopTextureRegistrarUnregisterExternalTexture(FlutterDesktopTextureRegistrarRef texture_registrar, int64_t texture_id)
void * user_data
Definition: ref_ptr.h:252
int64_t texture_id
GAsyncResult * result
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)
FlKeyEvent FlKeyResponderAsyncCallback callback
struct FlutterDesktopTextureRegistrar * FlutterDesktopTextureRegistrarRef
bool FlutterDesktopMessengerSendWithReply(FlutterDesktopMessengerRef messenger, const char *channel, const uint8_t *message, const size_t message_size, const FlutterDesktopBinaryReply reply, void *user_data)
FlutterDesktopTextureRegistrarRef FlutterDesktopRegistrarGetTextureRegistrar(FlutterDesktopPluginRegistrarRef registrar)
virtual bool TextureRegistrarMarkTextureFrameAvailable(int64_t texture_id)
void FlutterDesktopMessengerSendResponse(FlutterDesktopMessengerRef messenger, const FlutterDesktopMessageResponseHandle *handle, const uint8_t *data, size_t data_length)
virtual bool TextureRegistrarUnregisterExternalTexture(int64_t texture_id)
void(* FlutterDesktopBinaryReply)(const uint8_t *data, size_t data_size, void *user_data)
void(* FlutterDesktopOnPluginRegistrarDestroyed)(FlutterDesktopPluginRegistrarRef)
static flutter::testing::StubFlutterApi * s_stub_implementation
virtual int64_t TextureRegistrarRegisterExternalTexture(const FlutterDesktopTextureInfo *info)
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)
bool FlutterDesktopTextureRegistrarMarkExternalTextureFrameAvailable(FlutterDesktopTextureRegistrarRef texture_registrar, int64_t texture_id)
ScopedStubFlutterApi(std::unique_ptr< StubFlutterApi > stub)
bool FlutterDesktopMessengerSend(FlutterDesktopMessengerRef messenger, const char *channel, const uint8_t *message, const size_t message_size)