Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found
Select Git revision
  • api-redesign
  • main
  • 0.10.0
  • 0.10.1
  • 0.10.2
  • 0.7.0
  • 0.8.0
  • 0.8.1
  • 0.9.0
  • 0.9.1
  • 0.9.2
11 results

Target

Select target project
  • justJanne/libquassel
1 result
Select Git revision
  • api-redesign
  • main
  • 0.10.0
  • 0.10.1
  • 0.10.2
  • 0.7.0
  • 0.8.0
  • 0.8.1
  • 0.9.0
  • 0.9.1
  • 0.9.2
11 results
Show changes
Showing
with 193 additions and 2067 deletions
/*
* libquassel
* Copyright (c) 2021 Janne Mareike Koschinski
*
* This Source Code Form is subject to the terms of the Mozilla Public License,
* v. 2.0. If a copy of the MPL was not distributed with this file, You can
* obtain one at https://mozilla.org/MPL/2.0/.
*/
package de.justjanne.libquassel.protocol.syncables
import de.justjanne.libquassel.protocol.models.ids.NetworkId
import de.justjanne.libquassel.protocol.syncables.common.IrcUser
import de.justjanne.libquassel.protocol.syncables.state.IrcUserState
import de.justjanne.libquassel.protocol.testutil.nextIrcUser
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Assertions.assertNotEquals
import org.junit.jupiter.api.Nested
import org.junit.jupiter.api.Test
import org.threeten.bp.Instant
import kotlin.random.Random
class IrcUserTest {
@Test
fun testEmpty() {
val state = IrcUserState(
network = NetworkId(1),
nick = "nick",
user = "user",
host = "host"
)
val actual = IrcUser(state = state).apply {
update(emptyMap())
}.state()
assertEquals(state, actual)
}
@Test
fun testSerialization() {
val random = Random(1337)
val expected = random.nextIrcUser(NetworkId(random.nextInt()))
val actual = IrcUser(
state = IrcUserState(
network = expected.network,
nick = expected.nick,
user = expected.user,
host = expected.host
)
).apply {
update(IrcUser(state = expected).toVariantMap())
}.state()
assertEquals(expected, actual)
}
@Nested
inner class Setters {
@Test
fun testHostMask() {
val random = Random(1337)
val user = IrcUser(state = random.nextIrcUser(NetworkId(random.nextInt())))
val nick = user.nick()
assertNotEquals("$nick!user@host", user.hostMask())
user.updateHostmask("$nick!user@host")
assertEquals("$nick!user@host", user.hostMask())
}
@Test
fun testAddUserModes() {
val random = Random(1337)
val user = IrcUser(state = random.nextIrcUser(NetworkId(random.nextInt())))
user.setUserModes("abc")
assertEquals(setOf('a', 'b', 'c'), user.userModes())
user.addUserModes("ef")
assertEquals(setOf('a', 'b', 'c', 'e', 'f'), user.userModes())
}
@Test
fun testRemoveUserModes() {
val random = Random(1337)
val user = IrcUser(state = random.nextIrcUser(NetworkId(random.nextInt())))
user.setUserModes("abc")
assertEquals(setOf('a', 'b', 'c'), user.userModes())
user.removeUserModes("ac")
assertEquals(setOf('b'), user.userModes())
}
@Test
fun testUserUnverified() {
val random = Random(1337)
val user = IrcUser(state = random.nextIrcUser(NetworkId(random.nextInt())))
assertNotEquals("~newuser", user.user())
assertNotEquals(null, user.verifiedUser())
user.setUser("~newuser")
assertEquals("~newuser", user.user())
assertEquals(null, user.verifiedUser())
}
@Test
fun testUserVerified() {
val random = Random(1337)
val user = IrcUser(state = random.nextIrcUser(NetworkId(random.nextInt())))
assertNotEquals("newuser", user.user())
assertNotEquals("newuser", user.verifiedUser())
user.setUser("newuser")
assertEquals("newuser", user.user())
assertEquals("newuser", user.verifiedUser())
}
@Test
fun testHost() {
val random = Random(1337)
val user = IrcUser(state = random.nextIrcUser(NetworkId(random.nextInt())))
assertNotEquals("TeraPro33-41.LowerMyBills.com", user.host())
user.setHost("TeraPro33-41.LowerMyBills.com")
assertEquals("TeraPro33-41.LowerMyBills.com", user.host())
}
@Test
fun testRealName() {
val random = Random(1337)
val user = IrcUser(state = random.nextIrcUser(NetworkId(random.nextInt())))
assertNotEquals("Bruce Wayne", user.realName())
user.setRealName("Bruce Wayne")
assertEquals("Bruce Wayne", user.realName())
}
@Test
fun testAccount() {
val random = Random(1337)
val user = IrcUser(state = random.nextIrcUser(NetworkId(random.nextInt())))
assertNotEquals("thebatman", user.account())
user.setAccount("thebatman")
assertEquals("thebatman", user.account())
}
@Test
fun testAway() {
val random = Random(1337)
val user = IrcUser(state = random.nextIrcUser(NetworkId(random.nextInt())))
user.setAway(false)
assertEquals(false, user.isAway())
user.setAway(true)
assertEquals(true, user.isAway())
}
@Test
fun testAwayMessage() {
val random = Random(1337)
val user = IrcUser(state = random.nextIrcUser(NetworkId(random.nextInt())))
assertNotEquals("I’ll be back", user.awayMessage())
user.setAwayMessage("I’ll be back")
assertEquals("I’ll be back", user.awayMessage())
}
@Test
fun testIdleTime() {
val random = Random(1337)
val user = IrcUser(state = random.nextIrcUser(NetworkId(random.nextInt())))
val timestamp = Instant.ofEpochSecond(1614642922)
assertNotEquals(timestamp, user.idleTime())
user.setIdleTime(timestamp)
assertEquals(timestamp, user.idleTime())
}
@Test
fun testLoginTime() {
val random = Random(1337)
val user = IrcUser(state = random.nextIrcUser(NetworkId(random.nextInt())))
val timestamp = Instant.ofEpochSecond(1614642922)
assertNotEquals(timestamp, user.loginTime())
user.setLoginTime(timestamp)
assertEquals(timestamp, user.loginTime())
}
@Test
fun testIrcOperator() {
val random = Random(1337)
val user = IrcUser(state = random.nextIrcUser(NetworkId(random.nextInt())))
assertNotEquals("lorem ipsum i dolor sit amet", user.ircOperator())
user.setIrcOperator("lorem ipsum i dolor sit amet")
assertEquals("lorem ipsum i dolor sit amet", user.ircOperator())
}
@Test
fun testLastAwayMessage() {
val random = Random(1337)
val user = IrcUser(state = random.nextIrcUser(NetworkId(random.nextInt())))
val timestamp = Instant.ofEpochSecond(1614642922)
assertNotEquals(timestamp, user.lastAwayMessageTime())
user.setLastAwayMessage(timestamp.epochSecond.toInt())
assertEquals(timestamp, user.lastAwayMessageTime())
}
@Test
fun testLastAwayMessageTime() {
val random = Random(1337)
val user = IrcUser(state = random.nextIrcUser(NetworkId(random.nextInt())))
val timestamp = Instant.ofEpochSecond(1614642922)
assertNotEquals(timestamp, user.lastAwayMessageTime())
user.setLastAwayMessageTime(timestamp)
assertEquals(timestamp, user.lastAwayMessageTime())
}
@Test
fun testWhoisServiceReply() {
val random = Random(1337)
val user = IrcUser(state = random.nextIrcUser(NetworkId(random.nextInt())))
assertNotEquals("lorem ipsum i dolor sit amet", user.whoisServiceReply())
user.setWhoisServiceReply("lorem ipsum i dolor sit amet")
assertEquals("lorem ipsum i dolor sit amet", user.whoisServiceReply())
}
@Test
fun testSuserHost() {
val random = Random(1337)
val user = IrcUser(state = random.nextIrcUser(NetworkId(random.nextInt())))
assertNotEquals("lorem ipsum i dolor sit amet", user.suserHost())
user.setSuserHost("lorem ipsum i dolor sit amet")
assertEquals("lorem ipsum i dolor sit amet", user.suserHost())
}
@Test
fun testEncrypted() {
val random = Random(1337)
val user = IrcUser(state = random.nextIrcUser(NetworkId(random.nextInt())))
user.setEncrypted(false)
assertEquals(false, user.isEncrypted())
user.setEncrypted(true)
assertEquals(true, user.isEncrypted())
}
@Test
fun testServer() {
val random = Random(1337)
val user = IrcUser(state = random.nextIrcUser(NetworkId(random.nextInt())))
assertNotEquals("orwell.freenode.net", user.server())
user.setServer("orwell.freenode.net")
assertEquals("orwell.freenode.net", user.server())
}
}
}
/*
* libquassel
* Copyright (c) 2021 Janne Mareike Koschinski
*
* This Source Code Form is subject to the terms of the Mozilla Public License,
* v. 2.0. If a copy of the MPL was not distributed with this file, You can
* obtain one at https://mozilla.org/MPL/2.0/.
*/
package de.justjanne.libquassel.protocol.syncables
import de.justjanne.libquassel.protocol.syncables.common.NetworkConfig
import de.justjanne.libquassel.protocol.syncables.state.NetworkConfigState
import de.justjanne.libquassel.protocol.testutil.nextNetworkConfig
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Assertions.assertNotEquals
import org.junit.jupiter.api.Nested
import org.junit.jupiter.api.Test
import kotlin.random.Random
class NetworkConfigTest {
@Test
fun testEmpty() {
val actual = NetworkConfig().apply {
update(emptyMap())
}.state()
assertEquals(NetworkConfigState(), actual)
}
@Test
fun testSerialization() {
val random = Random(1337)
val expected = random.nextNetworkConfig()
val actual = NetworkConfig().apply {
update(NetworkConfig(state = expected).toVariantMap())
}.state()
assertEquals(expected, actual)
}
@Nested
inner class Setters {
@Test
fun testAutoWhoDelay() {
val random = Random(1337)
val networkConfig = NetworkConfig(state = random.nextNetworkConfig())
val value = random.nextInt()
assertNotEquals(value, networkConfig.autoWhoDelay())
networkConfig.setAutoWhoDelay(value)
assertEquals(value, networkConfig.autoWhoDelay())
}
@Test
fun testAutoWhoEnabled() {
val random = Random(1337)
val networkConfig = NetworkConfig(state = random.nextNetworkConfig())
networkConfig.setAutoWhoEnabled(false)
assertEquals(false, networkConfig.autoWhoEnabled())
networkConfig.setAutoWhoEnabled(true)
assertEquals(true, networkConfig.autoWhoEnabled())
}
@Test
fun testAutoWhoInterval() {
val random = Random(1337)
val networkConfig = NetworkConfig(state = random.nextNetworkConfig())
val value = random.nextInt()
assertNotEquals(value, networkConfig.autoWhoInterval())
networkConfig.setAutoWhoInterval(value)
assertEquals(value, networkConfig.autoWhoInterval())
}
@Test
fun testAutoWhoNickLimit() {
val random = Random(1337)
val networkConfig = NetworkConfig(state = random.nextNetworkConfig())
val value = random.nextInt()
assertNotEquals(value, networkConfig.autoWhoNickLimit())
networkConfig.setAutoWhoNickLimit(value)
assertEquals(value, networkConfig.autoWhoNickLimit())
}
@Test
fun testMaxPingCount() {
val random = Random(1337)
val networkConfig = NetworkConfig(state = random.nextNetworkConfig())
val value = random.nextInt()
assertNotEquals(value, networkConfig.maxPingCount())
networkConfig.setMaxPingCount(value)
assertEquals(value, networkConfig.maxPingCount())
}
@Test
fun testPingInterval() {
val random = Random(1337)
val networkConfig = NetworkConfig(state = random.nextNetworkConfig())
val value = random.nextInt()
assertNotEquals(value, networkConfig.pingInterval())
networkConfig.setPingInterval(value)
assertEquals(value, networkConfig.pingInterval())
}
@Test
fun testPingTimeoutEnabled() {
val random = Random(1337)
val networkConfig = NetworkConfig(state = random.nextNetworkConfig())
networkConfig.setPingTimeoutEnabled(false)
assertEquals(false, networkConfig.pingTimeoutEnabled())
networkConfig.setPingTimeoutEnabled(true)
assertEquals(true, networkConfig.pingTimeoutEnabled())
}
@Test
fun testStandardCtcp() {
val random = Random(1337)
val networkConfig = NetworkConfig(state = random.nextNetworkConfig())
networkConfig.setStandardCtcp(false)
assertEquals(false, networkConfig.standardCtcp())
networkConfig.setStandardCtcp(true)
assertEquals(true, networkConfig.standardCtcp())
}
}
}
/*
* libquassel
* Copyright (c) 2021 Janne Mareike Koschinski
*
* This Source Code Form is subject to the terms of the Mozilla Public License,
* v. 2.0. If a copy of the MPL was not distributed with this file, You can
* obtain one at https://mozilla.org/MPL/2.0/.
*/
package de.justjanne.libquassel.protocol.syncables
import de.justjanne.libquassel.protocol.models.ids.IdentityId
import de.justjanne.libquassel.protocol.models.ids.NetworkId
import de.justjanne.libquassel.protocol.models.network.ChannelModeType
import de.justjanne.libquassel.protocol.models.network.ConnectionState
import de.justjanne.libquassel.protocol.models.network.NetworkInfo
import de.justjanne.libquassel.protocol.models.network.NetworkServer
import de.justjanne.libquassel.protocol.models.types.QtType
import de.justjanne.libquassel.protocol.models.types.QuasselType
import de.justjanne.libquassel.protocol.serializers.qt.StringSerializerUtf8
import de.justjanne.libquassel.protocol.syncables.common.Network
import de.justjanne.libquassel.protocol.syncables.state.NetworkState
import de.justjanne.libquassel.protocol.testutil.mocks.EmptySession
import de.justjanne.libquassel.protocol.testutil.mocks.EmptySyncProxy
import de.justjanne.libquassel.protocol.testutil.nextNetwork
import de.justjanne.libquassel.protocol.testutil.nextString
import de.justjanne.libquassel.protocol.variant.qVariant
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Assertions.assertFalse
import org.junit.jupiter.api.Assertions.assertNotEquals
import org.junit.jupiter.api.Assertions.assertTrue
import org.junit.jupiter.api.Nested
import org.junit.jupiter.api.Test
import kotlin.random.Random
class NetworkTest {
@Test
fun testEmpty() {
val state = NetworkState(networkId = NetworkId(1))
val actual = Network(state = state).apply {
update(emptyMap())
}.state()
assertEquals(state, actual)
}
@Test
fun testInvalid() {
val state = NetworkState(networkId = NetworkId(1))
val actual = Network(state = state).apply {
update(
mapOf(
"connectionState" to qVariant(-2, QtType.Int),
)
)
}.state()
assertEquals(state, actual)
}
@Test
fun testSerialization() {
val random = Random(1337)
val networkId = NetworkId(random.nextInt())
val expected = random.nextNetwork(networkId)
val actual = Network(state = NetworkState(networkId = networkId)).apply {
update(Network(state = expected).toVariantMap())
}.state()
assertEquals(expected, actual)
}
@Test
fun testNetworkInfo() {
val random = Random(1337)
val networkId = NetworkId(random.nextInt())
val expected = random.nextNetwork(networkId)
val actual = Network(state = NetworkState(networkId = networkId)).apply {
update(Network(state = expected).toVariantMap())
}
assertEquals(
NetworkInfo(
networkName = expected.networkName,
networkId = expected.networkId,
identity = expected.identity,
codecForServer = expected.codecForServer,
codecForEncoding = expected.codecForEncoding,
codecForDecoding = expected.codecForDecoding,
serverList = expected.serverList,
useRandomServer = expected.useRandomServer,
perform = expected.perform,
useAutoIdentify = expected.useAutoIdentify,
autoIdentifyService = expected.autoIdentifyService,
autoIdentifyPassword = expected.autoIdentifyPassword,
useSasl = expected.useSasl,
saslAccount = expected.saslAccount,
saslPassword = expected.saslPassword,
useAutoReconnect = expected.useAutoReconnect,
autoReconnectInterval = expected.autoReconnectInterval,
autoReconnectRetries = expected.autoReconnectRetries,
unlimitedReconnectRetries = expected.unlimitedReconnectRetries,
rejoinChannels = expected.rejoinChannels,
useCustomMessageRate = expected.useCustomMessageRate,
messageRateBurstSize = expected.messageRateBurstSize,
messageRateDelay = expected.messageRateDelay,
unlimitedMessageRate = expected.unlimitedMessageRate
),
actual.networkInfo()
)
}
@Nested
inner class Setters {
@Test
fun testIdentity() {
val random = Random(1337)
val network = Network(state = random.nextNetwork())
assertNotEquals(IdentityId(4), network.identity())
network.setIdentity(IdentityId(4))
assertEquals(IdentityId(4), network.identity())
}
@Test
fun testMyNick() {
val random = Random(1337)
val network = Network(state = random.nextNetwork())
assertNotEquals("justJanne", network.myNick())
network.setMyNick("justJanne")
assertEquals("justJanne", network.myNick())
}
@Test
fun testLatency() {
val random = Random(1337)
val network = Network(state = random.nextNetwork())
assertNotEquals(500, network.latency())
network.setLatency(500)
assertEquals(500, network.latency())
}
@Test
fun testNetworkName() {
val random = Random(1337)
val network = Network(state = random.nextNetwork())
assertNotEquals("Freenode", network.networkName())
network.setNetworkName("Freenode")
assertEquals("Freenode", network.networkName())
}
@Test
fun testCurrentServer() {
val random = Random(1337)
val network = Network(state = random.nextNetwork())
assertNotEquals("irc.freenode.org", network.currentServer())
network.setCurrentServer("irc.freenode.org")
assertEquals("irc.freenode.org", network.currentServer())
}
@Test
fun testConnectionStateValid() {
val random = Random(1337)
val network = Network(state = random.nextNetwork())
assertNotEquals(ConnectionState.Initializing, network.connectionState())
network.setConnectionState(ConnectionState.Initializing.value)
assertEquals(ConnectionState.Initializing, network.connectionState())
}
@Test
fun testConnectionStateInvalid() {
val random = Random(1337)
val network = Network(state = random.nextNetwork())
assertNotEquals(ConnectionState.Disconnected, network.connectionState())
network.setConnectionState(-2)
assertEquals(ConnectionState.Disconnected, network.connectionState())
}
@Test
fun testServerList() {
val random = Random(1337)
val network = Network(state = random.nextNetwork())
val desired = listOf(
NetworkServer(
host = "irc.freenode.org",
port = 6697u,
useSsl = true,
sslVerify = true,
),
NetworkServer(
host = "irc.freenode.org",
port = 6667u,
useSsl = false,
sslVerify = false,
)
)
assertNotEquals(desired, network.serverList())
network.setServerList(
desired.map {
qVariant(it, QuasselType.NetworkServer)
}
)
assertEquals(desired, network.serverList())
}
@Test
fun testUseRandomServer() {
val random = Random(1337)
val network = Network(state = random.nextNetwork())
network.setUseRandomServer(false)
assertEquals(false, network.useRandomServer())
network.setUseRandomServer(true)
assertEquals(true, network.useRandomServer())
}
@Test
fun testPerform() {
val random = Random(1337)
val network = Network(state = random.nextNetwork())
val value = listOf(
"/wait 5; /ns ghost",
null,
"/mode -x"
)
val desired = listOf(
"/wait 5; /ns ghost",
"",
"/mode -x"
)
assertNotEquals(desired, network.perform())
network.setPerform(value)
assertEquals(desired, network.perform())
}
@Test
fun testUseAutoIdentify() {
val random = Random(1337)
val network = Network(state = random.nextNetwork())
network.setUseAutoIdentify(false)
assertEquals(false, network.useAutoIdentify())
network.setUseAutoIdentify(true)
assertEquals(true, network.useAutoIdentify())
}
@Test
fun testAutoIdentifyPassword() {
val random = Random(1337)
val network = Network(state = random.nextNetwork())
assertNotEquals("hunter2", network.autoIdentifyPassword())
network.setAutoIdentifyPassword("hunter2")
assertEquals("hunter2", network.autoIdentifyPassword())
}
@Test
fun testAutoIdentifyService() {
val random = Random(1337)
val network = Network(state = random.nextNetwork())
assertNotEquals("NickServ", network.autoIdentifyService())
network.setAutoIdentifyService("NickServ")
assertEquals("NickServ", network.autoIdentifyService())
}
@Test
fun testUseSasl() {
val random = Random(1337)
val network = Network(state = random.nextNetwork())
network.setUseSasl(false)
assertEquals(false, network.useSasl())
network.setUseSasl(true)
assertEquals(true, network.useSasl())
}
@Test
fun testSaslAccount() {
val random = Random(1337)
val network = Network(state = random.nextNetwork())
assertNotEquals("AzureDiamond", network.saslAccount())
network.setSaslAccount("AzureDiamond")
assertEquals("AzureDiamond", network.saslAccount())
}
@Test
fun testSaslPassword() {
val random = Random(1337)
val network = Network(state = random.nextNetwork())
assertNotEquals("hunter2", network.saslPassword())
network.setSaslPassword("hunter2")
assertEquals("hunter2", network.saslPassword())
}
@Test
fun testUseAutoReconnect() {
val random = Random(1337)
val network = Network(state = random.nextNetwork())
network.setUseAutoReconnect(false)
assertEquals(false, network.useAutoReconnect())
network.setUseAutoReconnect(true)
assertEquals(true, network.useAutoReconnect())
}
@Test
fun testAutoReconnectInterval() {
val random = Random(1337)
val network = Network(state = random.nextNetwork())
assertNotEquals(2500u, network.autoReconnectInterval())
network.setAutoReconnectInterval(2500u)
assertEquals(2500u, network.autoReconnectInterval())
}
@Test
fun testAutoReconnectRetries() {
val random = Random(1337)
val network = Network(state = random.nextNetwork())
assertNotEquals(7u.toUShort(), network.autoReconnectRetries())
network.setAutoReconnectRetries(7u.toUShort())
assertEquals(7u.toUShort(), network.autoReconnectRetries())
}
@Test
fun testUnlimitedReconnectRetries() {
val random = Random(1337)
val network = Network(state = random.nextNetwork())
network.setUnlimitedReconnectRetries(false)
assertEquals(false, network.unlimitedReconnectRetries())
network.setUnlimitedReconnectRetries(true)
assertEquals(true, network.unlimitedReconnectRetries())
}
@Test
fun testRejoinChannels() {
val random = Random(1337)
val network = Network(state = random.nextNetwork())
network.setRejoinChannels(false)
assertEquals(false, network.rejoinChannels())
network.setRejoinChannels(true)
assertEquals(true, network.rejoinChannels())
}
@Test
fun testUseCustomMessageRate() {
val random = Random(1337)
val network = Network(state = random.nextNetwork())
network.setUseCustomMessageRate(false)
assertEquals(false, network.useCustomMessageRate())
network.setUseCustomMessageRate(true)
assertEquals(true, network.useCustomMessageRate())
}
@Test
fun testMessageRateBurstSize() {
val random = Random(1337)
val network = Network(state = random.nextNetwork())
assertNotEquals(20u, network.messageRateBurstSize())
network.setMessageRateBurstSize(20u)
assertEquals(20u, network.messageRateBurstSize())
}
@Test
fun testMessageRateDelay() {
val random = Random(1337)
val network = Network(state = random.nextNetwork())
assertNotEquals(1200u, network.messageRateDelay())
network.setMessageRateDelay(1200u)
assertEquals(1200u, network.messageRateDelay())
}
@Test
fun testUnlimitedMessageRate() {
val random = Random(1337)
val network = Network(state = random.nextNetwork())
network.setUnlimitedMessageRate(false)
assertEquals(false, network.unlimitedMessageRate())
network.setUnlimitedMessageRate(true)
assertEquals(true, network.unlimitedMessageRate())
}
@Test
fun testCodecForServer() {
val random = Random(1337)
val network = Network(state = random.nextNetwork())
assertNotEquals("UTF_8", network.codecForServer())
network.setCodecForServer(StringSerializerUtf8.serializeRaw("UTF_8"))
assertEquals("UTF_8", network.codecForServer())
network.setCodecForServer(StringSerializerUtf8.serializeRaw("ISO_8859_1"))
assertEquals("ISO_8859_1", network.codecForServer())
}
@Test
fun testCodecForEncoding() {
val random = Random(1337)
val network = Network(state = random.nextNetwork())
assertNotEquals("UTF_8", network.codecForEncoding())
network.setCodecForEncoding(StringSerializerUtf8.serializeRaw("UTF_8"))
assertEquals("UTF_8", network.codecForEncoding())
network.setCodecForEncoding(StringSerializerUtf8.serializeRaw("ISO_8859_1"))
assertEquals("ISO_8859_1", network.codecForEncoding())
}
@Test
fun testCodecForDecoding() {
val random = Random(1337)
val network = Network(state = random.nextNetwork())
assertNotEquals("UTF_8", network.codecForDecoding())
network.setCodecForDecoding(StringSerializerUtf8.serializeRaw("UTF_8"))
assertEquals("UTF_8", network.codecForDecoding())
network.setCodecForDecoding(StringSerializerUtf8.serializeRaw("ISO_8859_1"))
assertEquals("ISO_8859_1", network.codecForDecoding())
}
}
@Nested
inner class User {
@Test
fun addNew() {
val random = Random(1337)
val session = NetworkMockSession()
val network = Network(session, state = random.nextNetwork(networkId = NetworkId(random.nextInt())))
val sizeBefore = network.ircUserCount()
assertNotEquals(0, sizeBefore)
val userName = random.nextString()
assertFalse(network.nicks().contains(userName))
assertFalse(session.synchronizeCalls.contains(network.ircUser(userName) as SyncableStub?))
network.addIrcUser(userName)
assertEquals(sizeBefore + 1, network.ircUserCount())
assertTrue(network.nicks().contains(userName))
assertTrue(session.synchronizeCalls.contains(network.ircUser(userName) as SyncableStub?))
}
@Test
fun addNewOffline() {
val random = Random(1337)
val network = Network(state = random.nextNetwork(networkId = NetworkId(random.nextInt())))
val sizeBefore = network.ircUserCount()
assertNotEquals(0, sizeBefore)
val userName = random.nextString()
assertFalse(network.nicks().contains(userName))
network.addIrcUser(userName)
assertEquals(sizeBefore + 1, network.ircUserCount())
assertTrue(network.nicks().contains(userName))
}
@Test
fun addExisting() {
val random = Random(1337)
val session = NetworkMockSession()
val network = Network(session, state = random.nextNetwork(networkId = NetworkId(random.nextInt())))
assertNotEquals(0, network.ircUserCount())
val user = network.ircUsers().first()
assertTrue(network.nicks().contains(user.nick()))
assertFalse(session.synchronizeCalls.contains(network.ircUser(user.nick()) as SyncableStub?))
assertEquals(user, network.newIrcUser(user.hostMask()))
assertTrue(network.nicks().contains(user.nick()))
assertFalse(session.synchronizeCalls.contains(network.ircUser(user.nick()) as SyncableStub?))
}
@Test
fun addExistingOffline() {
val random = Random(1337)
val network = Network(state = random.nextNetwork(networkId = NetworkId(random.nextInt())))
assertNotEquals(0, network.ircUserCount())
val user = network.ircUsers().first()
assertTrue(network.nicks().contains(user.nick()))
assertEquals(user, network.newIrcUser(user.hostMask()))
assertTrue(network.nicks().contains(user.nick()))
}
@Test
fun removeExisting() {
val random = Random(1337)
val network = Network(state = random.nextNetwork(networkId = NetworkId(random.nextInt())))
val sizeBefore = network.ircUserCount()
assertNotEquals(0, sizeBefore)
val user = network.ircUsers().first()
assertTrue(network.nicks().contains(user.nick()))
network.removeIrcUser(user)
assertEquals(sizeBefore - 1, network.ircUserCount())
assertFalse(network.nicks().contains(user.nick()))
}
}
@Nested
inner class Channel {
@Test
fun addNew() {
val random = Random(1337)
val session = NetworkMockSession()
val network = Network(session, state = random.nextNetwork(networkId = NetworkId(random.nextInt())))
val sizeBefore = network.ircChannelCount()
assertNotEquals(0, sizeBefore)
val channelName = random.nextString()
assertFalse(session.synchronizeCalls.contains(network.ircChannel(channelName) as SyncableStub?))
network.addIrcChannel(channelName)
assertEquals(sizeBefore + 1, network.ircChannelCount())
assertTrue(network.channels().contains(channelName))
assertTrue(session.synchronizeCalls.contains(network.ircChannel(channelName) as SyncableStub?))
}
@Test
fun addNewOffline() {
val random = Random(1337)
val network = Network(state = random.nextNetwork(networkId = NetworkId(random.nextInt())))
val sizeBefore = network.ircChannelCount()
assertNotEquals(0, sizeBefore)
val channelName = random.nextString()
network.addIrcChannel(channelName)
assertEquals(sizeBefore + 1, network.ircChannelCount())
assertTrue(network.channels().contains(channelName))
}
@Test
fun addExisting() {
val random = Random(1337)
val session = NetworkMockSession()
val network = Network(session, state = random.nextNetwork(networkId = NetworkId(random.nextInt())))
assertNotEquals(0, network.ircUserCount())
val existing = network.ircChannels().first()
assertFalse(session.synchronizeCalls.contains(network.ircChannel(existing.name()) as SyncableStub?))
assertEquals(existing, network.newIrcChannel(existing.name()))
assertFalse(session.synchronizeCalls.contains(network.ircChannel(existing.name()) as SyncableStub?))
}
@Test
fun addExistingOffline() {
val random = Random(1337)
val network = Network(state = random.nextNetwork(networkId = NetworkId(random.nextInt())))
assertNotEquals(0, network.ircUserCount())
val existing = network.ircChannels().first()
assertEquals(existing, network.newIrcChannel(existing.name()))
}
@Test
fun removeExisting() {
val random = Random(1337)
val network = Network(state = random.nextNetwork(networkId = NetworkId(random.nextInt())))
val sizeBefore = network.ircChannelCount()
assertNotEquals(0, sizeBefore)
network.removeIrcChannel(network.ircChannels().first())
assertEquals(sizeBefore - 1, network.ircChannelCount())
}
}
@Nested
inner class Support {
@Test
fun addNew() {
val random = Random(1337)
val network = Network(state = random.nextNetwork(networkId = NetworkId(random.nextInt())))
val sizeBefore = network.supports().size
assertNotEquals(0, sizeBefore)
val key = random.nextString()
val value = random.nextString()
assertFalse(network.supports(key))
assertNotEquals(value, network.supportValue(key))
network.addSupport(key, value)
assertEquals(sizeBefore + 1, network.supports().size)
assertTrue(network.supports(key))
assertEquals(value, network.supportValue(key))
}
@Test
fun addExisting() {
val random = Random(1337)
val network = Network(state = random.nextNetwork(networkId = NetworkId(random.nextInt())))
val sizeBefore = network.supports().size
assertNotEquals(0, sizeBefore)
val key = network.supports().keys.first()
val value = random.nextString()
assertTrue(network.supports(key))
assertNotEquals(value, network.supportValue(key))
network.addSupport(key, value)
assertEquals(sizeBefore, network.supports().size)
assertTrue(network.supports(key))
assertEquals(value, network.supportValue(key))
}
@Test
fun removeExisting() {
val random = Random(1337)
val network = Network(state = random.nextNetwork(networkId = NetworkId(random.nextInt())))
val sizeBefore = network.supports().size
assertNotEquals(0, sizeBefore)
val key = network.supports().keys.first()
assertTrue(network.supports(key))
network.removeSupport(key)
assertEquals(sizeBefore - 1, network.supports().size)
assertFalse(network.supports(key))
assertEquals(null, network.supportValue(key))
}
}
@Nested
inner class Capability {
@Test
fun addNew() {
val random = Random(1337)
val network = Network(state = random.nextNetwork(networkId = NetworkId(random.nextInt())))
val sizeBefore = network.caps().size
assertNotEquals(0, sizeBefore)
val key = random.nextString()
val value = random.nextString()
assertFalse(network.capAvailable(key))
assertNotEquals(value, network.capValue(key))
network.addCap(key, value)
assertEquals(sizeBefore + 1, network.caps().size)
assertTrue(network.capAvailable(key))
assertEquals(value, network.capValue(key))
}
@Test
fun addExisting() {
val random = Random(1337)
val network = Network(state = random.nextNetwork(networkId = NetworkId(random.nextInt())))
val sizeBefore = network.caps().size
assertNotEquals(0, sizeBefore)
val key = network.caps().keys.first()
val value = random.nextString()
assertTrue(network.capAvailable(key))
assertNotEquals(value, network.capValue(key))
network.addCap(key, value)
assertEquals(sizeBefore, network.caps().size)
assertTrue(network.capAvailable(key))
assertEquals(value, network.capValue(key))
}
@Test
fun acknowledgeNew() {
val random = Random(1337)
val network = Network(state = random.nextNetwork(networkId = NetworkId(random.nextInt())))
val sizeBefore = network.capsEnabled().size
assertNotEquals(0, sizeBefore)
val key = random.nextString()
assertFalse(network.capEnabled(key))
network.acknowledgeCap(key)
assertEquals(sizeBefore + 1, network.capsEnabled().size)
assertTrue(network.capEnabled(key))
}
@Test
fun acknowledgeExisting() {
val random = Random(1337)
val network = Network(state = random.nextNetwork(networkId = NetworkId(random.nextInt())))
val sizeBefore = network.capsEnabled().size
assertNotEquals(0, sizeBefore)
val key = network.capsEnabled().first()
assertTrue(network.capEnabled(key))
network.acknowledgeCap(key)
assertEquals(sizeBefore, network.capsEnabled().size)
assertTrue(network.capEnabled(key))
}
@Test
fun removeExisting() {
val random = Random(1337)
val network = Network(state = random.nextNetwork(networkId = NetworkId(random.nextInt())))
val sizeBefore = network.caps().size
assertNotEquals(0, sizeBefore)
network.removeCap(network.caps().keys.first())
assertEquals(sizeBefore - 1, network.caps().size)
}
@Test
fun clear() {
val random = Random(1337)
val network = Network(state = random.nextNetwork(networkId = NetworkId(random.nextInt())))
val sizeBefore = network.caps().size
assertNotEquals(0, sizeBefore)
network.clearCaps()
assertEquals(0, network.caps().size)
assertEquals(0, network.capsEnabled().size)
}
}
@Nested
inner class ChannelModes {
@Test
fun usual() {
val network = Network(
state = NetworkState(
networkId = NetworkId(1),
supports = mapOf(
"CHANMODES" to "eIbq,k,flj,CFLMPQScgimnprstuz"
)
)
)
assertEquals(
mapOf(
ChannelModeType.A_CHANMODE to setOf('e', 'I', 'b', 'q'),
ChannelModeType.B_CHANMODE to setOf('k'),
ChannelModeType.C_CHANMODE to setOf('f', 'l', 'j'),
ChannelModeType.D_CHANMODE to setOf(
'C', 'F', 'L', 'M', 'P', 'Q', 'S', 'c', 'g', 'i', 'm', 'n', 'p', 'r', 's', 't', 'u', 'z'
),
),
network.channelModes()
)
for (c in setOf('e', 'I', 'b', 'q')) {
assertEquals(ChannelModeType.A_CHANMODE, network.channelModeType(c))
}
for (c in setOf('k')) {
assertEquals(ChannelModeType.B_CHANMODE, network.channelModeType(c))
}
for (c in setOf('f', 'l', 'j')) {
assertEquals(ChannelModeType.C_CHANMODE, network.channelModeType(c))
}
for (c in setOf('C', 'F', 'L', 'M', 'P', 'Q', 'S', 'c', 'g', 'i', 'm', 'n', 'p', 'r', 's', 't', 'u', 'z')) {
assertEquals(ChannelModeType.D_CHANMODE, network.channelModeType(c))
}
}
@Test
fun blank() {
val network = Network(
state = NetworkState(
networkId = NetworkId(1),
supports = mapOf(
"CHANMODES" to ""
)
)
)
assertEquals(
mapOf<ChannelModeType, Set<Char>>(
ChannelModeType.A_CHANMODE to emptySet(),
ChannelModeType.B_CHANMODE to emptySet(),
ChannelModeType.C_CHANMODE to emptySet(),
ChannelModeType.D_CHANMODE to emptySet(),
),
network.channelModes()
)
}
@Test
fun empty() {
val network = Network(
state = NetworkState(
networkId = NetworkId(1),
supports = emptyMap()
)
)
assertEquals(
mapOf<ChannelModeType, Set<Char>>(
ChannelModeType.A_CHANMODE to emptySet(),
ChannelModeType.B_CHANMODE to emptySet(),
ChannelModeType.C_CHANMODE to emptySet(),
ChannelModeType.D_CHANMODE to emptySet(),
),
network.channelModes()
)
}
@Test
fun wrongData() {
val network = Network(
state = NetworkState(
networkId = NetworkId(1),
supports = mapOf(
"CHANMODES" to "a,b,c,d,e"
)
)
)
assertEquals(
mapOf(
ChannelModeType.A_CHANMODE to setOf('a'),
ChannelModeType.B_CHANMODE to setOf('b'),
ChannelModeType.C_CHANMODE to setOf('c'),
ChannelModeType.D_CHANMODE to setOf('d'),
),
network.channelModes()
)
}
}
@Nested
inner class Prefixes {
@Test
fun usual() {
val network = Network(
state = NetworkState(
networkId = NetworkId(1),
supports = mapOf(
"PREFIX" to "(@+)ov"
)
)
)
assertEquals(
listOf('@', '+'),
network.prefixes()
)
assertEquals(
listOf('o', 'v'),
network.prefixModes()
)
}
@Test
fun wrongFormatting() {
val network = Network(
state = NetworkState(
networkId = NetworkId(1),
supports = mapOf(
"PREFIX" to "(@+]ov"
)
)
)
assertEquals(
listOf('@', '+'),
network.prefixes()
)
assertEquals(
listOf('o', 'v'),
network.prefixModes()
)
}
@Test
fun onlyPrefixes() {
val network = Network(
state = NetworkState(
networkId = NetworkId(1),
supports = mapOf(
"PREFIX" to "@+"
)
)
)
assertEquals(
listOf('@', '+'),
network.prefixes()
)
assertEquals(
listOf('o', 'v'),
network.prefixModes()
)
}
@Test
fun onlyModes() {
val network = Network(
state = NetworkState(
networkId = NetworkId(1),
supports = mapOf(
"PREFIX" to "ov"
)
)
)
assertEquals(
listOf('@', '+'),
network.prefixes()
)
assertEquals(
listOf('o', 'v'),
network.prefixModes()
)
}
@Test
fun blank() {
val network = Network(
state = NetworkState(
networkId = NetworkId(1),
supports = mapOf(
"PREFIX" to ""
)
)
)
assertEquals(
listOf('~', '&', '@', '%', '+'),
network.prefixes()
)
assertEquals(
listOf('q', 'a', 'o', 'h', 'v'),
network.prefixModes()
)
}
@Test
fun wrongContent() {
val network = Network(
state = NetworkState(
networkId = NetworkId(1),
supports = mapOf(
"PREFIX" to "12345"
)
)
)
assertEquals(
listOf('~', '&', '@', '%', '+'),
network.prefixes()
)
assertEquals(
listOf('q', 'a', 'o', 'h', 'v'),
network.prefixModes()
)
}
}
class NetworkMockSession : EmptySession() {
val synchronizeCalls = mutableListOf<SyncableStub>()
override val proxy = object : EmptySyncProxy() {
override fun synchronize(syncable: SyncableStub) {
synchronizeCalls.add(syncable)
}
}
}
}
/*
* libquassel
* Copyright (c) 2021 Janne Mareike Koschinski
*
* This Source Code Form is subject to the terms of the Mozilla Public License,
* v. 2.0. If a copy of the MPL was not distributed with this file, You can
* obtain one at https://mozilla.org/MPL/2.0/.
*/
package de.justjanne.libquassel.protocol.syncables.invokers
import de.justjanne.libquassel.annotations.ProtocolSide
import de.justjanne.libquassel.protocol.syncables.invoker.Invokers
import org.junit.jupiter.api.Test
import kotlin.test.assertEquals
class InvokerTest {
@Test
fun testRegistered() {
assertEquals(
setOf(
"AliasManager",
"BacklogManager",
"BufferSyncer",
"BufferViewConfig",
"BufferViewManager",
"CertManager",
"CoreInfo",
"DccConfig",
"HighlightRuleManager",
"Identity",
"IgnoreListManager",
"IrcChannel",
"IrcListHelper",
"IrcUser",
"NetworkConfig",
"Network",
"RpcHandler",
"TransferManager",
"Transfer"
),
Invokers.list(ProtocolSide.CLIENT)
)
}
}
......@@ -11,15 +11,10 @@ package de.justjanne.libquassel.protocol.testutil
import java.nio.ByteBuffer
@Suppress("NOTHING_TO_INLINE")
inline fun byteBufferOf(
vararg elements: Byte
): ByteBuffer = ByteBuffer.wrap(byteArrayOf(*elements))
inline fun byteBufferOf(vararg elements: Byte): ByteBuffer = ByteBuffer.wrap(byteArrayOf(*elements))
@Suppress("NOTHING_TO_INLINE")
inline fun byteBufferOf(
vararg elements: UByte
): ByteBuffer = ByteBuffer.wrap(ubyteArrayOf(*elements).toByteArray())
inline fun byteBufferOf(vararg elements: UByte): ByteBuffer = ByteBuffer.wrap(ubyteArrayOf(*elements).toByteArray())
@Suppress("NOTHING_TO_INLINE")
inline fun byteBufferOf(): ByteBuffer =
ByteBuffer.allocateDirect(0)
inline fun byteBufferOf(): ByteBuffer = ByteBuffer.allocateDirect(0)
......@@ -41,17 +41,18 @@ inline fun <reified T : HandshakeMessage> handshakeSerializerTest(
useChainedByteBuffer {
HandshakeMessageSerializer.serialize(it, value, serializeFeatureSet)
},
ByteBufferMatcher(encoded.withRewind())
ByteBufferMatcher(encoded.withRewind()),
)
}
}
for (featureSet in featureSets) {
val after = HandshakeMessageSerializer.deserialize(
useChainedByteBuffer {
HandshakeMessageSerializer.serialize(it, value, featureSet)
},
featureSet
)
val after =
HandshakeMessageSerializer.deserialize(
useChainedByteBuffer {
HandshakeMessageSerializer.serialize(it, value, featureSet)
},
featureSet,
)
assertEquals(T::class.java, after::class.java)
if (matcher != null) {
assertThat(after as? T, matcher(value))
......
......@@ -35,7 +35,7 @@ inline fun <reified T : Any?> primitiveSerializerTest(
matcher,
featureSets,
deserializeFeatureSet,
serializeFeatureSet
serializeFeatureSet,
)
inline fun <reified T : Any?> primitiveSerializerTest(
......@@ -53,7 +53,7 @@ inline fun <reified T : Any?> primitiveSerializerTest(
matcher,
featureSets,
deserializeFeatureSet,
serializeFeatureSet
serializeFeatureSet,
)
inline fun <reified T : Any?> primitiveSerializerTest(
......@@ -76,9 +76,10 @@ inline fun <reified T : Any?> primitiveSerializerTest(
}
}
if (serializeFeatureSet != null) {
val after = useChainedByteBuffer {
serializer.serialize(it, value, serializeFeatureSet)
}
val after =
useChainedByteBuffer {
serializer.serialize(it, value, serializeFeatureSet)
}
assertThat(after, ByteBufferMatcher(encoded.withRewind()))
}
}
......
......@@ -9,44 +9,16 @@
package de.justjanne.libquassel.protocol.testutil
import de.justjanne.bitflags.of
import de.justjanne.libquassel.protocol.features.FeatureSet
import de.justjanne.libquassel.protocol.features.LegacyFeature
import de.justjanne.libquassel.protocol.features.QuasselFeatureName
import de.justjanne.libquassel.protocol.models.BufferActivity
import de.justjanne.libquassel.protocol.models.BufferInfo
import de.justjanne.libquassel.protocol.models.ConnectedClient
import de.justjanne.libquassel.protocol.models.alias.Alias
import de.justjanne.libquassel.protocol.models.flags.BufferType
import de.justjanne.libquassel.protocol.models.flags.MessageType
import de.justjanne.libquassel.protocol.models.ids.BufferId
import de.justjanne.libquassel.protocol.models.ids.IdentityId
import de.justjanne.libquassel.protocol.models.ids.MsgId
import de.justjanne.libquassel.protocol.models.ids.NetworkId
import de.justjanne.libquassel.protocol.models.network.IdentityDto
import de.justjanne.libquassel.protocol.models.network.IrcChannelDto
import de.justjanne.libquassel.protocol.models.network.IrcUserDto
import de.justjanne.libquassel.protocol.models.network.NetworkInfoDto
import de.justjanne.libquassel.protocol.models.network.NetworkServer
import de.justjanne.libquassel.protocol.models.rules.HighlightRule
import de.justjanne.libquassel.protocol.models.rules.IgnoreRule
import de.justjanne.libquassel.protocol.syncables.common.BufferViewConfig
import de.justjanne.libquassel.protocol.syncables.common.IrcChannel
import de.justjanne.libquassel.protocol.syncables.common.IrcUser
import de.justjanne.libquassel.protocol.syncables.state.AliasManagerState
import de.justjanne.libquassel.protocol.syncables.state.BufferSyncerState
import de.justjanne.libquassel.protocol.syncables.state.BufferViewConfigState
import de.justjanne.libquassel.protocol.syncables.state.BufferViewManagerState
import de.justjanne.libquassel.protocol.syncables.state.CertManagerState
import de.justjanne.libquassel.protocol.syncables.state.CoreInfoState
import de.justjanne.libquassel.protocol.syncables.state.DccConfigState
import de.justjanne.libquassel.protocol.syncables.state.IdentityState
import de.justjanne.libquassel.protocol.syncables.state.IrcChannelState
import de.justjanne.libquassel.protocol.syncables.state.IrcUserState
import de.justjanne.libquassel.protocol.syncables.state.NetworkConfigState
import de.justjanne.libquassel.protocol.syncables.state.NetworkState
import org.threeten.bp.Instant
import org.threeten.bp.temporal.ChronoUnit
import java.net.InetAddress
import java.util.EnumSet
import java.util.Locale
import java.util.UUID
import java.util.EnumSet
import kotlin.random.Random
import kotlin.random.nextUInt
......@@ -69,273 +41,104 @@ inline fun <reified T : Enum<T>> Random.nextEnum(): T {
fun Random.nextInstant(): Instant = Instant.ofEpochMilli(nextLong())
fun Random.nextNetwork(networkId: NetworkId = NetworkId(nextInt())) = NetworkState(
networkId = networkId,
identity = IdentityId(nextInt()),
myNick = nextString(),
latency = nextInt(),
networkName = nextString(),
currentServer = nextString(),
connected = nextBoolean(),
connectionState = nextEnum(),
ircUsers = List(nextInt(20)) {
IrcUser(state = nextIrcUser(networkId))
}.associateBy(IrcUser::nick).mapKeys { (key) ->
key.lowercase(Locale.ROOT)
},
ircChannels = List(nextInt(20)) {
IrcChannel(state = nextIrcChannel(networkId))
}.associateBy(IrcChannel::name).mapKeys { (key) ->
key.lowercase(Locale.ROOT)
},
supports = List(nextInt(20)) {
nextString().uppercase(Locale.ROOT) to nextString()
}.toMap(),
caps = List(nextInt(20)) {
nextString().lowercase(Locale.ROOT) to nextString()
}.toMap(),
capsEnabled = List(nextInt(20)) {
nextString()
}.toSet(),
serverList = List(nextInt(20)) {
nextNetworkServer()
},
useRandomServer = nextBoolean(),
perform = List(nextInt(20)) {
nextString()
},
useAutoIdentify = nextBoolean(),
autoIdentifyService = nextString(),
autoIdentifyPassword = nextString(),
useSasl = nextBoolean(),
saslAccount = nextString(),
saslPassword = nextString(),
useAutoReconnect = nextBoolean(),
autoReconnectInterval = nextUInt(),
autoReconnectRetries = nextUInt(UShort.MAX_VALUE.toUInt()).toUShort(),
unlimitedReconnectRetries = nextBoolean(),
rejoinChannels = nextBoolean(),
useCustomMessageRate = nextBoolean(),
messageRateBurstSize = nextUInt(),
messageRateDelay = nextUInt(),
codecForServer = nextString(),
codecForEncoding = nextString(),
codecForDecoding = nextString()
)
fun Random.nextNetworkServer() = NetworkServer(
host = nextString(),
port = nextUInt(),
password = nextString(),
useSsl = nextBoolean(),
sslVerify = nextBoolean(),
sslVersion = nextInt(),
useProxy = nextBoolean(),
proxyType = nextEnum(),
proxyHost = nextString(),
proxyPort = nextUInt(),
proxyUser = nextString(),
proxyPass = nextString()
)
fun Random.nextIrcUser(
networkId: NetworkId = NetworkId(nextInt())
) = IrcUserState(
network = networkId,
nick = nextString(),
user = nextString(),
host = nextString(),
realName = nextString(),
account = nextString(),
away = nextBoolean(),
awayMessage = nextString(),
idleTime = nextInstant(),
loginTime = nextInstant(),
server = nextString(),
ircOperator = nextString(),
lastAwayMessageTime = nextInstant(),
whoisServiceReply = nextString(),
suserHost = nextString(),
encrypted = nextBoolean()
)
fun Random.nextIrcChannel(
networkId: NetworkId = NetworkId(nextInt())
) = IrcChannelState(
network = networkId,
name = nextString(),
topic = nextString(),
password = nextString(),
encrypted = nextBoolean()
)
fun Random.nextBufferViewConfig(
bufferViewId: Int = nextInt()
) = BufferViewConfigState(
bufferViewId = bufferViewId,
bufferViewName = nextString(),
networkId = NetworkId(nextInt()),
addNewBuffersAutomatically = nextBoolean(),
sortAlphabetically = nextBoolean(),
hideInactiveNetworks = nextBoolean(),
hideInactiveBuffers = nextBoolean(),
disableDecoration = nextBoolean(),
allowedBufferTypes = BufferType.of(
List(nextInt(BufferType.values().size)) {
nextEnum()
}
),
minimumActivity = nextEnum<BufferActivity>(),
showSearch = nextBoolean(),
buffers = List(nextInt(5, 20)) {
BufferId(nextInt(0, 33))
}.toSet().toList().shuffled(),
removedBuffers = List(nextInt(5, 20)) {
BufferId(nextInt(34, 66))
}.toSet(),
hiddenBuffers = List(nextInt(5, 20)) {
BufferId(nextInt(67, 100))
}.toSet()
)
fun Random.nextAliasManager() = AliasManagerState(
aliases = List(nextInt(20)) {
Alias(nextString(), nextString())
}
)
fun Random.nextBufferViewManager() = BufferViewManagerState(
bufferViewConfigs = List(nextInt(20)) {
BufferViewConfig(state = BufferViewConfigState(bufferViewId = nextInt()))
}.associateBy(BufferViewConfig::bufferViewId)
)
fun Random.nextBufferSyncer(): BufferSyncerState {
val bufferInfos = List(nextInt(20)) { nextBufferInfo() }
val buffers = bufferInfos.map(BufferInfo::bufferId)
return BufferSyncerState(
activities = buffers.associateWith {
MessageType.of(nextUInt())
},
highlightCounts = buffers.associateWith { nextUInt(20u).toInt() },
lastSeenMsg = buffers.associateWith { MsgId(nextLong()) },
markerLines = buffers.associateWith { MsgId(nextLong()) },
bufferInfos = bufferInfos.associateBy(BufferInfo::bufferId),
fun Random.nextNetworkInfo(networkId: NetworkId = NetworkId(nextInt())) =
NetworkInfoDto(
networkId = networkId,
identity = IdentityId(nextInt()),
networkName = nextString(),
serverList =
List(nextInt(20)) {
nextNetworkServer()
},
useRandomServer = nextBoolean(),
perform =
List(nextInt(20)) {
nextString()
},
useAutoIdentify = nextBoolean(),
autoIdentifyService = nextString(),
autoIdentifyPassword = nextString(),
useSasl = nextBoolean(),
saslAccount = nextString(),
saslPassword = nextString(),
useAutoReconnect = nextBoolean(),
autoReconnectInterval = nextUInt(),
autoReconnectRetries = nextUInt(UShort.MAX_VALUE.toUInt()).toUShort(),
unlimitedReconnectRetries = nextBoolean(),
rejoinChannels = nextBoolean(),
useCustomMessageRate = nextBoolean(),
messageRateBurstSize = nextUInt(),
messageRateDelay = nextUInt(),
codecForServer = nextString(),
codecForEncoding = nextString(),
codecForDecoding = nextString(),
)
}
fun Random.nextBufferInfo(
bufferId: BufferId = BufferId(nextInt()),
networkId: NetworkId = NetworkId(nextInt())
) = BufferInfo(
bufferId = bufferId,
networkId = networkId,
type = BufferType.of(nextUInt().toUShort()),
groupId = -1,
bufferName = nextString()
)
fun Random.nextCertManager(identityId: IdentityId = IdentityId(nextInt())) = CertManagerState(
identityId = identityId,
certificatePem = nextString(),
privateKeyPem = nextString()
)
fun Random.nextCoreInfo() = CoreInfoState(
version = nextString(),
versionDate = nextInstant().truncatedTo(ChronoUnit.SECONDS),
startTime = nextInstant(),
connectedClientCount = nextInt(),
connectedClients = List(nextInt(20)) {
nextConnectedClient()
}
)
fun Random.nextConnectedClient() = ConnectedClient(
id = nextInt(),
remoteAddress = nextString(),
location = nextString(),
version = nextString(),
versionDate = nextInstant().truncatedTo(ChronoUnit.SECONDS),
connectedSince = nextInstant(),
secure = nextBoolean(),
features = nextFeatureSet()
)
fun Random.nextFeatureSet() = FeatureSet.build(
LegacyFeature.of(nextUInt()),
List(nextInt(20)) {
QuasselFeatureName(nextString())
}
)
fun Random.nextDccConfig() = DccConfigState(
dccEnabled = nextBoolean(),
outgoingIp = InetAddress.getByAddress(nextBytes(4)),
ipDetectionMode = nextEnum(),
portSelectionMode = nextEnum(),
minPort = nextUInt().toUShort(),
maxPort = nextUInt().toUShort(),
chunkSize = nextInt(),
sendTimeout = nextInt(),
usePassiveDcc = nextBoolean(),
useFastSend = nextBoolean()
)
fun Random.nextHighlightRule(id: Int) = HighlightRule(
id = id,
content = nextString(),
isRegEx = nextBoolean(),
isCaseSensitive = nextBoolean(),
isEnabled = nextBoolean(),
isInverse = nextBoolean(),
sender = nextString(),
channel = nextString()
)
fun Random.nextNetworkServer() =
NetworkServer(
host = nextString(),
port = nextUInt(),
password = nextString(),
useSsl = nextBoolean(),
sslVerify = nextBoolean(),
sslVersion = nextInt(),
useProxy = nextBoolean(),
proxyType = nextEnum(),
proxyHost = nextString(),
proxyPort = nextUInt(),
proxyUser = nextString(),
proxyPass = nextString(),
)
fun Random.nextIdentity(
identityId: IdentityId = IdentityId(nextInt())
) = IdentityState(
identityId = identityId,
identityName = nextString(),
realName = nextString(),
nicks = List(nextInt(20)) {
nextString()
},
awayNick = nextString(),
awayNickEnabled = nextBoolean(),
awayReason = nextString(),
awayReasonEnabled = nextBoolean(),
autoAwayEnabled = nextBoolean(),
autoAwayTime = nextInt(),
autoAwayReason = nextString(),
autoAwayReasonEnabled = nextBoolean(),
detachAwayEnabled = nextBoolean(),
detachAwayReason = nextString(),
detachAwayReasonEnabled = nextBoolean(),
ident = nextString(),
kickReason = nextString(),
partReason = nextString(),
quitReason = nextString()
)
fun Random.nextIrcUser() =
IrcUserDto(
nick = nextString(),
user = nextString(),
host = nextString(),
realName = nextString(),
account = nextString(),
away = nextBoolean(),
awayMessage = nextString(),
idleTime = nextInstant(),
loginTime = nextInstant(),
server = nextString(),
ircOperator = nextString(),
lastAwayMessageTime = nextInstant(),
whoisServiceReply = nextString(),
suserHost = nextString(),
encrypted = nextBoolean(),
)
fun Random.nextIgnoreRule() = IgnoreRule(
type = nextEnum(),
ignoreRule = nextString(),
isRegEx = nextBoolean(),
strictness = nextEnum(),
isEnabled = nextBoolean(),
scope = nextEnum(),
scopeRule = nextString()
)
fun Random.nextIrcChannel() =
IrcChannelDto(
name = nextString(),
topic = nextString(),
password = nextString(),
encrypted = nextBoolean(),
)
fun Random.nextNetworkConfig() = NetworkConfigState(
pingTimeoutEnabled = nextBoolean(),
pingInterval = nextInt(),
maxPingCount = nextInt(),
autoWhoEnabled = nextBoolean(),
autoWhoInterval = nextInt(),
autoWhoNickLimit = nextInt(),
autoWhoDelay = nextInt(),
standardCtcp = nextBoolean()
)
fun Random.nextIdentity(identityId: IdentityId = IdentityId(nextInt())) =
IdentityDto(
identityId = identityId,
identityName = nextString(),
realName = nextString(),
nicks =
List(nextInt(20)) {
nextString()
},
awayNick = nextString(),
awayNickEnabled = nextBoolean(),
awayReason = nextString(),
awayReasonEnabled = nextBoolean(),
autoAwayEnabled = nextBoolean(),
autoAwayTime = nextInt(),
autoAwayReason = nextString(),
autoAwayReasonEnabled = nextBoolean(),
detachAwayEnabled = nextBoolean(),
detachAwayReason = nextString(),
detachAwayReasonEnabled = nextBoolean(),
ident = nextString(),
kickReason = nextString(),
partReason = nextString(),
quitReason = nextString(),
)
......@@ -37,9 +37,10 @@ fun <T : Any?> serializerTest(
}
}
if (serializeFeatureSet != null) {
val after = useChainedByteBuffer {
serializer.serialize(it, value, serializeFeatureSet)
}
val after =
useChainedByteBuffer {
serializer.serialize(it, value, serializeFeatureSet)
}
assertThat(after, ByteBufferMatcher(encoded.withRewind()))
}
}
......
......@@ -41,17 +41,18 @@ inline fun <reified T : SignalProxyMessage> signalProxySerializerTest(
useChainedByteBuffer {
SignalProxyMessageSerializer.serialize(it, value, serializeFeatureSet)
},
ByteBufferMatcher(encoded.withRewind())
ByteBufferMatcher(encoded.withRewind()),
)
}
}
for (featureSet in featureSets) {
val after = SignalProxyMessageSerializer.deserialize(
useChainedByteBuffer {
SignalProxyMessageSerializer.serialize(it, value, featureSet)
},
featureSet
)
val after =
SignalProxyMessageSerializer.deserialize(
useChainedByteBuffer {
SignalProxyMessageSerializer.serialize(it, value, featureSet)
},
featureSet,
)
assertEquals(T::class.java, after::class.java)
if (matcher != null) {
assertThat(after as? T, matcher(value))
......
......@@ -22,7 +22,7 @@ inline fun <reified T> testPrimitiveSerializerVariant(
type: QuasselType,
data: T,
featureSet: FeatureSet = FeatureSet.all(),
matcher: Matcher<in T>? = null
matcher: Matcher<in T>? = null,
) {
val buffer = ChainedByteBuffer(limit = 16384)
QVariantSerializer.serialize(buffer, qVariant(data, type), featureSet)
......@@ -41,7 +41,7 @@ inline fun <reified T> testPrimitiveSerializerVariant(
type: QtType,
data: T,
featureSet: FeatureSet = FeatureSet.all(),
matcher: Matcher<in T>? = null
matcher: Matcher<in T>? = null,
) {
val buffer = ChainedByteBuffer(limit = 16384)
QVariantSerializer.serialize(buffer, qVariant(data, type), featureSet)
......
/*
* libquassel
* Copyright (c) 2021 Janne Mareike Koschinski
* Copyright (c) 2024 Janne Mareike Koschinski
*
* This Source Code Form is subject to the terms of the Mozilla Public License,
* v. 2.0. If a copy of the MPL was not distributed with this file, You can
* obtain one at https://mozilla.org/MPL/2.0/.
*/
package de.justjanne.libquassel.protocol.testutil.matchers
import org.hamcrest.BaseMatcher
import org.hamcrest.Description
class BomMatcherChar(private val expected: Char) : BaseMatcher<Char>() {
private val malformed = charArrayOf(
'\uFFFE', '\uFEFF', '\uFFFD', ''
)
override fun describeTo(description: Description?) {
description?.appendText(expected.toString())
}
override fun matches(item: Any?): Boolean {
if (item is Char) {
return (item == expected) || (item in malformed && expected in malformed)
}
return false
}
override fun matches(item: Any?): Boolean =
item is Char && item == expected
}
......@@ -12,9 +12,7 @@ import org.hamcrest.BaseMatcher
import org.hamcrest.Description
class BomMatcherString(private val expected: String?) : BaseMatcher<String?>() {
private val malformed = charArrayOf(
'￾', ''
)
private val malformed = charArrayOf('\uFFFE', '\uFEFF')
override fun describeTo(description: Description?) {
description?.appendText(expected)
......
......@@ -16,20 +16,24 @@ import org.hamcrest.Description
import java.nio.ByteBuffer
class ByteBufferMatcher(buffer: ByteBuffer?) : BaseMatcher<ByteBuffer>() {
private val expected = buffer?.let { original ->
val copy = ByteBuffer.allocateDirect(original.limit())
original.rewind()
copy.put(original)
copy.rewind()
original.rewind()
copy
}
private val expected =
buffer?.let { original ->
val copy = ByteBuffer.allocateDirect(original.limit())
original.rewind()
copy.put(original)
copy.rewind()
original.rewind()
copy
}
override fun describeTo(description: Description?) {
description?.appendText(expected?.contentToString())
}
override fun describeMismatch(item: Any?, description: Description?) {
override fun describeMismatch(
item: Any?,
description: Description?,
) {
description?.appendText("was ")
description?.appendText((item as? ByteBuffer)?.withRewind()?.contentToString())
}
......
......@@ -13,13 +13,16 @@ import org.hamcrest.BaseMatcher
import org.hamcrest.Description
class MapMatcher<K, V>(
private val expected: Map<K, V>
private val expected: Map<K, V>,
) : BaseMatcher<Map<K, V>>() {
override fun describeTo(description: Description?) {
description?.appendText(expected.toString())
}
override fun describeMismatch(item: Any?, description: Description?) {
override fun describeMismatch(
item: Any?,
description: Description?,
) {
if (item is Map<*, *>) {
for (key in expected.keys) {
if (!item.containsKey(key)) {
......
......@@ -21,33 +21,38 @@ import org.threeten.bp.ZonedDateTime
import org.threeten.bp.temporal.Temporal
class TemporalMatcher<T : Temporal>(
private val expected: T
private val expected: T,
) : BaseMatcher<T>() {
override fun describeTo(description: Description?) {
description?.appendText(expected.toString())
}
private fun localDateTime(value: Any?): LocalDateTime? = when (value) {
is ZonedDateTime -> value.toLocalDateTime()
is OffsetDateTime -> value.toLocalDateTime()
is LocalDateTime -> value
is Instant -> value.atOffset(ZoneOffset.UTC).toLocalDateTime()
is LocalDate -> value.atTime(LocalTime.MIN)
is LocalTime -> value.atDate(LocalDate.MIN)
null -> null
else -> throw Exception("Unsupported date format: ${value::class.java.simpleName}")
}
private fun localDateTime(value: Any?): LocalDateTime? =
when (value) {
is ZonedDateTime -> value.toLocalDateTime()
is OffsetDateTime -> value.toLocalDateTime()
is LocalDateTime -> value
is Instant -> value.atOffset(ZoneOffset.UTC).toLocalDateTime()
is LocalDate -> value.atTime(LocalTime.MIN)
is LocalTime -> value.atDate(LocalDate.MIN)
null -> null
else -> throw Exception("Unsupported date format: ${value::class.java.simpleName}")
}
private fun offset(value: Any?): ZoneOffset = when (value) {
is ZonedDateTime -> value.offset
is OffsetDateTime -> value.offset
is LocalDateTime -> value.atZone(ZoneId.systemDefault()).toOffsetDateTime().offset
is LocalDate -> value.atTime(LocalTime.MIN).atZone(ZoneId.systemDefault()).toOffsetDateTime().offset
is LocalTime -> value.atDate(LocalDate.MIN).atZone(ZoneId.systemDefault()).toOffsetDateTime().offset
else -> ZoneOffset.UTC
}
private fun offset(value: Any?): ZoneOffset =
when (value) {
is ZonedDateTime -> value.offset
is OffsetDateTime -> value.offset
is LocalDateTime -> value.atZone(ZoneId.systemDefault()).toOffsetDateTime().offset
is LocalDate -> value.atTime(LocalTime.MIN).atZone(ZoneId.systemDefault()).toOffsetDateTime().offset
is LocalTime -> value.atDate(LocalDate.MIN).atZone(ZoneId.systemDefault()).toOffsetDateTime().offset
else -> ZoneOffset.UTC
}
override fun describeMismatch(item: Any?, description: Description?) {
override fun describeMismatch(
item: Any?,
description: Description?,
) {
if (localDateTime(item) != localDateTime(expected)) {
description?.appendText("Expected local date time of ")
description?.appendValue(localDateTime(expected))
......
/*
* libquassel
* Copyright (c) 2021 Janne Mareike Koschinski
*
* This Source Code Form is subject to the terms of the Mozilla Public License,
* v. 2.0. If a copy of the MPL was not distributed with this file, You can
* obtain one at https://mozilla.org/MPL/2.0/.
*/
package de.justjanne.libquassel.protocol.testutil.mocks
import de.justjanne.libquassel.annotations.ProtocolSide
import de.justjanne.libquassel.protocol.models.BufferInfo
import de.justjanne.libquassel.protocol.models.ids.IdentityId
import de.justjanne.libquassel.protocol.models.ids.NetworkId
import de.justjanne.libquassel.protocol.session.Session
import de.justjanne.libquassel.protocol.syncables.HeartBeatHandler
import de.justjanne.libquassel.protocol.syncables.ObjectRepository
import de.justjanne.libquassel.protocol.syncables.common.AliasManager
import de.justjanne.libquassel.protocol.syncables.common.BacklogManager
import de.justjanne.libquassel.protocol.syncables.common.BufferSyncer
import de.justjanne.libquassel.protocol.syncables.common.BufferViewManager
import de.justjanne.libquassel.protocol.syncables.common.CertManager
import de.justjanne.libquassel.protocol.syncables.common.CoreInfo
import de.justjanne.libquassel.protocol.syncables.common.DccConfig
import de.justjanne.libquassel.protocol.syncables.common.HighlightRuleManager
import de.justjanne.libquassel.protocol.syncables.common.Identity
import de.justjanne.libquassel.protocol.syncables.common.IgnoreListManager
import de.justjanne.libquassel.protocol.syncables.common.IrcListHelper
import de.justjanne.libquassel.protocol.syncables.common.Network
import de.justjanne.libquassel.protocol.syncables.common.NetworkConfig
import de.justjanne.libquassel.protocol.syncables.common.RpcHandler
import de.justjanne.libquassel.protocol.variant.QVariantMap
open class EmptySession : Session {
override val heartBeatHandler = HeartBeatHandler()
override val rpcHandler = RpcHandler(this)
final override val side = ProtocolSide.CLIENT
final override val objectRepository = ObjectRepository()
override val proxy = EmptySyncProxy()
override fun init(
identityInfo: List<QVariantMap>,
bufferInfos: List<BufferInfo>,
networkIds: List<NetworkId>
) = Unit
override fun network(id: NetworkId): Network? = null
override fun addNetwork(id: NetworkId) = Unit
override fun removeNetwork(id: NetworkId) = Unit
override fun networks() = emptySet<Network>()
override fun identity(id: IdentityId): Identity? = null
override fun addIdentity(properties: QVariantMap) = Unit
override fun removeIdentity(id: IdentityId) = Unit
override fun identities() = emptySet<Identity>()
override fun certManager(id: IdentityId): CertManager? = null
override fun certManagers() = emptySet<CertManager>()
override fun rename(className: String, oldName: String, newName: String) = Unit
override val aliasManager = AliasManager(this)
override val bufferSyncer = BufferSyncer(this)
override val backlogManager = BacklogManager(this)
override val bufferViewManager = BufferViewManager(this)
override val ignoreListManager = IgnoreListManager(this)
override val highlightRuleManager = HighlightRuleManager(this)
override val ircListHelper = IrcListHelper(this)
override val coreInfo = CoreInfo(this)
override val dccConfig = DccConfig(this)
override val networkConfig = NetworkConfig(this)
}
/*
* libquassel
* Copyright (c) 2021 Janne Mareike Koschinski
*
* This Source Code Form is subject to the terms of the Mozilla Public License,
* v. 2.0. If a copy of the MPL was not distributed with this file, You can
* obtain one at https://mozilla.org/MPL/2.0/.
*/
package de.justjanne.libquassel.protocol.testutil.mocks
import de.justjanne.bitflags.of
import de.justjanne.libquassel.irc.IrcCaseMapper
import de.justjanne.libquassel.protocol.models.BufferInfo
import de.justjanne.libquassel.protocol.models.flags.BufferType
import de.justjanne.libquassel.protocol.models.ids.BufferId
import de.justjanne.libquassel.protocol.models.ids.IdentityId
import de.justjanne.libquassel.protocol.models.ids.NetworkId
import de.justjanne.libquassel.protocol.models.network.ChannelModes
import de.justjanne.libquassel.protocol.models.network.ConnectionState
import de.justjanne.libquassel.protocol.models.network.NetworkServer
import de.justjanne.libquassel.protocol.models.network.PortDefaults
import de.justjanne.libquassel.protocol.syncables.common.BufferSyncer
import de.justjanne.libquassel.protocol.syncables.common.IrcChannel
import de.justjanne.libquassel.protocol.syncables.common.IrcUser
import de.justjanne.libquassel.protocol.syncables.common.Network
import de.justjanne.libquassel.protocol.syncables.state.BufferSyncerState
import de.justjanne.libquassel.protocol.syncables.state.IrcChannelState
import de.justjanne.libquassel.protocol.syncables.state.IrcUserState
import de.justjanne.libquassel.protocol.syncables.state.NetworkState
class RealisticSession : EmptySession() {
private val networks = setOf(
Network(
this,
NetworkState(
networkId = NetworkId(1),
networkName = "FreeNode",
currentServer = "tepper.freenode.net",
connected = true,
connectionState = ConnectionState.Initialized,
myNick = "justJanne",
latency = 48,
identity = IdentityId(1),
serverList = listOf(
NetworkServer(
"irc.freenode.net",
PortDefaults.PORT_SSL.port,
useSsl = true
),
NetworkServer(
"chat.freenode.net",
PortDefaults.PORT_SSL.port,
useSsl = true
)
),
supports = mapOf(
"CHANTYPES" to "#",
"EXCEPTS" to null,
"INVEX" to null,
"CHANMODES" to "eIbq,k,flj,CFLMPQScgimnprstz",
"CHANLIMIT" to "#:120",
"PREFIX" to "(ov)@+",
"MAXLIST" to "bqeI:100",
"MODES" to "4",
"NETWORK" to "freenode",
"STATUSMSG" to "@+",
"CALLERID" to "g",
"CASEMAPPING" to "rfc1459",
"CHARSET" to "ascii",
"NICKLEN" to "16",
"CHANNELLEN" to "50",
"TOPICLEN" to "390",
"DEAF" to "D",
"FNC" to null,
"TARGMAX" to "NAMES:1,LIST:1,KICK:1,WHOIS:1,PRIVMSG:4,NOTICE:4,ACCEPT:,MONITOR:",
"EXTBAN" to "$,ajrxz",
"CLIENTVER" to "3.0",
"ETRACE" to null,
"KNOCK" to null,
"WHOX" to null,
"CPRIVMSG" to null,
"CNOTICE" to null,
"SAFELIST" to null,
"ELIST" to "CTU",
),
caps = mapOf(
"account-notify" to null,
"sasl" to null,
"identify-msg" to null,
"multi-prefix" to null,
"extended-join" to null
),
capsEnabled = setOf(
"sasl",
"account-notify",
"extended-join",
"multi-prefix"
),
ircUsers = setOf(
IrcUser(
this,
IrcUserState(
network = NetworkId(1),
nick = "justJanne",
user = "kuschku",
host = "kuschku.de",
realName = "Janne Mareike Koschinski <janne@kuschku.de>",
account = "justJanne",
server = "tepper.freenode.net"
)
),
IrcUser(
this,
IrcUserState(
network = NetworkId(1),
nick = "digitalcircuit",
user = "~quassel",
host = "2605:6000:1518:830d:ec4:7aff:fe6b:c6b0",
realName = "Shane <avatar@mg.zorro.casa>",
account = "digitalcircuit",
server = "wolfe.freenode.net"
)
),
IrcUser(
this,
IrcUserState(
network = NetworkId(1),
nick = "Sput",
user = "~sputnick",
host = "quassel/developer/sput",
realName = "Sputnick -- http://quassel-irc.org",
account = "Sput",
server = "niven.freenode.net"
)
)
).associateBy { IrcCaseMapper["rfc1459"].toLowerCase(it.nick()) },
ircChannels = setOf(
IrcChannel(
this,
IrcChannelState(
network = NetworkId(1),
name = "#quassel-test",
topic = "Quassel testing channel",
channelModes = ChannelModes(
d = setOf('n', 't', 'c')
),
userModes = mapOf(
"justjanne" to emptySet(),
"digitalcircuit" to emptySet(),
"Sput" to emptySet(),
)
)
)
).associateBy(IrcChannel::name)
)
)
).associateBy(Network::networkId)
private val buffers = setOf(
BufferInfo(
bufferId = BufferId(1),
networkId = NetworkId(1),
bufferName = "FreeNode",
type = BufferType.of(BufferType.Status)
),
BufferInfo(
bufferId = BufferId(2),
networkId = NetworkId(1),
bufferName = "#quassel-test",
type = BufferType.of(BufferType.Channel)
),
BufferInfo(
bufferId = BufferId(3),
networkId = NetworkId(1),
bufferName = "digitalcircuit",
type = BufferType.of(BufferType.Query)
),
BufferInfo(
bufferId = BufferId(4),
networkId = NetworkId(1),
bufferName = "ChanServ",
type = BufferType.of(BufferType.Query)
),
).associateBy(BufferInfo::bufferId)
override fun network(id: NetworkId): Network? = networks[id]
override val bufferSyncer = BufferSyncer(
this,
BufferSyncerState(
bufferInfos = buffers
)
)
}
......@@ -19,7 +19,7 @@ fun <T> testPrimitiveSerializerDirect(
serializer: PrimitiveSerializer<T>,
data: T,
featureSet: FeatureSet = FeatureSet.all(),
matcher: Matcher<T>? = null
matcher: Matcher<T>? = null,
) {
val buffer = ChainedByteBuffer(limit = 16384)
serializer.serialize(buffer, data, featureSet)
......
......@@ -147,14 +147,14 @@ class SignedIdTest {
BufferId(Int.MIN_VALUE),
BufferId(-1),
BufferId(0),
BufferId(Int.MAX_VALUE)
BufferId(Int.MAX_VALUE),
),
listOf(
BufferId(Int.MAX_VALUE),
BufferId(Int.MIN_VALUE),
BufferId(0),
BufferId(-1)
).sorted()
BufferId(-1),
).sorted(),
)
assertEquals(
......@@ -162,14 +162,14 @@ class SignedIdTest {
IdentityId(Int.MIN_VALUE),
IdentityId(-1),
IdentityId(0),
IdentityId(Int.MAX_VALUE)
IdentityId(Int.MAX_VALUE),
),
listOf(
IdentityId(Int.MAX_VALUE),
IdentityId(Int.MIN_VALUE),
IdentityId(0),
IdentityId(-1)
).sorted()
IdentityId(-1),
).sorted(),
)
assertEquals(
......@@ -177,14 +177,14 @@ class SignedIdTest {
MsgId(Long.MIN_VALUE),
MsgId(-1),
MsgId(0),
MsgId(Long.MAX_VALUE)
MsgId(Long.MAX_VALUE),
),
listOf(
MsgId(Long.MAX_VALUE),
MsgId(Long.MIN_VALUE),
MsgId(0),
MsgId(-1)
).sorted()
MsgId(-1),
).sorted(),
)
assertEquals(
......@@ -192,14 +192,14 @@ class SignedIdTest {
NetworkId(Int.MIN_VALUE),
NetworkId(-1),
NetworkId(0),
NetworkId(Int.MAX_VALUE)
NetworkId(Int.MAX_VALUE),
),
listOf(
NetworkId(Int.MAX_VALUE),
NetworkId(Int.MIN_VALUE),
NetworkId(0),
NetworkId(-1)
).sorted()
NetworkId(-1),
).sorted(),
)
}
}