Flutter Engine
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 
13 namespace flutter {
14 namespace 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 // implementantions 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.
26  bool message_engine_result = true;
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 SetTestFluttterStub.
33  static StubFlutterApi* GetTestStub();
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) {
45  return message_engine_result;
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) {
54  return message_engine_result;
55  }
56 
57  // Called for FlutterDesktopMessengerSendResponse.
58  virtual void MessengerSendResponse(
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 FlutterDesktopRegisterExternalTexture.
70  const FlutterDesktopTextureInfo* info) {
71  return -1;
72  }
73 
74  // Called for FlutterDesktopUnregisterExternalTexture.
76  return false;
77  }
78 
79  // Called for FlutterDesktopMarkExternalTextureFrameAvailable.
81  return false;
82  }
83 };
84 
85 // A test helper that owns a stub implementation, making it the test stub for
86 // the lifetime of the object, then restoring the previous value.
88  public:
89  // Calls SetTestFlutterStub with |stub|.
90  explicit ScopedStubFlutterApi(std::unique_ptr<StubFlutterApi> stub);
91 
92  // Restores the previous test stub.
94 
95  StubFlutterApi* stub() { return stub_.get(); }
96 
97  private:
98  std::unique_ptr<StubFlutterApi> stub_;
99  // The previous stub.
100  StubFlutterApi* previous_stub_;
101 };
102 
103 } // namespace testing
104 } // namespace flutter
105 
106 #endif // FLUTTER_SHELL_PLATFORM_COMMON_CLIENT_WRAPPER_TESTING_STUB_FLUTTER_API_H_
virtual void PluginRegistrarSetDestructionHandler(FlutterDesktopOnPluginRegistrarDestroyed callback)
static StubFlutterApi * GetTestStub()
virtual bool MessengerSend(const char *channel, const uint8_t *message, const size_t message_size)
void * user_data
int64_t texture_id
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
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
virtual bool TextureRegistrarMarkTextureFrameAvailable(int64_t texture_id)
virtual bool TextureRegistrarUnregisterExternalTexture(int64_t texture_id)
void(* FlutterDesktopBinaryReply)(const uint8_t *data, size_t data_size, void *user_data)
void(* FlutterDesktopOnPluginRegistrarDestroyed)(FlutterDesktopPluginRegistrarRef)
virtual int64_t TextureRegistrarRegisterExternalTexture(const FlutterDesktopTextureInfo *info)
virtual void MessengerSetCallback(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)