Imported Upstream version 3.6.0

Former-commit-id: da6be194a6b1221998fc28233f2503bd61dd9d14
This commit is contained in:
Jo Shields
2014-08-13 10:39:27 +01:00
commit a575963da9
50588 changed files with 8155799 additions and 0 deletions

View File

@@ -0,0 +1,65 @@
2009-07-09 Carlos Alberto Cortez <calberto.cortez@gmail.com>
* PageSourceTest.cs:
* PaperSizeTest.cs: Include the new tests in NET_2_0 define, to fix
the 1.1 build.
2009-07-08 Carlos Alberto Cortez <calberto.cortez@gmail.com>
* PageSourceTest.cs: New file, by Andy Hume <andyhume32@yahoo.co.uk>
2009-07-08 Carlos Alberto Cortez <calberto.cortez@gmail.com>
* PaperSizeTest.cs: New file, by Andy Hume <andyhume32@yahoo.co.uk>
2007-07-03 Sebastien Pouliot <sebastien@ximian.com>
* MarginsTest.cs: Remove operator tests before 2.0. Fix bots failures.
2007-05-29 Sebastien Pouliot <sebastien@ximian.com>
* MarginsTest.cs: New. Unit tests for Margins.
2007-05-03 Sebastien Pouliot <sebastien@ximian.com>
* PrintingServicesUnixTest.cs: New. Test case to make sure libgdiplus
was compiled with printing support.
2006-11-23 Carlos Alberto Cortez <calberto.cortez@gmail.com>
* PageSettingsTest.cs: Check for installed printers,
since we need to have at least one. Don't run the tests
otherwise.
2006-11-16 Carlos Alberto Cortez <calberto.cortez@gmail.com>
* PageSettingsTest.cs: New file.
2005-09-22 Sebastien Pouliot <sebastien@ximian.com>
* PrintingPermissionAttributeTest.cs: Removed *Choice security actions
2005-09-16 Sebastien Pouliot <sebastien@ximian.com>
* PrintingPermissionTest.cs: Before 2.0 some test cases throws
ArgumentException.
2005-08-26 Atsushi Enomoto <atsushi@ximian.com>
* PrintingPermissionTest.cs, PrintingPermissionAttributeTest.cs :
removed BOM. LF as eol.
2005-05-30 Sebastien Pouliot <sebastien@ximian.com>
* PrintingPermissionTest.cs: Added tests for unification as this
assembly is signed by the "MS final" key (not the ECMA key).
2004-09-09 Sebastien Pouliot <sebastien@ximian.com>
* PrintingPermissionAttributeTest.cs: New. Unit tests for Printing
PermissionAttribute.
* PrintingPermissionTest.cs: New. Unit tests for PrintingPermission.
2004-03-17 Ravindra <rkumar@novell.com>
* Created this repository for System.Drawing.Printing tests.
* ChangeLog: Added.

View File

@@ -0,0 +1,124 @@
//
// System.Drawing.Printing.Margins unit tests
//
// Authors:
// Sebastien Pouliot <sebastien@ximian.com>
//
// Copyright (C) 2007 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.Drawing;
using System.Drawing.Printing;
using System.Security.Permissions;
using NUnit.Framework;
namespace MonoTests.System.Drawing.Printing {
[TestFixture]
[SecurityPermission (SecurityAction.Deny, UnmanagedCode = true)]
public class MarginsTest {
[Test]
public void CtorDefault ()
{
Margins m = new Margins ();
Assert.AreEqual (100, m.Left, "Left");
Assert.AreEqual (100, m.Top, "Top");
Assert.AreEqual (100, m.Right, "Right");
Assert.AreEqual (100, m.Bottom, "Bottom");
Assert.AreEqual ("[Margins Left=100 Right=100 Top=100 Bottom=100]", m.ToString (), "ToString");
Margins clone = (Margins) m.Clone ();
Assert.AreEqual (m, clone, "clone");
#if NET_2_0
Assert.IsTrue (m == clone, "==");
Assert.IsFalse (m != clone, "!=");
#endif
}
[Test]
public void Ctor4Int ()
{
Margins m1 = new Margins (Int32.MaxValue, Int32.MaxValue, Int32.MaxValue, Int32.MaxValue);
Assert.AreEqual (Int32.MaxValue, m1.Left, "Left");
Assert.AreEqual (Int32.MaxValue, m1.Top, "Top");
Assert.AreEqual (Int32.MaxValue, m1.Right, "Right");
Assert.AreEqual (Int32.MaxValue, m1.Bottom, "Bottom");
// right smaller than left
Margins m2 = new Margins (Int32.MaxValue, 0, 10, 20);
// bottom smaller than top
Margins m3 = new Margins (10, 20, Int32.MaxValue, 0);
Assert.IsFalse (m2.GetHashCode () == m3.GetHashCode (), "GetHashCode");
#if NET_2_0
Assert.IsTrue (m1 != m2, "m1 != m2");
Assert.IsFalse (m1 == m2, "m1 == m2");
#endif
}
[Test]
[ExpectedException (typeof (ArgumentException))]
public void Ctor_BadLeft ()
{
new Margins (-1, 0, 0, 0);
}
[Test]
[ExpectedException (typeof (ArgumentException))]
public void Ctor_BadRight ()
{
new Margins (0, Int32.MinValue, 0, 0);
}
[Test]
[ExpectedException (typeof (ArgumentException))]
public void Ctor_BadTop ()
{
new Margins (0, 0, Int32.MinValue, 0);
}
[Test]
[ExpectedException (typeof (ArgumentException))]
public void Ctor_BadBottom ()
{
new Margins (0, 0, 0, -1);
}
[Test]
public void Equals ()
{
Margins m = new Margins ();
Assert.IsTrue (m.Equals (m), "Equals(m)");
Assert.IsFalse (m.Equals (null), "Equals(null)");
}
[Test]
public void OperatorsWithNulls ()
{
Margins m1 = null;
Margins m2 = null;
#if NET_2_0
Assert.IsTrue (m1 == m2, "null==null");
Assert.IsFalse (m1 != m2, "null!=null");
#endif
}
}
}

