2 // PrintingServicesUnix class unit tests
5 // Sebastien Pouliot <sebastien@ximian.com>
7 // Copyright (C) 2007 Novell, Inc (http://www.novell.com)
9 // Permission is hereby granted, free of charge, to any person obtaining
10 // a copy of this software and associated documentation files (the
11 // "Software"), to deal in the Software without restriction, including
12 // without limitation the rights to use, copy, modify, merge, publish,
13 // distribute, sublicense, and/or sell copies of the Software, and to
14 // permit persons to whom the Software is furnished to do so, subject to
15 // the following conditions:
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
20 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
30 using System.Collections.Generic;
32 using System.Drawing.Printing;
33 using System.Runtime.InteropServices;
34 using NUnit.Framework;
36 namespace MonoTests.System.Drawing.Printing {
39 public class PrintingServicesUnixTest {
41 [DllImport ("gdiplus.dll")]
42 static extern Status GdipGetPostScriptSavePage (IntPtr graphics);
45 public void BuiltInPrinting ()
47 // ensure libgdiplus is built with printing support enabled
48 if (GDIPlus.RunningOnWindows ())
49 Assert.Ignore ("Running on Windows.");
51 Assert.AreEqual (Status.InvalidParameter, GdipGetPostScriptSavePage (IntPtr.Zero), "Missing printing support");
54 #region Novell Bug #602934
56 #region CUPS methods and structs
58 [StructLayout (LayoutKind.Sequential)]
62 public string Instance;
64 public int NumOptions;
65 public IntPtr Options;
68 [StructLayout (LayoutKind.Sequential)]
75 readonly IntPtr CUPS_HTTP_DEFAULT = IntPtr.Zero;
77 [DllImport ("libcups")]
78 static extern IntPtr cupsGetNamedDest (IntPtr http, string name, string instance);
80 [DllImport ("libcups")]
81 static extern void cupsFreeDests (int num_dests, IntPtr dests);
83 [DllImport ("libcups")]
84 static extern void cupsFreeDests (int num_dests, ref CUPS_DEST dests);
88 Dictionary<string, string> GetOptionsOfFirstPrinterThroughCups ()
90 var options = new Dictionary<string, string> ();
92 var destPtr = cupsGetNamedDest (CUPS_HTTP_DEFAULT, PrinterSettings.InstalledPrinters [0], null);
93 var dest = (CUPS_DEST)Marshal.PtrToStructure (destPtr, typeof(CUPS_DEST));
94 var optionPtr = dest.Options;
95 int cupsOptionSize = Marshal.SizeOf (typeof(CUPS_OPTION));
96 for (int i = 0; i < dest.NumOptions; i++) {
97 var cupsOption = (CUPS_OPTION)Marshal.PtrToStructure (optionPtr, typeof(CUPS_OPTION));
98 options.Add (cupsOption.Name, cupsOption.Value);
99 optionPtr = (IntPtr)((long)optionPtr + cupsOptionSize);
101 cupsFreeDests (1, destPtr);
106 [Platform (Exclude = "Win", Reason = "Depends on CUPS which is usually not installed on Windows")]
107 public void Bug602934_PrinterSettingsReturnActualValues ()
109 if (PrinterSettings.InstalledPrinters.Count < 1)
110 Assert.Ignore ("Need at least one printer installed.");
112 var options = GetOptionsOfFirstPrinterThroughCups ();
114 var settings = new PrinterSettings () { PrinterName = PrinterSettings.InstalledPrinters [0] };
115 Assert.AreEqual (options ["PageSize"], settings.DefaultPageSettings.PaperSize.PaperName,
116 "Bug #602934 (https://bugzilla.novell.com/show_bug.cgi?id=602934) not fixed (PaperSize)");
117 if (options.ContainsKey("Resolution"))
118 Assert.AreEqual (options ["Resolution"], string.Format ("{0}dpi", settings.DefaultPageSettings.PrinterResolution.X),
119 "Bug #602934 (https://bugzilla.novell.com/show_bug.cgi?id=602934) not fixed (Resolution)");