diff options
author | Andy Cedilnik <andy.cedilnik@kitware.com> | 2004-04-30 16:17:06 (GMT) |
---|---|---|
committer | Andy Cedilnik <andy.cedilnik@kitware.com> | 2004-04-30 16:17:06 (GMT) |
commit | a828368232fe08e0065c26e07c38f4dafc78aadf (patch) | |
tree | 4d241763e626a7af5d127864e3afff22953d2633 /Tests/SwigTest/runme2.tcl | |
parent | 257daa4635ed9b88035c84c5cb1fcc689268a949 (diff) | |
download | CMake-a828368232fe08e0065c26e07c38f4dafc78aadf.zip CMake-a828368232fe08e0065c26e07c38f4dafc78aadf.tar.gz CMake-a828368232fe08e0065c26e07c38f4dafc78aadf.tar.bz2 |
ENH: Here is test for swig module
Diffstat (limited to 'Tests/SwigTest/runme2.tcl')
-rw-r--r-- | Tests/SwigTest/runme2.tcl | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/Tests/SwigTest/runme2.tcl b/Tests/SwigTest/runme2.tcl new file mode 100644 index 0000000..88ec2f6 --- /dev/null +++ b/Tests/SwigTest/runme2.tcl @@ -0,0 +1,70 @@ +# file: runme2.tcl + +# This file illustrates the low-level C++ interface +# created by SWIG. In this case, all of our C++ classes +# get converted into function calls. + +catch { load ./example[info sharedlibextension] example} + +# ----- Object creation ----- + +puts "Creating some objects:" +set c [new_Circle 10] +puts " Created circle $c" +set s [new_Square 10] +puts " Created square $s" + +# ----- Access a static member ----- + +puts "\nA total of $Shape_nshapes shapes were created" + +# ----- Member data access ----- + +# Set the location of the object +# Note: the base class must be used since that's where x and y +# were declared. + +Shape_x_set $c 20 +Shape_y_set $c 30 +Shape_x_set $s -10 +Shape_y_set $s 5 + +puts "\nHere is their current position:" +puts " Circle = ([Shape_x_get $c], [Shape_y_get $c])" +puts " Square = ([Shape_x_get $s], [Shape_y_get $s])" + +# ----- Call some methods ----- + +puts "\nHere are some properties of the shapes:" +foreach o "$c $s" { + puts " $o" + puts " area = [Shape_area $o]" + puts " perimeter = [Shape_perimeter $o]" +} +# Notice how the Shape_area() and Shape_perimeter() functions really +# invoke the appropriate virtual method on each object. + +# ----- Try to cause a type error ----- + +puts "\nI'm going to try and break the type system" + +if { [catch { + # Bad script! + Square_area $c # Try to invoke Square method on a Circle + puts " Bad bad SWIG!" + +}]} { + puts " Well, it didn't work. Good SWIG." +} + +# ----- Delete everything ----- + +puts "\nGuess I'll clean up now" + +# Note: this invokes the virtual destructor +delete_Shape $c +delete_Shape $s + +puts "$Shape_nshapes shapes remain" +puts "Goodbye" + |