winspool: Add a test for DeviceCapabilities, fix some bugs found
Dmitry Timoshkov
dmitry at codeweavers.com
Tue Apr 3 09:40:24 CDT 2007
Hello,
Changelog:
winspool: Add a test for DeviceCapabilities, fix some bugs found.
---
dlls/wineps.drv/driver.c | 19 +++----
dlls/winspool.drv/tests/info.c | 115 +++++++++++++++++++++++++++++++++++++++-
2 files changed, 121 insertions(+), 13 deletions(-)
diff --git a/dlls/wineps.drv/driver.c b/dlls/wineps.drv/driver.c
index 9c3136b..71c4651 100644
--- a/dlls/wineps.drv/driver.c
+++ b/dlls/wineps.drv/driver.c
@@ -447,15 +447,15 @@ DWORD PSDRV_DeviceCapabilities(LPSTR lpszDriver, LPCSTR lpszDevice, LPCSTR lpszP
DWORD ret;
pi = PSDRV_FindPrinterInfo(lpszDevice);
- TRACE("Cap=%d. Got PrinterInfo = %p\n", fwCapability, pi);
-
+ TRACE("%s %s %s, %u, %p, %p\n", debugstr_a(lpszDriver), debugstr_a(lpszDevice),
+ debugstr_a(lpszPort), fwCapability, lpszOutput, lpDevMode);
if (!pi) {
- ERR("no printerinfo for %s, return 0!\n",lpszDevice);
- return 0;
+ ERR("no printer info for %s %s, return 0!\n",
+ debugstr_a(lpszDriver), debugstr_a(lpszDevice));
+ return 0;
}
-
lpdm = lpDevMode ? lpDevMode : (DEVMODEA *)pi->Devmode;
switch(fwCapability) {
@@ -468,6 +468,7 @@ DWORD PSDRV_DeviceCapabilities(LPSTR lpszDriver, LPCSTR lpszDevice, LPCSTR lpszP
LIST_FOR_EACH_ENTRY(ps, &pi->ppd->PageSizes, PAGESIZE, entry)
{
+ TRACE("DC_PAPERS: %u\n", ps->WinPage);
i++;
if(lpszOutput != NULL)
*wp++ = ps->WinPage;
@@ -484,6 +485,7 @@ DWORD PSDRV_DeviceCapabilities(LPSTR lpszDriver, LPCSTR lpszDevice, LPCSTR lpszP
LIST_FOR_EACH_ENTRY(ps, &pi->ppd->PageSizes, PAGESIZE, entry)
{
i++;
+ TRACE("DC_PAPERSIZE: %f x %f\n", ps->PaperDimension->x, ps->PaperDimension->y);
if(lpszOutput != NULL) {
pt->x = ps->PaperDimension->x * 254.0 / 72.0;
pt->y = ps->PaperDimension->y * 254.0 / 72.0;
@@ -501,6 +503,7 @@ DWORD PSDRV_DeviceCapabilities(LPSTR lpszDriver, LPCSTR lpszDevice, LPCSTR lpszP
LIST_FOR_EACH_ENTRY(ps, &pi->ppd->PageSizes, PAGESIZE, entry)
{
+ TRACE("DC_PAPERNAMES: %s\n", debugstr_a(ps->FullName));
i++;
if(lpszOutput != NULL) {
lstrcpynA(cp, ps->FullName, 64);
@@ -593,9 +596,6 @@ DWORD PSDRV_DeviceCapabilities(LPSTR lpszDriver, LPCSTR lpszDevice, LPCSTR lpszP
POINT ptMax;
ptMax.x = ptMax.y = 0;
- if(lpszOutput == NULL)
- return -1;
-
LIST_FOR_EACH_ENTRY(ps, &pi->ppd->PageSizes, PAGESIZE, entry)
{
if(ps->PaperDimension->x > ptMax.x)
@@ -612,9 +612,6 @@ DWORD PSDRV_DeviceCapabilities(LPSTR lpszDriver, LPCSTR lpszDevice, LPCSTR lpszP
POINT ptMin;
ptMin.x = ptMin.y = -1;
- if(lpszOutput == NULL)
- return -1;
-
LIST_FOR_EACH_ENTRY(ps, &pi->ppd->PageSizes, PAGESIZE, entry)
{
if(ptMin.x == -1 || ps->PaperDimension->x < ptMin.x)
diff --git a/dlls/winspool.drv/tests/info.c b/dlls/winspool.drv/tests/info.c
index ebfed4b..c08603e 100644
--- a/dlls/winspool.drv/tests/info.c
+++ b/dlls/winspool.drv/tests/info.c
@@ -19,16 +19,18 @@
*/
#include <stdarg.h>
+#include <assert.h>
-#include "wine/test.h"
#include "windef.h"
#include "winbase.h"
#include "winerror.h"
#include "wingdi.h"
-#include <winnls.h>
+#include "winnls.h"
#include "winuser.h"
#include "winreg.h"
#include "winspool.h"
+#include "commdlg.h"
+#include "wine/test.h"
#define MAGIC_DEAD 0xdeadbeef
#define DEFAULT_PRINTER_SIZE 1000
@@ -1990,6 +1992,114 @@ static void test_EnumPrinters(void)
ok(neededA == neededW, "neededA %d neededW %d\n", neededA, neededW);
}
+static void test_DeviceCapabilities(void)
+{
+ HANDLE hComdlg32;
+ BOOL (WINAPI *pPrintDlg)(PRINTDLGA *);
+ PRINTDLGA prn_dlg;
+ DEVMODE *dm;
+ DEVNAMES *dn;
+ const char *driver, *device, *port;
+ WORD *papers;
+ POINT *paper_size;
+ POINTS ext;
+ struct
+ {
+ char name[64];
+ } *paper_name;
+ INT n_papers, n_paper_size, n_paper_names, n_copies, ret;
+ DWORD fields;
+
+ hComdlg32 = LoadLibrary("comdlg32.dll");
+ assert(hComdlg32);
+ pPrintDlg = GetProcAddress(hComdlg32, "PrintDlgA");
+ assert(pPrintDlg);
+
+ memset(&prn_dlg, 0, sizeof(prn_dlg));
+ prn_dlg.lStructSize = sizeof(prn_dlg);
+ prn_dlg.Flags = PD_RETURNDEFAULT;
+ ret = pPrintDlg(&prn_dlg);
+ FreeLibrary(hComdlg32);
+ if (!ret)
+ {
+ skip("no default printer\n");
+ return;
+ }
+ ok(prn_dlg.hDevMode != 0, "PrintDlg returned hDevMode == NULL\n");
+ ok(prn_dlg.hDevNames != 0, "PrintDlg returned hDevNames == NULL\n");
+
+ dm = GlobalLock(prn_dlg.hDevMode);
+ ok(dm != NULL, "GlobalLock(prn_dlg.hDevMode) failed\n");
+ trace("dmDeviceName \"%s\"\n", dm->dmDeviceName);
+
+ dn = GlobalLock(prn_dlg.hDevNames);
+ ok(dn != NULL, "GlobalLock(prn_dlg.hDevNames) failed\n");
+ ok(dn->wDriverOffset, "expected not 0 wDriverOffset\n");
+ ok(dn->wDeviceOffset, "expected not 0 wDeviceOffset\n");
+ ok(dn->wOutputOffset, "expected not 0 wOutputOffset\n");
+ ok(dn->wDefault == DN_DEFAULTPRN, "expected DN_DEFAULTPRN got %x\n", dn->wDefault);
+ driver = (const char *)dn + dn->wDriverOffset;
+ device = (const char *)dn + dn->wDeviceOffset;
+ port = (const char *)dn + dn->wOutputOffset;
+ trace("driver \"%s\" device \"%s\" port \"%s\"\n", driver, device, port);
+
+ ok(lstrcmp((const char *)dm->dmDeviceName, (const char *)dn + dn->wDeviceOffset) == 0, "device names not match\n");
+
+ n_papers = DeviceCapabilities(device, port, DC_PAPERS, NULL, NULL);
+ ok(n_papers > 0, "DeviceCapabilities DC_PAPERS failed\n");
+ papers = HeapAlloc(GetProcessHeap(), 0, sizeof(*papers) * n_papers);
+ ret = DeviceCapabilities(device, port, DC_PAPERS, (LPSTR)papers, NULL);
+ ok(ret == n_papers, "expected %d, got %d\n", n_papers, ret);
+ for (ret = 0; ret < n_papers; ret++)
+ trace("papers[%d] = %d\n", ret, papers[ret]);
+ HeapFree(GetProcessHeap(), 0, papers);
+
+ n_paper_size = DeviceCapabilities(device, port, DC_PAPERSIZE, NULL, NULL);
+ ok(n_paper_size > 0, "DeviceCapabilities DC_PAPERSIZE failed\n");
+ ok(n_paper_size == n_papers, "n_paper_size %d != n_papers %d\n", n_paper_size, n_papers);
+ paper_size = HeapAlloc(GetProcessHeap(), 0, sizeof(*paper_size) * n_paper_size);
+ ret = DeviceCapabilities(device, port, DC_PAPERSIZE, (LPSTR)paper_size, NULL);
+ ok(ret == n_paper_size, "expected %d, got %d\n", n_paper_size, ret);
+ for (ret = 0; ret < n_paper_size; ret++)
+ trace("paper_size[%d] = %d x %d\n", ret, paper_size[ret].x, paper_size[ret].y);
+ HeapFree(GetProcessHeap(), 0, paper_size);
+
+ n_paper_names = DeviceCapabilities(device, port, DC_PAPERNAMES, NULL, NULL);
+ ok(n_paper_names > 0, "DeviceCapabilities DC_PAPERNAMES failed\n");
+ ok(n_paper_names == n_papers, "n_paper_names %d != n_papers %d\n", n_paper_names, n_papers);
+ paper_name = HeapAlloc(GetProcessHeap(), 0, sizeof(*paper_name) * n_paper_names);
+ ret = DeviceCapabilities(device, port, DC_PAPERNAMES, (LPSTR)paper_name, NULL);
+ ok(ret == n_paper_names, "expected %d, got %d\n", n_paper_names, ret);
+ for (ret = 0; ret < n_paper_names; ret++)
+ trace("paper_name[%u] = %s\n", ret, paper_name[ret].name);
+ HeapFree(GetProcessHeap(), 0, paper_name);
+
+ n_copies = DeviceCapabilities(device, port, DC_COPIES, NULL, dm);
+ ok(n_copies > 0, "DeviceCapabilities DC_COPIES failed\n");
+ trace("n_copies = %d\n", n_copies);
+
+ ret = DeviceCapabilities(device, port, DC_MAXEXTENT, NULL, NULL);
+ ok(ret != -1, "DeviceCapabilities DC_MAXEXTENT failed\n");
+ ext = MAKEPOINTS(ret);
+ trace("max ext = %d x %d\n", ext.x, ext.y);
+
+ ret = DeviceCapabilities(device, port, DC_MINEXTENT, NULL, NULL);
+ ok(ret != -1, "DeviceCapabilities DC_MINEXTENT failed\n");
+ ext = MAKEPOINTS(ret);
+ trace("min ext = %d x %d\n", ext.x, ext.y);
+
+ fields = DeviceCapabilities(device, port, DC_FIELDS, NULL, NULL);
+ ok(fields != (DWORD)-1, "DeviceCapabilities DC_FIELDS failed\n");
+ trace("fields %x\n", fields);
+todo_wine
+ ok(fields == dm->dmFields, "fields %x != dmFields %x\n", fields, dm->dmFields);
+
+ GlobalUnlock(prn_dlg.hDevMode);
+ GlobalFree(prn_dlg.hDevMode);
+ GlobalUnlock(prn_dlg.hDevNames);
+ GlobalFree(prn_dlg.hDevNames);
+}
+
START_TEST(info)
{
hwinspool = GetModuleHandleA("winspool.drv");
@@ -2020,6 +2130,7 @@ START_TEST(info)
test_SetDefaultPrinter();
test_XcvDataW_MonitorUI();
test_XcvDataW_PortIsValid();
+ test_DeviceCapabilities();
/* Cleanup our temporary file */
DeleteFileA(tempfileA);
--
1.5.0.5
More information about the wine-patches
mailing list