Flutter macOS Embedder
FlutterEngineTestUtils.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_DARWIN_MACOS_FRAMEWORK_SOURCE_FLUTTERENGINETESTUTILS_H_
6 #define FLUTTER_SHELL_PLATFORM_DARWIN_MACOS_FRAMEWORK_SOURCE_FLUTTERENGINETESTUTILS_H_
7 
9 
10 #import <OCMock/OCMock.h>
11 
12 #include "flutter/testing/autoreleasepool_test.h"
13 #include "flutter/testing/test_dart_native_resolver.h"
14 #include "gtest/gtest.h"
15 
16 namespace flutter::testing {
17 
18 class FlutterEngineTest : public AutoreleasePoolTest {
19  public:
21 
22  FlutterEngine* GetFlutterEngine() { return engine_; };
23 
24  void SetUp() override;
25  void TearDown() override;
26 
27  void AddNativeCallback(const char* name, Dart_NativeFunction function);
28 
29  static void IsolateCreateCallback(void* user_data);
30 
31  void ShutDownEngine();
32 
33  private:
34  inline static std::shared_ptr<TestDartNativeResolver> native_resolver_;
35 
36  FlutterDartProject* project_;
37  FlutterEngine* engine_;
38 
39  FML_DISALLOW_COPY_AND_ASSIGN(FlutterEngineTest);
40 };
41 
42 // Returns a mock FlutterEngine that is able to work in environments
43 // without a real pasteboard.
44 //
45 // Callers MUST call [mockEngine shutDownEngine] when finished with the returned engine.
46 id CreateMockFlutterEngine(NSString* pasteboardString);
47 
48 class MockFlutterEngineTest : public AutoreleasePoolTest {
49  public:
51 
52  void SetUp() override;
53  void TearDown() override;
54 
55  id GetMockEngine() { return engine_mock_; }
56 
57  void ShutDownEngine();
58 
60  [engine_mock_ shutDownEngine];
61  [engine_mock_ stopMocking];
62  }
63 
64  private:
65  id engine_mock_;
66 
67  FML_DISALLOW_COPY_AND_ASSIGN(MockFlutterEngineTest);
68 };
69 
70 } // namespace flutter::testing
71 
72 #endif // FLUTTER_SHELL_PLATFORM_DARWIN_MACOS_FRAMEWORK_SOURCE_FLUTTERENGINETESTUTILS_H_
flutter::testing::FlutterEngineTest::FlutterEngineTest
FlutterEngineTest()
FlutterEngine
Definition: FlutterEngine.h:30
flutter::testing::FlutterEngineTest::ShutDownEngine
void ShutDownEngine()
Definition: FlutterEngineTestUtils.mm:63
flutter::testing::MockFlutterEngineTest::TearDown
void TearDown() override
Definition: FlutterEngineTestUtils.mm:98
FlutterEngine.h
flutter::testing::CreateMockFlutterEngine
id CreateMockFlutterEngine(NSString *pasteboardString)
Definition: FlutterEngineTestUtils.mm:76
flutter::testing::FlutterEngineTest::TearDown
void TearDown() override
Definition: FlutterEngineTestUtils.mm:57
user_data
void * user_data
Definition: texture_registrar_unittests.cc:27
flutter::testing
Definition: AccessibilityBridgeMacTest.mm:13
flutter::testing::MockFlutterEngineTest
Definition: FlutterEngineTestUtils.h:48
flutter::testing::FlutterEngineTest
Definition: FlutterEngineTestUtils.h:18
flutter::testing::FlutterEngineTest::SetUp
void SetUp() override
Definition: FlutterEngineTestUtils.mm:45
flutter::testing::MockFlutterEngineTest::SetUp
void SetUp() override
Definition: FlutterEngineTestUtils.mm:94
flutter::testing::MockFlutterEngineTest::~MockFlutterEngineTest
~MockFlutterEngineTest()
Definition: FlutterEngineTestUtils.h:59
flutter::testing::FlutterEngineTest::AddNativeCallback
void AddNativeCallback(const char *name, Dart_NativeFunction function)
Definition: FlutterEngineTestUtils.mm:72
flutter::testing::MockFlutterEngineTest::GetMockEngine
id GetMockEngine()
Definition: FlutterEngineTestUtils.h:55
FlutterDartProject
Definition: FlutterDartProject.mm:24
flutter::testing::FlutterEngineTest::GetFlutterEngine
FlutterEngine * GetFlutterEngine()
Definition: FlutterEngineTestUtils.h:22
flutter::testing::MockFlutterEngineTest::MockFlutterEngineTest
MockFlutterEngineTest()
flutter::testing::MockFlutterEngineTest::ShutDownEngine
void ShutDownEngine()
Definition: FlutterEngineTestUtils.mm:104
flutter::testing::FlutterEngineTest::IsolateCreateCallback
static void IsolateCreateCallback(void *user_data)
Definition: FlutterEngineTestUtils.mm:68