|
1 |
| -using libsignalservice.messages.multidevice; |
2 |
| -using Microsoft.VisualStudio.TestTools.UnitTesting; |
3 |
| -using System; |
4 |
| -using System.Collections.Generic; |
5 |
| -using System.IO; |
6 |
| -using System.Text; |
7 |
| - |
8 |
| -namespace libsignal_service_dotnet_tests |
9 |
| -{ |
10 |
| - [TestClass] |
11 |
| - public class ChunkedInputStreamTest |
12 |
| - { |
13 |
| - [TestMethod] |
14 |
| - public void TestReadRawVarint32() |
15 |
| - { |
16 |
| - MemoryStream ms = new MemoryStream(); |
17 |
| - byte[] input; |
18 |
| - int i; |
19 |
| - |
20 |
| - input = new byte[] { 216, 1, 0, 0, 0, 0, 0,}; |
21 |
| - ms.Write(input, 0, input.Length); |
22 |
| - ms.Position = 0; |
23 |
| - |
24 |
| - i = new ChunkedInputStream(ms).ReadRawVarint32(); |
25 |
| - ms.Position = 0; |
26 |
| - Assert.AreEqual(216, i); |
27 |
| - |
28 |
| - |
29 |
| - input = new byte[] { 172, 2, 0xff, 0xff, 0, 0, 0, }; |
30 |
| - ms.Write(input, 0, input.Length); |
31 |
| - ms.Position = 0; |
32 |
| - |
33 |
| - i = new ChunkedInputStream(ms).ReadRawVarint32(); |
34 |
| - ms.Position = 0; |
35 |
| - Assert.AreEqual(300, i); |
36 |
| - |
37 |
| - |
38 |
| - input = new byte[] { 5, 0xff, 0xff, 0xff, 0, 0, 0, }; |
39 |
| - ms.Write(input, 0, input.Length); |
40 |
| - ms.Position = 0; |
41 |
| - |
42 |
| - i = new ChunkedInputStream(ms).ReadRawVarint32(); |
43 |
| - ms.Position = 0; |
44 |
| - Assert.AreEqual(5, i); |
45 |
| - |
46 |
| - |
47 |
| - input = new byte[] { 199, 232, 67, 0xff, 0, 0, 0, }; |
48 |
| - ms.Write(input, 0, input.Length); |
49 |
| - ms.Position = 0; |
50 |
| - |
51 |
| - i = new ChunkedInputStream(ms).ReadRawVarint32(); |
52 |
| - ms.Position = 0; |
53 |
| - Assert.AreEqual(1111111, i); |
54 |
| - |
55 |
| - |
56 |
| - input = new byte[] { 128, 1, 0xff, 0xff, 0, 0, 0, }; |
57 |
| - ms.Write(input, 0, input.Length); |
58 |
| - ms.Position = 0; |
59 |
| - |
60 |
| - i = new ChunkedInputStream(ms).ReadRawVarint32(); |
61 |
| - ms.Position = 0; |
62 |
| - Assert.AreEqual(128, i); |
63 |
| - } |
64 |
| - } |
65 |
| -} |
| 1 | +using System.IO; |
| 2 | +using libsignalservice.messages.multidevice; |
| 3 | +using Microsoft.VisualStudio.TestTools.UnitTesting; |
| 4 | + |
| 5 | +namespace libsignal_service_dotnet_tests |
| 6 | +{ |
| 7 | + [TestClass] |
| 8 | + public class ChunkedInputStreamTests |
| 9 | + { |
| 10 | + [TestMethod] |
| 11 | + public void TestReadRawVarint32() |
| 12 | + { |
| 13 | + MemoryStream ms = new MemoryStream(); |
| 14 | + byte[] input; |
| 15 | + int i; |
| 16 | + |
| 17 | + input = new byte[] { 216, 1, 0, 0, 0, 0, 0,}; |
| 18 | + ms.Write(input, 0, input.Length); |
| 19 | + ms.Position = 0; |
| 20 | + |
| 21 | + i = new ChunkedInputStream(ms).ReadRawVarint32(); |
| 22 | + ms.Position = 0; |
| 23 | + Assert.AreEqual(216, i); |
| 24 | + |
| 25 | + |
| 26 | + input = new byte[] { 172, 2, 0xff, 0xff, 0, 0, 0, }; |
| 27 | + ms.Write(input, 0, input.Length); |
| 28 | + ms.Position = 0; |
| 29 | + |
| 30 | + i = new ChunkedInputStream(ms).ReadRawVarint32(); |
| 31 | + ms.Position = 0; |
| 32 | + Assert.AreEqual(300, i); |
| 33 | + |
| 34 | + |
| 35 | + input = new byte[] { 5, 0xff, 0xff, 0xff, 0, 0, 0, }; |
| 36 | + ms.Write(input, 0, input.Length); |
| 37 | + ms.Position = 0; |
| 38 | + |
| 39 | + i = new ChunkedInputStream(ms).ReadRawVarint32(); |
| 40 | + ms.Position = 0; |
| 41 | + Assert.AreEqual(5, i); |
| 42 | + |
| 43 | + |
| 44 | + input = new byte[] { 199, 232, 67, 0xff, 0, 0, 0, }; |
| 45 | + ms.Write(input, 0, input.Length); |
| 46 | + ms.Position = 0; |
| 47 | + |
| 48 | + i = new ChunkedInputStream(ms).ReadRawVarint32(); |
| 49 | + ms.Position = 0; |
| 50 | + Assert.AreEqual(1111111, i); |
| 51 | + |
| 52 | + |
| 53 | + input = new byte[] { 128, 1, 0xff, 0xff, 0, 0, 0, }; |
| 54 | + ms.Write(input, 0, input.Length); |
| 55 | + ms.Position = 0; |
| 56 | + |
| 57 | + i = new ChunkedInputStream(ms).ReadRawVarint32(); |
| 58 | + ms.Position = 0; |
| 59 | + Assert.AreEqual(128, i); |
| 60 | + } |
| 61 | + } |
| 62 | +} |
0 commit comments