Index: trunk/test/unit/org/openstreetmap/josm/data/imagery/WMTSTileSourceTest.java
===================================================================
--- trunk/test/unit/org/openstreetmap/josm/data/imagery/WMTSTileSourceTest.java	(revision 8568)
+++ trunk/test/unit/org/openstreetmap/josm/data/imagery/WMTSTileSourceTest.java	(revision 8569)
@@ -22,5 +22,6 @@
     private ImageryInfo testImageryTOPO_PL = getImagery("test/data/wmts/getcapabilities-TOPO.xml");
     private ImageryInfo testImageryORTO_PL = getImagery("test/data/wmts/getcapabilities-ORTO.xml");
-
+    private ImageryInfo testImageryWIEN = getImagery("test/data/wmts/getCapabilities-wien.xml");
+    private ImageryInfo testImageryWALLONIE = getImagery("test/data/wmts/WMTSCapabilities-Wallonie.xml");
 
     @BeforeClass
@@ -66,4 +67,41 @@
         assertEquals("TileXMax", 2, testSource.getTileXMax(2));
         assertEquals("TileYMax", 2, testSource.getTileYMax(2));
+        assertEquals("TileXMax", 5, testSource.getTileXMax(3));
+        assertEquals("TileYMax", 4, testSource.getTileYMax(3));
+
+    }
+
+    @Test
+    public void testWALLONIE() throws MalformedURLException, IOException {
+        Main.setProjection(Projections.getProjectionByCode("EPSG:31370"));
+        WMTSTileSource testSource = new WMTSTileSource(testImageryWALLONIE);
+    }
+
+    @Test
+    public void testWIEN() throws MalformedURLException, IOException {
+        Main.setProjection(Projections.getProjectionByCode("EPSG:3857"));
+        WMTSTileSource testSource = new WMTSTileSource(testImageryWIEN);
+        int zoomOffset = 10;
+
+        verifyMercatorTile(testSource, 0, 0, 1, zoomOffset);
+        verifyMercatorTile(testSource, 0, 0, 2, zoomOffset);
+        verifyMercatorTile(testSource, 1, 1, 2, zoomOffset);
+        for(int x = 0; x < 4; x++) {
+            for(int y = 0; y < 4; y++) {
+                verifyMercatorTile(testSource, x, y, 3, zoomOffset);
+            }
+        }
+        for(int x = 0; x < 8; x++) {
+            for(int y = 0; y < 4; y++) {
+                verifyMercatorTile(testSource, x, y, zoomOffset);
+            }
+        }
+
+        verifyMercatorTile(testSource, 2<<9 - 1, 2<<8 - 1, zoomOffset);
+
+        assertEquals("TileXMax", 1, testSource.getTileXMax(1));
+        assertEquals("TileYMax", 1, testSource.getTileYMax(1));
+        assertEquals("TileXMax", 2, testSource.getTileXMax(2));
+        assertEquals("TileYMax", 2, testSource.getTileYMax(2));
         assertEquals("TileXMax", 4, testSource.getTileXMax(3));
         assertEquals("TileYMax", 4, testSource.getTileYMax(3));
@@ -77,5 +115,5 @@
         verifyTile(new LatLon(56,12), testSource, 0, 0, 1);
         verifyTile(new LatLon(56,12), testSource, 0, 0, 2);
-        verifyTile(new LatLon(51.1323176, 16.8676823), testSource, 1, 1, 2);
+        verifyTile(new LatLon(51.1268639, 16.8731360), testSource, 1, 1, 2);
 
         assertEquals("TileXMax", 37, testSource.getTileXMax(1));
@@ -117,7 +155,11 @@
 
     private void verifyMercatorTile(WMTSTileSource testSource, int x, int y, int z) {
+        verifyMercatorTile(testSource, x, y, z, -1);
+    }
+
+    private void verifyMercatorTile(WMTSTileSource testSource, int x, int y, int z, int zoomOffset) {
         TemplatedTMSTileSource verifier = new TemplatedTMSTileSource(testImageryTMS);
         LatLon result = new LatLon(testSource.tileXYToLatLon(x, y, z));
-        LatLon expected = new LatLon(verifier.tileXYToLatLon(x, y, z-1));
+        LatLon expected = new LatLon(verifier.tileXYToLatLon(x, y, z + zoomOffset));
         System.out.println(z + "/" + x + "/" + y + " - result: " + result.toDisplayString() + " osmMercator: " +  expected.toDisplayString());
         assertEquals("Longitude" , expected.lon(), result.lon(), 1e-04);
