5#import <Foundation/Foundation.h>
6#import <OCMock/OCMock.h>
7#import <XCTest/XCTest.h>
9#import "flutter/shell/platform/darwin/common/framework/Headers/FlutterMacros.h"
10#import "flutter/shell/platform/darwin/ios/framework/Source/FlutterChannelKeyResponder.h"
11#import "flutter/shell/platform/darwin/ios/framework/Source/FlutterFakeKeyEvents.h"
15#define XCTAssertStrEqual(value, expected) \
16 XCTAssertTrue([value isEqualToString:expected], \
17 @"String \"%@\" not equal to the expected value of \"%@\"", value, expected)
31 if (@available(iOS 13.4, *)) {
33 XCTSkip(
@"Required API not present for test.");
35 _testKeyDownEvent =
keyDownEvent(UIKeyboardHIDUsageKeyboardA, 0x0, 0.0f,
"a",
"a");
36 _testKeyUpEvent =
keyUpEvent(UIKeyboardHIDUsageKeyboardA, 0x0, 0.0f);
40 _testKeyDownEvent = nil;
41 _testKeyUpEvent = nil;
45 __block NSMutableArray<id>* messages = [[NSMutableArray<id> alloc] init];
47 __block NSMutableArray<NSNumber*>* responses = [[NSMutableArray<NSNumber*> alloc] init];
50 OCMStub([mockKeyEventChannel sendMessage:[OCMArg
any] reply:[OCMArg
any]])
51 .andDo((^(NSInvocation* invocation) {
52 [invocation retainArguments];
54 [invocation getArgument:&message atIndex:2];
55 [messages addObject:message];
58 [invocation getArgument:&callback atIndex:3];
59 NSDictionary* keyMessage = @{
60 @"handled" : @(next_response),
70 [responses addObject:@(handled)];
73 XCTAssertEqual([messages
count], 1u);
76 XCTAssertEqual([[messages lastObject][
@"keyCode"] intValue], UIKeyboardHIDUsageKeyboardA);
77 XCTAssertEqual([[messages lastObject][
@"modifiers"] intValue], 0x0);
81 XCTAssertEqual([responses
count], 1u);
82 XCTAssertEqual([[responses lastObject] boolValue],
TRUE);
84 [messages removeAllObjects];
85 [responses removeAllObjects];
88 next_response =
FALSE;
91 [responses addObject:@(handled)];
94 XCTAssertEqual([messages
count], 1u);
97 XCTAssertEqual([[messages lastObject][
@"keyCode"] intValue], UIKeyboardHIDUsageKeyboardA);
98 XCTAssertEqual([[messages lastObject][
@"modifiers"] intValue], 0x0);
100 XCTAssertEqual([responses
count], 1u);
101 XCTAssertEqual([[responses lastObject] boolValue],
FALSE);
103 [messages removeAllObjects];
104 [responses removeAllObjects];
108 __block NSMutableArray<id>* messages = [[NSMutableArray<id> alloc] init];
109 __block NSMutableArray<NSNumber*>* responses = [[NSMutableArray<NSNumber*> alloc] init];
112 OCMStub([mockKeyEventChannel sendMessage:[OCMArg
any] reply:[OCMArg
any]])
113 .andDo((^(NSInvocation* invocation) {
114 [invocation retainArguments];
116 [invocation getArgument:&message atIndex:2];
117 [messages addObject:message];
120 [invocation getArgument:&callback atIndex:3];
128 [responses addObject:@(handled)];
131 XCTAssertEqual([messages
count], 1u);
134 XCTAssertEqual([[messages lastObject][
@"keyCode"] intValue], UIKeyboardHIDUsageKeyboardA);
135 XCTAssertEqual([[messages lastObject][
@"modifiers"] intValue], 0x0);
139 XCTAssertEqual([responses
count], 1u);
140 XCTAssertEqual([[responses lastObject] boolValue],
TRUE);
NS_ASSUME_NONNULL_BEGIN typedef void(^ FlutterReply)(id _Nullable reply)
static void copy(void *dst, const uint8_t *src, int width, int bpp, int deltaSrc, int offset, const SkPMColor ctable[])
FlKeyEvent uint64_t FlKeyResponderAsyncCallback callback
FlutterUIPressProxy *testKeyUpEvent API_AVAILABLE(ios(13.4))
FlutterUIPressProxy *testKeyDownEvent API_AVAILABLE(ios(13.4))
void handlePress:callback:(nonnull FlutterUIPressProxy *press, [callback] ios(13.4) API_AVAILABLE)
#define XCTAssertStrEqual(value, expected)
SK_API sk_sp< SkSurface > ios(9.0)
FlutterUIPressProxy * keyUpEvent(UIKeyboardHIDUsage keyCode, UIKeyModifierFlags modifierFlags=0x0, NSTimeInterval timestamp=0.0f, const char *characters="", const char *charactersIgnoringModifiers="") API_AVAILABLE(ios(13.4))
FlutterUIPressProxy * keyDownEvent(UIKeyboardHIDUsage keyCode, UIKeyModifierFlags modifierFlags=0x0, NSTimeInterval timestamp=0.0f, const char *characters="", const char *charactersIgnoringModifiers="") API_AVAILABLE(ios(13.4))
API_AVAILABLE(ios(14.0), macos(11.0)) static NSString *MTLCommandEncoderErrorStateToString(MTLCommandEncoderErrorState state)
SIT bool any(const Vec< 1, T > &x)