5 #import <Foundation/Foundation.h>
6 #import <OCMock/OCMock.h>
7 #import <XCTest/XCTest.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];
46 __block BOOL next_response = TRUE;
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];
53 NSDictionary* message;
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];
107 - (void)testEmptyResponseIsTakenAsHandled
API_AVAILABLE(ios(13.4)) {
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];
115 NSDictionary* message;
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);