Replaced most uses of the auto-generated glue code by explicit calls
[wine] / dlls / user / tests / sysparams.c
1 /* Unit test suite for functions SystemParametersInfo and GetSystemMetrics.
2  *
3  * Copyright 2002 Andriy Palamarchuk
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18  */
19
20 #include <assert.h>
21 #include <stdlib.h>
22 #include <stdio.h>
23
24 #include "wine/test.h"
25 #include "winbase.h"
26 #include "winreg.h"
27 #include "winuser.h"
28
29 #ifndef IDI_APPLICATIONA
30 # define IDI_APPLICATIONA IDI_APPLICATION
31 #endif
32 #ifndef IDC_ARROWA
33 # define IDC_ARROWA IDC_ARROW
34 #endif
35
36 #ifndef SPI_GETDESKWALLPAPER
37 # define SPI_GETDESKWALLPAPER 0x0073
38 #endif
39
40 static int strict;
41
42 #define eq(received, expected, label, type) \
43         ok((received) == (expected), "%s: got " type " instead of " type, (label),(received),(expected))
44
45
46 #define SPI_SETBEEP_REGKEY           "Control Panel\\Sound"
47 #define SPI_SETBEEP_VALNAME          "Beep"
48 #define SPI_SETMOUSE_REGKEY             "Control Panel\\Mouse"
49 #define SPI_SETMOUSE_VALNAME1           "MouseThreshold1"
50 #define SPI_SETMOUSE_VALNAME2           "MouseThreshold2"
51 #define SPI_SETMOUSE_VALNAME3           "MouseSpeed"
52 #define SPI_SETBORDER_REGKEY         "Control Panel\\Desktop\\WindowMetrics"
53 #define SPI_SETBORDER_VALNAME        "BorderWidth"
54 #define SPI_SETKEYBOARDSPEED_REGKEY             "Control Panel\\Keyboard"
55 #define SPI_SETKEYBOARDSPEED_VALNAME            "KeyboardSpeed"
56 #define SPI_SETSCREENSAVETIMEOUT_REGKEY         "Control Panel\\Desktop"
57 #define SPI_SETSCREENSAVETIMEOUT_VALNAME        "ScreenSaveTimeOut"
58 #define SPI_SETSCREENSAVEACTIVE_REGKEY          "Control Panel\\Desktop"
59 #define SPI_SETSCREENSAVEACTIVE_VALNAME         "ScreenSaveActive"
60 #define SPI_SETGRIDGRANULARITY_REGKEY           "Control Panel\\Desktop"
61 #define SPI_SETGRIDGRANULARITY_VALNAME          "GridGranularity"
62 #define SPI_SETKEYBOARDDELAY_REGKEY             "Control Panel\\Keyboard"
63 #define SPI_SETKEYBOARDDELAY_VALNAME            "KeyboardDelay"
64 #define SPI_SETICONTITLEWRAP_REGKEY1            "Control Panel\\Desktop\\WindowMetrics"
65 #define SPI_SETICONTITLEWRAP_REGKEY2            "Control Panel\\Desktop"
66 #define SPI_SETICONTITLEWRAP_VALNAME            "IconTitleWrap"
67 #define SPI_SETMENUDROPALIGNMENT_REGKEY1        "Software\\Microsoft\\Windows NT\\CurrentVersion\\Windows"
68 #define SPI_SETMENUDROPALIGNMENT_REGKEY2        "Control Panel\\Desktop"
69 #define SPI_SETMENUDROPALIGNMENT_VALNAME        "MenuDropAlignment"
70 #define SPI_SETDOUBLECLKWIDTH_REGKEY1           "Control Panel\\Mouse"
71 #define SPI_SETDOUBLECLKWIDTH_REGKEY2           "Control Panel\\Desktop"
72 #define SPI_SETDOUBLECLKWIDTH_VALNAME           "DoubleClickWidth"
73 #define SPI_SETDOUBLECLKHEIGHT_REGKEY1          "Control Panel\\Mouse"
74 #define SPI_SETDOUBLECLKHEIGHT_REGKEY2          "Control Panel\\Desktop"
75 #define SPI_SETDOUBLECLKHEIGHT_VALNAME          "DoubleClickHeight"
76 #define SPI_SETDOUBLECLICKTIME_REGKEY           "Control Panel\\Mouse"
77 #define SPI_SETDOUBLECLICKTIME_VALNAME          "DoubleClickSpeed"
78 #define SPI_SETMOUSEBUTTONSWAP_REGKEY           "Control Panel\\Mouse"
79 #define SPI_SETMOUSEBUTTONSWAP_VALNAME          "SwapMouseButtons"
80 #define SPI_SETWORKAREA_REGKEY                  "Control Panel\\Desktop"
81 #define SPI_SETWORKAREA_VALNAME                 "WINE_WorkArea"
82 #define SPI_SETSHOWSOUNDS_REGKEY     "Control Panel\\Accessibility\\ShowSounds"
83 #define SPI_SETSHOWSOUNDS_VALNAME    "On"
84 #define SPI_SETDRAGFULLWINDOWS_REGKEY           "Control Panel\\Desktop"
85 #define SPI_SETDRAGFULLWINDOWS_VALNAME          "DragFullWindows"
86 #define SPI_SETDESKWALLPAPER_REGKEY             "Control Panel\\Desktop"
87 #define SPI_SETDESKWALLPAPER_VALNAME            "Wallpaper"
88 /* FIXME - don't have access to Windows with this action (W95, NT5.0). Set real values */
89 #define SPI_SETKEYBOARDPREF_REGKEY      "Control Panel\\Desktop"
90 #define SPI_SETKEYBOARDPREF_VALNAME     "WINE_WorkArea"
91 #define SPI_SETSCREENREADER_REGKEY      "Control Panel\\Desktop"
92 #define SPI_SETSCREENREADER_VALNAME     "???"
93
94 /* volatile registry branch under CURRENT_USER_REGKEY for temporary values storage */
95 #define WINE_CURRENT_USER_REGKEY     "Wine"
96
97 static HWND ghTestWnd;
98
99 static DWORD WINAPI SysParamsThreadFunc( LPVOID lpParam );
100 static LRESULT CALLBACK SysParamsTestWndProc( HWND hWnd, UINT msg, WPARAM wParam,
101                                               LPARAM lParam );
102 static int change_counter;
103 static int change_last_param;
104
105 static LRESULT CALLBACK SysParamsTestWndProc( HWND hWnd, UINT msg, WPARAM wParam,
106                                               LPARAM lParam )
107 {
108     switch (msg) {
109
110     case WM_SETTINGCHANGE:
111         if (change_counter>0) {
112             ok(0,"too many changes counter=%d last change=%d\n",
113                change_counter,change_last_param);
114         }
115         change_counter++;
116         change_last_param = wParam;
117         break;
118
119     case WM_DESTROY:
120         PostQuitMessage( 0 );
121         break;
122
123     default:
124         return( DefWindowProcA( hWnd, msg, wParam, lParam ) );
125     }
126
127     return 0;
128 }
129
130 /*
131 Performs testing for system parameters messages
132 params:
133  - system parameter id
134  - supposed value of the registry key
135 */
136 static void test_change_message( int action, int optional )
137 {
138     if (change_counter==0 && optional==1)
139         return;
140     ok( 1 == change_counter,
141         "Missed a message: change_counter=%d", change_counter );
142     change_counter = 0;
143     ok( action == change_last_param,
144         "Wrong action got %d expected %d", change_last_param, action );
145     change_last_param = 0;
146 }
147
148 /*
149  * Tests the HKEY_CURRENT_USER subkey value.
150  * The value should contain string value.
151  *
152  * Params:
153  * lpsSubKey - subkey name
154  * lpsRegName - registry entry name
155  * lpsTestValue - value to test
156  */
157 static void _test_reg_key( LPSTR subKey1, LPSTR subKey2, LPSTR valName, LPSTR testValue )
158 {
159     CHAR  value[MAX_PATH];
160     DWORD valueLen;
161     DWORD type;
162     HKEY hKey;
163     LONG rc;
164     int found=0;
165
166     *value='\0';
167     valueLen=sizeof(value);
168     RegOpenKeyA( HKEY_CURRENT_USER, subKey1, &hKey );
169     rc=RegQueryValueExA( hKey, valName, NULL, &type, value, &valueLen );
170     RegCloseKey( hKey );
171     if (rc==ERROR_SUCCESS)
172     {
173         ok( !strcmp( testValue, value ),
174             "Wrong value in registry: subKey=%s, valName=%s, testValue=%s, value=%s",
175             subKey1, valName, testValue, value );
176         found++;
177     }
178     else if (strict)
179     {
180         ok(0,"Missing registry entry: subKey=%s, valName=%s",
181            subKey1, valName);
182     }
183     if (subKey2 && !strict)
184     {
185         *value='\0';
186         valueLen=sizeof(value);
187         RegOpenKeyA( HKEY_CURRENT_USER, subKey2, &hKey );
188         rc=RegQueryValueExA( hKey, valName, NULL, &type, value, &valueLen );
189         RegCloseKey( hKey );
190         if (rc==ERROR_SUCCESS)
191         {
192             ok( !strcmp( testValue, value ),
193                 "Wrong value in registry: subKey=%s, valName=%s, testValue=%s, value=%s",
194                 subKey2, valName, testValue, value );
195             found++;
196         }
197     }
198     ok(found,"Missing registry entry: %s in %s or %s",
199        valName, subKey1, (subKey2?subKey2:"<n/a>") );
200 }
201
202 #define test_reg_key( subKey, valName, testValue ) \
203     _test_reg_key( subKey, NULL, valName, testValue )
204 #define test_reg_key_ex( subKey1, subKey2, valName, testValue ) \
205     _test_reg_key( subKey1, subKey2, valName, testValue )
206
207 static void test_SPI_SETBEEP( void )                   /*      2 */
208 {
209     BOOL rc;
210     BOOL old_b;
211     BOOL b;
212     BOOL curr_val;
213
214     trace("testing SPI_{GET,SET}BEEP\n");
215     rc=SystemParametersInfoA( SPI_GETBEEP, 0, &old_b, 0 );
216     ok(rc!=0,"SystemParametersInfoA: rc=%d err=%ld\n",rc,GetLastError());
217
218     curr_val = TRUE;
219     rc=SystemParametersInfoA( SPI_SETBEEP, curr_val, 0, SPIF_UPDATEINIFILE | SPIF_SENDCHANGE );
220     ok(rc!=0,"SystemParametersInfoA: rc=%d err=%ld\n",rc,GetLastError());
221     test_change_message( SPI_SETBEEP, 0 );
222     test_reg_key( SPI_SETBEEP_REGKEY,
223                   SPI_SETBEEP_VALNAME,
224                   curr_val ? "Yes" : "No" );
225     rc=SystemParametersInfoA( SPI_GETBEEP, 0, &b, 0 );
226     ok(rc!=0,"SystemParametersInfoA: rc=%d err=%ld\n",rc,GetLastError());
227     eq( b, curr_val, "SPI_{GET,SET}BEEP", "%d" );
228     rc=SystemParametersInfoW( SPI_GETBEEP, 0, &b, 0 );
229     if (rc!=0 || GetLastError()!=ERROR_CALL_NOT_IMPLEMENTED)
230     {
231         ok(rc!=0,"SystemParametersInfoW: rc=%d err=%ld\n",rc,GetLastError());
232         eq( b, curr_val, "SystemParametersInfoW", "%d" );
233     }
234
235     /* is a message sent for the second change? */
236     rc=SystemParametersInfoA( SPI_SETBEEP, curr_val, 0, SPIF_UPDATEINIFILE | SPIF_SENDCHANGE );
237     ok(rc!=0,"SystemParametersInfoA: rc=%d err=%ld\n",rc,GetLastError());
238     test_change_message( SPI_SETBEEP, 0 );
239
240     curr_val = FALSE;
241     rc=SystemParametersInfoW( SPI_SETBEEP, curr_val, 0, SPIF_UPDATEINIFILE | SPIF_SENDCHANGE );
242     if (rc==0 && GetLastError()==ERROR_CALL_NOT_IMPLEMENTED)
243         rc=SystemParametersInfoA( SPI_SETBEEP, curr_val, 0, SPIF_UPDATEINIFILE | SPIF_SENDCHANGE );
244     ok(rc!=0,"SystemParametersInfo: rc=%d err=%ld\n",rc,GetLastError());
245     test_change_message( SPI_SETBEEP, 0 );
246     test_reg_key( SPI_SETBEEP_REGKEY,
247                   SPI_SETBEEP_VALNAME,
248                   curr_val ? "Yes" : "No" );
249     rc=SystemParametersInfoA( SPI_GETBEEP, 0, &b, 0 );
250     ok(rc!=0,"SystemParametersInfoA: rc=%d err=%ld\n",rc,GetLastError());
251     eq( b, curr_val, "SPI_{GET,SET}BEEP", "%d" );
252     rc=SystemParametersInfoW( SPI_GETBEEP, 0, &b, 0 );
253     if (rc!=0 || GetLastError()!=ERROR_CALL_NOT_IMPLEMENTED)
254     {
255         ok(rc!=0,"SystemParametersInfoW: rc=%d err=%ld\n",rc,GetLastError());
256         eq( b, curr_val, "SystemParametersInfoW", "%d" );
257     }
258     ok( MessageBeep( MB_OK ), "Return value of MessageBeep when sound is disabled" );
259
260     rc=SystemParametersInfoA( SPI_SETBEEP, old_b, 0, SPIF_UPDATEINIFILE );
261     ok(rc!=0,"***warning*** failed to restore the original value: rc=%d err=%ld\n",rc,GetLastError());
262 }
263
264 static char *setmouse_valuenames[3] = {
265     SPI_SETMOUSE_VALNAME1,
266     SPI_SETMOUSE_VALNAME2,
267     SPI_SETMOUSE_VALNAME3
268 };
269
270 /*
271  * Runs check for one setting of spi_setmouse.
272  */
273 static void run_spi_setmouse_test( int curr_val[], POINT *req_change, POINT *proj_change,
274                                    int nchange )
275 {
276     BOOL rc;
277     INT mi[3];
278     static int aw_turn = 0;
279
280     char buf[20];
281     int i;
282
283     aw_turn++;
284     rc=0;
285     if (aw_turn % 2!=0)        /* call unicode version each second call */
286         rc=SystemParametersInfoW( SPI_SETMOUSE, 0, curr_val, SPIF_UPDATEINIFILE | SPIF_SENDCHANGE );
287     if (aw_turn % 2==0 || (rc==0 && GetLastError()==ERROR_CALL_NOT_IMPLEMENTED))
288         rc=SystemParametersInfoA( SPI_SETMOUSE, 0, curr_val, SPIF_UPDATEINIFILE | SPIF_SENDCHANGE );
289     ok(rc!=0,"SystemParametersInfo: rc=%d err=%ld\n",rc,GetLastError());
290     test_change_message( SPI_SETMOUSE, 0 );
291     for (i = 0; i < 3; i++)
292     {
293         sprintf( buf, "%d", curr_val[i] );
294         test_reg_key( SPI_SETMOUSE_REGKEY, setmouse_valuenames[i], buf );
295     }
296
297     rc=SystemParametersInfoA( SPI_GETMOUSE, 0, mi, 0 );
298     ok(rc!=0,"SystemParametersInfoA: rc=%d err=%ld\n",rc,GetLastError());
299     for (i = 0; i < 3; i++)
300     {
301         ok(mi[i] == curr_val[i],
302            "incorrect value for %d: %d != %d", i, mi[i], curr_val[i]);
303     }
304
305     rc=SystemParametersInfoW( SPI_GETMOUSE, 0, mi, 0 );
306     if (rc!=0 && GetLastError()!=ERROR_CALL_NOT_IMPLEMENTED)
307     {
308         ok(rc!=0,"SystemParametersInfoA: rc=%d err=%ld\n",rc,GetLastError());
309         for (i = 0; i < 3; i++)
310         {
311             ok(mi[i] == curr_val[i],
312                "incorrect value for %d: %d != %d", i, mi[i], curr_val[i]);
313         }
314     }
315
316 #if 0  /* FIXME: this always fails for me  - AJ */
317     for (i = 0; i < nchange; i++)
318     {
319         POINT mv;
320         mouse_event( MOUSEEVENTF_ABSOLUTE | MOUSEEVENTF_MOVE, 0, 0, 0, 0 );
321         mouse_event( MOUSEEVENTF_MOVE, req_change[i].x, req_change[i].y, 0, 0 );
322         GetCursorPos( &mv );
323         ok( proj_change[i].x == mv.x, "Projected dx and real dx comparison. May fail under high load." );
324         ok( proj_change[i].y == mv.y, "Projected dy equals real dy. May fail under high load." );
325     }
326 #endif
327 }
328
329 static void test_SPI_SETMOUSE( void )                  /*      4 */
330 {
331     BOOL rc;
332     INT old_mi[3];
333
334     /* win nt default values - 6, 10, 1 */
335     INT curr_val[3] = {6, 10, 1};
336
337     /* requested and projected mouse movements */
338     POINT req_change[] =   { {6, 6}, { 7, 6}, { 8, 6}, {10, 10}, {11, 10}, {100, 100} };
339     POINT proj_change1[] = { {6, 6}, {14, 6}, {16, 6}, {20, 20}, {22, 20}, {200, 200} };
340     POINT proj_change2[] = { {6, 6}, {14, 6}, {16, 6}, {20, 20}, {44, 20}, {400, 400} };
341     POINT proj_change3[] = { {6, 6}, {14, 6}, {16, 6}, {20, 20}, {22, 20}, {200, 200} };
342     POINT proj_change4[] = { {6, 6}, { 7, 6}, { 8, 6}, {10, 10}, {11, 10}, {100, 100} };
343     POINT proj_change5[] = { {6, 6}, { 7, 6}, {16, 6}, {20, 20}, {22, 20}, {200, 200} };
344     POINT proj_change6[] = { {6, 6}, {28, 6}, {32, 6}, {40, 40}, {44, 40}, {400, 400} };
345     POINT proj_change7[] = { {6, 6}, {14, 6}, {32, 6}, {40, 40}, {44, 40}, {400, 400} };
346     POINT proj_change8[] = { {6, 6}, {28, 6}, {32, 6}, {40, 40}, {44, 40}, {400, 400} };
347
348     int nchange = sizeof( req_change ) / sizeof( POINT );
349
350     trace("testing SPI_{GET,SET}MOUSE\n");
351     rc=SystemParametersInfoA( SPI_GETMOUSE, 0, old_mi, 0 );
352     ok(rc!=0,"SystemParametersInfoA: rc=%d err=%ld\n",rc,GetLastError());
353
354     run_spi_setmouse_test( curr_val, req_change, proj_change1, nchange );
355
356     /* acceleration change */
357     curr_val[2] = 2;
358     run_spi_setmouse_test( curr_val, req_change, proj_change2, nchange );
359
360     /* acceleration change */
361     curr_val[2] = 3;
362     run_spi_setmouse_test( curr_val, req_change, proj_change3, nchange );
363
364     /* acceleration change */
365     curr_val[2] = 0;
366     run_spi_setmouse_test( curr_val, req_change, proj_change4, nchange );
367
368     /* threshold change */
369     curr_val[2] = 1;
370     curr_val[0] = 7;
371     run_spi_setmouse_test( curr_val, req_change, proj_change5, nchange );
372
373     /* threshold change */
374     curr_val[2] = 2;
375     curr_val[0] = 6;
376     curr_val[1] = 6;
377     run_spi_setmouse_test( curr_val, req_change, proj_change6, nchange );
378
379     /* threshold change */
380     curr_val[1] = 7;
381     run_spi_setmouse_test( curr_val, req_change, proj_change7, nchange );
382
383     /* threshold change */
384     curr_val[1] = 5;
385     run_spi_setmouse_test( curr_val, req_change, proj_change8, nchange );
386
387     rc=SystemParametersInfoA( SPI_SETMOUSE, 0, old_mi, SPIF_UPDATEINIFILE );
388     ok(rc!=0,"***warning*** failed to restore the original value: rc=%d err=%ld\n",rc,GetLastError());
389 }
390
391 static void test_setborder(UINT curr_val)
392 {
393     BOOL rc;
394     UINT border;
395     INT frame;
396     char buf[10];
397
398     rc=SystemParametersInfoA( SPI_SETBORDER, curr_val, 0, SPIF_UPDATEINIFILE | SPIF_SENDCHANGE );
399     ok(rc!=0,"SystemParametersInfoA: rc=%d err=%ld\n",rc,GetLastError());
400     test_change_message( SPI_SETBORDER, 1 );
401     sprintf( buf, "%d", curr_val );
402     test_reg_key( SPI_SETBORDER_REGKEY, SPI_SETBORDER_VALNAME, buf );
403
404     if (curr_val == 0)
405         curr_val = 1;
406     rc=SystemParametersInfoA( SPI_GETBORDER, 0, &border, 0 );
407     ok(rc!=0,"SystemParametersInfoA: rc=%d err=%ld\n",rc,GetLastError());
408     eq( border, curr_val, "SPI_{GET,SET}BORDER", "%d");
409
410     frame = curr_val + GetSystemMetrics( SM_CXDLGFRAME );
411     eq( frame, GetSystemMetrics( SM_CXFRAME ), "SM_CXFRAME", "%d" );
412     eq( frame, GetSystemMetrics( SM_CYFRAME ), "SM_CYFRAME", "%d" );
413     eq( frame, GetSystemMetrics( SM_CXSIZEFRAME ), "SM_CXSIZEFRAME", "%d" );
414     eq( frame, GetSystemMetrics( SM_CYSIZEFRAME ), "SM_CYSIZEFRAME", "%d" );
415 }
416
417 static void test_SPI_SETBORDER( void )                 /*      6 */
418 {
419     BOOL rc;
420     UINT old_border;
421
422     /* These tests hang when XFree86 4.0 for Windows is running (tested on
423      *  WinNT, SP2, Cygwin/XFree 4.1.0. Skip the test when XFree86 is
424      * running.
425      */
426     if (FindWindowA( NULL, "Cygwin/XFree86" ))
427         return;
428
429     trace("testing SPI_{GET,SET}BORDER\n");
430     rc=SystemParametersInfoA( SPI_GETBORDER, 0, &old_border, 0 );
431     ok(rc!=0,"SystemParametersInfoA: rc=%d err=%ld\n",rc,GetLastError());
432
433     test_setborder(1);
434     test_setborder(0);
435     test_setborder(7);
436     test_setborder(20);
437
438     /* This will restore sane values if the test hang previous run. */
439     if ( old_border == 7 || old_border == 20 )
440         old_border = -15;
441
442     rc=SystemParametersInfoA( SPI_SETBORDER, old_border, 0, SPIF_UPDATEINIFILE | SPIF_SENDCHANGE );
443     ok(rc!=0,"***warning*** failed to restore the original value: rc=%d err=%ld\n",rc,GetLastError());
444 }
445
446 static void test_SPI_SETKEYBOARDSPEED( void )          /*     10 */
447 {
448     BOOL rc;
449     UINT old_speed;
450     const UINT vals[]={0,20,31};
451     int i;
452
453     trace("testing SPI_{GET,SET}KEYBOARDSPEED\n");
454     rc=SystemParametersInfoA( SPI_GETKEYBOARDSPEED, 0, &old_speed, 0 );
455     ok(rc!=0,"SystemParametersInfoA: rc=%d err=%ld\n",rc,GetLastError());
456
457     for (i=0;i<sizeof(vals)/sizeof(*vals);i++)
458     {
459         UINT v;
460         char buf[10];
461
462         rc=SystemParametersInfoA( SPI_SETKEYBOARDSPEED, vals[i], 0,
463                                   SPIF_UPDATEINIFILE | SPIF_SENDCHANGE );
464         ok(rc!=0,"%d: rc=%d err=%ld\n",i,rc,GetLastError());
465         test_change_message( SPI_SETKEYBOARDSPEED, 0 );
466         sprintf( buf, "%d", vals[i] );
467         test_reg_key( SPI_SETKEYBOARDSPEED_REGKEY, SPI_SETKEYBOARDSPEED_VALNAME, buf );
468
469         rc=SystemParametersInfoA( SPI_GETKEYBOARDSPEED, 0, &v, 0 );
470         ok(rc!=0,"%d: rc=%d err=%ld\n",i,rc,GetLastError());
471         eq( v, vals[i], "SPI_{GET,SET}KEYBOARDSPEED", "%d" );
472     }
473
474     rc=SystemParametersInfoA( SPI_SETKEYBOARDSPEED, old_speed, 0, SPIF_UPDATEINIFILE );
475     ok(rc!=0,"***warning*** failed to restore the original value: rc=%d err=%ld\n",rc,GetLastError());
476 }
477
478 static void test_SPI_ICONHORIZONTALSPACING( void )     /*     13 */
479 {
480     BOOL rc;
481     INT old_spacing;
482     INT spacing;
483     INT curr_val;
484
485     trace("testing SPI_ICONHORIZONTALSPACING\n");
486     /* default value: 75 */
487     rc=SystemParametersInfoA( SPI_ICONHORIZONTALSPACING, 0, &old_spacing, 0 );
488     ok(rc!=0,"SystemParametersInfoA: rc=%d err=%ld\n",rc,GetLastError());
489
490     /* do not increase the value as it would upset the user's icon layout */
491     curr_val = (old_spacing > 32 ? old_spacing-1 : 32);
492     rc=SystemParametersInfoA( SPI_ICONHORIZONTALSPACING, curr_val, 0,
493                               SPIF_UPDATEINIFILE | SPIF_SENDCHANGE);
494     ok(rc!=0,"SystemParametersInfoA: rc=%d err=%ld\n",rc,GetLastError());
495     test_change_message( SPI_ICONHORIZONTALSPACING, 0 );
496     /* The registry keys depend on the Windows version and the values too
497      * => don't test them
498      */
499
500     rc=SystemParametersInfoA( SPI_ICONHORIZONTALSPACING, 0, &spacing, 0 );
501     ok(rc!=0,"SystemParametersInfoA: rc=%d err=%ld\n",rc,GetLastError());
502     eq( spacing, curr_val, "ICONHORIZONTALSPACING", "%d");
503     eq( GetSystemMetrics( SM_CXICONSPACING ), curr_val, "SM_CXICONSPACING", "%d" );
504
505     curr_val = 10;
506     rc=SystemParametersInfoA( SPI_ICONHORIZONTALSPACING, curr_val, 0,
507                               SPIF_UPDATEINIFILE | SPIF_SENDCHANGE);
508     ok(rc!=0,"SystemParametersInfoA: rc=%d err=%ld\n",rc,GetLastError());
509     curr_val = 32;      /*min value*/
510     test_change_message( SPI_ICONHORIZONTALSPACING, 0 );
511
512     rc=SystemParametersInfoA( SPI_ICONHORIZONTALSPACING, 0, &spacing, 0 );
513     ok(rc!=0,"SystemParametersInfoA: rc=%d err=%ld\n",rc,GetLastError());
514     eq( spacing, curr_val, "ICONHORIZONTALSPACING", "%d" );
515     eq( GetSystemMetrics( SM_CXICONSPACING ), curr_val, "SM_CXICONSPACING", "%d" );
516
517     rc=SystemParametersInfoA( SPI_ICONHORIZONTALSPACING, old_spacing, 0, SPIF_UPDATEINIFILE );
518     ok(rc!=0,"***warning*** failed to restore the original value: rc=%d err=%ld\n",rc,GetLastError());
519 }
520
521 static void test_SPI_SETSCREENSAVETIMEOUT( void )      /*     14 */
522 {
523     BOOL rc;
524     UINT old_timeout;
525     const UINT vals[]={0,32767};
526     int i;
527
528     trace("testing SPI_{GET,SET}SCREENSAVETIMEOUT\n");
529     rc=SystemParametersInfoA( SPI_GETSCREENSAVETIMEOUT, 0, &old_timeout, 0 );
530     ok(rc!=0,"SystemParametersInfoA: rc=%d err=%ld\n",rc,GetLastError());
531
532     for (i=0;i<sizeof(vals)/sizeof(*vals);i++)
533     {
534         UINT v;
535         char buf[10];
536
537         rc=SystemParametersInfoA( SPI_SETSCREENSAVETIMEOUT, vals[i], 0,
538                                SPIF_UPDATEINIFILE | SPIF_SENDCHANGE );
539         ok(rc!=0,"%d: rc=%d err=%ld\n",i,rc,GetLastError());
540         test_change_message( SPI_SETSCREENSAVETIMEOUT, 0 );
541         sprintf( buf, "%d", vals[i] );
542         test_reg_key( SPI_SETSCREENSAVETIMEOUT_REGKEY,
543                       SPI_SETSCREENSAVETIMEOUT_VALNAME, buf );
544
545         SystemParametersInfoA( SPI_GETSCREENSAVETIMEOUT, 0, &v, 0 );
546         ok(rc!=0,"%d: rc=%d err=%ld\n",i,rc,GetLastError());
547         eq( v, vals[i], "SPI_{GET,SET}SCREENSAVETIMEOUT", "%d" );
548     }
549
550     rc=SystemParametersInfoA( SPI_SETSCREENSAVETIMEOUT, old_timeout, 0,
551                               SPIF_UPDATEINIFILE );
552     ok(rc!=0,"***warning*** failed to restore the original value: rc=%d err=%ld\n",rc,GetLastError());
553 }
554
555 static void test_SPI_SETSCREENSAVEACTIVE( void )       /*     17 */
556 {
557     BOOL rc;
558     BOOL old_b;
559     const UINT vals[]={TRUE,FALSE};
560     int i;
561
562     trace("testing SPI_{GET,SET}SCREENSAVEACTIVE\n");
563     rc=SystemParametersInfoA( SPI_GETSCREENSAVEACTIVE, 0, &old_b, 0 );
564     ok(rc!=0,"SystemParametersInfoA: rc=%d err=%ld\n",rc,GetLastError());
565
566     for (i=0;i<sizeof(vals)/sizeof(*vals);i++)
567     {
568         UINT v;
569
570         rc=SystemParametersInfoA( SPI_SETSCREENSAVEACTIVE, vals[i], 0,
571                                   SPIF_UPDATEINIFILE | SPIF_SENDCHANGE );
572         ok(rc!=0,"%d: rc=%d err=%ld\n",i,rc,GetLastError());
573         test_change_message( SPI_SETSCREENSAVEACTIVE, 0 );
574         test_reg_key( SPI_SETSCREENSAVEACTIVE_REGKEY,
575                       SPI_SETSCREENSAVEACTIVE_VALNAME,
576                       vals[i] ? "1" : "0" );
577
578         rc=SystemParametersInfoA( SPI_GETSCREENSAVEACTIVE, 0, &v, 0 );
579         ok(rc!=0,"%d: rc=%d err=%ld\n",i,rc,GetLastError());
580         eq( v, vals[i], "SPI_{GET,SET}SCREENSAVEACTIVE", "%d" );
581     }
582
583     rc=SystemParametersInfoA( SPI_SETSCREENSAVEACTIVE, old_b, 0, SPIF_UPDATEINIFILE );
584     ok(rc!=0,"***warning*** failed to restore the original value: rc=%d err=%ld\n",rc,GetLastError());
585 }
586
587 static void test_SPI_SETGRIDGRANULARITY( void )        /*     19 */
588 {
589     /* ??? */;
590 }
591
592 static void test_SPI_SETKEYBOARDDELAY( void )          /*     23 */
593 {
594     BOOL rc;
595     UINT old_delay;
596     const UINT vals[]={0,3};
597     int i;
598
599     trace("testing SPI_{GET,SET}KEYBOARDDELAY\n");
600     rc=SystemParametersInfoA( SPI_GETKEYBOARDDELAY, 0, &old_delay, 0 );
601     ok(rc!=0,"SystemParametersInfoA: rc=%d err=%ld\n",rc,GetLastError());
602
603     for (i=0;i<sizeof(vals)/sizeof(*vals);i++)
604     {
605         UINT delay;
606         char buf[10];
607
608         rc=SystemParametersInfoA( SPI_SETKEYBOARDDELAY, vals[i], 0,
609                                   SPIF_UPDATEINIFILE | SPIF_SENDCHANGE );
610         ok(rc!=0,"%d: rc=%d err=%ld\n",i,rc,GetLastError());
611         test_change_message( SPI_SETKEYBOARDDELAY, 0 );
612         sprintf( buf, "%d", vals[i] );
613         test_reg_key( SPI_SETKEYBOARDDELAY_REGKEY,
614                       SPI_SETKEYBOARDDELAY_VALNAME, buf );
615
616         rc=SystemParametersInfoA( SPI_GETKEYBOARDDELAY, 0, &delay, 0 );
617         ok(rc!=0,"%d: rc=%d err=%ld\n",i,rc,GetLastError());
618         eq( delay, vals[i], "SPI_{GET,SET}KEYBOARDDELAY", "%d" );
619     }
620
621     rc=SystemParametersInfoA( SPI_SETKEYBOARDDELAY, old_delay, 0, SPIF_UPDATEINIFILE );
622     ok(rc!=0,"***warning*** failed to restore the original value: rc=%d err=%ld\n",rc,GetLastError());
623 }
624
625 static void test_SPI_ICONVERTICALSPACING( void )       /*     24 */
626 {
627     BOOL rc;
628     INT old_spacing;
629     INT spacing;
630     INT curr_val;
631
632     trace("testing SPI_ICONVERTICALSPACING\n");
633     /* default value: 75 */
634     rc=SystemParametersInfoA( SPI_ICONVERTICALSPACING, 0, &old_spacing, 0 );
635     ok(rc!=0,"SystemParametersInfoA: rc=%d err=%ld\n",rc,GetLastError());
636
637     /* do not increase the value as it would upset the user's icon layout */
638     curr_val = old_spacing-1;
639     rc=SystemParametersInfoA( SPI_ICONVERTICALSPACING, curr_val, 0,
640                               SPIF_UPDATEINIFILE | SPIF_SENDCHANGE);
641     ok(rc!=0,"SystemParametersInfoA: rc=%d err=%ld\n",rc,GetLastError());
642     test_change_message( SPI_ICONVERTICALSPACING, 0 );
643     /* The registry keys depend on the Windows version and the values too
644      * => don't test them
645      */
646
647     rc=SystemParametersInfoA( SPI_ICONVERTICALSPACING, 0, &spacing, 0 );
648     ok(rc!=0,"SystemParametersInfoA: rc=%d err=%ld\n",rc,GetLastError());
649     eq( spacing, curr_val, "ICONVERTICALSPACING", "%d" );
650     eq( GetSystemMetrics( SM_CYICONSPACING ), curr_val, "SM_CYICONSPACING", "%d" );
651
652     curr_val = 10;
653     rc=SystemParametersInfoA( SPI_ICONVERTICALSPACING, curr_val, 0,
654                               SPIF_UPDATEINIFILE | SPIF_SENDCHANGE);
655     ok(rc!=0,"SystemParametersInfoA: rc=%d err=%ld\n",rc,GetLastError());
656     curr_val = 32;      /*min value*/
657     test_change_message( SPI_ICONVERTICALSPACING, 0 );
658
659     rc=SystemParametersInfoA( SPI_ICONVERTICALSPACING, 0, &spacing, 0 );
660     ok(rc!=0,"SystemParametersInfoA: rc=%d err=%ld\n",rc,GetLastError());
661     eq( spacing, curr_val, "ICONVERTICALSPACING", "%d" );
662     eq( GetSystemMetrics( SM_CYICONSPACING ), curr_val, "SM_CYICONSPACING", "%d" );
663
664     rc=SystemParametersInfoA( SPI_ICONVERTICALSPACING, old_spacing, 0,
665                               SPIF_UPDATEINIFILE );
666     ok(rc!=0,"***warning*** failed to restore the original value: rc=%d err=%ld\n",rc,GetLastError());
667 }
668
669 static void test_SPI_SETICONTITLEWRAP( void )          /*     26 */
670 {
671     BOOL rc;
672     BOOL old_b;
673     const UINT vals[]={TRUE,FALSE};
674     int i;
675
676     /* These tests hang when XFree86 4.0 for Windows is running (tested on
677      * WinNT, SP2, Cygwin/XFree 4.1.0. Skip the test when XFree86 is
678      * running.
679      */
680     if (FindWindowA( NULL, "Cygwin/XFree86" ))
681         return;
682
683     trace("testing SPI_{GET,SET}ICONTITLEWRAP\n");
684     rc=SystemParametersInfoA( SPI_GETICONTITLEWRAP, 0, &old_b, 0 );
685     ok(rc!=0,"SystemParametersInfoA: rc=%d err=%ld\n",rc,GetLastError());
686
687     for (i=0;i<sizeof(vals)/sizeof(*vals);i++)
688     {
689         UINT v;
690
691         rc=SystemParametersInfoA( SPI_SETICONTITLEWRAP, vals[i], 0,
692                                   SPIF_UPDATEINIFILE | SPIF_SENDCHANGE );
693         ok(rc!=0,"%d: rc=%d err=%ld\n",i,rc,GetLastError());
694         test_change_message( SPI_SETICONTITLEWRAP, 1 );
695         test_reg_key_ex( SPI_SETICONTITLEWRAP_REGKEY1,
696                          SPI_SETICONTITLEWRAP_REGKEY2,
697                          SPI_SETICONTITLEWRAP_VALNAME,
698                          vals[i] ? "1" : "0" );
699
700         rc=SystemParametersInfoA( SPI_GETICONTITLEWRAP, 0, &v, 0 );
701         ok(rc!=0,"%d: rc=%d err=%ld\n",i,rc,GetLastError());
702         eq( v, vals[i], "SPI_{GET,SET}ICONTITLEWRAP", "%d" );
703     }
704
705     rc=SystemParametersInfoA( SPI_SETICONTITLEWRAP, old_b, 0, SPIF_UPDATEINIFILE );
706     ok(rc!=0,"***warning*** failed to restore the original value: rc=%d err=%ld\n",rc,GetLastError());
707 }
708
709 static void test_SPI_SETMENUDROPALIGNMENT( void )      /*     28 */
710 {
711     BOOL rc;
712     BOOL old_b;
713     const UINT vals[]={TRUE,FALSE};
714     int i;
715
716     trace("testing SPI_{GET,SET}MENUDROPALIGNMENT\n");
717     rc=SystemParametersInfoA( SPI_GETMENUDROPALIGNMENT, 0, &old_b, 0 );
718     ok(rc!=0,"SystemParametersInfoA: rc=%d err=%ld\n",rc,GetLastError());
719
720     for (i=0;i<sizeof(vals)/sizeof(*vals);i++)
721     {
722         UINT v;
723
724         rc=SystemParametersInfoA( SPI_SETMENUDROPALIGNMENT, vals[i], 0,
725                                   SPIF_UPDATEINIFILE | SPIF_SENDCHANGE );
726         ok(rc!=0,"%d: rc=%d err=%ld\n",i,rc,GetLastError());
727         test_change_message( SPI_SETMENUDROPALIGNMENT, 0 );
728         test_reg_key_ex( SPI_SETMENUDROPALIGNMENT_REGKEY1,
729                          SPI_SETMENUDROPALIGNMENT_REGKEY2,
730                          SPI_SETMENUDROPALIGNMENT_VALNAME,
731                          vals[i] ? "1" : "0" );
732
733         rc=SystemParametersInfoA( SPI_GETMENUDROPALIGNMENT, 0, &v, 0 );
734         ok(rc!=0,"%d: rc=%d err=%ld\n",i,rc,GetLastError());
735         eq( v, vals[i], "SPI_{GET,SET}MENUDROPALIGNMENT", "%d" );
736         eq( GetSystemMetrics( SM_MENUDROPALIGNMENT ), (int)vals[i],
737             "SM_MENUDROPALIGNMENT", "%d" );
738     }
739
740     rc=SystemParametersInfoA( SPI_SETMENUDROPALIGNMENT, old_b, 0,
741                               SPIF_UPDATEINIFILE );
742     ok(rc!=0,"***warning*** failed to restore the original value: rc=%d err=%ld\n",rc,GetLastError());
743 }
744
745 static void test_SPI_SETDOUBLECLKWIDTH( void )         /*     29 */
746 {
747     BOOL rc;
748     INT old_width;
749     const UINT vals[]={0,10000};
750     int i;
751
752     trace("testing SPI_{GET,SET}DOUBLECLKWIDTH\n");
753     old_width = GetSystemMetrics( SM_CXDOUBLECLK );
754
755     for (i=0;i<sizeof(vals)/sizeof(*vals);i++)
756     {
757         char buf[10];
758
759         rc=SystemParametersInfoA( SPI_SETDOUBLECLKWIDTH, vals[i], 0,
760                                   SPIF_UPDATEINIFILE | SPIF_SENDCHANGE );
761         ok(rc!=0,"%d: rc=%d err=%ld\n",i,rc,GetLastError());
762         test_change_message( SPI_SETDOUBLECLKWIDTH, 0 );
763         sprintf( buf, "%d", vals[i] );
764         test_reg_key_ex( SPI_SETDOUBLECLKWIDTH_REGKEY1,
765                          SPI_SETDOUBLECLKWIDTH_REGKEY2,
766                          SPI_SETDOUBLECLKWIDTH_VALNAME, buf );
767         eq( GetSystemMetrics( SM_CXDOUBLECLK ), (int)vals[i],
768             "SM_CXDOUBLECLK", "%d" );
769     }
770
771     rc=SystemParametersInfoA( SPI_SETDOUBLECLKWIDTH, old_width, 0,
772                               SPIF_UPDATEINIFILE );
773     ok(rc!=0,"***warning*** failed to restore the original value: rc=%d err=%ld\n",rc,GetLastError());
774 }
775
776 static void test_SPI_SETDOUBLECLKHEIGHT( void )        /*     30 */
777 {
778     BOOL rc;
779     INT old_height;
780     const UINT vals[]={0,10000};
781     int i;
782
783     trace("testing SPI_{GET,SET}DOUBLECLKHEIGHT\n");
784     old_height = GetSystemMetrics( SM_CYDOUBLECLK );
785
786     for (i=0;i<sizeof(vals)/sizeof(*vals);i++)
787     {
788         char buf[10];
789
790         rc=SystemParametersInfoA( SPI_SETDOUBLECLKHEIGHT, vals[i], 0,
791                                   SPIF_UPDATEINIFILE | SPIF_SENDCHANGE );
792         ok(rc!=0,"%d: rc=%d err=%ld\n",i,rc,GetLastError());
793         test_change_message( SPI_SETDOUBLECLKHEIGHT, 0 );
794         sprintf( buf, "%d", vals[i] );
795         test_reg_key_ex( SPI_SETDOUBLECLKHEIGHT_REGKEY1,
796                          SPI_SETDOUBLECLKHEIGHT_REGKEY2,
797                          SPI_SETDOUBLECLKHEIGHT_VALNAME, buf );
798         eq( GetSystemMetrics( SM_CYDOUBLECLK ), (int)vals[i],
799             "SM_CYDOUBLECLK", "%d" );
800     }
801
802     rc=SystemParametersInfoA( SPI_SETDOUBLECLKHEIGHT, old_height, 0,
803                               SPIF_UPDATEINIFILE );
804     ok(rc!=0,"***warning*** failed to restore the original value: rc=%d err=%ld\n",rc,GetLastError());
805 }
806
807 static void test_SPI_SETDOUBLECLICKTIME( void )        /*     32 */
808 {
809     BOOL rc;
810     UINT curr_val;
811     UINT saved_val;
812     UINT old_time;
813     char buf[10];
814
815     trace("testing SPI_{GET,SET}DOUBLECLICKTIME\n");
816     old_time = GetDoubleClickTime();
817
818     curr_val = 0;
819     rc=SystemParametersInfoA( SPI_SETDOUBLECLICKTIME, curr_val, 0,
820                               SPIF_UPDATEINIFILE | SPIF_SENDCHANGE );
821     ok(rc!=0,"SystemParametersInfoA: rc=%d err=%ld\n",rc,GetLastError());
822     test_change_message( SPI_SETDOUBLECLICKTIME, 0 );
823     sprintf( buf, "%d", curr_val );
824     test_reg_key( SPI_SETDOUBLECLICKTIME_REGKEY,
825                   SPI_SETDOUBLECLICKTIME_VALNAME, buf );
826     curr_val = 500; /* used value for 0 */
827     eq( GetDoubleClickTime(), curr_val, "GetDoubleClickTime", "%d" );
828
829     curr_val = 1000;
830     rc=SystemParametersInfoA( SPI_SETDOUBLECLICKTIME, curr_val, 0,
831                              SPIF_UPDATEINIFILE | SPIF_SENDCHANGE );
832     ok(rc!=0,"SystemParametersInfoA: rc=%d err=%ld\n",rc,GetLastError());
833     test_change_message( SPI_SETDOUBLECLICKTIME, 0 );
834     sprintf( buf, "%d", curr_val );
835     test_reg_key( SPI_SETDOUBLECLICKTIME_REGKEY,
836                   SPI_SETDOUBLECLICKTIME_VALNAME, buf );
837     eq( GetDoubleClickTime(), curr_val, "GetDoubleClickTime", "%d" );
838
839     saved_val = curr_val;
840
841     curr_val = 0;
842     SetDoubleClickTime( curr_val );
843     sprintf( buf, "%d", saved_val );
844     test_reg_key( SPI_SETDOUBLECLICKTIME_REGKEY,
845                   SPI_SETDOUBLECLICKTIME_VALNAME, buf );
846     curr_val = 500; /* used value for 0 */
847     eq( GetDoubleClickTime(), curr_val, "GetDoubleClickTime", "%d" );
848
849     curr_val = 1000;
850     SetDoubleClickTime( curr_val );
851     sprintf( buf, "%d", saved_val );
852     test_reg_key( SPI_SETDOUBLECLICKTIME_REGKEY,
853                   SPI_SETDOUBLECLICKTIME_VALNAME, buf );
854     eq( GetDoubleClickTime(), curr_val, "GetDoubleClickTime", "%d" );
855
856     rc=SystemParametersInfoA(SPI_SETDOUBLECLICKTIME, old_time, 0, SPIF_UPDATEINIFILE);
857     ok(rc!=0,"***warning*** failed to restore the original value: rc=%d err=%ld\n",rc,GetLastError());
858 }
859
860 static void test_SPI_SETMOUSEBUTTONSWAP( void )        /*     33 */
861 {
862     BOOL rc;
863     BOOL old_b;
864     const UINT vals[]={TRUE,FALSE};
865     int i;
866
867     trace("testing SPI_{GET,SET}MOUSEBUTTONSWAP\n");
868     old_b = GetSystemMetrics( SM_SWAPBUTTON );
869
870     for (i=0;i<sizeof(vals)/sizeof(*vals);i++)
871     {
872         rc=SystemParametersInfoA( SPI_SETMOUSEBUTTONSWAP, vals[i], 0,
873                                   SPIF_UPDATEINIFILE | SPIF_SENDCHANGE );
874         ok(rc!=0,"%d: rc=%d err=%ld\n",i,rc,GetLastError());
875         test_change_message( SPI_SETMOUSEBUTTONSWAP, 0 );
876         test_reg_key( SPI_SETMOUSEBUTTONSWAP_REGKEY,
877                       SPI_SETMOUSEBUTTONSWAP_VALNAME,
878                       vals[i] ? "1" : "0" );
879         eq( GetSystemMetrics( SM_SWAPBUTTON ), (int)vals[i],
880             "SM_SWAPBUTTON", "%d" );
881     }
882
883     rc=SystemParametersInfoA( SPI_SETMOUSEBUTTONSWAP, old_b, 0,
884                               SPIF_UPDATEINIFILE );
885     ok(rc!=0,"***warning*** failed to restore the original value: rc=%d err=%ld\n",rc,GetLastError());
886 }
887
888 static void test_SPI_SETFASTTASKSWITCH( void )         /*     36 */
889 {
890     BOOL rc;
891     BOOL v;
892
893     trace("testing SPI_GETFASTTASKSWITCH\n");
894     rc=SystemParametersInfoA( SPI_GETFASTTASKSWITCH, 0, &v, 0 );
895     ok(rc!=0,"SystemParametersInfoA: rc=%d err=%ld\n",rc,GetLastError());
896     /* there is not a single Windows platform on which SPI_GETFASTTASKSWITCH
897      * works. That sure simplifies testing!
898      */
899 }
900
901 static void test_SPI_SETDRAGFULLWINDOWS( void )        /*     37 */
902 {
903     BOOL rc;
904     BOOL old_b;
905     const UINT vals[]={TRUE,FALSE};
906     int i;
907
908     trace("testing SPI_{GET,SET}DRAGFULLWINDOWS\n");
909     rc=SystemParametersInfoA( SPI_GETDRAGFULLWINDOWS, 0, &old_b, 0 );
910     if (rc==0 && (GetLastError()==0 || GetLastError()==ERROR_CALL_NOT_IMPLEMENTED))
911     {
912         /* SPI_{GET,SET}DRAGFULLWINDOWS is not implemented on Win95 */
913         trace("SPI_{GET,SET}DRAGFULLWINDOWS not supported on this platform\n");
914         return;
915     }
916     ok(rc!=0,"SystemParametersInfoA: rc=%d err=%ld\n",rc,GetLastError());
917
918     for (i=0;i<sizeof(vals)/sizeof(*vals);i++)
919     {
920         UINT v;
921
922         rc=SystemParametersInfoA( SPI_SETDRAGFULLWINDOWS, vals[i], 0,
923                                   SPIF_UPDATEINIFILE | SPIF_SENDCHANGE );
924         ok(rc!=0,"%d: rc=%d err=%ld\n",i,rc,GetLastError());
925         test_change_message( SPI_SETDRAGFULLWINDOWS, 0 );
926         test_reg_key( SPI_SETDRAGFULLWINDOWS_REGKEY,
927                       SPI_SETDRAGFULLWINDOWS_VALNAME,
928                       vals[i] ? "1" : "0" );
929
930         rc=SystemParametersInfoA( SPI_GETDRAGFULLWINDOWS, 0, &v, 0 );
931         ok(rc!=0,"%d: rc=%d err=%ld\n",i,rc,GetLastError());
932         eq( v, vals[i], "SPI_{GET,SET}DRAGFULLWINDOWS", "%d" );
933     }
934
935     rc=SystemParametersInfoA( SPI_SETDRAGFULLWINDOWS, old_b, 0, SPIF_UPDATEINIFILE );
936     ok(rc!=0,"***warning*** failed to restore the original value: rc=%d err=%ld\n",rc,GetLastError());
937 }
938
939 static void test_SPI_SETWORKAREA( void )               /*     47 */
940 {
941     BOOL rc;
942     RECT old_area;
943     RECT area;
944     RECT curr_val;
945
946     trace("testing SPI_{GET,SET}WORKAREA\n");
947     rc=SystemParametersInfoA(SPI_GETWORKAREA, 0, &old_area, 0);
948     ok(rc!=0,"SystemParametersInfoA: rc=%d err=%ld\n",rc,GetLastError());
949
950     /* Modify the work area only minimally as this causes the icons that
951      * fall outside it to be moved around thus requiring the user to
952      * reposition them manually one by one.
953      * Changing the work area by just one pixel should make this occurence
954      * reasonably unlikely.
955      */
956     curr_val.left = old_area.left;
957     curr_val.top = old_area.top;
958     curr_val.right = old_area.right-1;
959     curr_val.bottom = old_area.bottom-1;
960     rc=SystemParametersInfoA( SPI_SETWORKAREA, 0, &curr_val,
961                               SPIF_UPDATEINIFILE | SPIF_SENDCHANGE );
962     ok(rc!=0,"SystemParametersInfoA: rc=%d err=%ld\n",rc,GetLastError());
963     test_change_message( SPI_SETWORKAREA, 0 );
964     rc=SystemParametersInfoA( SPI_GETWORKAREA, 0, &area, 0 );
965     ok(rc!=0,"SystemParametersInfoA: rc=%d err=%ld\n",rc,GetLastError());
966     eq( area.left,   curr_val.left,   "left",   "%ld" );
967     eq( area.top,    curr_val.top,    "top",    "%ld" );
968     eq( area.right,  curr_val.right,  "right",  "%ld" );
969     eq( area.bottom, curr_val.bottom, "bottom", "%ld" );
970
971     rc=SystemParametersInfoA( SPI_SETWORKAREA, 0, &old_area,
972                               SPIF_UPDATEINIFILE | SPIF_SENDCHANGE );
973     ok(rc!=0,"***warning*** failed to restore the original value: rc=%d err=%ld\n",rc,GetLastError());
974     test_change_message( SPI_SETWORKAREA, 0 );
975     rc=SystemParametersInfoA( SPI_GETWORKAREA, 0, &area, 0 );
976     ok(rc!=0,"SystemParametersInfoA: rc=%d err=%ld\n",rc,GetLastError());
977     eq( area.left,   old_area.left,   "left",   "%ld" );
978     eq( area.top,    old_area.top,    "top",    "%ld" );
979     eq( area.right,  old_area.right,  "right",  "%ld" );
980     eq( area.bottom, old_area.bottom, "bottom", "%ld" );
981 }
982
983 static void test_SPI_SETSHOWSOUNDS( void )             /*     57 */
984 {
985     BOOL rc;
986     BOOL old_b;
987     const UINT vals[]={TRUE,FALSE};
988     int i;
989
990     trace("testing SPI_{GET,SET}SHOWSOUNDS\n");
991     SetLastError(0);
992     rc=SystemParametersInfoA( SPI_GETSHOWSOUNDS, 0, &old_b, 0 );
993     if (rc==0 && GetLastError()==0)
994     {
995         /* SPI_{GET,SET}SHOWSOUNDS is completely broken on Win9x */
996         trace("SPI_{GET,SET}SHOWSOUNDS not supported on this platform\n");
997         return;
998     }
999     ok(rc!=0,"SystemParametersInfoA: rc=%d err=%ld\n",rc,GetLastError());
1000
1001     for (i=0;i<sizeof(vals)/sizeof(*vals);i++)
1002     {
1003         UINT v;
1004
1005         rc=SystemParametersInfoA( SPI_SETSHOWSOUNDS, vals[i], 0,
1006                                   SPIF_UPDATEINIFILE | SPIF_SENDCHANGE );
1007         ok(rc!=0,"%d: rc=%d err=%ld\n",i,rc,GetLastError());
1008         test_change_message( SPI_SETSHOWSOUNDS, 0 );
1009         test_reg_key( SPI_SETSHOWSOUNDS_REGKEY,
1010                       SPI_SETSHOWSOUNDS_VALNAME,
1011                       vals[i] ? "1" : "0" );
1012
1013         rc=SystemParametersInfoA( SPI_GETSHOWSOUNDS, 0, &v, 0 );
1014         ok(rc!=0,"%d: rc=%d err=%ld\n",i,rc,GetLastError());
1015         eq( v, vals[i], "SPI_GETSHOWSOUNDS", "%d" );
1016         eq( GetSystemMetrics( SM_SHOWSOUNDS ), (int)vals[i],
1017             "SM_SHOWSOUNDS", "%d" );
1018     }
1019
1020     rc=SystemParametersInfoA( SPI_SETSHOWSOUNDS, old_b, 0, SPIF_UPDATEINIFILE );
1021     ok(rc!=0,"***warning*** failed to restore the original value: rc=%d err=%ld\n",rc,GetLastError());
1022 }
1023
1024 static void test_SPI_SETKEYBOARDPREF( void )           /*     69 */
1025 {
1026     /* TODO!!! - don't have version of Windows which has this */
1027 }
1028
1029 static void test_SPI_SETSCREENREADER( void )           /*     71 */
1030 {
1031     /* TODO!!! - don't have version of Windows which has this */
1032 }
1033
1034 static void test_SPI_SETWALLPAPER( void )              /*   115 */
1035 {
1036     BOOL rc;
1037     char oldval[260];
1038     char newval[260];
1039
1040     trace("testing SPI_{GET,SET}DESKWALLPAPER\n");
1041     SetLastError(0);
1042     rc=SystemParametersInfoA(SPI_GETDESKWALLPAPER, 260, oldval, 0);
1043     if (rc==0 && (GetLastError()==0 || GetLastError()==ERROR_INVALID_SPI_VALUE))
1044     {
1045         /* SPI_{GET,SET}DESKWALLPAPER is completely broken on Win9x and
1046          * unimplemented on NT4
1047          */
1048         trace("SPI_{GET,SET}DESKWALLPAPER not supported on this platform\n");
1049         return;
1050     }
1051     ok(rc!=0,"SystemParametersInfoA: rc=%d err=%ld\n",rc,GetLastError());
1052     test_reg_key(SPI_SETDESKWALLPAPER_REGKEY, SPI_SETDESKWALLPAPER_VALNAME, oldval);
1053
1054     strcpy(newval, "");
1055     rc=SystemParametersInfoA(SPI_SETDESKWALLPAPER, 0, newval, SPIF_UPDATEINIFILE | SPIF_SENDCHANGE);
1056     ok(rc!=0,"SystemParametersInfoA: rc=%d err=%ld\n",rc,GetLastError());
1057     test_change_message(SPI_SETDESKWALLPAPER, 0);
1058
1059     rc=SystemParametersInfoA(SPI_SETDESKWALLPAPER, 0, oldval, SPIF_UPDATEINIFILE);
1060     ok(rc!=0,"***warning*** failed to restore the original value: rc=%d err=%ld\n",rc,GetLastError());
1061 }
1062
1063 /*
1064  * Registry entries for the system parameters.
1065  * Names are created by 'SET' flags names.
1066  * We assume that corresponding 'GET' entries use the same registry keys.
1067  */
1068 static DWORD WINAPI SysParamsThreadFunc( LPVOID lpParam )
1069 {
1070     test_SPI_SETBEEP();                         /*      1 */
1071     test_SPI_SETMOUSE();                        /*      4 */
1072     /* Messes up systems settings on Win9x */
1073     /*test_SPI_SETBORDER();*/                   /*      6 */
1074     test_SPI_SETKEYBOARDSPEED();                /*     10 */
1075     test_SPI_ICONHORIZONTALSPACING();           /*     13 */
1076     test_SPI_SETSCREENSAVETIMEOUT();            /*     14 */
1077     test_SPI_SETSCREENSAVEACTIVE();             /*     17 */
1078     test_SPI_SETGRIDGRANULARITY();              /*     19 */
1079     test_SPI_SETKEYBOARDDELAY();                /*     23 */
1080     test_SPI_ICONVERTICALSPACING();             /*     24 */
1081     test_SPI_SETICONTITLEWRAP();                /*     26 */
1082     test_SPI_SETMENUDROPALIGNMENT();            /*     28 */
1083     test_SPI_SETDOUBLECLKWIDTH();               /*     29 */
1084     test_SPI_SETDOUBLECLKHEIGHT();              /*     30 */
1085     test_SPI_SETDOUBLECLICKTIME();              /*     32 */
1086     test_SPI_SETMOUSEBUTTONSWAP();              /*     33 */
1087     test_SPI_SETFASTTASKSWITCH();               /*     36 */
1088     test_SPI_SETDRAGFULLWINDOWS();              /*     37 */
1089     test_SPI_SETWORKAREA();                     /*     47 */
1090     test_SPI_SETSHOWSOUNDS();                   /*     57 */
1091     test_SPI_SETKEYBOARDPREF();                 /*     69 */
1092     test_SPI_SETSCREENREADER();                 /*     71 */
1093     test_SPI_SETWALLPAPER();                    /*    115 */
1094     SendMessageA( ghTestWnd, WM_DESTROY, 0, 0 );
1095     return 0;
1096 }
1097
1098 START_TEST(sysparams)
1099 {
1100     int argc;
1101     char** argv;
1102     WNDCLASSA wc;
1103     MSG msg;
1104     HANDLE hThread;
1105     DWORD dwThreadId;
1106     HANDLE hInstance = GetModuleHandleA( NULL );
1107
1108     argc = winetest_get_mainargs(&argv);
1109     strict=(argc >= 3 && strcmp(argv[2],"strict")==0);
1110     trace("strict=%d\n",strict);
1111
1112     change_counter = 0;
1113     change_last_param = 0;
1114
1115     wc.lpszClassName = "SysParamsTestClass";
1116     wc.lpfnWndProc = SysParamsTestWndProc;
1117     wc.style = CS_OWNDC | CS_VREDRAW | CS_HREDRAW;
1118     wc.hInstance = hInstance;
1119     wc.hIcon = LoadIconA( 0, IDI_APPLICATIONA );
1120     wc.hCursor = LoadCursorA( 0, IDC_ARROWA );
1121     wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1 );
1122     wc.lpszMenuName = 0;
1123     wc.cbClsExtra = 0;
1124     wc.cbWndExtra = 0;
1125     RegisterClassA( &wc );
1126
1127     ghTestWnd = CreateWindowA( "SysParamsTestClass", "Test System Parameters Application",
1128                                WS_OVERLAPPEDWINDOW, 0, 0, 100, 100, 0, 0, hInstance, NULL );
1129
1130     hThread = CreateThread( NULL, 0, SysParamsThreadFunc, 0, 0, &dwThreadId );
1131     assert( hThread );
1132     CloseHandle( hThread );
1133
1134     while( GetMessageA( &msg, 0, 0, 0 )) {
1135         TranslateMessage( &msg );
1136         DispatchMessageA( &msg );
1137     }
1138 }