1 /*
2  * PROJECT:         ReactOS api tests
3  * LICENSE:         GPL - See COPYING in the top level directory
4  * PURPOSE:         Test for NtUserEnumDisplaySettings
5  * PROGRAMMERS:
6  */
7 
8 #include <win32nt.h>
9 
10 
11 
12 static struct
13 {
14     DEVMODEW devmode;
15     CHAR buffer[0xffff];
16 } data;
17 
18 START_TEST(NtUserEnumDisplaySettings)
19 {
20     UNICODE_STRING usDeviceName;
21     WCHAR szName[] = L"DISPLAY";
22     NTSTATUS Status;
23     INT i;
24 
25     SetLastError(ERROR_SUCCESS);
26     Status = NtUserEnumDisplaySettings(NULL, 0, 0, 0);
27     TEST(Status == STATUS_ACCESS_VIOLATION);
28     TEST(GetLastError() == ERROR_SUCCESS);
29 
30     data.devmode.dmDriverExtra = 0;
31     for (i = 0; i < 2 * sizeof(DEVMODEW); i++)
32     {
33         data.devmode.dmSize = i;
34         Status = NtUserEnumDisplaySettings(NULL, 1000, (DEVMODEW*)&data, 0);
35         if (i != sizeof(DEVMODEW))
36         {
37             TEST(Status == STATUS_BUFFER_TOO_SMALL);
38         }
39     }
40     TEST(GetLastError() == ERROR_SUCCESS);
41 
42     usDeviceName.Buffer = NULL;
43     usDeviceName.Length = 0;
44     usDeviceName.MaximumLength = 0;
45     Status = NtUserEnumDisplaySettings(&usDeviceName, ENUM_CURRENT_SETTINGS, (DEVMODEW*)&data, 0);
46     TEST(Status == STATUS_BUFFER_TOO_SMALL);
47     Status = NtUserEnumDisplaySettings(&usDeviceName, -4, (DEVMODEW*)&data, 0);
48     TEST(Status == STATUS_BUFFER_TOO_SMALL);
49 
50     data.devmode.dmSize = sizeof(DEVMODEW);
51     data.devmode.dmDriverExtra = 0xffff;
52     Status = NtUserEnumDisplaySettings(NULL, ENUM_CURRENT_SETTINGS, (DEVMODEW*)&data, 0);
53     TEST(Status == STATUS_SUCCESS);
54 
55     data.devmode.dmSize = sizeof(DEVMODEW);
56     data.devmode.dmDriverExtra = 0;
57     Status = NtUserEnumDisplaySettings(NULL, ENUM_CURRENT_SETTINGS, (DEVMODEW*)&data, 0);
58     TEST(Status == STATUS_SUCCESS);
59 
60     usDeviceName.Buffer = NULL;
61     usDeviceName.Length = 0;
62     usDeviceName.MaximumLength = 0;
63     Status = NtUserEnumDisplaySettings(&usDeviceName, ENUM_CURRENT_SETTINGS, (DEVMODEW*)&data, 0);
64     TEST(Status == STATUS_INVALID_PARAMETER_1);
65     Status = NtUserEnumDisplaySettings(&usDeviceName, -4, (DEVMODEW*)&data, 0);
66     TEST(Status == STATUS_INVALID_PARAMETER_1);
67 
68     Status = NtUserEnumDisplaySettings(NULL, 0, (DEVMODEW*)&data, 0);
69     TEST(Status == STATUS_SUCCESS);
70     Status = NtUserEnumDisplaySettings(NULL, 1, (DEVMODEW*)&data, 0);
71     TEST(Status == STATUS_SUCCESS);
72     Status = NtUserEnumDisplaySettings(NULL, 2, (DEVMODEW*)&data, 0);
73     TEST(Status == STATUS_SUCCESS);
74     Status = NtUserEnumDisplaySettings(NULL, 4, (DEVMODEW*)&data, 0);
75     TEST(Status == STATUS_SUCCESS);
76     Status = NtUserEnumDisplaySettings(NULL, 8, (DEVMODEW*)&data, 0);
77     TEST(Status == STATUS_SUCCESS);
78 
79     Status = NtUserEnumDisplaySettings(NULL, 247, (DEVMODEW*)&data, 0);
80     TEST(Status == STATUS_SUCCESS);
81     Status = NtUserEnumDisplaySettings(NULL, 248, (DEVMODEW*)&data, 0);
82     TEST(Status == STATUS_INVALID_PARAMETER_2);
83 
84     Status = NtUserEnumDisplaySettings(NULL, -1, (DEVMODEW*)&data, 0);
85     TEST(Status == STATUS_SUCCESS);
86     Status = NtUserEnumDisplaySettings(NULL, -2, (DEVMODEW*)&data, 0);
87     TEST(Status == STATUS_SUCCESS);
88     Status = NtUserEnumDisplaySettings(NULL, -3, (DEVMODEW*)&data, 0);
89     TEST(Status == STATUS_SUCCESS);
90     Status = NtUserEnumDisplaySettings(NULL, -4, (DEVMODEW*)&data, 0);
91     TEST(Status == STATUS_INVALID_PARAMETER_2);
92 
93     Status = NtUserEnumDisplaySettings(&usDeviceName, ENUM_CURRENT_SETTINGS, (DEVMODEW*)&data, 0);
94     TEST(Status == STATUS_INVALID_PARAMETER_1);
95 
96     usDeviceName.Buffer = szName;
97     usDeviceName.Length = (USHORT)wcslen(szName);
98     usDeviceName.MaximumLength = usDeviceName.Length;
99     Status = NtUserEnumDisplaySettings(&usDeviceName, ENUM_CURRENT_SETTINGS, (DEVMODEW*)&data, 0);
100     TEST(Status == STATUS_INVALID_PARAMETER_1);
101 
102     Status = NtUserEnumDisplaySettings(&usDeviceName, 1000, (DEVMODEW*)&data, 123456);
103     TEST(Status == STATUS_INVALID_PARAMETER_1);
104 
105     TEST(GetLastError() == ERROR_SUCCESS);
106 
107 }
108