2007-06-21 06:07:10 +02:00
|
|
|
/*
|
|
|
|
* Unit test suite for the Spooler Setup API (Printing)
|
|
|
|
*
|
|
|
|
* Copyright 2007 Detlef Riekenberg
|
|
|
|
*
|
|
|
|
* 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 <stdio.h>
|
|
|
|
|
|
|
|
#include "windef.h"
|
|
|
|
#include "winbase.h"
|
|
|
|
#include "winerror.h"
|
|
|
|
#include "wingdi.h"
|
|
|
|
#include "wine/test.h"
|
|
|
|
|
|
|
|
|
|
|
|
/* ##### */
|
|
|
|
|
|
|
|
static HMODULE hdll;
|
2017-01-27 17:33:13 +01:00
|
|
|
static HANDLE (WINAPI *pPSetupCreateMonitorInfo)(DWORD, const WCHAR *);
|
2007-06-21 06:07:10 +02:00
|
|
|
static VOID (WINAPI *pPSetupDestroyMonitorInfo)(HANDLE);
|
2007-06-22 00:31:55 +02:00
|
|
|
static BOOL (WINAPI *pPSetupEnumMonitor)(HANDLE, DWORD, LPWSTR, LPDWORD);
|
2007-06-21 06:07:10 +02:00
|
|
|
|
|
|
|
/* ########################### */
|
|
|
|
|
|
|
|
static LPCSTR load_functions(void)
|
|
|
|
{
|
|
|
|
LPCSTR ptr;
|
|
|
|
|
|
|
|
ptr = "ntprint.dll";
|
|
|
|
hdll = LoadLibraryA(ptr);
|
|
|
|
if (!hdll) return ptr;
|
|
|
|
|
|
|
|
ptr = "PSetupCreateMonitorInfo";
|
|
|
|
pPSetupCreateMonitorInfo = (VOID *) GetProcAddress(hdll, ptr);
|
|
|
|
if (!pPSetupCreateMonitorInfo) return ptr;
|
|
|
|
|
|
|
|
ptr = "PSetupDestroyMonitorInfo";
|
|
|
|
pPSetupDestroyMonitorInfo = (VOID *) GetProcAddress(hdll, ptr);
|
|
|
|
if (!pPSetupDestroyMonitorInfo) return ptr;
|
|
|
|
|
2007-06-22 00:31:55 +02:00
|
|
|
ptr = "PSetupEnumMonitor";
|
|
|
|
pPSetupEnumMonitor = (VOID *) GetProcAddress(hdll, ptr);
|
|
|
|
if (!pPSetupEnumMonitor) return ptr;
|
2007-06-21 06:07:10 +02:00
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ########################### */
|
|
|
|
|
|
|
|
static void test_PSetupCreateMonitorInfo(VOID)
|
|
|
|
{
|
|
|
|
HANDLE mi;
|
2017-01-27 17:33:13 +01:00
|
|
|
WCHAR buffer[1024] = {'\\','\\'};
|
2022-03-02 09:03:57 +01:00
|
|
|
DWORD len = ARRAY_SIZE(buffer) - 2;
|
2017-01-27 17:33:13 +01:00
|
|
|
GetComputerNameW(buffer + 2, &len);
|
2007-06-21 06:07:10 +02:00
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
2017-01-27 17:33:13 +01:00
|
|
|
mi = pPSetupCreateMonitorInfo(0, NULL);
|
2012-06-12 21:56:06 +02:00
|
|
|
if (!mi && (GetLastError() == RPC_S_SERVER_UNAVAILABLE)) {
|
2012-06-21 00:01:19 +02:00
|
|
|
win_skip("The service 'Spooler' is required for many tests\n");
|
2012-06-12 21:56:06 +02:00
|
|
|
return;
|
|
|
|
}
|
2022-03-02 09:04:03 +01:00
|
|
|
ok( mi != NULL, "got %p with %lu (expected '!= NULL')\n", mi, GetLastError());
|
2007-06-21 06:07:10 +02:00
|
|
|
if (mi) pPSetupDestroyMonitorInfo(mi);
|
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
2017-01-27 17:33:13 +01:00
|
|
|
mi = pPSetupCreateMonitorInfo(0, buffer);
|
2022-03-02 09:04:03 +01:00
|
|
|
ok( mi != NULL, "got %p with %lu (expected '!= NULL')\n", mi, GetLastError());
|
2007-06-21 06:07:10 +02:00
|
|
|
if (mi) pPSetupDestroyMonitorInfo(mi);
|
|
|
|
|
2017-01-27 17:33:13 +01:00
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
mi = pPSetupCreateMonitorInfo(0, buffer + 1);
|
|
|
|
todo_wine {
|
|
|
|
ok( mi == NULL, "got %p\n", mi );
|
2022-03-02 09:04:03 +01:00
|
|
|
ok( GetLastError() == ERROR_INVALID_NAME, "got %ld\n", GetLastError() );
|
2017-01-27 17:33:13 +01:00
|
|
|
}
|
|
|
|
if (mi) pPSetupDestroyMonitorInfo(mi);
|
2007-06-21 06:07:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* ########################### */
|
|
|
|
|
|
|
|
static void test_PSetupDestroyMonitorInfo(VOID)
|
|
|
|
{
|
|
|
|
HANDLE mi;
|
|
|
|
|
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
pPSetupDestroyMonitorInfo(NULL);
|
|
|
|
/* lasterror is returned */
|
2022-03-02 09:04:03 +01:00
|
|
|
trace("returned with %lu\n", GetLastError());
|
2007-06-21 06:07:10 +02:00
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
2017-01-27 17:33:13 +01:00
|
|
|
mi = pPSetupCreateMonitorInfo(0, NULL);
|
2012-06-12 21:56:06 +02:00
|
|
|
if (!mi && (GetLastError() == RPC_S_SERVER_UNAVAILABLE)) {
|
2012-06-21 00:01:19 +02:00
|
|
|
win_skip("The service 'Spooler' is required for many tests\n");
|
2012-06-12 21:56:06 +02:00
|
|
|
return;
|
|
|
|
}
|
2022-03-02 09:04:03 +01:00
|
|
|
ok( mi != NULL, "got %p with %lu (expected '!= NULL')\n", mi, GetLastError());
|
2007-06-21 06:07:10 +02:00
|
|
|
|
|
|
|
if (!mi) return;
|
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
pPSetupDestroyMonitorInfo(mi);
|
|
|
|
/* lasterror is returned */
|
2022-03-02 09:04:03 +01:00
|
|
|
trace("returned with %lu\n", GetLastError());
|
2007-06-21 06:07:10 +02:00
|
|
|
|
2012-06-21 00:01:19 +02:00
|
|
|
/* Trying to destroy the handle twice crashes with native ntprint.dll */
|
2007-06-21 06:07:10 +02:00
|
|
|
if (0) {
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
pPSetupDestroyMonitorInfo(mi);
|
2022-03-02 09:04:03 +01:00
|
|
|
trace(" with %lu\n", GetLastError());
|
2007-06-21 06:07:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ########################### */
|
|
|
|
|
2007-06-22 00:31:55 +02:00
|
|
|
static void test_PSetupEnumMonitor(VOID)
|
|
|
|
{
|
|
|
|
HANDLE mi;
|
|
|
|
WCHAR buffer[MAX_PATH+2];
|
|
|
|
DWORD minsize = 0;
|
|
|
|
DWORD size;
|
|
|
|
DWORD res;
|
|
|
|
DWORD index=0;
|
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
2017-01-27 17:33:13 +01:00
|
|
|
mi = pPSetupCreateMonitorInfo(0, NULL);
|
2007-06-22 00:31:55 +02:00
|
|
|
if (!mi) {
|
|
|
|
skip("PSetupCreateMonitorInfo\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
minsize = 0;
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
res = pPSetupEnumMonitor(mi, 0, NULL, &minsize);
|
|
|
|
ok( !res && (GetLastError() == ERROR_INSUFFICIENT_BUFFER) && (minsize > 0),
|
2022-03-02 09:04:03 +01:00
|
|
|
"got %lu with %lu and %lu (expected '0' with ERROR_INSUFFICIENT_BUFFER "
|
2007-06-22 00:31:55 +02:00
|
|
|
"and '> 0')\n", res, GetLastError(), minsize);
|
|
|
|
|
|
|
|
|
2018-06-08 22:19:07 +02:00
|
|
|
size = ARRAY_SIZE(buffer);
|
2007-06-22 00:31:55 +02:00
|
|
|
if ((minsize + 1) > size) {
|
2022-03-02 09:04:03 +01:00
|
|
|
skip("overflow: %lu\n", minsize);
|
2007-06-22 00:31:55 +02:00
|
|
|
pPSetupDestroyMonitorInfo(mi);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (0) {
|
|
|
|
/* XP: ERROR_INVALID_PARAMETER, w2k: Crash */
|
|
|
|
SetLastError(0xdeadbeef);
|
2018-06-08 22:19:07 +02:00
|
|
|
size = ARRAY_SIZE(buffer);
|
2007-06-22 00:31:55 +02:00
|
|
|
res = pPSetupEnumMonitor(NULL, 0, buffer, &size);
|
|
|
|
ok( !res && (GetLastError() == ERROR_INVALID_PARAMETER),
|
2022-03-02 09:04:03 +01:00
|
|
|
"got %lu with %lu (expected '0' with ERROR_INVALID_PARAMETER)\n",
|
2007-06-22 00:31:55 +02:00
|
|
|
res, GetLastError());
|
|
|
|
}
|
|
|
|
|
|
|
|
if (0) {
|
|
|
|
/* XP: Crash, w2k: Success (how can that work?) */
|
|
|
|
SetLastError(0xdeadbeef);
|
2018-06-08 22:19:07 +02:00
|
|
|
size = ARRAY_SIZE(buffer);
|
2007-06-22 00:31:55 +02:00
|
|
|
res = pPSetupEnumMonitor(mi, 0, NULL, &size);
|
2022-03-02 09:04:03 +01:00
|
|
|
trace("got %lu with %lu and %lu\n", res, GetLastError(), size);
|
2007-06-22 00:31:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (0) {
|
|
|
|
/* XP: ERROR_INVALID_PARAMETER, w2k: Crash */
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
res = pPSetupEnumMonitor(mi, 0, buffer, NULL);
|
|
|
|
ok( !res && (GetLastError() == ERROR_INVALID_PARAMETER),
|
2022-03-02 09:04:03 +01:00
|
|
|
"got %lu with %lu (expected '0' with ERROR_INVALID_PARAMETER)\n",
|
2007-06-22 00:31:55 +02:00
|
|
|
res, GetLastError());
|
|
|
|
}
|
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
size = minsize - 1;
|
|
|
|
res = pPSetupEnumMonitor(mi, 0, buffer, &size);
|
|
|
|
ok( !res && (GetLastError() == ERROR_INSUFFICIENT_BUFFER),
|
2022-03-02 09:04:03 +01:00
|
|
|
"got %lu with %lu and %lu (expected '0' with ERROR_INSUFFICIENT_BUFFER)\n",
|
2007-06-22 00:31:55 +02:00
|
|
|
res, GetLastError(), size);
|
|
|
|
|
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
size = minsize;
|
|
|
|
res = pPSetupEnumMonitor(mi, 0, buffer, &size);
|
2022-03-02 09:04:03 +01:00
|
|
|
ok( res, "got %lu with %lu and %lu (expected '!= 0')\n",
|
2007-06-22 00:31:55 +02:00
|
|
|
res, GetLastError(), size);
|
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
size = minsize + 1;
|
|
|
|
res = pPSetupEnumMonitor(mi, 0, buffer, &size);
|
2022-03-02 09:04:03 +01:00
|
|
|
ok( res, "got %lu with %lu and %lu (expected '!= 0')\n",
|
2007-06-22 00:31:55 +02:00
|
|
|
res, GetLastError(), size);
|
|
|
|
|
|
|
|
/* try max. 20 monitors */
|
|
|
|
while (res && (index < 20)) {
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
buffer[0] = '\0';
|
2018-06-08 22:19:07 +02:00
|
|
|
size = ARRAY_SIZE(buffer);
|
2007-06-22 00:31:55 +02:00
|
|
|
res = pPSetupEnumMonitor(mi, index, buffer, &size);
|
|
|
|
ok( res || (GetLastError() == ERROR_NO_MORE_ITEMS),
|
2022-03-02 09:04:03 +01:00
|
|
|
"(%lu) got %lu with %lu and %lu (expected '!=0' or: '0' with "
|
2007-06-22 00:31:55 +02:00
|
|
|
"ERROR_NO_MORE_ITEMS)\n", index, res, GetLastError(), size);
|
|
|
|
|
|
|
|
if (res) index++;
|
|
|
|
}
|
|
|
|
pPSetupDestroyMonitorInfo(mi);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ########################### */
|
|
|
|
|
2007-06-21 06:07:10 +02:00
|
|
|
START_TEST(ntprint)
|
|
|
|
{
|
2011-02-28 22:29:38 +01:00
|
|
|
load_functions();
|
2007-06-21 06:07:10 +02:00
|
|
|
|
|
|
|
test_PSetupCreateMonitorInfo();
|
|
|
|
test_PSetupDestroyMonitorInfo();
|
2007-06-22 00:31:55 +02:00
|
|
|
test_PSetupEnumMonitor();
|
2007-06-21 06:07:10 +02:00
|
|
|
|
|
|
|
}
|