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     /* iModeNum out of range */
80     Status = NtUserEnumDisplaySettings(NULL, 5000, (DEVMODEW*)&data, 0);
81     TEST(Status == STATUS_INVALID_PARAMETER_2);
82 
83     /* Secret values? */
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 
89     /* What's going on here? */
90     Status = NtUserEnumDisplaySettings(NULL, -3, (DEVMODEW*)&data, 0);
91     ok_ntstatus(Status, STATUS_INVALID_PARAMETER_3);
92     Status = NtUserEnumDisplaySettings(NULL, -4, (DEVMODEW*)&data, 0);
93     ok_ntstatus(Status, STATUS_INVALID_PARAMETER_2);
94 
95     Status = NtUserEnumDisplaySettings(&usDeviceName, ENUM_CURRENT_SETTINGS, (DEVMODEW*)&data, 0);
96     TEST(Status == STATUS_INVALID_PARAMETER_1);
97 
98     usDeviceName.Buffer = szName;
99     usDeviceName.Length = (USHORT)wcslen(szName);
100     usDeviceName.MaximumLength = usDeviceName.Length;
101     Status = NtUserEnumDisplaySettings(&usDeviceName, ENUM_CURRENT_SETTINGS, (DEVMODEW*)&data, 0);
102     TEST(Status == STATUS_INVALID_PARAMETER_1);
103 
104     Status = NtUserEnumDisplaySettings(&usDeviceName, 1000, (DEVMODEW*)&data, 123456);
105     TEST(Status == STATUS_INVALID_PARAMETER_1);
106 
107     TEST(GetLastError() == ERROR_SUCCESS);
108 
109 }
110