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

Further tests

parent 00aa4fb3
No related branches found
No related tags found
1 merge request!2Draft: Jetpack compose rewrite
Pipeline #577 passed
......@@ -16,25 +16,22 @@
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package de.kuschku.libquassel.protocol.testutil
import de.kuschku.libquassel.protocol.features.FeatureSet
import de.kuschku.libquassel.protocol.io.ChainedByteBuffer
import de.kuschku.libquassel.protocol.io.print
import de.kuschku.libquassel.protocol.serializers.handshake.HandshakeSerializer
import de.kuschku.libquassel.protocol.serializers.primitive.QtSerializer
import org.hamcrest.Matcher
import org.hamcrest.MatcherAssert
import org.junit.Assert
import org.hamcrest.MatcherAssert.assertThat
import org.junit.jupiter.api.Assertions.assertEquals
fun <T> testHandshakeSerializerDirect(serializer: HandshakeSerializer<T>, data: T, matcher: Matcher<T>? = null) {
fun <T> testHandshakeSerializerDirect(
serializer: HandshakeSerializer<T>,
data: T,
matcher: Matcher<T>? = null
) {
val after = serializer.deserialize(serializer.serialize(data))
if (matcher != null) {
MatcherAssert.assertThat(data, matcher)
assertThat(after, matcher)
} else {
Assert.assertEquals(data, after)
assertEquals(data, after)
}
}
......@@ -16,34 +16,31 @@
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package de.kuschku.libquassel.protocol.testutil
import de.kuschku.libquassel.protocol.features.FeatureSet
import de.kuschku.libquassel.protocol.io.ChainedByteBuffer
import de.kuschku.libquassel.protocol.io.print
import de.kuschku.libquassel.protocol.serializers.handshake.HandshakeMapSerializer
import de.kuschku.libquassel.protocol.serializers.handshake.HandshakeSerializer
import de.kuschku.libquassel.protocol.serializers.primitive.QtSerializer
import org.hamcrest.Matcher
import org.hamcrest.MatcherAssert
import org.junit.Assert
import org.hamcrest.MatcherAssert.assertThat
import org.junit.jupiter.api.Assertions.assertEquals
fun <T> testHandshakeSerializerEncoded(serializer: HandshakeSerializer<T>, data: T, matcher: Matcher<T>? = null) {
val connectionFeatureSet = FeatureSet.build()
fun <T> testHandshakeSerializerEncoded(
serializer: HandshakeSerializer<T>,
data: T,
featureSet: FeatureSet = FeatureSet.all(),
matcher: Matcher<T>? = null
) {
val buffer = ChainedByteBuffer()
HandshakeMapSerializer.serialize(buffer, serializer.serialize(data), connectionFeatureSet)
HandshakeMapSerializer.serialize(buffer, serializer.serialize(data), featureSet)
val result = buffer.toBuffer()
result.print()
val after = serializer.deserialize(HandshakeMapSerializer.deserialize(result, connectionFeatureSet))
Assert.assertEquals(0, result.remaining())
val after = serializer.deserialize(HandshakeMapSerializer.deserialize(result, featureSet))
assertEquals(0, result.remaining())
if (matcher != null) {
MatcherAssert.assertThat(data, matcher)
assertThat(after, matcher)
} else {
Assert.assertEquals(data, after)
assertEquals(data, after)
}
}
......@@ -16,31 +16,30 @@
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package de.kuschku.libquassel.protocol.testutil
import de.kuschku.libquassel.protocol.features.FeatureSet
import de.kuschku.libquassel.protocol.io.ChainedByteBuffer
import de.kuschku.libquassel.protocol.io.print
import de.kuschku.libquassel.protocol.serializers.primitive.QtSerializer
import org.hamcrest.Matcher
import org.hamcrest.MatcherAssert
import org.junit.Assert
import org.hamcrest.MatcherAssert.assertThat
import org.junit.jupiter.api.Assertions.assertEquals
fun <T> testQtSerializerDirect(serializer: QtSerializer<T>, data: T, matcher: Matcher<T>? = null) {
val connectionFeatureSet = FeatureSet.build()
fun <T> testQtSerializerDirect(
serializer: QtSerializer<T>,
data: T,
featureSet: FeatureSet = FeatureSet.all(),
matcher: Matcher<T>? = null
) {
val buffer = ChainedByteBuffer()
serializer.serialize(buffer, data, connectionFeatureSet)
serializer.serialize(buffer, data, featureSet)
val result = buffer.toBuffer()
result.print()
val after = serializer.deserialize(result, connectionFeatureSet)
Assert.assertEquals(0, result.remaining())
val after = serializer.deserialize(result, featureSet)
assertEquals(0, result.remaining())
if (matcher != null) {
MatcherAssert.assertThat(data, matcher)
assertThat(after, matcher)
} else {
Assert.assertEquals(data, after)
assertEquals(data, after)
}
}
......@@ -16,9 +16,7 @@
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package de.kuschku.libquassel.protocol.testutil
import de.kuschku.libquassel.protocol.features.FeatureSet
import de.kuschku.libquassel.protocol.io.ChainedByteBuffer
import de.kuschku.libquassel.protocol.io.print
......@@ -26,22 +24,25 @@ import de.kuschku.libquassel.protocol.serializers.primitive.QVariantSerializer
import de.kuschku.libquassel.protocol.serializers.primitive.QtSerializer
import de.kuschku.libquassel.protocol.variant.QVariant
import org.hamcrest.Matcher
import org.hamcrest.MatcherAssert
import org.junit.Assert
import org.hamcrest.MatcherAssert.assertThat
import org.junit.jupiter.api.Assertions.assertEquals
fun <T> testQtSerializerVariant(serializer: QtSerializer<T>, data: T, matcher: Matcher<in T>? = null) {
val connectionFeatureSet = FeatureSet.build()
fun <T> testQtSerializerVariant(
serializer: QtSerializer<T>,
data: T,
featureSet: FeatureSet = FeatureSet.all(),
matcher: Matcher<in T>? = null
) {
val buffer = ChainedByteBuffer()
QVariantSerializer.serialize(buffer, QVariant.of(data, serializer), connectionFeatureSet)
QVariantSerializer.serialize(buffer, QVariant.of(data, serializer), featureSet)
val result = buffer.toBuffer()
result.print()
val after = QVariantSerializer.deserialize(result, connectionFeatureSet)
Assert.assertEquals(0, result.remaining())
val after = QVariantSerializer.deserialize(result, featureSet)
assertEquals(0, result.remaining())
if (matcher != null) {
MatcherAssert.assertThat(data, matcher)
@Suppress("UNCHECKED_CAST")
assertThat(after.value() as T, matcher)
} else {
Assert.assertEquals(data, after.value())
assertEquals(data, after.value())
}
}
/*
* Quasseldroid - Quassel client for Android
*
* Copyright (c) 2021 Janne Mareike Koschinski
* Copyright (c) 2021 The Quassel Project
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 3 as published
* by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package de.kuschku.libquassel.protocol.testutil
import de.kuschku.libquassel.protocol.features.FeatureSet
import de.kuschku.libquassel.protocol.io.ChainedByteBuffer
import de.kuschku.libquassel.protocol.io.print
import de.kuschku.libquassel.protocol.serializers.primitive.QuasselSerializer
import org.hamcrest.Matcher
import org.hamcrest.MatcherAssert.assertThat
import org.junit.jupiter.api.Assertions.assertEquals
fun <T> testQuasselSerializerDirect(
serializer: QuasselSerializer<T>,
data: T,
featureSet: FeatureSet = FeatureSet.all(),
matcher: Matcher<T>? = null
) {
val buffer = ChainedByteBuffer()
serializer.serialize(buffer, data, featureSet)
val result = buffer.toBuffer()
println("direct")
result.print()
val after = serializer.deserialize(result, featureSet)
assertEquals(0, result.remaining())
if (matcher != null) {
assertThat(after, matcher)
} else {
assertEquals(data, after)
}
}
/*
* Quasseldroid - Quassel client for Android
*
* Copyright (c) 2021 Janne Mareike Koschinski
* Copyright (c) 2021 The Quassel Project
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 3 as published
* by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package de.kuschku.libquassel.protocol.testutil
import de.kuschku.libquassel.protocol.features.FeatureSet
import de.kuschku.libquassel.protocol.io.ChainedByteBuffer
import de.kuschku.libquassel.protocol.io.print
import de.kuschku.libquassel.protocol.serializers.primitive.QVariantSerializer
import de.kuschku.libquassel.protocol.serializers.primitive.QuasselSerializer
import de.kuschku.libquassel.protocol.variant.QVariant
import org.hamcrest.Matcher
import org.hamcrest.MatcherAssert.assertThat
import org.junit.jupiter.api.Assertions.assertEquals
fun <T> testQuasselSerializerVariant(
serializer: QuasselSerializer<T>,
data: T,
featureSet: FeatureSet = FeatureSet.all(),
matcher: Matcher<in T>? = null
) {
val buffer = ChainedByteBuffer()
QVariantSerializer.serialize(buffer, QVariant.of(data, serializer), featureSet)
val result = buffer.toBuffer()
result.print()
val after = QVariantSerializer.deserialize(result, featureSet)
assertEquals(0, result.remaining())
if (matcher != null) {
@Suppress("UNCHECKED_CAST")
assertThat(after.value() as T, matcher)
} else {
assertEquals(data, after.value())
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment