Mercurial > stress-tester
changeset 676:f1547b730293
NcDataHelper bugfixes
author | Devel 2 |
---|---|
date | Tue, 21 Nov 2017 10:43:31 +0100 |
parents | 1002a35b0cdd |
children | ff5f3f3cdf60 |
files | stress-tester/src/main/java/com/passus/st/reader/nc/NcDataHelper.java stress-tester/src/test/java/com/passus/st/reader/nc/NcDataHelperTest.java |
diffstat | 2 files changed, 18 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/stress-tester/src/main/java/com/passus/st/reader/nc/NcDataHelper.java Tue Nov 21 09:29:19 2017 +0100 +++ b/stress-tester/src/main/java/com/passus/st/reader/nc/NcDataHelper.java Tue Nov 21 10:43:31 2017 +0100 @@ -126,7 +126,7 @@ throw new IndexOutOfBoundsException(); } - data[startIndex] = (byte) bytes; + data[startIndex] = (byte) (0x80 | bytes); startIndex++; DataUtils.putInt(data, startIndex, bytes, value); return bytes + 1; @@ -201,8 +201,8 @@ if (endIndex - startIndex < bytes + 2) { throw new IndexOutOfBoundsException(); } - data[startIndex++] = (byte) (value >> 8); - data[startIndex++] = (byte) value; + data[startIndex++] = (byte) 0x80; + data[startIndex++] = (byte) bytes; DataUtils.putLong(data, startIndex, bytes, value); return bytes + 2;
--- a/stress-tester/src/test/java/com/passus/st/reader/nc/NcDataHelperTest.java Tue Nov 21 09:29:19 2017 +0100 +++ b/stress-tester/src/test/java/com/passus/st/reader/nc/NcDataHelperTest.java Tue Nov 21 10:43:31 2017 +0100 @@ -22,7 +22,7 @@ return new Object[][]{ {new byte[]{0x00}, 1, 0x00}, {new byte[]{0x7F}, 1, 0x7F}, - {new byte[]{(byte) 0x81, (byte) 0x03}, 2, 0x03} + {new byte[]{(byte) 0x81, (byte) 0xFF}, 2, 0xFF} }; } @@ -31,7 +31,7 @@ return new Object[][]{ {new byte[]{0x00, 0x00}, 2, 0x00L}, {new byte[]{0x00, 0x7F}, 2, 0x7FL}, - {new byte[]{(byte) 0x80, 0x01, 0x03}, 3, 0x03L} + {new byte[]{(byte) 0x80, 0x02, (byte) 0x80, 0x01}, 4, 0x8001L} }; } @@ -57,6 +57,13 @@ assertEquals(expectedLength, length.intValue()); } + @Test(dataProvider = "validIntVLC") + public void testWriteIntVLC(byte[] expectedResult, int expectedBytes, int length) { + byte[] result = new byte[expectedResult.length]; + helper.writeIntVLC(length, result); + assertEquals(expectedResult, result); + } + @Test(dataProvider = "validLongVLC") public void testReadLongVLC_ByteBuff(byte[] data, int expectedBytes, long expectedLength) { ByteBuff buff = new HeapByteBuff(); @@ -79,4 +86,10 @@ assertEquals(expectedLength, length.longValue()); } + @Test(dataProvider = "validLongVLC") + public void testWriteLongVLC(byte[] expectedResult, int expectedBytes, long length) { + byte[] result = new byte[expectedResult.length]; + helper.writeLongVLC(length, result); + assertEquals(expectedResult, result); + } }