1 /* 2 * PROJECT: ReactOS Print Spooler DLL API Tests 3 * LICENSE: GPL-2.0+ (https://spdx.org/licenses/GPL-2.0+) 4 * PURPOSE: Tests for GetPrintProcessorDirectoryA/GetPrintProcessorDirectoryW 5 * COPYRIGHT: Copyright 2015-2016 Colin Finck (colin@reactos.org) 6 */ 7 8 #include <apitest.h> 9 10 #define WIN32_NO_STATUS 11 #include <windef.h> 12 #include <winbase.h> 13 #include <wingdi.h> 14 #include <winspool.h> 15 16 START_TEST(GetPrintProcessorDirectoryA) 17 { 18 DWORD cbNeeded; 19 DWORD cbTemp; 20 PSTR pszBuffer; 21 22 // Try with an invalid level, this needs to be caught first. 23 SetLastError(0xDEADBEEF); 24 cbNeeded = 0xDEADBEEF; 25 ok(!GetPrintProcessorDirectoryA(NULL, NULL, 0, NULL, 0, &cbNeeded), "GetPrintProcessorDirectoryA returns TRUE!\n"); 26 ok(GetLastError() == ERROR_INVALID_LEVEL, "GetPrintProcessorDirectoryA returns error %lu!\n", GetLastError()); 27 ok(cbNeeded == 0xDEADBEEF, "cbNeeded is %lu!\n", cbNeeded); 28 29 // Now try with valid level, but no pcbNeeded. 30 SetLastError(0xDEADBEEF); 31 ok(!GetPrintProcessorDirectoryA(NULL, NULL, 1, NULL, 0, NULL), "GetPrintProcessorDirectoryA returns TRUE!\n"); 32 ok(GetLastError() == RPC_X_NULL_REF_POINTER, "GetPrintProcessorDirectoryA returns error %lu!\n", GetLastError()); 33 34 // Try with an invalid environment as well. 35 SetLastError(0xDEADBEEF); 36 cbNeeded = 0xDEADBEEF; 37 ok(!GetPrintProcessorDirectoryA(NULL, "invalid", 1, NULL, 0, &cbNeeded), "GetPrintProcessorDirectoryA returns TRUE!\n"); 38 ok(GetLastError() == ERROR_INVALID_ENVIRONMENT, "GetPrintProcessorDirectoryA returns error %lu!\n", GetLastError()); 39 ok(cbNeeded == 0, "cbNeeded is %lu!\n", cbNeeded); 40 41 // Now get the required buffer size by supplying pcbNeeded. This needs to fail with ERROR_INSUFFICIENT_BUFFER. 42 // Note for GetPrintProcessorDirectoryA: cbNeeded will be the same as for GetPrintProcessorDirectoryW, even though the ANSI string only needs half of it! 43 SetLastError(0xDEADBEEF); 44 cbNeeded = 0; 45 ok(!GetPrintProcessorDirectoryA(NULL, NULL, 1, NULL, 0, &cbNeeded), "GetPrintProcessorDirectoryA returns TRUE!\n"); 46 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "GetPrintProcessorDirectoryA returns error %lu!\n", GetLastError()); 47 ok(cbNeeded > 0, "cbNeeded is 0!\n"); 48 49 // Now provide the demanded size, but no buffer. 50 SetLastError(0xDEADBEEF); 51 cbTemp = 0xDEADBEEF; 52 ok(!GetPrintProcessorDirectoryA(NULL, NULL, 1, NULL, cbNeeded, &cbTemp), "GetPrintProcessorDirectoryA returns TRUE!\n"); 53 ok(GetLastError() == ERROR_INVALID_USER_BUFFER, "GetPrintProcessorDirectoryA returns error %lu!\n", GetLastError()); 54 ok(cbTemp == 0, "cbTemp is %lu!\n", cbTemp); 55 56 // Same error has to occur with a size too small. 57 SetLastError(0xDEADBEEF); 58 cbTemp = 0xDEADBEEF; 59 ok(!GetPrintProcessorDirectoryA(NULL, NULL, 1, NULL, 1, &cbTemp), "GetPrintProcessorDirectoryA returns TRUE!\n"); 60 ok(GetLastError() == ERROR_INVALID_USER_BUFFER, "GetPrintProcessorDirectoryA returns error %lu!\n", GetLastError()); 61 ok(cbTemp == 0, "cbTemp is %lu!\n", cbTemp); 62 63 // Finally use the function as intended and aim for success! 64 pszBuffer = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, cbNeeded); 65 SetLastError(0xDEADBEEF); 66 ok(GetPrintProcessorDirectoryA(NULL, NULL, 1, (PBYTE)pszBuffer, cbNeeded, &cbTemp), "GetPrintProcessorDirectoryA returns FALSE!\n"); 67 ok(GetLastError() == ERROR_SUCCESS, "GetPrintProcessorDirectoryA returns error %lu!\n", GetLastError()); 68 69 // Note for GetPrintProcessorDirectoryA: cbNeeded is the same as for GetPrintProcessorDirectoryW! 70 ok(strlen(pszBuffer) == cbNeeded / sizeof(WCHAR) - 1, "GetPrintProcessorDirectoryA string is %Iu characters long, but %lu characters expected!\n", strlen(pszBuffer), cbNeeded / sizeof(WCHAR) - 1); 71 HeapFree(GetProcessHeap(), 0, pszBuffer); 72 } 73 74 START_TEST(GetPrintProcessorDirectoryW) 75 { 76 DWORD cbNeeded; 77 DWORD cbTemp; 78 PWSTR pwszBuffer; 79 80 // Try with an invalid level, this needs to be caught first. 81 SetLastError(0xDEADBEEF); 82 cbNeeded = 0xDEADBEEF; 83 ok(!GetPrintProcessorDirectoryW(NULL, NULL, 0, NULL, 0, &cbNeeded), "GetPrintProcessorDirectoryW returns TRUE!\n"); 84 ok(GetLastError() == ERROR_INVALID_LEVEL, "GetPrintProcessorDirectoryW returns error %lu!\n", GetLastError()); 85 ok(cbNeeded == 0xDEADBEEF, "cbNeeded is %lu!\n", cbNeeded); 86 87 // Now try with valid level, but no pcbNeeded. 88 SetLastError(0xDEADBEEF); 89 ok(!GetPrintProcessorDirectoryW(NULL, NULL, 1, NULL, 0, NULL), "GetPrintProcessorDirectoryW returns TRUE!\n"); 90 ok(GetLastError() == RPC_X_NULL_REF_POINTER, "GetPrintProcessorDirectoryW returns error %lu!\n", GetLastError()); 91 92 // Try with an invalid environment as well. 93 SetLastError(0xDEADBEEF); 94 cbNeeded = 0xDEADBEEF; 95 ok(!GetPrintProcessorDirectoryW(NULL, L"invalid", 1, NULL, 0, &cbNeeded), "GetPrintProcessorDirectoryW returns TRUE!\n"); 96 ok(GetLastError() == ERROR_INVALID_ENVIRONMENT, "GetPrintProcessorDirectoryW returns error %lu!\n", GetLastError()); 97 ok(cbNeeded == 0, "cbNeeded is %lu!\n", cbNeeded); 98 99 // Now get the required buffer size by supplying pcbNeeded. This needs to fail with ERROR_INSUFFICIENT_BUFFER. 100 SetLastError(0xDEADBEEF); 101 cbNeeded = 0; 102 ok(!GetPrintProcessorDirectoryW(NULL, NULL, 1, NULL, 0, &cbNeeded), "GetPrintProcessorDirectoryW returns TRUE!\n"); 103 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "GetPrintProcessorDirectoryW returns error %lu!\n", GetLastError()); 104 ok(cbNeeded > 0, "cbNeeded is 0!\n"); 105 106 // Now provide the demanded size, but no buffer. 107 SetLastError(0xDEADBEEF); 108 cbTemp = 0xDEADBEEF; 109 ok(!GetPrintProcessorDirectoryW(NULL, NULL, 1, NULL, cbNeeded, &cbTemp), "GetPrintProcessorDirectoryW returns TRUE!\n"); 110 ok(GetLastError() == ERROR_INVALID_USER_BUFFER, "GetPrintProcessorDirectoryW returns error %lu!\n", GetLastError()); 111 ok(cbTemp == 0, "cbTemp is %lu!\n", cbTemp); 112 113 // Same error has to occur with a size too small. 114 SetLastError(0xDEADBEEF); 115 cbTemp = 0xDEADBEEF; 116 ok(!GetPrintProcessorDirectoryW(NULL, NULL, 1, NULL, 1, &cbTemp), "GetPrintProcessorDirectoryW returns TRUE!\n"); 117 ok(GetLastError() == ERROR_INVALID_USER_BUFFER, "GetPrintProcessorDirectoryW returns error %lu!\n", GetLastError()); 118 ok(cbTemp == 0, "cbTemp is %lu!\n", cbTemp); 119 120 // Finally use the function as intended and aim for success! 121 pwszBuffer = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, cbNeeded); 122 SetLastError(0xDEADBEEF); 123 ok(GetPrintProcessorDirectoryW(NULL, NULL, 1, (PBYTE)pwszBuffer, cbNeeded, &cbTemp), "GetPrintProcessorDirectoryW returns FALSE!\n"); 124 ok(GetLastError() == ERROR_SUCCESS, "GetPrintProcessorDirectoryW returns error %lu!\n", GetLastError()); 125 ok(wcslen(pwszBuffer) == cbNeeded / sizeof(WCHAR) - 1, "GetPrintProcessorDirectoryW string is %Iu characters long, but %lu characters expected!\n", wcslen(pwszBuffer), cbNeeded / sizeof(WCHAR) - 1); 126 HeapFree(GetProcessHeap(), 0, pwszBuffer); 127 } 128