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
Branches
No related tags found
1 merge request!2Draft: Jetpack compose rewrite
Pipeline #577 passed
Showing
with 386 additions and 153 deletions
......@@ -30,7 +30,7 @@ import kotlin.concurrent.getOrSet
abstract class StringSerializer(
private val charset: Charset,
private val nullLimited: Boolean = false,
private val nullLimited: Boolean,
) : QtSerializer<String?> {
override val qtType = QtType.QString
override val javaType: Class<out String> = String::class.java
......@@ -38,10 +38,8 @@ abstract class StringSerializer(
private val encoderLocal = ThreadLocal<StringEncoder>()
private fun encoder() = encoderLocal.getOrSet { StringEncoder(charset) }
@Suppress("NOTHING_TO_INLINE")
private inline fun addNullBytes(before: Int) = if (nullLimited) before + 1 else before
@Suppress("NOTHING_TO_INLINE")
private inline fun removeNullBytes(before: Int) = if (nullLimited) before - 1 else before
private fun addNullBytes(before: Int) = if (nullLimited) before + 1 else before
private fun removeNullBytes(before: Int) = if (nullLimited) before - 1 else before
override fun serialize(buffer: ChainedByteBuffer, data: String?, featureSet: FeatureSet) {
if (data == null) {
......
......@@ -19,4 +19,4 @@
package de.kuschku.libquassel.protocol.serializers.primitive
object StringSerializerUtf16 : StringSerializer(Charsets.UTF_16BE)
object StringSerializerUtf16 : StringSerializer(Charsets.UTF_16BE, false)
......@@ -19,4 +19,4 @@
package de.kuschku.libquassel.protocol.serializers.primitive
object StringSerializerUtf8 : StringSerializer(Charsets.UTF_8)
object StringSerializerUtf8 : StringSerializer(Charsets.UTF_8, false)
......@@ -30,12 +30,12 @@ object TimeSerializer : QtSerializer<LocalTime> {
override val javaType: Class<out LocalTime> = LocalTime::class.java
override fun serialize(buffer: ChainedByteBuffer, data: LocalTime, featureSet: FeatureSet) {
val millisecondOfDay = (data.toNanoOfDay() / 1000).toInt()
val millisecondOfDay = (data.toNanoOfDay() / 1_000_000).toInt()
IntSerializer.serialize(buffer, millisecondOfDay, featureSet)
}
override fun deserialize(buffer: ByteBuffer, featureSet: FeatureSet): LocalTime {
val millisecondOfDay = IntSerializer.deserialize(buffer, featureSet).toLong()
return LocalTime.ofNanoOfDay(millisecondOfDay * 1000)
return LocalTime.ofNanoOfDay(millisecondOfDay * 1_000_000)
}
}
......@@ -21,6 +21,8 @@ package de.kuschku.libquassel.protocol.types
import de.kuschku.bitflags.Flag
import de.kuschku.bitflags.Flags
import de.kuschku.bitflags.toEnumSet
import de.kuschku.libquassel.protocol.features.LegacyFeature
enum class BufferActivity(
override val value: UInt,
......@@ -33,7 +35,7 @@ enum class BufferActivity(
companion object : Flags<UInt, BufferActivity> {
private val values = values().associateBy(BufferActivity::value)
override fun get(value: UInt) = values[value]
override fun all() = values.values
override val all: BufferActivities = values.values.toEnumSet()
}
}
......
......@@ -19,12 +19,12 @@
package de.kuschku.libquassel.protocol.types
import de.kuschku.bitflags.of
import de.kuschku.bitflags.none
data class BufferInfo(
val bufferId: BufferId = BufferId(-1),
val networkId: NetworkId = NetworkId(-1),
val type: BufferTypes = BufferType.of(),
val type: BufferTypes = BufferType.none(),
val groupId: Int = -1,
val bufferName: String? = null,
)
......@@ -21,6 +21,7 @@ package de.kuschku.libquassel.protocol.types
import de.kuschku.bitflags.Flag
import de.kuschku.bitflags.Flags
import de.kuschku.bitflags.toEnumSet
enum class BufferType(
override val value: UShort,
......@@ -34,7 +35,7 @@ enum class BufferType(
companion object : Flags<UShort, BufferType> {
private val values = values().associateBy(BufferType::value)
override fun get(value: UShort) = values[value]
override fun all() = values.values
override val all: BufferTypes = values.values.toEnumSet()
}
}
......
......@@ -21,6 +21,7 @@ package de.kuschku.libquassel.protocol.types
import de.kuschku.bitflags.Flag
import de.kuschku.bitflags.Flags
import de.kuschku.bitflags.toEnumSet
enum class MessageFlag(
override val value: UInt,
......@@ -34,7 +35,7 @@ enum class MessageFlag(
companion object : Flags<UInt, MessageFlag> {
private val values = values().associateBy(MessageFlag::value)
override fun get(value: UInt) = values[value]
override fun all() = values.values
override val all: MessageFlags = values.values.toEnumSet()
}
}
......
......@@ -21,6 +21,7 @@ package de.kuschku.libquassel.protocol.types
import de.kuschku.bitflags.Flag
import de.kuschku.bitflags.Flags
import de.kuschku.bitflags.toEnumSet
enum class MessageType(
override val value: UInt,
......@@ -48,7 +49,7 @@ enum class MessageType(
companion object : Flags<UInt, MessageType> {
private val values = values().associateBy(MessageType::value)
override fun get(value: UInt) = values[value]
override fun all() = values.values
override val all: MessageTypes = values.values.toEnumSet()
}
}
......
......@@ -38,42 +38,10 @@ sealed class QVariant<T> constructor(
open val serializer: QtSerializer<T>,
) {
class Typed<T> internal constructor(data: T, serializer: QtSerializer<T>) :
QVariant<T>(data, serializer) {
override fun equals(other: Any?): Boolean {
if (this === other) return true
if (other !is Typed<*>) return false
if (data != other.data) return false
if (serializer.qtType != other.serializer.qtType) return false
return true
}
override fun hashCode(): Int {
var result = data?.hashCode() ?: 0
result = 31 * result + serializer.qtType.hashCode()
return result
}
}
QVariant<T>(data, serializer)
class Custom<T> internal constructor(data: T, override val serializer: QuasselSerializer<T>) :
QVariant<T>(data, serializer) {
override fun equals(other: Any?): Boolean {
if (this === other) return true
if (other !is Custom<*>) return false
if (data != other.data) return false
if (serializer.quasselType != other.serializer.quasselType) return false
return true
}
override fun hashCode(): Int {
var result = data?.hashCode() ?: 0
result = 31 * result + serializer.quasselType.hashCode()
return result
}
}
QVariant<T>(data, serializer)
fun value(): T = data
......
......@@ -105,8 +105,7 @@ enum class QtType(val id: kotlin.Int) {
QVariant(138),//, VariantSerializer),
User(256),
UserType(127),
LastType(-1);
UserType(127);
val serializableName =
if (name.startsWith("Q")) name
......
......@@ -37,7 +37,8 @@ enum class QuasselType(
NetworkInfo("NetworkInfo"),
NetworkServer("Network::Server"),
QHostAddress("QHostAddress"),
PeerPtr("PeerPtr");
PeerPtr("PeerPtr"),
Unknown("");
companion object {
private val values = values().associateBy(QuasselType::typeName)
......
......@@ -16,46 +16,37 @@
* 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.handshake
import de.kuschku.bitflags.none
import de.kuschku.libquassel.protocol.features.FeatureSet
import de.kuschku.libquassel.protocol.features.LegacyFeature
import de.kuschku.libquassel.protocol.messages.handshake.ClientInit
import de.kuschku.libquassel.protocol.testutil.byteBufferOf
import de.kuschku.libquassel.protocol.testutil.testDeserialize
import de.kuschku.libquassel.protocol.testutil.testHandshakeSerializerDirect
import de.kuschku.libquassel.protocol.testutil.testHandshakeSerializerEncoded
import org.junit.Test
import de.kuschku.libquassel.protocol.testutil.handshakeSerializerTest
import org.junit.jupiter.api.Test
class ClientInitSerializerTest {
@Test
fun testSimple() {
val value = ClientInit(
fun testSimple() = handshakeSerializerTest(
ClientInitSerializer,
ClientInit(
clientVersion = "Quasseldroid test",
buildDate = "Never",
clientFeatures = flags(),
clientFeatures = LegacyFeature.none(),
featureList = emptyList()
),
byteBufferOf(0x00u, 0x00u, 0x00u, 0x0Au, 0x00u, 0x00u, 0x00u, 0x0Cu, 0x00u, 0x00u, 0x00u, 0x00u, 0x07u, 0x4Du, 0x73u, 0x67u, 0x54u, 0x79u, 0x70u, 0x65u, 0x00u, 0x00u, 0x00u, 0x0Au, 0x00u, 0x00u, 0x00u, 0x00u, 0x14u, 0x00u, 0x43u, 0x00u, 0x6Cu, 0x00u, 0x69u, 0x00u, 0x65u, 0x00u, 0x6Eu, 0x00u, 0x74u, 0x00u, 0x49u, 0x00u, 0x6Eu, 0x00u, 0x69u, 0x00u, 0x74u, 0x00u, 0x00u, 0x00u, 0x0Cu, 0x00u, 0x00u, 0x00u, 0x00u, 0x0Du, 0x43u, 0x6Cu, 0x69u, 0x65u, 0x6Eu, 0x74u, 0x56u, 0x65u, 0x72u, 0x73u, 0x69u, 0x6Fu, 0x6Eu, 0x00u, 0x00u, 0x00u, 0x0Au, 0x00u, 0x00u, 0x00u, 0x00u, 0x22u, 0x00u, 0x51u, 0x00u, 0x75u, 0x00u, 0x61u, 0x00u, 0x73u, 0x00u, 0x73u, 0x00u, 0x65u, 0x00u, 0x6Cu, 0x00u, 0x64u, 0x00u, 0x72u, 0x00u, 0x6Fu, 0x00u, 0x69u, 0x00u, 0x64u, 0x00u, 0x20u, 0x00u, 0x74u, 0x00u, 0x65u, 0x00u, 0x73u, 0x00u, 0x74u, 0x00u, 0x00u, 0x00u, 0x0Cu, 0x00u, 0x00u, 0x00u, 0x00u, 0x0Au, 0x43u, 0x6Cu, 0x69u, 0x65u, 0x6Eu, 0x74u, 0x44u, 0x61u, 0x74u, 0x65u, 0x00u, 0x00u, 0x00u, 0x0Au, 0x00u, 0x00u, 0x00u, 0x00u, 0x0Au, 0x00u, 0x4Eu, 0x00u, 0x65u, 0x00u, 0x76u, 0x00u, 0x65u, 0x00u, 0x72u, 0x00u, 0x00u, 0x00u, 0x0Cu, 0x00u, 0x00u, 0x00u, 0x00u, 0x08u, 0x46u, 0x65u, 0x61u, 0x74u, 0x75u, 0x72u, 0x65u, 0x73u, 0x00u, 0x00u, 0x00u, 0x03u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u, 0x0Cu, 0x00u, 0x00u, 0x00u, 0x00u, 0x0Bu, 0x46u, 0x65u, 0x61u, 0x74u, 0x75u, 0x72u, 0x65u, 0x4Cu, 0x69u, 0x73u, 0x74u, 0x00u, 0x00u, 0x00u, 0x0Bu, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u)
)
testHandshakeSerializerDirect(ClientInitSerializer, value)
testHandshakeSerializerEncoded(ClientInitSerializer, value)
// @formatter:off
testDeserialize(ClientInitSerializer, value, byteBufferOf(0x00u, 0x00u, 0x00u, 0x0Au, 0x00u, 0x00u, 0x00u, 0x0Cu, 0x00u, 0x00u, 0x00u, 0x00u, 0x07u, 0x4Du, 0x73u, 0x67u, 0x54u, 0x79u, 0x70u, 0x65u, 0x00u, 0x00u, 0x00u, 0x0Au, 0x00u, 0x00u, 0x00u, 0x00u, 0x14u, 0x00u, 0x43u, 0x00u, 0x6Cu, 0x00u, 0x69u, 0x00u, 0x65u, 0x00u, 0x6Eu, 0x00u, 0x74u, 0x00u, 0x49u, 0x00u, 0x6Eu, 0x00u, 0x69u, 0x00u, 0x74u, 0x00u, 0x00u, 0x00u, 0x0Cu, 0x00u, 0x00u, 0x00u, 0x00u, 0x0Du, 0x43u, 0x6Cu, 0x69u, 0x65u, 0x6Eu, 0x74u, 0x56u, 0x65u, 0x72u, 0x73u, 0x69u, 0x6Fu, 0x6Eu, 0x00u, 0x00u, 0x00u, 0x0Au, 0x00u, 0x00u, 0x00u, 0x00u, 0x22u, 0x00u, 0x51u, 0x00u, 0x75u, 0x00u, 0x61u, 0x00u, 0x73u, 0x00u, 0x73u, 0x00u, 0x65u, 0x00u, 0x6Cu, 0x00u, 0x64u, 0x00u, 0x72u, 0x00u, 0x6Fu, 0x00u, 0x69u, 0x00u, 0x64u, 0x00u, 0x20u, 0x00u, 0x74u, 0x00u, 0x65u, 0x00u, 0x73u, 0x00u, 0x74u, 0x00u, 0x00u, 0x00u, 0x0Cu, 0x00u, 0x00u, 0x00u, 0x00u, 0x0Au, 0x43u, 0x6Cu, 0x69u, 0x65u, 0x6Eu, 0x74u, 0x44u, 0x61u, 0x74u, 0x65u, 0x00u, 0x00u, 0x00u, 0x0Au, 0x00u, 0x00u, 0x00u, 0x00u, 0x0Au, 0x00u, 0x4Eu, 0x00u, 0x65u, 0x00u, 0x76u, 0x00u, 0x65u, 0x00u, 0x72u, 0x00u, 0x00u, 0x00u, 0x0Cu, 0x00u, 0x00u, 0x00u, 0x00u, 0x08u, 0x46u, 0x65u, 0x61u, 0x74u, 0x75u, 0x72u, 0x65u, 0x73u, 0x00u, 0x00u, 0x00u, 0x03u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u, 0x0Cu, 0x00u, 0x00u, 0x00u, 0x00u, 0x0Bu, 0x46u, 0x65u, 0x61u, 0x74u, 0x75u, 0x72u, 0x65u, 0x4Cu, 0x69u, 0x73u, 0x74u, 0x00u, 0x00u, 0x00u, 0x0Bu, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u))
// @formatter:on
}
@Test
fun testRealistic() {
val features = FeatureSet.all()
val value = ClientInit(
fun testRealistic() = handshakeSerializerTest(
ClientInitSerializer,
ClientInit(
clientVersion = "Quasseldroid <a href=\"https://git.kuschku.de/justJanne/QuasselDroid-ng/commit/b622ad63056b6054b06e09f8e1f1ef2b0c3aaf9a\">v1.3.3</a>",
buildDate = "2020-04-27T22:21:17Z",
clientFeatures = features.legacyFeatures(),
featureList = features.featureList()
clientFeatures = FeatureSet.all().legacyFeatures(),
featureList = FeatureSet.all().featureList()
)
)
testHandshakeSerializerDirect(ClientInitSerializer, value)
testHandshakeSerializerEncoded(ClientInitSerializer, value)
}
}
......@@ -16,31 +16,24 @@
* 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.testutil.byteBufferOf
import de.kuschku.libquassel.protocol.testutil.testDeserialize
import de.kuschku.libquassel.protocol.testutil.testQtSerializerDirect
import de.kuschku.libquassel.protocol.testutil.testQtSerializerVariant
import org.junit.Test
import de.kuschku.libquassel.protocol.testutil.qtSerializerTest
import org.junit.jupiter.api.Test
class BoolSerializerTest {
@Test
fun testTrue() {
testQtSerializerDirect(BoolSerializer, true)
testQtSerializerVariant(BoolSerializer, true)
// @formatter:off
testDeserialize(BoolSerializer, true, byteBufferOf(1))
// @formatter:on
}
fun testTrue() = qtSerializerTest(
BoolSerializer,
true,
byteBufferOf(1)
)
@Test
fun testFalse() {
testQtSerializerDirect(BoolSerializer, false)
testQtSerializerVariant(BoolSerializer, false)
// @formatter:off
testDeserialize(BoolSerializer, false, byteBufferOf(0))
// @formatter:on
}
fun testFalse() = qtSerializerTest(
BoolSerializer,
false,
byteBufferOf(0)
)
}
/*
* 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.bitflags.none
import de.kuschku.bitflags.validValues
import de.kuschku.libquassel.protocol.testutil.byteBufferOf
import de.kuschku.libquassel.protocol.testutil.quasselSerializerTest
import de.kuschku.libquassel.protocol.types.BufferId
import de.kuschku.libquassel.protocol.types.BufferInfo
import de.kuschku.libquassel.protocol.types.BufferType
import de.kuschku.libquassel.protocol.types.NetworkId
import org.junit.jupiter.api.Test
class BufferInfoSerializerTest {
@Test
fun testBaseCase() = quasselSerializerTest(
BufferInfoSerializer,
BufferInfo(
BufferId(-1),
NetworkId(-1),
BufferType.none(),
-1,
""
),
byteBufferOf(0xFFu, 0xFFu, 0xFFu, 0xFFu, 0xFFu, 0xFFu, 0xFFu, 0xFFu, 0x00u, 0x00u, 0xFFu, 0xFFu, 0xFFu, 0xFFu, 0x00u, 0x00u, 0x00u, 0x00u)
)
@Test
fun testNormal() = quasselSerializerTest(
BufferInfoSerializer,
BufferInfo(
BufferId.MAX_VALUE,
NetworkId.MAX_VALUE,
BufferType.validValues(),
Int.MAX_VALUE,
"äẞ\u0000\uFFFF"
),
byteBufferOf(127, -1, -1, -1, 127, -1, -1, -1, 0, 15, 127, -1, -1, -1, 0, 0, 0, 9, -61, -92, -31, -70, -98, 0, -17, -65, -65)
)
}
......@@ -16,31 +16,27 @@
* 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.testutil.byteBufferOf
import de.kuschku.libquassel.protocol.testutil.matchers.ByteBufferMatcher
import de.kuschku.libquassel.protocol.testutil.testDeserialize
import de.kuschku.libquassel.protocol.testutil.testQtSerializerDirect
import org.junit.Test
import de.kuschku.libquassel.protocol.testutil.qtSerializerTest
import org.junit.jupiter.api.Test
class ByteBufferSerializerTest {
@Test
fun testBaseCase() {
val value = byteBufferOf(0)
testQtSerializerDirect(ByteBufferSerializer, value, ByteBufferMatcher(value))
// @formatter:off
testDeserialize(ByteBufferSerializer, ByteBufferMatcher(value), byteBufferOf(0, 0, 0, 1, 0))
// @formatter:on
}
fun testBaseCase() = qtSerializerTest(
ByteBufferSerializer,
byteBufferOf(0),
byteBufferOf(0, 0, 0, 1, 0),
::ByteBufferMatcher
)
@Test
fun testNormal() {
val value = byteBufferOf(1, 2, 3, 4, 5, 6, 7, 8, 9)
testQtSerializerDirect(ByteBufferSerializer, value, ByteBufferMatcher(value))
// @formatter:off
testDeserialize(ByteBufferSerializer, ByteBufferMatcher(value), byteBufferOf(0, 0, 0, 9, 1, 2, 3, 4, 5, 6, 7, 8, 9))
// @formatter:on
}
fun testNormal() = qtSerializerTest(
ByteBufferSerializer,
byteBufferOf(1, 2, 3, 4, 5, 6, 7, 8, 9),
byteBufferOf(0, 0, 0, 9, 1, 2, 3, 4, 5, 6, 7, 8, 9),
::ByteBufferMatcher
)
}
......@@ -16,55 +16,39 @@
* 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.testutil.byteBufferOf
import de.kuschku.libquassel.protocol.testutil.testDeserialize
import de.kuschku.libquassel.protocol.testutil.testQtSerializerDirect
import de.kuschku.libquassel.protocol.testutil.testQtSerializerVariant
import org.junit.Test
import de.kuschku.libquassel.protocol.testutil.qtSerializerTest
import org.junit.jupiter.api.Test
import kotlin.experimental.inv
class ByteSerializerTest {
@Test
fun testZero() {
val value = 0.toByte()
testQtSerializerDirect(ByteSerializer, value)
testQtSerializerVariant(ByteSerializer, value)
// @formatter:off
testDeserialize(ByteSerializer, value, byteBufferOf(0))
// @formatter:on
}
fun testZero() = qtSerializerTest(
ByteSerializer,
0.toByte(),
byteBufferOf(0)
)
@Test
fun testMinimal() {
val value = Byte.MIN_VALUE
testQtSerializerDirect(ByteSerializer, value)
testQtSerializerVariant(ByteSerializer, value)
// @formatter:off
testDeserialize(ByteSerializer, value, byteBufferOf(-128))
// @formatter:on
}
fun testMinimal() = qtSerializerTest(
ByteSerializer,
Byte.MIN_VALUE,
byteBufferOf(-128)
)
@Test
fun testMaximal() {
val value = Byte.MAX_VALUE
testQtSerializerDirect(ByteSerializer, value)
testQtSerializerVariant(ByteSerializer, value)
// @formatter:off
testDeserialize(ByteSerializer, value, byteBufferOf(127))
// @formatter:on
}
fun testMaximal() = qtSerializerTest(
ByteSerializer,
Byte.MAX_VALUE,
byteBufferOf(127)
)
@Test
fun testAllOnes() {
val value = 0.toByte().inv()
testQtSerializerDirect(ByteSerializer, value)
testQtSerializerVariant(ByteSerializer, value)
// @formatter:off
testDeserialize(ByteSerializer, value, byteBufferOf(-1))
// @formatter:on
}
fun testAllOnes() = qtSerializerTest(
ByteSerializer,
0.toByte().inv(),
byteBufferOf(-1)
)
}
/*
* 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.testutil.byteBufferOf
import de.kuschku.libquassel.protocol.testutil.matchers.TemporalMatcher
import de.kuschku.libquassel.protocol.testutil.qtSerializerTest
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.assertThrows
import org.threeten.bp.*
import org.threeten.bp.chrono.JapaneseDate
class DateTimeSerializerTest {
private val serializer = DateTimeSerializer
@Test
fun testEpoch() = qtSerializerTest(
DateTimeSerializer,
Instant.EPOCH,
byteBufferOf(0, 37, 61, -116, 0, 0, 0, 0, 2),
matcher = ::TemporalMatcher
)
@Test
fun testEpochAtTimezone() = qtSerializerTest(
DateTimeSerializer,
Instant.EPOCH.atOffset(ZoneOffset.ofTotalSeconds(1234)),
byteBufferOf(0x00u, 0x25u, 0x3Du, 0x8Cu, 0x00u, 0x12u, 0xD4u, 0x50u, 0x03u, 0x00u, 0x00u, 0x04u, 0xD2u),
matcher = ::TemporalMatcher
)
@Test
fun testEpochByCalendarAtTimezone() = qtSerializerTest(
DateTimeSerializer,
LocalDateTime
.of(1970, 1, 1, 0, 0)
.atZone(ZoneId.of("Europe/Berlin"))
.toInstant(),
byteBufferOf(0, 37, 61, -117, 4, -17, 109, -128, 2),
matcher = ::TemporalMatcher
)
@Test
fun testNormalCase() = qtSerializerTest(
DateTimeSerializer,
LocalDateTime
.of(2019, Month.JANUARY, 15, 20, 25)
.atZone(ZoneId.of("Europe/Berlin"))
.toInstant(),
byteBufferOf(0, 37, -125, -125, 4, 42, -106, -32, 2),
matcher = ::TemporalMatcher
)
@Test
fun testLocalDateTime() = qtSerializerTest(
DateTimeSerializer,
LocalDateTime
.of(2019, Month.JANUARY, 15, 20, 25),
byteBufferOf(0x00u, 0x25u, 0x83u, 0x83u, 0x04u, 0x61u, 0x85u, 0x60u, 0xFFu),
matcher = ::TemporalMatcher
)
@Test
fun testZonedDateTime() = qtSerializerTest(
DateTimeSerializer,
LocalDateTime
.of(2019, Month.JANUARY, 15, 20, 25)
.atZone(ZoneId.systemDefault()),
matcher = ::TemporalMatcher
)
@Test
fun testUnknownDateTime() = qtSerializerTest(
DateTimeSerializer,
LocalDateTime
.of(2019, Month.JANUARY, 15, 20, 25),
byteBufferOf(0x00u, 0x25u, 0x83u, 0x83u, 0x04u, 0x61u, 0x85u, 0x60u, 0x07u),
matcher = ::TemporalMatcher
)
@Test
fun testOldJavaDate() {
assertThrows<IllegalArgumentException>("Unsupported Format: org.threeten.bp.chrono.JapaneseDate") {
qtSerializerTest(
DateTimeSerializer,
JapaneseDate.now(),
matcher = ::TemporalMatcher
)
}
}
}
/*
* 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.testutil.byteBufferOf
import de.kuschku.libquassel.protocol.testutil.qtSerializerTest
import org.junit.jupiter.api.Test
class DoubleSerializerTest {
@Test
fun testZero() = qtSerializerTest(
DoubleSerializer,
0.0,
byteBufferOf(0x00u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u)
)
@Test
fun testMinimal() = qtSerializerTest(
DoubleSerializer,
Double.MIN_VALUE,
byteBufferOf(0x00u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u, 0x01u)
)
@Test
fun testMaximal() = qtSerializerTest(
DoubleSerializer,
Double.MAX_VALUE,
byteBufferOf(0x7Fu, 0xEFu, 0xFFu, 0xFFu, 0xFFu, 0xFFu, 0xFFu, 0xFFu)
)
@Test
fun testInfinityPositive() = qtSerializerTest(
DoubleSerializer,
Double.POSITIVE_INFINITY,
byteBufferOf(0x7Fu, 0xF0u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u)
)
@Test
fun testInfinityNegative() = qtSerializerTest(
DoubleSerializer,
Double.NEGATIVE_INFINITY,
byteBufferOf(0xFFu, 0xF0u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u)
)
@Test
fun testNotANumber() = qtSerializerTest(
DoubleSerializer,
Double.NaN,
byteBufferOf(0x7Fu, 0xF8u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u)
)
}
/*
* 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.testutil.byteBufferOf
import de.kuschku.libquassel.protocol.testutil.qtSerializerTest
import org.junit.jupiter.api.Test
class FloatSerializerTest {
@Test
fun testZero() = qtSerializerTest(
FloatSerializer,
0f,
byteBufferOf(0x00u, 0x00u, 0x00u, 0x00u)
)
@Test
fun testMinimal() = qtSerializerTest(
FloatSerializer,
Float.MIN_VALUE,
byteBufferOf(0x00u, 0x00u, 0x00u, 0x01u)
)
@Test
fun testMaximal() = qtSerializerTest(
FloatSerializer,
Float.MAX_VALUE,
byteBufferOf(0x7Fu, 0x7Fu, 0xFFu, 0xFFu)
)
@Test
fun testInfinityPositive() = qtSerializerTest(
FloatSerializer,
Float.POSITIVE_INFINITY,
byteBufferOf(0x7Fu, 0x80u, 0x00u, 0x00u)
)
@Test
fun testInfinityNegative() = qtSerializerTest(
FloatSerializer,
Float.NEGATIVE_INFINITY,
byteBufferOf(0xFFu, 0x80u, 0x00u, 0x00u)
)
@Test
fun testNotANumber() = qtSerializerTest(
FloatSerializer,
Float.NaN,
byteBufferOf(0x7Fu, 0xC0u, 0x00u, 0x00u)
)
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment