# This file is a tcltest script to test drawing FTI icons.
# It covers the following functionalities:
# 1. Draw icons of type polygon into a canvas.
# 2. Draw icons of type outlinepolygon into a canvas.
# 3. Draw icons of type point into a canvas.

set scriptDir [file normalize [file join [file dirname [info script]] ".."]]
set auto_path [linsert $auto_path 0 $scriptDir]

package require Tk
package require poFti

package require tcltest
tcltest::configure {*}$argv
source [file join [file dirname [info script]] constraints.tcl]

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

    set vtxListIcon         [list 10.0 10.0 20.0 10.0 20.0 20.0]
    set vtxListCanvas       [list 10.0 90.0 20.0 90.0 20.0 80.0]
    set vtxListCanvasScaled [list 20.0 180.0 40.0 180.0 40.0 160.0]

    #
    # Test-Suite 1: Draw polygons into a canvas.
    #
    test draw-1.1 "Draw Icon of type polygon using default values" -setup {
        set iconObj [poFti Icon new]
        set itemObj [poFti Item new "Item-Polygon" "polygon"]
        $iconObj AddItem $itemObj
        $itemObj AddVertices {*}$vtxListIcon
        set canvasId [canvas .c -width 100 -height 100]
    } -body {
        $iconObj Draw $canvasId
        set itemList [$canvasId find withtag "FtiIcon"]
        set itemId [lindex $itemList 0]
        set res1 [llength $itemList]
        set res2 [$canvasId gettags $itemId]
        set res3 [$canvasId coords $itemId]
        list $res1 {*}$res2 {*}$res3
    } -cleanup {
        $iconObj destroy
        destroy $canvasId
    } -result [list 1 "FtiIcon" "FtiIcon" "Item-Polygon" "polygon" 0 {*}$vtxListCanvas]

    test draw-1.2 "Draw Icon of type polygon using scaling and user tag" -setup {
        set iconObj [poFti Icon new]
        set itemObj [poFti Item new "Item-Polygon" "polygon"]
        $iconObj AddItem $itemObj
        $itemObj AddVertices {*}$vtxListIcon
        set canvasId [canvas .c -width 200 -height 200]
    } -body {
        $iconObj Draw $canvasId -tag "UserTag"
        set itemList [$canvasId find withtag "FtiIcon"]
        set itemId [lindex $itemList 0]
        set res1 [llength $itemList]
        set res2 [$canvasId gettags $itemId]
        set res3 [$canvasId coords $itemId]
        list $res1 {*}$res2 {*}$res3
    } -cleanup {
        $iconObj destroy
        destroy $canvasId
    } -result [list 1 "FtiIcon" "UserTag" "Item-Polygon" "polygon" 0 {*}$vtxListCanvasScaled]

    #
    # Test-Suite 2: Draw outline polygons into a canvas.
    #

    test draw-2.1 "Draw Icon of type outlinepolygon using special colors" -setup {
        set iconObj [poFti Icon new]
        set itemObj [poFti Item new "Item-Polygon" "outlinepolygon"]
        $itemObj SetColor "iconcolor"
        $itemObj SetOutlineColor "outlinecolor"
        $iconObj AddItem $itemObj
        $itemObj AddVertices {*}$vtxListIcon
        set canvasId [canvas .c -width 200 -height 200]
    } -body {
        $iconObj Draw $canvasId -tag "UserTag"
        set itemList [$canvasId find withtag "FtiIcon"]
        set itemId [lindex $itemList 0]
        set res1 [llength $itemList]
        set res2 [$canvasId gettags $itemId]
        set res3 [$canvasId coords $itemId]
        list $res1 {*}$res2 {*}$res3
    } -cleanup {
        $iconObj destroy
        destroy $canvasId
    } -result [list 1 "FtiIcon" "UserTag" "Item-Polygon" "outlinepolygon" "iconcolor" "outlinecolor" {*}$vtxListCanvasScaled]

    #
    # Test-Suite 3: Draw points into a canvas.
    #

    test draw-3.1 "Draw Icon of type point using default values" -setup {
        set iconObj [poFti Icon new]
        set itemObj [poFti Item new "Item-Point" "point"]
        $itemObj SetColor 2
        $iconObj AddItem $itemObj
        $itemObj AddVertices 10.0 10.0
        set canvasId [canvas .c -width 100 -height 100]
    } -body {
        $iconObj Draw $canvasId
        set itemList [$canvasId find withtag "FtiIcon"]
        set itemId [lindex $itemList 0]
        set res1 [llength $itemList]
        set res2 [$canvasId gettags $itemId]
        list $res1 {*}$res2
    } -cleanup {
        $iconObj destroy
        destroy $canvasId
    } -result [list 1 "FtiIcon" "FtiIcon" "Item-Point" "point" 2]
}

tcltest::cleanupTests
namespace delete ::draw::test
