From 31bf4a328561debe2874785d38d8135ce96fa085 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Sharma?= <737941+loic-sharma@users.noreply.github.com> Date: Wed, 17 Jan 2024 15:36:22 -0800 Subject: [PATCH] [Windows] Reduce Visual Studio build errors caused by keyboard unit tests (flutter/engine#49814) The `EXPECT_CALL_IS_EVENT` macro used features that are not supported by Visual Studio 2022's intellisense, which results in >130 errors when editing in Visual Studio. These issues only affect the editing experience, building still works as expected. This change reduces false errors in Visual Studio by making `EXPECT_CALL_IS_EVENT` buildable in Visual Studio. [C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style --- .../platform/windows/keyboard_unittests.cc | 8 +++++--- .../platform/windows/testing/test_keyboard.h | 20 +++++++++++-------- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/engine/src/flutter/shell/platform/windows/keyboard_unittests.cc b/engine/src/flutter/shell/platform/windows/keyboard_unittests.cc index 629c7ebdea..7265dd5d2d 100644 --- a/engine/src/flutter/shell/platform/windows/keyboard_unittests.cc +++ b/engine/src/flutter/shell/platform/windows/keyboard_unittests.cc @@ -544,9 +544,11 @@ class KeyboardTest : public WindowsTest { // Define compound `expect` in macros. If they're defined in functions, the // stacktrace wouldn't print where the function is called in the unit tests. -#define EXPECT_CALL_IS_EVENT(_key_call, ...) \ - EXPECT_EQ(_key_call.type, KeyCall::kKeyCallOnKey); \ - EXPECT_EVENT_EQUALS(_key_call.key_event, __VA_ARGS__); +#define EXPECT_CALL_IS_EVENT(_key_call, _type, _physical, _logical, \ + _character, _synthesized) \ + EXPECT_EQ(_key_call.type, KeyCall::kKeyCallOnKey); \ + EXPECT_EVENT_EQUALS(_key_call.key_event, _type, _physical, _logical, \ + _character, _synthesized); #define EXPECT_CALL_IS_TEXT(_key_call, u16_string) \ EXPECT_EQ(_key_call.type, KeyCall::kKeyCallOnText); \ diff --git a/engine/src/flutter/shell/platform/windows/testing/test_keyboard.h b/engine/src/flutter/shell/platform/windows/testing/test_keyboard.h index 1ec3a3b38c..bcadb6f512 100644 --- a/engine/src/flutter/shell/platform/windows/testing/test_keyboard.h +++ b/engine/src/flutter/shell/platform/windows/testing/test_keyboard.h @@ -145,13 +145,17 @@ class MockMessageQueue { // Expect the |_target| FlutterKeyEvent has the required properties. #define EXPECT_EVENT_EQUALS(_target, _type, _physical, _logical, _character, \ _synthesized) \ - EXPECT_PRED_FORMAT2(_EventEquals, _target, \ - (FlutterKeyEvent{ \ - .type = _type, \ - .physical = _physical, \ - .logical = _logical, \ - .character = _character, \ - .synthesized = _synthesized, \ - })); + EXPECT_PRED_FORMAT2( \ + _EventEquals, _target, \ + (FlutterKeyEvent{ \ + /* struct_size = */ sizeof(FlutterKeyEvent), \ + /* timestamp = */ 0, \ + /* type = */ _type, \ + /* physical = */ _physical, \ + /* logical = */ _logical, \ + /* character = */ _character, \ + /* synthesized = */ _synthesized, \ + /* device_type = */ kFlutterKeyEventDeviceTypeKeyboard, \ + })); #endif // FLUTTER_SHELL_PLATFORM_WINDOWS_TESTING_TEST_KEYBOARD_H_