static void test_PrintDlgA(void) { DWORD res; LPPRINTDLGA pDlg; pDlg = HeapAlloc(GetProcessHeap(), 0, (sizeof(PRINTDLGA)) * 2); if (!pDlg) return; #if 0 /* will crash with unpatched wine */ SetLastError(0xdeadbeef); res = PrintDlgA(NULL); ok( !res && (CommDlgExtendedError() == CDERR_INITIALIZATION), "returned %ld with 0x%lx and 0x%lx (expected '0' and " \ "CDERR_INITIALIZATION)\n", res, GetLastError(), CommDlgExtendedError()); }
int QPrintDialogPrivate::openWindowsPrintDialogModally() { Q_Q(QPrintDialog); QWidget *parent = q->parentWidget(); if (parent) parent = parent->window(); else parent = qApp->activeWindow(); QWidget modal_widget; modal_widget.setAttribute(Qt::WA_NoChildEventsForParent, true); modal_widget.setParent(parent, Qt::Window); QApplicationPrivate::enterModal(&modal_widget); HGLOBAL *tempDevNames = ep->createDevNames(); bool result; bool done; void *pd = QT_WA_INLINE( (void*)(qt_win_make_PRINTDLG<PRINTDLGW, DEVMODEW>(parent, q, this, tempDevNames)), (void*)(qt_win_make_PRINTDLG<PRINTDLGA, DEVMODEA>(parent, q, this, tempDevNames)) ); do { done = true; QT_WA({ PRINTDLGW *pdw = reinterpret_cast<PRINTDLGW *>(pd); result = PrintDlgW(pdw); if ((pdw->Flags & PD_PAGENUMS) && (pdw->nFromPage > pdw->nToPage)) done = false; if (result && pdw->hDC == 0) result = false; else if (!result) done = true; }, { PRINTDLGA *pda = reinterpret_cast<PRINTDLGA *>(pd); result = PrintDlgA(pda); if ((pda->Flags & PD_PAGENUMS) && (pda->nFromPage > pda->nToPage)) done = false; if (result && pda->hDC == 0) result = false; else if (!result) done = true; });
#if 0 /* will crash with unpatched wine */ SetLastError(0xdeadbeef); res = PrintDlgA(NULL); ok( !res && (CommDlgExtendedError() == CDERR_INITIALIZATION), "returned %ld with 0x%lx and 0x%lx (expected '0' and " \ "CDERR_INITIALIZATION)\n", res, GetLastError(), CommDlgExtendedError()); } #endif ZeroMemory(pDlg, sizeof(PRINTDLGA)); pDlg->lStructSize = sizeof(PRINTDLGA) - 1; SetLastError(0xdeadbeef); res = PrintDlgA(pDlg); ok( !res && (CommDlgExtendedError() == CDERR_STRUCTSIZE), "returned %ld with 0x%lx and 0x%lx (expected '0' and " \ "CDERR_STRUCTSIZE)\n", res, GetLastError(), CommDlgExtendedError()); ZeroMemory(pDlg, sizeof(PRINTDLGA)); pDlg->lStructSize = sizeof(PRINTDLGA); pDlg->Flags = PD_RETURNDEFAULT; SetLastError(0xdeadbeef); res = PrintDlgA(pDlg); ok( res || (CommDlgExtendedError() == PDERR_NODEFAULTPRN), "returned %ld with 0x%lx and 0x%lx (expected '!= 0' or '0' and " \ "PDERR_NODEFAULTPRN)\n", res, GetLastError(), CommDlgExtendedError()); HeapFree(GetProcessHeap(), 0, pDlg);
/* bug 6829 */ static void test_DialogCancel(void) { OPENFILENAMEA ofn; BOOL result; char szFileName[MAX_PATH] = ""; char szInitialDir[MAX_PATH]; GetWindowsDirectory(szInitialDir, MAX_PATH); ZeroMemory(&ofn, sizeof(ofn)); ofn.lStructSize = sizeof(ofn); ofn.hwndOwner = NULL; ofn.lpstrFilter = "Text Files (*.txt)\0*.txt\0All Files (*.*)\0*.*\0"; ofn.lpstrFile = szFileName; ofn.nMaxFile = MAX_PATH; ofn.Flags = OFN_EXPLORER | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY | OFN_ENABLEHOOK; ofn.lpstrDefExt = "txt"; ofn.lpfnHook = OFNHookProc; ofn.lpstrInitialDir = szInitialDir; PrintDlgA(NULL); ok(CDERR_INITIALIZATION == CommDlgExtendedError(), "expected CDERR_INITIALIZATION, got %d\n", CommDlgExtendedError()); result = GetOpenFileNameA(&ofn); ok(0 == result, "expected 0, got %d\n", result); ok(0 == CommDlgExtendedError(), "expected 0, got %d\n", CommDlgExtendedError()); PrintDlgA(NULL); ok(CDERR_INITIALIZATION == CommDlgExtendedError(), "expected CDERR_INITIALIZATION, got %d\n", CommDlgExtendedError()); result = GetSaveFileNameA(&ofn); ok(0 == result, "expected 0, got %d\n", result); ok(0 == CommDlgExtendedError(), "expected 0, got %d\n", CommDlgExtendedError()); PrintDlgA(NULL); ok(CDERR_INITIALIZATION == CommDlgExtendedError(), "expected CDERR_INITIALIZATION, got %d\n", CommDlgExtendedError()); /* Before passing the ofn to Unicode functions, remove the ANSI strings */ ofn.lpstrFilter = NULL; ofn.lpstrInitialDir = NULL; ofn.lpstrDefExt = NULL; PrintDlgA(NULL); ok(CDERR_INITIALIZATION == CommDlgExtendedError(), "expected CDERR_INITIALIZATION, got %d\n", CommDlgExtendedError()); SetLastError(0xdeadbeef); result = GetOpenFileNameW((LPOPENFILENAMEW) &ofn); if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED) win_skip("GetOpenFileNameW is not implemented\n"); else { ok(0 == result, "expected 0, got %d\n", result); ok(0 == CommDlgExtendedError() || broken(CDERR_INITIALIZATION == CommDlgExtendedError()), /* win9x */ "expected 0, got %d\n", CommDlgExtendedError()); } SetLastError(0xdeadbeef); result = GetSaveFileNameW((LPOPENFILENAMEW) &ofn); if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED) win_skip("GetSaveFileNameW is not implemented\n"); else { ok(0 == result, "expected 0, got %d\n", result); ok(0 == CommDlgExtendedError() || broken(CDERR_INITIALIZATION == CommDlgExtendedError()), /* win9x */ "expected 0, got %d\n", CommDlgExtendedError()); } }
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"); }
static void test_PrintDlgA(void) { DWORD res; LPPRINTDLGA pDlg; DEVNAMES *pDevNames; LPCSTR driver; LPCSTR device; LPCSTR port; CHAR buffer[MAX_PATH]; LPSTR ptr; 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), "returned %d with 0x%x and 0x%x (expected '0' and " "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), "returned %d with 0x%x and 0x%x (expected '0' and " "CDERR_STRUCTSIZE)\n", res, GetLastError(), CommDlgExtendedError()); 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()); ZeroMemory(pDlg, sizeof(PRINTDLGA)); pDlg->lStructSize = sizeof(PRINTDLGA); pDlg->Flags = PD_RETURNDEFAULT; SetLastError(0xdeadbeef); res = PrintDlgA(pDlg); ok( res || (CommDlgExtendedError() == PDERR_NODEFAULTPRN), "returned %d with 0x%x and 0x%x (expected '!= 0' or '0' and " "PDERR_NODEFAULTPRN)\n", res, GetLastError(), CommDlgExtendedError()); 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); HeapFree(GetProcessHeap(), 0, pDlg); }
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]; int job_id; 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"); goto end; } GlobalFree(pd.hDevMode); GlobalFree(pd.hDevNames); ok(pd.hDC != NULL, "PrintDlg didn't return a DC.\n"); if (!(print_dc = pd.hDC)) goto end; 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; job_id = StartDocA(print_dc, &doc_info); ok(job_id > 0 || GetLastError() == ERROR_SPL_NO_STARTDOC, /* Vista can fail with this error when using the XPS driver */ "StartDocA failed ret %d gle %d\n", job_id, GetLastError()); if(job_id <= 0) { skip("StartDoc failed\n"); goto end; } /* StartDoc may or may not call abort proc */ 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; /* following functions sometimes call abort proc too */ ok(FillRect(print_dc, &rect, (HBRUSH)(COLOR_BACKGROUND + 1)), "FillRect failed\n"); ok(EndPage(print_dc) > 0, "EndPage failed\n"); ok(EndDoc(print_dc) > 0, "EndDoc failed\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; end: SetLastError(0xdeadbeef); if(!DeleteFileA(filename)) trace("Failed to delete temporary file (err = %x)\n", GetLastError()); }
static void test_PrintDlgExW(void) { PRINTPAGERANGE pagerange[2]; LPPRINTDLGEXW pDlg; DEVNAMES *dn; HRESULT res; /* PrintDlgEx not present before w2k */ if (!pPrintDlgExW) { skip("PrintDlgExW not available\n"); return; } /* Set CommDlgExtendedError != 0 */ PrintDlgA(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; PrintDlgA(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; PrintDlgA(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()); /* nStartPage must be START_PAGE_GENERAL for the general page or a valid property sheet index */ ZeroMemory(pDlg, sizeof(PRINTDLGEXW)); pDlg->lStructSize = sizeof(PRINTDLGEXW); pDlg->hwndOwner = GetDesktopWindow(); pDlg->Flags = PD_RETURNDEFAULT | PD_NOWARNING | PD_NOPAGENUMS; res = pPrintDlgExW(pDlg); ok((res == E_INVALIDARG), "got 0x%x (expected 'E_INVALIDARG')\n", res); /* Use PD_NOPAGENUMS or set nMaxPageRanges and lpPageRanges */ ZeroMemory(pDlg, sizeof(PRINTDLGEXW)); pDlg->lStructSize = sizeof(PRINTDLGEXW); pDlg->hwndOwner = GetDesktopWindow(); pDlg->Flags = PD_RETURNDEFAULT | PD_NOWARNING; pDlg->nStartPage = START_PAGE_GENERAL; res = pPrintDlgExW(pDlg); ok((res == E_INVALIDARG), "got 0x%x (expected 'E_INVALIDARG')\n", res); /* this is invalid: a valid lpPageRanges with 0 for nMaxPageRanges */ ZeroMemory(pDlg, sizeof(PRINTDLGEXW)); pDlg->lStructSize = sizeof(PRINTDLGEXW); pDlg->hwndOwner = GetDesktopWindow(); pDlg->Flags = PD_RETURNDEFAULT | PD_NOWARNING; pDlg->lpPageRanges = pagerange; pDlg->nStartPage = START_PAGE_GENERAL; res = pPrintDlgExW(pDlg); ok((res == E_INVALIDARG), "got 0x%x (expected 'E_INVALIDARG')\n", res); /* this is invalid: NULL for lpPageRanges with a valid nMaxPageRanges */ ZeroMemory(pDlg, sizeof(PRINTDLGEXW)); pDlg->lStructSize = sizeof(PRINTDLGEXW); pDlg->hwndOwner = GetDesktopWindow(); pDlg->Flags = PD_RETURNDEFAULT | PD_NOWARNING; pDlg->nMaxPageRanges = 1; pDlg->nStartPage = START_PAGE_GENERAL; res = pPrintDlgExW(pDlg); ok((res == E_INVALIDARG), "got 0x%x (expected 'E_INVALIDARG')\n", res); /* this works: lpPageRanges with a valid nMaxPageRanges */ ZeroMemory(pDlg, sizeof(PRINTDLGEXW)); pDlg->lStructSize = sizeof(PRINTDLGEXW); pDlg->hwndOwner = GetDesktopWindow(); pDlg->Flags = PD_RETURNDEFAULT | PD_NOWARNING; pDlg->nMaxPageRanges = 1; pDlg->lpPageRanges = pagerange; pDlg->nStartPage = START_PAGE_GENERAL; res = pPrintDlgExW(pDlg); if (res == E_FAIL) { skip("No printer configured.\n"); HeapFree(GetProcessHeap(), 0, pDlg); return; } ok(res == S_OK, "got 0x%x (expected S_OK)\n", res); dn = GlobalLock(pDlg->hDevNames); ok(dn != NULL, "expected '!= NULL' for GlobalLock(%p)\n",pDlg->hDevNames); if (dn) { ok(dn->wDriverOffset, "(expected '!= 0' for wDriverOffset)\n"); ok(dn->wDeviceOffset, "(expected '!= 0' for wDeviceOffset)\n"); ok(dn->wOutputOffset, "(expected '!= 0' for wOutputOffset)\n"); ok(dn->wDefault == DN_DEFAULTPRN, "got 0x%x (expected DN_DEFAULTPRN)\n", dn->wDefault); GlobalUnlock(pDlg->hDevNames); } GlobalFree(pDlg->hDevMode); GlobalFree(pDlg->hDevNames); /* this works also: PD_NOPAGENUMS */ ZeroMemory(pDlg, sizeof(PRINTDLGEXW)); pDlg->lStructSize = sizeof(PRINTDLGEXW); pDlg->hwndOwner = GetDesktopWindow(); pDlg->Flags = PD_RETURNDEFAULT | PD_NOWARNING | PD_NOPAGENUMS; pDlg->nStartPage = START_PAGE_GENERAL; res = pPrintDlgExW(pDlg); ok(res == S_OK, "got 0x%x (expected S_OK)\n", res); GlobalFree(pDlg->hDevMode); GlobalFree(pDlg->hDevNames); /* this works: PD_RETURNDC with PD_RETURNDEFAULT */ ZeroMemory(pDlg, sizeof(PRINTDLGEXW)); pDlg->lStructSize = sizeof(PRINTDLGEXW); pDlg->hwndOwner = GetDesktopWindow(); pDlg->Flags = PD_RETURNDEFAULT | PD_NOWARNING | PD_NOPAGENUMS | PD_RETURNDC; pDlg->nStartPage = START_PAGE_GENERAL; res = pPrintDlgExW(pDlg); ok(res == S_OK, "got 0x%x (expected S_OK)\n", res); ok(pDlg->hDC != NULL, "HDC missing for PD_RETURNDC\n"); GlobalFree(pDlg->hDevMode); GlobalFree(pDlg->hDevNames); DeleteDC(pDlg->hDC); /* this works: PD_RETURNIC with PD_RETURNDEFAULT */ ZeroMemory(pDlg, sizeof(PRINTDLGEXW)); pDlg->lStructSize = sizeof(PRINTDLGEXW); pDlg->hwndOwner = GetDesktopWindow(); pDlg->Flags = PD_RETURNDEFAULT | PD_NOWARNING | PD_NOPAGENUMS | PD_RETURNIC; pDlg->nStartPage = START_PAGE_GENERAL; res = pPrintDlgExW(pDlg); ok(res == S_OK, "got 0x%x (expected S_OK)\n", res); ok(pDlg->hDC != NULL, "HDC missing for PD_RETURNIC\n"); GlobalFree(pDlg->hDevMode); GlobalFree(pDlg->hDevNames); DeleteDC(pDlg->hDC); /* interactive PrintDlgEx tests */ if (!winetest_interactive) { skip("interactive PrintDlgEx tests (set WINETEST_INTERACTIVE=1)\n"); return; } ZeroMemory(pDlg, sizeof(PRINTDLGEXW)); pDlg->lStructSize = sizeof(PRINTDLGEXW); pDlg->hwndOwner = GetDesktopWindow(); pDlg->Flags = PD_NOPAGENUMS | PD_RETURNIC; pDlg->nStartPage = START_PAGE_GENERAL; pDlg->lpCallback = &unknown; pDlg->dwResultAction = S_OK; res = pPrintDlgExW(pDlg); ok(res == S_OK, "got 0x%x (expected S_OK)\n", res); ok(pDlg->dwResultAction == PD_RESULT_PRINT, "expected PD_RESULT_PRINT, got %#x\n", pDlg->dwResultAction); ok(pDlg->hDC != NULL, "HDC missing for PD_RETURNIC\n"); GlobalFree(pDlg->hDevMode); GlobalFree(pDlg->hDevNames); DeleteDC(pDlg->hDC); HeapFree(GetProcessHeap(), 0, pDlg); }
static void test_PrintDlgA(void) { DWORD res, n_copies = 0; LPPRINTDLGA pDlg; DEVNAMES *pDevNames; LPCSTR driver; LPCSTR device; LPCSTR port; CHAR buffer[MAX_PATH]; LPSTR ptr; DEVMODEA *dm; 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), "returned %d with 0x%x and 0x%x (expected '0' and " "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), "returned %d with 0x%x and 0x%x (expected '0' and " "CDERR_STRUCTSIZE)\n", res, GetLastError(), CommDlgExtendedError()); 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()); ZeroMemory(pDlg, sizeof(PRINTDLGA)); pDlg->lStructSize = sizeof(PRINTDLGA); pDlg->Flags = PD_RETURNDEFAULT; SetLastError(0xdeadbeef); res = PrintDlgA(pDlg); ok( res || (CommDlgExtendedError() == PDERR_NODEFAULTPRN), "returned %d with 0x%x and 0x%x (expected '!= 0' or '0' and " "PDERR_NODEFAULTPRN)\n", res, GetLastError(), CommDlgExtendedError()); 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, '\\'); 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'; ok( lstrcmpiA(driver, buffer) == 0, "got driver '%s' (expected '%s')\n", driver, buffer); n_copies = DeviceCapabilitiesA(device, port, DC_COPIES, NULL, NULL); ok(n_copies > 0, "DeviceCapabilities(DC_COPIES) failed\n"); } GlobalUnlock(pDlg->hDevNames); GlobalFree(pDlg->hDevMode); GlobalFree(pDlg->hDevNames); /* if device doesn't support printing of multiple copies then * an attempt to set number of copies > 1 in print dialog would * cause the PrintDlg under Windows display the MessageBox and * the test will hang waiting for user response. */ if (n_copies > 1) { ZeroMemory(pDlg, sizeof(*pDlg)); pDlg->lStructSize = sizeof(*pDlg); pDlg->Flags = PD_ENABLEPRINTHOOK; pDlg->lpfnPrintHook = print_hook_proc; res = PrintDlgA(pDlg); ok(res, "PrintDlg error %#x\n", CommDlgExtendedError()); /* Version of Microsoft XPS Document Writer driver shipped before Win7 * reports that it can print multiple copies, but returns 1. */ ok(pDlg->nCopies == 123 || broken(pDlg->nCopies == 1), "expected nCopies 123, got %d\n", pDlg->nCopies); ok(pDlg->hDevMode != 0, "hDevMode should not be 0\n"); dm = GlobalLock(pDlg->hDevMode); /* some broken drivers use always PD_USEDEVMODECOPIES */ ok((S1(U1(*dm)).dmCopies == 1) || broken(S1(U1(*dm)).dmCopies == 123), "expected dm->dmCopies 1, got %d\n", S1(U1(*dm)).dmCopies); GlobalUnlock(pDlg->hDevMode); GlobalFree(pDlg->hDevMode); GlobalFree(pDlg->hDevNames); ZeroMemory(pDlg, sizeof(*pDlg)); pDlg->lStructSize = sizeof(*pDlg); pDlg->Flags = PD_ENABLEPRINTHOOK | PD_USEDEVMODECOPIES; pDlg->lpfnPrintHook = print_hook_proc; res = PrintDlgA(pDlg); ok(res, "PrintDlg error %#x\n", CommDlgExtendedError()); ok(pDlg->nCopies == 1, "expected nCopies 1, got %d\n", pDlg->nCopies); ok(pDlg->hDevMode != 0, "hDevMode should not be 0\n"); dm = GlobalLock(pDlg->hDevMode); ok(S1(U1(*dm)).dmCopies == 123, "expected dm->dmCopies 123, got %d\n", S1(U1(*dm)).dmCopies); GlobalUnlock(pDlg->hDevMode); GlobalFree(pDlg->hDevMode); GlobalFree(pDlg->hDevNames); } HeapFree(GetProcessHeap(), 0, pDlg); }