Skip to content

Commit edd3e6e

Browse files
committed
Add both-endian try read extensions
1 parent 244b741 commit edd3e6e

File tree

6 files changed

+788
-0
lines changed

6 files changed

+788
-0
lines changed

SabreTools.IO.Test/Extensions/BinaryReaderExtensionsTests.cs

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1713,6 +1713,17 @@ public void TryReadByteTest()
17131713
Assert.Equal(default, read);
17141714
}
17151715

1716+
[Fact]
1717+
public void TryReadByteBothEndianTest()
1718+
{
1719+
var stream = new MemoryStream([]);
1720+
var br = new BinaryReader(stream);
1721+
bool actual = br.TryReadByteBothEndian(out BothUInt8 read);
1722+
Assert.False(actual);
1723+
Assert.Equal(default, read.LittleEndian);
1724+
Assert.Equal(default, read.BigEndian);
1725+
}
1726+
17161727
[Fact]
17171728
public void TryReadBytesTest()
17181729
{
@@ -1734,6 +1745,17 @@ public void TryReadSByteTest()
17341745
Assert.Equal(default, read);
17351746
}
17361747

1748+
[Fact]
1749+
public void TryReadSByteBothEndianTest()
1750+
{
1751+
var stream = new MemoryStream([]);
1752+
var br = new BinaryReader(stream);
1753+
bool actual = br.TryReadSByteBothEndian(out BothInt8 read);
1754+
Assert.False(actual);
1755+
Assert.Equal(default, read.LittleEndian);
1756+
Assert.Equal(default, read.BigEndian);
1757+
}
1758+
17371759
[Fact]
17381760
public void TryReadCharTest()
17391761
{
@@ -1774,6 +1796,17 @@ public void TryReadInt16LittleEndianTest()
17741796
Assert.Equal(default, read);
17751797
}
17761798

1799+
[Fact]
1800+
public void TryReadInt16BothEndianTest()
1801+
{
1802+
var stream = new MemoryStream([]);
1803+
var br = new BinaryReader(stream);
1804+
bool actual = br.TryReadInt16BothEndian(out BothInt16 read);
1805+
Assert.False(actual);
1806+
Assert.Equal(default, read.LittleEndian);
1807+
Assert.Equal(default, read.BigEndian);
1808+
}
1809+
17771810
[Fact]
17781811
public void TryReadUInt16Test()
17791812
{
@@ -1804,6 +1837,17 @@ public void TryReadUInt16LittleEndianTest()
18041837
Assert.Equal(default, read);
18051838
}
18061839

1840+
[Fact]
1841+
public void TryReadUInt16BothEndianTest()
1842+
{
1843+
var stream = new MemoryStream([]);
1844+
var br = new BinaryReader(stream);
1845+
bool actual = br.TryReadUInt16BothEndian(out BothUInt16 read);
1846+
Assert.False(actual);
1847+
Assert.Equal(default, read.LittleEndian);
1848+
Assert.Equal(default, read.BigEndian);
1849+
}
1850+
18071851
[Fact]
18081852
public void TryReadWORDTest()
18091853
{
@@ -1834,6 +1878,17 @@ public void TryReadWORDLittleEndianTest()
18341878
Assert.Equal(default, read);
18351879
}
18361880

1881+
[Fact]
1882+
public void TryReadWORDBothEndianTest()
1883+
{
1884+
var stream = new MemoryStream([]);
1885+
var br = new BinaryReader(stream);
1886+
bool actual = br.TryReadWORDBothEndian(out BothUInt16 read);
1887+
Assert.False(actual);
1888+
Assert.Equal(default, read.LittleEndian);
1889+
Assert.Equal(default, read.BigEndian);
1890+
}
1891+
18371892
[Fact]
18381893
public void TryReadHalfTest()
18391894
{
@@ -1946,6 +2001,17 @@ public void TryReadInt32LittleEndianTest()
19462001
Assert.Equal(default, read);
19472002
}
19482003

