Skip to content
Snippets Groups Projects
Verified Commit 0ea27011 authored by Janne Mareike Koschinski's avatar Janne Mareike Koschinski
Browse files

Additional testing

parent 3c0e613b
No related branches found
No related tags found
No related merge requests found
Pipeline #583 passed
Showing
with 31 additions and 26 deletions
......@@ -69,7 +69,6 @@ class ExampleUnitTest {
channel.write(sizeBuffer)
sizeBuffer.clear()
}
println(sendBuffer.toBuffer().contentToString())
channel.write(sendBuffer)
channel.flush()
sendBuffer.clear()
......
......@@ -20,6 +20,5 @@
package de.kuschku.bitflags
interface Flags<T, U> where U : Flag<T>, U : Enum<U> {
operator fun get(value: T): U?
val all: Set<U>
}
......@@ -22,5 +22,5 @@ package de.kuschku.codecoverage
/**
* Used to mark inline functions as generated for jacoco
*/
@Retention(AnnotationRetention.SOURCE)
@Retention(AnnotationRetention.RUNTIME)
annotation class Generated
......@@ -78,7 +78,6 @@ enum class LegacyFeature(
fun get(feature: QuasselFeature) = features[feature]
private val values = values().associateBy(LegacyFeature::value)
override fun get(value: UInt) = values[value]
override val all: LegacyFeatures = values.values.toEnumSet()
}
}
......
......@@ -19,6 +19,9 @@
package de.kuschku.libquassel.protocol.features
import de.kuschku.codecoverage.Generated
@Generated
inline class QuasselFeatureName(
val name: String,
)
......
......@@ -21,12 +21,10 @@ package de.kuschku.libquassel.protocol.io
import java.nio.ByteBuffer
fun copyData(from: ByteBuffer, to: ByteBuffer, desiredAmount: Int = -1) {
fun copyData(from: ByteBuffer, to: ByteBuffer, desiredAmount: Int) {
val limit = from.limit()
val availableAmount = minOf(from.remaining(), to.remaining())
val amount =
if (desiredAmount < 0) availableAmount
else minOf(availableAmount, desiredAmount)
val amount = minOf(availableAmount, desiredAmount)
from.limit(from.position() + amount)
to.put(from)
from.limit(limit)
......
......@@ -90,8 +90,11 @@ class ChainedByteBuffer(
val requested = minOf(value.remaining(), chunkSize)
if (bufferList.lastOrNull()?.hasRemaining() != true) {
ensureSpace(requested)
} else {
ensureSpace(minOf(bufferList.last().remaining(), requested))
}
copyData(value, bufferList.last())
copyData(value, bufferList.last(), requested)
}
}
......
......@@ -52,13 +52,21 @@ class StringEncoder(charset: Charset) {
return encodeInternal(charBuffer)
}
fun encodeChar(data: Char?): ByteBuffer {
if (!encoder.canEncode(data ?: '\u0000')) {
return ByteBuffer.allocateDirect(2)
private fun replacementChar(data: Char?): Char {
return if (data == null || !encoder.canEncode(data)) {
if (encoder.canEncode('\uFFFD')) {
'\uFFFD'
} else {
'\u0000'
}
} else {
data
}
}
val charBuffer = charBuffer(2)
charBuffer.put(data ?: '\u0000')
fun encodeChar(data: Char?): ByteBuffer {
val charBuffer = charBuffer(1)
charBuffer.put(replacementChar(data))
charBuffer.flip()
return encodeInternal(charBuffer)
}
......
......@@ -26,7 +26,7 @@ import java.nio.ByteBuffer
object BoolSerializer : QtSerializer<Boolean> {
override val qtType: QtType = QtType.Bool
override val javaType: Class<Boolean> = Boolean::class.java
override val javaType: Class<Boolean> = Boolean::class.javaObjectType
override fun serialize(buffer: ChainedByteBuffer, data: Boolean, featureSet: FeatureSet) {
buffer.put(
......
......@@ -26,7 +26,7 @@ import java.nio.ByteBuffer
object ByteSerializer : QtSerializer<Byte> {
override val qtType: QtType = QtType.Char
override val javaType: Class<Byte> = Byte::class.java
override val javaType: Class<Byte> = Byte::class.javaObjectType
override fun serialize(buffer: ChainedByteBuffer, data: Byte, featureSet: FeatureSet) {
buffer.put(data)
......
......@@ -26,7 +26,7 @@ import java.nio.ByteBuffer
object DoubleSerializer : QtSerializer<Double> {
override val qtType: QtType = QtType.Double
override val javaType: Class<Double> = Double::class.java
override val javaType: Class<Double> = Double::class.javaObjectType
override fun serialize(buffer: ChainedByteBuffer, data: Double, featureSet: FeatureSet) {
buffer.putDouble(data)
......
......@@ -26,7 +26,7 @@ import java.nio.ByteBuffer
object FloatSerializer : QtSerializer<Float> {
override val qtType: QtType = QtType.Float
override val javaType: Class<Float> = Float::class.java
override val javaType: Class<Float> = Float::class.javaObjectType
override fun serialize(buffer: ChainedByteBuffer, data: Float, featureSet: FeatureSet) {
buffer.putFloat(data)
......
......@@ -26,7 +26,7 @@ import java.nio.ByteBuffer
object IntSerializer : QtSerializer<Int> {
override val qtType: QtType = QtType.Int
override val javaType: Class<Int> = Int::class.java
override val javaType: Class<Int> = Int::class.javaObjectType
override fun serialize(buffer: ChainedByteBuffer, data: Int, featureSet: FeatureSet) {
buffer.putInt(data)
......
......@@ -26,7 +26,7 @@ import java.nio.ByteBuffer
object LongSerializer : QtSerializer<Long> {
override val qtType: QtType = QtType.Long
override val javaType: Class<Long> = Long::class.java
override val javaType: Class<Long> = Long::class.javaObjectType
override fun serialize(buffer: ChainedByteBuffer, data: Long, featureSet: FeatureSet) {
buffer.putLong(data)
......
......@@ -28,7 +28,7 @@ import kotlin.concurrent.getOrSet
object QCharSerializer : QtSerializer<Char> {
override val qtType: QtType = QtType.QChar
override val javaType: Class<out Char> = Char::class.java
override val javaType: Class<out Char> = Char::class.javaObjectType
private val encoderLocal = ThreadLocal<StringEncoder>()
private fun encoder() = encoderLocal.getOrSet { StringEncoder(Charsets.UTF_16BE) }
......
......@@ -26,7 +26,7 @@ import java.nio.ByteBuffer
object ShortSerializer : QtSerializer<Short> {
override val qtType: QtType = QtType.Short
override val javaType: Class<Short> = Short::class.java
override val javaType: Class<Short> = Short::class.javaObjectType
override fun serialize(buffer: ChainedByteBuffer, data: Short, featureSet: FeatureSet) {
buffer.putShort(data)
......
......@@ -33,7 +33,6 @@ enum class BufferActivity(
companion object : Flags<UInt, BufferActivity> {
private val values = values().associateBy(BufferActivity::value)
override fun get(value: UInt) = values[value]
override val all: BufferActivities = values.values.toEnumSet()
}
}
......
......@@ -34,7 +34,6 @@ enum class BufferType(
companion object : Flags<UShort, BufferType> {
private val values = values().associateBy(BufferType::value)
override fun get(value: UShort) = values[value]
override val all: BufferTypes = values.values.toEnumSet()
}
}
......
......@@ -34,7 +34,6 @@ enum class MessageFlag(
companion object : Flags<UInt, MessageFlag> {
private val values = values().associateBy(MessageFlag::value)
override fun get(value: UInt) = values[value]
override val all: MessageFlags = values.values.toEnumSet()
}
}
......
......@@ -48,7 +48,6 @@ enum class MessageType(
companion object : Flags<UInt, MessageType> {
private val values = values().associateBy(MessageType::value)
override fun get(value: UInt) = values[value]
override val all: MessageTypes = values.values.toEnumSet()
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment