1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.tools;
|
---|
3 |
|
---|
4 | import static org.junit.Assert.assertEquals;
|
---|
5 | import static org.junit.Assert.assertNotNull;
|
---|
6 |
|
---|
7 | import java.awt.Transparency;
|
---|
8 | import java.awt.image.BufferedImage;
|
---|
9 | import java.io.File;
|
---|
10 | import java.io.IOException;
|
---|
11 |
|
---|
12 | import org.junit.BeforeClass;
|
---|
13 | import org.junit.Test;
|
---|
14 | import org.openstreetmap.josm.JOSMFixture;
|
---|
15 | import org.openstreetmap.josm.TestUtils;
|
---|
16 |
|
---|
17 | /**
|
---|
18 | * Unit tests of {@link ImageProvider} class.
|
---|
19 | */
|
---|
20 | public class ImageProviderTest {
|
---|
21 |
|
---|
22 | /**
|
---|
23 | * Setup test.
|
---|
24 | */
|
---|
25 | @BeforeClass
|
---|
26 | public static void setUp() {
|
---|
27 | JOSMFixture.createUnitTestFixture().init();
|
---|
28 | }
|
---|
29 |
|
---|
30 | /**
|
---|
31 | * Non-regression test for ticket <a href="https://josm.openstreetmap.de/ticket/9984">#9984</a>
|
---|
32 | * @throws IOException if an error occurs during reading
|
---|
33 | */
|
---|
34 | @Test
|
---|
35 | public void testTicket9984() throws IOException {
|
---|
36 | File file = new File(TestUtils.getRegressionDataFile(9984, "tile.png"));
|
---|
37 | assertEquals(Transparency.TRANSLUCENT, ImageProvider.read(file, true, true).getTransparency());
|
---|
38 | assertEquals(Transparency.TRANSLUCENT, ImageProvider.read(file, false, true).getTransparency());
|
---|
39 | assertEquals(Transparency.OPAQUE, ImageProvider.read(file, false, false).getTransparency());
|
---|
40 | assertEquals(Transparency.OPAQUE, ImageProvider.read(file, true, false).getTransparency());
|
---|
41 | }
|
---|
42 |
|
---|
43 | /**
|
---|
44 | * Non-regression test for ticket <a href="https://josm.openstreetmap.de/ticket/10030">#10030</a>
|
---|
45 | * @throws IOException if an error occurs during reading
|
---|
46 | */
|
---|
47 | @Test
|
---|
48 | public void testTicket10030() throws IOException {
|
---|
49 | File file = new File(TestUtils.getRegressionDataFile(10030, "tile.jpg"));
|
---|
50 | BufferedImage img = ImageProvider.read(file, true, true);
|
---|
51 | assertNotNull(img);
|
---|
52 | }
|
---|
53 |
|
---|
54 | /**
|
---|
55 | * Test fetching an image using {@code wiki://} protocol.
|
---|
56 | */
|
---|
57 | @Test
|
---|
58 | public void testWikiProtocol() {
|
---|
59 | // https://commons.wikimedia.org/wiki/File:OpenJDK_logo.svg
|
---|
60 | assertNotNull(ImageProvider.get("wiki://OpenJDK_logo.svg"));
|
---|
61 | }
|
---|
62 |
|
---|
63 | /**
|
---|
64 | * Test fetching an image using {@code data:} URL.
|
---|
65 | */
|
---|
66 | @Test
|
---|
67 | public void testDataUrl() {
|
---|
68 | // Red dot image, taken from https://en.wikipedia.org/wiki/Data_URI_scheme#HTML
|
---|
69 | assertNotNull(ImageProvider.get("data:image/png;base64," +
|
---|
70 | "iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4"+
|
---|
71 | "//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg=="));
|
---|
72 | }
|
---|
73 | }
|
---|