1 /* 2 * PROJECT: ReactOS API tests 3 * LICENSE: GPL - See COPYING in the top level directory 4 * PURPOSE: Test for SystemParametersInfo function family 5 * PROGRAMMERS: Giannis Adamopoulos 6 */ 7 8 #include "precomp.h" 9 10 HWND hWnd1, hWnd2; 11 12 /* FIXME: test for HWND_TOP, etc...*/ 13 static int get_iwnd(HWND hWnd) 14 { 15 if(hWnd == hWnd1) return 1; 16 else if(hWnd == hWnd2) return 2; 17 else return 0; 18 } 19 20 LRESULT CALLBACK SysParamsTestProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) 21 { 22 int iwnd = get_iwnd(hWnd); 23 24 if(message > WM_USER || !iwnd || IsDWmMsg(message) || IseKeyMsg(message)) 25 return DefWindowProc(hWnd, message, wParam, lParam); 26 27 switch(message) 28 { 29 case WM_GETICON : 30 case WM_SETICON: 31 break; 32 case WM_WINDOWPOSCHANGING: 33 case WM_WINDOWPOSCHANGED: 34 { 35 WINDOWPOS* pwp = (WINDOWPOS*)lParam; 36 ok(wParam==0,"expected wParam=0\n"); 37 RECORD_MESSAGE(iwnd, message, SENT, get_iwnd(pwp->hwndInsertAfter), pwp->flags); 38 break; 39 } 40 default: 41 RECORD_MESSAGE(iwnd, message, SENT, 0,0); 42 } 43 return DefWindowProc(hWnd, message, wParam, lParam); 44 } 45 46 static void FlushMessages() 47 { 48 MSG msg; 49 50 while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) 51 { 52 int iwnd = get_iwnd(msg.hwnd); 53 if(!(msg.message > WM_USER || !iwnd || IsDWmMsg(msg.message) || IseKeyMsg(msg.message))) 54 RECORD_MESSAGE(iwnd, msg.message, POST,0,0); 55 DispatchMessageA( &msg ); 56 } 57 } 58 59 MSG_ENTRY NcMetricsChange_chain[]={ 60 {2,WM_WINDOWPOSCHANGING, SENT, 0, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOCOPYBITS|SWP_NOMOVE|SWP_NOZORDER|SWP_NOREDRAW}, 61 {2,WM_GETMINMAXINFO}, 62 {2,WM_NCCALCSIZE}, 63 {2,WM_WINDOWPOSCHANGED, SENT, 0, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOCOPYBITS|SWP_NOMOVE|SWP_NOZORDER|SWP_NOREDRAW | SWP_NOCLIENTSIZE | SWP_NOCLIENTMOVE | SWP_NOSIZE}, 64 {1,WM_WINDOWPOSCHANGING, SENT, 0, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOCOPYBITS|SWP_NOMOVE|SWP_NOZORDER|SWP_NOREDRAW}, 65 {1,WM_GETMINMAXINFO}, 66 {1,WM_NCCALCSIZE}, 67 {1,WM_WINDOWPOSCHANGED, SENT, 0, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOCOPYBITS|SWP_NOMOVE|SWP_NOZORDER|SWP_NOREDRAW | SWP_NOCLIENTSIZE | SWP_NOCLIENTMOVE | SWP_NOSIZE}, 68 {0,0}}; 69 70 MSG_ENTRY NcMetricsChange1_chain[]={ 71 {2,WM_WINDOWPOSCHANGING, SENT, 0, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOCOPYBITS|SWP_NOMOVE|SWP_NOZORDER|SWP_NOREDRAW}, 72 {2,WM_GETMINMAXINFO}, 73 {2,WM_NCCALCSIZE}, 74 {2,WM_WINDOWPOSCHANGED, SENT, 0, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOCOPYBITS|SWP_NOMOVE|SWP_NOZORDER|SWP_NOREDRAW | SWP_NOCLIENTSIZE | SWP_NOCLIENTMOVE | SWP_NOSIZE}, 75 {1,WM_WINDOWPOSCHANGING, SENT, 0, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOCOPYBITS|SWP_NOMOVE|SWP_NOZORDER|SWP_NOREDRAW}, 76 {1,WM_GETMINMAXINFO}, 77 {1,WM_NCCALCSIZE}, 78 {1,WM_WINDOWPOSCHANGED, SENT, 0, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOCOPYBITS|SWP_NOMOVE|SWP_NOZORDER|SWP_NOREDRAW | SWP_NOCLIENTSIZE | SWP_NOCLIENTMOVE | SWP_NOSIZE}, 79 {2,WM_SETTINGCHANGE}, 80 {1,WM_SETTINGCHANGE}, 81 {0,0}}; 82 83 MSG_ENTRY CaptionHeight_chain[]={ 84 {2,WM_WINDOWPOSCHANGING, SENT, 0, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOCOPYBITS|SWP_NOMOVE|SWP_NOZORDER|SWP_NOREDRAW}, 85 {2,WM_GETMINMAXINFO}, 86 {2,WM_NCCALCSIZE}, 87 {2,WM_WINDOWPOSCHANGED, SENT, 0, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOCOPYBITS|SWP_NOMOVE|SWP_NOZORDER|SWP_NOREDRAW | SWP_NOCLIENTSIZE}, 88 {2,WM_MOVE}, 89 {1,WM_WINDOWPOSCHANGING, SENT, 0, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOCOPYBITS|SWP_NOMOVE|SWP_NOZORDER|SWP_NOREDRAW}, 90 {1,WM_GETMINMAXINFO}, 91 {1,WM_NCCALCSIZE}, 92 {1,WM_WINDOWPOSCHANGED, SENT, 0, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOCOPYBITS|SWP_NOMOVE|SWP_NOZORDER|SWP_NOREDRAW | SWP_NOCLIENTSIZE}, 93 {1,WM_MOVE}, 94 {0,0}}; 95 96 static void Test_NonClientMetrics() 97 { 98 NONCLIENTMETRICS NonClientMetrics; 99 100 /* WARNING: this test requires themes and dwm to be disabled */ 101 102 SetCursorPos(0,0); 103 104 /* Retrieve th non client metrics */ 105 NonClientMetrics.cbSize = sizeof(NONCLIENTMETRICS); 106 SystemParametersInfo(SPI_GETNONCLIENTMETRICS, sizeof(NONCLIENTMETRICS), &NonClientMetrics, 0); 107 FlushMessages(); 108 COMPARE_CACHE(empty_chain); 109 110 /* Set the non client metric without making any change */ 111 SystemParametersInfo(SPI_SETNONCLIENTMETRICS, sizeof(NONCLIENTMETRICS), &NonClientMetrics, 0); 112 FlushMessages(); 113 COMPARE_CACHE(NcMetricsChange_chain); 114 115 /* Set the same metrics again with the SPIF_SENDCHANGE param */ 116 SystemParametersInfo(SPI_SETNONCLIENTMETRICS, sizeof(NONCLIENTMETRICS), &NonClientMetrics, SPIF_SENDCHANGE|SPIF_UPDATEINIFILE ); 117 FlushMessages(); 118 COMPARE_CACHE(NcMetricsChange1_chain); 119 120 /* Slightly change the caption height */ 121 NonClientMetrics.iCaptionHeight += 1; 122 SystemParametersInfo(SPI_SETNONCLIENTMETRICS, sizeof(NONCLIENTMETRICS), &NonClientMetrics, 0); 123 FlushMessages(); 124 COMPARE_CACHE(CaptionHeight_chain); 125 126 /* Restore the original caption height */ 127 NonClientMetrics.iCaptionHeight -= 1; 128 SystemParametersInfo(SPI_SETNONCLIENTMETRICS, sizeof(NONCLIENTMETRICS), &NonClientMetrics, 0); 129 FlushMessages(); 130 COMPARE_CACHE(CaptionHeight_chain); 131 } 132 133 static void Test_MouseSpeed() 134 { 135 ULONG ulMouseSpeed, temp; 136 BOOL ret; 137 138 ret = SystemParametersInfo(SPI_GETMOUSESPEED, 0, &ulMouseSpeed, 0); 139 ok(ret, "SystemParametersInfo failed\n"); 140 ok(ulMouseSpeed >= 1 && ulMouseSpeed <=20, "Wrong mouse speed (%d)\n", (int)ulMouseSpeed); 141 142 temp = 1; 143 ret = SystemParametersInfo(SPI_SETMOUSESPEED, 0, (PVOID)temp, SPIF_SENDCHANGE | SPIF_UPDATEINIFILE); 144 ok(ret, "SystemParametersInfo failed\n"); 145 ret = SystemParametersInfo(SPI_GETMOUSESPEED, 0, &temp, 0); 146 ok(ret, "SystemParametersInfo failed\n"); 147 ok(temp == 1, "SPI_GETMOUSESPEED did not get value set by SPI_SETMOUSESPEED (%d instead of 1)\n", (int)temp); 148 149 temp = 20; 150 ret = SystemParametersInfo(SPI_SETMOUSESPEED, 0, (PVOID)temp, SPIF_SENDCHANGE | SPIF_UPDATEINIFILE); 151 ok(ret, "SystemParametersInfo failed\n"); 152 ret = SystemParametersInfo(SPI_GETMOUSESPEED, 0, &temp, 0); 153 ok(ret, "SystemParametersInfo failed\n"); 154 ok(temp == 20, "SPI_GETMOUSESPEED did not get value set by SPI_SETMOUSESPEED (%d instead of 20)\n", (int)temp); 155 156 temp = 21; 157 ret = SystemParametersInfo(SPI_SETMOUSESPEED, 0, (PVOID)temp, SPIF_SENDCHANGE | SPIF_UPDATEINIFILE); 158 ok(!ret, "expected SystemParametersInfo to fail\n"); 159 ret = SystemParametersInfo(SPI_GETMOUSESPEED, 0, &temp, 0); 160 ok(ret, "SystemParametersInfo failed\n"); 161 ok(temp == 20, "SPI_GETMOUSESPEED got unexpected value (%d instead of 20)\n", (int)temp); 162 163 temp = 0; 164 ret = SystemParametersInfo(SPI_SETMOUSESPEED, 0, (PVOID)temp, SPIF_SENDCHANGE | SPIF_UPDATEINIFILE); 165 ok(!ret, "expected SystemParametersInfo to fail\n"); 166 ret = SystemParametersInfo(SPI_GETMOUSESPEED, 0, &temp, 0); 167 ok(ret, "SystemParametersInfo failed\n"); 168 ok(temp == 20, "SPI_GETMOUSESPEED got unexpected value (%d instead of 20)\n", (int)temp); 169 170 ret = SystemParametersInfo(SPI_SETMOUSESPEED, 0, (PVOID)ulMouseSpeed, SPIF_SENDCHANGE | SPIF_UPDATEINIFILE); 171 ok(ret, "SystemParametersInfo failed\n"); 172 } 173 174 START_TEST(SystemParametersInfo) 175 { 176 RegisterSimpleClass(SysParamsTestProc, L"sysparamstest"); 177 hWnd1 = CreateWindowW(L"sysparamstest", L"sysparamstest", WS_OVERLAPPEDWINDOW, 178 20, 20, 300, 300, NULL, NULL, 0, NULL); 179 180 hWnd2 = CreateWindowW(L"sysparamstest", L"sysparamstest", WS_OVERLAPPEDWINDOW, 181 200, 200, 300, 300, NULL, NULL, 0, NULL); 182 183 Test_NonClientMetrics(); 184 Test_MouseSpeed(); 185 186 DestroyWindow(hWnd1); 187 DestroyWindow(hWnd2); 188 UnregisterClassW(L"sysparamstest", 0); 189 } 190