546 {
547 __block NSMutableArray<TestKeyEvent*>* events = [[NSMutableArray<TestKeyEvent*> alloc] init];
550 id keyEventCallback = ^(
BOOL handled) {
551 last_handled = handled;
552 };
553
555 initWithSendEvent:^(const FlutterKeyEvent& event, _Nullable FlutterKeyEventCallback callback,
556 void* _Nullable user_data) {
557 [events addObject:[[
TestKeyEvent alloc] initWithEvent:&event
558 callback:callback
559 userData:user_data]];
560 }];
561
562
563
564
565
566
567 [responder
handlePress:keyDownEvent(kKeyCodeNumpad1, kModifierFlagNumPadKey, 123.0, "1", "1")
569
570 XCTAssertEqual([events
count], 1u);
571 event = [events lastObject].data;
572 XCTAssertNotEqual(
event,
nullptr);
578 XCTAssertEqual(
event->synthesized,
false);
579 [[events lastObject] respond:TRUE];
580
581 [events removeAllObjects];
582
583
584
585 [responder
handlePress:keyDownEvent(kKeyCodeUndefined, kModifierFlagNone, 123.0)
587
588 XCTAssertEqual([events
count], 1u);
589 event = [events lastObject].data;
590 XCTAssertNotEqual(
event,
nullptr);
593 XCTAssertEqual(
event->physical, kPhysicalKeyUndefined);
594 XCTAssertEqual(
event->logical, kLogicalKeyUndefined);
595 XCTAssertEqual(
event->character,
nullptr);
596 XCTAssertEqual(
event->synthesized,
false);
597 [[events lastObject] respond:TRUE];
598
599 [events removeAllObjects];
600
601
602
603 [responder
handlePress:keyDownEvent(kKeyCodeF1, kModifierFlagNone, 123.0f, "\\^P", "\\^P")
605
606 XCTAssertEqual([events
count], 1u);
607 event = [events lastObject].data;
608 XCTAssertNotEqual(
event,
nullptr);
613 XCTAssertEqual(
event->character,
nullptr);
614 XCTAssertEqual(
event->synthesized,
false);
615 [[events lastObject] respond:TRUE];
616
617 [events removeAllObjects];
618
619
620
621 [responder
handlePress:keyDownEvent(kKeyCodeKeyA, kModifierFlagNone, 123.0f, "a", "a")
623
624 XCTAssertEqual([events
count], 1u);
625 event = [events lastObject].data;
626 XCTAssertNotEqual(
event,
nullptr);
632 XCTAssertEqual(
event->synthesized,
false);
633 [[events lastObject] respond:TRUE];
634
635 [events removeAllObjects];
636
637
638
639 [responder
handlePress:keyDownEvent(kKeyCodeShiftLeft, kModifierFlagShiftAny, 123.0f)
641
642 XCTAssertEqual([events
count], 1u);
643 event = [events lastObject].data;
644 XCTAssertNotEqual(
event,
nullptr);
649 XCTAssertEqual(
event->character,
nullptr);
650 XCTAssertEqual(
event->synthesized,
false);
651
652 [events removeAllObjects];
653
654
655
656 [responder
handlePress:keyUpEvent(kKeyCodeNumpad1, kModifierFlagNumPadKey, 123.0f)
658
659 XCTAssertEqual([events
count], 2u);
660
661
662
663 event = [events firstObject].data;
664 XCTAssertNotEqual(
event,
nullptr);
669 XCTAssertEqual(
event->character,
nullptr);
670 XCTAssertEqual(
event->synthesized,
true);
671
672 event = [events lastObject].data;
673 XCTAssertNotEqual(
event,
nullptr);
678 XCTAssertEqual(
event->character,
nullptr);
679 XCTAssertEqual(
event->synthesized,
false);
680 [[events lastObject] respond:TRUE];
681
682 [events removeAllObjects];
683
684
685
686 [responder
handlePress:keyUpEvent(kKeyCodeF1, kModifierFlagNone, 123.0f)
688
689 XCTAssertEqual([events
count], 1u);
690 event = [events lastObject].data;
691 XCTAssertNotEqual(
event,
nullptr);
696 XCTAssertEqual(
event->character,
nullptr);
697 XCTAssertEqual(
event->synthesized,
false);
698 [[events lastObject] respond:TRUE];
699
700 [events removeAllObjects];
701
702
703
704 [responder
handlePress:keyUpEvent(kKeyCodeUndefined, kModifierFlagNone, 123.0)
706
707 XCTAssertEqual([events
count], 1u);
708 event = [events lastObject].data;
709 XCTAssertNotEqual(
event,
nullptr);
712 XCTAssertEqual(
event->physical, kPhysicalKeyUndefined);
713 XCTAssertEqual(
event->logical, kLogicalKeyUndefined);
714 XCTAssertEqual(
event->synthesized,
false);
715 [[events lastObject] respond:TRUE];
716
717 [events removeAllObjects];
718
719
720
721 [responder
handlePress:keyUpEvent(kKeyCodeKeyA, kModifierFlagNone, 123.0f)
723
724 XCTAssertEqual([events
count], 1u);
725 event = [events lastObject].data;
726 XCTAssertNotEqual(
event,
nullptr);
731 XCTAssertEqual(
event->character,
nullptr);
732 XCTAssertEqual(
event->synthesized,
false);
733 [[events lastObject] respond:TRUE];
734
735 [events removeAllObjects];
736
737
738
739 [responder
handlePress:keyUpEvent(kKeyCodeShiftLeft, kModifierFlagShiftAny, 123.0f)
741
742 XCTAssertEqual([events
count], 1u);
743 event = [events lastObject].data;
744 XCTAssertNotEqual(
event,
nullptr);
745 XCTAssertEqual(
event->physical, 0ull);
746 XCTAssertEqual(
event->logical, 0ull);
747 XCTAssertEqual(
event->synthesized,
false);
748 XCTAssertFalse([[events lastObject] hasCallback]);
749 XCTAssertEqual(last_handled,
TRUE);
750
751 [events removeAllObjects];
752}
constexpr uint64_t kLogicalF1
constexpr uint64_t kLogicalNumpad1
constexpr uint64_t kPhysicalShiftLeft
constexpr uint64_t kPhysicalF1
constexpr uint64_t kPhysicalNumpad1
constexpr uint64_t kLogicalShiftLeft