#!/bin/sh # the next line restarts using wish \ exec wish8.4 "$0" "$@" # # RCS Version $Revision: 1.3 $ # RCS Last Change: $Date: 2002/10/07 17:38:09 $ # Original Author: Michael I. Schwartz, mschwart@nyx.net # # This file tests the various functions of ini # Changes will be made to # the ini file \TEST.INI # If all tests complete successfully, these changes are undone. # If not, you may wish to clean them up by hand. # Enhanced through suggestions by Jan Nijtmans, # to work with both Tclsh and Wish. # If executed under Wish, set up a text pane for output. Otherwise, use stdout. # Test for Tk by using tk_patchLevel variable if [ info exist tk_patchLevel ] { set file [info script] if {![winfo exists .f]} { frame .f button .f.d -text Dismiss -command [list destroy .] pack .f.d -side left button .f.a -text "Run Again" -command [list source $file] pack .f.a -side right button .f.c -text "See Code" -command [list see_code $file] pack .f.c -side right pack .f -side top -fill x text .t -yscrollcommand [list .s set] scrollbar .s -command [list .t yview] pack .s -side right -fill y pack .t -side right -expand y -fill both } else { wm deiconify . raise . } .t delete 1.0 end proc puts args { # Put only the last argument--ignore any channels or flags .t insert end "[lindex $args end]\n" .t see end update # Slight pause for effect after 100 } proc see_code file { if {![winfo exists .n]} { toplevel .n text .n.t -yscrollcommand [list .n.s set] scrollbar .n.s -command [list .n.t yview] pack .n.s -side right -fill y pack .n.t -side right -expand y -fill both set f [open $file r] .n.t insert end [read $f] close $f .n.t configure -state disabled } else { wm deiconify .n raise .n } } } # Output an informational message if [ catch { set windir $env(SystemRoot) } err ] { set windir "" } set profdir [ pwd ] puts "\ # This file tests the various functions of ini\n\ # Changes will be made to the ini file \n\ # $profdir\\TEST.INI\n\ # If all tests complete successfully, these changes are undone.\n\ # If not, you may wish to clean them up by hand.\n\n" # Get the package puts "Ini:Test1: Getting the package" if [ catch { package require ini } err ] { puts "Error: $err" puts "Package require didn't work for ini. Trying load." if [ catch { load ini } err ] { puts "Error: $err" puts "Can't load ini. Do it by hand, and source this script again." error "Giving up." } } # For unix only, set the directory to the current directory if [ catch { set default_profdir [ ini dir ] puts "Ini: The default ini directory is $default_profdir" } err ] { # Probably this is not a Windows platform.... puts "\nGetting ini directory only works on Unix platforms" } else { # This avoids certain permission and configuration problems for testing purposes if [ catch { ini dir $profdir } err ] { puts "\nCannot set ini directory to $profdir: $err" } } # Get the version puts "Ini:Test2: Get the version" set ver [ini version] puts "Ini:Test2: Success: Ini version: $ver" if { $ver < "0.6.0.1" } { puts "Ini:Test2: Error: Version loaded seems to be lower than version expected!" } # Now test the ini puts "Ini:Test3: Get a non-existent ini" if [ catch { ini get -private test.ini -section test1 -default "***Failure default***" } err ] { puts "Ini:Test3: Error: ini get -private test.ini -section test1 failed\n$err\n" } else { puts "Ini:Test3: Success: Initial ini get -private test.ini -section test1 returned\n\t$err, the specified default" } # Now, create the entry puts "Ini:Test4: Set a non-existent ini" if [ catch { ini set -private test.ini -section test1 -key albert -value osaurus } err ] { puts "Ini:Test4: Error in setting albert/osaurus\n$err" } else { set retval [ ini get -private test.ini -section test1 -key albert ] if { $retval == "osaurus" } { puts "Ini:Test4: Succeeded in setting albert/osaurus" } else { puts "Ini:Test4: Error: Got :$retval: instead of :osaurus:" } } puts "Ini:Test5: Set another non-existent ini" if [ catch { ini set -private test.ini -section test1 -key diplo -value docus } err ] { puts "Ini:Test5: Error in setting diplo/docus" } else { set retval [ini get -private test.ini -section test1 -key diplo] if { $retval == "docus" } { puts "Ini:Test5: Succeeded in setting diplo/docus" } else { puts "Ini:Test5: Error: Got :$retval: instead of :docus:" } } puts "Ini:Test6: Delete an existing ini key" ini delete -private test.ini -section test1 -key diplo set retval [ini get -private test.ini -section test1 -key diplo -default "*****"] if { $retval != "*****" } { puts "Ini:Test6: Failed in deletion of key diplo" } else { puts "Ini:Test6: Succeeded in deletion of key diplo" } puts "Ini:Test7: Delete an existing ini section" # Now delete the whole section ini delete -private test.ini -section test1 set retval [ini get -private test.ini -section test1 -key albert -default "*****"] if { $retval != "*****" } { puts "Ini:Test7: Failed in deletion of section test1" } else { puts "Ini:Test7: Succeeded in deletion of section test1" } # This test only works under Win95 and WinNT if [info exists tcl_platform(os) ] { if { $tcl_platform(os) == "Win32s" } { puts "Ini:Test8: Skipped since this requires Win95 or WinNT" } else { # Add some entries to the test ini ini set -private test.ini -section test1 -key diplo -value docus ini set -private test.ini -section test2 -key bronto -value saurus ini set -private test.ini -section test2 -key allo -value saurus ini set -private test.ini -section test2 -key tyranno -value "saurus rex" # Get the list of sections in a ini set retval [ini get -private test.ini] if { [llength $retval] == 2 } { puts "Ini:Test8: Succeeded in getting list of sections" } else { puts "Ini:Test8: Error in getting list of sections" } # Clean up ini delete -private test.ini -section test1 ini delete -private test.ini -section test2 } } else { puts "Ini:Test8: Skipped since tcl_platform(os) does not exist" }