2006-07-03 22:55:53 +02:00
|
|
|
/*
|
|
|
|
* Unit test suite for comdlg32 API functions: printer dialogs
|
|
|
|
*
|
2007-09-24 15:41:09 +02:00
|
|
|
* Copyright 2006-2007 Detlef Riekenberg
|
2006-07-03 22:55:53 +02:00
|
|
|
*
|
|
|
|
* 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 <stdarg.h>
|
|
|
|
|
|
|
|
#include "windef.h"
|
|
|
|
#include "winbase.h"
|
|
|
|
#include "winerror.h"
|
|
|
|
#include "wingdi.h"
|
|
|
|
#include "winuser.h"
|
2008-03-22 23:50:43 +01:00
|
|
|
#include "objbase.h"
|
2006-07-03 22:55:53 +02:00
|
|
|
|
|
|
|
#include "cderr.h"
|
|
|
|
#include "commdlg.h"
|
|
|
|
|
|
|
|
#include "wine/test.h"
|
|
|
|
|
2007-10-26 00:33:48 +02:00
|
|
|
/* ########################### */
|
|
|
|
|
|
|
|
static HMODULE hcomdlg32;
|
|
|
|
static HRESULT (WINAPI * pPrintDlgExA)(LPPRINTDLGEXA);
|
|
|
|
static HRESULT (WINAPI * pPrintDlgExW)(LPPRINTDLGEXW);
|
|
|
|
|
|
|
|
/* ########################### */
|
2007-09-24 15:41:09 +02:00
|
|
|
|
|
|
|
static const CHAR emptyA[] = "";
|
|
|
|
static const CHAR PrinterPortsA[] = "PrinterPorts";
|
2006-07-03 22:55:53 +02:00
|
|
|
|
2007-10-26 00:33:48 +02:00
|
|
|
/* ########################### */
|
|
|
|
|
|
|
|
static LPCSTR load_functions(void)
|
|
|
|
{
|
|
|
|
LPCSTR ptr;
|
|
|
|
|
|
|
|
ptr = "comdlg32.dll";
|
2008-06-09 09:16:56 +02:00
|
|
|
hcomdlg32 = GetModuleHandleA(ptr);
|
2007-10-26 00:33:48 +02:00
|
|
|
|
|
|
|
ptr = "PrintDlgExA";
|
|
|
|
pPrintDlgExA = (void *) GetProcAddress(hcomdlg32, ptr);
|
|
|
|
if (!pPrintDlgExA) return ptr;
|
|
|
|
|
|
|
|
ptr = "PrintDlgExW";
|
|
|
|
pPrintDlgExW = (void *) GetProcAddress(hcomdlg32, ptr);
|
|
|
|
if (!pPrintDlgExW) return ptr;
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ########################### */
|
2007-08-09 19:11:20 +02:00
|
|
|
|
|
|
|
static void test_PageSetupDlgA(void)
|
|
|
|
{
|
|
|
|
LPPAGESETUPDLGA pDlg;
|
|
|
|
DWORD res;
|
|
|
|
|
|
|
|
pDlg = HeapAlloc(GetProcessHeap(), 0, (sizeof(PAGESETUPDLGA)) * 2);
|
|
|
|
if (!pDlg) return;
|
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
res = PageSetupDlgA(NULL);
|
|
|
|
ok( !res && (CommDlgExtendedError() == CDERR_INITIALIZATION),
|
|
|
|
"returned %u with %u and 0x%x (expected '0' and "
|
|
|
|
"CDERR_INITIALIZATION)\n", res, GetLastError(), CommDlgExtendedError());
|
|
|
|
|
|
|
|
ZeroMemory(pDlg, sizeof(PAGESETUPDLGA));
|
|
|
|
pDlg->lStructSize = sizeof(PAGESETUPDLGA) -1;
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
res = PageSetupDlgA(pDlg);
|
|
|
|
ok( !res && (CommDlgExtendedError() == CDERR_STRUCTSIZE),
|
|
|
|
"returned %u with %u and 0x%x (expected '0' and "
|
|
|
|
"CDERR_STRUCTSIZE)\n", res, GetLastError(), CommDlgExtendedError());
|
|
|
|
|
2007-08-10 07:12:04 +02:00
|
|
|
ZeroMemory(pDlg, sizeof(PAGESETUPDLGA));
|
|
|
|
pDlg->lStructSize = sizeof(PAGESETUPDLGA) +1;
|
|
|
|
pDlg->Flags = PSD_RETURNDEFAULT;
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
res = PageSetupDlgA(pDlg);
|
|
|
|
ok( !res && (CommDlgExtendedError() == CDERR_STRUCTSIZE),
|
|
|
|
"returned %u with %u and 0x%x (expected '0' and CDERR_STRUCTSIZE)\n",
|
|
|
|
res, GetLastError(), CommDlgExtendedError());
|
|
|
|
|
2007-08-09 19:11:20 +02:00
|
|
|
|
|
|
|
ZeroMemory(pDlg, sizeof(PAGESETUPDLGA));
|
|
|
|
pDlg->lStructSize = sizeof(PAGESETUPDLGA);
|
2007-10-06 16:43:58 +02:00
|
|
|
pDlg->Flags = PSD_RETURNDEFAULT | PSD_NOWARNING;
|
2007-08-09 19:11:20 +02:00
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
res = PageSetupDlgA(pDlg);
|
|
|
|
ok( res || (CommDlgExtendedError() == PDERR_NODEFAULTPRN),
|
|
|
|
"returned %u with %u and 0x%x (expected '!= 0' or '0' and "
|
|
|
|
"PDERR_NODEFAULTPRN)\n", res, GetLastError(), CommDlgExtendedError());
|
2007-09-24 21:18:10 +02:00
|
|
|
|
2007-08-19 11:34:57 +02:00
|
|
|
if (!res && (CommDlgExtendedError() == PDERR_NODEFAULTPRN)) {
|
2007-09-24 21:18:10 +02:00
|
|
|
skip("No printer configured.\n");
|
|
|
|
HeapFree(GetProcessHeap(), 0, pDlg);
|
|
|
|
return;
|
2007-08-19 11:34:57 +02:00
|
|
|
}
|
2007-09-24 21:18:10 +02:00
|
|
|
|
2007-08-09 19:11:20 +02:00
|
|
|
ok( pDlg->hDevMode && pDlg->hDevNames,
|
|
|
|
"got %p and %p (expected '!= NULL' for both)\n",
|
|
|
|
pDlg->hDevMode, pDlg->hDevNames);
|
|
|
|
|
|
|
|
GlobalFree(pDlg->hDevMode);
|
|
|
|
GlobalFree(pDlg->hDevNames);
|
|
|
|
|
|
|
|
HeapFree(GetProcessHeap(), 0, pDlg);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2007-10-26 00:33:48 +02:00
|
|
|
/* ########################### */
|
2006-07-03 22:55:53 +02:00
|
|
|
|
|
|
|
static void test_PrintDlgA(void)
|
|
|
|
{
|
|
|
|
DWORD res;
|
|
|
|
LPPRINTDLGA pDlg;
|
2007-09-24 15:41:09 +02:00
|
|
|
DEVNAMES *pDevNames;
|
|
|
|
LPCSTR driver;
|
|
|
|
LPCSTR device;
|
|
|
|
LPCSTR port;
|
|
|
|
CHAR buffer[MAX_PATH];
|
|
|
|
LPSTR ptr;
|
2006-07-03 22:55:53 +02:00
|
|
|
|
|
|
|
|
|
|
|
pDlg = HeapAlloc(GetProcessHeap(), 0, (sizeof(PRINTDLGA)) * 2);
|
|
|
|
if (!pDlg) return;
|
|
|
|
|
|
|
|
|
|
|
|
/* will crash with unpatched wine */
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
res = PrintDlgA(NULL);
|
|
|
|
ok( !res && (CommDlgExtendedError() == CDERR_INITIALIZATION),
|
2006-12-27 00:19:50 +01:00
|
|
|
"returned %d with 0x%x and 0x%x (expected '0' and "
|
2006-07-03 22:55:53 +02:00
|
|
|
"CDERR_INITIALIZATION)\n", res, GetLastError(), CommDlgExtendedError());
|
|
|
|
|
|
|
|
ZeroMemory(pDlg, sizeof(PRINTDLGA));
|
|
|
|
pDlg->lStructSize = sizeof(PRINTDLGA) - 1;
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
res = PrintDlgA(pDlg);
|
|
|
|
ok( !res && (CommDlgExtendedError() == CDERR_STRUCTSIZE),
|
2006-12-27 00:19:50 +01:00
|
|
|
"returned %d with 0x%x and 0x%x (expected '0' and "
|
2006-07-03 22:55:53 +02:00
|
|
|
"CDERR_STRUCTSIZE)\n", res, GetLastError(), CommDlgExtendedError());
|
|
|
|
|
2007-08-10 07:12:04 +02:00
|
|
|
ZeroMemory(pDlg, sizeof(PRINTDLGA));
|
|
|
|
pDlg->lStructSize = sizeof(PRINTDLGA) + 1;
|
|
|
|
pDlg->Flags = PD_RETURNDEFAULT;
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
res = PrintDlgA(pDlg);
|
|
|
|
ok( !res && (CommDlgExtendedError() == CDERR_STRUCTSIZE),
|
|
|
|
"returned %u with %u and 0x%x (expected '0' and "
|
|
|
|
"CDERR_STRUCTSIZE)\n", res, GetLastError(), CommDlgExtendedError());
|
|
|
|
|
2006-07-03 22:55:53 +02:00
|
|
|
|
|
|
|
ZeroMemory(pDlg, sizeof(PRINTDLGA));
|
|
|
|
pDlg->lStructSize = sizeof(PRINTDLGA);
|
|
|
|
pDlg->Flags = PD_RETURNDEFAULT;
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
res = PrintDlgA(pDlg);
|
2006-07-23 20:39:18 +02:00
|
|
|
ok( res || (CommDlgExtendedError() == PDERR_NODEFAULTPRN),
|
2006-12-27 00:19:50 +01:00
|
|
|
"returned %d with 0x%x and 0x%x (expected '!= 0' or '0' and "
|
2006-07-23 20:39:18 +02:00
|
|
|
"PDERR_NODEFAULTPRN)\n", res, GetLastError(), CommDlgExtendedError());
|
2006-07-03 22:55:53 +02:00
|
|
|
|
2007-09-24 15:41:09 +02:00
|
|
|
if (!res && (CommDlgExtendedError() == PDERR_NODEFAULTPRN)) {
|
|
|
|
skip("No printer configured.\n");
|
|
|
|
HeapFree(GetProcessHeap(), 0, pDlg);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ok(pDlg->hDevNames != NULL, "(expected '!= NULL')\n");
|
|
|
|
pDevNames = GlobalLock(pDlg->hDevNames);
|
|
|
|
ok(pDevNames != NULL, "(expected '!= NULL')\n");
|
|
|
|
|
|
|
|
if (pDevNames) {
|
|
|
|
ok(pDevNames->wDriverOffset, "(expected '!= 0' for wDriverOffset)\n");
|
|
|
|
ok(pDevNames->wDeviceOffset, "(expected '!= 0' for wDeviceOffset)\n");
|
|
|
|
ok(pDevNames->wOutputOffset, "(expected '!= 0' for wOutputOffset)\n");
|
|
|
|
ok(pDevNames->wDefault == DN_DEFAULTPRN, "got 0x%x (expected DN_DEFAULTPRN)\n", pDevNames->wDefault);
|
|
|
|
|
|
|
|
driver = (LPCSTR)pDevNames + pDevNames->wDriverOffset;
|
|
|
|
device = (LPCSTR)pDevNames + pDevNames->wDeviceOffset;
|
|
|
|
port = (LPCSTR)pDevNames + pDevNames->wOutputOffset;
|
|
|
|
trace("driver '%s' device '%s' port '%s'\n", driver, device, port);
|
|
|
|
|
|
|
|
/* The Driver Entry does not include a Path */
|
|
|
|
ptr = strrchr(driver, '\\');
|
|
|
|
todo_wine {
|
|
|
|
ok( ptr == NULL, "got %p for '%s' (expected NULL for a simple name)\n", ptr, driver);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* The Driver Entry does not have an extension (fixed to ".drv") */
|
|
|
|
ptr = strrchr(driver, '.');
|
|
|
|
todo_wine {
|
|
|
|
ok( ptr == NULL, "got %p for '%s' (expected NULL for no extension)\n", ptr, driver);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
buffer[0] = '\0';
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
res = GetProfileStringA(PrinterPortsA, device, emptyA, buffer, sizeof(buffer));
|
|
|
|
ptr = strchr(buffer, ',');
|
|
|
|
ok( (res > 1) && (ptr != NULL),
|
|
|
|
"got %u with %u and %p for '%s' (expected '>1' and '!= NULL')\n",
|
|
|
|
res, GetLastError(), ptr, buffer);
|
|
|
|
|
|
|
|
if (ptr) ptr[0] = '\0';
|
|
|
|
todo_wine {
|
|
|
|
ok( lstrcmpiA(driver, buffer) == 0,
|
|
|
|
"got driver '%s' (expected '%s')\n", driver, buffer);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
GlobalUnlock(pDlg->hDevNames);
|
|
|
|
|
|
|
|
GlobalFree(pDlg->hDevMode);
|
|
|
|
GlobalFree(pDlg->hDevNames);
|
2006-07-03 22:55:53 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, pDlg);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2007-10-26 00:33:48 +02:00
|
|
|
/* ########################### */
|
|
|
|
|
|
|
|
static void test_PrintDlgExW(void)
|
|
|
|
{
|
|
|
|
LPPRINTDLGEXW pDlg;
|
|
|
|
HRESULT res;
|
|
|
|
|
|
|
|
/* Set CommDlgExtendedError != 0 */
|
|
|
|
PrintDlg(NULL);
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
res = pPrintDlgExW(NULL);
|
|
|
|
ok( (res == E_INVALIDARG),
|
|
|
|
"got 0x%x with %u and %u (expected 'E_INVALIDARG')\n",
|
|
|
|
res, GetLastError(), CommDlgExtendedError());
|
|
|
|
|
|
|
|
|
|
|
|
pDlg = HeapAlloc(GetProcessHeap(), 0, (sizeof(PRINTDLGEXW)) + 8);
|
|
|
|
if (!pDlg) return;
|
|
|
|
|
|
|
|
/* lStructSize must be exact */
|
|
|
|
ZeroMemory(pDlg, sizeof(PRINTDLGEXW));
|
|
|
|
pDlg->lStructSize = sizeof(PRINTDLGEXW) - 1;
|
|
|
|
PrintDlg(NULL);
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
res = pPrintDlgExW(pDlg);
|
|
|
|
ok( (res == E_INVALIDARG),
|
|
|
|
"got 0x%x with %u and %u (expected 'E_INVALIDARG')\n",
|
|
|
|
res, GetLastError(), CommDlgExtendedError());
|
|
|
|
|
|
|
|
|
|
|
|
ZeroMemory(pDlg, sizeof(PRINTDLGEXW));
|
|
|
|
pDlg->lStructSize = sizeof(PRINTDLGEXW) + 1;
|
|
|
|
PrintDlg(NULL);
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
res = pPrintDlgExW(pDlg);
|
|
|
|
ok( (res == E_INVALIDARG),
|
|
|
|
"got 0x%x with %u and %u (expected 'E_INVALIDARG')\n",
|
|
|
|
res, GetLastError(), CommDlgExtendedError());
|
|
|
|
|
|
|
|
|
|
|
|
ZeroMemory(pDlg, sizeof(PRINTDLGEXW));
|
|
|
|
pDlg->lStructSize = sizeof(PRINTDLGEXW);
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
res = pPrintDlgExW(pDlg);
|
|
|
|
ok( (res == E_HANDLE),
|
|
|
|
"got 0x%x with %u and %u (expected 'E_HANDLE')\n",
|
|
|
|
res, GetLastError(), CommDlgExtendedError());
|
|
|
|
|
|
|
|
|
|
|
|
HeapFree(GetProcessHeap(), 0, pDlg);
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2008-10-07 16:01:01 +02:00
|
|
|
static BOOL abort_proc_called = FALSE;
|
|
|
|
static BOOL CALLBACK abort_proc(HDC hdc, int error) { return abort_proc_called = TRUE; }
|
|
|
|
static void test_abort_proc(void)
|
|
|
|
{
|
|
|
|
HDC print_dc;
|
|
|
|
RECT rect = {0, 0, 100, 100};
|
|
|
|
DOCINFOA doc_info = {0};
|
|
|
|
PRINTDLGA pd = {0};
|
|
|
|
char filename[MAX_PATH];
|
|
|
|
|
|
|
|
if (!GetTempFileNameA(".", "prn", 0, filename))
|
|
|
|
{
|
|
|
|
skip("Failed to create a temporary file name\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
pd.lStructSize = sizeof(pd);
|
|
|
|
pd.Flags = PD_RETURNDEFAULT | PD_ALLPAGES | PD_RETURNDC | PD_PRINTTOFILE;
|
|
|
|
pd.nFromPage = 1;
|
|
|
|
pd.nToPage = 1;
|
|
|
|
pd.nCopies = 1;
|
|
|
|
|
|
|
|
if (!PrintDlgA(&pd))
|
|
|
|
{
|
|
|
|
skip("No default printer available.\n");
|
|
|
|
ok(DeleteFileA(filename), "Failed to delete temporary file\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ok(pd.hDC != NULL, "PrintDlg didn't return a DC.\n");
|
|
|
|
if (!(print_dc = pd.hDC))
|
|
|
|
{
|
|
|
|
ok(DeleteFileA(filename), "Failed to delete temporary file\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ok(SetAbortProc(print_dc, abort_proc) > 0, "SetAbortProc failed\n");
|
|
|
|
ok(!abort_proc_called, "AbortProc got called unexpectedly by SetAbortProc.\n");
|
|
|
|
abort_proc_called = FALSE;
|
|
|
|
|
|
|
|
doc_info.cbSize = sizeof(doc_info);
|
|
|
|
doc_info.lpszDocName = "Some document";
|
|
|
|
doc_info.lpszOutput = filename;
|
|
|
|
|
|
|
|
ok(StartDocA(print_dc, &doc_info) > 0, "StartDocA failed\n");
|
|
|
|
ok(abort_proc_called, "AbortProc didn't get called by StartDoc.\n");
|
|
|
|
abort_proc_called = FALSE;
|
|
|
|
|
|
|
|
ok(StartPage(print_dc) > 0, "StartPage failed\n");
|
|
|
|
ok(!abort_proc_called, "AbortProc got called unexpectedly by StartPage.\n");
|
|
|
|
abort_proc_called = FALSE;
|
|
|
|
|
|
|
|
ok(FillRect(print_dc, &rect, (HBRUSH)(COLOR_BACKGROUND + 1)), "FillRect failed\n");
|
|
|
|
ok(!abort_proc_called, "AbortProc got called unexpectedly by StretchBlt.\n");
|
|
|
|
abort_proc_called = FALSE;
|
|
|
|
|
|
|
|
ok(EndPage(print_dc) > 0, "EndPage failed\n");
|
|
|
|
ok(!abort_proc_called, "AbortProc got called unexpectedly by EndPage.\n");
|
|
|
|
abort_proc_called = FALSE;
|
|
|
|
|
|
|
|
ok(EndDoc(print_dc) > 0, "EndDoc failed\n");
|
|
|
|
ok(!abort_proc_called, "AbortProc got called unexpectedly by EndDoc.\n");
|
|
|
|
abort_proc_called = FALSE;
|
|
|
|
|
|
|
|
ok(DeleteDC(print_dc), "DeleteDC failed\n");
|
|
|
|
ok(!abort_proc_called, "AbortProc got called unexpectedly by DeleteDC.\n");
|
|
|
|
abort_proc_called = FALSE;
|
|
|
|
|
|
|
|
ok(DeleteFileA(filename), "Failed to delete temporary file\n");
|
|
|
|
}
|
|
|
|
|
2007-10-26 00:33:48 +02:00
|
|
|
/* ########################### */
|
2006-07-03 22:55:53 +02:00
|
|
|
|
|
|
|
START_TEST(printdlg)
|
|
|
|
{
|
2007-10-26 00:33:48 +02:00
|
|
|
LPCSTR ptr;
|
|
|
|
|
|
|
|
ptr = load_functions();
|
|
|
|
|
2007-08-09 19:11:20 +02:00
|
|
|
test_PageSetupDlgA();
|
2006-07-03 22:55:53 +02:00
|
|
|
test_PrintDlgA();
|
2008-10-07 16:01:01 +02:00
|
|
|
test_abort_proc();
|
2006-07-03 22:55:53 +02:00
|
|
|
|
2007-10-26 00:33:48 +02:00
|
|
|
/* PrintDlgEx not present before w2k */
|
|
|
|
if (ptr) {
|
|
|
|
skip("%s\n", ptr);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
test_PrintDlgExW();
|
2006-07-03 22:55:53 +02:00
|
|
|
}
|