Throw exception on System.loadLibrary fail (#3916)

This commit is contained in:
Adrian Cojocaru
2025-10-31 15:53:24 +02:00
committed by GitHub
parent 73595014b1
commit 76da093e5e
49 changed files with 119 additions and 48 deletions

View File

@@ -20,6 +20,7 @@ public abstract class LibraryLoader {
private static volatile LibraryLoader loader = DEFAULT;
private static boolean loaded;
private static boolean handleLoadError = false;
/**
* Set the library loader that loads the shared library.
@@ -30,10 +31,17 @@ public abstract class LibraryLoader {
loader = libraryLoader;
}
/**
* Catch UnsatisfiedLinkErrors on load
*/
public static void enableErrorHandling(boolean value) {
handleLoadError = value;
}
/**
* Loads "libmaplibre.so" native shared library.
* <p>
* Catches UnsatisfiedLinkErrors and prints a warning to logcat.
* Catches UnsatisfiedLinkErrors (if enabled) and prints a warning to logcat.
* </p>
*/
public static synchronized void load() {
@@ -47,6 +55,10 @@ public abstract class LibraryLoader {
String message = "Failed to load native shared library.";
Logger.e(TAG, message, error);
MapStrictMode.strictModeViolation(message, error);
if (!handleLoadError) {
throw error;
}
}
}

View File

@@ -0,0 +1,13 @@
package org.maplibre.android
import org.junit.BeforeClass
open class BaseTest {
companion object {
@JvmStatic
@BeforeClass
fun setup() {
LibraryLoader.enableErrorHandling(true)
}
}
}

View File

@@ -20,7 +20,7 @@ import org.mockito.ArgumentMatchers
import org.mockito.Mockito
import java.io.File
class MapLibreTest {
class MapLibreTest : BaseTest() {
private var context: Context? = null
private var appContext: Context? = null

View File

@@ -4,10 +4,11 @@ import org.maplibre.android.maps.MapLibreMap
import org.junit.Assert
import org.junit.Before
import org.junit.Test
import org.maplibre.android.BaseTest
import org.mockito.InjectMocks
import org.mockito.Mockito
class AnnotationTest {
class AnnotationTest : BaseTest() {
@InjectMocks
private val maplibreMap = Mockito.mock(MapLibreMap::class.java)
private var annotation: Annotation? = null

View File

@@ -4,11 +4,12 @@ import android.graphics.Bitmap
import org.junit.Assert
import org.junit.Before
import org.junit.Test
import org.maplibre.android.BaseTest
import org.mockito.Mock
import org.mockito.Mockito
import org.mockito.MockitoAnnotations
class IconTest {
class IconTest : BaseTest() {
@Mock
var bitmap: Bitmap? = null

View File

@@ -7,10 +7,11 @@ import org.maplibre.android.maps.MapLibreMap
import org.maplibre.android.maps.Projection
import org.junit.Assert
import org.junit.Test
import org.maplibre.android.BaseTest
import org.mockito.InjectMocks
import org.mockito.Mockito
class InfoWindowTest {
class InfoWindowTest : BaseTest() {
@InjectMocks
var mMapView = Mockito.mock(MapView::class.java)

View File

@@ -6,9 +6,10 @@ import org.maplibre.android.geometry.LatLng
import org.maplibre.android.utils.MockParcel
import org.junit.Assert
import org.junit.Test
import org.maplibre.android.BaseTest
import org.mockito.Mockito
class MarkerTest {
class MarkerTest : BaseTest() {
@Test
fun testSanity() {
val markerOptions = MarkerOptions()

View File

@@ -3,8 +3,9 @@ package org.maplibre.android.annotations
import org.maplibre.android.geometry.LatLng
import org.junit.Assert
import org.junit.Test
import org.maplibre.android.BaseTest
class PolygonTest {
class PolygonTest : BaseTest() {
@Test
fun testSanity() {
val polygonOptions = PolygonOptions()

View File

@@ -3,8 +3,9 @@ package org.maplibre.android.annotations
import org.maplibre.android.geometry.LatLng
import org.junit.Assert
import org.junit.Test
import org.maplibre.android.BaseTest
class PolylineTest {
class PolylineTest : BaseTest() {
@Test
fun testSanity() {
val polylineOptions = PolylineOptions()

View File

@@ -3,11 +3,12 @@ package org.maplibre.android.attribution
import org.junit.Assert
import org.junit.Test
import org.junit.runner.RunWith
import org.maplibre.android.BaseTest
import org.robolectric.RobolectricTestRunner
import org.robolectric.RuntimeEnvironment
@RunWith(RobolectricTestRunner::class)
class AttributionParseTest {
class AttributionParseTest : BaseTest() {
@Test
@Throws(Exception::class)
fun testParseAttributionStringSatellite() {

View File

@@ -9,11 +9,12 @@ import org.maplibre.android.geometry.LatLng
import org.junit.Assert
import org.junit.Test
import org.junit.runner.RunWith
import org.maplibre.android.BaseTest
import org.mockito.Mockito
import org.robolectric.RobolectricTestRunner
@RunWith(RobolectricTestRunner::class)
class CameraPositionTest {
class CameraPositionTest : BaseTest() {
@Test
fun testSanity() {
val latLng = LatLng(1.0, 2.0)

View File

@@ -10,8 +10,9 @@ import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.junit.rules.ExpectedException
import org.maplibre.android.BaseTest
class LatLngBoundsTest {
class LatLngBoundsTest : BaseTest() {
private var latLngBounds: LatLngBounds? = null
@Before

View File

@@ -3,8 +3,9 @@ package org.maplibre.android.geometry
import org.maplibre.android.utils.MockParcel
import org.junit.Assert
import org.junit.Test
import org.maplibre.android.BaseTest
class LatLngSpanTest {
class LatLngSpanTest : BaseTest() {
@Test
fun testSanity() {
val latLngSpan = LatLngSpan(0.0, 0.0)

View File

@@ -6,9 +6,10 @@ import org.junit.Assert
import org.junit.Rule
import org.junit.Test
import org.junit.rules.ExpectedException
import org.maplibre.android.BaseTest
import org.mockito.Mockito
class LatLngTest {
class LatLngTest : BaseTest() {
@Test
fun testSanity() {
val latLng = LatLng(0.0, 0.0)

View File

@@ -3,8 +3,9 @@ package org.maplibre.android.geometry
import org.maplibre.android.utils.MockParcel
import org.junit.Assert
import org.junit.Test
import org.maplibre.android.BaseTest
class ProjectedMetersTest {
class ProjectedMetersTest : BaseTest() {
@Test
fun testSanity() {
val projectedMeters = ProjectedMeters(0.0, 0.0)

View File

@@ -3,8 +3,9 @@ package org.maplibre.android.geometry
import org.maplibre.android.utils.MockParcel
import org.junit.Assert
import org.junit.Test
import org.maplibre.android.BaseTest
class VisibleRegionTest {
class VisibleRegionTest : BaseTest() {
@Test
fun testSanity() {
val region = VisibleRegion(FAR_LEFT, FAR_RIGHT, NEAR_LEFT, NEAR_RIGHT, BOUNDS)

View File

@@ -8,13 +8,14 @@ import org.junit.Assert
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import org.maplibre.android.BaseTest
import org.mockito.ArgumentMatchers
import org.mockito.Mock
import org.mockito.Mockito
import org.mockito.junit.MockitoJUnitRunner
@RunWith(MockitoJUnitRunner::class)
class CompassEngineTest {
class CompassEngineTest : BaseTest() {
private var compassEngine: LocationComponentCompassEngine? = null
@Mock

View File

@@ -15,8 +15,9 @@ import io.mockk.*
import org.junit.Assert
import org.junit.Before
import org.junit.Test
import org.maplibre.android.BaseTest
class IndicatorLocationLayerRendererTest {
class IndicatorLocationLayerRendererTest : BaseTest() {
private val style: Style = mockk(relaxUnitFun = true)
private val layerSourceProvider: LayerSourceProvider = mockk(relaxUnitFun = true)

View File

@@ -18,13 +18,14 @@ import org.junit.Assert.*
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import org.maplibre.android.BaseTest
import org.maplibre.android.location.LocationComponentConstants.DEFAULT_TRACKING_PADDING_ANIM_DURATION
import org.mockito.Mockito
import org.robolectric.RobolectricTestRunner
import org.maplibre.testUtils.Assert as MapLibreAssert
@RunWith(RobolectricTestRunner::class)
class LocationAnimatorCoordinatorTest {
class LocationAnimatorCoordinatorTest : BaseTest() {
private lateinit var locationAnimatorCoordinator: LocationAnimatorCoordinator
private val cameraPosition: CameraPosition = CameraPosition.DEFAULT

View File

@@ -19,11 +19,12 @@ import org.maplibre.android.maps.Transform
import org.maplibre.android.maps.UiSettings
import org.junit.Assert
import org.junit.Test
import org.maplibre.android.BaseTest
import org.mockito.ArgumentCaptor
import org.mockito.ArgumentMatchers
import org.mockito.Mockito
class LocationCameraControllerTest {
class LocationCameraControllerTest : BaseTest() {
@Test
fun setCameraMode_mapTransitionsAreCancelled() {
val maplibreMap = Mockito.mock(MapLibreMap::class.java)

View File

@@ -13,13 +13,14 @@ import org.junit.Rule
import org.junit.Test
import org.junit.rules.ExpectedException
import org.junit.runner.RunWith
import org.maplibre.android.BaseTest
import org.mockito.Mock
import org.mockito.Mockito
import org.mockito.junit.MockitoJUnit
import org.mockito.junit.MockitoJUnitRunner
@RunWith(MockitoJUnitRunner::class)
class LocationComponentActivationOptionsTest {
class LocationComponentActivationOptionsTest : BaseTest() {
@Mock
private val context: Context? = null

View File

@@ -10,12 +10,13 @@ import org.junit.Rule
import org.junit.Test
import org.junit.rules.ExpectedException
import org.junit.runner.RunWith
import org.maplibre.android.BaseTest
import org.mockito.Mock
import org.mockito.Mockito
import org.mockito.junit.MockitoJUnitRunner
@RunWith(MockitoJUnitRunner::class)
class LocationComponentOptionsTest {
class LocationComponentOptionsTest : BaseTest() {
@Mock
private val context: Context? = null

View File

@@ -9,10 +9,11 @@ import org.junit.Assert.assertTrue
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import org.maplibre.android.BaseTest
import org.mockito.junit.MockitoJUnitRunner
@RunWith(MockitoJUnitRunner::class)
class LocationComponentPositionManagerTest {
class LocationComponentPositionManagerTest : BaseTest() {
private lateinit var style: Style
private lateinit var layer: Layer

View File

@@ -17,6 +17,7 @@ import org.junit.Assert
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import org.maplibre.android.BaseTest
import org.mockito.ArgumentCaptor
import org.mockito.Mock
import org.mockito.Mockito.*
@@ -24,7 +25,7 @@ import org.mockito.MockitoAnnotations
import org.robolectric.RobolectricTestRunner
@RunWith(RobolectricTestRunner::class)
class LocationComponentTest {
class LocationComponentTest : BaseTest() {
private lateinit var locationComponent: LocationComponent
@Mock

View File

@@ -13,10 +13,11 @@ import org.maplibre.android.style.sources.GeoJsonSource
import org.junit.Assert
import org.junit.Before
import org.junit.Test
import org.maplibre.android.BaseTest
import org.mockito.ArgumentMatchers
import org.mockito.Mockito
class LocationLayerControllerTest {
class LocationLayerControllerTest : BaseTest() {
private val maplibreMap = Mockito.mock(MapLibreMap::class.java)
private val style = Mockito.mock(
Style::class.java

View File

@@ -6,10 +6,11 @@ import io.mockk.mockk
import io.mockk.verify
import org.junit.Test
import org.junit.runner.RunWith
import org.maplibre.android.BaseTest
import org.robolectric.RobolectricTestRunner
@RunWith(RobolectricTestRunner::class)
class MapLibreAnimatorTest {
class MapLibreAnimatorTest : BaseTest() {
@Test
fun fps_unlimited() {

View File

@@ -13,6 +13,7 @@ import org.junit.After
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import org.maplibre.android.BaseTest
import org.mockito.ArgumentCaptor
import org.mockito.ArgumentMatchers
import org.mockito.Mock
@@ -23,7 +24,7 @@ import java.util.concurrent.TimeUnit
import java.util.concurrent.atomic.AtomicReference
@RunWith(MockitoJUnitRunner::class)
class AndroidLocationEngineImplTest {
class AndroidLocationEngineImplTest : BaseTest() {
@Mock
private val locationManagerMock: LocationManager? = null
private var engine: LocationEngine? = null

View File

@@ -5,13 +5,14 @@ import org.assertj.core.api.Assertions.*
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import org.maplibre.android.BaseTest
import org.maplibre.android.location.engine.AndroidLocationEngineImpl.AndroidLocationEngineCallbackTransport
import org.mockito.Mock
import org.mockito.Mockito.*
import org.mockito.junit.MockitoJUnitRunner
@RunWith(MockitoJUnitRunner::class)
class LocationEngineProxyTest {
class LocationEngineProxyTest : BaseTest() {
@Mock
private val callback: LocationEngineCallback<LocationEngineResult>? = null

View File

@@ -3,10 +3,11 @@ package org.maplibre.android.location.engine
import org.assertj.core.api.Assertions.*
import org.junit.Test
import org.junit.runner.RunWith
import org.maplibre.android.BaseTest
import org.mockito.junit.MockitoJUnitRunner
@RunWith(MockitoJUnitRunner::class)
class LocationEngineRequestTest {
class LocationEngineRequestTest : BaseTest() {
@Test
fun checkDefaultValues() {
val request = LocationEngineRequest.Builder(1000L).build()

View File

@@ -7,12 +7,13 @@ import android.os.Bundle
import org.assertj.core.api.Assertions.*
import org.junit.Test
import org.junit.runner.RunWith
import org.maplibre.android.BaseTest
import org.mockito.Mockito.*
import org.mockito.junit.MockitoJUnitRunner
import java.util.Collections
@RunWith(MockitoJUnitRunner::class)
class LocationEngineResultTest {
class LocationEngineResultTest : BaseTest(){
@Test
fun checkNullIntent() {
val result = LocationEngineResult.extractResult(null)

View File

@@ -9,6 +9,7 @@ import org.junit.Assert.*
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import org.maplibre.android.BaseTest
import org.maplibre.android.location.engine.AndroidLocationEngineImpl.AndroidLocationEngineCallbackTransport
import org.mockito.Mock
import org.mockito.Mockito.*
@@ -19,7 +20,7 @@ import java.util.concurrent.TimeUnit
import java.util.concurrent.atomic.AtomicReference
@RunWith(MockitoJUnitRunner::class)
class LocationEngineTest {
class LocationEngineTest : BaseTest() {
@Mock
private val locationEngineImpl: LocationEngineImpl<LocationListener>? = null
private var engine: LocationEngine? = null

View File

@@ -11,6 +11,7 @@ import org.junit.Assert.*
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import org.maplibre.android.BaseTest
import org.mockito.ArgumentMatchers
import org.mockito.Mockito.*
import org.mockito.junit.MockitoJUnitRunner
@@ -18,7 +19,7 @@ import java.util.concurrent.CountDownLatch
import java.util.concurrent.TimeUnit
@RunWith(MockitoJUnitRunner::class)
class MapLibreFusedLocationEngineImplAdditionalTest2 {
class MapLibreFusedLocationEngineImplAdditionalTest2 : BaseTest() {
private val engines = ArrayList<LocationEngineProxy<*>>()
private var mockLocationManager: LocationManager? = null
private var location = Location(PROVIDER)

View File

@@ -13,6 +13,7 @@ import org.junit.After
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import org.maplibre.android.BaseTest
import org.mockito.ArgumentCaptor
import org.mockito.ArgumentMatchers.*
import org.mockito.Mock
@@ -23,7 +24,7 @@ import java.util.concurrent.TimeUnit
import java.util.concurrent.atomic.AtomicReference
@RunWith(MockitoJUnitRunner::class)
class MapLibreFusedLocationEngineImplTest {
class MapLibreFusedLocationEngineImplTest : BaseTest() {
@Mock
private val locationManagerMock: LocationManager? = null
private var engine: LocationEngine? = null

View File

@@ -5,10 +5,11 @@ import io.mockk.verify
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import org.maplibre.android.BaseTest
import org.robolectric.RobolectricTestRunner
@RunWith(RobolectricTestRunner::class)
class LoggerTest {
class LoggerTest : BaseTest() {
private val logger: LoggerDefinition = mockk(relaxed = true)

View File

@@ -8,12 +8,13 @@ import org.maplibre.android.annotations.MarkerOptions
import org.maplibre.android.geometry.LatLng
import org.junit.Assert
import org.junit.Test
import org.maplibre.android.BaseTest
import org.maplibre.android.annotations.PolygonOptions
import org.maplibre.android.annotations.PolylineOptions
import org.mockito.ArgumentMatchers
import org.mockito.Mockito
class AnnotationManagerTest {
class AnnotationManagerTest : BaseTest() {
private val aNativeMapView: NativeMap = Mockito.mock(NativeMapView::class.java)
private val aMapView = Mockito.mock(MapView::class.java)

View File

@@ -5,12 +5,13 @@ import org.junit.Assert
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import org.maplibre.android.BaseTest
import org.mockito.InjectMocks
import org.mockito.Mockito
import org.robolectric.RobolectricTestRunner
@RunWith(RobolectricTestRunner::class)
class AttributionDialogManagerTest {
class AttributionDialogManagerTest : BaseTest() {
@InjectMocks
var context = Mockito.mock(
Context::class.java

View File

@@ -7,6 +7,7 @@ import org.maplibre.android.maps.MapView.*
import org.junit.Assert
import org.junit.Before
import org.junit.Test
import org.maplibre.android.BaseTest
import org.mockito.ArgumentMatchers
import org.mockito.Mock
import org.mockito.Mockito
@@ -15,7 +16,7 @@ import org.mockito.MockitoAnnotations
/**
* Tests integration of MapChangeDispatcher and see if events are correctly forwarded.
*/
class MapChangeReceiverTest {
class MapChangeReceiverTest : BaseTest() {
private var mapChangeEventManager: MapChangeReceiver? = null
@Mock

View File

@@ -11,10 +11,11 @@ import io.mockk.verify
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import org.maplibre.android.BaseTest
import org.robolectric.RobolectricTestRunner
@RunWith(RobolectricTestRunner::class)
class MapLibreMapOptionsAttrsTest {
class MapLibreMapOptionsAttrsTest : BaseTest() {
@RelaxedMockK
private lateinit var options: MapLibreMapOptions

View File

@@ -8,12 +8,13 @@ import org.maplibre.android.geometry.LatLng
import org.junit.Assert
import org.junit.Test
import org.junit.runner.RunWith
import org.maplibre.android.BaseTest
import org.robolectric.RobolectricTestRunner
import org.robolectric.RuntimeEnvironment
import java.util.*
@RunWith(RobolectricTestRunner::class)
class MapLibreMapOptionsTest {
class MapLibreMapOptionsTest : BaseTest() {
@Test
fun testSanity() {
Assert.assertNotNull("should not be null",

View File

@@ -15,12 +15,13 @@ import org.junit.Assert.assertEquals
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import org.maplibre.android.BaseTest
import org.mockito.Mock
import org.mockito.MockitoAnnotations
import org.robolectric.RobolectricTestRunner
@RunWith(RobolectricTestRunner::class)
class MapLibreMapTest {
class MapLibreMapTest : BaseTest() {
private lateinit var maplibreMap: MapLibreMap

View File

@@ -9,9 +9,10 @@ import org.maplibre.android.geometry.LatLng
import org.maplibre.android.maps.MapLibreMap.*
import org.junit.Before
import org.junit.Test
import org.maplibre.android.BaseTest
import org.mockito.Mockito
class MapTouchListenersTest {
class MapTouchListenersTest : BaseTest() {
private var mapGestureDetector: MapGestureDetector? = null
private var latLng: LatLng? = null
private var pointF: PointF? = null

View File

@@ -13,10 +13,11 @@ import org.junit.Assert.assertEquals
import org.junit.Assert.assertTrue
import org.junit.Test
import org.junit.runner.RunWith
import org.maplibre.android.BaseTest
import org.robolectric.RobolectricTestRunner
@RunWith(RobolectricTestRunner::class)
class StyleBuilderTest {
class StyleBuilderTest : BaseTest() {
@Test
fun testFromUrl() {

View File

@@ -19,12 +19,13 @@ import org.junit.Assert
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import org.maplibre.android.BaseTest
import org.mockito.Mock
import org.mockito.MockitoAnnotations
import org.robolectric.RobolectricTestRunner
@RunWith(RobolectricTestRunner::class)
class StyleTest {
class StyleTest : BaseTest() {
private lateinit var maplibreMap: MapLibreMap

View File

@@ -8,12 +8,13 @@ import io.mockk.*
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import org.maplibre.android.BaseTest
import org.robolectric.RobolectricTestRunner
import org.robolectric.Shadows.shadowOf
import org.robolectric.shadows.ShadowLooper
@RunWith(RobolectricTestRunner::class)
class TransformTest {
class TransformTest : BaseTest() {
private lateinit var mapView: MapView
private lateinit var nativeMapView: NativeMap

View File

@@ -11,10 +11,11 @@ import org.maplibre.android.maps.widgets.CompassView
import org.junit.Assert
import org.junit.Before
import org.junit.Test
import org.maplibre.android.BaseTest
import org.mockito.InjectMocks
import org.mockito.Mockito
class UiSettingsTest {
class UiSettingsTest : BaseTest() {
@InjectMocks
var mapview = Mockito.mock(MapView::class.java)

View File

@@ -9,10 +9,11 @@ import org.junit.Assert.assertEquals
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import org.maplibre.android.BaseTest
import org.robolectric.RobolectricTestRunner
@RunWith(RobolectricTestRunner::class)
class HttpRequestUrlTest {
class HttpRequestUrlTest : BaseTest() {
@Before
fun setUp() {

View File

@@ -7,10 +7,11 @@ import okhttp3.Call
import org.junit.Assert.assertEquals
import org.junit.Test
import org.junit.runner.RunWith
import org.maplibre.android.BaseTest
import org.robolectric.RobolectricTestRunner
@RunWith(RobolectricTestRunner::class)
class HttpRequestUtilTest {
class HttpRequestUtilTest : BaseTest() {
@Test
fun replaceHttpClient() {

View File

@@ -10,6 +10,7 @@ import org.maplibre.android.utils.ColorUtils
import org.junit.Assert
import org.junit.Test
import org.junit.runner.RunWith
import org.maplibre.android.BaseTest
import org.robolectric.RobolectricTestRunner
import java.util.*
@@ -17,7 +18,7 @@ import java.util.*
* Expression unit tests that validate the expression output with the expected Object[]array representation.
*/
@RunWith(RobolectricTestRunner::class)
class ExpressionTest {
class ExpressionTest : BaseTest() {
@Test
fun testPropertyValueIsExpression() {
val property: PropertyValue<*> = PropertyFactory.lineWidth(Expression.get("width"))

View File

@@ -3,8 +3,9 @@ package org.maplibre.android.utils
import android.graphics.Color
import org.junit.Assert
import org.junit.Test
import org.maplibre.android.BaseTest
class ColorUtilsTest {
class ColorUtilsTest : BaseTest() {
@Test
fun rgbaToColor_decimalComponent() {