kopia lustrzana https://github.com/meshtastic/Meshtastic-Android
use unmock to test and fix the channel suffix generation to match device
rodzic
c405cdc200
commit
699d5076b5
|
@ -4,6 +4,7 @@ apply plugin: 'kotlin-parcelize'
|
|||
apply plugin: 'kotlinx-serialization'
|
||||
apply plugin: 'com.google.gms.google-services'
|
||||
apply plugin: 'com.github.triplet.play'
|
||||
apply plugin: 'de.mobilej.unmock'
|
||||
// apply plugin: "app.brant.amazonappstorepublisher"
|
||||
|
||||
// Apply the Crashlytics Gradle plugin
|
||||
|
@ -14,6 +15,11 @@ apply plugin: 'com.google.protobuf'
|
|||
|
||||
apply plugin: 'kotlin-kapt'
|
||||
|
||||
unMock {
|
||||
keep "android.net.Uri"
|
||||
keep "android.util.Base64"
|
||||
}
|
||||
|
||||
android {
|
||||
/*
|
||||
signingConfigs {
|
||||
|
|
|
@ -1,15 +1,7 @@
|
|||
package com.geeksville.mesh.model
|
||||
|
||||
import android.graphics.Bitmap
|
||||
import android.net.Uri
|
||||
import android.util.Base64
|
||||
import com.geeksville.mesh.ChannelProtos
|
||||
import com.geeksville.mesh.MeshProtos
|
||||
import com.google.protobuf.ByteString
|
||||
import com.google.zxing.BarcodeFormat
|
||||
import com.google.zxing.MultiFormatWriter
|
||||
import com.journeyapps.barcodescanner.BarcodeEncoder
|
||||
import java.net.MalformedURLException
|
||||
|
||||
/** Utility function to make it easy to declare byte arrays - FIXME move someplace better */
|
||||
fun byteArrayOfInts(vararg ints: Int) = ByteArray(ints.size) { pos -> ints[pos].toByte() }
|
||||
|
@ -74,14 +66,13 @@ data class Channel(
|
|||
*/
|
||||
val humanName: String
|
||||
get() {
|
||||
val suffix: Char = if (settings.psk.size() != 1) {
|
||||
// we have a full PSK, so hash it to generate the suffix
|
||||
val code = settings.psk.fold(0, { acc, x -> acc xor (x.toInt() and 0xff) })
|
||||
|
||||
'A' + (code % 26)
|
||||
} else
|
||||
'0' + settings.psk.byteAt(0).toInt()
|
||||
// start with the PSK then xor in the name
|
||||
val pskCode = xorHash(psk.toByteArray())
|
||||
val nameCode = xorHash(name.toByteArray())
|
||||
val suffix = 'A' + ((pskCode xor nameCode) % 26)
|
||||
|
||||
return "#${name}-${suffix}"
|
||||
}
|
||||
}
|
||||
|
||||
fun xorHash(b: ByteArray) = b.fold(0, { acc, x -> acc xor (x.toInt() and 0xff) })
|
|
@ -8,9 +8,10 @@ import org.junit.Test
|
|||
import java.util.*
|
||||
|
||||
class NodeInfoTest {
|
||||
val ni1 = NodeInfo(4, MeshUser("+one", "User One", "U1"), Position(37.1, 121.1, 35))
|
||||
val ni2 = NodeInfo(5, MeshUser("+two", "User Two", "U2"), Position(37.11, 121.1, 40))
|
||||
val ni3 = NodeInfo(6, MeshUser("+three", "User Three", "U3"), Position(37.101, 121.1, 40))
|
||||
val model = MeshProtos.HardwareModel.ANDROID_SIM
|
||||
val ni1 = NodeInfo(4, MeshUser("+one", "User One", "U1", model), Position(37.1, 121.1, 35))
|
||||
val ni2 = NodeInfo(5, MeshUser("+two", "User Two", "U2", model), Position(37.11, 121.1, 40))
|
||||
val ni3 = NodeInfo(6, MeshUser("+three", "User Three", "U3", model), Position(37.101, 121.1, 40))
|
||||
|
||||
private val currentDefaultLocale = LocaleListCompat.getDefault().get(0)
|
||||
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
package com.geeksville.mesh.model
|
||||
|
||||
import android.net.Uri
|
||||
import org.junit.Assert
|
||||
import org.junit.Test
|
||||
|
||||
class ChannelSetTest {
|
||||
/** make sure we match the python and device code behavior */
|
||||
@Test
|
||||
fun matchPython() {
|
||||
val url = Uri.parse("https://www.meshtastic.org/d/#CgUYAyIBAQ")
|
||||
val cs = ChannelSet(url)
|
||||
Assert.assertEquals("LongSlow", cs.primaryChannel!!.name, )
|
||||
Assert.assertEquals("#LongSlow-V", cs.primaryChannel!!.humanName, )
|
||||
}
|
||||
}
|
|
@ -1,5 +1,6 @@
|
|||
package com.geeksville.mesh.service
|
||||
|
||||
import com.geeksville.mesh.MeshProtos
|
||||
import com.geeksville.mesh.MeshUser
|
||||
import com.geeksville.mesh.NodeInfo
|
||||
import com.geeksville.mesh.Position
|
||||
|
@ -8,8 +9,8 @@ import org.junit.Test
|
|||
|
||||
|
||||
class MeshServiceTest {
|
||||
|
||||
val nodeInfo = NodeInfo(4, MeshUser("+one", "User One", "U1"), Position(37.1, 121.1, 35, 10))
|
||||
val model = MeshProtos.HardwareModel.ANDROID_SIM
|
||||
val nodeInfo = NodeInfo(4, MeshUser("+one", "User One", "U1", model), Position(37.1, 121.1, 35, 10))
|
||||
|
||||
@Test
|
||||
fun givenNodeInfo_whenUpdatingWithNewTime_thenPositionTimeIsUpdated() {
|
||||
|
|
|
@ -10,7 +10,7 @@ buildscript {
|
|||
mavenCentral()
|
||||
}
|
||||
dependencies {
|
||||
classpath 'com.android.tools.build:gradle:4.1.2'
|
||||
classpath 'com.android.tools.build:gradle:4.1.3'
|
||||
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
|
||||
classpath "org.jetbrains.kotlin:kotlin-serialization:$kotlin_version"
|
||||
|
||||
|
@ -28,6 +28,9 @@ buildscript {
|
|||
|
||||
//classpath "app.brant:amazonappstorepublisher:0.1.0"
|
||||
classpath 'com.github.triplet.gradle:play-publisher:2.8.0'
|
||||
|
||||
// for unit testing https://github.com/bjoernQ/unmock-plugin
|
||||
classpath 'com.github.bjoernq:unmockplugin:0.7.6'
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Ładowanie…
Reference in New Issue