6 #include "gtest/gtest.h"
14 #define FLUTTER_NOINLINE __declspec(noinline)
16 #define FLUTTER_NOINLINE __attribute__((noinline))
19 using TestWindowProcDelegate = std::function<std::optional<
20 LRESULT>(HWND hwnd, UINT
message, WPARAM wparam, LPARAM lparam)>;
25 bool TestWindowProcCallback(HWND hwnd,
31 TestWindowProcDelegate& delegate =
32 *
static_cast<TestWindowProcDelegate*
>(
user_data);
33 auto delegate_result = delegate(hwnd,
message, wparam, lparam);
34 if (delegate_result) {
35 *result = *delegate_result;
37 return delegate_result.has_value();
42 bool TestWindowProcCallback2(HWND hwnd,
54 TEST(WindowProcDelegateManagerTest, CallsCorrectly) {
59 TestWindowProcDelegate delegate = [&called, &dummy_hwnd](
60 HWND hwnd, UINT
message, WPARAM wparam,
63 EXPECT_EQ(hwnd, dummy_hwnd);
67 return std::optional<LRESULT>();
76 TEST(WindowProcDelegateManagerTest, ReplacementRegister) {
79 bool called_a =
false;
80 TestWindowProcDelegate delegate_a =
81 [&called_a](HWND hwnd, UINT
message, WPARAM wparam, LPARAM lparam) {
83 return std::optional<LRESULT>();
85 bool called_b =
false;
86 TestWindowProcDelegate delegate_b =
87 [&called_b](HWND hwnd, UINT
message, WPARAM wparam, LPARAM lparam) {
89 return std::optional<LRESULT>();
98 EXPECT_FALSE(called_a);
99 EXPECT_TRUE(called_b);
102 TEST(WindowProcDelegateManagerTest, RegisterMultiple) {
105 bool called_a =
false;
106 TestWindowProcDelegate delegate_a =
107 [&called_a](HWND hwnd, UINT
message, WPARAM wparam, LPARAM lparam) {
109 return std::optional<LRESULT>();
111 bool called_b =
false;
112 TestWindowProcDelegate delegate_b =
113 [&called_b](HWND hwnd, UINT
message, WPARAM wparam, LPARAM lparam) {
115 return std::optional<LRESULT>();
124 EXPECT_TRUE(called_a);
125 EXPECT_TRUE(called_b);
128 TEST(WindowProcDelegateManagerTest, Ordered) {
129 TestWindowProcDelegate delegate_1 = [](HWND hwnd, UINT
message, WPARAM wparam,
130 LPARAM lparam) {
return 1; };
131 TestWindowProcDelegate delegate_2 = [](HWND hwnd, UINT
message, WPARAM wparam,
132 LPARAM lparam) {
return 2; };
142 std::optional<LRESULT> result =
145 EXPECT_EQ(result, 1);
156 std::optional<LRESULT> result =
159 EXPECT_EQ(result, 2);
163 TEST(WindowProcDelegateManagerTest, ConflictingDelegates) {
166 bool called_a =
false;
167 TestWindowProcDelegate delegate_a =
168 [&called_a](HWND hwnd, UINT
message, WPARAM wparam, LPARAM lparam) {
170 return std::optional<LRESULT>(1);
172 bool called_b =
false;
173 TestWindowProcDelegate delegate_b =
174 [&called_b](HWND hwnd, UINT
message, WPARAM wparam, LPARAM lparam) {
176 return std::optional<LRESULT>(1);
188 EXPECT_TRUE(called_a || called_b);
189 EXPECT_NE(called_a, called_b);
192 TEST(WindowProcDelegateManagerTest, Unregister) {
196 TestWindowProcDelegate delegate = [&called](HWND hwnd, UINT
message,
197 WPARAM wparam, LPARAM lparam) {
199 return std::optional<LRESULT>();
205 EXPECT_FALSE(result);
206 EXPECT_FALSE(called);