Flutter Engine
stub_flutter_glfw_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_GLFW_WRAPPER_TESTING_STUB_FLUTTER_GLFW_API_H_
6 #define FLUTTER_SHELL_PLATFORM_GLFW_WRAPPER_TESTING_STUB_FLUTTER_GLFW_API_H_
7 
8 #include <memory>
9 
10 #include "flutter/shell/platform/glfw/public/flutter_glfw.h"
11 
12 namespace flutter {
13 namespace testing {
14 
15 // Base class for a object that provides test implementations of the APIs in
16 // the headers in platform/glfw/public/.
17 
18 // Linking this class into a test binary will provide dummy forwarding
19 // implementantions of that C API, so that the wrapper can be tested separately
20 // from the actual library.
22  public:
23  // Sets |stub| as the instance to which calls to the Flutter library C APIs
24  // will be forwarded.
25  static void SetTestStub(StubFlutterGlfwApi* stub);
26 
27  // Returns the current stub, as last set by SetTestFluttterStub.
29 
30  virtual ~StubFlutterGlfwApi() {}
31 
32  // Called for FlutterDesktopInit.
33  virtual bool Init() { return true; }
34 
35  // Called for FlutterDesktopTerminate.
36  virtual void Terminate() {}
37 
38  // Called for FlutterDesktopCreateWindow.
40  const FlutterDesktopWindowProperties& window_properties,
41  const FlutterDesktopEngineProperties& engine_properties) {
42  return nullptr;
43  }
44 
45  // Called for FlutterDesktopDestroyWindow
46  virtual void DestroyWindow() {}
47 
48  // Called for FlutterDesktopWindowSetHoverEnabled.
49  virtual void SetHoverEnabled(bool enabled) {}
50 
51  // Called for FlutterDesktopWindowSetTitle.
52  virtual void SetWindowTitle(const char* title) {}
53 
54  // Called for FlutterDesktopWindowSetIcon.
55  virtual void SetWindowIcon(uint8_t* pixel_data, int width, int height) {}
56 
57  // Called for FlutterDesktopWindowGetFrame.
58  virtual void GetWindowFrame(int* x, int* y, int* width, int* height) {
59  x = y = width = height = 0;
60  }
61 
62  // Called for FlutterDesktopWindowGetFrame.
63  virtual void SetWindowFrame(int x, int y, int width, int height) {}
64 
65  // Called for FlutterDesktopWindowGetScaleFactor.
66  virtual double GetWindowScaleFactor() { return 1.0; }
67 
68  // Called for FlutterDesktopWindowSetPixelRatioOverride.
69  virtual void SetPixelRatioOverride(double pixel_ratio) {}
70 
71  // Called for FlutterDesktopWindowSetSizeLimits.
72  virtual void SetSizeLimits(FlutterDesktopSize minimum_size,
73  FlutterDesktopSize maximum_size) {}
74 
75  // Called for FlutterDesktopRunWindowEventLoopWithTimeout.
76  virtual bool RunWindowEventLoopWithTimeout(uint32_t millisecond_timeout) {
77  return true;
78  }
79 
80  // Called for FlutterDesktopRunEngine.
82  const FlutterDesktopEngineProperties& properties) {
83  return nullptr;
84  }
85 
86  // Called for FlutterDesktopRunEngineEventLoopWithTimeout.
87  virtual void RunEngineEventLoopWithTimeout(uint32_t millisecond_timeout) {}
88 
89  // Called for FlutterDesktopShutDownEngine.
90  virtual bool ShutDownEngine() { return true; }
91 
92  // Called for FlutterDesktopPluginRegistrarEnableInputBlocking.
93  virtual void PluginRegistrarEnableInputBlocking(const char* channel) {}
94 };
95 
96 // A test helper that owns a stub implementation, making it the test stub for
97 // the lifetime of the object, then restoring the previous value.
99  public:
100  // Calls SetTestFlutterStub with |stub|.
101  ScopedStubFlutterGlfwApi(std::unique_ptr<StubFlutterGlfwApi> stub);
102 
103  // Restores the previous test stub.
105 
106  StubFlutterGlfwApi* stub() { return stub_.get(); }
107 
108  private:
109  std::unique_ptr<StubFlutterGlfwApi> stub_;
110  // The previous stub.
111  StubFlutterGlfwApi* previous_stub_;
112 };
113 
114 } // namespace testing
115 } // namespace flutter
116 
117 #endif // FLUTTER_SHELL_PLATFORM_GLFW_CLIENT_WRAPPER_TESTING_STUB_FLUTTER_GLFW_API_H_
virtual void SetSizeLimits(FlutterDesktopSize minimum_size, FlutterDesktopSize maximum_size)
virtual void SetHoverEnabled(bool enabled)
virtual void SetWindowIcon(uint8_t *pixel_data, int width, int height)
virtual void SetPixelRatioOverride(double pixel_ratio)
static void SetTestStub(StubFlutterGlfwApi *stub)
virtual FlutterDesktopWindowControllerRef CreateWindow(const FlutterDesktopWindowProperties &window_properties, const FlutterDesktopEngineProperties &engine_properties)
virtual void SetWindowTitle(const char *title)
int32_t height
int32_t width
static StubFlutterGlfwApi * GetTestStub()
virtual void PluginRegistrarEnableInputBlocking(const char *channel)
virtual void SetWindowFrame(int x, int y, int width, int height)
virtual void GetWindowFrame(int *x, int *y, int *width, int *height)
virtual bool RunWindowEventLoopWithTimeout(uint32_t millisecond_timeout)
virtual FlutterDesktopEngineRef RunEngine(const FlutterDesktopEngineProperties &properties)
virtual void RunEngineEventLoopWithTimeout(uint32_t millisecond_timeout)