[MOUNTMGR_APITEST] Dump returned mount points
[reactos.git] / modules / rostests / apitests / mountmgr / QueryPoints.c
1 /*
2 * PROJECT: ReactOS api tests
3 * LICENSE: GPLv2+ - See COPYING in the top level directory
4 * PURPOSE: Test for QueryPoints IOCTL
5 * PROGRAMMER: Pierre Schweitzer
6 */
7
8 #include "precomp.h"
9
10 VOID
11 TraceMountPoint(PMOUNTMGR_MOUNT_POINTS MountPoints,
12 PMOUNTMGR_MOUNT_POINT MountPoint)
13 {
14 trace("MountPoint: %p\n", MountPoint);
15 trace("\tSymbolicLinkName: %.*S\n", MountPoint->SymbolicLinkNameLength / sizeof(WCHAR), (PWSTR)((ULONG_PTR)MountPoints + MountPoint->SymbolicLinkNameOffset));
16 trace("\tDeviceName: %.*S\n", MountPoint->DeviceNameLength / sizeof(WCHAR), (PWSTR)((ULONG_PTR)MountPoints + MountPoint->DeviceNameOffset));
17 }
18
19 START_TEST(QueryPoints)
20 {
21 BOOL Ret;
22 HANDLE MountMgrHandle;
23 DWORD BytesReturned, Drives, i;
24 struct {
25 MOUNTMGR_MOUNT_POINT;
26 WCHAR Buffer[sizeof(L"\\DosDevice\\A:")];
27 } SinglePoint;
28 MOUNTMGR_MOUNT_POINTS MountPoints;
29 PMOUNTMGR_MOUNT_POINTS AllocatedPoints;
30
31 MountMgrHandle = CreateFileW(MOUNTMGR_DOS_DEVICE_NAME, 0,
32 FILE_SHARE_READ | FILE_SHARE_WRITE, NULL,
33 OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL,
34 INVALID_HANDLE_VALUE);
35 if (MountMgrHandle == INVALID_HANDLE_VALUE)
36 {
37 win_skip("MountMgr unavailable: %lx\n", GetLastError());
38 return;
39 }
40
41 ZeroMemory(&SinglePoint, sizeof(SinglePoint));
42
43 Ret = DeviceIoControl(MountMgrHandle, IOCTL_MOUNTMGR_QUERY_POINTS,
44 &SinglePoint, sizeof(MOUNTMGR_MOUNT_POINT),
45 &MountPoints, sizeof(MOUNTMGR_MOUNT_POINTS),
46 &BytesReturned, NULL);
47 ok(Ret == FALSE, "IOCTL unexpectedly succeed\n");
48 ok(GetLastError() == ERROR_MORE_DATA, "Unexcepted failure: %lx\n", GetLastError());
49
50 AllocatedPoints = RtlAllocateHeap(RtlGetProcessHeap(), 0, MountPoints.Size);
51 if (AllocatedPoints == NULL)
52 {
53 win_skip("Insufficiant memory\n");
54 }
55 else
56 {
57 AllocatedPoints->NumberOfMountPoints = 0;
58
59 Ret = DeviceIoControl(MountMgrHandle, IOCTL_MOUNTMGR_QUERY_POINTS,
60 &SinglePoint, sizeof(MOUNTMGR_MOUNT_POINT),
61 AllocatedPoints, MountPoints.Size,
62 &BytesReturned, NULL);
63 ok(Ret == TRUE, "IOCTL unexpectedly failed %lx\n", GetLastError());
64
65 for (i = 0; i < AllocatedPoints->NumberOfMountPoints; ++i)
66 {
67 TraceMountPoint(AllocatedPoints, &AllocatedPoints->MountPoints[i]);
68 }
69
70 RtlFreeHeap(RtlGetProcessHeap(), 0, AllocatedPoints);
71 }
72
73 Drives = GetLogicalDrives();
74 if (Drives == 0)
75 {
76 win_skip("Drives map unavailable: %lx\n", GetLastError());
77 goto Done;
78 }
79
80 for (i = 0; i < 26; i++)
81 {
82 if (!(Drives & (1 << i)))
83 {
84 break;
85 }
86 }
87
88 if (i == 26)
89 {
90 win_skip("All the drive letters are in use, skipping\n");
91 goto Done;
92 }
93
94 SinglePoint.SymbolicLinkNameOffset = sizeof(MOUNTMGR_MOUNT_POINT);
95 SinglePoint.SymbolicLinkNameLength = sizeof(L"\\DosDevice\\A:") - sizeof(UNICODE_NULL);
96 StringCbPrintfW((PWSTR)((ULONG_PTR)&SinglePoint + sizeof(MOUNTMGR_MOUNT_POINT)),
97 sizeof(L"\\DosDevice\\A:"),
98 L"\\DosDevice\\%C:",
99 i + L'A');
100
101 Ret = DeviceIoControl(MountMgrHandle, IOCTL_MOUNTMGR_QUERY_POINTS,
102 &SinglePoint, sizeof(SinglePoint),
103 &MountPoints, sizeof(MOUNTMGR_MOUNT_POINTS),
104 &BytesReturned, NULL);
105 ok(Ret == FALSE, "IOCTL unexpectedly succeed\n");
106 ok(GetLastError() == ERROR_FILE_NOT_FOUND, "Unexcepted failure: %lx\n", GetLastError());
107
108 Done:
109 CloseHandle(MountMgrHandle);
110 }