[PATCH 4/7] kernel32/tests: initial tests for cdrom.c (try 2)

Dan Kegel dank at kegel.com
Fri Feb 10 14:30:30 CST 2012


As Joerg noted, there's no reason for this to be protected by
WINETEST_INTERACTIVE, so I removed that check.
Also now use A versions of functions.

---
 dlls/kernel32/tests/Makefile.in |    1 +
 dlls/kernel32/tests/cdrom.c     |  156 +++++++++++++++++++++++++++++++++++++++
 2 files changed, 157 insertions(+), 0 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..bc3456c 100644
--- a/dlls/kernel32/tests/Makefile.in
+++ b/dlls/kernel32/tests/Makefile.in
@@ -5,6 +5,7 @@ C_SRCS = \
 	actctx.c \
 	alloc.c \
 	atom.c \
+	cdrom.c \
 	change.c \
 	codepage.c \
 	comm.c \
diff --git a/dlls/kernel32/tests/cdrom.c b/dlls/kernel32/tests/cdrom.c
new file mode 100644
index 0000000..f8e1968
--- /dev/null
+++ b/dlls/kernel32/tests/cdrom.c
@@ -0,0 +1,156 @@
+/*
+ * Unit test suite for cdrom functions
+ *
+ * Copyright (C) 2012 Dan Kegel
+ *
+ * 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 <windows.h>
+
+#include <ddk/ntddcdvd.h>
+#include <ntddscsi.h>
+#include <ddk/scsi.h>
+
+#include "wine/test.h"
+
+#include <pshpack1.h>
+
+typedef struct xDVD_LAYER_DESCRIPTOR {
+    struct _DVD_DESCRIPTOR_HEADER h;
+    struct _DVD_LAYER_DESCRIPTOR layer;
+
+    /* If this struct is not 22 bytes, IOCTL_DVD_READ_STRUCTURE
+     * in Windows 7 complains "incorrect parameter".
+     * So either use pack(1) and explicit padding, or leave out pack(1).
+     */
+    char reserved1;
+} xDVD_LAYER_DESCRIPTOR;
+
+#include <poppack.h>
+
+/* Backdoor way to do the same thing as IOCTL_DVD_READ_STRUCTURE */
+DWORD read_discStructure(HANDLE device, int format, void *obuf, int obuflen)
+{
+    struct _READ_DVD_STRUCTURE cdb;
+    DWORD bytes_read;
+    DWORD bRet;
+
+    unsigned char ibuf[sizeof(SCSI_PASS_THROUGH_DIRECT) + 96];
+    SCSI_PASS_THROUGH_DIRECT *pptd = (SCSI_PASS_THROUGH_DIRECT *) ibuf;
+
+    ZeroMemory(ibuf, sizeof(ibuf));
+    ZeroMemory(&cdb, sizeof(cdb));
+    cdb.OperationCode = SCSIOP_READ_DVD_STRUCTURE;
+    cdb.AllocationLength = sizeof(struct _READ_DVD_STRUCTURE);
+    cdb.Format = format;
+    memcpy(pptd->Cdb, &cdb, sizeof(cdb));
+
+    pptd->DataBuffer = obuf;
+    pptd->DataTransferLength = obuflen;
+    pptd->DataIn = SCSI_IOCTL_DATA_IN;
+    pptd->CdbLength = sizeof(cdb);
+    pptd->Length = sizeof(SCSI_PASS_THROUGH_DIRECT);
+    pptd->SenseInfoLength = sizeof(ibuf) - sizeof(SCSI_PASS_THROUGH_DIRECT);
+    pptd->SenseInfoOffset = sizeof(SCSI_PASS_THROUGH_DIRECT);
+    pptd->TimeOutValue = 10000;
+
+    bRet = DeviceIoControl(device, IOCTL_SCSI_PASS_THROUGH_DIRECT,
+                           &ibuf, sizeof(ibuf),
+                           &ibuf, sizeof(ibuf), &bytes_read,
+                           NULL);
+    return bRet;
+}
+
+/* Compare dvd layer descriptor as read via two different APIs */
+static void test_readStruct_layer_vs_passthrough(HANDLE hdevice)
+{
+    struct xDVD_LAYER_DESCRIPTOR xlayer1;
+    struct xDVD_LAYER_DESCRIPTOR xlayer2;
+    DVD_READ_STRUCTURE ibuf;
+    DWORD bytes_read;
+    BOOL bRet;
+
+    bRet = read_discStructure(hdevice, DvdPhysicalDescriptor, &xlayer1, sizeof(xlayer1));
+    ok(bRet, "can't read layer via SCSI_PASS_THROUGH_DIRECT\n");
+
+    ZeroMemory(&ibuf, sizeof(ibuf));
+    ibuf.Format = DvdPhysicalDescriptor;
+    bRet = DeviceIoControl(hdevice, IOCTL_DVD_READ_STRUCTURE,
+                           &ibuf, sizeof(ibuf),
+                           &xlayer2, sizeof(xlayer2), &bytes_read, 0);
+    ok(bRet, "can't read layer via IOCTL_DVD_READ_STRUCTURE\n");
+
+    ok(memcmp(&xlayer1.layer, &xlayer2.layer, sizeof(xlayer1.layer)) == 0,
+       "SCSI_PASS_THROUGH_DIRECT and IOCTL_DVD_READ_STRUCTURE report different results for DvdPhysicalDescriptor\n");
+}
+
+static BOOL isDvd(HANDLE hdevice)
+{
+    struct xDVD_LAYER_DESCRIPTOR xlayer;
+    DVD_READ_STRUCTURE ibuf;
+    DWORD bytes_read;
+
+    ZeroMemory(&ibuf, sizeof(ibuf));
+    ibuf.Format = DvdPhysicalDescriptor;
+    return DeviceIoControl(hdevice, IOCTL_DVD_READ_STRUCTURE,
+                           &ibuf, sizeof(ibuf),
+                           &xlayer, sizeof(xlayer), &bytes_read, 0);
+}
+
+START_TEST(cdrom)
+{
+    char drivepath[8];
+    char driveletter;
+    int i;
+    HANDLE hdevice;
+
+    driveletter = 0;
+    for (i='c'; i < 'y'; i++) {
+        drivepath[0] = i;
+        drivepath[1] = ':';
+        drivepath[2] = 0;
+        if (GetDriveTypeA(drivepath) == DRIVE_CDROM) {
+           driveletter = i;
+           break;
+        }
+    }
+    if (!driveletter) {
+        skip("GetDriveTypeA() found no CD/DVD drives\n");
+        return;
+    }
+    drivepath[0] = '\\';
+    drivepath[1] = '\\';
+    drivepath[2] = '.';
+    drivepath[3] = '\\';
+    drivepath[4] = driveletter;
+    drivepath[5] = ':';
+    drivepath[6] = 0;
+
+    /* GENERIC_WRITE because without it, passthrough doesn't work on win7 */
+    hdevice = CreateFileA(drivepath, GENERIC_READ|GENERIC_WRITE,
+                         FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL);
+    if (hdevice == INVALID_HANDLE_VALUE) {
+        skip("Can't open %s\n", drivepath);
+        return;
+    }
+    if (!isDvd(hdevice)) {
+        skip("can't read DVD info from %s\n", drivepath);
+    } else {
+        /* DVD tests */
+        test_readStruct_layer_vs_passthrough(hdevice);
+    }
+    CloseHandle(hdevice);
+}
-- 
1.7.9




More information about the wine-patches mailing list