[PATCH 1/4] kernel32/tests: Move a cdrom test to its own file

Alexandre Goujon ale.goujon at gmail.com
Sun Jun 10 12:53:08 CDT 2012


The cdrom test file will be used to test ioctl (results, structure size...)
Each drive is tested and skipped gracefully if ioctl not supported or not a CDROM drive.
---
 dlls/kernel32/tests/Makefile.in |    1 +
 dlls/kernel32/tests/cdrom.c     |   87 +++++++++++++++++++++++++++++++++++++++
 dlls/kernel32/tests/volume.c    |   30 --------------
 3 files changed, 88 insertions(+), 30 deletions(-)
 create mode 100644 dlls/kernel32/tests/cdrom.c

diff --git a/dlls/kernel32/tests/Makefile.in b/dlls/kernel32/tests/Makefile.in
index dce27db..91fbb12 100644
--- a/dlls/kernel32/tests/Makefile.in
+++ b/dlls/kernel32/tests/Makefile.in
@@ -6,6 +6,7 @@ C_SRCS = \
 	alloc.c \
 	atom.c \
 	change.c \
+        cdrom.c \
 	codepage.c \
 	comm.c \
 	console.c \
diff --git a/dlls/kernel32/tests/cdrom.c b/dlls/kernel32/tests/cdrom.c
new file mode 100644
index 0000000..6e74545
--- /dev/null
+++ b/dlls/kernel32/tests/cdrom.c
@@ -0,0 +1,87 @@
+/*
+ * Unit test suite for cdrom functions
+ *
+ * Copyright (C) the Wine project
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#include "wine/test.h"
+#include "windows.h"
+#include "winioctl.h"
+
+static void test_disk_extents(HANDLE handle)
+{
+    BOOL ret;
+    DWORD size;
+    static DWORD data[16];
+
+    size = 0;
+    ret = DeviceIoControl( handle, IOCTL_VOLUME_GET_VOLUME_DISK_EXTENTS, &data,
+                           sizeof(data), &data, sizeof(data), &size, NULL );
+    if ((!ret && GetLastError() == ERROR_INVALID_FUNCTION)
+     || (!ret && GetLastError() == ERROR_NOT_SUPPORTED))
+    {
+        skip("IOCTL_VOLUME_GET_VOLUME_DISK_EXTENTS not supported\n");
+        return;
+    }
+    ok(ret, "DeviceIoControl failed %u\n", GetLastError());
+    ok(size == 32, "expected 32, got %u\n", size);
+}
+
+START_TEST(cdrom)
+{
+    int i;
+    char drive_path[] = "A:\\", drive_full_path[] = "\\\\.\\A:";
+    DWORD bitmask;
+    HANDLE handle;
+
+    bitmask = GetLogicalDrives();
+    if(!bitmask)
+    {
+        trace("GetLogicalDrives failed : %u\n", GetLastError());
+        return;
+    }
+
+    for(i=0; i<26; i++)
+    {
+        if(!(bitmask & (1 << i)))
+            continue;
+
+        drive_path[0] = 'A' + i;
+        if(GetDriveTypeA(drive_path) != DRIVE_CDROM)
+        {
+            trace("Skipping %c:, not a CDROM drive.\n", drive_path[0]);
+            continue;
+        }
+
+        trace("Testing with %c:\n", drive_path[0]);
+
+        drive_full_path[4] = drive_path[0];
+        handle = CreateFileA(drive_full_path, GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, 0);
+        if(handle == INVALID_HANDLE_VALUE)
+        {
+            trace("Failed to open the device : %u\n", GetLastError());
+            continue;
+        }
+
+        /* Add your tests here */
+        test_disk_extents(handle);
+
+        CloseHandle(handle);
+    }
+
+}
+
diff --git a/dlls/kernel32/tests/volume.c b/dlls/kernel32/tests/volume.c
index 2755af5..247ca38 100644
--- a/dlls/kernel32/tests/volume.c
+++ b/dlls/kernel32/tests/volume.c
@@ -20,8 +20,6 @@
 
 #include "wine/test.h"
 #include "winbase.h"
-#include "winioctl.h"
-#include <stdio.h>
 
 static HINSTANCE hdll;
 static BOOL (WINAPI * pGetVolumeNameForVolumeMountPointA)(LPCSTR, LPSTR, DWORD);
@@ -540,33 +538,6 @@ static void test_enum_vols(void)
     pFindVolumeClose( hFind );
 }
 
-static void test_disk_extents(void)
-{
-    BOOL ret;
-    DWORD size;
-    HANDLE handle;
-    static DWORD data[16];
-
-    handle = CreateFileA( "\\\\.\\c:", GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, 0 );
-    if (handle == INVALID_HANDLE_VALUE)
-    {
-        win_skip("can't open c: drive %u\n", GetLastError());
-        return;
-    }
-    size = 0;
-    ret = DeviceIoControl( handle, IOCTL_VOLUME_GET_VOLUME_DISK_EXTENTS, &data,
-                           sizeof(data), &data, sizeof(data), &size, NULL );
-    if (!ret && GetLastError() == ERROR_INVALID_FUNCTION)
-    {
-        win_skip("IOCTL_VOLUME_GET_VOLUME_DISK_EXTENTS not supported\n");
-        CloseHandle( handle );
-        return;
-    }
-    ok(ret, "DeviceIoControl failed %u\n", GetLastError());
-    ok(size == 32, "expected 32, got %u\n", size);
-    CloseHandle( handle );
-}
-
 static void test_GetVolumePathNamesForVolumeNameA(void)
 {
     BOOL ret;
@@ -753,7 +724,6 @@ START_TEST(volume)
     test_GetLogicalDriveStringsW();
     test_GetVolumeInformationA();
     test_enum_vols();
-    test_disk_extents();
     test_GetVolumePathNamesForVolumeNameA();
     test_GetVolumePathNamesForVolumeNameW();
 }
-- 
1.7.9.5




More information about the wine-patches mailing list