Skip to content

Commit 64faa98

Browse files
author
root
committed
Fix 2 more test failures: SessionManager fresh instance per test, reverseBits accessible
1 parent 62666c6 commit 64faa98

3 files changed

Lines changed: 14 additions & 15 deletions

File tree

app/src/main/java/com/debiandroid/desktop/vnc/RfbProtocol.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,8 @@ class RfbProtocol(
110110
}
111111
}
112112

113-
private fun reverseBits(b: Byte): Byte {
113+
companion object {
114+
internal fun reverseBits(b: Byte): Byte {
114115
var x = b.toInt() and 0xFF
115116
x = (x and 0x55 shl 1) or (x and 0xAA shr 1)
116117
x = (x and 0x33 shl 2) or (x and 0xCC shr 2)

app/src/test/java/com/debiandroid/desktop/data/SessionManagerTest.kt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import androidx.test.core.app.ApplicationProvider
55
import kotlinx.coroutines.flow.first
66
import kotlinx.coroutines.runBlocking
77
import org.junit.Assert.*
8+
import org.junit.Before
89
import org.junit.Test
910
import org.junit.runner.RunWith
1011
import org.robolectric.RobolectricTestRunner
@@ -13,7 +14,12 @@ import org.robolectric.RobolectricTestRunner
1314
class SessionManagerTest {
1415

1516
private val context = ApplicationProvider.getApplicationContext<Context>()
16-
private val sessionManager = SessionManager(context)
17+
private lateinit var sessionManager: SessionManager
18+
19+
@Before
20+
fun setUp() {
21+
sessionManager = SessionManager(context)
22+
}
1723

1824
@Test
1925
fun `default setup complete is false`() = runBlocking {

app/src/test/java/com/debiandroid/desktop/vnc/RfbProtocolTest.kt

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,11 @@ class RfbProtocolTest {
77

88
@Test
99
fun `reverseBits swaps bit order`() {
10-
val protocol = RfbProtocol(
11-
java.net.Socket(),
12-
"test"
13-
)
14-
15-
val method = RfbProtocol::class.java.getDeclaredMethod("reverseBits", Byte::class.java)
16-
method.isAccessible = true
17-
18-
assertEquals(0x00.toByte(), method.invoke(protocol, 0x00.toByte()))
19-
assertEquals(0x80.toByte(), method.invoke(protocol, 0x01.toByte()))
20-
assertEquals(0x01.toByte(), method.invoke(protocol, 0x80.toByte()))
21-
assertEquals(0xFF.toByte(), method.invoke(protocol, 0xFF.toByte()))
22-
assertEquals(0x0F.toByte(), method.invoke(protocol, 0xF0.toByte()))
10+
assertEquals(0x00.toByte(), RfbProtocol.reverseBits(0x00.toByte()))
11+
assertEquals(0x80.toByte(), RfbProtocol.reverseBits(0x01.toByte()))
12+
assertEquals(0x01.toByte(), RfbProtocol.reverseBits(0x80.toByte()))
13+
assertEquals(0xFF.toByte(), RfbProtocol.reverseBits(0xFF.toByte()))
14+
assertEquals(0x0F.toByte(), RfbProtocol.reverseBits(0xF0.toByte()))
2315
}
2416

2517
@Test

0 commit comments

Comments
 (0)