@@ -77,4 +77,42 @@ public void testAssignStyleMap() {
7777 assertNotNull (styleMap .get ("BlueKey" ));
7878 assertEquals (styles .get ("BlueKey" ), redStyle );
7979 }
80+
81+ @ Test
82+ public void testBitmapUrlSchemeValidation () throws Exception {
83+ KmlRenderer renderer = new KmlRenderer (null , null , null , null , null , null , null );
84+ java .lang .reflect .Method method = KmlRenderer .class .getDeclaredMethod ("getBitmapFromUrl" , String .class );
85+ method .setAccessible (true );
86+
87+ // Should throw MalformedURLException for file:// scheme
88+ try {
89+ method .invoke (renderer , "file:///android_asset/image.png" );
90+ org .junit .Assert .fail ("Should have thrown InvocationTargetException containing MalformedURLException" );
91+ } catch (java .lang .reflect .InvocationTargetException e ) {
92+ assertTrue (e .getCause () instanceof java .net .MalformedURLException );
93+ assertEquals ("Unsupported scheme: file" , e .getCause ().getMessage ());
94+ }
95+
96+ // Should throw MalformedURLException for ftp:// scheme
97+ try {
98+ method .invoke (renderer , "ftp://example.com/image.png" );
99+ org .junit .Assert .fail ("Should have thrown InvocationTargetException containing MalformedURLException" );
100+ } catch (java .lang .reflect .InvocationTargetException e ) {
101+ assertTrue (e .getCause () instanceof java .net .MalformedURLException );
102+ assertEquals ("Unsupported scheme: ftp" , e .getCause ().getMessage ());
103+ }
104+
105+ // For http/https, it should not throw MalformedURLException with "Unsupported scheme"
106+ try {
107+ method .invoke (renderer , "http://example.com/image.png" );
108+ } catch (java .lang .reflect .InvocationTargetException e ) {
109+ org .junit .Assert .assertFalse (e .getCause ().getMessage () != null && e .getCause ().getMessage ().startsWith ("Unsupported scheme" ));
110+ }
111+
112+ try {
113+ method .invoke (renderer , "https://example.com/image.png" );
114+ } catch (java .lang .reflect .InvocationTargetException e ) {
115+ org .junit .Assert .assertFalse (e .getCause ().getMessage () != null && e .getCause ().getMessage ().startsWith ("Unsupported scheme" ));
116+ }
117+ }
80118}
0 commit comments