View File

@@ -0,0 +1,74 @@
//
// Copyright (C) 2006 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
// Author:
// Carlos Alberto Cortez <calberto.cortez@gmail.com>
//
using NUnit.Framework;
using System;
using System.Drawing;
using System.Drawing.Printing;
namespace MonoTests.System.Drawing.Printing
{
[TestFixture]
public class PageSettingsTest
{
[Test]
public void CloneTest ()
{
// Check for installed printers, because we need
// to have at least one to test
if (PrinterSettings.InstalledPrinters.Count == 0)
Assert.Ignore ("No printers found.");
PageSettings ps = new PageSettings ();
ps.Color = false;
ps.Landscape = true;
ps.Margins = new Margins (120, 130, 140, 150);
ps.PaperSize = new PaperSize ("My Custom Size", 222, 333);
PageSettings clone = (PageSettings) ps.Clone ();
Assert.AreEqual (ps.Color, clone.Color, "#1");
Assert.AreEqual (ps.Landscape, clone.Landscape, "#2");
Assert.AreEqual (ps.Margins, clone.Margins, "#3");
Assert.AreSame (ps.PrinterSettings, clone.PrinterSettings, "#4");
// PaperSize
Assert.AreEqual (ps.PaperSize.PaperName, clone.PaperSize.PaperName, "#5");
Assert.AreEqual (ps.PaperSize.Width, clone.PaperSize.Width, "#6");
Assert.AreEqual (ps.PaperSize.Height, clone.PaperSize.Height, "#7");
Assert.AreEqual (ps.PaperSize.Kind, clone.PaperSize.Kind, "#8");
// PrinterResolution
Assert.AreEqual (ps.PrinterResolution.X, clone.PrinterResolution.X, "#9");
Assert.AreEqual (ps.PrinterResolution.Y, clone.PrinterResolution.Y, "#10");
Assert.AreEqual (ps.PrinterResolution.Kind, clone.PrinterResolution.Kind, "#11");
// PaperSource
Assert.AreEqual (ps.PaperSource.Kind, clone.PaperSource.Kind, "#12");
Assert.AreEqual (ps.PaperSource.SourceName, clone.PaperSource.SourceName, "#13");
}
}
}

View File

@@ -0,0 +1,99 @@
//
// Copyright (C) 2009 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
// Author:
// Andy Hume <andyhume32@yahoo.co.uk>
//
using NUnit.Framework;
using System;
using System.Drawing;
using System.Drawing.Printing;
namespace MonoTests.System.Drawing.Printing
{
[TestFixture]
public class PaperSourceTest
{
#if NET_2_0
[Test]
public void KindTest ()
{
PaperSource ps = new PaperSource ();
//
// Set Custom
ps.RawKind = (int)PaperSourceKind.Custom;
Assert.AreEqual (PaperSourceKind.Custom, ps.Kind, "Kind #8");
Assert.AreEqual (257, ps.RawKind, "RawKind #8");
//
// An integer value of 256 and above returns Custom (0x257)
ps.RawKind = 256;
Assert.AreEqual (256, ps.RawKind, "out: #" + 256);
Assert.AreEqual (PaperSourceKind.Custom, ps.Kind, "kind is custom: #" + 256);
//
// Zero
ps.RawKind = 0;
Assert.AreEqual ((PaperSourceKind)0, ps.Kind, "Kind #1");
Assert.AreEqual (0, ps.RawKind, "RawKind #1");
//
// Well-known
ps.RawKind = (int)PaperSourceKind.Upper;
Assert.AreEqual (PaperSourceKind.Upper, ps.Kind, "Kind #2");
Assert.AreEqual ((int)PaperSourceKind.Upper, ps.RawKind, "RawKind #2");
//
ps.RawKind = (int)PaperSourceKind.FormSource;
Assert.AreEqual (PaperSourceKind.FormSource, ps.Kind, "Kind #3");
Assert.AreEqual ((int)PaperSourceKind.FormSource, ps.RawKind, "RawKind #3");
//
// Too Big
ps.RawKind = 999999;
Assert.AreEqual (PaperSourceKind.Custom, ps.Kind, "Kind #4");
Assert.AreEqual (999999, ps.RawKind, "RawKind #4");
//
ps.RawKind = int.MaxValue;
Assert.AreEqual (PaperSourceKind.Custom, ps.Kind, "Kind #5");
Assert.AreEqual (int.MaxValue, ps.RawKind, "RawKind #5");
//
// Negative -- Looks as if MSFT forgot to check for negative!
ps.RawKind = -1;
Assert.AreEqual ((PaperSourceKind)(-1), ps.Kind, "Kind #6");
Assert.AreEqual (-1, ps.RawKind, "RawKind #6");
//
ps.RawKind = int.MinValue;
Assert.AreEqual ((PaperSourceKind)(int.MinValue), ps.Kind, "Kind #7");
Assert.AreEqual (int.MinValue, ps.RawKind, "RawKind #7");
}
#endif
}
}

