From: Colin Finck Date: Wed, 16 Nov 2016 08:54:54 +0000 (+0000) Subject: [WINSPOOL_APITEST] X-Git-Tag: ReactOS-0.4.4-FOSDEM2017~297 X-Git-Url: https://git.reactos.org/?p=reactos.git;a=commitdiff_plain;h=8f3b3eb6e236d6a9ba036cbafe6c161c7174997c [WINSPOOL_APITEST] Add tests for GetPrintProcessorDirectoryA and another one for GetPrintProcessorDirectoryW. Tested against Windows Server 2003 SP2. Step 1 for CORE-12399 svn path=/trunk/; revision=73238 --- diff --git a/rostests/apitests/winspool/GetPrintProcessorDirectory.c b/rostests/apitests/winspool/GetPrintProcessorDirectory.c index 04d76d2b6db..e764f0b879e 100644 --- a/rostests/apitests/winspool/GetPrintProcessorDirectory.c +++ b/rostests/apitests/winspool/GetPrintProcessorDirectory.c @@ -2,7 +2,7 @@ * PROJECT: ReactOS Print Spooler DLL API Tests * LICENSE: GNU GPLv2 or any later version as published by the Free Software Foundation * PURPOSE: Tests for GetPrintProcessorDirectoryA/GetPrintProcessorDirectoryW - * COPYRIGHT: Copyright 2015 Colin Finck + * COPYRIGHT: Copyright 2015-2016 Colin Finck */ #include @@ -13,7 +13,59 @@ #include #include -START_TEST(GetPrintProcessorDirectory) +START_TEST(GetPrintProcessorDirectoryA) +{ + DWORD cbNeeded; + DWORD cbTemp; + PSTR pszBuffer; + + // Try with an invalid level, this needs to be caught first. + SetLastError(0xDEADBEEF); + ok(!GetPrintProcessorDirectoryA(NULL, NULL, 0, NULL, 0, NULL), "GetPrintProcessorDirectoryA returns TRUE!\n"); + ok(GetLastError() == ERROR_INVALID_LEVEL, "GetPrintProcessorDirectoryA returns error %lu!\n", GetLastError()); + + // Now try with valid level, but no pcbNeeded. + SetLastError(0xDEADBEEF); + ok(!GetPrintProcessorDirectoryA(NULL, NULL, 1, NULL, 0, NULL), "GetPrintProcessorDirectoryA returns TRUE!\n"); + ok(GetLastError() == RPC_X_NULL_REF_POINTER, "GetPrintProcessorDirectoryA returns error %lu!\n", GetLastError()); + + // Try with an invalid environment as well. + SetLastError(0xDEADBEEF); + ok(!GetPrintProcessorDirectoryA(NULL, "invalid", 1, NULL, 0, &cbNeeded), "GetPrintProcessorDirectoryA returns TRUE!\n"); + ok(GetLastError() == ERROR_INVALID_ENVIRONMENT, "GetPrintProcessorDirectoryA returns error %lu!\n", GetLastError()); + ok(cbNeeded == 0, "cbNeeded is %lu!\n", cbNeeded); + + // Now get the required buffer size by supplying pcbNeeded. This needs to fail with ERROR_INSUFFICIENT_BUFFER. + // Note for GetPrintProcessorDirectoryA: cbNeeded will be the same as for GetPrintProcessorDirectoryW, even though the ANSI string only needs half of it! + SetLastError(0xDEADBEEF); + ok(!GetPrintProcessorDirectoryA(NULL, NULL, 1, NULL, 0, &cbNeeded), "GetPrintProcessorDirectoryA returns TRUE!\n"); + ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "GetPrintProcessorDirectoryA returns error %lu!\n", GetLastError()); + ok(cbNeeded > 0, "cbNeeded is 0!\n"); + + // Now provide the demanded size, but no buffer. + SetLastError(0xDEADBEEF); + ok(!GetPrintProcessorDirectoryA(NULL, NULL, 1, NULL, cbNeeded, &cbTemp), "GetPrintProcessorDirectoryA returns TRUE!\n"); + ok(GetLastError() == ERROR_INVALID_USER_BUFFER, "GetPrintProcessorDirectoryA returns error %lu!\n", GetLastError()); + ok(cbTemp == 0, "cbNeeded is %lu!\n", cbNeeded); + + // Same error has to occur with a size too small. + SetLastError(0xDEADBEEF); + ok(!GetPrintProcessorDirectoryA(NULL, NULL, 1, NULL, 1, &cbTemp), "GetPrintProcessorDirectoryA returns TRUE!\n"); + ok(GetLastError() == ERROR_INVALID_USER_BUFFER, "GetPrintProcessorDirectoryA returns error %lu!\n", GetLastError()); + ok(cbTemp == 0, "cbNeeded is %lu!\n", cbNeeded); + + // Finally use the function as intended and aim for success! + pszBuffer = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, cbNeeded); + SetLastError(0xDEADBEEF); + ok(GetPrintProcessorDirectoryA(NULL, NULL, 1, (PBYTE)pszBuffer, cbNeeded, &cbTemp), "GetPrintProcessorDirectoryA returns FALSE!\n"); + ok(GetLastError() == ERROR_SUCCESS, "GetPrintProcessorDirectoryA returns error %lu!\n", GetLastError()); + + // Note for GetPrintProcessorDirectoryA: cbNeeded is the same as for GetPrintProcessorDirectoryW! + ok(strlen(pszBuffer) == cbNeeded / sizeof(WCHAR) - 1, "GetPrintProcessorDirectoryA string is %Iu characters long, but %lu characters expected!\n", strlen(pszBuffer), cbNeeded / sizeof(WCHAR) - 1); + HeapFree(GetProcessHeap(), 0, pszBuffer); +} + +START_TEST(GetPrintProcessorDirectoryW) { DWORD cbNeeded; DWORD cbTemp; @@ -54,9 +106,10 @@ START_TEST(GetPrintProcessorDirectory) ok(cbTemp == 0, "cbNeeded is %lu!\n", cbNeeded); // Finally use the function as intended and aim for success! - pwszBuffer = HeapAlloc(GetProcessHeap(), 0, cbNeeded); + pwszBuffer = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, cbNeeded); SetLastError(0xDEADBEEF); - ok(GetPrintProcessorDirectoryW(NULL, NULL, 1, (PBYTE)pwszBuffer, cbNeeded, &cbNeeded), "GetPrintProcessorDirectoryW returns FALSE!\n"); + ok(GetPrintProcessorDirectoryW(NULL, NULL, 1, (PBYTE)pwszBuffer, cbNeeded, &cbTemp), "GetPrintProcessorDirectoryW returns FALSE!\n"); ok(GetLastError() == ERROR_SUCCESS, "GetPrintProcessorDirectoryW returns error %lu!\n", GetLastError()); + ok(wcslen(pwszBuffer) == cbNeeded / sizeof(WCHAR) - 1, "GetPrintProcessorDirectoryW string is %Iu characters long, but %lu characters expected!\n", wcslen(pwszBuffer), cbNeeded / sizeof(WCHAR) - 1); HeapFree(GetProcessHeap(), 0, pwszBuffer); } diff --git a/rostests/apitests/winspool/testlist.c b/rostests/apitests/winspool/testlist.c index 189eb7ce84e..3cc417434f7 100644 --- a/rostests/apitests/winspool/testlist.c +++ b/rostests/apitests/winspool/testlist.c @@ -13,7 +13,8 @@ extern void func_ClosePrinter(void); extern void func_EnumPrinters(void); extern void func_EnumPrintProcessorDatatypes(void); -extern void func_GetPrintProcessorDirectory(void); +extern void func_GetPrintProcessorDirectoryA(void); +extern void func_GetPrintProcessorDirectoryW(void); extern void func_IsValidDevmodeA(void); extern void func_IsValidDevmodeW(void); extern void func_OpenPrinter(void); @@ -24,7 +25,8 @@ const struct test winetest_testlist[] = { "ClosePrinter", func_ClosePrinter }, { "EnumPrinters", func_EnumPrinters }, { "EnumPrintProcessorDatatypes", func_EnumPrintProcessorDatatypes }, - { "GetPrintProcessorDirectory", func_GetPrintProcessorDirectory }, + { "GetPrintProcessorDirectoryA", func_GetPrintProcessorDirectoryA }, + { "GetPrintProcessorDirectoryW", func_GetPrintProcessorDirectoryW }, { "IsValidDevmodeA", func_IsValidDevmodeA }, { "IsValidDevmodeW", func_IsValidDevmodeW }, { "OpenPrinter", func_OpenPrinter },