source: branches/geomap/gui/test/geomapdataprovider.test @ 5949

Last change on this file since 5949 was 5949, checked in by dkearney, 7 years ago

adding data provider and layer objects, updating mapviewer to remove layers from client and server.

File size: 11.4 KB
Line 
1# Commands covered:
2#   Rappture::GeoMapDataProvider
3#
4# This file contains a collection of tests for one of the Rappture Tcl
5# commands.  Sourcing this file into Tcl runs the tests and
6# generates output for errors.  No output means no errors were found.
7#
8# ======================================================================
9# AUTHOR:  Derrick Kearney, Purdue University
10# Copyright (c) 2004-2015  HUBzero Foundation, LLC
11#
12# See the file "license.terms" for information on usage and redistribution
13# of this file, and for a DISCLAIMER OF ALL WARRANTIES.
14
15
16if {[lsearch [namespace children] ::tcltest] == -1} {
17    package require tcltest
18    package require RapptureGUI
19    package require BLT
20    namespace import -force ::tcltest::*
21}
22catch {unset lib}
23
24proc check {var size} {
25    set l [llength $var]
26    if {$l != $size} {
27        return "length mismatch: should have been $size, was $l"
28    }
29    for {set i 0} {$i < $size} {set i [expr $i+1]} {
30        set j [lindex $var $i]
31        if {$j != "item $i"} {
32            return "element $i should have been \"item $i\", was \"$j\""
33        }
34    }
35    return ok
36}
37
38# temporary class for testing protected methods
39itcl::class TestDataProvider {
40    inherit Rappture::GeoMapDataProvider
41
42    constructor {type driver url} {
43        Rappture::GeoMapDataProvider::constructor $type $driver $url
44    } {
45        # empty
46    }
47    destructor {
48        # empty
49    }
50    public method do { args } {eval $args}
51}
52
53#----------------------------------------------------------
54#----------------------------------------------------------
55# constructor command
56# Rappture::GeoMapDataProvider <name> <type> <driver> <url>
57#----------------------------------------------------------
58test geomapdataprovider-1.1 {Rappture::GeoMapDataProvider, 0 arguments} {
59    list [catch {Rappture::GeoMapDataProvider} msg] $msg
60} {0 {}}
61
62
63test geomapdataprovider-1.2 {Rappture::GeoMapDataProvider, 1 arguments} {
64    list [catch {Rappture::GeoMapDataProvider name "image"} msg] $msg
65} {1 {wrong # args: should be "::Rappture::GeoMapDataProvider name type driver url ?arg arg ...?"}}
66
67
68test geomapdataprovider-1.3 {Rappture::GeoMapDataProvider, 2 arguments} {
69    list [catch {Rappture::GeoMapDataProvider name "image" "xyz"} msg] $msg
70} {1 {wrong # args: should be "::Rappture::GeoMapDataProvider name type driver url ?arg arg ...?"}}
71
72
73test geomapdataprovider-1.4 {
74    Rappture::GeoMapDataProvider, type driver url
75} -body {
76    list [catch {Rappture::GeoMapDataProvider name "image" "xyz" \
77                    {http://myurl.com/{z}/{x}/{y}.jpg}
78                } msg] $msg
79} -cleanup {
80    catch {itcl::delete object name} err
81} -result {0 name}
82
83
84#----------------------------------------------------------
85# Type command
86# $dp Type
87# $dp Type <type>
88#----------------------------------------------------------
89test geomapdataprovider-2.1 {Type, 0 arguments} {
90    set dp [TestDataProvider #auto "image" "xyz" {http://myurl.com/{z}/{x}/{y}.jpg}]
91    list [catch {$dp do Type} msg] $msg
92} {0 image}
93
94test geomapdataprovider-2.2 {Type, set type to "image"} {
95    set dp [TestDataProvider #auto "elevation" "xyz" {http://myurl.com/{z}/{x}/{y}.jpg}]
96    list [catch {$dp do Type "image"} msg] $msg
97} {0 image}
98
99test geomapdataprovider-2.3 {Type, set type to "feature"} {
100    set dp [TestDataProvider #auto "image" "xyz" {http://myurl.com/{z}/{x}/{y}.jpg}]
101    list [catch {$dp do Type "feature"} msg] $msg
102} {0 feature}
103
104test geomapdataprovider-2.4 {Type, set type to "icon"} {
105    set dp [TestDataProvider #auto "image" "xyz" {http://myurl.com/{z}/{x}/{y}.jpg}]
106    list [catch {$dp do Type "icon"} msg] $msg
107} {0 icon}
108
109test geomapdataprovider-2.5 {Type, set type to "line"} {
110    set dp [TestDataProvider #auto "image" "xyz" {http://myurl.com/{z}/{x}/{y}.jpg}]
111    list [catch {$dp do Type "line"} msg] $msg
112} {0 line}
113
114test geomapdataprovider-2.6 {Type, set type to "point"} {
115    set dp [TestDataProvider #auto "image" "xyz" {http://myurl.com/{z}/{x}/{y}.jpg}]
116    list [catch {$dp do Type "point"} msg] $msg
117} {0 point}
118
119test geomapdataprovider-2.7 {Type, set type to "polygon"} {
120    set dp [TestDataProvider #auto "image" "xyz" {http://myurl.com/{z}/{x}/{y}.jpg}]
121    list [catch {$dp do Type "polygon"} msg] $msg
122} {0 polygon}
123
124test geomapdataprovider-2.8 {Type, set type to "text"} {
125    set dp [TestDataProvider #auto "image" "xyz" {http://myurl.com/{z}/{x}/{y}.jpg}]
126    list [catch {$dp do Type "text"} msg] $msg
127} {0 text}
128
129test geomapdataprovider-2.9 {Type, set type to "image" and retrieve type} {
130    set dp [TestDataProvider #auto "elevation" "xyz" {http://myurl.com/{z}/{x}/{y}.jpg}]
131    $dp do Type "image"
132    list [catch {$dp do Type} msg] $msg
133} {0 image}
134
135
136#----------------------------------------------------------
137# Driver command
138# $dp Driver
139# $dp Driver <driver>
140#----------------------------------------------------------
141test geomapdataprovider-3.1 {Driver, 0 arguments} {
142    set dp [TestDataProvider #auto "image" "xyz" {http://myurl.com/{z}/{x}/{y}.jpg}]
143    list [catch {$dp do Driver} msg] $msg
144} {0 xyz}
145
146test geomapdataprovider-3.2 {Driver, set driver to "arcgis"} {
147    set dp [TestDataProvider #auto "image" "xyz" {http://myurl.com/{z}/{x}/{y}.jpg}]
148    list [catch {$dp do Driver "arcgis"} msg] $msg
149} {0 arcgis}
150
151test geomapdataprovider-3.3 {Driver, set driver to "colorramp"} {
152    set dp [TestDataProvider #auto "image" "xyz" {http://myurl.com/{z}/{x}/{y}.jpg}]
153    list [catch {$dp do Driver "colorramp"} msg] $msg
154} {0 colorramp}
155
156test geomapdataprovider-3.4 {Driver, set driver to "debug"} {
157    set dp [TestDataProvider #auto "image" "xyz" {http://myurl.com/{z}/{x}/{y}.jpg}]
158    list [catch {$dp do Driver "debug"} msg] $msg
159} {0 debug}
160
161test geomapdataprovider-3.5 {Driver, set driver to "gdal"} {
162    set dp [TestDataProvider #auto "image" "xyz" {http://myurl.com/{z}/{x}/{y}.jpg}]
163    list [catch {$dp do Driver "gdal"} msg] $msg
164} {0 gdal}
165
166test geomapdataprovider-3.6 {Driver, set driver to "ogr"} {
167    set dp [TestDataProvider #auto "image" "xyz" {http://myurl.com/{z}/{x}/{y}.jpg}]
168    list [catch {$dp do Driver "ogr"} msg] $msg
169} {0 ogr}
170
171test geomapdataprovider-3.7 {Driver, set driver to "tfs"} {
172    set dp [TestDataProvider #auto "image" "xyz" {http://myurl.com/{z}/{x}/{y}.jpg}]
173    list [catch {$dp do Driver "tfs"} msg] $msg
174} {0 tfs}
175
176test geomapdataprovider-3.8 {Driver, set driver to "tms"} {
177    set dp [TestDataProvider #auto "image" "xyz" {http://myurl.com/{z}/{x}/{y}.jpg}]
178    list [catch {$dp do Driver "tms"} msg] $msg
179} {0 tms}
180
181test geomapdataprovider-3.9 {Driver, set driver to "wcs"} {
182    set dp [TestDataProvider #auto "image" "xyz" {http://myurl.com/{z}/{x}/{y}.jpg}]
183    list [catch {$dp do Driver "wcs"} msg] $msg
184} {0 wcs}
185
186test geomapdataprovider-3.10 {Driver, set driver to "wfs"} {
187    set dp [TestDataProvider #auto "image" "xyz" {http://myurl.com/{z}/{x}/{y}.jpg}]
188    list [catch {$dp do Driver "wfs"} msg] $msg
189} {0 wfs}
190
191test geomapdataprovider-3.11 {Driver, set driver to "wms"} {
192    set dp [TestDataProvider #auto "image" "xyz" {http://myurl.com/{z}/{x}/{y}.jpg}]
193    list [catch {$dp do Driver "wms"} msg] $msg
194} {0 wms}
195
196test geomapdataprovider-3.11 {Driver, set driver to "xyz"} {
197    set dp [TestDataProvider #auto "image" "colorramp" {http://myurl.com/{z}/{x}/{y}.jpg}]
198    list [catch {$dp do Driver "xyz"} msg] $msg
199} {0 xyz}
200
201test geomapdataprovider-3.12 {Driver, set type to "xyz" and retrieve type} {
202    set dp [TestDataProvider #auto "image" "colorramp" {http://myurl.com/{z}/{x}/{y}.jpg}]
203    $dp do Driver "xyz"
204    list [catch {$dp do Driver} msg] $msg
205} {0 xyz}
206
207
208#----------------------------------------------------------
209# Url command
210# $dp Url
211# $dp Url <url>
212#----------------------------------------------------------
213test geomapdataprovider-4.1 {Url, 0 arguments} {
214    set dp [TestDataProvider #auto "image" "xyz" {http://myurl.com/{z}/{x}/{y}.jpg}]
215    list [catch {$dp do Url} msg] $msg
216} {0 http://myurl.com/{z}/{x}/{y}.jpg}
217
218test geomapdataprovider-4.2 {Url, valid http url} {
219    set dp [TestDataProvider #auto "image" "xyz" {http://myurl.com/{z}/{x}/{y}.jpg}]
220    list [catch {$dp do Url {http://mynewurl.com/{z}/{x}/{y}.jpg}} msg] $msg
221} {0 http://mynewurl.com/{z}/{x}/{y}.jpg}
222
223test geomapdataprovider-4.3 {Url, valid file url} {
224    set dp [TestDataProvider #auto "image" "xyz" {http://myurl.com/{z}/{x}/{y}.jpg}]
225    list [catch {$dp do Url {file:///myfilename.jpg}} msg] $msg
226} {0 file:///myfilename.jpg}
227
228test geomapdataprovider-4.4 {Url, invalid url} {
229    set dp [TestDataProvider #auto "image" "xyz" {http://myurl.com/{z}/{x}/{y}.jpg}]
230    list [catch {$dp do Url "mynewurl"} msg] $msg
231} {1 {bad value "mynewurl": should be a valid url or url pattern}}
232
233test geomapdataprovider-4.5 {Url, set url and retrieve it} {
234    set dp [TestDataProvider #auto "image" "xyz" {http://myurl.com/{z}/{x}/{y}.jpg}]
235    $dp do Url {file:///myfilename.jpg}
236    list [catch {$dp do Url} msg] $msg
237} {0 file:///myfilename.jpg}
238
239#----------------------------------------------------------
240# attribution flag
241# $dp configure -attribution "copyright text"
242# $dp cget -attribution
243#----------------------------------------------------------
244
245test geomapdataprovider-5.1 {-attribution, set to non-empty string} {
246    set dp [Rappture::GeoMapDataProvider #auto "image" "xyz" \
247                {http://myurl.com/{z}/{x}/{y}.jpg} \
248                -attribution "copyright text"]
249    list [catch {$dp cget -attribution} msg] $msg
250} {0 {copyright text}}
251
252test geomapdataprovider-5.2 {-attribution, set to empty string} {
253    set dp [Rappture::GeoMapDataProvider #auto "image" "xyz" \
254                {http://myurl.com/{z}/{x}/{y}.jpg} \
255                -attribution "copyright text"]
256    $dp configure -attribution ""
257    list [catch {$dp cget -attribution} msg] $msg
258} {0 {}}
259
260
261#----------------------------------------------------------
262# cache flag
263# $dp configure -cache true
264# $dp cget -cache
265#----------------------------------------------------------
266
267test geomapdataprovider-6.1 {-cache, set to boolean true} {
268    set dp [Rappture::GeoMapDataProvider #auto "image" "xyz" \
269                {http://myurl.com/{z}/{x}/{y}.jpg} \
270                -cache true]
271    list [catch {$dp cget -cache} msg] $msg
272} {0 true}
273
274test geomapdataprovider-6.2 {-cache, set to boolean false} {
275    set dp [Rappture::GeoMapDataProvider #auto "image" "xyz" \
276                {http://myurl.com/{z}/{x}/{y}.jpg} \
277                -cache false]
278    list [catch {$dp cget -cache} msg] $msg
279} {0 false}
280
281test geomapdataprovider-6.3 {-attribution, set and retrieve cache} {
282    set dp [Rappture::GeoMapDataProvider #auto "image" "xyz" \
283                {http://myurl.com/{z}/{x}/{y}.jpg} \
284                -cache "false"]
285    $dp configure -cache "true"
286    list [catch {$dp cget -cache} msg] $msg
287} {0 true}
288
289test geomapdataprovider-6.1 {-cache, set to invalid boolean} {
290    set dp [Rappture::GeoMapDataProvider #auto "image" "xyz" \
291                {http://myurl.com/{z}/{x}/{y}.jpg}]
292    list [catch {$dp configure -cache "notabool"} msg] $msg
293} {1 {bad value "notabool": should be a boolean}}
294
295
296#----------------------------------------------------------
297# exportToBltTree
298# $dp exportToBltTree $tree
299#----------------------------------------------------------
300
301test geomapdataprovider-7.1 {exportToBltTree, } {
302    set dp [Rappture::GeoMapDataProvider #auto "image" "xyz" \
303                {http://myurl.com/{z}/{x}/{y}.jpg}]
304    set tree [blt::tree create]
305    $dp exportToBltTree $tree
306    $tree dump root
307} {-1 0 ::tree0 {type image driver xyz cache true attribution {}} {}
308}
309
310
311# TODO:
312
313::tcltest::cleanupTests
314return
315
Note: See TracBrowser for help on using the repository browser.