View File

@@ -0,0 +1,138 @@
//
// Copyright (C) 2009 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
// Author:
// Andy Hume <andyhume32@yahoo.co.uk>
//
using NUnit.Framework;
using System;
using System.Drawing;
using System.Drawing.Printing;
namespace MonoTests.System.Drawing.Printing
{
[TestFixture]
public class PaperSizeTest
{
#if NET_2_0
[Test]
public void PaperSizeKindTest()
{
// set_RawKind seems to accept any value (no ArgEx seen), but get_Kind
// returns "Custom" when it's set to a value bigger than the biggest enum.
//
PaperSize ps = new PaperSize ("foo", 100, 100);
//
// Zero == Custom
Assert.AreEqual(PaperKind.Custom, ps.Kind, "Kind #1");
Assert.AreEqual(0, ps.RawKind, "RawKind #1");
try {
ps.Height = 1;
Assert.AreEqual (1 , ps.Height, "get_Height #1");
} catch (ArgumentException) {
Assert.Fail ("should not have thrown #1");
}
//
// Well-known
ps.RawKind = (int)PaperKind.A4;
Assert.AreEqual (PaperKind.A4, ps.Kind, "Kind #2");
Assert.AreEqual ((int)PaperKind.A4, ps.RawKind, "RawKind #2");
try {
ps.Height = 2;
Assert.Fail("should have thrown #2");
} catch (ArgumentException) {
}
//
ps.RawKind = (int)PaperKind.JapaneseEnvelopeKakuNumber3;
Assert.AreEqual (PaperKind.JapaneseEnvelopeKakuNumber3, ps.Kind, "Kind #3");
Assert.AreEqual ((int)PaperKind.JapaneseEnvelopeKakuNumber3, ps.RawKind, "RawKind #3");
//
// Too Big
ps.RawKind = 999999;
Assert.AreEqual (PaperKind.Custom, ps.Kind, "Kind #4");
Assert.AreEqual (999999, ps.RawKind, "RawKind #4");
// The properties can be changed only when the *real* Kind is Custom
// and not when is 'effectively' Custom.
try {
ps.Height = 4;
Assert.Fail("should have thrown #4");
} catch (ArgumentException) {
}
//
ps.RawKind = int.MaxValue;
Assert.AreEqual (PaperKind.Custom, ps.Kind, "Kind #5");
Assert.AreEqual (int.MaxValue, ps.RawKind, "RawKind #5");
//
// Negative -- Looks as if MSFT forgot to check for negative!
ps.RawKind = -1;
Assert.AreEqual ((PaperKind)(-1), ps.Kind, "Kind #6");
Assert.AreEqual (-1, ps.RawKind, "RawKind #6");
//
ps.RawKind = int.MinValue;
Assert.AreEqual ((PaperKind)(int.MinValue), ps.Kind, "Kind #7");
Assert.AreEqual (int.MinValue, ps.RawKind, "RawKind #7");
//
// Where's the top limit?
ps.RawKind = (int)PaperKind.PrcEnvelopeNumber10Rotated;
Assert.AreEqual (PaperKind.PrcEnvelopeNumber10Rotated, ps.Kind, "Kind #8");
Assert.AreEqual ((int)PaperKind.PrcEnvelopeNumber10Rotated, ps.RawKind, "RawKind #8");
// +1
ps.RawKind = 1 + (int)PaperKind.PrcEnvelopeNumber10Rotated;
Assert.AreEqual (PaperKind.Custom, ps.Kind, "Kind #9");
Assert.AreEqual (1 + (int)PaperKind.PrcEnvelopeNumber10Rotated, ps.RawKind, "RawKind #9");
try {
ps.Height = 9;
Assert.Fail("should have thrown #9");
} catch (ArgumentException) {
}
// Set Custom
ps.RawKind = (int)PaperKind.Custom;
Assert.AreEqual (PaperKind.Custom, ps.Kind, "Kind #1b");
Assert.AreEqual (0, ps.RawKind, "RawKind #1b");
try {
ps.Height = 1;
Assert.AreEqual (1 , ps.Height, "get_Height #1b");
} catch (ArgumentException) {
Assert.Fail ("should not have thrown #1b");
}
}
#endif
}
}

View File

