|
1 | | -namespace AssetRipper.TextureDecoder.Tests |
| 1 | +using AssetRipper.TextureDecoder.Etc; |
| 2 | + |
| 3 | +namespace AssetRipper.TextureDecoder.Tests; |
| 4 | + |
| 5 | +public sealed class EtcTests |
2 | 6 | { |
3 | | - public sealed class EtcTests |
| 7 | + [Test] |
| 8 | + public void DecompressETCTest() |
4 | 9 | { |
5 | | - [Test] |
6 | | - public void DecompressETCTest() |
| 10 | + AssertCorrectByteCountReadFor256SquareWithMips(TestFileFolders.EtcTestFiles + "test.etc", (data, size) => |
7 | 11 | { |
8 | | - ReadOnlySpan<byte> data = File.ReadAllBytes(TestFileFolders.EtcTestFiles + "test.etc"); |
9 | | - int totalBytesRead = 0; |
10 | | - foreach (int size in new int[] { 256, 128, 64, 32, 16, 8, 4, 2, 1 }) //mip maps |
11 | | - { |
12 | | - int bytesRead = Etc.EtcDecoder.DecompressETC(data.Slice(totalBytesRead), size, size, out _); |
13 | | - totalBytesRead += bytesRead; |
14 | | - } |
15 | | - Assert.That(totalBytesRead, Is.EqualTo(data.Length)); |
16 | | - } |
| 12 | + return EtcDecoder.DecompressETC(data, size, size, out _); |
| 13 | + }); |
| 14 | + } |
17 | 15 |
|
18 | | - [Test] |
19 | | - public void DecompressETC2Test() |
| 16 | + [Test] |
| 17 | + public void DecompressETC2Test() |
| 18 | + { |
| 19 | + AssertCorrectByteCountReadFor256SquareWithMips(TestFileFolders.EtcTestFiles + "test.etc2", (data, size) => |
20 | 20 | { |
21 | | - ReadOnlySpan<byte> data = File.ReadAllBytes(TestFileFolders.EtcTestFiles + "test.etc2"); |
22 | | - int totalBytesRead = 0; |
23 | | - foreach (int size in new int[] { 256, 128, 64, 32, 16, 8, 4, 2, 1 }) //mip maps |
24 | | - { |
25 | | - int bytesRead = Etc.EtcDecoder.DecompressETC2(data.Slice(totalBytesRead), size, size, out _); |
26 | | - totalBytesRead += bytesRead; |
27 | | - } |
28 | | - Assert.That(totalBytesRead, Is.EqualTo(data.Length)); |
29 | | - } |
| 21 | + return EtcDecoder.DecompressETC2(data, size, size, out _); |
| 22 | + }); |
| 23 | + } |
30 | 24 |
|
31 | | - [Test] |
32 | | - public void DecompressETC2A1Test() |
| 25 | + [Test] |
| 26 | + public void DecompressETC2A1Test() |
| 27 | + { |
| 28 | + AssertCorrectByteCountReadFor256SquareWithMips(TestFileFolders.EtcTestFiles + "test.etc2a1", (data, size) => |
33 | 29 | { |
34 | | - ReadOnlySpan<byte> data = File.ReadAllBytes(TestFileFolders.EtcTestFiles + "test.etc2a1"); |
35 | | - int totalBytesRead = 0; |
36 | | - foreach (int size in new int[] { 256, 128, 64, 32, 16, 8, 4, 2, 1 }) //mip maps |
37 | | - { |
38 | | - int bytesRead = Etc.EtcDecoder.DecompressETC2A1(data.Slice(totalBytesRead), size, size, out _); |
39 | | - totalBytesRead += bytesRead; |
40 | | - } |
41 | | - Assert.That(totalBytesRead, Is.EqualTo(data.Length)); |
42 | | - } |
| 30 | + return EtcDecoder.DecompressETC2A1(data, size, size, out _); |
| 31 | + }); |
| 32 | + } |
43 | 33 |
|
44 | | - [Test] |
45 | | - public void DecompressETC2A8Test() |
| 34 | + [Test] |
| 35 | + public void DecompressETC2A8Test() |
| 36 | + { |
| 37 | + AssertCorrectByteCountReadFor256SquareWithMips(TestFileFolders.EtcTestFiles + "test.etc2a8", (data, size) => |
46 | 38 | { |
47 | | - ReadOnlySpan<byte> data = File.ReadAllBytes(TestFileFolders.EtcTestFiles + "test.etc2a8"); |
48 | | - int totalBytesRead = 0; |
49 | | - foreach (int size in new int[] { 256, 128, 64, 32, 16, 8, 4, 2, 1 }) //mip maps |
50 | | - { |
51 | | - int bytesRead = Etc.EtcDecoder.DecompressETC2A8(data.Slice(totalBytesRead), size, size, out _); |
52 | | - totalBytesRead += bytesRead; |
53 | | - } |
54 | | - Assert.That(totalBytesRead, Is.EqualTo(data.Length)); |
55 | | - } |
| 39 | + return EtcDecoder.DecompressETC2A8(data, size, size, out _); |
| 40 | + }); |
| 41 | + } |
56 | 42 |
|
57 | | - [Test] |
58 | | - public void DecompressEACRSignedTest() |
| 43 | + [Test] |
| 44 | + public void DecompressEACRSignedTest() |
| 45 | + { |
| 46 | + AssertCorrectByteCountReadFor256SquareWithMips(TestFileFolders.EtcTestFiles + "test.eac_r", (data, size) => |
59 | 47 | { |
60 | | - ReadOnlySpan<byte> data = File.ReadAllBytes(TestFileFolders.EtcTestFiles + "test.eac_r"); |
61 | | - int totalBytesRead = 0; |
62 | | - foreach (int size in new int[] { 256, 128, 64, 32, 16, 8, 4, 2, 1 }) //mip maps |
63 | | - { |
64 | | - int bytesRead = Etc.EtcDecoder.DecompressEACRSigned(data.Slice(totalBytesRead), size, size, out _); |
65 | | - totalBytesRead += bytesRead; |
66 | | - } |
67 | | - Assert.That(totalBytesRead, Is.EqualTo(data.Length)); |
68 | | - } |
| 48 | + return EtcDecoder.DecompressEACRSigned(data, size, size, out _); |
| 49 | + }); |
| 50 | + } |
69 | 51 |
|
70 | | - [Test] |
71 | | - public void DecompressEACRUnsignedTest() |
| 52 | + [Test] |
| 53 | + public void DecompressEACRUnsignedTest() |
| 54 | + { |
| 55 | + AssertCorrectByteCountReadFor256SquareWithMips(TestFileFolders.EtcTestFiles + "test.eac_r", (data, size) => |
72 | 56 | { |
73 | | - ReadOnlySpan<byte> data = File.ReadAllBytes(TestFileFolders.EtcTestFiles + "test.eac_r"); |
74 | | - int totalBytesRead = 0; |
75 | | - foreach (int size in new int[] { 256, 128, 64, 32, 16, 8, 4, 2, 1 }) //mip maps |
76 | | - { |
77 | | - int bytesRead = Etc.EtcDecoder.DecompressEACRUnsigned(data.Slice(totalBytesRead), size, size, out _); |
78 | | - totalBytesRead += bytesRead; |
79 | | - } |
80 | | - Assert.That(totalBytesRead, Is.EqualTo(data.Length)); |
81 | | - } |
| 57 | + return EtcDecoder.DecompressEACRUnsigned(data, size, size, out _); |
| 58 | + }); |
| 59 | + } |
82 | 60 |
|
83 | | - [Test] |
84 | | - public void DecompressEACRGSignedTest() |
| 61 | + [Test] |
| 62 | + public void DecompressEACRGSignedTest() |
| 63 | + { |
| 64 | + AssertCorrectByteCountReadFor256SquareWithMips(TestFileFolders.EtcTestFiles + "test.eac_rg", (data, size) => |
85 | 65 | { |
86 | | - ReadOnlySpan<byte> data = File.ReadAllBytes(TestFileFolders.EtcTestFiles + "test.eac_rg"); |
87 | | - int totalBytesRead = 0; |
88 | | - foreach (int size in new int[] { 256, 128, 64, 32, 16, 8, 4, 2, 1 }) //mip maps |
89 | | - { |
90 | | - int bytesRead = Etc.EtcDecoder.DecompressEACRGSigned(data.Slice(totalBytesRead), size, size, out _); |
91 | | - totalBytesRead += bytesRead; |
92 | | - } |
93 | | - Assert.That(totalBytesRead, Is.EqualTo(data.Length)); |
94 | | - } |
95 | | - |
96 | | - [Test] |
97 | | - public void DecompressEACRGUnsignedTest() |
| 66 | + return EtcDecoder.DecompressEACRGSigned(data, size, size, out _); |
| 67 | + }); |
| 68 | + } |
| 69 | + |
| 70 | + [Test] |
| 71 | + public void DecompressEACRGUnsignedTest() |
| 72 | + { |
| 73 | + AssertCorrectByteCountReadFor256SquareWithMips(TestFileFolders.EtcTestFiles + "test.eac_rg", (data, size) => |
| 74 | + { |
| 75 | + return EtcDecoder.DecompressEACRGUnsigned(data, size, size, out _); |
| 76 | + }); |
| 77 | + } |
| 78 | + |
| 79 | + private delegate int DecodingDelegate(ArraySegment<byte> data, int size); |
| 80 | + |
| 81 | + private static void AssertCorrectByteCountReadFor256SquareWithMips(string path, DecodingDelegate decoder) |
| 82 | + { |
| 83 | + byte[] data = File.ReadAllBytes(path); |
| 84 | + int totalBytesRead = 0; |
| 85 | + foreach (int size in new int[] { 256, 128, 64, 32, 16, 8, 4, 2, 1 }) //mip maps |
98 | 86 | { |
99 | | - ReadOnlySpan<byte> data = File.ReadAllBytes(TestFileFolders.EtcTestFiles + "test.eac_rg"); |
100 | | - int totalBytesRead = 0; |
101 | | - foreach (int size in new int[] { 256, 128, 64, 32, 16, 8, 4, 2, 1 }) //mip maps |
102 | | - { |
103 | | - int bytesRead = Etc.EtcDecoder.DecompressEACRGUnsigned(data.Slice(totalBytesRead), size, size, out _); |
104 | | - totalBytesRead += bytesRead; |
105 | | - } |
106 | | - Assert.That(totalBytesRead, Is.EqualTo(data.Length)); |
| 87 | + int bytesRead = decoder.Invoke(new ArraySegment<byte>(data, totalBytesRead, data.Length - totalBytesRead), size); |
| 88 | + totalBytesRead += bytesRead; |
107 | 89 | } |
| 90 | + Assert.That(totalBytesRead, Is.EqualTo(data.Length)); |
108 | 91 | } |
109 | 92 | } |
0 commit comments