2004+
[Fact]
2005+
public void TryReadInt32BothEndianTest()
2006+
{
2007+
var stream = new MemoryStream([]);
2008+
var br = new BinaryReader(stream);
2009+
bool actual = br.TryReadInt32BothEndian(out BothInt32 read);
2010+
Assert.False(actual);
2011+
Assert.Equal(default, read.LittleEndian);
2012+
Assert.Equal(default, read.BigEndian);
2013+
}
2014+
19492015
[Fact]
19502016
public void TryReadUInt32Test()
19512017
{
@@ -1976,6 +2042,17 @@ public void TryReadUInt32LittleEndianTest()
19762042
Assert.Equal(default, read);
19772043
}
19782044

2045+
[Fact]
2046+
public void TryReadUInt32BothEndianTest()
2047+
{
2048+
var stream = new MemoryStream([]);
2049+
var br = new BinaryReader(stream);
2050+
bool actual = br.TryReadUInt32BothEndian(out BothUInt32 read);
2051+
Assert.False(actual);
2052+
Assert.Equal(default, read.LittleEndian);
2053+
Assert.Equal(default, read.BigEndian);
2054+
}
2055+
19792056
[Fact]
19802057
public void TryReadDWORDTest()
19812058
{
@@ -2006,6 +2083,17 @@ public void TryReadDWORDLittleEndianTest()
20062083
Assert.Equal(default, read);
20072084
}
20082085

2086+
[Fact]
2087+
public void TryReadDWORDBothEndianTest()
2088+
{
2089+
var stream = new MemoryStream([]);
2090+
var br = new BinaryReader(stream);
2091+
bool actual = br.TryReadDWORDBothEndian(out BothUInt32 read);
2092+
Assert.False(actual);
2093+
Assert.Equal(default, read.LittleEndian);
2094+
Assert.Equal(default, read.BigEndian);
2095+
}
2096+
20092097
[Fact]
20102098
public void TryReadSingleTest()
20112099
{
@@ -2118,6 +2206,17 @@ public void TryReadInt64LittleEndianTest()
21182206
Assert.Equal(default, read);
21192207
}
21202208

2209+
[Fact]
2210+
public void TryReadInt64BothEndianTest()
2211+
{
2212+
var stream = new MemoryStream([]);
2213+
var br = new BinaryReader(stream);
2214+
bool actual = br.TryReadInt64BothEndian(out BothInt64 read);
2215+
Assert.False(actual);
2216+
Assert.Equal(default, read.LittleEndian);
2217+
Assert.Equal(default, read.BigEndian);
2218+
}
2219+
21212220
[Fact]
21222221
public void TryReadUInt64Test()
21232222
{
@@ -2148,6 +2247,17 @@ public void TryReadUInt64LittleEndianTest()
21482247
Assert.Equal(default, read);
21492248
}
21502249

2250+
[Fact]
2251+
public void TryReadUInt64BothEndianTest()
2252+
{
2253+
var stream = new MemoryStream([]);
2254+
var br = new BinaryReader(stream);
2255+
bool actual = br.TryReadUInt64BothEndian(out BothUInt64 read);
2256+
Assert.False(actual);
2257+
Assert.Equal(default, read.LittleEndian);
2258+
Assert.Equal(default, read.BigEndian);
2259+
}
2260+
21512261
[Fact]
21522262
public void TryReadQWORDTest()
21532263
{
@@ -2178,6 +2288,17 @@ public void TryReadQWORDLittleEndianTest()
21782288
Assert.Equal(default, read);
21792289
}
21802290