@@ -0,0 +1,139 @@
//
// Copyright (C) 2004-2005 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
// Author:
//
// Jordi Mas i Hernandez, jordimash@gmail.com
//
using NUnit.Framework;
using System;
using System.IO;
using System.Drawing.Printing;
using System.Security;
using System.Security.Permissions;
namespace MonoTests.System.Drawing.Printing {
[TestFixture]
public class PrinterUnitConvertTest
{
static int n = 100, r;
[Test]
public void ConvertFromDisplay ()
{
r = PrinterUnitConvert.Convert (n, PrinterUnit.Display,
PrinterUnit.Display);
Assert.AreEqual (100, r, "CFD#1");
r = PrinterUnitConvert.Convert (n, PrinterUnit.Display,
PrinterUnit.HundredthsOfAMillimeter);
Assert.AreEqual (2540, r, "CFD#2");
r = PrinterUnitConvert.Convert (n, PrinterUnit.Display,
PrinterUnit.TenthsOfAMillimeter);
Assert.AreEqual (254, r, "CFD#3");
r = PrinterUnitConvert.Convert (n, PrinterUnit.Display,
PrinterUnit.ThousandthsOfAnInch);
Assert.AreEqual (1000, r, "CFD#4");
}
[Test]
public void ConvertFromHundredthsOfAMillimeter ()
{
r = PrinterUnitConvert.Convert (n, PrinterUnit.HundredthsOfAMillimeter,
PrinterUnit.Display);
Assert.AreEqual (4, r, "CFH#1");
r = PrinterUnitConvert.Convert (n, PrinterUnit.HundredthsOfAMillimeter,
PrinterUnit.HundredthsOfAMillimeter);
Assert.AreEqual (100, r, "CFH#2");
r = PrinterUnitConvert.Convert (n, PrinterUnit.HundredthsOfAMillimeter,
PrinterUnit.TenthsOfAMillimeter);
Assert.AreEqual (10, r, "CFH#3");
r = PrinterUnitConvert.Convert (n, PrinterUnit.HundredthsOfAMillimeter,
PrinterUnit.ThousandthsOfAnInch);
Assert.AreEqual (39, r, "CFH#4");
}
[Test]
public void ConvertFromTenthsOfAMillimeter ()
{
r = PrinterUnitConvert.Convert (n, PrinterUnit.TenthsOfAMillimeter,
PrinterUnit.Display);
Assert.AreEqual (39, r, "CFT#1");
r = PrinterUnitConvert.Convert (n, PrinterUnit.TenthsOfAMillimeter,
PrinterUnit.HundredthsOfAMillimeter);
Assert.AreEqual (1000, r, "CFT#2");
r = PrinterUnitConvert.Convert (n, PrinterUnit.TenthsOfAMillimeter,
PrinterUnit.TenthsOfAMillimeter);
Assert.AreEqual (100, r, "CFT#3");
r = PrinterUnitConvert.Convert (n, PrinterUnit.TenthsOfAMillimeter,
PrinterUnit.ThousandthsOfAnInch);
Assert.AreEqual (394, r, "CFT#4");
}
[Test]
public void ConvertFromThousandthsOfAnInch ()
{
r = PrinterUnitConvert.Convert (n, PrinterUnit.ThousandthsOfAnInch,
PrinterUnit.Display);
Assert.AreEqual (10, r, "CFI#1");
r = PrinterUnitConvert.Convert (n, PrinterUnit.ThousandthsOfAnInch,
PrinterUnit.HundredthsOfAMillimeter);
Assert.AreEqual (254, r, "CFI#2");
r = PrinterUnitConvert.Convert (n, PrinterUnit.ThousandthsOfAnInch,
PrinterUnit.TenthsOfAMillimeter);
Assert.AreEqual (25, r, "CFI#3");
r = PrinterUnitConvert.Convert (n, PrinterUnit.ThousandthsOfAnInch,
PrinterUnit.ThousandthsOfAnInch);
Assert.AreEqual (100, r, "CFI#4");
}
}
}

View File

