# gorilla.test:  tests for the Password Gorilla application
#
# This file contains a collection of tests for the password manager
# Password Gorilla.  
#
# To make the test type "gorilla.tcl --test". A help menuitem
# "Gorillatest" will be created which will perform the test after
# having been clicked.
#
# Note: Only test failures will be reported
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.	See the
# GNU General Public License for more details.

# -------------------------------------------------------------------------

package require tcltest 2.2
set argv ""
eval ::tcltest::configure $argv

# puts "running tests for Password Gorilla ..."

# ------------- samples -----------------

# old form:
# proc TestProcedure {} { return chimpanzee }
# test gorilla-0.1 {initial test} { TestProcedure } gorilla

# new form:
# test gorilla-0.2 {initial test} \
	# -setup { proc TestProcedure {} { return goat } } \
	# -body {TestProcedure} \
	# -result {gorilla} \
	# -cleanup {rename TestProcedure ""}
	
# create a safe environment for testing purposes

namespace eval ::gorilla::test {
	namespace import ::tcltest::*
	
	# CATEGORY: Security
	# ------------------
	
	# module is expected to run with option --test or --tcltest
	# FIXME: Mac menu handling

	# test will show if windows are withdrawn and opened
	test lock-database-1.1 { general lock-unlock-run } \
		-setup {} \
		-body {
			gorilla::LockDatabase
		} \
		-result GORILLA_OK
	
	# test gorilla-1.3 {MacOSX Preferences menuitem disabled} \
		# -constraints mac \
		# -body { info commands ::tk::mac::ShowPreferences }
		# -result ""
		# 
	# test gorilla-1.4 {MacOSX About menuitem disabled} \
		# -constraints mac \
		# -body {	return [.mbar.apple entryconfigure 0 -state] } \
		# -result disabled
		# 
	# test gorilla-1.5 {MacOSX menuitems disabled} \
		# -constraints mac \
		# -setup {set widget .mbar}
		# -body {
			# foreach {menu_name menu_widget menu_itemlist} $::gorilla::menu_desc {
				# set index 0
				# foreach {title a b c d } $menu_itemlist {
					# if { $title ne "separator" } {
						# if { [$widget.$menu_widget entryconfigure $index -state] ne "disabled" } {
							# return ERROR
						# }
					# }
					# incr index
				# }
			# }
			# return OK
		# } \
		# -result OK
		# 
	
} ;# end of namespace eval ::gorilla::test


# ----------------------------------------------------------------------
# cleanup

namespace delete ::gorilla::test
# puts "Tests for unit Password Gorilla finished."