2291+
[Fact]
2292+
public void TryReadQWORDBothEndianTest()
2293+
{
2294+
var stream = new MemoryStream([]);
2295+
var br = new BinaryReader(stream);
2296+
bool actual = br.TryReadQWORDBothEndian(out BothUInt64 read);
2297+
Assert.False(actual);
2298+
Assert.Equal(default, read.LittleEndian);
2299+
Assert.Equal(default, read.BigEndian);
2300+
}
2301+
21812302
[Fact]
21822303
public void TryReadDoubleTest()
21832304
{

SabreTools.IO.Test/Extensions/ByteArrayReaderExtensionsTests.cs

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1550,6 +1550,16 @@ public void TryReadByteValueTest()
15501550
Assert.Equal(default, read);
15511551
}
15521552

1553+
[Fact]
1554+
public void TryReadByteBothEndianTest()
1555+
{
1556+
int offset = 0;
1557+
bool actual = Array.Empty<byte>().TryReadByteBothEndian(ref offset, out BothUInt8 read);
1558+
Assert.False(actual);
1559+
Assert.Equal(default, read.LittleEndian);
1560+
Assert.Equal(default, read.BigEndian);
1561+
}
1562+
15531563
[Fact]
15541564
public void TryReadBytesTest()
15551565
{
@@ -1568,6 +1578,16 @@ public void TryReadSByteTest()
15681578
Assert.Equal(default, read);
15691579
}
15701580

1581+
[Fact]
1582+
public void TryReadSByteBothEndianTest()
1583+
{
1584+
int offset = 0;
1585+
bool actual = Array.Empty<byte>().TryReadSByteBothEndian(ref offset, out BothInt8 read);
1586+
Assert.False(actual);
1587+
Assert.Equal(default, read.LittleEndian);
1588+
Assert.Equal(default, read.BigEndian);
1589+
}
1590+
15711591
[Fact]
15721592
public void TryReadCharTest()
15731593
{
@@ -1604,6 +1624,16 @@ public void TryReadInt16LittleEndianTest()
16041624
Assert.Equal(default, read);
16051625
}
16061626

1627+
[Fact]
1628+
public void TryReadInt16BothEndianTest()
1629+
{
1630+
int offset = 0;
1631+
bool actual = Array.Empty<byte>().TryReadInt16BothEndian(ref offset, out BothInt16 read);
1632+
Assert.False(actual);
1633+
Assert.Equal(default, read.LittleEndian);
1634+
Assert.Equal(default, read.BigEndian);
1635+
}
1636+
16071637
[Fact]
16081638
public void TryReadUInt16Test()
16091639
{
@@ -1631,6 +1661,16 @@ public void TryReadUInt16LittleEndianTest()
16311661
Assert.Equal(default, read);
16321662
}
16331663

1664+
[Fact]
1665+
public void TryReadUInt16BothEndianTest()
1666+
{
1667+
int offset = 0;
1668+
bool actual = Array.Empty<byte>().TryReadUInt16BothEndian(ref offset, out BothUInt16 read);
1669+
Assert.False(actual);
1670+
Assert.Equal(default, read.LittleEndian);
1671+
Assert.Equal(default, read.BigEndian);
1672+
}
1673+
16341674
[Fact]
16351675
public void TryReadWORDTest()
16361676
{
@@ -1658,6 +1698,16 @@ public void TryReadWORDLittleEndianTest()
16581698
Assert.Equal(default, read);
16591699
}
16601700

1701+
[Fact]
1702+
public void TryReadWORDBothEndianTest()
1703+
{
1704+
int offset = 0;
1705+
bool actual = Array.Empty<byte>().TryReadWORDBothEndian(ref offset, out BothUInt16 read);
1706+
Assert.False(actual);
1707+
Assert.Equal(default, read.LittleEndian);
1708+
Assert.Equal(default, read.BigEndian);
1709+
}
1710+
16611711
[Fact]
16621712
public void TryReadHalfTest()
16631713
{
@@ -1759,6 +1809,16 @@ public void TryReadInt32LittleEndianTest()
17591809
Assert.Equal(default, read);
17601810
}
17611811

