Move tests to appropriate modules (#3377)

This commit is contained in:
Phil Oliver 2025-10-07 12:23:41 -04:00 committed by GitHub
parent e1da9fda01
commit 9a6c78fcd1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 12 additions and 66 deletions

View file

@ -1,77 +0,0 @@
/*
* Copyright (c) 2025 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 com.geeksville.mesh
import android.net.Uri
import dagger.hilt.android.testing.HiltAndroidRule
import dagger.hilt.android.testing.HiltAndroidTest
import org.junit.Assert
import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.meshtastic.core.model.util.getChannelUrl
import org.meshtastic.core.model.util.primaryChannel
import org.meshtastic.core.model.util.toChannelSet
@HiltAndroidTest
class ChannelSetTest {
@get:Rule var hiltRule = HiltAndroidRule(this)
@Before
fun init() {
hiltRule.inject()
}
/** make sure we match the python and device code behavior */
@Test
fun matchPython() {
val url = Uri.parse("https://meshtastic.org/e/#CgMSAQESBggBQANIAQ")
val cs = url.toChannelSet()
Assert.assertEquals("LongFast", cs.primaryChannel!!.name)
Assert.assertEquals(url, cs.getChannelUrl(false))
}
/** validate against the host or path in a case-insensitive way */
@Test
fun parseCaseInsensitive() {
var url = Uri.parse("HTTPS://MESHTASTIC.ORG/E/#CgMSAQESBggBQANIAQ")
Assert.assertEquals("LongFast", url.toChannelSet().primaryChannel!!.name)
url = Uri.parse("HTTPS://mEsHtAsTiC.OrG/e/#CgMSAQESBggBQANIAQ")
Assert.assertEquals("LongFast", url.toChannelSet().primaryChannel!!.name)
}
/** properly parse channel config when `?add=true` is in the fragment */
@Test
fun handleAddInFragment() {
val url = Uri.parse("https://meshtastic.org/e/#CgMSAQESBggBQANIAQ?add=true")
val cs = url.toChannelSet()
Assert.assertEquals("Custom", cs.primaryChannel!!.name)
Assert.assertFalse(cs.hasLoraConfig())
}
/** properly parse channel config when `?add=true` is in the query parameters */
@Test
fun handleAddInQueryParams() {
val url = Uri.parse("https://meshtastic.org/e/?add=true#CgMSAQESBggBQANIAQ")
val cs = url.toChannelSet()
Assert.assertEquals("Custom", cs.primaryChannel!!.name)
Assert.assertFalse(cs.hasLoraConfig())
}
}

View file

@ -1,71 +0,0 @@
/*
* Copyright (c) 2025 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 com.geeksville.mesh
import androidx.test.ext.junit.runners.AndroidJUnit4
import org.junit.Assert
import org.junit.Test
import org.junit.runner.RunWith
import org.meshtastic.core.model.Channel
import org.meshtastic.core.model.numChannels
import org.meshtastic.core.model.util.URL_PREFIX
import org.meshtastic.core.model.util.getChannelUrl
import org.meshtastic.core.model.util.toChannelSet
@RunWith(AndroidJUnit4::class)
class ChannelTest {
@Test
fun channelUrlGood() {
val ch = channelSet {
settings.add(Channel.default.settings)
loraConfig = Channel.default.loraConfig
}
val channelUrl = ch.getChannelUrl()
Assert.assertTrue(channelUrl.toString().startsWith(URL_PREFIX))
Assert.assertEquals(channelUrl.toChannelSet(), ch)
}
@Test
fun channelHashGood() {
val ch = Channel.default
Assert.assertEquals(8, ch.hash)
}
@Test
fun numChannelsGood() {
val ch = Channel.default
Assert.assertEquals(104, ch.loraConfig.numChannels)
}
@Test
fun channelNumGood() {
val ch = Channel.default
Assert.assertEquals(20, ch.channelNum)
}
@Test
fun radioFreqGood() {
val ch = Channel.default
Assert.assertEquals(906.875f, ch.radioFreq)
}
}

View file

@ -1,39 +0,0 @@
/*
* Copyright (c) 2025 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 com.geeksville.mesh
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
/**
* Instrumented test, which will execute on an Android device.
*
* See [testing documentation](http://d.android.com/tools/testing).
*/
@RunWith(AndroidJUnit4::class)
class ExampleInstrumentedTest {
@Test
fun useAppContext() {
// Context of the app under test.
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
assertEquals("com.geeksville.mesh", appContext.packageName)
}
}