@@ -0,0 +1,134 @@
//
// PrintingPermissionAttributeTest.cs -
// NUnit Test Cases for PrintingPermissionAttribute
//
// Author:
// Sebastien Pouliot <sebastien@ximian.com>
//
// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using NUnit.Framework;
using System;
using System.Drawing.Printing;
using System.Security;
using System.Security.Permissions;
namespace MonoTests.System.Drawing.Printing {
[TestFixture]
public class PrintingPermissionAttributeTest {
[Test]
public void Default ()
{
PrintingPermissionAttribute a = new PrintingPermissionAttribute (SecurityAction.Assert);
Assert.AreEqual (a.ToString (), a.TypeId.ToString (), "TypeId");
Assert.IsFalse (a.Unrestricted, "Unrestricted");
Assert.AreEqual (PrintingPermissionLevel.NoPrinting, a.Level, "PrintingPermissionLevel");
PrintingPermission sp = (PrintingPermission)a.CreatePermission ();
Assert.IsFalse (sp.IsUnrestricted (), "IsUnrestricted");
}
[Test]
public void Action ()
{
PrintingPermissionAttribute a = new PrintingPermissionAttribute (SecurityAction.Assert);
Assert.AreEqual (SecurityAction.Assert, a.Action, "Action=Assert");
a.Action = SecurityAction.Demand;
Assert.AreEqual (SecurityAction.Demand, a.Action, "Action=Demand");
a.Action = SecurityAction.Deny;
Assert.AreEqual (SecurityAction.Deny, a.Action, "Action=Deny");
a.Action = SecurityAction.InheritanceDemand;
Assert.AreEqual (SecurityAction.InheritanceDemand, a.Action, "Action=InheritanceDemand");
a.Action = SecurityAction.LinkDemand;
Assert.AreEqual (SecurityAction.LinkDemand, a.Action, "Action=LinkDemand");
a.Action = SecurityAction.PermitOnly;
Assert.AreEqual (SecurityAction.PermitOnly, a.Action, "Action=PermitOnly");
a.Action = SecurityAction.RequestMinimum;
Assert.AreEqual (SecurityAction.RequestMinimum, a.Action, "Action=RequestMinimum");
a.Action = SecurityAction.RequestOptional;
Assert.AreEqual (SecurityAction.RequestOptional, a.Action, "Action=RequestOptional");
a.Action = SecurityAction.RequestRefuse;
Assert.AreEqual (SecurityAction.RequestRefuse, a.Action, "Action=RequestRefuse");
}
[Test]
public void Action_Invalid ()
{
PrintingPermissionAttribute a = new PrintingPermissionAttribute ((SecurityAction)Int32.MinValue);
// no validation in attribute
}
[Test]
public void Unrestricted ()
{
PrintingPermissionAttribute a = new PrintingPermissionAttribute (SecurityAction.Assert);
a.Unrestricted = true;
PrintingPermission wp = (PrintingPermission)a.CreatePermission ();
Assert.IsTrue (wp.IsUnrestricted (), "IsUnrestricted");
Assert.AreEqual (PrintingPermissionLevel.NoPrinting, a.Level, "NoPrinting");
a.Unrestricted = false;
wp = (PrintingPermission)a.CreatePermission ();
Assert.IsFalse (wp.IsUnrestricted (), "!IsUnrestricted");
}
[Test]
public void Level ()
{
PrintingPermissionAttribute a = new PrintingPermissionAttribute (SecurityAction.Assert);
a.Level = PrintingPermissionLevel.NoPrinting;
Assert.AreEqual (PrintingPermissionLevel.NoPrinting, a.Level, "NoPrinting");
a.Level = PrintingPermissionLevel.SafePrinting;
Assert.AreEqual (PrintingPermissionLevel.SafePrinting, a.Level, "SafePrinting");
a.Level = PrintingPermissionLevel.DefaultPrinting;
Assert.AreEqual (PrintingPermissionLevel.DefaultPrinting, a.Level, "DefaultPrintin.");
a.Level = PrintingPermissionLevel.AllPrinting;
Assert.AreEqual (PrintingPermissionLevel.AllPrinting, a.Level, "AllPrinting");
}
[Test]
[ExpectedException (typeof (ArgumentException))]
public void Level_Invalid ()
{
PrintingPermissionAttribute a = new PrintingPermissionAttribute (SecurityAction.Assert);
a.Level = (PrintingPermissionLevel) Int32.MinValue;
}
[Test]
public void Attributes ()
{
Type t = typeof (PrintingPermissionAttribute);
Assert.IsFalse (t.IsSerializable, "IsSerializable");
object [] attrs = t.GetCustomAttributes (typeof (AttributeUsageAttribute), false);
Assert.AreEqual (1, attrs.Length, "AttributeUsage");
AttributeUsageAttribute aua = (AttributeUsageAttribute)attrs [0];
Assert.IsTrue (aua.AllowMultiple, "AllowMultiple");
Assert.IsTrue (aua.Inherited, "Inherited");
AttributeTargets at = AttributeTargets.All;
Assert.AreEqual (at, aua.ValidOn, "ValidOn");
}
}
}

View File

