Flutter Engine
stub_flutter_windows_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_WINDOWS_WRAPPER_TESTING_STUB_FLUTTER_WINDOWS_API_H_
6 #define FLUTTER_SHELL_PLATFORM_WINDOWS_WRAPPER_TESTING_STUB_FLUTTER_WINDOWS_API_H_
7 
8 #include <memory>
9 
10 #include "flutter/shell/platform/windows/public/flutter_windows.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/windows/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(StubFlutterWindowsApi* stub);
26 
27  // Returns the current stub, as last set by SetTestFluttterStub.
29 
31 
32  // Called for FlutterDesktopViewControllerCreate.
35  return nullptr;
36  }
37 
38  // Called for FlutterDesktopViewControllerDestroy.
39  virtual void ViewControllerDestroy() {}
40 
41  // Called for FlutterDesktopViewControllerHandleTopLevelWindowProc.
43  UINT message,
44  WPARAM wparam,
45  LPARAM lparam,
46  LRESULT* result) {
47  return false;
48  }
49 
50  // Called for FlutterDesktopEngineCreate.
52  const FlutterDesktopEngineProperties& engine_properties) {
53  return nullptr;
54  }
55 
56  // Called for FlutterDesktopEngineDestroy.
57  virtual bool EngineDestroy() { return true; }
58 
59  // Called for FlutterDesktopEngineRun.
60  virtual bool EngineRun(const char* entry_point) { return true; }
61 
62  // Called for FlutterDesktopEngineProcessMessages.
63  virtual uint64_t EngineProcessMessages() { return 0; }
64 
65  // Called for FlutterDesktopEngineReloadSystemFonts.
66  virtual void EngineReloadSystemFonts() {}
67 
68  // Called for FlutterDesktopViewGetHWND.
69  virtual HWND ViewGetHWND() { return reinterpret_cast<HWND>(1); }
70 
71  // Called for FlutterDesktopPluginRegistrarRegisterTopLevelWindowProcDelegate.
74  void* user_data) {}
75 
76  // Called for
77  // FlutterDesktopPluginRegistrarUnregisterTopLevelWindowProcDelegate.
80 };
81 
82 // A test helper that owns a stub implementation, making it the test stub for
83 // the lifetime of the object, then restoring the previous value.
85  public:
86  // Calls SetTestFlutterStub with |stub|.
87  ScopedStubFlutterWindowsApi(std::unique_ptr<StubFlutterWindowsApi> stub);
88 
89  // Restores the previous test stub.
91 
92  StubFlutterWindowsApi* stub() { return stub_.get(); }
93 
94  private:
95  std::unique_ptr<StubFlutterWindowsApi> stub_;
96  // The previous stub.
97  StubFlutterWindowsApi* previous_stub_;
98 };
99 
100 } // namespace testing
101 } // namespace flutter
102 
103 #endif // FLUTTER_SHELL_PLATFORM_WINDOWS_CLIENT_WRAPPER_TESTING_STUB_FLUTTER_WINDOWS_API_H_
virtual bool ViewControllerHandleTopLevelWindowProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam, LRESULT *result)
G_BEGIN_DECLS FlValue gpointer user_data
int32_t height
int32_t width
bool(* FlutterDesktopWindowProcCallback)(HWND, UINT, WPARAM, LPARAM, void *, LRESULT *result)
static void SetTestStub(StubFlutterWindowsApi *stub)
static StubFlutterWindowsApi * GetTestStub()
virtual void PluginRegistrarRegisterTopLevelWindowProcDelegate(FlutterDesktopWindowProcCallback delegate, void *user_data)
virtual FlutterDesktopViewControllerRef ViewControllerCreate(int width, int height, FlutterDesktopEngineRef engine)
virtual bool EngineRun(const char *entry_point)
virtual FlutterDesktopEngineRef EngineCreate(const FlutterDesktopEngineProperties &engine_properties)
virtual void PluginRegistrarUnregisterTopLevelWindowProcDelegate(FlutterDesktopWindowProcCallback delegate)