|
| 1 | +/* |
| 2 | + * Copyright 2026 Google LLC |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +package com.google.maps.android.compose.wms |
| 18 | + |
| 19 | +import org.junit.Assert.assertArrayEquals |
| 20 | +import org.junit.Test |
| 21 | + |
| 22 | +public class WmsUrlTileProviderTest { |
| 23 | + |
| 24 | + private val worldSize: Double = 20037508.34789244 |
| 25 | + |
| 26 | + @Test |
| 27 | + public fun testGetBoundingBoxZoom0() { |
| 28 | + val provider = WmsUrlTileProvider { _, _, _, _, _ -> "" } |
| 29 | + val bbox = provider.getBoundingBox(0, 0, 0) |
| 30 | + |
| 31 | + // Zoom 0, Tile 0,0 should cover the entire world |
| 32 | + val expected = doubleArrayOf(-worldSize, -worldSize, worldSize, worldSize) |
| 33 | + assertArrayEquals(expected, bbox, 0.001) |
| 34 | + } |
| 35 | + |
| 36 | + @Test |
| 37 | + public fun testGetBoundingBoxZoom1() { |
| 38 | + val provider = WmsUrlTileProvider { _, _, _, _, _ -> "" } |
| 39 | + |
| 40 | + // Zoom 1, Tile 0,0 (Top Left) |
| 41 | + val bbox00 = provider.getBoundingBox(0, 0, 1) |
| 42 | + val expected00 = doubleArrayOf(-worldSize, 0.0, 0.0, worldSize) |
| 43 | + assertArrayEquals(expected00, bbox00, 0.001) |
| 44 | + |
| 45 | + // Zoom 1, Tile 1,1 (Bottom Right) |
| 46 | + val bbox11 = provider.getBoundingBox(1, 1, 1) |
| 47 | + val expected11 = doubleArrayOf(0.0, -worldSize, worldSize, 0.0) |
| 48 | + assertArrayEquals(expected11, bbox11, 0.001) |
| 49 | + } |
| 50 | + |
| 51 | + @Test |
| 52 | + public fun testGetBoundingBoxSpecificTile() { |
| 53 | + val provider = WmsUrlTileProvider { _, _, _, _, _ -> "" } |
| 54 | + |
| 55 | + // Zoom 2, Tile 1,1 |
| 56 | + // Num tiles = 4x4. Tile size = 2 * worldSize / 4 = worldSize / 2 |
| 57 | + // xMin = -worldSize + 1 * (worldSize/2) = -worldSize/2 |
| 58 | + // xMax = -worldSize + 2 * (worldSize/2) = 0 |
| 59 | + // yMax = worldSize - 1 * (worldSize/2) = worldSize/2 |
| 60 | + // yMin = worldSize - 2 * (worldSize/2) = 0 |
| 61 | + val bbox = provider.getBoundingBox(1, 1, 2) |
| 62 | + val expected = doubleArrayOf(-worldSize / 2, 0.0, 0.0, worldSize / 2) |
| 63 | + assertArrayEquals(expected, bbox, 0.001) |
| 64 | + } |
| 65 | +} |
0 commit comments