[GDI32_APITEST]
[reactos.git] / rostests / apitests / gdi32 / SetSysColors.c
1 /*
2 * PROJECT: ReactOS api tests
3 * LICENSE: GPL - See COPYING in the top level directory
4 * PURPOSE: Test for SetSysColors
5 * PROGRAMMERS: Timo Kreuzer
6 */
7
8 #include <stdio.h>
9 #include <wine/test.h>
10 #include <windows.h>
11
12 #define TEST(x) ok(x, #x"\n")
13
14 #define NUM_SYSCOLORS 31
15
16 void Test_SetSysColors()
17 {
18 INT i;
19 INT nElements[NUM_SYSCOLORS+1];
20 COLORREF crOldColors[NUM_SYSCOLORS];
21 COLORREF crColors[NUM_SYSCOLORS+1];
22
23 /* First save the Old colors */
24 for (i = 0; i < NUM_SYSCOLORS; i++)
25 {
26 nElements[i] = i;
27 crOldColors[i] = GetSysColor(i);
28 }
29
30 for (i = 0; i < NUM_SYSCOLORS+1; i++)
31 crColors[i] = RGB(i, 255-i, i*3);
32 nElements[NUM_SYSCOLORS] = nElements[0];
33
34 SetLastError(0xdeadbeef);
35 ok(SetSysColors(-1, nElements, crColors) == FALSE, "Expected FALSE, got TRUE\n");
36 ok(GetLastError() == ERROR_NOACCESS, "Expected ERROR_NOACCESS, got %ld\n", GetLastError());
37 ok(SetSysColors(0, nElements, crColors) == TRUE, "Expected TRUE, got FALSE\n");
38 ok(SetSysColors(0, NULL, crColors) == TRUE, "Expected TRUE, got FALSE\n");
39 ok(SetSysColors(0, nElements, NULL) == TRUE, "Expected TRUE, got FALSE\n");
40 ok(SetSysColors(1, NULL, crColors) == FALSE, "Expected FALSE, got TRUE\n");
41 ok(GetLastError() == ERROR_NOACCESS, "Expected ERROR_NOACCESS, got %ld\n", GetLastError());
42 ok(SetSysColors(1, nElements, NULL) == FALSE, "Expected FALSE, got TRUE\n");
43 ok(GetLastError() == ERROR_NOACCESS, "Expected ERROR_NOACCESS, got %ld\n", GetLastError());
44 ok(SetSysColors(1, nElements, crColors) == TRUE, "Expected TRUE, got FALSE\n");
45 ok(SetSysColors(NUM_SYSCOLORS, nElements, crColors) == TRUE, "Expected TRUE, got FALSE\n");
46 for (i = 0; i < NUM_SYSCOLORS; i++)
47 ok(GetSysColor(nElements[i]) == crColors[i], "Expected %06lx, got %06lx\n", crColors[i], GetSysColor(nElements[i]));
48
49 /* try more than NUM_SYSCOLORS */
50 ok(SetSysColors(NUM_SYSCOLORS+1, nElements, crColors) == TRUE, "Expected TRUE, got FALSE\n");
51 nElements[NUM_SYSCOLORS] = 10000;
52 ok(SetSysColors(NUM_SYSCOLORS+1, nElements, crColors) == TRUE, "Expected TRUE, got FALSE\n");
53
54 /* restore old SysColors */
55 SetSysColors(NUM_SYSCOLORS, nElements, crOldColors);
56 }
57
58 START_TEST(SetSysColors)
59 {
60 Test_SetSysColors();
61 }
62