mirror of
https://github.com/meshtastic/Meshtastic-Android.git
synced 2026-03-21 07:11:25 -04:00
make channel unit tests
This commit is contained in:
22
app/src/androidTest/java/com/geeksville/mesh/ChannelTest.kt
Normal file
22
app/src/androidTest/java/com/geeksville/mesh/ChannelTest.kt
Normal file
@@ -0,0 +1,22 @@
|
||||
package com.geeksville.mesh
|
||||
|
||||
|
||||
import androidx.compose.frames.open
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4
|
||||
import com.geeksville.mesh.model.Channel
|
||||
import org.junit.Assert
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
|
||||
@RunWith(AndroidJUnit4::class)
|
||||
class ChannelTest {
|
||||
@Test
|
||||
fun channelUrlGood() {
|
||||
open() // Needed to make Compose think we are inside a Frame
|
||||
val ch = Channel.emulated
|
||||
|
||||
Assert.assertTrue(ch.getChannelUrl().toString().startsWith(Channel.prefix))
|
||||
Assert.assertEquals(Channel(ch.getChannelUrl()), ch)
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,13 +1,11 @@
|
||||
package com.geeksville.mesh
|
||||
|
||||
import androidx.test.platform.app.InstrumentationRegistry
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4
|
||||
|
||||
import androidx.test.platform.app.InstrumentationRegistry
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
|
||||
import org.junit.Assert.*
|
||||
|
||||
/**
|
||||
* Instrumented test, which will execute on an Android device.
|
||||
*
|
||||
@@ -19,6 +17,6 @@ class ExampleInstrumentedTest {
|
||||
fun useAppContext() {
|
||||
// Context of the app under test.
|
||||
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
|
||||
assertEquals("com.geeksville.com.geeksville.mesh", appContext.packageName)
|
||||
assertEquals("com.geeksville.mesh", appContext.packageName)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,11 +24,14 @@ import java.net.MalformedURLException
|
||||
data class Channel(
|
||||
var name: String,
|
||||
var modemConfig: ModemConfig,
|
||||
var settings: MeshProtos.ChannelSettings? = null
|
||||
var settings: MeshProtos.ChannelSettings? = MeshProtos.ChannelSettings.getDefaultInstance()
|
||||
) {
|
||||
companion object {
|
||||
// Placeholder when emulating
|
||||
val emulated = Channel("Default", ModemConfig.Bw125Cr45Sf128)
|
||||
val emulated = Channel(
|
||||
MeshProtos.ChannelSettings.newBuilder().setName("Default")
|
||||
.setModemConfig(ModemConfig.Bw125Cr45Sf128).build()
|
||||
)
|
||||
|
||||
const val prefix = "https://www.meshtastic.org/c/"
|
||||
|
||||
@@ -53,20 +56,20 @@ data class Channel(
|
||||
var editable = false
|
||||
|
||||
/// Return an URL that represents the current channel values
|
||||
fun getChannelUrl(): String {
|
||||
fun getChannelUrl(): Uri {
|
||||
// If we have a valid radio config use it, othterwise use whatever we have saved in the prefs
|
||||
|
||||
val channelBytes = settings?.toByteArray() ?: ByteArray(0) // if unset just use empty
|
||||
val enc = Base64.encodeToString(channelBytes, base64Flags)
|
||||
|
||||
return "$prefix$enc"
|
||||
return Uri.parse("$prefix$enc")
|
||||
}
|
||||
|
||||
fun getChannelQR(): Bitmap {
|
||||
val multiFormatWriter = MultiFormatWriter()
|
||||
|
||||
val bitMatrix =
|
||||
multiFormatWriter.encode(getChannelUrl(), BarcodeFormat.QR_CODE, 192, 192);
|
||||
multiFormatWriter.encode(getChannelUrl().toString(), BarcodeFormat.QR_CODE, 192, 192);
|
||||
val barcodeEncoder = BarcodeEncoder()
|
||||
return barcodeEncoder.createBitmap(bitMatrix)
|
||||
}
|
||||
@@ -128,7 +131,7 @@ object UIState : Logging {
|
||||
radioConfig.value = c
|
||||
|
||||
getPreferences(context).edit(commit = true) {
|
||||
this.putString("channel-url", getChannel()!!.getChannelUrl())
|
||||
this.putString("channel-url", getChannel()!!.getChannelUrl().toString())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,14 +0,0 @@
|
||||
package com.geeksville.mesh.model
|
||||
|
||||
import org.junit.Test
|
||||
|
||||
class ChannelTest {
|
||||
@Test
|
||||
fun channelUrlGood() {
|
||||
val ch = Channel.emulated
|
||||
|
||||
// FIXME, currently not allowed because it is a Compose model
|
||||
// Assert.assertTrue(ch.getChannelUrl().startsWith(Channel.prefix))
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user