# -------------------------------------------------------
# File: "ExportCmd.test"
#                        Created: 2004-09-07 15:43:09
#              Last modification: 2009-03-05 10:06:58
# 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 export] command defined 
# in the Tcladdressbook extension.
# 
# -------------------------------------------------------

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

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

	test AddressbookExport-1-1 {Export a person's record} -setup {
	} -body {
		set PersonName "TclABExportTestPerson[incr PersonNum]"
		set PersonID [addressbook create person $PersonName]
		return [addressbook export $PersonID]
	} -cleanup {
	} -match glob -result "BEGIN:VCARD*END:VCARD*"
		
	test AddressbookExport-1-2 {Check exported person's name} -setup {
	} -body {
		set PersonName "TclABExportTestPerson[incr PersonNum]"
		set PersonID [addressbook create person $PersonName]
		set vcard [addressbook export $PersonID]
		# Check the name
		return [regexp "N:$PersonName" $vcard]
	} -cleanup {
	} -result "1"
		
	test AddressbookExport-1-3 {Check exported person's UID} -setup {
	} -body {
		set PersonName "TclABExportTestPerson[incr PersonNum]"
		set PersonID [addressbook create person $PersonName]
		set vcard [addressbook export $PersonID]
		# Check the UID
		regsub ":" $PersonID {\\\\:} uid
		return [regexp "X-ABUID:$uid" $vcard]
	} -cleanup {
	} -result "1"
		
	test AddressbookExport-1-4 {Check exported person's birthday} -setup {
	} -body {
		set PersonName "TclABExportTestPerson[incr PersonNum]"
		set PersonID [addressbook create person $PersonName]
		# Set birthday to 1st January 2000
		addressbook set $PersonID Birthday 946728000
		set vcard [addressbook export $PersonID]
		# Check the name
		return [regexp "BDAY;value=date:2000-01-01" $vcard]
	} -cleanup {
	} -result "1"
		
	# Usage string
	# ============
	test AddressbookExport-2-1 {Usage string for wrong num args} -setup {
	} -body {
		addressbook export
	} -cleanup {
	} -returnCodes error \
	  -result "wrong # args: should be \"addressbook export personID\""

	# Cleanup
	::tcltest::cleanupTests
}

namespace delete ::addressbook::test

