[NTFS]
[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 <apitest.h>
9
10 #include <wingdi.h>
11 #include <winuser.h>
12
13 #define TEST(x) ok(x, #x"\n")
14
15 #define NUM_SYSCOLORS 31
16
17 void Test_SetSysColors()
18 {
19 INT i;
20 INT nElements[NUM_SYSCOLORS+1];
21 COLORREF crOldColors[NUM_SYSCOLORS];
22 COLORREF crColors[NUM_SYSCOLORS+1];
23
24 /* First save the Old colors */
25 for (i = 0; i < NUM_SYSCOLORS; i++)
26 {
27 nElements[i] = i;
28 crOldColors[i] = GetSysColor(i);
29 }
30
31 for (i = 0; i < NUM_SYSCOLORS+1; i++)
32 crColors[i] = RGB(i, 255-i, i*3);
33 nElements[NUM_SYSCOLORS] = nElements[0];
34
35 SetLastError(0xdeadbeef);
36 ok(SetSysColors(-1, nElements, crColors) == FALSE, "Expected FALSE, got TRUE\n");
37 ok(GetLastError() == ERROR_NOACCESS, "Expected ERROR_NOACCESS, got %ld\n", GetLastError());
38 ok(SetSysColors(0, nElements, crColors) == TRUE, "Expected TRUE, got FALSE\n");
39 ok(SetSysColors(0, NULL, crColors) == TRUE, "Expected TRUE, got FALSE\n");
40 ok(SetSysColors(0, nElements, NULL) == TRUE, "Expected TRUE, got FALSE\n");
41 ok(SetSysColors(1, NULL, crColors) == FALSE, "Expected FALSE, got TRUE\n");
42 ok(GetLastError() == ERROR_NOACCESS, "Expected ERROR_NOACCESS, got %ld\n", GetLastError());
43 ok(SetSysColors(1, nElements, NULL) == FALSE, "Expected FALSE, got TRUE\n");
44 ok(GetLastError() == ERROR_NOACCESS, "Expected ERROR_NOACCESS, got %ld\n", GetLastError());
45 ok(SetSysColors(1, nElements, crColors) == TRUE, "Expected TRUE, got FALSE\n");
46 ok(SetSysColors(NUM_SYSCOLORS, nElements, crColors) == TRUE, "Expected TRUE, got FALSE\n");
47 for (i = 0; i < NUM_SYSCOLORS; i++)
48 ok(GetSysColor(nElements[i]) == crColors[i], "Expected %06lx, got %06lx\n", crColors[i], GetSysColor(nElements[i]));
49
50 /* try more than NUM_SYSCOLORS */
51 ok(SetSysColors(NUM_SYSCOLORS+1, nElements, crColors) == TRUE, "Expected TRUE, got FALSE\n");
52 nElements[NUM_SYSCOLORS] = 10000;
53 ok(SetSysColors(NUM_SYSCOLORS+1, nElements, crColors) == TRUE, "Expected TRUE, got FALSE\n");
54
55 /* restore old SysColors */
56 SetSysColors(NUM_SYSCOLORS, nElements, crOldColors);
57 }
58
59 START_TEST(SetSysColors)
60 {
61 Test_SetSysColors();
62 }
63