Browse code

fix test

devnewton authored on 23/01/2014 at 15:21:02
Showing 1 changed files
... ...
@@ -58,10 +58,10 @@ public class TestTmxLoader {
58 58
                 tilesetParentDir = mapParentDir;
59 59
             }
60 60
             if (null != tileset.getImage()) {
61
-                tileset.getImage().setSource(new File(tilesetParentDir, tileset.getImage().getSource()).getCanonicalPath());
61
+                tileset.getImage().setSource(convertRelativeToAbsolutePath(tilesetParentDir, tileset.getImage().getSource()));
62 62
             }
63 63
             for (TmxTile tile : tileset.getTiles()) {
64
-                tile.getFrame().getImage().setSource(new File(tilesetParentDir, tile.getFrame().getImage().getSource()).getCanonicalPath());
64
+                tile.getFrame().getImage().setSource(convertRelativeToAbsolutePath(tilesetParentDir, tile.getFrame().getImage().getSource()));
65 65
             }
66 66
         }
67 67
         loader.decode(map);
... ...
@@ -72,6 +72,13 @@ public class TestTmxLoader {
72 72
         Assert.assertEquals(32, map.getTileheight());
73 73
         Assert.assertEquals(1, map.getLayers().size());
74 74
     }
75
+    
76
+    private String convertRelativeToAbsolutePath(File parentDir, String relativePath) throws IOException {
77
+        if(new File(relativePath).isAbsolute()) {
78
+            return relativePath;
79
+        }
80
+        return new File(parentDir, relativePath).getCanonicalPath();        
81
+    }
75 82
 
76 83
     private String loadText(File f) throws IOException {
77 84
         try (InputStream is = new FileInputStream(f); Scanner s = new Scanner(is, "UTF-8").useDelimiter("\\Z")) {