EncodingTest.cs 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. //
  2. // EncodingTest.cs - Unit Tests for System.Text.Encoding
  3. //
  4. // Author:
  5. // Gert Driesen ([email protected])
  6. //
  7. // Copyright (C) 2007 Gert Driesen
  8. //
  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:
  16. //
  17. // The above copyright notice and this permission notice shall be
  18. // included in all copies or substantial portions of the Software.
  19. //
  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.
  27. //
  28. using System;
  29. using System.Text;
  30. using NUnit.Framework;
  31. namespace MonoTests.System.Text
  32. {
  33. [TestFixture]
  34. public class EncodingTest
  35. {
  36. [Test]
  37. [Category ("NotWorking")]
  38. [ExpectedException (typeof (NotSupportedException))]
  39. public void IsBrowserDisplay ()
  40. {
  41. MyEncoding enc = new MyEncoding ();
  42. Assert.IsFalse (enc.IsBrowserDisplay);
  43. }
  44. [Test]
  45. [Category ("NotWorking")]
  46. [ExpectedException (typeof (NotSupportedException))]
  47. public void IsBrowserSave ()
  48. {
  49. MyEncoding enc = new MyEncoding ();
  50. Assert.IsFalse (enc.IsBrowserSave);
  51. }
  52. [Test]
  53. [Category ("NotWorking")]
  54. [ExpectedException (typeof (NotSupportedException))]
  55. public void IsMailNewsDisplay ()
  56. {
  57. MyEncoding enc = new MyEncoding ();
  58. Assert.IsFalse (enc.IsMailNewsDisplay);
  59. }
  60. [Test]
  61. [Category ("NotWorking")]
  62. [ExpectedException (typeof (NotSupportedException))]
  63. public void IsMailNewsSave ()
  64. {
  65. MyEncoding enc = new MyEncoding ();
  66. Assert.IsFalse (enc.IsMailNewsSave);
  67. }
  68. [Test]
  69. public void GetEncoding_CodePage_Default ()
  70. {
  71. Assert.AreEqual (Encoding.Default, Encoding.GetEncoding (0));
  72. }
  73. [Test]
  74. public void GetEncoding_CodePage_Invalid ()
  75. {
  76. try {
  77. Encoding.GetEncoding (-1);
  78. Assert.Fail ("#A1");
  79. } catch (ArgumentOutOfRangeException ex) {
  80. Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#A2");
  81. Assert.IsNull (ex.InnerException, "#A3");
  82. Assert.IsNotNull (ex.Message, "#A4");
  83. Assert.IsNotNull (ex.ParamName, "#A5");
  84. Assert.AreEqual ("codepage", ex.ParamName, "#A6");
  85. }
  86. try {
  87. Encoding.GetEncoding (65536);
  88. Assert.Fail ("#B1");
  89. } catch (ArgumentOutOfRangeException ex) {
  90. Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#B2");
  91. Assert.IsNull (ex.InnerException, "#B3");
  92. Assert.IsNotNull (ex.Message, "#B4");
  93. Assert.IsNotNull (ex.ParamName, "#B5");
  94. Assert.AreEqual ("codepage", ex.ParamName, "#B6");
  95. }
  96. }
  97. [Test]
  98. public void GetEncoding_Name_NotSupported ()
  99. {
  100. try {
  101. Encoding.GetEncoding ("doesnotexist");
  102. Assert.Fail ("#1");
  103. } catch (ArgumentException ex) {
  104. Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
  105. Assert.IsNull (ex.InnerException, "#3");
  106. Assert.IsNotNull (ex.Message, "#4");
  107. Assert.IsTrue (ex.Message.IndexOf ("doesnotexist") != -1, "#5");
  108. Assert.IsNotNull (ex.ParamName, "#6");
  109. Assert.AreEqual ("name", ex.ParamName, "#7");
  110. }
  111. }
  112. [Test]
  113. [ExpectedException (typeof (ArgumentNullException))]
  114. public void GetEncoding_Name_Null ()
  115. {
  116. Encoding.GetEncoding ((string) null);
  117. }
  118. }
  119. }