Flutter iOS Embedder
FlutterEngineGroupTest.mm
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 #import <OCMock/OCMock.h>
6 #import <XCTest/XCTest.h>
7 
10 
12 
13 @interface FlutterEngineGroup ()
14 - (FlutterEngine*)makeEngine;
15 @end
16 
17 @interface FlutterEngineGroupTest : XCTestCase
18 @end
19 
20 @implementation FlutterEngineGroupTest
21 
22 - (void)testMake {
23  FlutterEngineGroup* group = [[FlutterEngineGroup alloc] initWithName:@"foo" project:nil];
25  XCTAssertNotNil(engine);
26 }
27 
28 - (void)testSpawn {
29  FlutterEngineGroup* group = [[FlutterEngineGroup alloc] initWithName:@"foo" project:nil];
30  FlutterEngine* spawner = [group makeEngineWithEntrypoint:nil libraryURI:nil];
31  spawner.isGpuDisabled = YES;
32  FlutterEngine* spawnee = [group makeEngineWithEntrypoint:nil libraryURI:nil];
33  XCTAssertNotNil(spawner);
34  XCTAssertNotNil(spawnee);
35  XCTAssertEqual(&spawner.threadHost, &spawnee.threadHost);
36  XCTAssertEqual(spawner.isGpuDisabled, spawnee.isGpuDisabled);
37 }
38 
39 - (void)testDeleteLastEngine {
40  FlutterEngineGroup* group = [[FlutterEngineGroup alloc] initWithName:@"foo" project:nil];
41  @autoreleasepool {
42  FlutterEngine* spawner = [group makeEngineWithEntrypoint:nil libraryURI:nil];
43  XCTAssertNotNil(spawner);
44  }
45  FlutterEngine* spawnee = [group makeEngineWithEntrypoint:nil libraryURI:nil];
46  XCTAssertNotNil(spawnee);
47 }
48 
49 - (void)testCustomEntrypoint {
50  FlutterEngineGroup* group = OCMPartialMock([[FlutterEngineGroup alloc] initWithName:@"foo"
51  project:nil]);
52  FlutterEngine* mockEngine = OCMClassMock([FlutterEngine class]);
53  OCMStub([group makeEngine]).andReturn(mockEngine);
54  OCMStub([mockEngine spawnWithEntrypoint:[OCMArg any]
55  libraryURI:[OCMArg any]
56  initialRoute:[OCMArg any]
57  entrypointArgs:[OCMArg any]])
58  .andReturn(OCMClassMock([FlutterEngine class]));
59  FlutterEngine* spawner = [group makeEngineWithEntrypoint:@"firstEntrypoint"
60  libraryURI:@"firstLibraryURI"];
61  XCTAssertNotNil(spawner);
62  OCMVerify([spawner runWithEntrypoint:@"firstEntrypoint"
63  libraryURI:@"firstLibraryURI"
64  initialRoute:nil
65  entrypointArgs:nil]);
66 
67  FlutterEngine* spawnee = [group makeEngineWithEntrypoint:@"secondEntrypoint"
68  libraryURI:@"secondLibraryURI"];
69  XCTAssertNotNil(spawnee);
70  OCMVerify([spawner spawnWithEntrypoint:@"secondEntrypoint"
71  libraryURI:@"secondLibraryURI"
72  initialRoute:nil
73  entrypointArgs:nil]);
74 }
75 
76 - (void)testCustomInitialRoute {
77  FlutterEngineGroup* group = OCMPartialMock([[FlutterEngineGroup alloc] initWithName:@"foo"
78  project:nil]);
79  FlutterEngine* mockEngine = OCMClassMock([FlutterEngine class]);
80  OCMStub([group makeEngine]).andReturn(mockEngine);
81  OCMStub([mockEngine spawnWithEntrypoint:[OCMArg any]
82  libraryURI:[OCMArg any]
83  initialRoute:[OCMArg any]
84  entrypointArgs:[OCMArg any]])
85  .andReturn(OCMClassMock([FlutterEngine class]));
86  FlutterEngine* spawner = [group makeEngineWithEntrypoint:nil libraryURI:nil initialRoute:@"foo"];
87  XCTAssertNotNil(spawner);
88  OCMVerify([spawner runWithEntrypoint:nil libraryURI:nil initialRoute:@"foo" entrypointArgs:nil]);
89 
90  FlutterEngine* spawnee = [group makeEngineWithEntrypoint:nil libraryURI:nil initialRoute:@"bar"];
91  XCTAssertNotNil(spawnee);
92  OCMVerify([spawner spawnWithEntrypoint:nil
93  libraryURI:nil
94  initialRoute:@"bar"
95  entrypointArgs:nil]);
96 }
97 
98 - (void)testCustomEntrypointArgs {
99  FlutterEngineGroup* group = OCMPartialMock([[FlutterEngineGroup alloc] initWithName:@"foo"
100  project:nil]);
101  FlutterEngine* mockEngine = OCMClassMock([FlutterEngine class]);
102  OCMStub([group makeEngine]).andReturn(mockEngine);
103  OCMStub([mockEngine spawnWithEntrypoint:[OCMArg any]
104  libraryURI:[OCMArg any]
105  initialRoute:[OCMArg any]
106  entrypointArgs:[OCMArg any]])
107  .andReturn(OCMClassMock([FlutterEngine class]));
108  FlutterEngineGroupOptions* firstOptions = [[FlutterEngineGroupOptions alloc] init];
109  NSArray* firstEntrypointArgs = @[ @"foo", @"first" ];
110  firstOptions.entrypointArgs = firstEntrypointArgs;
111  FlutterEngine* spawner = [group makeEngineWithOptions:firstOptions];
112  XCTAssertNotNil(spawner);
113  OCMVerify([spawner runWithEntrypoint:nil
114  libraryURI:nil
115  initialRoute:nil
116  entrypointArgs:firstEntrypointArgs]);
117 
118  NSArray* secondEntrypointArgs = @[ @"bar", @"second" ];
119  FlutterEngineGroupOptions* secondOptions = [[FlutterEngineGroupOptions alloc] init];
120  secondOptions.entrypointArgs = secondEntrypointArgs;
121  FlutterEngine* spawnee = [group makeEngineWithOptions:secondOptions];
122  XCTAssertNotNil(spawnee);
123  OCMVerify([spawner spawnWithEntrypoint:nil
124  libraryURI:nil
125  initialRoute:nil
126  entrypointArgs:secondEntrypointArgs]);
127 }
128 
129 - (void)testReleasesProjectOnDealloc {
130  __weak FlutterDartProject* weakProject;
131  @autoreleasepool {
132  FlutterDartProject* mockProject = OCMClassMock([FlutterDartProject class]);
133  FlutterEngineGroup* group = [[FlutterEngineGroup alloc] initWithName:@"foo"
134  project:mockProject];
135  XCTAssertNotNil(group);
136  weakProject = mockProject;
137  XCTAssertNotNil(weakProject);
138  group = nil;
139  mockProject = nil;
140  }
141  XCTAssertNil(weakProject);
142 }
143 
144 @end
FlutterEngine::isGpuDisabled
BOOL isGpuDisabled
Definition: FlutterEngine.h:456
FlutterEngine
Definition: FlutterEngine.h:61
FlutterEngineGroup.h
-[FlutterEngineGroup makeEngineWithEntrypoint:libraryURI:initialRoute:]
FlutterEngine * makeEngineWithEntrypoint:libraryURI:initialRoute:(nullable NSString *entrypoint,[libraryURI] nullable NSString *libraryURI,[initialRoute] nullable NSString *initialRoute)
Definition: FlutterEngineGroup.mm:52
FlutterEngine_Test.h
-[FlutterEngineGroup makeEngineWithEntrypoint:libraryURI:]
FlutterEngine * makeEngineWithEntrypoint:libraryURI:(nullable NSString *entrypoint,[libraryURI] nullable NSString *libraryURI)
Definition: FlutterEngineGroup.mm:47
FlutterEngineGroupOptions
Definition: FlutterEngineGroup.h:16
engine
id engine
Definition: FlutterTextInputPluginTest.mm:89
FlutterEngineGroupOptions::entrypointArgs
NSArray< NSString * > * entrypointArgs
Definition: FlutterEngineGroup.h:41
FlutterEngineGroupTest
Definition: FlutterEngineGroupTest.mm:17
FlutterDartProject
Definition: FlutterDartProject.mm:262
FlutterEngineGroup
Definition: FlutterEngineGroup.h:56
-[FlutterEngine threadHost]
const flutter::ThreadHost & threadHost()
FLUTTER_ASSERT_ARC
Definition: FlutterChannelKeyResponder.mm:13
-[FlutterEngineGroup makeEngineWithOptions:]
FlutterEngine * makeEngineWithOptions:(nullable FlutterEngineGroupOptions *options)
Definition: FlutterEngineGroup.mm:62