Skip to content

Commit

Permalink
Big-endian test case fixes: XML (#49689)
Browse files Browse the repository at this point in the history
* Update expected results for endian-dependent tests BinHex_9/BinHex_10

* Input strings for XML encode/decode tests are hard-coded little-endian
  • Loading branch information
uweigand authored Mar 16, 2021
1 parent 21d8418 commit 79037eb
Show file tree
Hide file tree
Showing 17 changed files with 64 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5755,7 +5755,14 @@ public void BinHex_9(XmlWriterUtils utils)
w.WriteBinHex(Wbase64, 0, (int)Wbase64len);
w.WriteEndElement();
}
Assert.True(utils.CompareReader("<root a='610062006300' />"));
if (System.BitConverter.IsLittleEndian)
{
Assert.True(utils.CompareReader("<root a='610062006300' />"));
}
else
{
Assert.True(utils.CompareReader("<root a='006100620063' />"));
}
}

// Call WriteBinHex and verify results can be read as a string
Expand All @@ -5777,7 +5784,14 @@ public void BinHex_10(XmlWriterUtils utils)
w.WriteBinHex(Wbase64, 0, (int)Wbase64len);
w.WriteEndElement();
}
Assert.True(utils.CompareReader("<root>610062006300</root>"));
if (System.BitConverter.IsLittleEndian)
{
Assert.True(utils.CompareReader("<root>610062006300</root>"));
}
else
{
Assert.True(utils.CompareReader("<root>006100620063</root>"));
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.

using OLEDB.Test.ModuleCore;
using System.Buffers.Binary;

namespace System.Xml.Tests
{
Expand Down Expand Up @@ -47,7 +48,8 @@ public int v3()
string strUni = string.Empty;
for (int i = 0; i < _dbyte.Length; i = i + 2)
{
strUni += (BitConverter.ToChar(_dbyte, i)).ToString();
char c = (char)BinaryPrimitives.ReadUInt16LittleEndian(new Span<byte>(_dbyte, i, 2));
strUni += c.ToString();
}
CError.WriteLine(strUni + " " + XmlConvert.EncodeName(strUni));
CError.Compare(XmlConvert.EncodeName(strUni), "_xFF71_", "EncodeName");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.

using OLEDB.Test.ModuleCore;
using System.Buffers.Binary;

namespace System.Xml.Tests
{
Expand All @@ -26,7 +27,8 @@ public int XmlEncodeName4()
int i = ((CurVariation.id) - 1) * 2;
string strEnVal = string.Empty;

strEnVal = XmlConvert.EncodeName((BitConverter.ToChar(_byte_BaseChar, i)).ToString());
char c = (char)BinaryPrimitives.ReadUInt16LittleEndian(new Span<byte>(_byte_BaseChar, i, 2));
strEnVal = XmlConvert.EncodeName(c.ToString());
CError.Compare(strEnVal, _Expbyte_BaseChar[i / 2], "Comparison failed at " + i);
return TEST_PASS;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.

using OLEDB.Test.ModuleCore;
using System.Buffers.Binary;

namespace System.Xml.Tests
{
Expand All @@ -26,7 +27,8 @@ public int XmlEncodeName5()
int i = ((CurVariation.id) - 1) * 2;
string strEnVal = string.Empty;

strEnVal = XmlConvert.EncodeNmToken((BitConverter.ToChar(_byte_BaseChar, i)).ToString());
char c = (char)BinaryPrimitives.ReadUInt16LittleEndian(new Span<byte>(_byte_BaseChar, i, 2));
strEnVal = XmlConvert.EncodeNmToken(c.ToString());

if (_Expbyte_BaseChar[i / 2] != "_x0387_" && _Expbyte_BaseChar[i / 2] != "_x0640_" && _Expbyte_BaseChar[i / 2] != "_x064B_" && _Expbyte_BaseChar[i / 2] != "_x0670_" && _Expbyte_BaseChar[i / 2] != "_x06D6_" && _Expbyte_BaseChar[i / 2] != "_x06E4_" && _Expbyte_BaseChar[i / 2] != "_x06E7_" && _Expbyte_BaseChar[i / 2] != "_x093C_" && _Expbyte_BaseChar[i / 2] != "_x093E_" && _Expbyte_BaseChar[i / 2] != "_x0962_" && _Expbyte_BaseChar[i / 2] != "_x09E2_" && _Expbyte_BaseChar[i / 2] != "_x09EF_" && _Expbyte_BaseChar[i / 2] != "_x0A71_" && _Expbyte_BaseChar[i / 2] != "_x0ABC_" && _Expbyte_BaseChar[i / 2] != "_x0ABE_" && _Expbyte_BaseChar[i / 2] != "_x0B3C_" && _Expbyte_BaseChar[i / 2] != "_x0B3E_" && _Expbyte_BaseChar[i / 2] != "_x0E31_" && _Expbyte_BaseChar[i / 2] != "_x0E34_" && _Expbyte_BaseChar[i / 2] != "_x0E46_" && _Expbyte_BaseChar[i / 2] != "_x0EB1_" && _Expbyte_BaseChar[i / 2] != "_x0EB4_" && _Expbyte_BaseChar[i / 2] != "_x0EBC_" && _Expbyte_BaseChar[i / 2] != "_x0F3F_")
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.

using OLEDB.Test.ModuleCore;
using System.Buffers.Binary;

namespace System.Xml.Tests
{
Expand All @@ -28,7 +29,8 @@ public int XmlEncodeName6()
string strDeVal = string.Empty;
string strVal = string.Empty;

strVal = (BitConverter.ToChar(_byte_BaseChar, i)).ToString();
char c = (char)BinaryPrimitives.ReadUInt16LittleEndian(new Span<byte>(_byte_BaseChar, i, 2));
strVal = c.ToString();
strEnVal = XmlConvert.EncodeName(strVal);
CError.Compare(strEnVal, _Expbyte_BaseChar[i / 2], "Encode Comparison failed at " + i);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.

using OLEDB.Test.ModuleCore;
using System.Buffers.Binary;

namespace System.Xml.Tests
{
Expand All @@ -26,7 +27,8 @@ public int XmlEncodeName1()
int i = ((CurVariation.id) - 1) * 2;
string strEnVal = string.Empty;

strEnVal = XmlConvert.EncodeName((BitConverter.ToChar(_byte_CombiningChar, i)).ToString());
char c = (char)BinaryPrimitives.ReadUInt16LittleEndian(new Span<byte>(_byte_CombiningChar, i, 2));
strEnVal = XmlConvert.EncodeName(c.ToString());
CError.Compare(strEnVal, _Expbyte_CombiningChar[i / 2], "Comparison failed at " + i);
return TEST_PASS;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.

using OLEDB.Test.ModuleCore;
using System.Buffers.Binary;

namespace System.Xml.Tests
{
Expand All @@ -26,7 +27,8 @@ public int XmlEncodeName2()
int i = ((CurVariation.id) - 1) * 2;
string strEnVal = string.Empty;

strEnVal = XmlConvert.EncodeNmToken((BitConverter.ToChar(_byte_CombiningChar, i)).ToString());
char c = (char)BinaryPrimitives.ReadUInt16LittleEndian(new Span<byte>(_byte_CombiningChar, i, 2));
strEnVal = XmlConvert.EncodeNmToken(c.ToString());
if (_Expbyte_CombiningChar[i / 2] != "_x0A6F_" && _Expbyte_CombiningChar[i / 2] != "_x0E46_")
{
CError.Compare(strEnVal, _Expbyte_CombiningChar[i / 2], "Comparison failed at " + i);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.

using OLEDB.Test.ModuleCore;
using System.Buffers.Binary;

namespace System.Xml.Tests
{
Expand All @@ -28,7 +29,8 @@ public int XmlEncodeName3()
string strEnVal = string.Empty;
string strVal = string.Empty;

strVal = (BitConverter.ToChar(_byte_CombiningChar, i)).ToString();
char c = (char)BinaryPrimitives.ReadUInt16LittleEndian(new Span<byte>(_byte_CombiningChar, i, 2));
strVal = c.ToString();
strEnVal = XmlConvert.EncodeName(strVal);
CError.Compare(strEnVal, _Expbyte_CombiningChar[i / 2], "Encode Comparison failed at " + i);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.

using OLEDB.Test.ModuleCore;
using System.Buffers.Binary;

namespace System.Xml.Tests
{
Expand All @@ -26,7 +27,8 @@ public int XmlEncodeName1()
int i = ((CurVariation.id) - 1) * 2;
string strEnVal = string.Empty;

strEnVal = XmlConvert.EncodeName((BitConverter.ToChar(_byte_Digit, i)).ToString());
char c = (char)BinaryPrimitives.ReadUInt16LittleEndian(new Span<byte>(_byte_Digit, i, 2));
strEnVal = XmlConvert.EncodeName(c.ToString());
CError.Compare(strEnVal, _Expbyte_Digit[i / 2], "Comparison failed at " + i);
return TEST_PASS;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.

using OLEDB.Test.ModuleCore;
using System.Buffers.Binary;

namespace System.Xml.Tests
{
Expand All @@ -26,7 +27,8 @@ public int XmlEncodeName2()
int i = ((CurVariation.id) - 1) * 2;
string strEnVal = string.Empty;

strEnVal = XmlConvert.EncodeNmToken((BitConverter.ToChar(_byte_Digit, i)).ToString());
char c = (char)BinaryPrimitives.ReadUInt16LittleEndian(new Span<byte>(_byte_Digit, i, 2));
strEnVal = XmlConvert.EncodeNmToken(c.ToString());
if (_Expbyte_Digit[i / 2] != "_x0A70_")
{
CError.Compare(strEnVal, _Expbyte_Digit[i / 2], "Comparison failed at " + i);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.

using OLEDB.Test.ModuleCore;
using System.Buffers.Binary;

namespace System.Xml.Tests
{
Expand All @@ -28,7 +29,8 @@ public int XmlEncodeName3()
string strEnVal = string.Empty;
string strVal = string.Empty;

strVal = (BitConverter.ToChar(_byte_Digit, i)).ToString();
char c = (char)BinaryPrimitives.ReadUInt16LittleEndian(new Span<byte>(_byte_Digit, i, 2));
strVal = c.ToString();
strEnVal = XmlConvert.EncodeName(strVal);
CError.Compare(strEnVal, _Expbyte_Digit[i / 2], "Encode Comparison failed at " + i);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.

using OLEDB.Test.ModuleCore;
using System.Buffers.Binary;

namespace System.Xml.Tests
{
Expand All @@ -26,7 +27,8 @@ public int XmlEncodeName1()
int i = ((CurVariation.id) - 1) * 2;
string strEnVal = string.Empty;

strEnVal = XmlConvert.EncodeName((BitConverter.ToChar(_byte_EmbeddedNull, i)).ToString());
char c = (char)BinaryPrimitives.ReadUInt16LittleEndian(new Span<byte>(_byte_EmbeddedNull, i, 2));
strEnVal = XmlConvert.EncodeName(c.ToString());
CError.Compare(strEnVal, _Expbyte_EmbeddedNull[i / 2], "Comparison failed at " + i);
return TEST_PASS;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.

using OLEDB.Test.ModuleCore;
using System.Buffers.Binary;

namespace System.Xml.Tests
{
Expand All @@ -26,7 +27,8 @@ public int XmlEncodeName2()
int i = ((CurVariation.id) - 1) * 2;
string strEnVal = string.Empty;

strEnVal = XmlConvert.EncodeNmToken((BitConverter.ToChar(_byte_EmbeddedNull, i)).ToString());
char c = (char)BinaryPrimitives.ReadUInt16LittleEndian(new Span<byte>(_byte_EmbeddedNull, i, 2));
strEnVal = XmlConvert.EncodeNmToken(c.ToString());
CError.Compare(strEnVal, _Expbyte_EmbeddedNull[i / 2], "Comparison failed at " + i);
return TEST_PASS;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.

using OLEDB.Test.ModuleCore;
using System.Buffers.Binary;

namespace System.Xml.Tests
{
Expand All @@ -28,7 +29,8 @@ public int XmlEncodeName3()
string strEnVal = string.Empty;
string strVal = string.Empty;

strVal = (BitConverter.ToChar(_byte_EmbeddedNull, i)).ToString();
char c = (char)BinaryPrimitives.ReadUInt16LittleEndian(new Span<byte>(_byte_EmbeddedNull, i, 2));
strVal = c.ToString();
strEnVal = XmlConvert.EncodeName(strVal);
CError.Compare(strEnVal, _Expbyte_EmbeddedNull[i / 2], "Encode Comparison failed at " + i);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.

using OLEDB.Test.ModuleCore;
using System.Buffers.Binary;

namespace System.Xml.Tests
{
Expand All @@ -26,7 +27,8 @@ public int XmlEncodeName()
int i = ((CurVariation.id) - 1) * 2;
string strEnVal = string.Empty;

strEnVal = XmlConvert.EncodeName((BitConverter.ToChar(_byte_Ideographic, i)).ToString());
char c = (char)BinaryPrimitives.ReadUInt16LittleEndian(new Span<byte>(_byte_Ideographic, i, 2));
strEnVal = XmlConvert.EncodeName(c.ToString());
CError.Compare(strEnVal, _Expbyte_Ideographic[i / 2], "Comparison failed at " + i);
return TEST_PASS;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.

using OLEDB.Test.ModuleCore;
using System.Buffers.Binary;

namespace System.Xml.Tests
{
Expand All @@ -26,7 +27,8 @@ public int XmlEncodeName()
int i = ((CurVariation.id) - 1) * 2;
string strEnVal = string.Empty;

strEnVal = XmlConvert.EncodeNmToken((BitConverter.ToChar(_byte_Ideographic, i)).ToString());
char c = (char)BinaryPrimitives.ReadUInt16LittleEndian(new Span<byte>(_byte_Ideographic, i, 2));
strEnVal = XmlConvert.EncodeNmToken(c.ToString());
if (_Expbyte_Ideographic[i / 2] != "_x302A_")
{
CError.Compare(strEnVal, _Expbyte_Ideographic[i / 2], "Comparison failed at " + i);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.

using OLEDB.Test.ModuleCore;
using System.Buffers.Binary;

namespace System.Xml.Tests
{
Expand All @@ -28,7 +29,8 @@ public int XmlEncodeName()
string strEnVal = string.Empty;
string strVal = string.Empty;

strVal = (BitConverter.ToChar(_byte_Ideographic, i)).ToString();
char c = (char)BinaryPrimitives.ReadUInt16LittleEndian(new Span<byte>(_byte_Ideographic, i, 2));
strVal = c.ToString();
strEnVal = XmlConvert.EncodeName(strVal);
CError.Compare(strEnVal, _Expbyte_Ideographic[i / 2], "Encode Comparison failed at " + i);

Expand Down

0 comments on commit 79037eb

Please sign in to comment.