Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
stub_flutter_api.h
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#ifndef FLUTTER_SHELL_PLATFORM_COMMON_CLIENT_WRAPPER_TESTING_STUB_FLUTTER_API_H_
6#define FLUTTER_SHELL_PLATFORM_COMMON_CLIENT_WRAPPER_TESTING_STUB_FLUTTER_API_H_
7
8#include <memory>
9
10#include "flutter/shell/platform/common/public/flutter_messenger.h"
11#include "flutter/shell/platform/common/public/flutter_plugin_registrar.h"
12
13namespace flutter {
14namespace testing {
15
16// Base class for a object that provides test implementations of the APIs in
17// the headers in platform/common/public/.
18
19// Linking this class into a test binary will provide dummy forwarding
20// implementations of that C API, so that the wrapper can be tested separately
21// from the actual library.
23 public:
24 // Used by the callers to simulate a result from the engine when sending a
25 // message.
27
28 // Sets |stub| as the instance to which calls to the Flutter library C APIs
29 // will be forwarded.
30 static void SetTestStub(StubFlutterApi* stub);
31
32 // Returns the current stub, as last set by SetTestFlutterStub.
34
35 virtual ~StubFlutterApi() {}
36
37 // Called for FlutterDesktopPluginRegistrarSetDestructionHandler.
40
41 // Called for FlutterDesktopMessengerSend.
42 virtual bool MessengerSend(const char* channel,
43 const uint8_t* message,
44 const size_t message_size) {
46 }
47
48 // Called for FlutterDesktopMessengerSendWithReply.
49 virtual bool MessengerSendWithReply(const char* channel,
50 const uint8_t* message,
51 const size_t message_size,
52 const FlutterDesktopBinaryReply reply,
53 void* user_data) {
55 }
56
57 // Called for FlutterDesktopMessengerSendResponse.
60 const uint8_t* data,
61 size_t data_length) {}
62
63 // Called for FlutterDesktopMessengerSetCallback.
64 virtual void MessengerSetCallback(const char* channel,
66 void* user_data) {}
67
68 // Called for FlutterDesktopTextureRegistrarRegisterExternalTexture.
71 return -1;
72 }
73
74 // Called for FlutterDesktopTextureRegistrarUnregisterExternalTexture.
76 int64_t texture_id,
77 void (*callback)(void* user_data),
78 void* user_data) {}
79
80 // Called for FlutterDesktopTextureRegistrarMarkExternalTextureFrameAvailable.
82 return false;
83 }
84};
85
86// A test helper that owns a stub implementation, making it the test stub for
87// the lifetime of the object, then restoring the previous value.
89 public:
90 // Calls SetTestFlutterStub with |stub|.
91 explicit ScopedStubFlutterApi(std::unique_ptr<StubFlutterApi> stub);
92
93 // Restores the previous test stub.
95
96 StubFlutterApi* stub() { return stub_.get(); }
97
98 private:
99 std::unique_ptr<StubFlutterApi> stub_;
100 // The previous stub.
101 StubFlutterApi* previous_stub_;
102};
103
104} // namespace testing
105} // namespace flutter
106
107#endif // FLUTTER_SHELL_PLATFORM_COMMON_CLIENT_WRAPPER_TESTING_STUB_FLUTTER_API_H_
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition DM.cpp:213
virtual bool TextureRegistrarMarkTextureFrameAvailable(int64_t texture_id)
static void SetTestStub(StubFlutterApi *stub)
virtual void MessengerSetCallback(const char *channel, FlutterDesktopMessageCallback callback, void *user_data)
static StubFlutterApi * GetTestStub()
virtual void PluginRegistrarSetDestructionHandler(FlutterDesktopOnPluginRegistrarDestroyed callback)
virtual void MessengerSendResponse(const FlutterDesktopMessageResponseHandle *handle, const uint8_t *data, size_t data_length)
virtual bool MessengerSendWithReply(const char *channel, const uint8_t *message, const size_t message_size, const FlutterDesktopBinaryReply reply, void *user_data)
virtual bool MessengerSend(const char *channel, const uint8_t *message, const size_t message_size)
virtual void TextureRegistrarUnregisterExternalTexture(int64_t texture_id, void(*callback)(void *user_data), void *user_data)
virtual int64_t TextureRegistrarRegisterExternalTexture(const FlutterDesktopTextureInfo *info)
FlKeyEvent uint64_t FlKeyResponderAsyncCallback callback
void(* FlutterDesktopBinaryReply)(const uint8_t *data, size_t data_size, void *user_data)
void(* FlutterDesktopMessageCallback)(FlutterDesktopMessengerRef, const FlutterDesktopMessage *, void *)
void(* FlutterDesktopOnPluginRegistrarDestroyed)(FlutterDesktopPluginRegistrarRef)
Win32Message message
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot data
Definition switches.h:41
int64_t texture_id