-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
289 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
package library | ||
|
||
public class ParseException(public val position: Long, msg: String, e: Exception) : RuntimeException(msg, e) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package dltcore | ||
|
||
import assertk.assertThat | ||
import assertk.assertions.isEqualTo | ||
import org.junit.Test | ||
|
||
class DltExtensionsTest { | ||
@Test | ||
fun `test int to string`() { | ||
assertThat(0x30313233.asStringValue()).isEqualTo("0123") | ||
assertThat(0x30313200.asStringValue()).isEqualTo("012") | ||
assertThat(0x30310000.asStringValue()).isEqualTo("01") | ||
assertThat(0x30000000.asStringValue()).isEqualTo("0") | ||
assertThat(0x00000000.asStringValue()).isEqualTo("") | ||
} | ||
|
||
@Test | ||
fun `test string to int`() { | ||
assertThat("1234".asIntValue()).isEqualTo(0x31323334) | ||
assertThat("123".asIntValue()).isEqualTo(0x31323300) | ||
assertThat("12".asIntValue()).isEqualTo(0x31320000) | ||
assertThat("1".asIntValue()).isEqualTo(0x31000000) | ||
} | ||
} |
151 changes: 151 additions & 0 deletions
151
src/test/kotlin/library/ByteBufferBinaryInputStreamTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,151 @@ | ||
package library | ||
|
||
import assertk.assertFailure | ||
import assertk.assertThat | ||
import assertk.assertions.hasClass | ||
import assertk.assertions.isEqualTo | ||
import assertk.assertions.isFalse | ||
import assertk.assertions.isTrue | ||
import org.junit.Test | ||
import java.nio.BufferUnderflowException | ||
|
||
class ByteBufferBinaryInputStreamTest { | ||
@Test | ||
fun `test byte`() { | ||
ByteBufferBinaryInputStream(createSequencedByteBuffer(4)).let { | ||
it.order(ByteOrder.BIG_ENDIAN) | ||
assertThat(it.hasRemaining()).isTrue() | ||
assertThat(it.position()).isEqualTo(0) | ||
assertThat(it.readByte()).isEqualTo(0x00) | ||
assertThat(it.readByte()).isEqualTo(0x01) | ||
assertThat(it.readByte()).isEqualTo(0x02) | ||
assertThat(it.readByte()).isEqualTo(0x03) | ||
assertThat(it.hasRemaining()).isFalse() | ||
assertFailure { | ||
it.readByte() | ||
}.hasClass(BufferUnderflowException::class) | ||
} | ||
|
||
ByteBufferBinaryInputStream(createSequencedByteBuffer(4)).let { | ||
it.order(ByteOrder.LITTLE_ENDIAN) | ||
assertThat(it.hasRemaining()).isTrue() | ||
assertThat(it.position()).isEqualTo(0) | ||
assertThat(it.readByte()).isEqualTo(0x00) | ||
assertThat(it.readByte()).isEqualTo(0x01) | ||
assertThat(it.readByte()).isEqualTo(0x02) | ||
assertThat(it.readByte()).isEqualTo(0x03) | ||
assertThat(it.hasRemaining()).isFalse() | ||
assertFailure { | ||
it.readByte() | ||
}.hasClass(BufferUnderflowException::class) | ||
} | ||
} | ||
|
||
@Test | ||
fun `test short`() { | ||
ByteBufferBinaryInputStream(createSequencedByteBuffer(4)).let { | ||
it.order(ByteOrder.BIG_ENDIAN) | ||
assertThat(it.hasRemaining()).isTrue() | ||
assertThat(it.position()).isEqualTo(0) | ||
assertThat(it.readShort()).isEqualTo(0x0001) | ||
assertThat(it.hasRemaining()).isTrue() | ||
assertThat(it.position()).isEqualTo(2) | ||
assertThat(it.readShort()).isEqualTo(0x0203) | ||
assertThat(it.hasRemaining()).isFalse() | ||
assertFailure { | ||
it.readShort() | ||
}.hasClass(BufferUnderflowException::class) | ||
} | ||
|
||
ByteBufferBinaryInputStream(createSequencedByteBuffer(4)).let { | ||
it.order(ByteOrder.LITTLE_ENDIAN) | ||
assertThat(it.hasRemaining()).isTrue() | ||
assertThat(it.position()).isEqualTo(0) | ||
assertThat(it.readShort()).isEqualTo(0x0100) | ||
assertThat(it.hasRemaining()).isTrue() | ||
assertThat(it.position()).isEqualTo(2) | ||
assertThat(it.readShort()).isEqualTo(0x0302) | ||
assertThat(it.hasRemaining()).isFalse() | ||
assertFailure { | ||
it.readShort() | ||
}.hasClass(BufferUnderflowException::class) | ||
} | ||
} | ||
|
||
@Test | ||
fun `test int`() { | ||
ByteBufferBinaryInputStream(createSequencedByteBuffer(8)).let { | ||
it.order(ByteOrder.BIG_ENDIAN) | ||
assertThat(it.hasRemaining()).isTrue() | ||
assertThat(it.position()).isEqualTo(0) | ||
assertThat(it.readInt()).isEqualTo(0x00010203) | ||
assertThat(it.hasRemaining()).isTrue() | ||
assertThat(it.position()).isEqualTo(4) | ||
assertThat(it.readInt()).isEqualTo(0x04050607) | ||
assertThat(it.hasRemaining()).isFalse() | ||
assertFailure { | ||
it.readInt() | ||
}.hasClass(BufferUnderflowException::class) | ||
} | ||
|
||
ByteBufferBinaryInputStream(createSequencedByteBuffer(8)).let { | ||
it.order(ByteOrder.LITTLE_ENDIAN) | ||
assertThat(it.hasRemaining()).isTrue() | ||
assertThat(it.position()).isEqualTo(0) | ||
assertThat(it.readInt()).isEqualTo(0x03020100) | ||
assertThat(it.hasRemaining()).isTrue() | ||
assertThat(it.position()).isEqualTo(4) | ||
assertThat(it.readInt()).isEqualTo(0x07060504) | ||
assertThat(it.hasRemaining()).isFalse() | ||
assertFailure { | ||
it.readInt() | ||
}.hasClass(BufferUnderflowException::class) | ||
} | ||
} | ||
|
||
@Test | ||
fun `test long`() { | ||
ByteBufferBinaryInputStream(createSequencedByteBuffer(16)).let { | ||
it.order(ByteOrder.BIG_ENDIAN) | ||
assertThat(it.hasRemaining()).isTrue() | ||
assertThat(it.position()).isEqualTo(0) | ||
assertThat(it.readLong()).isEqualTo(0x0001020304050607) | ||
assertThat(it.hasRemaining()).isTrue() | ||
assertThat(it.position()).isEqualTo(8) | ||
assertThat(it.readLong()).isEqualTo(0x08090a0b0c0d0e0f) | ||
assertThat(it.hasRemaining()).isFalse() | ||
assertFailure { | ||
it.readLong() | ||
}.hasClass(BufferUnderflowException::class) | ||
} | ||
|
||
ByteBufferBinaryInputStream(createSequencedByteBuffer(16)).let { | ||
it.order(ByteOrder.LITTLE_ENDIAN) | ||
assertThat(it.hasRemaining()).isTrue() | ||
assertThat(it.position()).isEqualTo(0) | ||
assertThat(it.readLong()).isEqualTo(0x0706050403020100) | ||
assertThat(it.hasRemaining()).isTrue() | ||
assertThat(it.position()).isEqualTo(8) | ||
assertThat(it.readLong()).isEqualTo(0x0f0e0d0c0b0a0908) | ||
assertThat(it.hasRemaining()).isFalse() | ||
assertFailure { | ||
it.readLong() | ||
}.hasClass(BufferUnderflowException::class) | ||
} | ||
} | ||
|
||
@Test | ||
fun `test array`() { | ||
ByteBufferBinaryInputStream(createSequencedByteBuffer(64)).let { | ||
assertThat(it.readArray(32)).isEqualTo(createSequencedByteArray(32)) | ||
assertThat(it.position()).isEqualTo(32) | ||
assertThat(it.readArray(16)).isEqualTo(createSequencedByteArray(16, 32)) | ||
assertThat(it.position()).isEqualTo(48) | ||
assertThat(it.readArray(16)).isEqualTo(createSequencedByteArray(16, 48)) | ||
assertThat(it.position()).isEqualTo(64) | ||
assertFailure { | ||
it.readArray(1) | ||
}.hasClass(BufferUnderflowException::class) | ||
} | ||
} | ||
} |
Oops, something went wrong.