TextWriterTest.cs 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. //
  2. // TextWriterTest.cs
  3. //
  4. // Author:
  5. // Atsushi Enomoto <[email protected]>
  6. //
  7. // Copyright (C) 2004 Novell (http://www.novell.com)
  8. //
  9. using System;
  10. using System.Globalization;
  11. using System.IO;
  12. using System.Text;
  13. using NUnit.Framework;
  14. namespace MonoTests.System.IO
  15. {
  16. [TestFixture]
  17. public class TextWriterTest : Assertion
  18. {
  19. class MyTextWriter : TextWriter
  20. {
  21. public override Encoding Encoding { get { return Encoding.Default; } }
  22. internal MyTextWriter ()
  23. : base (CultureInfo.InvariantCulture)
  24. {
  25. }
  26. public void UpdateLine ()
  27. {
  28. CoreNewLine = new char [] {'Z'};
  29. }
  30. public void UpdateLine2 ()
  31. {
  32. CoreNewLine [0] = 'Y';
  33. }
  34. }
  35. [Test]
  36. public void CoreNewLine ()
  37. {
  38. MyTextWriter w = new MyTextWriter ();
  39. AssertNotNull (w.NewLine);
  40. w.UpdateLine ();
  41. AssertEquals ('Z', w.NewLine [0]);
  42. w.UpdateLine2 ();
  43. AssertEquals ('Y', w.NewLine [0]);
  44. }
  45. class ArrayOrCharTester : TextWriter {
  46. public bool called_array;
  47. public override Encoding Encoding { get { return Encoding.UTF8; }}
  48. public override void Write (char [] x, int a, int b)
  49. {
  50. called_array = true;
  51. }
  52. public override void Write (char c)
  53. {
  54. }
  55. }
  56. [Test]
  57. public void TestCharArrayCallsArrayIntInt ()
  58. {
  59. ArrayOrCharTester x = new ArrayOrCharTester ();
  60. x.Write (new char [] {'a','b','c'});
  61. AssertEquals (true, x.called_array);
  62. }
  63. }
  64. }