Ticket #10836: 10836_test.patch
File 10836_test.patch, 5.1 KB (added by , 9 years ago) |
---|
-
test/unit/org/openstreetmap/josm/TestUtils.java
20 20 public class TestUtils { 21 21 22 22 /** 23 * Returns the path to images root directory. 24 * @return path to images root directory 25 */ 26 public static String getImagesRoot() { 27 String imagesRoot = System.getProperty("josm.images"); 28 if (imagesRoot == null || imagesRoot.isEmpty()) { 29 imagesRoot = "images"; 30 System.out.println("System property josm.images is not set, using '" + imagesRoot + "'"); 31 } 32 return imagesRoot.endsWith("/") ? imagesRoot : imagesRoot + "/"; 33 } 34 35 /** 23 36 * Returns the path to test data root directory. 24 37 * @return path to test data root directory 25 38 */ -
test/unit/org/openstreetmap/josm/tools/ImageProviderTest.java
5 5 import static org.junit.Assert.assertThat; 6 6 7 7 import java.awt.Transparency; 8 import java.awt.event.ActionEvent; 8 9 import java.io.File; 9 10 import java.io.IOException; 11 import java.nio.file.FileVisitResult; 12 import java.nio.file.FileVisitor; 13 import java.nio.file.Files; 14 import java.nio.file.Path; 15 import java.nio.file.Paths; 16 import java.nio.file.attribute.BasicFileAttributes; 17 import java.util.regex.Pattern; 18 19 import javax.swing.AbstractAction; 10 20 21 import org.junit.BeforeClass; 11 22 import org.junit.Test; 23 import org.openstreetmap.josm.JOSMFixture; 24 import org.openstreetmap.josm.Main; 12 25 import org.openstreetmap.josm.TestUtils; 13 26 14 27 /** … … 17 30 public class ImageProviderTest { 18 31 19 32 /** 33 * Setup test. 34 */ 35 @BeforeClass 36 public static void setUp() { 37 JOSMFixture.createUnitTestFixture().init(); 38 } 39 40 /** 20 41 * Non-regression test for ticket <a href="https://josm.openstreetmap.de/ticket/9984">#9984</a> 21 42 * @throws IOException if an error occurs during reading 22 43 */ … … 38 59 File file = new File(TestUtils.getRegressionDataFile(10030, "tile.jpg")); 39 60 ImageProvider.read(file, true, true); 40 61 } 62 63 /** 64 * Non-regression test for ticket <a href="https://josm.openstreetmap.de/ticket/10836">#10836</a> 65 * @throws IOException if an error occurs during reading 66 */ 67 @Test 68 public void testTicket10836() throws IOException { 69 final Path rootDir = Paths.get(TestUtils.getImagesRoot()); 70 // Search for all SVG files 71 Files.walkFileTree(rootDir, new FileVisitor<Path>() { 72 private final Pattern pattern = Pattern.compile(".*\\.svg"); 73 74 @Override 75 public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException { 76 return FileVisitResult.CONTINUE; 77 } 78 79 @Override 80 public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { 81 String path = file.toString(); 82 if (pattern.matcher(path).matches()) { 83 Main.info("Decoding SVG file: "+path); 84 // Validate SVG file in background, as done in TaggingPreset 85 new ImageProvider(path.replace(rootDir+File.separator, "")).getInBackground( 86 new ImageProvider.ImageResourceCallback() { 87 @Override 88 public void finished(ImageResource result) { 89 result.getImageIcon(new AbstractAction() { 90 @Override 91 public void actionPerformed(ActionEvent e) { 92 // Do nothing 93 } 94 }); 95 } 96 }); 97 } 98 return FileVisitResult.CONTINUE; 99 } 100 101 @Override 102 public FileVisitResult visitFileFailed(Path file, IOException exc) throws IOException { 103 Main.error(exc); 104 if (pattern.matcher(file.toString()).matches()) { 105 // If an SVG file has failed, make the test fail 106 throw exc; 107 } 108 return FileVisitResult.CONTINUE; 109 } 110 111 @Override 112 public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException { 113 if (exc != null) { 114 Main.error(exc); 115 if (dir.equals(rootDir)) { 116 // If the root directory has failed, make the test fail 117 throw exc; 118 } 119 } 120 return FileVisitResult.CONTINUE; 121 }}); 122 } 41 123 }