# -------------------------------------------------------
# File: "SetmeCmd.test"
#                        Created: 2004-09-07 15:43:09
#              Last modification: 2009-03-04 09:15:51
# Author: Bernard Desgraupes
# e-mail: <bdesgraupes@users.sourceforge.net.fr>
# www: <http://tcladdressbook.sourceforge.net>
# (c) Copyright: Bernard Desgraupes, 2004-2009
# All rights reserved.
# This software is free software with BSD licence.
# Versions history: see the Changes.Log file.
# 
# Test suite for the Tcl [addressbook setme] command defined 
# in the Tcladdressbook extension.
# 
# -------------------------------------------------------

source [file join [file dir [info script]] TclABCommonTests.tcl]

namespace eval ::addressbook::test {
	namespace import ::tcltest::*

	test AddressbookSetme-1-1 {Set another Me record} -setup {
	} -body {
		set PersonName "TclABSetmeTestPerson[incr PersonNum]"
		set PersonID [addressbook create person $PersonName]
		set SaveID [addressbook getme -id]
		addressbook setme $PersonID
		set MeID [addressbook getme -id]
		set result [expr {$MeID eq $PersonID}]
		addressbook setme $SaveID
		return $result
	} -cleanup {
	} -result "1"
		
	test AddressbookSetme-1-2 {Check name in other ME record} -setup {
	} -body {
		set PersonName "TclABSetmeTestPerson[incr PersonNum]"
		set PersonID [addressbook create person $PersonName]
		set SaveID [addressbook getme -id]
		addressbook setme $PersonID
		set rec [addressbook getme]
		set LastName [keylget rec Last]
		set result [expr {$LastName eq $PersonName}]
		addressbook setme $SaveID
		return $result
	} -cleanup {
	} -result "1"
		
		
	# Usage string
	# ============
	test AddressbookSetme-2-1 {Usage string for wrong num args} -setup {
	} -body {
		addressbook setme
	} -cleanup {
	} -returnCodes error \
	  -result "wrong # args: should be \"addressbook setme recordID\""

	# Cleanup
	::tcltest::cleanupTests
}

namespace delete ::addressbook::test

