1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176
|
# $Id: zoomtest.py 5542 2006-07-03 22:43:20Z hobu $
#
# Project: MapServer
# Purpose: xUnit style Python mapscript tests of Map "zooming"
# Author: Sean Gillies, sgillies@frii.com
#
# ===========================================================================
# Copyright (c) 2004, Sean Gillies
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the "Software"),
# to deal in the Software without restriction, including without limitation
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
# and/or sell copies of the Software, and to permit persons to whom the
# Software is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included
# in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
# DEALINGS IN THE SOFTWARE.
# ===========================================================================
#
# Execute this module as a script from mapserver/mapscript/python
#
# python tests/cases/zoomtest.py -v
#
# ===========================================================================
import os, sys
import unittest
# the testing module helps us import the pre-installed mapscript
from testing import mapscript, MapZoomTestCase
# ===========================================================================
# Test begins now
class ZoomPointTestCase(MapZoomTestCase):
def testRecenter(self):
"""ZoomPointTestCase.testRecenter: recentering the map with a point returns the same extent"""
w, h = (self.mapobj1.width, self.mapobj1.height)
p = mapscript.pointObj(50.0, 50.0)
extent = self.mapobj1.extent
self.mapobj1.zoomPoint(1, p, w, h, extent, None)
new_extent = self.mapobj1.extent
self.assertRectsEqual(new_extent, mapscript.rectObj(-50,-50,50,50))
def testZoomInPoint(self):
"""ZoomPointTestCase.testZoomInPoint: zooming in by a power of 2 returns the proper extent"""
w, h = (self.mapobj1.width, self.mapobj1.height)
p = mapscript.pointObj(50.0, 50.0)
extent = self.mapobj1.extent
self.mapobj1.zoomPoint(2, p, w, h, extent, None)
new_extent = self.mapobj1.extent
self.assertRectsEqual(new_extent, mapscript.rectObj(-25,-25,25,25))
def testZoomOutPoint(self):
"""ZoomPointTestCase.testZoomOutPoint: zooming out by a power of 2 returns the proper extent"""
w, h = (self.mapobj1.width, self.mapobj1.height)
p = mapscript.pointObj()
p.x, p.y = (50, 50)
extent = self.mapobj1.extent
self.mapobj1.zoomPoint(-2, p, w, h, extent, None)
new_extent = self.mapobj1.extent
self.assertRectsEqual(new_extent, mapscript.rectObj(-100,-100,100,100))
def testZoomOutPointConstrained(self):
"""ZoomPointTestCase.testZoomOutPointConstrained: zooming out to a constrained extent returns proper extent"""
w, h = (self.mapobj1.width, self.mapobj1.height)
max = mapscript.rectObj()
max.minx, max.miny, max.maxx, max.maxy = (-100.0,-100.0,100.0,100.0)
p = mapscript.pointObj()
p.x, p.y = (50, 50)
extent = self.mapobj1.extent
self.mapobj1.zoomPoint(-4, p, w, h, extent, max)
new_extent = self.mapobj1.extent
self.assertRectsEqual(new_extent, max)
def testZoomBadSize(self):
"""ZoomPointTestCase.testZoomBadSize: zooming to a bad size raises proper error"""
p = mapscript.pointObj()
p.x, p.y = (50, 50)
extent = self.mapobj1.extent
w = 0
h = -1
self.assertRaises(mapscript.MapServerError,
self.mapobj1.zoomPoint, -2, p, w, h, extent, None);
def testZoomBadExtent(self):
"""ZoomPointTestCase.testZoomBadExtent: zooming to a bad extent raises proper error"""
p = mapscript.pointObj()
p.x, p.y = (50, 50)
extent = self.mapobj1.extent
extent.maxx = extent.maxx - 1000000
w = 100
h = 100
self.assertRaises(mapscript.MapServerError,
self.mapobj1.zoomPoint, -2, p, w, h, extent, None);
class ZoomRectangleTestCase(MapZoomTestCase):
def testZoomRectangle(self):
"""ZoomRectangleTestCase.testZoomRectangle: zooming to an extent returns proper map extent"""
w, h = (self.mapobj1.width, self.mapobj1.height)
r = mapscript.rectObj(1, 26, 26, 1, 1)
extent = self.mapobj1.extent
self.mapobj1.zoomRectangle(r, w, h, extent, None)
new_extent = self.mapobj1.extent
self.assertRectsEqual(new_extent, mapscript.rectObj(-49,24,-24,49))
def testZoomRectangleConstrained(self):
"""ZoomRectangleTestCase.testZoomRectangleConstrained: zooming to a constrained extent returns proper extent"""
w, h = (self.mapobj1.width, self.mapobj1.height)
max = mapscript.rectObj(-100.0, -100.0, 100.0, 100.0)
r = mapscript.rectObj(0, 200, 200, 0, 1)
extent = self.mapobj1.extent
self.mapobj1.zoomRectangle(r, w, h, extent, max)
new_extent = self.mapobj1.extent
self.assertRectsEqual(new_extent, max)
def testZoomRectangleBadly(self):
"""zooming into an invalid extent raises proper error"""
w, h = (self.mapobj1.width, self.mapobj1.height)
r = mapscript.rectObj(0, 0, 200, 200)
extent = self.mapobj1.extent
self.assertRaises(mapscript.MapServerError,
self.mapobj1.zoomRectangle, r, w, h, extent, None)
class ZoomScaleTestCase(MapZoomTestCase):
def testRecenter(self):
"""ZoomScaleTestCase.testRecenter: recentering map returns proper extent"""
w, h = (self.mapobj1.width, self.mapobj1.height)
p = mapscript.pointObj()
p.x, p.y = (50, 50)
scale = 2834.6472
extent = self.mapobj1.extent
self.mapobj1.zoomScale(scale, p, w, h, extent, None)
new_extent = self.mapobj1.extent
self.assertRectsEqual(new_extent, mapscript.rectObj(-50,-50,50,50))
def testZoomInScale(self):
"""ZoomScaleTestCase.testZoomInScale: zooming in to a specified scale returns proper extent"""
w, h = (self.mapobj1.width, self.mapobj1.height)
p = mapscript.pointObj()
p.x, p.y = (50, 50)
scale = 1417.3236
extent = self.mapobj1.extent
self.mapobj1.zoomScale(scale, p, w, h, extent, None)
new_extent = self.mapobj1.extent
self.assertRectsEqual(new_extent, mapscript.rectObj(-25,-25,25,25))
def testZoomOutScale(self):
"""ZoomScaleTestCase.testZoomOutScale: zooming out to a specified scale returns proper extent"""
w, h = (self.mapobj1.width, self.mapobj1.height)
p = mapscript.pointObj()
p.x, p.y = (50, 50)
scale = 5669.2944
extent = self.mapobj1.extent
self.mapobj1.zoomScale(scale, p, w, h, extent, None)
new_extent = self.mapobj1.extent
self.assertRectsEqual(new_extent, mapscript.rectObj(-100,-100,100,100))
def testZoomOutPointConstrained(self):
"""ZoomScaleTestCase.testZoomOutPointConstrained: zooming out to a constrained extent returns proper extent"""
w, h = (self.mapobj1.width, self.mapobj1.height)
max = mapscript.rectObj()
max.minx, max.miny, max.maxx, max.maxy = (-100.0,-100.0,100.0,100.0)
p = mapscript.pointObj()
p.x, p.y = (50, 50)
extent = self.mapobj1.extent
scale = 10000
self.mapobj1.zoomScale(scale, p, w, h, extent, max)
new_extent = self.mapobj1.extent
self.assertRectsEqual(new_extent, max)
# ===========================================================================
# Run the tests outside of the main suite
if __name__ == '__main__':
unittest.main()
|