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

Implement further tests and cleanup connection init parsing

parent 0ea27011
No related branches found
No related tags found
No related merge requests found
/*
* Quasseldroid - Quassel client for Android
*
* Copyright (c) 2020 Janne Mareike Koschinski
* Copyright (c) 2020 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.serializers.primitive
import de.kuschku.libquassel.protocol.serializers.QuasselSerializers
import de.kuschku.libquassel.protocol.testutil.byteBufferOf
import de.kuschku.libquassel.protocol.testutil.quasselSerializerTest
import de.kuschku.libquassel.protocol.types.DccIpDetectionMode
import de.kuschku.libquassel.protocol.types.DccPortSelectionMode
import de.kuschku.libquassel.protocol.variant.QuasselType
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Test
class DccIpDetectionModeSerializerTest {
@Test
fun testIsRegistered() {
assertEquals(
DccIpDetectionModeSerializer,
QuasselSerializers.find<DccIpDetectionMode>(
QuasselType.DccConfigIpDetectionMode
),
)
}
@Test
fun testAutomatic() = quasselSerializerTest(
DccIpDetectionModeSerializer,
DccIpDetectionMode.Automatic,
byteBufferOf(0x00u)
)
@Test
fun testManual() = quasselSerializerTest(
DccIpDetectionModeSerializer,
DccIpDetectionMode.Manual,
byteBufferOf(0x01u)
)
}
/*
* Quasseldroid - Quassel client for Android
*
* Copyright (c) 2020 Janne Mareike Koschinski
* Copyright (c) 2020 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.serializers.primitive
import de.kuschku.libquassel.protocol.serializers.QuasselSerializers
import de.kuschku.libquassel.protocol.testutil.byteBufferOf
import de.kuschku.libquassel.protocol.testutil.quasselSerializerTest
import de.kuschku.libquassel.protocol.types.DccIpDetectionMode
import de.kuschku.libquassel.protocol.types.DccPortSelectionMode
import de.kuschku.libquassel.protocol.variant.QuasselType
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Test
class DccPortSelectionModeSerializerTest {
@Test
fun testIsRegistered() {
assertEquals(
DccPortSelectionModeSerializer,
QuasselSerializers.find<DccPortSelectionMode>(
QuasselType.DccConfigPortSelectionMode
),
)
}
@Test
fun testAutomatic() = quasselSerializerTest(
DccPortSelectionModeSerializer,
DccPortSelectionMode.Automatic,
byteBufferOf(0x00u)
)
@Test
fun testManual() = quasselSerializerTest(
DccPortSelectionModeSerializer,
DccPortSelectionMode.Manual,
byteBufferOf(0x01u)
)
}
/*
* Quasseldroid - Quassel client for Android
*
* Copyright (c) 2020 Janne Mareike Koschinski
* Copyright (c) 2020 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.serializers.primitive
import de.kuschku.libquassel.protocol.serializers.QuasselSerializers
import de.kuschku.libquassel.protocol.testutil.byteBufferOf
import de.kuschku.libquassel.protocol.testutil.quasselSerializerTest
import de.kuschku.libquassel.protocol.variant.QuasselType
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Test
import java.net.Inet4Address
import java.net.Inet6Address
import java.net.InetAddress
class QHostAddressSerializerTest {
@Test
fun testIsRegistered() {
assertEquals(
QHostAddressSerializer,
QuasselSerializers.find<InetAddress>(
QuasselType.QHostAddress
),
)
}
@Test
fun testIpv4() = quasselSerializerTest(
QHostAddressSerializer,
Inet4Address.getByAddress(byteArrayOf(
127, 0, 0, 1
)),
byteBufferOf(
0x00,
127, 0, 0, 1
)
)
@Test
fun testIpv6() = quasselSerializerTest(
QHostAddressSerializer,
Inet6Address.getByAddress(ubyteArrayOf(
0x26u, 0x07u, 0xf1u, 0x88u, 0x00u, 0x00u, 0x00u, 0x00u, 0xdeu, 0xadu, 0xbeu, 0xefu, 0xcau, 0xfeu, 0xfeu, 0xd1u,
).toByteArray()),
byteBufferOf(
0x01u,
0x26u, 0x07u, 0xf1u, 0x88u, 0x00u, 0x00u, 0x00u, 0x00u, 0xdeu, 0xadu, 0xbeu, 0xefu, 0xcau, 0xfeu, 0xfeu, 0xd1u,
)
)
}
......@@ -22,13 +22,14 @@ import de.kuschku.libquassel.protocol.features.FeatureSet
import de.kuschku.libquassel.protocol.serializers.handshake.HandshakeSerializer
import de.kuschku.libquassel.protocol.serializers.primitive.HandshakeMapSerializer
import de.kuschku.libquassel.protocol.serializers.primitive.QtSerializer
import de.kuschku.libquassel.protocol.serializers.primitive.Serializer
import org.hamcrest.Matcher
import org.hamcrest.MatcherAssert.assertThat
import org.junit.jupiter.api.Assertions.assertEquals
import java.nio.ByteBuffer
fun <T> deserialize(
serializer: QtSerializer<T>,
serializer: Serializer<T>,
buffer: ByteBuffer,
featureSet: FeatureSet = FeatureSet.all()
): T {
......@@ -38,7 +39,7 @@ fun <T> deserialize(
}
fun <T> testDeserialize(
serializer: QtSerializer<T>,
serializer: Serializer<T>,
matcher: Matcher<in T>,
buffer: ByteBuffer,
featureSet: FeatureSet = FeatureSet.all()
......@@ -48,7 +49,7 @@ fun <T> testDeserialize(
}
fun <T> testDeserialize(
serializer: QtSerializer<T>,
serializer: Serializer<T>,
data: T,
buffer: ByteBuffer,
featureSet: FeatureSet = FeatureSet.all()
......
......@@ -23,6 +23,7 @@ import de.kuschku.libquassel.protocol.io.ChainedByteBuffer
import de.kuschku.libquassel.protocol.serializers.handshake.HandshakeSerializer
import de.kuschku.libquassel.protocol.serializers.primitive.HandshakeMapSerializer
import de.kuschku.libquassel.protocol.serializers.primitive.QtSerializer
import de.kuschku.libquassel.protocol.serializers.primitive.Serializer
import de.kuschku.libquassel.protocol.testutil.matchers.ByteBufferMatcher
import org.hamcrest.Matcher
import org.hamcrest.MatcherAssert.assertThat
......@@ -30,7 +31,7 @@ import org.junit.jupiter.api.Assertions.assertEquals
import java.nio.ByteBuffer
fun <T> serialize(
serializer: QtSerializer<T>,
serializer: Serializer<T>,
data: T,
featureSet: FeatureSet = FeatureSet.all()
): ByteBuffer {
......@@ -40,7 +41,7 @@ fun <T> serialize(
}
fun <T> testSerialize(
serializer: QtSerializer<T>,
serializer: Serializer<T>,
data: T,
buffer: ByteBuffer,
featureSet: FeatureSet = FeatureSet.all()
......
/*
* 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.serializers.primitive.Serializer
import org.hamcrest.Matcher
import java.nio.ByteBuffer
fun <T : Any?> serializerTest(
serializer: Serializer<T>,
value: T,
encoded: ByteBuffer? = null,
matcher: ((T) -> Matcher<T>)? = null,
deserializeFeatureSet: FeatureSet? = FeatureSet.all(),
serializeFeatureSet: FeatureSet? = FeatureSet.all(),
) {
if (encoded != null) {
if (deserializeFeatureSet != null) {
if (matcher != null) {
testDeserialize(serializer, matcher(value), encoded.rewind(), deserializeFeatureSet)
} else {
testDeserialize(serializer, value, encoded.rewind(), deserializeFeatureSet)
}
}
if (serializeFeatureSet != null) {
testSerialize(serializer, value, encoded.rewind(), serializeFeatureSet)
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment