UTF32EncodingTest.cs 813 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. using NUnit.Framework;
  2. using System;
  3. using System.Text;
  4. #if NET_2_0
  5. namespace MonoTests.System.Text {
  6. [TestFixture]
  7. public class UTF32EncodingTest : Assertion {
  8. [Test]
  9. public void TestGetPreamble() {
  10. byte[] lePreamble = new UTF32Encoding(false, true).GetPreamble();
  11. if (!AreEqual(lePreamble, new byte[]{ 0xff, 0xfe, 0, 0 })) {
  12. Fail ("Little-endian UTF32 preamble is incorrect");
  13. }
  14. byte[] bePreamble = new UTF32Encoding(true, true).GetPreamble();
  15. if (!AreEqual(bePreamble, new byte[]{ 0, 0, 0xfe, 0xff })) {
  16. Fail ("Big-endian UTF32 preamble is incorrect");
  17. }
  18. }
  19. private bool AreEqual(byte[] a, byte[] b) {
  20. if (a.Length != b.Length)
  21. return false;
  22. for (int i = 0; i < a.Length; ++i) {
  23. if (a[i] != b[i])
  24. return false;
  25. }
  26. return true;
  27. }
  28. }
  29. }
  30. #endif