Open-source multiplayer game server compatible with the RuneScape client https://www.openrs2.org/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
openrs2/util/src/test/kotlin/org/openrs2/util/io/SkipOutputStreamTest.kt

71 lines
2.0 KiB

package org.openrs2.util.io
import org.junit.jupiter.api.Assertions.assertArrayEquals
import java.io.ByteArrayOutputStream
import java.io.FilterOutputStream
import java.io.OutputStream
import kotlin.test.Test
import kotlin.test.assertTrue
class SkipOutputStreamTest {
@Test
fun testSkipBytes() {
for (n in 0..5) {
val expected = byteArrayOf(1, 2, 3, 4, 5).drop(n).toByteArray()
ByteArrayOutputStream().use { out ->
SkipOutputStream(out, n.toLong()).use { skip ->
skip.write(1)
skip.write(2)
skip.write(3)
skip.write(4)
skip.write(5)
}
assertArrayEquals(expected, out.toByteArray())
}
ByteArrayOutputStream().use { out ->
SkipOutputStream(out, n.toLong()).use { skip ->
skip.write(byteArrayOf(1, 2, 3, 4, 5))
}
assertArrayEquals(expected, out.toByteArray())
}
ByteArrayOutputStream().use { out ->
SkipOutputStream(out, n.toLong()).use { skip ->
skip.write(byteArrayOf(1, 2, 3))
skip.write(byteArrayOf(4, 5))
}
assertArrayEquals(expected, out.toByteArray())
}
ByteArrayOutputStream().use { out ->
SkipOutputStream(out, n.toLong()).use { skip ->
skip.write(byteArrayOf(0, 1, 2, 3, 4, 5, 6), 1, 5)
}
assertArrayEquals(expected, out.toByteArray())
}
}
}
@Test
fun testFlush() {
val out = object : FilterOutputStream(OutputStream.nullOutputStream()) {
var flushed = false
override fun flush() {
flushed = true
}
}
SkipOutputStream(out, 0).use { skip ->
skip.flush()
}
assertTrue(out.flushed)
}
}