// try to encode some bytes at once with GetBytes
private void EncoderFallbackExceptions_GetBytes (
byte [] bytes,
int testno,
Encoder enc,
EncoderFallbackExceptionTest t)
{
try {
enc.GetBytes (
t.str.ToCharArray (), 0, t.str.Length,
bytes, 0, true);
Assert.IsTrue (
t.eindex.Length == 0,
String.Format (
"test#{0}-1: UNEXPECTED SUCCESS",
testno));
} catch(EncoderFallbackException ex) {
Assert.IsTrue (
t.eindex.Length > 0,
String.Format (
"test#{0}-1: UNEXPECTED FAIL",
testno));
Assert.IsTrue (
ex.Index == t.eindex[0],
String.Format (
"test#{0}-1: Expected exception at {1} not {2}.",
testno, t.eindex[0], ex.Index));
Assert.IsTrue (
!ex.IsUnknownSurrogate (),
String.Format (
"test#{0}-1: Expected false not {1} in IsUnknownSurrogate().",
testno,
ex.IsUnknownSurrogate ()));
// NOTE: I know that in the previous check we
// have asserted that ex.IsUnknownSurrogate()
// is always false, but this does not mean that
// we don't have to take in consideration its
// real value for the next check.
if (ex.IsUnknownSurrogate ())
Assert.IsTrue (
ex.CharUnknownHigh == t.str[ex.Index]
&& ex.CharUnknownLow == t.str[ex.Index + 1],
String.Format (
"test#{0}-1: expected ({1:X}, {2:X}) not ({3:X}, {4:X}).",
testno,
t.str[ex.Index],
t.str[ex.Index + 1],
ex.CharUnknownHigh,
ex.CharUnknownLow));
else
Assert.IsTrue (
ex.CharUnknown == t.str[ex.Index],
String.Format (
"test#{0}-1: expected ({1:X}) not ({2:X}).",
testno,
t.str[ex.Index],
ex.CharUnknown));
enc.Reset ();
}
}