Commit 03210d44 authored by Stefan Leichter's avatar Stefan Leichter Committed by Alexandre Julliard

Moved implementation of GetDefaultPrinter from ascii to unicode, added

tests for GetDefaultPrinterA.
parent b859a686
...@@ -101,7 +101,10 @@ static const WCHAR Separator_FileW[] = {'S','e','p','a','r','a','t','o','r',' ', ...@@ -101,7 +101,10 @@ static const WCHAR Separator_FileW[] = {'S','e','p','a','r','a','t','o','r',' ',
'i','l','e',0}; 'i','l','e',0};
static const WCHAR Share_NameW[] = {'S','h','a','r','e',' ','N','a','m','e',0}; static const WCHAR Share_NameW[] = {'S','h','a','r','e',' ','N','a','m','e',0};
static const WCHAR WinPrintW[] = {'W','i','n','P','r','i','n','t',0}; static const WCHAR WinPrintW[] = {'W','i','n','P','r','i','n','t',0};
static const WCHAR deviceW[] = {'d','e','v','i','c','e',0};
static const WCHAR devicesW[] = {'d','e','v','i','c','e','s',0}; static const WCHAR devicesW[] = {'d','e','v','i','c','e','s',0};
static const WCHAR windowsW[] = {'w','i','n','d','o','w','s',0};
static const WCHAR emptyStringW[] = {0};
static const WCHAR May_Delete_Value[] = {'W','i','n','e','M','a','y','D','e','l','e','t','e','M','e',0}; static const WCHAR May_Delete_Value[] = {'W','i','n','e','M','a','y','D','e','l','e','t','e','M','e',0};
...@@ -3114,66 +3117,102 @@ BOOL WINAPI EnumPortsA(LPSTR name,DWORD level,LPBYTE buffer,DWORD bufsize, ...@@ -3114,66 +3117,102 @@ BOOL WINAPI EnumPortsA(LPSTR name,DWORD level,LPBYTE buffer,DWORD bufsize,
return TRUE; return TRUE;
} }
/****************************************************************************** /******************************************************************************
* GetDefaultPrinterA (WINSPOOL.@) * GetDefaultPrinterW (WINSPOOL.@)
*
* FIXME
* This function must read the value from data 'device' of key
* HCU\\Software\\Microsoft\\Windows NT\\CurrentVersion\\Windows
*/ */
BOOL WINAPI GetDefaultPrinterA(LPSTR name, LPDWORD namesize) BOOL WINAPI GetDefaultPrinterW(LPWSTR name, LPDWORD namesize)
{ {
char *ptr; BOOL retval = TRUE;
DWORD insize, len;
WCHAR *buffer, *ptr;
if (*namesize < 1) if (!namesize)
{ {
SetLastError (ERROR_INSUFFICIENT_BUFFER); SetLastError(ERROR_INVALID_PARAMETER);
return FALSE; return FALSE;
} }
if (!GetProfileStringA ("windows", "device", "", name, *namesize)) /* make the buffer big enough for the stuff from the profile/registry,
{ * the content must fit into the local buffer to compute the correct
SetLastError (ERROR_FILE_NOT_FOUND); * size even if the extern buffer is to small or not given.
return FALSE; * (20 for ,driver,port) */
} insize = *namesize;
len = max(100, (insize + 20));
buffer = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR));
if ((ptr = strchr (name, ',')) == NULL) if (!GetProfileStringW(windowsW, deviceW, emptyStringW, buffer, len))
{ {
SetLastError (ERROR_FILE_NOT_FOUND); SetLastError (ERROR_FILE_NOT_FOUND);
return FALSE; retval = FALSE;
} goto end;
}
TRACE("%s\n", debugstr_w(buffer));
if ((ptr = strchrW(buffer, ',')) == NULL)
{
SetLastError(ERROR_INVALID_NAME);
retval = FALSE;
goto end;
}
*ptr = '\0'; *ptr = 0;
*namesize = strlen (name) + 1; *namesize = strlenW(buffer) + 1;
return TRUE; if(!name || (*namesize > insize))
{
SetLastError(ERROR_INSUFFICIENT_BUFFER);
retval = FALSE;
goto end;
}
strcpyW(name, buffer);
end:
if(buffer) HeapFree( GetProcessHeap(), 0, buffer);
return retval;
} }
/****************************************************************************** /******************************************************************************
* GetDefaultPrinterW (WINSPOOL.@) * GetDefaultPrinterA (WINSPOOL.@)
*/ */
BOOL WINAPI GetDefaultPrinterW(LPWSTR name, LPDWORD namesize) BOOL WINAPI GetDefaultPrinterA(LPSTR name, LPDWORD namesize)
{ {
char *buf; BOOL retval = TRUE;
BOOL ret; DWORD insize = 0;
WCHAR *bufferW = NULL;
if (*namesize < 1)
{ if (!namesize)
SetLastError (ERROR_INSUFFICIENT_BUFFER); {
return FALSE; SetLastError(ERROR_INVALID_PARAMETER);
} return FALSE;
}
buf = HeapAlloc (GetProcessHeap (), 0, *namesize);
ret = GetDefaultPrinterA (buf, namesize); if(name && *namesize) {
if (ret) insize = *namesize;
{ bufferW = HeapAlloc( GetProcessHeap(), 0, insize * sizeof(WCHAR));
DWORD len = MultiByteToWideChar (CP_ACP, 0, buf, -1, name, *namesize); }
if (!len)
{ if(!GetDefaultPrinterW( bufferW, namesize)) {
SetLastError (ERROR_INSUFFICIENT_BUFFER); retval = FALSE;
ret = FALSE; goto end;
} }
else *namesize = len;
} *namesize = WideCharToMultiByte(CP_ACP, 0, bufferW, -1, name, insize,
NULL, NULL);
HeapFree (GetProcessHeap (), 0, buf); if (!*namesize)
return ret; {
*namesize = WideCharToMultiByte(CP_ACP, 0, bufferW, -1, NULL, 0, NULL, NULL);
retval = FALSE;
}
TRACE("0x%08lx/0x%08lx:%s\n", *namesize, insize, debugstr_w(bufferW));
end:
if(bufferW) HeapFree( GetProcessHeap(), 0, bufferW);
return retval;
} }
......
/* /*
* Copyright (C) 2003 Stefan Leichter * Copyright (C) 2003, 2004 Stefan Leichter
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
...@@ -25,7 +25,91 @@ ...@@ -25,7 +25,91 @@
#include "wingdi.h" #include "wingdi.h"
#include "winspool.h" #include "winspool.h"
static void test_printer_directory(ivoid) static void test_default_printer(void)
{
#define DEFAULT_PRINTER_SIZE 1000
BOOL retval;
DWORD exact = DEFAULT_PRINTER_SIZE;
DWORD size;
FARPROC func = NULL;
HMODULE lib = NULL;
char buffer[DEFAULT_PRINTER_SIZE];
lib = GetModuleHandleA("winspool.drv");
if (!lib) {
ok( 0, "GetModuleHandleA(\"winspool.drv\") failed\n");
return;
}
func = GetProcAddress( lib, "GetDefaultPrinterA");
if (!func)
/* only supported on NT like OSes starting with win2k */
return;
retval = func( buffer, &exact);
if (ERROR_FILE_NOT_FOUND == GetLastError()) {
ok( 0, "this test requires a default printer to be set\n");
return;
}
if (!retval || !exact || !strlen(buffer)) {
ok( 0, "function call GetDefaultPrinterA failed unexpected!\n"
"function returned %s\n"
"returned buffer size 0x%08lx\n"
"returned buffer content %s\n",
retval ? "true" : "false", exact, buffer);
return;
}
SetLastError(ERROR_SUCCESS);
retval = func( NULL, NULL);
ok( !retval, "function result wrong! False expected\n");
ok( ERROR_INVALID_PARAMETER == GetLastError(),
"Last error wrong! ERROR_INVALID_PARAMETER expected, got 0x%08lx\n",
GetLastError());
SetLastError(ERROR_SUCCESS);
retval = func( buffer, NULL);
ok( !retval, "function result wrong! False expected\n");
ok( ERROR_INVALID_PARAMETER == GetLastError(),
"Last error wrong! ERROR_INVALID_PARAMETER expected, got 0x%08lx\n",
GetLastError());
SetLastError(ERROR_SUCCESS);
size = 0;
retval = func( NULL, &size);
ok( !retval, "function result wrong! False expected\n");
ok( ERROR_INSUFFICIENT_BUFFER == GetLastError(),
"Last error wrong! ERROR_INSUFFICIENT_BUFFER expected, got 0x%08lx\n",
GetLastError());
ok( size == exact, "Parameter size wrong! %ld expected got %ld\n",
exact, size);
SetLastError(ERROR_SUCCESS);
size = DEFAULT_PRINTER_SIZE;
retval = func( NULL, &size);
ok( !retval, "function result wrong! False expected\n");
ok( ERROR_INSUFFICIENT_BUFFER == GetLastError(),
"Last error wrong! ERROR_INSUFFICIENT_BUFFER expected, got 0x%08lx\n",
GetLastError());
ok( size == exact, "Parameter size wrong! %ld expected got %ld\n",
exact, size);
size = 0;
retval = func( buffer, &size);
ok( !retval, "function result wrong! False expected\n");
ok( ERROR_INSUFFICIENT_BUFFER == GetLastError(),
"Last error wrong! ERROR_INSUFFICIENT_BUFFER expected, got 0x%08lx\n",
GetLastError());
ok( size == exact, "Parameter size wrong! %ld expected got %ld\n",
exact, size);
size = exact;
retval = func( buffer, &size);
ok( retval, "function result wrong! True expected\n");
ok( size == exact, "Parameter size wrong! %ld expected got %ld\n",
exact, size);
}
static void test_printer_directory(void)
{ LPBYTE buffer = NULL; { LPBYTE buffer = NULL;
DWORD cbBuf, pcbNeeded; DWORD cbBuf, pcbNeeded;
BOOL res; BOOL res;
...@@ -79,5 +163,6 @@ static void test_printer_directory(ivoid) ...@@ -79,5 +163,6 @@ static void test_printer_directory(ivoid)
START_TEST(info) START_TEST(info)
{ {
test_default_printer();
test_printer_directory(); test_printer_directory();
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment