source: branches/geomap/gui/test/map.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: 6.3 KB
Line 
1# Commands covered:
2#   Rappture::Map
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    namespace import -force ::tcltest::*
20}
21catch {unset lib}
22
23proc check {var size} {
24    set l [llength $var]
25    if {$l != $size} {
26        return "length mismatch: should have been $size, was $l"
27    }
28    for {set i 0} {$i < $size} {set i [expr $i+1]} {
29        set j [lindex $var $i]
30        if {$j != "item $i"} {
31            return "element $i should have been \"item $i\", was \"$j\""
32        }
33    }
34    return ok
35}
36
37#----------------------------------------------------------
38
39#----------------------------------------------------------
40# constructor command
41# Rappture::Map <name>
42#----------------------------------------------------------
43
44test map-1.1 {Rappture::Map, 0 arguments} {
45    list [catch {Rappture::Map} msg] $msg
46} {0 {}}
47
48test map-1.2 {Rappture::Map, 1 arguments} {
49    list [catch {Rappture::Map .m0} msg] $msg
50} {0 .m0}
51
52#----------------------------------------------------------
53# layer command
54#
55# layer add ?-type type? layerData
56# layer delete layerName
57# layer settings layerName
58# layer names
59#----------------------------------------------------------
60
61set layerTree [blt::tree create]
62$layerTree set root \
63    type "image" \
64    driver "xyz" \
65    url "file:///myfile.txt" \
66    label "mylayer1" \
67    description "this is layer1" \
68    attribution "" \
69    cache "false" \
70    visibility "true" \
71    opacity "1.0"
72
73test map-2.0.0 {layer add, ingesting blt::tree layer data} {
74    set m [Rappture::Map #auto]
75    set err [catch {$m layer add $layerTree} msg]
76    if {$err != 0} {
77        list $err $msg
78    } else {
79        set layerName $msg
80        list $err [string compare $layerName ""]
81    }
82} {0 1}
83
84test map-2.0.1 {layer add, ingesting blt::tree layer data using -format flag} {
85    set m [Rappture::Map #auto]
86    set err [catch {$m layer add -format blt_tree $layerTree} msg]
87    if {$err != 0} {
88        list $err $msg
89    } else {
90        set layerName $msg
91        list $err [string compare $layerName ""]
92    }
93} {0 1}
94
95test map-2.0.2 {layer add, -format, invalid format} {
96    set m [Rappture::Map #auto]
97    list [catch {$m layer add -format bad_format $layerTree} msg] $msg
98} {1 {bad format "bad_format": should be one of blt_tree}}
99
100test map-2.0.3 {layer add, invalid option flag} {
101    set m [Rappture::Map #auto]
102    list [catch {$m layer add -badflag $layerTree} msg] $msg
103} {1 {invalid option "-badflag": should be one of -format}}
104
105
106test map-2.1.0 {layer delete, delete a layer} {
107    set m [Rappture::Map #auto]
108    set layerName [$m layer add -format blt_tree $layerTree]
109    list [catch {$m layer delete $layerName} msg] $msg
110} {0 {}}
111
112test map-2.1.1 {layer delete, delete an invalid layer, no layers exist} {
113    set m [Rappture::Map #auto]
114    # set layerName [$m layer add -format blt_tree $layerTree]
115    list [catch {$m layer delete "invalidLayerName"} msg] $msg
116} {1 {invalid layer "invalidLayerName": should be one of }}
117
118test map-2.1.2 {layer delete, delete an invalid layer, map with layers} {
119    set m [Rappture::Map #auto]
120    set layerName1 [$m layer add -format blt_tree $layerTree]
121    set layerName2 [$m layer add -format blt_tree $layerTree]
122    set err [catch {$m layer delete "invalidLayerName"} msg]
123    set msg [lrange [split $msg] 0 end-2]
124    list $err $msg
125} {1 {invalid layer {"invalidLayerName":} should be one of}}
126
127test map-2.2.0 {layer names, map with no layers} {
128    set m [Rappture::Map #auto]
129    list [catch {$m layer names} msg] $msg
130} {0 {}}
131
132test map-2.2.1 {layer names, map with a single layer} {
133    set m [Rappture::Map #auto]
134    set layerName1 [$m layer add -format blt_tree $layerTree]
135    set err [catch {$m layer names} msg]
136    if {$err == 0} {
137        set msg [string compare $layerName1 $msg]
138    }
139    list $err $msg
140} {0 0}
141
142test map-2.2.2 {layer names, map with a multiple layers} {
143    set m [Rappture::Map #auto]
144    set layerName1 [$m layer add -format blt_tree $layerTree]
145    set layerName2 [$m layer add -format blt_tree $layerTree]
146    set layerName3 [$m layer add -format blt_tree $layerTree]
147    set err [catch {$m layer names} msg]
148    if {$err == 0} {
149        foreach l [list $layerName1 $layerName2 $layerName3]  {
150            set i [lsearch -exact $msg $l]
151            if {$i >= 0} {
152                set msg [lreplace $msg $i $i]
153            }
154        }
155    }
156    list $err $msg
157} {0 {}}
158
159test map-2.2.3 {layer names, map with a multiple layers, add and delete} {
160    set m [Rappture::Map #auto]
161    set layerName1 [$m layer add -format blt_tree $layerTree]
162    set layerName2 [$m layer add -format blt_tree $layerTree]
163    set layerName3 [$m layer add -format blt_tree $layerTree]
164    $m layer delete $layerName2
165    set err [catch {$m layer names} msg]
166    if {$err == 0} {
167        foreach l [list $layerName1 $layerName3]  {
168            set i [lsearch -exact $msg $l]
169            if {$i >= 0} {
170                set msg [lreplace $msg $i $i]
171            }
172        }
173    }
174    list $err $msg
175} {0 {}}
176
177test map-2.3.0 {layer settings, retreive a layer's settings} {
178    set m [Rappture::Map #auto]
179    set layerName1 [$m layer add -format blt_tree $layerTree]
180    set err [catch {$m layer settings $layerName1} msg]
181    if {$err == 0} {
182        # compare the lists
183        set layerdata [$layerTree get root]
184        set msg [expr {[lsort $msg] eq [lsort $layerdata]}]
185    }
186    list $err $msg
187} {0 1}
188
189test map-2.3.1 {layer settings, unknown layer} {
190    set m [Rappture::Map #auto]
191    set layerName1 [$m layer add -format blt_tree $layerTree]
192    list [catch {$m layer settings "badLayerName"} msg] $msg
193} {1 {unknown layer "badLayerName"}}
194
195test map-2.4.0 {layer, bad option} {
196    set m [Rappture::Map #auto]
197    list [catch {$m layer badCommand} msg] $msg
198} {1 {unknown layer option "badCommand"}}
199
200
201
202
203# TODO:
204
205::tcltest::cleanupTests
206return
207
Note: See TracBrowser for help on using the repository browser.