mirror of
https://github.com/meshtastic/Meshtastic-Android.git
synced 2026-04-20 22:23:37 +00:00
Refactor map layer management and navigation infrastructure (#4921)
Signed-off-by: James Rich <2199651+jamesarich@users.noreply.github.com>
This commit is contained in:
parent
b608a04ca4
commit
a005231d94
142 changed files with 5408 additions and 3090 deletions
|
|
@ -0,0 +1,49 @@
|
|||
/*
|
||||
* Copyright (c) 2026 Meshtastic LLC
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.meshtastic.core.common.util
|
||||
|
||||
import org.junit.runner.RunWith
|
||||
import org.robolectric.RobolectricTestRunner
|
||||
import org.robolectric.annotation.Config
|
||||
import kotlin.test.Test
|
||||
import kotlin.test.assertEquals
|
||||
import kotlin.test.assertTrue
|
||||
|
||||
@RunWith(RobolectricTestRunner::class)
|
||||
@Config(sdk = [34])
|
||||
class CommonUriTest {
|
||||
|
||||
@Test
|
||||
fun testParse() {
|
||||
val uri = CommonUri.parse("https://meshtastic.org/path/to/page?param1=value1¶m2=true#fragment")
|
||||
assertEquals("meshtastic.org", uri.host)
|
||||
assertEquals("fragment", uri.fragment)
|
||||
assertEquals(listOf("path", "to", "page"), uri.pathSegments)
|
||||
assertEquals("value1", uri.getQueryParameter("param1"))
|
||||
assertTrue(uri.getBooleanQueryParameter("param2", false))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testBooleanParameters() {
|
||||
val uri = CommonUri.parse("meshtastic://test?t1=true&t2=1&t3=yes&f1=false&f2=0")
|
||||
assertTrue(uri.getBooleanQueryParameter("t1", false))
|
||||
assertTrue(uri.getBooleanQueryParameter("t2", false))
|
||||
assertTrue(uri.getBooleanQueryParameter("t3", false))
|
||||
assertTrue(!uri.getBooleanQueryParameter("f1", true))
|
||||
assertTrue(!uri.getBooleanQueryParameter("f2", true))
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,42 @@
|
|||
/*
|
||||
* Copyright (c) 2026 Meshtastic LLC
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.meshtastic.core.common
|
||||
|
||||
import kotlin.test.Test
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
class ByteUtilsTest {
|
||||
|
||||
@Test
|
||||
fun testByteArrayOfInts() {
|
||||
val bytes = byteArrayOfInts(0x01, 0xFF, 0x80)
|
||||
assertEquals(3, bytes.size)
|
||||
assertEquals(1, bytes[0])
|
||||
assertEquals(-1, bytes[1]) // 0xFF as signed byte
|
||||
assertEquals(-128, bytes[2].toInt()) // 0x80 as signed byte
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testXorHash() {
|
||||
val data = byteArrayOfInts(0x01, 0x02, 0x03)
|
||||
assertEquals(0 xor 1 xor 2 xor 3, xorHash(data))
|
||||
|
||||
val data2 = byteArrayOfInts(0xFF, 0xFF)
|
||||
assertEquals(0xFF xor 0xFF, xorHash(data2))
|
||||
assertEquals(0, xorHash(data2))
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,53 @@
|
|||
/*
|
||||
* Copyright (c) 2026 Meshtastic LLC
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.meshtastic.core.common.util
|
||||
|
||||
import kotlin.test.Test
|
||||
import kotlin.test.assertEquals
|
||||
import kotlin.test.assertTrue
|
||||
|
||||
class LocationUtilsTest {
|
||||
|
||||
@Test
|
||||
fun testGpsFormat() {
|
||||
val formatted = GPSFormat.toDec(45.123456, -93.654321)
|
||||
assertEquals("45.12345, -93.65432", formatted)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testLatLongToMeter() {
|
||||
// Distance from (0,0) to (0,1) at equator should be approx 111.3km
|
||||
val distance = latLongToMeter(0.0, 0.0, 0.0, 1.0)
|
||||
assertTrue(distance > 111000 && distance < 112000, "Distance was $distance")
|
||||
|
||||
// Distance from (45, -93) to (45, -92)
|
||||
val distance2 = latLongToMeter(45.0, -93.0, 45.0, -92.0)
|
||||
assertTrue(distance2 > 78000 && distance2 < 79000, "Distance was $distance2")
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testBearing() {
|
||||
// North
|
||||
assertEquals(0.0, bearing(0.0, 0.0, 1.0, 0.0), 0.1)
|
||||
// East
|
||||
assertEquals(90.0, bearing(0.0, 0.0, 0.0, 1.0), 0.1)
|
||||
// South
|
||||
assertEquals(180.0, bearing(0.0, 0.0, -1.0, 0.0), 0.1)
|
||||
// West
|
||||
assertEquals(270.0, bearing(0.0, 0.0, 0.0, -1.0), 0.1)
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,38 @@
|
|||
/*
|
||||
* Copyright (c) 2026 Meshtastic LLC
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.meshtastic.core.common.util
|
||||
|
||||
import kotlin.test.Test
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
class NumberFormatterTest {
|
||||
|
||||
@Test
|
||||
fun testFormat() {
|
||||
assertEquals("1.23", NumberFormatter.format(1.23456, 2))
|
||||
assertEquals("1.235", NumberFormatter.format(1.23456, 3))
|
||||
assertEquals("1.00", NumberFormatter.format(1.0, 2))
|
||||
assertEquals("0.00", NumberFormatter.format(0.0, 2))
|
||||
assertEquals("-1.23", NumberFormatter.format(-1.23456, 2))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testFormatZeroDecimalPlaces() {
|
||||
assertEquals("1", NumberFormatter.format(1.23, 0))
|
||||
assertEquals("-1", NumberFormatter.format(-1.23, 0))
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,31 @@
|
|||
/*
|
||||
* Copyright (c) 2026 Meshtastic LLC
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.meshtastic.core.common.util
|
||||
|
||||
import kotlin.test.Test
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
class UrlUtilsTest {
|
||||
|
||||
@Test
|
||||
fun testEncode() {
|
||||
assertEquals("Hello%20World", UrlUtils.encode("Hello World"))
|
||||
assertEquals("abc-123._~", UrlUtils.encode("abc-123._~"))
|
||||
assertEquals("%21%40%23%24%25", UrlUtils.encode("!@#$%"))
|
||||
assertEquals("%C3%A1%C3%A9%C3%AD", UrlUtils.encode("áéí"))
|
||||
}
|
||||
}
|
||||
|
|
@ -32,20 +32,10 @@ actual class CommonUri(private val uri: URI) {
|
|||
|
||||
actual fun getQueryParameter(key: String): String? = queryParameters[key]?.firstOrNull()
|
||||
|
||||
actual fun getBooleanQueryParameter(key: String, defaultValue: Boolean): Boolean =
|
||||
when (getQueryParameter(key)?.lowercase()) {
|
||||
"1",
|
||||
"true",
|
||||
"yes",
|
||||
"on",
|
||||
-> true
|
||||
"0",
|
||||
"false",
|
||||
"no",
|
||||
"off",
|
||||
-> false
|
||||
else -> defaultValue
|
||||
}
|
||||
actual fun getBooleanQueryParameter(key: String, defaultValue: Boolean): Boolean {
|
||||
val value = getQueryParameter(key) ?: return defaultValue
|
||||
return value != "false" && value != "0"
|
||||
}
|
||||
|
||||
actual override fun toString(): String = uri.toString()
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,44 @@
|
|||
/*
|
||||
* Copyright (c) 2026 Meshtastic LLC
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.meshtastic.core.common.util
|
||||
|
||||
import kotlin.test.Test
|
||||
import kotlin.test.assertEquals
|
||||
import kotlin.test.assertTrue
|
||||
|
||||
class CommonUriTest {
|
||||
|
||||
@Test
|
||||
fun testParse() {
|
||||
val uri = CommonUri.parse("https://meshtastic.org/path/to/page?param1=value1¶m2=true#fragment")
|
||||
assertEquals("meshtastic.org", uri.host)
|
||||
assertEquals("fragment", uri.fragment)
|
||||
assertEquals(listOf("path", "to", "page"), uri.pathSegments)
|
||||
assertEquals("value1", uri.getQueryParameter("param1"))
|
||||
assertTrue(uri.getBooleanQueryParameter("param2", false))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testBooleanParameters() {
|
||||
val uri = CommonUri.parse("meshtastic://test?t1=true&t2=1&t3=yes&f1=false&f2=0")
|
||||
assertTrue(uri.getBooleanQueryParameter("t1", false))
|
||||
assertTrue(uri.getBooleanQueryParameter("t2", false))
|
||||
assertTrue(uri.getBooleanQueryParameter("t3", false))
|
||||
assertTrue(!uri.getBooleanQueryParameter("f1", true))
|
||||
assertTrue(!uri.getBooleanQueryParameter("f2", true))
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue