//
using System;
+using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Printing;
using System.Runtime.InteropServices;
Assert.AreEqual (Status.InvalidParameter, GdipGetPostScriptSavePage (IntPtr.Zero), "Missing printing support");
}
+
+ #region Novell Bug #602934
+
+ #region CUPS methods and structs
+
+ [StructLayout (LayoutKind.Sequential)]
+ struct CUPS_DEST
+ {
+ public string Name;
+ public string Instance;
+ public int IsDefault;
+ public int NumOptions;
+ public IntPtr Options;
+ }
+
+ [StructLayout (LayoutKind.Sequential)]
+ struct CUPS_OPTION
+ {
+ public string Name;
+ public string Value;
+ }
+
+ readonly IntPtr CUPS_HTTP_DEFAULT = IntPtr.Zero;
+
+ [DllImport ("libcups")]
+ static extern IntPtr cupsGetNamedDest (IntPtr http, string name, string instance);
+
+ [DllImport ("libcups")]
+ static extern void cupsFreeDests (int num_dests, IntPtr dests);
+
+ [DllImport ("libcups")]
+ static extern void cupsFreeDests (int num_dests, ref CUPS_DEST dests);
+
+ #endregion
+
+ Dictionary<string, string> GetOptionsOfFirstPrinterThroughCups ()
+ {
+ var options = new Dictionary<string, string> ();
+
+ var destPtr = cupsGetNamedDest (CUPS_HTTP_DEFAULT, PrinterSettings.InstalledPrinters [0], null);
+ var dest = (CUPS_DEST)Marshal.PtrToStructure (destPtr, typeof(CUPS_DEST));
+ var optionPtr = dest.Options;
+ int cupsOptionSize = Marshal.SizeOf (typeof(CUPS_OPTION));
+ for (int i = 0; i < dest.NumOptions; i++) {
+ var cupsOption = (CUPS_OPTION)Marshal.PtrToStructure (optionPtr, typeof(CUPS_OPTION));
+ options.Add (cupsOption.Name, cupsOption.Value);
+ optionPtr = (IntPtr)((long)optionPtr + cupsOptionSize);
+ }
+ cupsFreeDests (1, destPtr);
+
+ return options;
+ }
+
+ [Test]
+ [Platform (Exclude = "Win", Reason = "Depends on CUPS which is usually not installed on Windows")]
+ public void Bug602934_PrinterSettingsReturnActualValues ()
+ {
+ if (PrinterSettings.InstalledPrinters.Count < 1)
+ Assert.Ignore ("Need at least one printer installed.");
+
+ var options = GetOptionsOfFirstPrinterThroughCups ();
+
+ var settings = new PrinterSettings () { PrinterName = PrinterSettings.InstalledPrinters [0] };
+ Assert.AreEqual (options ["PageSize"], settings.DefaultPageSettings.PaperSize.PaperName,
+ "Bug #602934 (https://bugzilla.novell.com/show_bug.cgi?id=602934) not fixed (PaperSize)");
+ Assert.AreEqual (options ["Resolution"], string.Format ("{0}dpi", settings.DefaultPageSettings.PrinterResolution.X),
+ "Bug #602934 (https://bugzilla.novell.com/show_bug.cgi?id=602934) not fixed (Resolution)");
+ }
+
+ #endregion
+
}
}