[Printing] Add unit test for Novell bug #602934
authorEberhard Beilharz <eb1@sil.org>
Fri, 28 Feb 2014 15:36:26 +0000 (16:36 +0100)
committerEberhard Beilharz <eb1@sil.org>
Fri, 28 Feb 2014 15:36:26 +0000 (16:36 +0100)
This unit test demonstrates the problem reported as #602934
(https://bugzilla.novell.com/show_bug.cgi?id=602934).

mcs/class/System.Drawing/Test/System.Drawing.Printing/PrintingServicesUnixTest.cs

index 48dd5b66ce1c77820e9998f36c013e51b8f6290b..4cc01193e823796921dfa8f850634882091301f2 100644 (file)
@@ -27,6 +27,7 @@
 //
 
 using System;
+using System.Collections.Generic;
 using System.Drawing;
 using System.Drawing.Printing;
 using System.Runtime.InteropServices;
@@ -49,5 +50,76 @@ namespace MonoTests.System.Drawing.Printing {
 
                        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
+
        }
 }