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',' ',
'i','l','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 deviceW[] = {'d','e','v','i','c','e',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};
......@@ -3114,66 +3117,102 @@ BOOL WINAPI EnumPortsA(LPSTR name,DWORD level,LPBYTE buffer,DWORD bufsize,
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;
}
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
* size even if the extern buffer is to small or not given.
* (20 for ,driver,port) */
insize = *namesize;
len = max(100, (insize + 20));
buffer = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR));
if (!GetProfileStringW(windowsW, deviceW, emptyStringW, buffer, len))
{
SetLastError (ERROR_FILE_NOT_FOUND);
return FALSE;
retval = FALSE;
goto end;
}
TRACE("%s\n", debugstr_w(buffer));
if ((ptr = strchr (name, ',')) == NULL)
if ((ptr = strchrW(buffer, ',')) == NULL)
{
SetLastError (ERROR_FILE_NOT_FOUND);
return FALSE;
SetLastError(ERROR_INVALID_NAME);
retval = FALSE;
goto end;
}
*ptr = '\0';
*namesize = strlen (name) + 1;
return TRUE;
*ptr = 0;
*namesize = strlenW(buffer) + 1;
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 ret;
BOOL retval = TRUE;
DWORD insize = 0;
WCHAR *bufferW = NULL;
if (*namesize < 1)
if (!namesize)
{
SetLastError (ERROR_INSUFFICIENT_BUFFER);
SetLastError(ERROR_INVALID_PARAMETER);
return FALSE;
}
buf = HeapAlloc (GetProcessHeap (), 0, *namesize);
ret = GetDefaultPrinterA (buf, namesize);
if (ret)
{
DWORD len = MultiByteToWideChar (CP_ACP, 0, buf, -1, name, *namesize);
if (!len)
{
SetLastError (ERROR_INSUFFICIENT_BUFFER);
ret = FALSE;
if(name && *namesize) {
insize = *namesize;
bufferW = HeapAlloc( GetProcessHeap(), 0, insize * sizeof(WCHAR));
}
else *namesize = len;
if(!GetDefaultPrinterW( bufferW, namesize)) {
retval = FALSE;
goto end;
}
HeapFree (GetProcessHeap (), 0, buf);
return ret;
*namesize = WideCharToMultiByte(CP_ACP, 0, bufferW, -1, name, insize,
NULL, NULL);
if (!*namesize)
{
*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
* modify it under the terms of the GNU Lesser General Public
......@@ -25,7 +25,91 @@
#include "wingdi.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;
DWORD cbBuf, pcbNeeded;
BOOL res;
......@@ -79,5 +163,6 @@ static void test_printer_directory(ivoid)
START_TEST(info)
{
test_default_printer();
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