getFieldOrder() {
+ return FIELDS;
+ }
+ }
+
+ /**
+ * The PRINTER_INFO_4 structure specifies general printer information.
+ *
+ * The structure can be used to retrieve minimal printer information on a
+ * call to EnumPrinters. Such a call is a fast and easy way to retrieve the
+ * names and attributes of all locally installed printers on a system and
+ * all remote printer connections that a user has established.
+ *
+ * @see
+ * PRINTER_INFO_4 structure
+ */
+ public static class PRINTER_INFO_4 extends Structure {
+
+ public static final List FIELDS = createFieldsOrder("pPrinterName", "pServerName", "Attributes");
+
+ /**
+ * Pointer to a null-terminated string that specifies the name of the
+ * printer (local or remote).
+ */
+ public String pPrinterName;
+ /**
+ * Pointer to a null-terminated string that is the name of the server.
+ */
+ public String pServerName;
+ /**
+ * Specifies information about the returned data.
+ */
+ public DWORD Attributes;
+
+ public PRINTER_INFO_4() {
super();
}
@@ -201,14 +434,37 @@ protected List getFieldOrder() {
}
}
- public class LPPRINTER_DEFAULTS extends Structure {
- public static final List FIELDS = createFieldsOrder("pDatatype", "pDevMode", "DesiredAccess");
-
- public String pDatatype;
- public PVOID pDevMode;
- public int DesiredAccess;
-
- @Override
+ /**
+ * The PRINTER_DEFAULTS structure specifies the default data type,
+ * environment, initialization data, and access rights for a printer.
+ *
+ * @see
+ * PRINTER_DEFAULTS structure
+ */
+ public class LPPRINTER_DEFAULTS extends Structure {
+
+ public static final List FIELDS = createFieldsOrder("pDatatype", "pDevMode", "DesiredAccess");
+
+ /**
+ * Pointer to a null-terminated string that specifies the default data
+ * type for a printer.
+ */
+ public String pDatatype;
+ /**
+ * Pointer to a DEVMODE structure that identifies the default
+ * environment and initialization data for a printer.
+ */
+ PVOID pDevMode;
+ /**
+ * Specifies desired access rights for a printer. The OpenPrinter
+ * function uses this member to set access rights to the printer. These
+ * rights can affect the operation of the SetPrinter and DeletePrinter
+ * functions.
+ */
+ int DesiredAccess;
+
+ @Override
protected List getFieldOrder() {
return FIELDS;
}
@@ -217,9 +473,7 @@ protected List getFieldOrder() {
/**
* The OpenPrinter function retrieves a handle to the specified printer or
* print server or other types of handles in the print subsystem.
- *
- * @see MSDN
- *
+ *
* @param pPrinterName
* [in] A pointer to a null-terminated string that specifies the
* name of the printer or print server, the printer object, the
@@ -239,15 +493,45 @@ protected List getFieldOrder() {
* be NULL.
* @return If the function succeeds, the return value is a nonzero value. If
* the function fails, the return value is zero.
- */
+ *
+ * @see
+ * OpenPrinter function
+ */
boolean OpenPrinter(
- // _In_
+ // _In_
String pPrinterName,
// _Out_
HANDLEByReference phPrinter,
// _In_
LPPRINTER_DEFAULTS pDefault);
+ /**
+ * The ClosePrinter function closes the specified printer object.
+ * Note This is a blocking or synchronous function and might not return
+ * immediately.
+ * How quickly this function returns depends on run-time factors such as
+ * network status, print server configuration, and printer driver
+ * implementation-factors that are difficult to predict when writing an
+ * application. Calling this function from a thread that manages interaction
+ * with the user interface could make the application appear to be
+ * unresponsive.
+ *
+ * When the ClosePrinter function returns, the handle hPrinter is invalid,
+ * regardless of whether the function has succeeded or failed.
+ *
+ * @param hPrinter
+ * A handle to the printer object to be closed. This handle is
+ * returned by the OpenPrinter or AddPrinter function.
+ * @return If the function succeeds, the return value is a nonzero value. If
+ * the function fails, the return value is zero.
+ *
+ * @see
+ * ClosePrinter function
+ */
+ boolean ClosePrinter(HANDLE hPrinter);
+
/**
* The FindFirstPrinterChangeNotification function creates a change
* notification object and returns a handle to the object. You can then use
@@ -261,9 +545,7 @@ boolean OpenPrinter(
* FindNextPrinterChangeNotification function to retrieve information about
* the change, and to reset the change notification object for use in the
* next wait operation.
- *
- * @see MSDN
- *
+ *
* @param hPrinter
* [in] A handle to the printer or print server that you want to
* monitor. Use the OpenPrinter or AddPrinter function to
@@ -273,12 +555,12 @@ boolean OpenPrinter(
* to enter a signaled state. A change notification occurs when
* one or more of the specified conditions are met. The fdwFilter
* parameter can be zero if pPrinterNotifyOptions is non-NULL.
- *
+ *
* @param fdwOptions
- * Reserved; must be zero.
- * @param pPrinterNotifyOptions
+ * Reserved; must be zero.
+ * @param pPrinterNotifyOptions
* [in, optional] A pointer to a PRINTER_NOTIFY_OPTIONS
- * structure. The pTypes member of this structure is an array of
+ * structure. The pTypes member of this structure is an array of
* one or more PRINTER_NOTIFY_OPTIONS_TYPE structures, each of which
* specifies a printer information field to monitor. A change
* notification occurs when one or more of the specified fields
@@ -287,14 +569,18 @@ boolean OpenPrinter(
* new printer information. This parameter can be NULL if
* fdwFilter is nonzero. For a list of fields that can be
* monitored, see PRINTER_NOTIFY_OPTIONS_TYPE.
- *
+ *
* @return If the function succeeds, the return value is a handle to a
* change notification object associated with the specified printer
* or print server. If the function fails, the return value is
* INVALID_HANDLE_VALUE.
- */
+ *
+ * @see
+ * FindFirstPrinterChangeNotification function
+ */
HANDLE FindFirstPrinterChangeNotification(
- // _In_
+ // _In_
HANDLE hPrinter, int fdwFilter, int fdwOptions,
// _In_opt_
LPVOID pPrinterNotifyOptions);
@@ -311,9 +597,7 @@ HANDLE FindFirstPrinterChangeNotification(
* changes occurs to the printer or print server. The
* FindFirstPrinterChangeNotification function creates the change
* notification object and specifies the set of changes to be monitored.
- *
- * @see MSDN
- *
+ *
* @param hChange
* [in] A handle to a change notification object associated with
* a printer or print server. You obtain such a handle by calling
@@ -328,7 +612,7 @@ HANDLE FindFirstPrinterChangeNotification(
* those specified in the fdwFilter parameter of the
* FindFirstPrinterChangeNotification call. The system sets one
* or more of the following bit flags.
- *
+ *
* @param pPrinterNotifyOptions
* [in, optional] A pointer to a PRINTER_NOTIFY_OPTIONS
* structure. Set the Flags member of this structure to
@@ -336,7 +620,7 @@ HANDLE FindFirstPrinterChangeNotification(
* return the current data for all monitored printer information
* fields. The function ignores all other members of the
* structure. This parameter can be NULL.
- *
+ *
* @param ppPrinterNotifyInfo
* [out, optional] A pointer to a pointer variable that receives
* a pointer to a system-allocated, read-only buffer. Call the
@@ -358,12 +642,16 @@ HANDLE FindFirstPrinterChangeNotification(
* no additional notifications will be sent until you make a
* second FindNextPrinterChangeNotification call that specifies
* PRINTER_NOTIFY_OPTIONS_REFRESH.
- *
+ *
* @return If the function succeeds, the return value is a nonzero value. If
* the function fails, the return value is zero.
- */
+ *
+ * @see
+ * FindClosePrinterChangeNotification function
+ */
boolean FindNextPrinterChangeNotification(
- // _In_
+ // _In_
HANDLE hChange,
// _Out_opt_
DWORDByReference pdwChange,
@@ -378,23 +666,65 @@ boolean FindNextPrinterChangeNotification(
* FindFirstPrinterChangeNotification function. The printer or print server
* associated with the change notification object will no longer be
* monitored by that object.
- *
- * @see MSDN
- *
+ *
* @param hChange
* [in] A handle to the change notification object to be closed.
* This is a handle created by calling the
* FindFirstPrinterChangeNotification function.
- *
+ *
* @return If the function succeeds, the return value is a nonzero value. If
* the function fails, the return value is zero.
- */
+ *
+ * @see
+ * FindClosePrinterChangeNotification function
+ */
boolean FindClosePrinterChangeNotification(
- // _In_
+ // _In_
HANDLE hChange);
+ /**
+ * The EnumJobs function retrieves information about a specified set of
+ * print jobs for a specified printer.
+ *
+ * @param hPrinter
+ * A handle to the printer object whose print jobs the function
+ * enumerates. Use the OpenPrinter or AddPrinter function to
+ * retrieve a printer handle.
+ * @param FirstJob
+ * The zero-based position within the print queue of the first
+ * print job to enumerate. For example, a value of 0 specifies
+ * that enumeration should begin at the first print job in the
+ * print queue; a value of 9 specifies that enumeration should
+ * begin at the tenth print job in the print queue.
+ * @param NoJobs
+ * The total number of print jobs to enumerate.
+ * @param Level
+ * The type of information returned in the pJob buffer.
+ * @param pJob
+ * A pointer to a buffer that receives an array of JOB_INFO_1,
+ * JOB_INFO_2, or JOB_INFO_3 structures. The buffer must be large
+ * enough to receive the array of structures and any strings or
+ * other data to which the structure members point.
+ * @param cbBuf
+ * The size, in bytes, of the pJob buffer.
+ * @param pcbNeeded
+ * A pointer to a variable that receives the number of bytes
+ * copied if the function succeeds. If the function fails, the
+ * variable receives the number of bytes required.
+ * @param pcReturned
+ * A pointer to a variable that receives the number of
+ * JOB_INFO_1, JOB_INFO_2, or JOB_INFO_3 structures returned in
+ * the pJob buffer.
+ * @return If the function succeeds, the return value is a nonzero value. If
+ * the function fails, the return value is zero.
+ *
+ * @see
+ * EnumJobs function
+ */
boolean EnumJobs(
- // _In_
+ // _In_
HANDLE hPrinter,
// _In_
int FirstJob,
@@ -411,31 +741,96 @@ boolean EnumJobs(
// _Out_
IntByReference pcReturned);
- public static class JOB_INFO_1 extends Structure {
- public static final List FIELDS = createFieldsOrder(
+ /**
+ * The JOB_INFO_1 structure specifies print-job information such as the
+ * job-identifier value, the name of the printer for which the job is
+ * spooled, the name of the machine that created the print job, the name of
+ * the user that owns the print job, and so on.
+ *
+ * @see
+ * JOB_INFO_1 structure
+ */
+ public static class JOB_INFO_1 extends Structure {
+
+ public static final List FIELDS = createFieldsOrder(
"JobId", "pPrinterName",
"pMachineName", "pUserName", "pDocument", "pDatatype",
"pStatus", "Status", "Priority", "Position", "TotalPages",
"PagesPrinted", "Submitted");
-
- public int JobId;
- public String pPrinterName;
- public String pMachineName;
- public String pUserName;
- public String pDocument;
- public String pDatatype;
- public String pStatus;
- public int Status;
- public int Priority;
- public int Position;
- public int TotalPages;
- public int PagesPrinted;
- public SYSTEMTIME Submitted;
-
- @Override
- protected List getFieldOrder() {
- return FIELDS;
- }
+
+ /**
+ * A job identifier.
+ */
+ public int JobId;
+ /**
+ * A pointer to a null-terminated string that specifies the name of the
+ * printer for which the job is spooled.
+ */
+ public String pPrinterName;
+ /**
+ * A pointer to a null-terminated string that specifies the name of the
+ * machine that created the print job.
+ */
+ public String pMachineName;
+ /**
+ * A pointer to a null-terminated string that specifies the name of the
+ * user that owns the print job.
+ */
+ public String pUserName;
+ /**
+ * A pointer to a null-terminated string that specifies the name of the
+ * print job (for example, "MS-WORD: Review.doc").
+ */
+ public String pDocument;
+ /**
+ * A pointer to a null-terminated string that specifies the type of data
+ * used to record the print job.
+ */
+ public String pDatatype;
+ /**
+ * A pointer to a null-terminated string that specifies the status of
+ * the print job. This member should be checked prior to Status and, if
+ * pStatus is NULL, the status is defined by the contents of the Status
+ * member.
+ */
+ public String pStatus;
+ /**
+ * The job status. The value of this member can be zero or a combination
+ * of one or more of the following values. A value of zero indicates
+ * that the print queue was paused after the document finished spooling.
+ */
+ public int Status;
+ /**
+ * The job priority. This member can be one of the following values or
+ * in the range between 1 through 99 (MIN_PRIORITY through
+ * MAX_PRIORITY).
+ */
+ public int Priority;
+ /**
+ * The job's position in the print queue.
+ */
+ public int Position;
+ /**
+ * The total number of pages that the document contains. This value may
+ * be zero if the print job does not contain page delimiting
+ * information.
+ */
+ public int TotalPages;
+ /**
+ * The number of pages that have printed. This value may be zero if the
+ * print job does not contain page delimiting information.
+ */
+ public int PagesPrinted;
+ /**
+ * A SYSTEMTIME structure that specifies the time that this document was
+ * spooled.
+ *
+ * This time value is in Universal Time Coordinate (UTC) format. You
+ * should convert it to a local time value before displaying it. You can
+ * use the FileTimeToLocalFileTime function to perform the conversion.
+ */
+ public SYSTEMTIME Submitted;
public JOB_INFO_1() {
super();
@@ -444,5 +839,10 @@ public JOB_INFO_1() {
public JOB_INFO_1(int size) {
super(new Memory(size));
}
+
+ @Override
+ protected List getFieldOrder() {
+ return FIELDS;
+ }
}
}
diff --git a/contrib/platform/src/com/sun/jna/platform/win32/WinspoolUtil.java b/contrib/platform/src/com/sun/jna/platform/win32/WinspoolUtil.java
index 9104e20280..15c9876bd6 100644
--- a/contrib/platform/src/com/sun/jna/platform/win32/WinspoolUtil.java
+++ b/contrib/platform/src/com/sun/jna/platform/win32/WinspoolUtil.java
@@ -15,13 +15,14 @@
import com.sun.jna.platform.win32.WinNT.HANDLEByReference;
import com.sun.jna.platform.win32.Winspool.JOB_INFO_1;
import com.sun.jna.platform.win32.Winspool.PRINTER_INFO_1;
+import com.sun.jna.platform.win32.Winspool.PRINTER_INFO_2;
import com.sun.jna.platform.win32.Winspool.PRINTER_INFO_4;
import com.sun.jna.ptr.IntByReference;
/**
* Winspool Utility API.
*
- * @author dblock[at]dblock.org
+ * @author dblock[at]dblock.org, Ivan Ridao Freitas, Padrus
*/
public abstract class WinspoolUtil {
@@ -45,6 +46,78 @@ public static PRINTER_INFO_1[] getPrinterInfo1() {
return (PRINTER_INFO_1[]) pPrinterEnum.toArray(pcReturned.getValue());
}
+
+ public static PRINTER_INFO_2[] getPrinterInfo2() {
+ return getPrinterInfo2(Winspool.PRINTER_ENUM_LOCAL);
+ }
+
+ /**
+ * Returns printers that are physically attached to the local machine as
+ * well as remote printers to which it has a network connection.
+ */
+ public static PRINTER_INFO_2[] getAllPrinterInfo2() {
+ // When Name is NULL, setting Flags to PRINTER_ENUM_LOCAL | PRINTER_ENUM_CONNECTIONS
+ // enumerates printers that are installed on the local machine.
+ // These printers include those that are physically attached to the local machine
+ // as well as remote printers to which it has a network connection.
+ // See https://msdn.microsoft.com/en-us/library/windows/desktop/dd162692(v=vs.85).aspx
+ return getPrinterInfo2(Winspool.PRINTER_ENUM_LOCAL | Winspool.PRINTER_ENUM_CONNECTIONS);
+ }
+
+ private static PRINTER_INFO_2[] getPrinterInfo2(int flags) {
+ IntByReference pcbNeeded = new IntByReference();
+ IntByReference pcReturned = new IntByReference();
+ Winspool.INSTANCE.EnumPrinters(flags, null, 2, null, 0, pcbNeeded, pcReturned);
+ if (pcbNeeded.getValue() <= 0)
+ return new PRINTER_INFO_2[0];
+
+ PRINTER_INFO_2 pPrinterEnum = new PRINTER_INFO_2(pcbNeeded.getValue());
+ if (!Winspool.INSTANCE.EnumPrinters(flags, null, 2, pPrinterEnum.getPointer(), pcbNeeded.getValue(), pcbNeeded,
+ pcReturned))
+ throw new Win32Exception(Kernel32.INSTANCE.GetLastError());
+
+ pPrinterEnum.read();
+ return (PRINTER_INFO_2[]) pPrinterEnum.toArray(pcReturned.getValue());
+ }
+
+ public static PRINTER_INFO_2 getPrinterInfo2(String printerName) {
+ IntByReference pcbNeeded = new IntByReference();
+ IntByReference pcReturned = new IntByReference();
+ HANDLEByReference pHandle = new HANDLEByReference();
+
+ if (!Winspool.INSTANCE.OpenPrinter(printerName, pHandle, null))
+ throw new Win32Exception(Kernel32.INSTANCE.GetLastError());
+
+ Win32Exception we = null;
+ PRINTER_INFO_2 pinfo2 = null;
+
+ try {
+ Winspool.INSTANCE.GetPrinter(pHandle.getValue(), 2, null, 0, pcbNeeded);
+ if (pcbNeeded.getValue() <= 0)
+ return new PRINTER_INFO_2();
+
+ pinfo2 = new PRINTER_INFO_2(pcbNeeded.getValue());
+ if (!Winspool.INSTANCE.GetPrinter(pHandle.getValue(), 2, pinfo2.getPointer(), pcbNeeded.getValue(), pcReturned))
+ throw new Win32Exception(Kernel32.INSTANCE.GetLastError());
+
+ pinfo2.read();
+ } catch (Win32Exception e) {
+ we = e;
+ } finally {
+ if (!Winspool.INSTANCE.ClosePrinter(pHandle.getValue())) {
+ Win32Exception ex = new Win32Exception(Kernel32.INSTANCE.GetLastError());
+ if (we != null) {
+ ex.addSuppressed(we);
+ }
+ }
+ }
+
+ if (we != null) {
+ throw we;
+ }
+
+ return pinfo2;
+ }
public static PRINTER_INFO_4[] getPrinterInfo4() {
IntByReference pcbNeeded = new IntByReference();
diff --git a/contrib/platform/test/com/sun/jna/platform/win32/WinspoolTest.java b/contrib/platform/test/com/sun/jna/platform/win32/WinspoolTest.java
index 42de43edb1..0bc6f0e2b5 100644
--- a/contrib/platform/test/com/sun/jna/platform/win32/WinspoolTest.java
+++ b/contrib/platform/test/com/sun/jna/platform/win32/WinspoolTest.java
@@ -12,12 +12,15 @@
*/
package com.sun.jna.platform.win32;
-import junit.framework.TestCase;
-
+import com.sun.jna.Native;
+import com.sun.jna.platform.win32.WinNT.HANDLEByReference;
import com.sun.jna.platform.win32.Winspool.PRINTER_INFO_1;
+import com.sun.jna.platform.win32.Winspool.PRINTER_INFO_2;
import com.sun.jna.platform.win32.Winspool.PRINTER_INFO_4;
import com.sun.jna.ptr.IntByReference;
+import junit.framework.TestCase;
+
/**
* @author dblock[at]dblock[dot]org
*/
@@ -30,40 +33,65 @@ public static void main(String[] args) {
public void testEnumPrinters_4() {
IntByReference pcbNeeded = new IntByReference();
IntByReference pcReturned = new IntByReference();
- // if there're no printers installed, EnumPrinters will succeed with zero items returned
- Winspool.INSTANCE.EnumPrinters(Winspool.PRINTER_ENUM_LOCAL,
- null, 4, null, 0, pcbNeeded, pcReturned);
+ // if there are no printers installed, EnumPrinters will succeed with zero items returned
+ Winspool.INSTANCE.EnumPrinters(Winspool.PRINTER_ENUM_LOCAL, null, 4, null, 0, pcbNeeded, pcReturned);
assertTrue(pcReturned.getValue() == 0);
if (pcbNeeded.getValue() > 0) {
- PRINTER_INFO_4 pPrinterEnum = new PRINTER_INFO_4(pcbNeeded.getValue());
- assertTrue(Winspool.INSTANCE.EnumPrinters(Winspool.PRINTER_ENUM_LOCAL,
- null, 4, pPrinterEnum.getPointer(), pcbNeeded.getValue(), pcbNeeded, pcReturned));
- assertTrue(pcReturned.getValue() >= 0);
+ PRINTER_INFO_4 pPrinterEnum = new PRINTER_INFO_4(pcbNeeded.getValue());
+ assertTrue(Winspool.INSTANCE.EnumPrinters(Winspool.PRINTER_ENUM_LOCAL, null, 4, pPrinterEnum.getPointer(), pcbNeeded.getValue(), pcbNeeded, pcReturned));
+ assertTrue(pcReturned.getValue() >= 0);
PRINTER_INFO_4[] printerInfo = (PRINTER_INFO_4[]) pPrinterEnum.toArray(pcReturned.getValue());
for(PRINTER_INFO_4 pi : printerInfo) {
assertTrue(pi.pPrinterName == null || pi.pPrinterName.length() >= 0);
- // System.out.println(pi.pPrinterName);
}
}
}
+ public void testEnumPrinters_2() {
+ IntByReference pcbNeeded = new IntByReference();
+ IntByReference pcReturned = new IntByReference();
+ // if there are no printers installed, EnumPrinters will succeed with zero items returned
+ Winspool.INSTANCE.EnumPrinters(Winspool.PRINTER_ENUM_LOCAL, null, 2, null, 0, pcbNeeded, pcReturned);
+ assertTrue(pcReturned.getValue() == 0);
+ if (pcbNeeded.getValue() > 0) {
+ PRINTER_INFO_2 pPrinterEnum = new PRINTER_INFO_2(pcbNeeded.getValue());
+ assertTrue(Winspool.INSTANCE.EnumPrinters(Winspool.PRINTER_ENUM_LOCAL, null, 2, pPrinterEnum.getPointer(), pcbNeeded.getValue(), pcbNeeded, pcReturned));
+ assertTrue(pcReturned.getValue() >= 0);
+ PRINTER_INFO_2[] printerInfo = (PRINTER_INFO_2[]) pPrinterEnum.toArray(pcReturned.getValue());
+ for(PRINTER_INFO_2 pi : printerInfo) {
+ assertTrue(pi.pPrinterName == null || pi.pPrinterName.length() >= 0);
+ }
+ }
+ }
+
public void testEnumPrinters_1() {
IntByReference pcbNeeded = new IntByReference();
IntByReference pcReturned = new IntByReference();
- // if there're no printers installed, EnumPrinters will succeed with zero items returned
- Winspool.INSTANCE.EnumPrinters(Winspool.PRINTER_ENUM_LOCAL,
- null, 1, null, 0, pcbNeeded, pcReturned);
+ // if there are no printers installed, EnumPrinters will succeed with zero items returned
+ Winspool.INSTANCE.EnumPrinters(Winspool.PRINTER_ENUM_LOCAL, null, 1, null, 0, pcbNeeded, pcReturned);
assertTrue(pcReturned.getValue() == 0);
if (pcbNeeded.getValue() > 0) {
PRINTER_INFO_1 pPrinterEnum = new PRINTER_INFO_1(pcbNeeded.getValue());
- assertTrue(Winspool.INSTANCE.EnumPrinters(Winspool.PRINTER_ENUM_LOCAL,
- null, 1, pPrinterEnum.getPointer(), pcbNeeded.getValue(), pcbNeeded, pcReturned));
+ assertTrue(Winspool.INSTANCE.EnumPrinters(Winspool.PRINTER_ENUM_LOCAL, null, 1, pPrinterEnum.getPointer(), pcbNeeded.getValue(), pcbNeeded, pcReturned));
assertTrue(pcReturned.getValue() >= 0);
PRINTER_INFO_1[] printerInfo = (PRINTER_INFO_1[]) pPrinterEnum.toArray(pcReturned.getValue());
for(PRINTER_INFO_1 pi : printerInfo) {
assertTrue(pi.pName == null || pi.pName.length() >= 0);
- // System.out.println(pi.pName);
}
}
}
+
+ public void testOpenPrinter() {
+ HANDLEByReference hbr = new HANDLEByReference();
+ boolean result = Winspool.INSTANCE.OpenPrinter("1234567890A123", hbr, null);
+ assertFalse("OpenPrinter should return false on failure.", result);
+ assertNull("The pointer-to-a-printer-handle should be null on failure.", hbr.getValue());
+ assertEquals("GetLastError() should return ERROR_INVALID_PRINTER_NAME", WinError.ERROR_INVALID_PRINTER_NAME, Native.getLastError());
+ }
+
+ public void testClosePrinter() {
+ boolean result = Winspool.INSTANCE.ClosePrinter(null);
+ assertFalse("ClosePrinter should return false on failure.", result);
+ assertEquals("GetLastError() should return ERROR_INVALID_HANDLE", WinError.ERROR_INVALID_HANDLE, Native.getLastError());
+ }
}
diff --git a/contrib/platform/test/com/sun/jna/platform/win32/WinspoolUtilTest.java b/contrib/platform/test/com/sun/jna/platform/win32/WinspoolUtilTest.java
index 793de5349a..0d83c2388b 100644
--- a/contrib/platform/test/com/sun/jna/platform/win32/WinspoolUtilTest.java
+++ b/contrib/platform/test/com/sun/jna/platform/win32/WinspoolUtilTest.java
@@ -23,7 +23,7 @@
public class WinspoolUtilTest extends TestCase {
public static void main(String[] args) {
- junit.textui.TestRunner.run(Shell32UtilTest.class);
+ junit.textui.TestRunner.run(WinspoolUtilTest.class);
for(PRINTER_INFO_1 printerInfo : WinspoolUtil.getPrinterInfo1()) {
System.out.println(printerInfo.pName + ": " + printerInfo.pDescription);
}
@@ -36,7 +36,21 @@ public void testGetPrinterInfo1() {
assertTrue(WinspoolUtil.getPrinterInfo1().length >= 0);
}
- public void testGetPrinterInfo4() {
- assertTrue(WinspoolUtil.getPrinterInfo4().length >= 0);
+ public void testGetPrinterInfo2() {
+ assertTrue(WinspoolUtil.getPrinterInfo2().length >= 0);
}
+
+ public void testGetPrinterInfo2Specific() {
+ try {
+ WinspoolUtil.getPrinterInfo2("1234567890A123");
+ fail("A Win32Exception with ERROR_INVALID_PRINTER_NAME should have been thrown instead of hitting this.");
+ } catch (Win32Exception e) {
+ assertEquals("A Win32Exception with ERROR_INVALID_PRINTER_NAME message should have been thrown.",
+ Kernel32Util.formatMessage(W32Errors.HRESULT_FROM_WIN32(WinError.ERROR_INVALID_PRINTER_NAME)), e.getMessage());
+ }
+ }
+
+ public void testGetPrinterInfo4() {
+ assertTrue(WinspoolUtil.getPrinterInfo4().length >= 0);
+ }
}