EncoderTest.cs 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. //
  2. // EncoderTest.cs
  3. //
  4. // Author:
  5. // Atsushi Enomoto <[email protected]>
  6. //
  7. // (C) 2006 Novell, Inc.
  8. //
  9. using NUnit.Framework;
  10. using System;
  11. using System.Text;
  12. namespace MonoTests.System.Text
  13. {
  14. [TestFixture]
  15. public class EncoderTest
  16. {
  17. #if NET_2_0
  18. [Test]
  19. [ExpectedException (typeof (ArgumentNullException))]
  20. public void ConvertNullChars ()
  21. {
  22. int bytesUsed, charsUsed;
  23. bool done;
  24. Encoding.UTF8.GetEncoder ().Convert (
  25. null, 0, 100, new byte [100], 0, 100, false,
  26. out bytesUsed, out charsUsed, out done);
  27. }
  28. [Test]
  29. [ExpectedException (typeof (ArgumentNullException))]
  30. public void ConvertNullBytes ()
  31. {
  32. int bytesUsed, charsUsed;
  33. bool done;
  34. Encoding.UTF8.GetEncoder ().Convert (
  35. new char [100], 0, 100, null, 0, 100, false,
  36. out bytesUsed, out charsUsed, out done);
  37. }
  38. [Test]
  39. public void ConvertLimitedDestination ()
  40. {
  41. byte [] bytes = new byte [10000];
  42. char [] chars = new char [10000];
  43. Encoder conv = Encoding.UTF8.GetEncoder ();
  44. int bytesUsed, charsUsed;
  45. bool done;
  46. conv.Convert (chars, 0, 10000, bytes, 0, 1000, true,
  47. out bytesUsed, out charsUsed, out done);
  48. Assert.IsFalse (done, "#1");
  49. Assert.AreEqual (625, bytesUsed, "#2");
  50. Assert.AreEqual (625, charsUsed, "#3");
  51. }
  52. #endif
  53. }
  54. }