summaryrefslogtreecommitdiff
path: root/Examples/test-suite/tcl
diff options
context:
space:
mode:
authorOlly Betts <olly@survex.com>2023-05-12 16:18:46 +1200
committerOlly Betts <olly@survex.com>2023-05-12 16:18:46 +1200
commit5b709dd1632580e52fbbf1385c66abccbd16b728 (patch)
tree22dc87977ee955eb1d0c3851dba02a77624daf28 /Examples/test-suite/tcl
parenta44a7de3481e5f59c08dd71ec89b30b7578a52b9 (diff)
parentb6eaee8d1219619113f715a7ee35644bfd557f34 (diff)
downloadswig-5b709dd1632580e52fbbf1385c66abccbd16b728.tar.gz
Merge branch 'JS-check-fix'
Diffstat (limited to 'Examples/test-suite/tcl')
-rw-r--r--Examples/test-suite/tcl/li_constraints_runme.tcl51
1 files changed, 51 insertions, 0 deletions
diff --git a/Examples/test-suite/tcl/li_constraints_runme.tcl b/Examples/test-suite/tcl/li_constraints_runme.tcl
new file mode 100644
index 000000000..5ef802a06
--- /dev/null
+++ b/Examples/test-suite/tcl/li_constraints_runme.tcl
@@ -0,0 +1,51 @@
+if [ catch { load ./li_constraints[info sharedlibextension] li_constraints} err_msg ] {
+ puts stderr "Could not load shared object:\n$err_msg"
+}
+
+proc check_double {except fn f val} {
+ set actual [ catch { $fn $val } err_msg ]
+ if { $actual == 0 } {
+ if { $except != 0 } {
+ error "function '$f' with $val should perform an exception"
+ }
+ } else {
+ if { $except == 0 } {
+ error "function '$f' with $val should not perform an exception"
+ } elseif { [ string equal $err_msg "ValueError Expected a $f value." ] != 1 } {
+ error "function '$f' with $val should perform a proper exception"
+ }
+ }
+}
+
+proc nonnegative {val } { test_nonnegative $val }
+check_double 0 nonnegative "non-negative" 10
+check_double 0 nonnegative "non-negative" 0
+check_double 1 nonnegative "non-negative" -10
+
+proc nonpositive {val } { test_nonpositive $val }
+check_double 1 nonpositive "non-positive" 10
+check_double 0 nonpositive "non-positive" 0
+check_double 0 nonpositive "non-positive" -10
+
+proc positive {val } { test_positive $val }
+check_double 0 positive "positive" 10
+check_double 1 positive "positive" 0
+check_double 1 positive "positive" -10
+
+proc negative {val } { test_negative $val }
+check_double 1 negative "negative" 10
+check_double 1 negative "negative" 0
+check_double 0 negative "negative" -10
+
+proc nonzero {val } { test_nonzero $val }
+check_double 0 nonzero "nonzero" 10
+check_double 1 nonzero "nonzero" 0
+check_double 0 nonzero "nonzero" -10
+
+set actual [ catch { test_nonnull NULL } err_msg ]
+if { ($actual != 1) ||
+ ([ string equal $err_msg "ValueError Received a NULL pointer." ] != 1) } {
+ error "Test 'test_nonnull' with null value fail"
+}
+set nonnull [ get_nonnull ]
+test_nonnull $nonnull