View file

@ -1,68 +0,0 @@
/*
* Copyright (c) 2025 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 com.geeksville.mesh
import androidx.core.os.LocaleListCompat
import com.geeksville.mesh.ConfigProtos.Config.DisplayConfig.DisplayUnits
import org.junit.After
import org.junit.Assert
import org.junit.Before
import org.junit.Test
import org.meshtastic.core.model.MeshUser
import org.meshtastic.core.model.NodeInfo
import org.meshtastic.core.model.Position
import java.util.Locale
class NodeInfoTest {
private val model = MeshProtos.HardwareModel.ANDROID_SIM
private val node =
listOf(
NodeInfo(4, MeshUser("+zero", "User Zero", "U0", model)),
NodeInfo(5, MeshUser("+one", "User One", "U1", model), Position(37.1, 121.1, 35)),
NodeInfo(6, MeshUser("+two", "User Two", "U2", model), Position(37.11, 121.1, 40)),
NodeInfo(7, MeshUser("+three", "User Three", "U3", model), Position(37.101, 121.1, 40)),
NodeInfo(8, MeshUser("+four", "User Four", "U4", model), Position(37.116, 121.1, 40)),
)
private val currentDefaultLocale = LocaleListCompat.getDefault().get(0) ?: Locale.US
@Before
fun setup() {
Locale.setDefault(Locale.US)
}
@After
fun tearDown() {
Locale.setDefault(currentDefaultLocale)
}
@Test
fun distanceGood() {
Assert.assertEquals(node[1].distance(node[2]), 1111)
Assert.assertEquals(node[1].distance(node[3]), 111)
Assert.assertEquals(node[1].distance(node[4]), 1779)
}
@Test
fun distanceStrGood() {
Assert.assertEquals(node[1].distanceStr(node[2], DisplayUnits.METRIC_VALUE), "1.1 km")
Assert.assertEquals(node[1].distanceStr(node[3], DisplayUnits.METRIC_VALUE), "111 m")
Assert.assertEquals(node[1].distanceStr(node[4], DisplayUnits.IMPERIAL_VALUE), "1.1 mi")
Assert.assertEquals(node[1].distanceStr(node[3], DisplayUnits.IMPERIAL_VALUE), "364 ft")
}
}

View file

@ -1,39 +0,0 @@
/*
* Copyright (c) 2025 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 com.geeksville.mesh
import org.junit.Assert
import org.junit.Test
import org.meshtastic.core.model.Position
class PositionTest {
@Test
fun degGood() {
Assert.assertEquals(Position.degI(89.0), 890000000)
Assert.assertEquals(Position.degI(-89.0), -890000000)
Assert.assertEquals(Position.degD(Position.degI(89.0)), 89.0, 0.01)
Assert.assertEquals(Position.degD(Position.degI(-89.0)), -89.0, 0.01)
}
@Test
fun givenPositionCreatedWithoutTime_thenTimeIsSet() {
val position = Position(37.1, 121.1, 35)
Assert.assertTrue(position.time != 0)
}
}

View file

@ -1,33 +0,0 @@
/*
* Copyright (c) 2025 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 com.geeksville.mesh.model
import org.junit.Assert.assertEquals
import org.junit.Test
import org.meshtastic.core.model.DeviceVersion
class DeviceVersionTest {
/** make sure we match the python and device code behavior */
@Test
fun canParse() {
assertEquals(10000, DeviceVersion("1.0.0").asInt)
assertEquals(10101, DeviceVersion("1.1.1").asInt)
assertEquals(12357, DeviceVersion("1.23.57").asInt)
assertEquals(12357, DeviceVersion("1.23.57.abde123").asInt)
}
}