[Mono-dev] Mono 3.2.8 incompatibility with .NET 4.0 on Windows 7-10
Jason Curl
jcurlnews at arcor.de
Tue Dec 15 11:55:54 UTC 2015
Hello,
I'm porting some code from Windows to Mono and I've found what I believe
bugs in the implementation of System.Text Decoder/Encoder and UTF8. I've
attached a test case that passes on Windows .NET 4.0 (using VS2015 on
Windows 10 x64), but fails under Mono 3.2.8 using the standard
installation from Ubuntu 14.04.3 fully patched at the time of writing.
Note, as this is code originally written 3 years ago, I believe the test
cases also work on Windows 7 .NET 4.0 (no .NET 4.5) also.
I've also got a link to a downloadable .zip file containing the sources
and the nUnit package for easy compiling on Windows as well as Linux
without having to create your own project (done due to size restrictions
on the mailing list). nUnit 2.6.4 is present, so that it compiles out of
the box on both platforms (sorry, not sure how best to set up two
platforms simultaneously, but that's another topic). The nUnit test
cases are in the file Test.cs.
https://onedrive.live.com/redir?resid=BF4840F0055AAAE6!189631&authkey=!ABf5p3IYB3ar2ws&ithint=file%2czip
Notes about the tests:
EncoderFlushUtf8WithBadData
* Convert is told to flush with true, so I expect that there to be 13
characters converted, but on Mono only 12 and there's no '.' as
specified by the EncoderReplacementFallback(".").
EncoderFlushUtf8Completed
* complete is true under mono, but under Windows it's false.
I'm looking on advice on how to work around the differences. I can't
change the version of Mono I'm using (I'm restricted to Ubuntu 14.04.3
for the next three years).
I've got some more errors but haven't investigated the problems yet and
will provide unit test cases to describe the errors.
Regards,
Jason.
-------------- next part --------------
namespace EncoderTest
{
using System;
using System.Text;
using NUnit.Framework;
[TestFixture]
public class Test
{
[Test]
public void EncoderFlushUtf8WithBadData()
{
Encoding enc = Encoding.GetEncoding("UTF-8", new EncoderReplacementFallback("."), new DecoderReplacementFallback("."));
Decoder d = enc.GetDecoder();
byte[] m = new byte[] {
0x4F, 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56,
0x57, 0x58, 0x59, 0x5A, 0xF3, 0xA0
};
char[] c = new char[30];
int bu;
int cu;
bool complete;
d.Convert(m, 0, 14,
c, 0, c.Length, true,
out bu, out cu, out complete);
Console.WriteLine("bu={0}, cu={1}", bu, cu);
Assert.IsTrue(complete);
Assert.AreEqual(14, bu);
Assert.AreEqual(13, cu);
Assert.AreEqual("OPQRSTUVWXYZ.", new string(c, 0, 13));
}
[Test]
public void EncoderFlushUtf8Completed()
{
Encoding enc = Encoding.GetEncoding("UTF-8", new EncoderReplacementFallback("."), new DecoderReplacementFallback("."));
Decoder d = enc.GetDecoder();
byte[] m = new byte[] {
0x4F, 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56,
0x57, 0x58, 0x59, 0x5A, 0xE2, 0x82
};
char[] c = new char[30];
int bu;
int cu;
bool complete;
d.Convert(m, 0, 14,
c, 0, 12, true,
out bu, out cu, out complete);
Console.WriteLine("bu={0}, cu={1}", bu, cu);
Assert.IsFalse(complete);
Assert.AreEqual(12, bu);
Assert.AreEqual(12, cu);
Assert.AreEqual("OPQRSTUVWXYZ", new string(c, 0, 12));
}
}
}
More information about the Mono-devel-list
mailing list