From: Patrick Rudolph Subject: [PATCH 2/2] user32: add tests for valid cbSize in GetMonitorInfoA try 2 Message-Id: <8f8d0a3ee9ac2bf4abc8e6e2d0a0b47a@das-labor.org> Date: Fri, 18 Apr 2014 19:13:07 +0200 check for valid cbSize in user32.GetMonitorInfoA fixes bug http://bugs.winehq.org/show_bug.cgi?id=35788 try 2: add more test-cases and check returned values From 51130d189b269af0ffa3ff32657ecf2001cd606f Mon Sep 17 00:00:00 2001 From: Patrick Rudolph Date: Fri, 18 Apr 2014 19:07:55 +0200 Subject: [PATCH] user32: add tests for cbSize in GetMonitorInfoA --- dlls/user32/tests/monitor.c | 59 +++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 57 insertions(+), 2 deletions(-) diff --git a/dlls/user32/tests/monitor.c b/dlls/user32/tests/monitor.c index a2df20e..32b1f8b 100644 --- a/dlls/user32/tests/monitor.c +++ b/dlls/user32/tests/monitor.c @@ -296,6 +296,36 @@ static void test_monitors(void) HMONITOR monitor, primary, nearest; POINT pt; RECT rc; + MONITORINFO mi; + MONITORINFOEXA miex; + BOOL ret; + DWORD i; + + const struct + { + DWORD cbSize; + BOOL ret; + } testdatami[] = { + {0, FALSE}, + {sizeof(MONITORINFO)+1, FALSE}, + {sizeof(MONITORINFO)-1, FALSE}, + {sizeof(MONITORINFO), TRUE}, + {-1, FALSE}, + {0xdeadbeef, FALSE}, + }; + + const struct + { + DWORD cbSize; + BOOL ret; + } testdatamiex[] = { + {0, FALSE}, + {sizeof(MONITORINFOEXA)+1, FALSE}, + {sizeof(MONITORINFOEXA)-1, FALSE}, + {sizeof(MONITORINFOEXA), TRUE}, + {-1, FALSE}, + {0xdeadbeef, FALSE}, + }; if (!pMonitorFromPoint || !pMonitorFromWindow || !pMonitorFromRect) { @@ -351,8 +381,6 @@ static void test_monitors(void) nearest = primary; while (monitor != NULL) { - MONITORINFO mi; - BOOL ret; ok( monitor != primary, "got primary %p\n", monitor ); nearest = monitor; mi.cbSize = sizeof(mi); @@ -362,6 +390,33 @@ static void test_monitors(void) monitor = pMonitorFromRect( &rc, MONITOR_DEFAULTTONULL ); } + /* tests for cbSize in MONITORINFO */ + monitor = pMonitorFromWindow( 0, MONITOR_DEFAULTTOPRIMARY ); + for (i = 0; i < (sizeof(testdatami) / sizeof(testdatami[0])); i++) + { + memset( &mi, 0, sizeof(mi) ); + mi.cbSize = testdatami[i].cbSize; + ret = pGetMonitorInfoA( monitor, &mi ); + ok( ret == testdatami[i].ret, "GetMonitorInfo returned wrong value\n" ); + if (ret) + ok( (mi.dwFlags & MONITORINFOF_PRIMARY), "MONITORINFOF_PRIMARY flag isn't set\n" ); + else + ok( !(mi.dwFlags & MONITORINFOF_PRIMARY), "MONITORINFOF_PRIMARY flag is set\n" ); + } + + /* tests for cbSize in MONITORINFOEXA */ + for (i = 0; i < (sizeof(testdatamiex) / sizeof(testdatamiex[0])); i++) + { + memset( &miex, 0, sizeof(miex) ); + miex.cbSize = testdatamiex[i].cbSize; + ret = pGetMonitorInfoA( monitor, (LPMONITORINFO)&miex ); + ok( ret == testdatamiex[i].ret, "GetMonitorInfo returned wrong value\n" ); + if (ret) + ok( (miex.dwFlags & MONITORINFOF_PRIMARY), "MONITORINFOF_PRIMARY flag isn't set\n" ); + else + ok( !(miex.dwFlags & MONITORINFOF_PRIMARY), "MONITORINFOF_PRIMARY flag is set\n" ); + } + SetRect( &rc, rc.left+1, rc.top+1, rc.left+2, rc.top+2 ); monitor = pMonitorFromRect( &rc, MONITOR_DEFAULTTONULL ); -- 1.8.5.3