1812+
[Fact]
1813+
public void TryReadInt32BothEndianTest()
1814+
{
1815+
int offset = 0;
1816+
bool actual = Array.Empty<byte>().TryReadInt32BothEndian(ref offset, out BothInt32 read);
1817+
Assert.False(actual);
1818+
Assert.Equal(default, read.LittleEndian);
1819+
Assert.Equal(default, read.BigEndian);
1820+
}
1821+
17621822
[Fact]
17631823
public void TryReadUInt32Test()
17641824
{
@@ -1786,6 +1846,16 @@ public void TryReadUInt32LittleEndianTest()
17861846
Assert.Equal(default, read);
17871847
}
17881848

1849+
[Fact]
1850+
public void TryReadUInt32BothEndianTest()
1851+
{
1852+
int offset = 0;
1853+
bool actual = Array.Empty<byte>().TryReadUInt32BothEndian(ref offset, out BothUInt32 read);
1854+
Assert.False(actual);
1855+
Assert.Equal(default, read.LittleEndian);
1856+
Assert.Equal(default, read.BigEndian);
1857+
}
1858+
17891859
[Fact]
17901860
public void TryReadDWORDTest()
17911861
{
@@ -1813,6 +1883,16 @@ public void TryReadDWORDLittleEndianTest()
18131883
Assert.Equal(default, read);
18141884
}
18151885

1886+
[Fact]
1887+
public void TryReadDWORDBothEndianTest()
1888+
{
1889+
int offset = 0;
1890+
bool actual = Array.Empty<byte>().TryReadDWORDBothEndian(ref offset, out BothUInt32 read);
1891+
Assert.False(actual);
1892+
Assert.Equal(default, read.LittleEndian);
1893+
Assert.Equal(default, read.BigEndian);
1894+
}
1895+
18161896
[Fact]
18171897
public void TryReadSingleTest()
18181898
{
@@ -1914,6 +1994,16 @@ public void TryReadInt64LittleEndianTest()
19141994
Assert.Equal(default, read);
19151995
}
19161996

1997+
[Fact]
1998+
public void TryReadInt64BothEndianTest()
1999+
{
2000+
int offset = 0;
2001+
bool actual = Array.Empty<byte>().TryReadInt64BothEndian(ref offset, out BothInt64 read);
2002+
Assert.False(actual);
2003+
Assert.Equal(default, read.LittleEndian);
2004+
Assert.Equal(default, read.BigEndian);
2005+
}
2006+
19172007
[Fact]
19182008
public void TryReadUInt64Test()
19192009
{
@@ -1941,6 +2031,16 @@ public void TryReadUInt64LittleEndianTest()
19412031
Assert.Equal(default, read);
19422032
}
19432033

2034+
[Fact]
2035+
public void TryReadUInt64BothEndianTest()
2036+
{
2037+
int offset = 0;
2038+
bool actual = Array.Empty<byte>().TryReadUInt64BothEndian(ref offset, out BothUInt64 read);
2039+
Assert.False(actual);
2040+
Assert.Equal(default, read.LittleEndian);
2041+
Assert.Equal(default, read.BigEndian);
2042+
}
2043+
19442044
[Fact]
19452045
public void TryReadQWORDTest()
19462046
{
@@ -1968,6 +2068,16 @@ public void TryReadQWORDLittleEndianTest()
19682068
Assert.Equal(default, read);
19692069
}
19702070

2071+
[Fact]
2072+
public void TryReadQWORDBothEndianTest()
2073+
{
2074+
int offset = 0;
2075+
bool actual = Array.Empty<byte>().TryReadQWORDBothEndian(ref offset, out BothUInt64 read);
2076+
Assert.False(actual);
2077+
Assert.Equal(default, read.LittleEndian);
2078+
Assert.Equal(default, read.BigEndian);
2079+
}
2080+
19712081
[Fact]
19722082
public void TryReadDoubleTest()
19732083
{

0 commit comments

Comments
 (0)