PrintDialogTest.cs 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. //
  2. // PrintDialogTest.cs: Tests for PrintDialog class.
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining
  5. // a copy of this software and associated documentation files (the
  6. // "Software"), to deal in the Software without restriction, including
  7. // without limitation the rights to use, copy, modify, merge, publish,
  8. // distribute, sublicense, and/or sell copies of the Software, and to
  9. // permit persons to whom the Software is furnished to do so, subject to
  10. // the following conditions:
  11. //
  12. // The above copyright notice and this permission notice shall be
  13. // included in all copies or substantial portions of the Software.
  14. //
  15. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  16. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  17. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  18. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  19. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  20. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  21. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  22. //
  23. // Copyright (c) 2006 Novell, Inc. (http://www.novell.com)
  24. //
  25. // Authors:
  26. // Carlos Alberto Cortez <[email protected]>
  27. //
  28. using System;
  29. using System.Collections;
  30. using System.Drawing;
  31. using System.Drawing.Printing;
  32. using System.Windows.Forms;
  33. using NUnit.Framework;
  34. namespace MonoTests.System.Windows.Forms
  35. {
  36. [TestFixture]
  37. public class PrintDialogTest
  38. {
  39. [Test]
  40. [Category("Printing")]
  41. public void DefaultValues ()
  42. {
  43. PrintDialog pd = new PrintDialog ();
  44. Assert.IsTrue (pd.AllowPrintToFile, "#1");
  45. Assert.IsFalse (pd.AllowSelection, "#2");
  46. Assert.IsFalse (pd.AllowSomePages, "#3");
  47. Assert.IsNull (pd.Document, "#4");
  48. #if NET_2_0
  49. Assert.IsNotNull (pd.PrinterSettings, "#5");
  50. #else
  51. Assert.IsNull (pd.PrinterSettings, "#5");
  52. #endif
  53. Assert.IsFalse (pd.PrintToFile, "#6");
  54. Assert.IsFalse (pd.ShowHelp, "#7");
  55. Assert.IsTrue (pd.ShowNetwork, "#8");
  56. }
  57. [Test]
  58. [Category("Printing")]
  59. public void DocumentTest ()
  60. {
  61. PrintDialog pd = new PrintDialog ();
  62. PrintDocument pdoc1 = new PrintDocument ();
  63. PrinterSettings ps1 = new PrinterSettings ();
  64. pdoc1.PrinterSettings = ps1;
  65. pd.Document = pdoc1;
  66. Assert.AreEqual (pdoc1, pd.Document, "#1");
  67. Assert.AreEqual (ps1, pd.PrinterSettings, "#2");
  68. PrinterSettings ps2 = new PrinterSettings ();
  69. pdoc1.PrinterSettings = ps2;
  70. pd.Document = pdoc1;
  71. Assert.AreEqual (pdoc1, pd.Document, "#3");
  72. Assert.AreEqual (ps2, pd.PrinterSettings, "#4");
  73. pd.Document = null;
  74. Assert.IsNull (pd.Document, "#5");
  75. Assert.IsNotNull (pd.PrinterSettings, "#6");
  76. if (pd.PrinterSettings == ps1)
  77. Assert.Fail ("#7");
  78. }
  79. [Test]
  80. [Category("Printing")]
  81. public void PrinterSettingsTest ()
  82. {
  83. PrintDialog pd = new PrintDialog ();
  84. PrinterSettings ps1 = new PrinterSettings ();
  85. pd.PrinterSettings = ps1;
  86. Assert.AreEqual (ps1, pd.PrinterSettings, "#1");
  87. Assert.IsNull (pd.Document, "#2");
  88. pd.PrinterSettings = null;
  89. Assert.IsNotNull (pd.PrinterSettings, "#3");
  90. Assert.IsNull (pd.Document, "#4");
  91. if (pd.PrinterSettings == ps1)
  92. Assert.Fail ("#5");
  93. }
  94. #if ONLY_1_1
  95. [Test] // bug #80764
  96. public void ShowDialog_PrinterSettings_Null ()
  97. {
  98. PrintDialog pd = new PrintDialog ();
  99. try {
  100. pd.ShowDialog ();
  101. Assert.Fail ("#1");
  102. } catch (ArgumentException ex) {
  103. // PrintDialog needs a PrinterSettings object to display
  104. Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
  105. Assert.IsNull (ex.InnerException, "#3");
  106. Assert.IsNotNull (ex.Message, "#4");
  107. Assert.IsNull (ex.ParamName, "#5");
  108. }
  109. }
  110. #endif
  111. }
  112. }