source: trunk/lang/tcl/tests/element.test @ 1722

Last change on this file since 1722 was 1042, checked in by mmc, 16 years ago

Fixed the Rappture::encoding::encode and decode operations to honor "--".
This is handy when the string may start with a dash, as in:

Rappture::encoding::encode -- -hi

Fixed the library.tcl code to guard against encode/decode problem by
using the "--" in front of strings obtained from the xml.

Cleaned up the tests for the Rappture::LibraryObj? class. Everything
works properly now, except for units. Some of the tests are failing
because the units code reports "length" instead of "area" (test finds
this problem). This should be fixed in the units code.

File size: 3.3 KB
Line 
1# Commands covered: Rappture::library
2#
3# This file contains a collection of tests for one of the Rappture Tcl
4# commands.  Sourcing this file into Tcl runs the tests and
5# generates output for errors.  No output means no errors were found.
6#
7# ======================================================================
8# AUTHOR:  Derrick Kearney, Purdue University
9# Copyright (c) 2004-2006  Purdue Research Foundation
10#
11# See the file "license.terms" for information on usage and redistribution
12# of this file, and for a DISCLAIMER OF ALL WARRANTIES.
13
14
15if {[lsearch [namespace children] ::tcltest] == -1} {
16    package require tcltest
17    package require Rappture
18    namespace import -force ::tcltest::*
19}
20catch {unset lib}
21set lib [Rappture::library rplib_test.xml]
22
23#----------------------------------------------------------
24# element command
25# element "?-as <fval>? ?<path>?"
26#     <fval> can be component, id, type, path, object
27#----------------------------------------------------------
28test library-5.0.1 {element command 0 arg} {
29    $lib element
30} {}
31test library-5.1.1 {element command path as default 1 arg} {
32    $lib element "input"
33} {input}
34test library-5.1.2 {element command path w/ id as default 1 arg} {
35    $lib element "input.number(min)"
36} {number(min)}
37test library-5.1.3 {element command non-existant path 1 arg} {
38    $lib element "kdsf.werw(we12)"
39} {}
40test library-5.2.1 {element command path 2 arg} {
41    list [catch {$lib element "input.number(min)" "wreew"} msg] $msg
42} {1 {wrong # args: should be "element ?-as fval? ?path?"}}
43test library-5.3.1.1 {element command path -as flag  no option} {
44    list [catch {$lib element -as} msg] $msg
45} {1 {bad path component "-as"}}
46test library-5.3.2 {element command path -as component, path with id} {
47    $lib element -as component "input.number(max)"
48} {number(max)}
49test library-5.3.3 {element command path -as id, path with id} {
50    $lib element -as id "input.number(max)"
51} {max}
52test library-5.3.4 {element command path -as type, path with id} {
53    $lib element -as type "input.number(max)"
54} {number}
55test library-5.3.5 {element command path -as path, path with id} {
56    $lib element -as path "input.number(max)"
57} {input.number(max)}
58test library-5.3.6 {element command path -as object, path with id} {
59    set ele [$lib element -as object "input.number(max)"]
60    list [catch {$ele isa ::Rappture::LibraryObj} msg] $msg
61} {0 1}
62test library-5.3.7.1 {element command path -as junk, path with id} {
63    list [catch {$lib element -as junk "input.number(max)"} msg] $msg
64} {1 {bad flavor "junk": should be component, id, object, path, type}}
65test library-5.3.8 {element command path -as component, path does not exist} {
66    $lib element -as component "input.test(we)"
67} {}
68test library-5.3.9 {element command path -as id, path does not exist} {
69    $lib element -as id "input.test(we)"
70} {}
71test library-5.3.10 {element command path -as type, path does not exist} {
72    $lib element -as type "input.test(we)"
73} {}
74test library-5.3.11 {element command path -as path, path does not exist} {
75    $lib element -as path "input.test(we)"
76} {}
77test library-5.3.12 {element command path -as object, path does not exist} {
78    $lib element -as object "input.test(we)"
79} {}
80test library-5.4.1 {element command path -junk path} {
81    list [catch {$lib element -junk "input"} msg] $msg
82} {1 {bad option "-junk": should be -as}}
83
84::tcltest::cleanupTests
85return
Note: See TracBrowser for help on using the repository browser.