@@ -0,0 +1,482 @@
//
// PrintingPermissionTest.cs - NUnit Test Cases for PrintingPermission
//
// Author:
// Sebastien Pouliot <sebastien@ximian.com>
//
// Copyright (C) 2004-2005 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using NUnit.Framework;
using System;
using System.IO;
using System.Drawing.Printing;
using System.Security;
using System.Security.Permissions;
namespace MonoTests.System.Drawing.Printing {
[TestFixture]
public class PrintingPermissionTest {
static PrintingPermissionLevel[] AllLevel = {
PrintingPermissionLevel.NoPrinting,
PrintingPermissionLevel.SafePrinting,
PrintingPermissionLevel.DefaultPrinting,
PrintingPermissionLevel.AllPrinting,
};
static PrintingPermissionLevel[] AllLevelExceptNoLevel = {
PrintingPermissionLevel.SafePrinting,
PrintingPermissionLevel.DefaultPrinting,
PrintingPermissionLevel.AllPrinting,
};
static PrintingPermissionLevel[] AllLevelExceptAllLevel = {
PrintingPermissionLevel.NoPrinting,
PrintingPermissionLevel.SafePrinting,
PrintingPermissionLevel.DefaultPrinting,
};
static PrintingPermissionLevel[] AllLevelExceptNoAndAllLevel = {
PrintingPermissionLevel.SafePrinting,
PrintingPermissionLevel.DefaultPrinting,
};
[Test]
public void PermissionState_None ()
{
PermissionState ps = PermissionState.None;
PrintingPermission pp = new PrintingPermission (ps);
Assert.AreEqual (PrintingPermissionLevel.NoPrinting, pp.Level, "Level");
Assert.IsFalse (pp.IsUnrestricted (), "IsUnrestricted");
SecurityElement se = pp.ToXml ();
// only class and version are present
Assert.AreEqual ("NoPrinting", se.Attribute ("Level"), "Xml-Level");
Assert.IsNull (se.Children, "Xml-Children");
PrintingPermission copy = (PrintingPermission)pp.Copy ();
Assert.IsFalse (Object.ReferenceEquals (pp, copy), "ReferenceEquals");
Assert.AreEqual (pp.Level, copy.Level, "Level");
Assert.AreEqual (pp.IsUnrestricted (), copy.IsUnrestricted (), "IsUnrestricted ()");
}
[Test]
public void PermissionState_Unrestricted ()
{
PermissionState ps = PermissionState.Unrestricted;
PrintingPermission pp = new PrintingPermission (ps);
Assert.AreEqual (PrintingPermissionLevel.AllPrinting, pp.Level, "Level");
Assert.IsTrue (pp.IsUnrestricted (), "IsUnrestricted");
SecurityElement se = pp.ToXml ();
// only class and version are present
Assert.AreEqual ("true", se.Attribute ("Unrestricted"), "Xml-Unrestricted");
Assert.IsNull (se.Children, "Xml-Children");
PrintingPermission copy = (PrintingPermission)pp.Copy ();
Assert.IsFalse (Object.ReferenceEquals (pp, copy), "ReferenceEquals");
Assert.AreEqual (pp.Level, copy.Level, "Level");
Assert.AreEqual (pp.IsUnrestricted (), copy.IsUnrestricted (), "IsUnrestricted ()");
}
[Test]
[ExpectedException (typeof (ArgumentException))]
public void PermissionState_Bad ()
{
PermissionState ps = (PermissionState)77;
PrintingPermission pp = new PrintingPermission (ps);
}
[Test]
[ExpectedException (typeof (ArgumentException))]
public void PrintingPermissionLevels_Bad ()
{
PrintingPermissionLevel ppl = (PrintingPermissionLevel)(PrintingPermissionLevel.AllPrinting + 1);
PrintingPermission pp = new PrintingPermission (ppl);
}
[Test]
[ExpectedException (typeof (ArgumentException))]
public void Level_PrintingPermissionLevels_Bad ()
{
PrintingPermissionLevel ppl = (PrintingPermissionLevel)(PrintingPermissionLevel.AllPrinting + 1);
PrintingPermission pp = new PrintingPermission (PermissionState.None);
pp.Level = ppl;
}
[Test]
public void Copy ()
{
PrintingPermission pp = new PrintingPermission (PermissionState.None);
foreach (PrintingPermissionLevel ppl in AllLevel) {
pp.Level = ppl;
PrintingPermission copy = (PrintingPermission)pp.Copy ();
Assert.AreEqual (ppl, copy.Level, ppl.ToString ());
}
}
[Test]
public void Intersect_Null ()
{
PrintingPermission pp = new PrintingPermission (PermissionState.None);
// No intersection with null
foreach (PrintingPermissionLevel ppl in AllLevel) {
pp.Level = ppl;
Assert.IsNull (pp.Intersect (null), ppl.ToString ());
}
}
[Test]
public void Intersect_None ()
{
PrintingPermission sp1 = new PrintingPermission (PermissionState.None);
PrintingPermission sp2 = new PrintingPermission (PermissionState.None);
foreach (PrintingPermissionLevel ppl in AllLevelExceptNoLevel) {
sp2.Level = ppl;
// 1. Intersect None with ppl
PrintingPermission result = (PrintingPermission)sp1.Intersect (sp2);
Assert.IsNull (result, "None N " + ppl.ToString ());
// 2. Intersect ppl with None
result = (PrintingPermission)sp2.Intersect (sp1);
Assert.IsNull (result, "None N " + ppl.ToString ());
}
}
[Test]
public void Intersect_Self ()
{
PrintingPermission pp = new PrintingPermission (PermissionState.None);
foreach (PrintingPermissionLevel ppl in AllLevelExceptNoLevel) {
pp.Level = ppl;
PrintingPermission result = (PrintingPermission)pp.Intersect (pp);
Assert.AreEqual (ppl, result.Level, ppl.ToString ());
}
}
[Test]
public void Intersect_Unrestricted ()
{
// Intersection with unrestricted == Copy
// a. source (this) is unrestricted
PrintingPermission sp1 = new PrintingPermission (PermissionState.Unrestricted);
PrintingPermission sp2 = new PrintingPermission (PermissionState.None);
foreach (PrintingPermissionLevel ppl in AllLevelExceptNoLevel) {
sp2.Level = ppl;
PrintingPermission result = (PrintingPermission)sp1.Intersect (sp2);
Assert.AreEqual (sp2.Level, result.Level, "target " + ppl.ToString ());
}
// b. destination (target) is unrestricted
foreach (PrintingPermissionLevel ppl in AllLevelExceptNoLevel) {
sp2.Level = ppl;
PrintingPermission result = (PrintingPermission)sp2.Intersect (sp1);
Assert.AreEqual (sp2.Level, result.Level, "source " + ppl.ToString ());
}
// exceptions for NoLevel
sp2.Level = PrintingPermissionLevel.NoPrinting;
Assert.IsNull (sp1.Intersect (sp2), "target NoLevel");
Assert.IsNull (sp2.Intersect (sp1), "source NoLevel");
}
[Test]
public void IsSubset_Null ()
{
PrintingPermission pp = new PrintingPermission (PermissionState.None);
Assert.IsTrue (pp.IsSubsetOf (null), "NoLevel");
foreach (PrintingPermissionLevel ppl in AllLevelExceptNoLevel) {
pp.Level = ppl;
Assert.IsFalse (pp.IsSubsetOf (null), ppl.ToString ());
}
}
[Test]
public void IsSubset_None ()
{
// IsSubset with none
// a. source (this) is none -> target is never a subset
PrintingPermission sp1 = new PrintingPermission (PermissionState.None);
PrintingPermission sp2 = new PrintingPermission (PermissionState.None);
foreach (PrintingPermissionLevel ppl in AllLevel) {
sp2.Level = ppl;
Assert.IsTrue (sp1.IsSubsetOf (sp2), "target " + ppl.ToString ());
}
// b. destination (target) is none -> target is always a subset
foreach (PrintingPermissionLevel ppl in AllLevelExceptNoLevel) {
sp2.Level = ppl;
Assert.IsFalse (sp2.IsSubsetOf (sp1), "source " + ppl.ToString ());
}
// exception of NoLevel
sp2.Level = PrintingPermissionLevel.NoPrinting;
Assert.IsTrue (sp2.IsSubsetOf (sp1), "source NoLevel");
}
[Test]
public void IsSubset_Self ()
{
PrintingPermission pp = new PrintingPermission (PermissionState.None);
foreach (PrintingPermissionLevel ppl in AllLevel) {
pp.Level = ppl;
PrintingPermission result = (PrintingPermission)pp.Intersect (pp);
Assert.IsTrue (pp.IsSubsetOf (pp), ppl.ToString ());
}
}
[Test]
public void IsSubset_Unrestricted ()
{
// IsSubset with unrestricted
// a. source (this) is unrestricted -> target is never a subset
PrintingPermission sp1 = new PrintingPermission (PermissionState.Unrestricted);
PrintingPermission sp2 = new PrintingPermission (PermissionState.None);
foreach (PrintingPermissionLevel ppl in AllLevelExceptAllLevel) {
sp2.Level = ppl;
Assert.IsFalse (sp1.IsSubsetOf (sp2), "target " + ppl.ToString ());
}
// exception of AllLevel
sp2.Level = PrintingPermissionLevel.AllPrinting;
Assert.IsTrue (sp1.IsSubsetOf (sp2), "target AllLevel");
// b. destination (target) is unrestricted -> target is always a subset
foreach (PrintingPermissionLevel ppl in AllLevel) {
sp2.Level = ppl;
Assert.IsTrue (sp2.IsSubsetOf (sp1), "source " + ppl.ToString ());
}
}
[Test]
public void Union_Null ()
{
PrintingPermission pp = new PrintingPermission (PermissionState.None);
// Union with null is a simple copy
foreach (PrintingPermissionLevel ppl in AllLevel) {
pp.Level = ppl;
PrintingPermission union = (PrintingPermission)pp.Union (null);
Assert.AreEqual (ppl, union.Level, ppl.ToString ());
}
}
[Test]
public void Union_None ()
{
// Union with none is same
PrintingPermission pp1 = new PrintingPermission (PermissionState.None);
PrintingPermission pp2 = new PrintingPermission (PermissionState.None);
PrintingPermission union = null;
// a. source (this) is none
pp2.Level = PrintingPermissionLevel.NoPrinting;
union = (PrintingPermission)pp1.Union (pp2);
Assert.IsNull (union, "target NoPrinting");
foreach (PrintingPermissionLevel ppl in AllLevelExceptNoAndAllLevel) {
pp2.Level = ppl;
union = (PrintingPermission)pp1.Union (pp2);
Assert.IsFalse (union.IsUnrestricted (), "target " + ppl.ToString ());
}
pp2.Level = PrintingPermissionLevel.AllPrinting;
union = (PrintingPermission)pp1.Union (pp2);
Assert.IsTrue (union.IsUnrestricted (), "target AllPrinting");
// b. destination (target) is none
pp2.Level = PrintingPermissionLevel.NoPrinting;
union = (PrintingPermission)pp2.Union (pp1);
Assert.IsNull (union, "source NoPrinting");
foreach (PrintingPermissionLevel ppl in AllLevelExceptNoAndAllLevel) {
pp2.Level = ppl;
union = (PrintingPermission)pp2.Union (pp1);
Assert.IsFalse (union.IsUnrestricted (), "source " + ppl.ToString ());
}
pp2.Level = PrintingPermissionLevel.AllPrinting;
union = (PrintingPermission)pp2.Union (pp1);
Assert.IsTrue (union.IsUnrestricted (), "source AllPrinting");
}
[Test]
public void Union_Self ()
{
PrintingPermission pp = new PrintingPermission (PermissionState.None);
foreach (PrintingPermissionLevel ppl in AllLevelExceptNoLevel) {
pp.Level = ppl;
PrintingPermission result = (PrintingPermission)pp.Union (pp);
Assert.AreEqual (ppl, result.Level, ppl.ToString ());
}
// union of NoPrinting with NoPrinting == null
pp.Level = PrintingPermissionLevel.NoPrinting;
Assert.IsNull (pp.Union (pp), "NoPrinting");
}
[Test]
public void Union_Unrestricted ()
{
// Union with unrestricted is unrestricted
PrintingPermission sp1 = new PrintingPermission (PermissionState.Unrestricted);
PrintingPermission sp2 = new PrintingPermission (PermissionState.None);
// a. source (this) is unrestricted
foreach (PrintingPermissionLevel ppl in AllLevel) {
sp2.Level = ppl;
PrintingPermission union = (PrintingPermission)sp1.Union (sp2);
Assert.IsTrue (union.IsUnrestricted (), "target " + ppl.ToString ());
}
// b. destination (target) is unrestricted
foreach (PrintingPermissionLevel ppl in AllLevel) {
sp2.Level = ppl;
PrintingPermission union = (PrintingPermission)sp2.Union (sp1);
Assert.IsTrue (union.IsUnrestricted (), "source " + ppl.ToString ());
}
}
[Test]
[ExpectedException (typeof (ArgumentNullException))]
public void FromXml_Null ()
{
PrintingPermission pp = new PrintingPermission (PermissionState.None);
pp.FromXml (null);
}
[Test]
public void FromXml_WrongTag ()
{
PrintingPermission pp = new PrintingPermission (PermissionState.None);
SecurityElement se = pp.ToXml ();
se.Tag = "IMono";
pp.FromXml (se);
// note: normally IPermission classes (in corlib) DO care about the
// IPermission tag
}
[Test]
public void FromXml_WrongTagCase ()
{
PrintingPermission pp = new PrintingPermission (PermissionState.None);
SecurityElement se = pp.ToXml ();
se.Tag = "IPERMISSION"; // instead of IPermission
pp.FromXml (se);
// note: normally IPermission classes (in corlib) DO care about the
// IPermission tag
}
[Test]
#if !NET_2_0
[ExpectedException (typeof (ArgumentException))]
#endif
public void FromXml_WrongClass ()
{
PrintingPermission pp = new PrintingPermission (PermissionState.None);
SecurityElement se = pp.ToXml ();
SecurityElement w = new SecurityElement (se.Tag);
w.AddAttribute ("class", "Wrong" + se.Attribute ("class"));
w.AddAttribute ("version", se.Attribute ("version"));
pp.FromXml (w);
// doesn't care of the class name at that stage
// anyway the class has already be created so...
}
[Test]
[ExpectedException (typeof (ArgumentException))]
public void FromXml_NoClass ()
{
PrintingPermission pp = new PrintingPermission (PermissionState.None);
SecurityElement se = pp.ToXml ();
SecurityElement w = new SecurityElement (se.Tag);
w.AddAttribute ("version", se.Attribute ("version"));
pp.FromXml (w);
// note: normally IPermission classes (in corlib) DO NOT care about
// attribute "class" name presence in the XML
}
[Test]
[ExpectedException (typeof (ArgumentException))]
public void FromXml_WrongVersion ()
{
PrintingPermission pp = new PrintingPermission (PermissionState.None);
SecurityElement se = pp.ToXml ();
se.Attributes.Remove ("version");
se.Attributes.Add ("version", "2");
pp.FromXml (se);
}
[Test]
#if !NET_2_0
[ExpectedException (typeof (ArgumentException))]
#endif
public void FromXml_NoVersion ()
{
PrintingPermission pp = new PrintingPermission (PermissionState.None);
SecurityElement se = pp.ToXml ();
SecurityElement w = new SecurityElement (se.Tag);
w.AddAttribute ("class", se.Attribute ("class"));
pp.FromXml (w);
}
// Unification tests (with the MS final key)
// note: corlib already test the ECMA key support for unification
private const string PermissionPattern = "<PermissionSet class=\"System.Security.PermissionSet\" version=\"1\"><IPermission class=\"System.Drawing.Printing.PrintingPermission, System.Drawing, Version={0}, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a\" version=\"1\" Level=\"NoPrinting\"/></PermissionSet>";
private const string fx10version = "1.0.3300.0";
private const string fx11version = "1.0.5000.0";
private const string fx20version = "2.0.0.0";
private void Unification (string xml)
{
PermissionSetAttribute psa = new PermissionSetAttribute (SecurityAction.Assert);
psa.XML = xml;
string pset = psa.CreatePermissionSet ().ToString ();
string currentVersion = typeof (string).Assembly.GetName ().Version.ToString ();
Assert.IsTrue ((pset.IndexOf (currentVersion) > 0), currentVersion);
}
[Test]
public void Unification_FromFx10 ()
{
Unification (String.Format (PermissionPattern, fx10version));
}
[Test]
public void Unification_FromFx11 ()
{
Unification (String.Format (PermissionPattern, fx11version));
}
[Test]
public void Unification_FromFx20 ()
{
Unification (String.Format (PermissionPattern, fx20version));
}
#if NET_2_0
[Test]
[Category ("NotWorking")]
[ExpectedException (typeof (FileLoadException))]
public void Unification_FromFx99 ()
{
Type.GetType (String.Format (PermissionPattern, "9.99.999.9999"));
}
#else
[Test]
public void Unification_FromFx99 ()
{
Unification (String.Format (PermissionPattern, "9.99.999.9999"));
}
#endif
}
}

View File

@@ -0,0 +1,125 @@
//
// PrintingServicesUnix class unit tests
//
// Authors:
// Sebastien Pouliot <sebastien@ximian.com>
//
// Copyright (C) 2007 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Printing;
using System.Runtime.InteropServices;
using NUnit.Framework;
namespace MonoTests.System.Drawing.Printing {
[TestFixture]
public class PrintingServicesUnixTest {
[DllImport ("gdiplus.dll")]
static extern Status GdipGetPostScriptSavePage (IntPtr graphics);
[Test]
public void BuiltInPrinting ()
{
// ensure libgdiplus is built with printing support enabled
if (GDIPlus.RunningOnWindows ())
Assert.Ignore ("Running on Windows.");
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
}
}