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
Showing
with 288 additions and 62 deletions
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
plugins {
id("com.android.application")
id("kotlin-android")
......@@ -23,6 +21,10 @@ android {
val androidxComposeVersion: String by project.extra
kotlinCompilerExtensionVersion = androidxComposeVersion
}
kotlinOptions {
useIR = true
}
}
kapt {
......@@ -65,7 +67,8 @@ dependencies {
implementation("io.coil-kt", "coil", "1.1.1")
implementation("dev.chrisbanes.accompanist", "accompanist-coil", "0.5.0")
testImplementation("junit", "junit", "4.13.1")
val junit4Version: String by project.extra
testImplementation("junit", "junit", junit4Version)
androidTestImplementation("androidx.test.ext", "junit", "1.1.2")
androidTestImplementation("androidx.test.espresso", "espresso-core", "3.3.0")
}
plugins {
kotlin("jvm")
id("jacoco")
}
tasks.withType<Test> {
useJUnitPlatform()
}
tasks.getByName<JacocoReport>("jacocoTestReport") {
reports {
sourceDirectories.from(fileTree("src/main/kotlin"))
classDirectories.from(fileTree("build/classes"))
xml.destination = File("$buildDir/reports/jacoco/report.xml")
html.isEnabled = true
xml.isEnabled = true
csv.isEnabled = false
}
}
dependencies {
implementation(kotlin("stdlib"))
testImplementation("junit", "junit", "4.13.1")
val junit5Version: String by project.extra
testImplementation("org.junit.jupiter", "junit-jupiter-api", junit5Version)
testRuntimeOnly("org.junit.jupiter", "junit-jupiter-engine", junit5Version)
val hamcrestVersion: String by project.extra
testImplementation("org.hamcrest", "hamcrest-library", hamcrestVersion)
}
......@@ -19,26 +19,7 @@
package de.kuschku.bitflags
import java.util.*
interface Flags<T, U> where U : Flag<T>, U : Enum<U> {
operator fun get(value: T): U?
fun all(): Collection<U>
}
inline fun <reified T> Flags<*, T>.of(
vararg values: T
) where T: Flag<*>, T: Enum<T> = values.toEnumSet()
inline fun <reified T> Flags<*, T>.of(
values: Collection<T>
) where T: Flag<*>, T: Enum<T> = values.toEnumSet()
inline fun <reified T: Enum<T>> Array<out T>.toEnumSet() =
EnumSet.noneOf(T::class.java).apply {
addAll(this@toEnumSet)
}
inline fun <reified T: Enum<T>> Collection<T>.toEnumSet() =
EnumSet.noneOf(T::class.java).apply {
addAll(this@toEnumSet)
val all: Set<U>
}
/*
* 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.bitflags
import java.util.*
inline fun <reified T> Flags<*, T>.none(): EnumSet<T>
where T : Flag<*>, T : Enum<T> = EnumSet.noneOf(T::class.java)
/*
* 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.bitflags
import java.util.*
inline fun <reified T> Flags<*, T>.of(vararg values: T): EnumSet<T>
where T : Flag<*>, T : Enum<T> = values.toEnumSet()
inline fun <reified T> Flags<*, T>.of(values: Collection<T>): EnumSet<T>
where T : Flag<*>, T : Enum<T> = values.toEnumSet()
......@@ -21,6 +21,12 @@ package de.kuschku.bitflags
import java.util.*
inline fun <reified T : Enum<T>> List<T>.toEnumSet(): EnumSet<T> =
if (this.isEmpty()) EnumSet.noneOf(T::class.java)
else EnumSet.of(this.first(), *this.subList(1, this.size).toTypedArray())
inline fun <reified T : Enum<T>> Array<out T>.toEnumSet() =
EnumSet.noneOf(T::class.java).apply {
addAll(this@toEnumSet)
}
inline fun <reified T : Enum<T>> Collection<T>.toEnumSet() =
EnumSet.noneOf(T::class.java).apply {
addAll(this@toEnumSet)
}
......@@ -24,40 +24,40 @@ import kotlin.experimental.and
inline fun <reified T> Flags<Byte, T>.of(value: Byte?): EnumSet<T> where T : Flag<Byte>, T : Enum<T> {
if (value == null) return emptyList<T>().toEnumSet()
return this.all().filter { (value and it.value) != 0.toByte() }.toEnumSet()
return all.filter { (value and it.value) != 0.toByte() }.toEnumSet()
}
inline fun <reified T> Flags<UByte, T>.of(value: UByte?): EnumSet<T> where T : Flag<UByte>, T : Enum<T> {
if (value == null) return emptyList<T>().toEnumSet()
return this.all().filter { (value and it.value) != 0.toUByte() }.toEnumSet()
return all.filter { (value and it.value) != 0.toUByte() }.toEnumSet()
}
inline fun <reified T> Flags<Short, T>.of(value: Short?): EnumSet<T> where T : Flag<Short>, T : Enum<T> {
if (value == null) return emptyList<T>().toEnumSet()
return this.all().filter { (value and it.value) != 0.toShort() }.toEnumSet()
return all.filter { (value and it.value) != 0.toShort() }.toEnumSet()
}
inline fun <reified T> Flags<UShort, T>.of(value: UShort?): EnumSet<T> where T : Flag<UShort>, T : Enum<T> {
if (value == null) return emptyList<T>().toEnumSet()
return this.all().filter { (value and it.value) != 0.toUShort() }.toEnumSet()
return all.filter { (value and it.value) != 0.toUShort() }.toEnumSet()
}
inline fun <reified T> Flags<Int, T>.of(value: Int?): EnumSet<T> where T : Flag<Int>, T : Enum<T> {
if (value == null) return emptyList<T>().toEnumSet()
return this.all().filter { (value and it.value) != 0 }.toEnumSet()
return all.filter { (value and it.value) != 0 }.toEnumSet()
}
inline fun <reified T> Flags<UInt, T>.of(value: UInt?): EnumSet<T> where T : Flag<UInt>, T : Enum<T> {
if (value == null) return emptyList<T>().toEnumSet()
return this.all().filter { (value and it.value) != 0u }.toEnumSet()
return all.filter { (value and it.value) != 0u }.toEnumSet()
}
inline fun <reified T> Flags<Long, T>.of(value: Long?): EnumSet<T> where T : Flag<Long>, T : Enum<T> {
if (value == null) return emptyList<T>().toEnumSet()
return this.all().filter { (value and it.value) != 0L }.toEnumSet()
return all.filter { (value and it.value) != 0L }.toEnumSet()
}
inline fun <reified T> Flags<ULong, T>.of(value: ULong?): EnumSet<T> where T : Flag<ULong>, T : Enum<T> {
if (value == null) return emptyList<T>().toEnumSet()
return this.all().filter { (value and it.value) != 0uL }.toEnumSet()
return all.filter { (value and it.value) != 0uL }.toEnumSet()
}
/*
* 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.bitflags
import java.util.*
@JvmName("validValuesUByte")
inline fun <reified T> Flags<UByte, T>.validValues(): EnumSet<T>
where T : Flag<UByte>, T : Enum<T> =
all.filter { it.value != 0.toUByte() }.toEnumSet()
@JvmName("validValuesByte")
inline fun <reified T> Flags<Byte, T>.validValues(): EnumSet<T>
where T : Flag<Byte>, T : Enum<T> =
all.filter { it.value != 0.toByte() }.toEnumSet()
@JvmName("validValuesUShort")
inline fun <reified T> Flags<UShort, T>.validValues(): EnumSet<T>
where T : Flag<UShort>, T : Enum<T> =
all.filter { it.value != 0.toUShort() }.toEnumSet()
@JvmName("validValuesShort")
inline fun <reified T> Flags<Short, T>.validValues(): EnumSet<T>
where T : Flag<Short>, T : Enum<T> =
all.filter { it.value != 0.toShort() }.toEnumSet()
@JvmName("validValuesUInt")
inline fun <reified T> Flags<UInt, T>.validValues(): EnumSet<T>
where T : Flag<UInt>, T : Enum<T> =
all.filter { it.value != 0u }.toEnumSet()
@JvmName("validValuesInt")
inline fun <reified T> Flags<Int, T>.validValues(): EnumSet<T>
where T : Flag<Int>, T : Enum<T> =
all.filter { it.value != 0 }.toEnumSet()
@JvmName("validValuesULong")
inline fun <reified T> Flags<ULong, T>.validValues(): EnumSet<T>
where T : Flag<ULong>, T : Enum<T> =
all.filter { it.value != 0uL }.toEnumSet()
@JvmName("validValuesLong")
inline fun <reified T> Flags<Long, T>.validValues(): EnumSet<T>
where T : Flag<Long>, T : Enum<T> =
all.filter { it.value != 0L }.toEnumSet()
......@@ -41,6 +41,9 @@ allprojects {
extra["androidxLifecycleVersion"] = "2.3.0-rc01"
extra["androidxMultidexVersion"] = "2.0.1"
extra["daggerHiltVersion"] = "2.31.2-alpha"
extra["hamcrestVersion"] = "2.1"
extra["junit4Version"] = "4.13.1"
extra["junit5Version"] = "5.3.1"
extra["mdcVersion"] = "1.2.1"
repositories {
......@@ -56,7 +59,6 @@ allprojects {
"-Xopt-in=kotlin.ExperimentalUnsignedTypes"
)
jvmTarget = "1.8"
useIR = true
}
}
}
plugins {
kotlin("jvm")
jacoco
}
tasks.withType<Test> {
useJUnitPlatform()
}
jacoco {
toolVersion = "0.8.6"
}
tasks.getByName<JacocoReport>("jacocoTestReport") {
reports {
sourceDirectories.from(fileTree("src/main/kotlin"))
xml.destination = File("$buildDir/reports/jacoco/report.xml")
html.isEnabled = true
xml.isEnabled = true
csv.isEnabled = false
}
}
dependencies {
......@@ -7,5 +26,9 @@ dependencies {
implementation("org.threeten", "threetenbp", "1.4.0")
api(project(":bitflags"))
testImplementation("junit", "junit", "4.13.1")
val junit5Version: String by project.extra
testImplementation("org.junit.jupiter", "junit-jupiter-api", junit5Version)
testRuntimeOnly("org.junit.jupiter", "junit-jupiter-engine", junit5Version)
val hamcrestVersion: String by project.extra
testImplementation("org.hamcrest", "hamcrest-library", hamcrestVersion)
}
......@@ -45,7 +45,7 @@ class FeatureSet internal constructor(
fun build(vararg features: QuasselFeature) = FeatureSet(features.toSet())
fun build(features: Set<QuasselFeature>) = FeatureSet(features)
fun all() = build(*QuasselFeature.values())
fun empty() = build()
fun none() = build()
private fun parseFeatures(features: LegacyFeatures) =
features.map(LegacyFeature::feature).toSet()
......
......@@ -21,6 +21,8 @@ package de.kuschku.libquassel.protocol.features
import de.kuschku.bitflags.Flag
import de.kuschku.bitflags.Flags
import de.kuschku.bitflags.toEnumSet
import java.util.*
/**
* A list of features that are optional in core and/or client, but need runtime checking
......@@ -68,7 +70,7 @@ enum class LegacyFeature(
private val values = values().associateBy(LegacyFeature::value)
override fun get(value: UInt) = values[value]
override fun all() = values.values
override val all: LegacyFeatures = values.values.toEnumSet()
}
}
......
......@@ -32,7 +32,7 @@ object DateTimeSerializer : QtSerializer<Temporal> {
override val javaType: Class<out Temporal> = Temporal::class.java
override fun serialize(buffer: ChainedByteBuffer, data: Temporal, featureSet: FeatureSet) {
fun serialize(data: LocalDateTime, timeSpec: TimeSpec, offset: ZoneOffset? = null) {
fun serialize(data: LocalDateTime, timeSpec: TimeSpec, offset: ZoneOffset?) {
DateSerializer.serialize(buffer, data.toLocalDate(), featureSet)
TimeSerializer.serialize(buffer, data.toLocalTime(), featureSet)
ByteSerializer.serialize(buffer, timeSpec.value, featureSet)
......@@ -43,13 +43,13 @@ object DateTimeSerializer : QtSerializer<Temporal> {
when (data) {
is LocalDateTime ->
serialize(data, TimeSpec.LocalUnknown)
serialize(data, TimeSpec.LocalUnknown, null)
is OffsetDateTime ->
serialize(data.toLocalDateTime(), TimeSpec.OffsetFromUTC, data.offset)
is ZonedDateTime ->
serialize(data.toLocalDateTime(), TimeSpec.OffsetFromUTC, data.offset)
is Instant ->
serialize(data.atOffset(ZoneOffset.UTC).toLocalDateTime(), TimeSpec.OffsetFromUTC)
serialize(data.atOffset(ZoneOffset.UTC).toLocalDateTime(), TimeSpec.UTC, null)
else ->
throw IllegalArgumentException("Unsupported Format: ${data::class.java.canonicalName}")
}
......@@ -66,12 +66,10 @@ object DateTimeSerializer : QtSerializer<Temporal> {
TimeSpec.LocalUnknown,
TimeSpec.LocalDST ->
localDateTime
.atZone(ZoneId.systemDefault())
TimeSpec.OffsetFromUTC ->
localDateTime
.atOffset(ZoneOffset.ofTotalSeconds(
IntSerializer.deserialize(buffer, featureSet)))
.toInstant()
TimeSpec.UTC ->
localDateTime
.atOffset(ZoneOffset.UTC)
......
/*
* 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.serializers.primitive
import de.kuschku.libquassel.protocol.features.FeatureSet
import de.kuschku.libquassel.protocol.io.ChainedByteBuffer
import de.kuschku.libquassel.protocol.variant.QtType
import java.nio.ByteBuffer
object DoubleSerializer : QtSerializer<Double> {
override val qtType: QtType = QtType.Double
override val javaType: Class<Double> = Double::class.java
override fun serialize(buffer: ChainedByteBuffer, data: Double, featureSet: FeatureSet) {
buffer.putDouble(data)
}
override fun deserialize(buffer: ByteBuffer, featureSet: FeatureSet): Double {
return buffer.getDouble()
}
}
/*
* 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.serializers.primitive
import de.kuschku.libquassel.protocol.features.FeatureSet
import de.kuschku.libquassel.protocol.io.ChainedByteBuffer
import de.kuschku.libquassel.protocol.variant.QtType
import java.nio.ByteBuffer
object FloatSerializer : QtSerializer<Float> {
override val qtType: QtType = QtType.Float
override val javaType: Class<Float> = Float::class.java
override fun serialize(buffer: ChainedByteBuffer, data: Float, featureSet: FeatureSet) {
buffer.putFloat(data)
}
override fun deserialize(buffer: ByteBuffer, featureSet: FeatureSet): Float {
return buffer.getFloat()
}
}
......@@ -65,7 +65,7 @@ object MessageSerializer : QuasselSerializer<Message> {
Instant.ofEpochSecond(IntSerializer.deserialize(buffer, featureSet).toLong()),
type = MessageType.of(UIntSerializer.deserialize(buffer, featureSet)),
flag = MessageFlag.of(
UByteSerializer.deserialize(buffer, featureSet).toUInt() and 0xffu
UByteSerializer.deserialize(buffer, featureSet).toUInt()
),
bufferInfo = BufferInfoSerializer.deserialize(buffer, featureSet),
sender = StringSerializerUtf8.deserialize(buffer, featureSet) ?: "",
......
......@@ -21,7 +21,7 @@ package de.kuschku.libquassel.protocol.serializers.primitive
import de.kuschku.libquassel.protocol.features.FeatureSet
import de.kuschku.libquassel.protocol.io.ChainedByteBuffer
import de.kuschku.libquassel.protocol.serializers.*
import de.kuschku.libquassel.protocol.serializers.NoSerializerForTypeException
import de.kuschku.libquassel.protocol.variant.QVariant
import de.kuschku.libquassel.protocol.variant.QVariant_
import de.kuschku.libquassel.protocol.variant.QtType
......
......@@ -29,13 +29,20 @@ object Serializers {
private val qtSerializers = setOf<QtSerializer<*>>(
VoidSerializer,
BoolSerializer,
ByteSerializer,
UByteSerializer,
ShortSerializer,
UShortSerializer,
IntSerializer,
UIntSerializer,
LongSerializer,
ULongSerializer,
QCharSerializer,
QVariantMapSerializer,
QVariantListSerializer,
FloatSerializer,
DoubleSerializer,
QCharSerializer,
StringSerializerUtf16,
QStringListSerializer,
ByteBufferSerializer,
......@@ -44,16 +51,12 @@ object Serializers {
TimeSerializer,
DateTimeSerializer,
LongSerializer,
ShortSerializer,
ByteSerializer,
ULongSerializer,
UShortSerializer,
UByteSerializer,
QVariantSerializer,
QVariantListSerializer,
QVariantMapSerializer,
).associateBy(QtSerializer<*>::qtType)
private val quasselSerializers = listOf<QuasselSerializer<*>>(
BufferIdSerializer,
BufferInfoSerializer,
//DccConfigIpDetectionModeSerializer,
......@@ -69,9 +72,6 @@ object Serializers {
//NetworkServerSerializer,
//QHostAddressSerializer,
PeerPtrSerializer,
).associateBy(QtSerializer<*>::qtType)
private val quasselSerializers = listOf<QuasselSerializer<*>>(
).associateBy(QuasselSerializer<*>::quasselType)
operator fun get(type: QtType) = qtSerializers[type]
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment