#
# imgtools.test --
#
#    Unit tests for imgtools.c
#
# Copyright (c) 2016-2017 by Simon Bachmann <simonbachmann@bluewin.ch>
# All rights reserved.
#
# Permission is hereby granted, without written agreement and without
# license or royalty fees, to use, copy, modify, and distribute this
# software and its documentation for any purpose, provided that the
# above copyright notice and the following two paragraphs appear in
# all copies of this software.
# 

package require tcltest 2.3

eval ::tcltest::configure $argv

namespace eval ::imgtools::test::imgtools {
    namespace import ::tcltest::*
    namespace import ::imgtools::test::*
    variable setup {
        set testImg1 [file join [file normalize [workingDirectory]] smiley.png]
        set blue [file join [file normalize [workingDirectory]] blue.png]
        set red [file join [file normalize [workingDirectory]] red.png]
        set rot0 [file join [file normalize [workingDirectory]] drawing.png]
        set gradVert [file join [file normalize [workingDirectory]] gradientVertical.png]
        set gradHoriz [file join [file normalize [workingDirectory]] gradientHorizontal.png]
        set gradCol [file join [file normalize [workingDirectory]] gradientColor.png]
        set photo [file join [file normalize [workingDirectory]] photo.png]
        image create photo smiley -file $testImg1
        image create photo emptyImg
        image create photo emptyImg2
        image create photo emptyImg3
        image create photo destImg
        image create photo blueImg -file $blue
        image create photo redImg -file $red
        image create photo rotated0 -file $rot0                 ;# 39x22
        # vertical, black to white, 256x256:
        image create photo gradientVertical -file $gradVert
        # horizontal, black to white, 256x256:
        image create photo gradientHorizontal -file $gradHoriz
        # vertical, #11AA77 to #FF2277
        image create photo gradientColor -file $gradCol
        image create photo photo -file $photo                   ;# 100x75
    }
    variable cleanup {
        image delete smiley
        image delete destImg
        image delete emptyImg emptyImg2 emptyImg3
        image delete blueImg redImg
        image delete rotated0
        image delete gradientVertical gradientHorizontal gradientColor
        image delete photo
    }
    
    #
    # ### Imgtools_Gradient ###
    #
     
    #
    # arguments and options
    #
    test gradient-1.0 {No fromColor} -setup $setup -body {
        ::imgtools::gradient
    } -cleanup $cleanup -returnCodes error -match glob -result {wrong # args: should be "* fromColor toColor ?options? destImg"}
    
    test gradient-1.1 {No toColor} -setup $setup -body {
        ::imgtools::gradient black
    } -cleanup $cleanup -returnCodes error -match glob -result {wrong # args: should be "* fromColor toColor ?options? destImg"}
    
    test gradient-1.2 {no destImg} -setup $setup -body {
        ::imgtools::gradient red green
    } -cleanup $cleanup -returnCodes error -match glob -result {wrong # args: should be "* fromColor toColor ?options? destImg"}
    
    test gradient-1.3 {dest image does not exist} -setup $setup -body {
        ::imgtools::gradient yellow black invalid
    } -cleanup $cleanup -returnCodes error -result {image "invalid" not found}
    
    test gradient-1.4 {invalid fromColor} -setup $setup -body {
        ::imgtools::gradient invalid magenta destImg
    } -cleanup $cleanup -returnCodes error -result {unknown color name "invalid"}
    
    test gradient-1.5 {invalid toColor} -setup $setup -body {
        ::imgtools::gradient cyan invalid destImg
    } -cleanup $cleanup -returnCodes error -result {unknown color name "invalid"}
    
    test gradient-1.6 {existing, but not accepted common opt: -alpha} -setup $setup -body {
        ::imgtools::gradient #001122 orange -alpha 1 destImg
    } -cleanup $cleanup -returnCodes error -result {bad option "-alpha": must be -compositingrule, -shrink, -to or -orient}
    
    test gradient-1.7 {existing, but not accepted common opt: -background} -setup $setup -body {
        ::imgtools::gradient #445566 #778899 -background blue destImg
    } -cleanup $cleanup -returnCodes error -result {bad option "-background": must be -compositingrule, -shrink, -to or -orient}
    
    test gradient-1.7.1 {existing, but not accepted common opt: -from} -setup $setup -body {
        ::imgtools::gradient red green -from 3 2 4 5 destImg
    } -cleanup $cleanup -returnCodes error -result {bad option "-from": must be -compositingrule, -shrink, -to or -orient}
    
    test gradient-1.8 {existing, but not accepted common opt: -interpolation} -setup $setup -body {
        ::imgtools::gradient "light green" #123456 -interpolation nearest destImg
    } -cleanup $cleanup -returnCodes error -result {bad option "-interpolation": must be -compositingrule, -shrink, -to or -orient}
    
    test gradient-1.9 {non existing option} -setup $setup -body {
        ::imgtools::gradient yellow yellow -invalid destImg
    } -cleanup $cleanup -returnCodes error -result {bad option "-invalid": must be -compositingrule, -shrink, -to or -orient}
    
    test gradient-1.10 {accepted common opts} -setup $setup -body {
        ::imgtools::gradient blue blue -compositingrule set -shrink -to 0 0 15 15 -orient horizontal destImg
    } -cleanup $cleanup -returnCodes ok -result {destImg}
    
    #
    # Functionality
    #
    test gradient-2.0 {empty dest image} -setup $setup -body {
        ::imgtools::gradient red green destImg
        compareImages destImg emptyImg
    } -cleanup $cleanup -returnCodes ok -result {1}
    
    test gradient-2.1 {vertical gradient} -setup $setup -body {
        ::imgtools::gradient black white -to 0 0 256 256 destImg
        compareImages destImg gradientVertical
    } -cleanup $cleanup -returnCodes ok -result {1}
    
    test gradient-2.2 {horizontal gradient} -setup $setup -body {
        ::imgtools::gradient black white -orient horizontal -to 0 0 256 256 destImg
        compareImages destImg gradientHorizontal
    } -cleanup $cleanup -returnCodes ok -result {1}
    
    test gradient-2.3 {unicolor gradient} -setup $setup -body {
        ::imgtools::gradient blue blue -to 0 0 15 destImg
        compareImages destImg blueImg
    } -cleanup $cleanup -returnCodes ok -result {1}
    
    test gradient-2.4 {multicolor/direction gradient} -setup $setup -body {
        ::imgtools::gradient #11AA77 #FF2277 -to 0 0 15 15 destImg
        compareImages destImg gradientColor
    } -cleanup $cleanup -returnCodes ok -result {1}
    
    #
    # Sizes
    #
    test gradient-3.0 {zero sized gradient} -setup $setup -body {
        emptyImg copy smiley
        ::imgtools::gradient brown "dark red" -to 2 3 2 3 smiley
        compareImages smiley emptyImg
    } -cleanup $cleanup -returnCodes ok -result {1}
    
    test gradient-3.1 {no -to option} -setup $setup -body {
        ::imgtools::gradient #11AA77 #FF2277 smiley
        compareImages smiley gradientColor
    } -cleanup $cleanup -returnCodes ok -result {1}
    
    test gradient-3.2 {-to smaller than image} -setup $setup -body {
        emptyImg copy rotated0
        ::imgtools::gradient #11AA77 #FF2277 -to 0 0 15 15 emptyImg
        emptyImg2 copy emptyImg -from 0 0 15 15
        emptyImg3 copy emptyImg -from 15 0 39 22
        destImg copy rotated0 -from 15 0 39 22
        list [compareImages emptyImg2 gradientColor] [compareImages emptyImg3 destImg]
    } -cleanup $cleanup -returnCodes ok -result {1 1}
    
    test gradient-3.3 {region larger than image} -setup $setup -body {
        ::imgtools::gradient black white -to 0 0 256 256 rotated0
        compareImages rotated0 gradientVertical
    } -cleanup $cleanup -returnCodes ok -result {1} 
    
    test gradient-3.4 {region completely outside image} -setup $setup -body {
        destImg copy rotated0
        ::imgtools::gradient black white -orient horizontal -to 39 0 295 256 destImg
        emptyImg copy destImg -from 39 0 295 256
        emptyImg2 copy destImg -from 0 0 39 22
        list [compareImages emptyImg gradientHorizontal] [compareImages emptyImg2 rotated0]
    } -cleanup $cleanup -returnCodes ok -result {1 1}
    
    test gradient-3.5 {region larger than image, user-spec sizes} -setup $setup -body {
        destImg configure -width 24 -height 33
        ::imgtools::gradient black white -to 0 0 256 256 destImg
        list [image width destImg] [image height destImg]
    } -cleanup $cleanup -returnCodes ok -result {24 33}
    
    test gradient-3.6 {size with only two coordinates for -to, I} -setup $setup -body {
        ::imgtools::gradient #11AA77 #FF2277 -to 0 0 smiley
        compareImages smiley gradientColor
    } -cleanup $cleanup -returnCodes ok -result {1}
    
    test gradient-3.7 {size with only two coordinates for -to, II} -setup $setup -body {
        ::imgtools::gradient yellow #33525F -to 5 9 photo
        list [image width photo] [image height photo]
    } -cleanup $cleanup -returnCodes ok -result {100 75}
    
    test gradient-3.8 {result} -setup $setup -body {
        ::imgtools::gradient cyan magenta gradientVertical
    } -cleanup $cleanup -returnCodes ok -result {gradientVertical}
    
    #
    # ### Imgtools_PutImage ###
    #
    
    #
    # -shrink option
    #
    test putimage-1.0 {No -shrink option, -width and -height 0, size of destImg smaller than scaled data} -setup $setup -body {
        ::imgtools::scale smiley 60% destImg
        expr {[image width destImg] == 9 && [image height destImg] == 9}
    } -cleanup $cleanup -returnCodes ok -result {1}
    
    test putimage-1.1 {No -shrink option, -width and -height 0, size of destImg larger than scaled data} -setup $setup -body {
        destImg copy smiley
        ::imgtools::scale smiley 10% destImg
        expr {[image width destImg] == [image width smiley] && [image height destImg] == [image width smiley]}
    } -cleanup $cleanup -returnCodes ok -result {1}
        
    test putimage-1.2 {No -shrink option, -width and -heigth of destimage larger than scaled data} -setup $setup -body {
        destImg configure -width 100 -height 100
        ::imgtools::scale smiley 100% destImg
        expr {[image width destImg] == 100 && [image height destImg] == 100}
    } -cleanup $cleanup -returnCodes ok -result {1}
    
    test putimage-1.3 {No -shrink option, -width and -heigth of destimage smaller than scaled data} -setup $setup -body {
        destImg configure -width 10 -height 10
        ::imgtools::scale smiley 200% destImg
        expr {[image width destImg] == 10 && [image height destImg] == 10}
    } -cleanup $cleanup -returnCodes ok -result {1}
    
    test putimage-1.4 {-shrink option, -width and -height 0, size of destImg smaller than scaled data} -setup $setup -body {
        ::imgtools::scale smiley 33% -shrink destImg
        expr {[image width destImg] == 5 && [image height destImg] == 5}
    } -cleanup $cleanup -returnCodes ok -result {1}
    
    test putimage-1.5 {-shrink option, -width and -height 0, size of destImg larger than scaled data} -setup $setup -body {
        destImg copy smiley
        ::imgtools::scale smiley 33% -shrink destImg
        expr {[image width destImg] == 5 && [image height destImg] == 5}
    } -cleanup $cleanup -returnCodes ok -result {1}
    
    test putimage-1.6.0 {-shrink option, -width 0, -height larger than scaled data} -setup $setup -body {
        destImg copy smiley
        destImg configure -height [image height smiley]
        ::imgtools::scale smiley 33% -shrink destImg
        expr {[image width destImg] == 5 && [image height destImg] == [image height smiley]}
    } -cleanup $cleanup -returnCodes ok -result {1}
    
    test putimage-1.6.1 {-shrink option, -height 0, -width larger than scaled data} -setup $setup -body {
        destImg copy smiley
        destImg configure -width [image width smiley]
        ::imgtools::scale smiley 33% -shrink destImg
        expr {[image width destImg] == [image width smiley] && [image height destImg] == 5}
    } -cleanup $cleanup -returnCodes ok -result {1}
    
    test putimage-1.6.2 {-shrink option, -width and -height of destimage larger than scaled data} -setup $setup -body {
        destImg configure -width 100 -height 100
        ::imgtools::scale smiley 66% -shrink destImg
        expr {[image width destImg] == 100 && [image height destImg] == 100}
    } -cleanup $cleanup -returnCodes ok -result {1}
    
    test putimage-1.7 {-shrink option, -width and -height of destimage smaller than scaled data} -setup $setup -body {
        destImg configure -width 10 -height 10
        ::imgtools::scale smiley 200% -shrink destImg
        expr {[image width destImg] == 10 && [image height destImg] == 10}
    } -cleanup $cleanup -returnCodes ok -result {1}
    
    #
    # -compositingrule option
    #
    test putimage-2.0 {Empty destImg: set and overlay give the same result} -setup $setup -body {
        ::imgtools::scale smiley 144% -compositingrule set destImg
        ::imgtools::scale smiley 144% -compositingrule overlay emptyImg
        compareImages destImg emptyImg
    } -cleanup $cleanup -returnCodes ok -result {1}
    
    test putimage-2.1 {destImg not emty, composite set} -setup $setup -body {
        ::imgtools::scale smiley 100% -compositingrule set blueImg
        compareImages smiley blueImg
    } -cleanup $cleanup -returnCodes ok -result {1}
    
    test putimage-2.2 {destImg not empty, composite overlay} -setup $setup -body {
        ::imgtools::scale smiley 100% -compositingrule overlay blueImg
        set pixel [blueImg get 6 6]
        expr {[lindex $pixel 0] == 197 && [lindex $pixel 1] == 197 && [lindex $pixel 2] == 58}
    } -cleanup $cleanup -returnCodes ok -result {1}
    
    test putimage-2.3 {No composite option: same result as with overlay} -setup $setup -body {
        destImg copy blueImg
        ::imgtools::scale smiley 100% -compositingrule overlay blueImg
        ::imgtools::scale smiley 100% destImg
        compareImages blueImg destImg
    } -cleanup $cleanup -returnCodes ok -result {1}
    
    #
    # Other stuff
    #
    test putimage-3.1 {source and dest image are the same, scale} -setup $setup -body {
        ::imgtools::scale smiley 150%x50% -shrink smiley
        list [image width smiley] [image height smiley]
    } -cleanup $cleanup -returnCodes ok -result {23 8}
    
    test putimage-3.2 {source and dest image are the same, rotate} -setup $setup -body {
        ::imgtools::rotate smiley -45 smiley
        list [image width smiley] [image height smiley]
    } -cleanup $cleanup -returnCodes ok -result {21 21}
    
    test putimage-3.3 {source and dest image are the same, transparency} -setup $setup -body {
        ::imgtools::transparency set smiley .5 smiley
        list [image width smiley] [image height smiley]
    } -cleanup $cleanup -returnCodes ok -result {15 15}
    
    #
    # Effects of the -to option
    #
    test putimage-4.1 {-to option matches pos and size of processed src} -setup $setup -body {
        set results {}
        ::imgtools::scale photo 20x20 destImg
        
        ::imgtools::scale photo 20x20 -to 0 -shrink -compositingrule set emptyImg
        lappend results [compareImages emptyImg destImg]
        ::imgtools::scale photo 20x20 -to 0 0 -shrink -compositingrule set emptyImg
        lappend results [compareImages emptyImg destImg]
        ::imgtools::scale photo 20x20 -to 0 0 20 -shrink -compositingrule set emptyImg
        lappend results [compareImages emptyImg destImg]
        ::imgtools::scale photo 20x20 -to 0 0 20 20 -shrink -compositingrule set emptyImg
        lappend results [compareImages emptyImg destImg]
        
        set results
    } -cleanup $cleanup -returnCodes ok -result {1 1 1 1}
    
    test putimage-4.2 {-to region is smaller than data in both directions } -setup $setup -body {
        ::imgtools::scale photo 150x50 emptyImg
        destImg copy emptyImg -to 11 21 200 100
        ::imgtools::scale photo 150x50 -to 11 21 23 69 emptyImg2
        emptyImg3 copy destImg -from 0 0 23 69
        compareImages emptyImg3 emptyImg2
    } -cleanup $cleanup -returnCodes ok -result {1}
        
    test putimage-4.3 {-to region: x smaller, y larger } -setup $setup -body {
        ::imgtools::scale photo 150x50 emptyImg
        destImg copy emptyImg -to 11 21 200 100         
        ::imgtools::scale photo 150x50 -to 11 21 50 100 emptyImg2
        emptyImg3 copy destImg -from 0 0 50 100
        compareImages emptyImg2 emptyImg3
    } -cleanup $cleanup -returnCodes ok -result {1}
    
    test putimage-4.4 {-to region: x larger, y smaller } -setup $setup -body {
        ::imgtools::scale photo 150x50 emptyImg
        destImg copy emptyImg -to 11 21 200 100         
        ::imgtools::scale photo 150x50 -to 11 21 199 69 emptyImg2
        emptyImg3 copy destImg -from 0 0 199 69
        compareImages emptyImg2 emptyImg3
    } -cleanup $cleanup -returnCodes ok -result {1}
    
    test putimage-4.5 {-to region: both directions larger than data } -setup $setup -body {
        ::imgtools::scale photo 150x50 emptyImg
        destImg copy emptyImg -to 11 21 200 100         
        ::imgtools::scale photo 150x50 -to 11 21 200 100 emptyImg2
        emptyImg3 copy destImg -from 0 0 200 100
        compareImages emptyImg2 emptyImg3
    } -cleanup $cleanup -returnCodes ok -result {1}
        
    
    #
    # ### Imgtools_GetImage ###
    #
    # the error condition cannot be tested
    # otherwise, there's nothing to test really
    
    #
    # ### Imgtools_ApplySubregion ###
    #
    test applysubregion-1.1 {corners outside image} -setup $setup -body {
        ::imgtools::scale smiley 200% -from 0 1 100 10 destImg
    } -cleanup $cleanup -returnCodes error -result {coordinates extend outside image}
    
    test applysubregion-2.1 {test normal operation, scale} -setup $setup -body {
        emptyImg copy rotated0 -from 5 6 10 11
        ::imgtools::scale emptyImg 123% emptyImg2
        ::imgtools::scale rotated0 123% -from 10 11 5 6 destImg
        compareImages destImg emptyImg2
    } -cleanup $cleanup -returnCodes ok -result {1}
    
    test applysubregion-2.2 {normal operation, rotate} -setup $setup -body {
        emptyImg copy smiley -from 1 1 14 14
        ::imgtools::rotate emptyImg 9° emptyImg2
        ::imgtools::rotate smiley 9° -from 1 1 14 14 destImg
        compareImages destImg emptyImg2
    } -cleanup $cleanup -returnCodes ok -result {1}
    
    test applysubregion-2.3 {normal operation, transparency modify} -setup $setup -body {
        emptyImg copy photo -from 0 1 99 75
        ::imgtools::transparency set emptyImg .01 emptyImg2
        ::imgtools::transparency set photo .01 -from 0 1 99 75 destImg
        compareImages destImg emptyImg2
    } -cleanup $cleanup -returnCodes ok -result {1}
    
    test applysubregion-2.4 {normal operation, transparency mask} -setup $setup -body {
        emptyImg copy photo -from 22 22 23 23
        ::imgtools::transparency mask emptyImg rotated0 emptyImg2
        ::imgtools::transparency mask photo rotated0 -from 22 22 23 23 destImg
        compareImages destImg emptyImg2
    } -cleanup $cleanup -returnCodes ok -result {1}
    
    #
    # ### Imgtools_FreeImage ###
    #
    # We can't really thest this one with tcltest
    #
    
    #
    # ### Imgtools_NormalizeImage
    #
    # Not used (yet), so we can't test it
    
    # 
    # ### Imgtools_ParseCommonOpts ###
    #
    
    #
    # gereral
    #
    test parsecommonopts-1.0 {test default: -composite} -setup $setup -body {
        destImg copy rotated0
        ::imgtools::scale smiley 100% rotated0
        ::imgtools::scale smiley 100% -compositingrule overlay destImg
        compareImages rotated0 destImg
    } -cleanup $cleanup -returnCodes ok -result {1}
    
    test parsecommonopts-1.1 {test defaults: -shrink} -setup $setup -body {
        ::imgtools::scale smiley 100% rotated0
        list [image width rotated0] [image height rotated0]
    } -cleanup $cleanup -returnCodes ok -result {39 22}
    
    test parsecommonopts-1.2 {test defaults: -interpolation} -setup $setup -body {
        ::imgtools::scale smiley 333% destImg
        ::imgtools::scale smiley 333% -interpolation catrom emptyImg
        compareImages destImg emptyImg
    } -cleanup $cleanup -returnCodes ok -result {1}
    
    test parsecommonopts-1.3 {defaults: -background and -alpha} -setup $setup -body {
        ::imgtools::rotate smiley 43 destImg
        getPixel destImg 0 0
    } -cleanup $cleanup -returnCodes ok -result {0 0 0 0}
    
    test parsecommonopts-1.4 {defaults: -to} -setup $setup -body {
        ::imgtools::transparency set smiley 1 destImg
        ::imgtools::transparency set smiley 1 -to 0 0 15 15 emptyImg
        compareImages destImg emptyImg
    } -cleanup $cleanup -returnCodes ok -result {1}
    
    test parsecommonopts-1.7 {defaults: -orient} -setup $setup -body {
        ::imgtools::gradient black white -to 0 0 256 256 destImg
        compareImages destImg gradientVertical
    } -cleanup $cleanup -returnCodes ok -result {1}
    
    test parsecommonopts-1.8 {defaults: -from} -setup $setup -body {
        ::imgtools::scale rotated0 99% destImg
        ::imgtools::scale rotated0 99% -from 0 0 39 22 emptyImg
        compareImages destImg emptyImg
    } -cleanup $cleanup -returnCodes ok -result {1}
    
    test parsecommonopts-1.9 {defaults: -clipping} -setup $setup -body {
        ::imgtools::rotate photo -5° destImg
        ::imgtools::rotate photo -5° -clipping none emptyImg
        compareImages destImg emptyImg
    } -cleanup $cleanup -returnCodes ok -result {1}
    
    test parsecommonopts-1.5 {nonexisting option} -setup $setup -body {
        ::imgtools::rotate smiley 10 -invalid 4 destImg
    } -cleanup $cleanup -returnCodes error -match glob -result {bad option "-invalid": must be -compositingrule, -shrink, -interpolation, -background, -alpha, -from, -to*-clipping*}
    
    test parsecommonopts-1.6 {existing option, but not allowed with command} -setup $setup -body {
        ::imgtools::scale smiley 16 -background yellow destImg
    } -cleanup $cleanup -returnCodes error -match glob -result {bad option "-background": must be -compositingrule, -shrink, -interpolation, -from*-to*}
    
    #
    # -compositingrule
    #
    test parsecommonopts-2.1 {missing value} -setup $setup -body {
        ::imgtools::transparency increase smiley .6 -compositingrule destImg
    } -cleanup $cleanup -returnCodes error -result {option "-compositingrule" requires an argument}
    
    test parsecommonopts-2.2 {value: overlay} -setup $setup -body {
        # just check if the value is accepted. 
        # Functionality is checked with putimage-2.* tests
        ::imgtools::rotate smiley -1 -compositingrule overlay destImg
    } -cleanup $cleanup -returnCodes ok -result {destImg}
    
    test parsecommonopts-2.3 {value: set} -setup $setup -body {
        # just check if the value is accepted. 
        # Functionality is checked with putimage-2.* tests
        ::imgtools::rotate smiley -1 -compositingrule set destImg
    } -cleanup $cleanup -returnCodes ok -result {destImg}
    
    test parsecommonopts-2.4 {value: invalid} -setup $setup -body {
        ::imgtools::scale smiley 12 -compositingrule invalid destImg
    } -cleanup $cleanup -returnCodes error -result {compositing rule must be one of "overlay" or "set"}
    
    #
    # -shrink
    #
    test parsecommonopts-3.0 {option accepted?} -setup $setup -body {
        # Functionalitiy is checked with putiage tests
        ::imgtools::scale smiley 20x25 -shrink rotated0
        list [image width rotated0] [image height rotated0]
    } -cleanup $cleanup -returnCodes ok -result {20 25}
    
    #
    # -interpolation
    #
    test parsecommonopts-4.0 {missing value} -setup $setup -body {
        ::imgtools::rotate smiley 180 -interpolation destImg
    } -cleanup $cleanup -returnCodes error -result {option "-interpolation" requires an argument}
    
    test parsecommonopts-4.1 {value: nearest} -setup $setup -body {
        ::imgtools::scale smiley 61 -interpolation nearest destImg
    } -cleanup $cleanup -returnCodes ok -result {destImg}
    
    test parsecommonopts-4.2 {value: linear} -setup $setup -body {
        ::imgtools::rotate smiley -123 -interpolation linear -shrink destImg 
    } -cleanup $cleanup -returnCodes ok -result {destImg}
    
    test parsecommonopts-4.3 {value: catrom} -setup $setup -body {
        ::imgtools::scale smiley 100% -compositingrule set -interpolation catrom -shrink destImg
    } -cleanup $cleanup -returnCodes ok -result {destImg}
    
    test parsecommonopts-4.4 {value: invalid} -setup $setup -body {
        ::imgtools::rotate rotated0 55 -shrink -interpolation invalid destImg
    } -cleanup $cleanup -returnCodes error -match glob -result {bad interpolation method "invalid": must be nearest, linear, catrom, lanczos2*lanczos3*}
    
    test parsecommonopts-4.5 {value: lanczos2} -setup $setup -body {
        ::imgtools::rotate smiley 32 -interpolation lanczos2 destImg
    } -cleanup $cleanup -returnCodes ok -result {destImg}
    
    test parsecommonopts-4.6 {value: lanczos3} -setup $setup -body {
        ::imgtools::rotate smiley 85 -interpolation lanczos3 destImg
    } -cleanup $cleanup -returnCodes ok -result {destImg}
    
    #
    # -background
    #
    test parsecommonopts-5.0 {missing value} -setup $setup -body {
        ::imgtools::rotate smiley 3 -background destImg
    } -cleanup $cleanup -returnCodes error -result {option -background requires an argument}
    
    test parsecommonopts-5.1 {unknown color name} -setup $setup -body {
        ::imgtools::rotate smiley 3 -background invalid destImg
    } -cleanup $cleanup -returnCodes error -result {unknown color name "invalid"}
    
    test parsecommonopts-5.2 {invalid color name} -setup $setup -body {
        ::imgtools::rotate smiley 22 -shrink -background #invalid destImg
    } -cleanup $cleanup -returnCodes error -result {invalid color name "#invalid"}
    
    test parsecommonopts-5.3 {valid color} -setup $setup -body {
        ::imgtools::rotate smiley 45 -background #112233 -alpha 0.0001% destImg
        getPixel destImg 1 1 
    } -cleanup $cleanup -returnCodes ok -result {17 34 51 0}
    
    test parsecommonopts-5.4 {invalid color name again} -setup $setup -body {
        ::imgtools::rotate smiley 22 -shrink -background -alpha 34% destImg
    } -cleanup $cleanup -returnCodes error -result {unknown color name "-alpha"}
    
    #
    # -alpha
    #
    test parsecommonopts-6.0 {missing value} -setup $setup -body {
        ::imgtools::rotate smiley 99 -alpha destImg
    } -cleanup $cleanup -returnCodes error -result {option -alpha requires an argument}
    
    test parsecommonopts-6.1 {bad value} -setup $setup -body {
        #just one "random" error - finer grained checks in getalphaval-*
        ::imgtools::rotate smiley 98 -alpha -shrink destImg
    } -cleanup $cleanup -returnCodes error -result {expected floating-point number but got "-shrink"}
    
    test parsecommonopts-6.3 {valid alpha} -setup $setup -body {
        ::imgtools::rotate smiley 45 -alpha .2 destImg
        # destImg is larger than smiley!
        getPixel destImg 20 20
    } -cleanup $cleanup -returnCodes ok -result {0 0 0 51}
    
    #
    # -to
    #
    test parsecommonopts-7.0 {missing value} -setup $setup -body {
        ::imgtools::transparency set smiley .4 -to destImg
    } -cleanup $cleanup -returnCodes error -result {option -to requires an argument}
    
    test parsecommonopts-7.1 {not integer value} -setup $setup -body {
        ::imgtools::transparency set smiley .6 -to 3 4.4 destImg
    } -cleanup $cleanup -returnCodes error -result {expected integer but got "4.4"}
    
    test parsecommonopts-7.2 {negative value / coords termination} -setup $setup -body {
        ::imgtools::transparency set smiley .8 -to 4 3 13 -14 destImg
    } -cleanup $cleanup -returnCodes error -result {bad option "-14": must be -compositingrule, -shrink, -from or -to}
    
    test parsecommonopts-7.3 {valid values} -setup $setup -body {
        ::imgtools::transparency set smiley 1 -to 4 4 destImg
        lindex [getPixel destImg 14 14] 3
    } -cleanup $cleanup -returnCodes ok -result 255
    
    #
    # -orient
    #
    test parsecommonopts-8.0 {missing value for -orient} -setup $setup -body {
        ::imgtools::gradient black white -to 0 0 10 10 -orient destImg
    } -cleanup $cleanup -returnCodes error -result {option -orient requires an argument}
    
    test parsecommonopts-8.1 {valid value for -orient: vertical} -setup $setup -body {
        ::imgtools::gradient black white -to 0 0 256 256 -orient vertical destImg
        compareImages destImg gradientVertical
    } -cleanup $cleanup -returnCodes ok -result {1}
    
    test parsecommonopts-8.2 {valid value for -orient: horizontal} -setup $setup -body {
        ::imgtools::gradient black white -to 0 0 256 256 -orient horizontal destImg
        compareImages destImg gradientHorizontal
    } -cleanup $cleanup -returnCodes ok -result {1}
    
    test parsecommonopts-8.3 {invalid value for -orient} -setup $setup -body {
        ::imgtools::gradient black white -to 0 0 10 10 -orient invalid destImg
    } -cleanup $cleanup -returnCodes error -result {unknown orientation "invalid": must be horizontal or vertical}
    
    #
    # -from
    #
    test parsecommonopts-9.1 {missing value} -setup $setup -body {
        ::imgtools::transparency set smiley .4 -from destImg
    } -cleanup $cleanup -returnCodes error -result {option -from requires an argument}
    
    test parsecommonopts-9.2 {not integer value} -setup $setup -body {
        ::imgtools::scale smiley 2x3 -from 3 4.4 destImg
    } -cleanup $cleanup -returnCodes error -result {expected integer but got "4.4"}
    
    test parsecommonopts-9.4 {negative value / coords termination} -setup $setup -body {
        ::imgtools::rotate rotated0 999 -from 4 3 13 -14 destImg
    } -cleanup $cleanup -returnCodes error -match glob -result {bad option "-14": must be -compositingrule, -shrink, -interpolation, -background, -alpha, -from, -to*-clipping*}
    
    test parsecommonopts-9.5 {valid values} -setup $setup -body {
        ::imgtools::scale smiley 20x21 -from 4 4 destImg
    } -cleanup $cleanup -returnCodes ok -result {destImg}
    
    #
    # -clipping
    #
    test parsecommonopts-10.1 {missing value} -setup $setup -body {
        ::imgtools::rotate smiley 2 -clipping destImg
    } -cleanup $cleanup -returnCodes error -result {option -clipping requires an argument}
    
    test parsecommonopts-10.2 {invalid value} -setup $setup -body {
        ::imgtools::rotate smiley 3 -clipping invalid destImg
    } -cleanup $cleanup -returnCodes error -result {unknown clipping mode "invalid": must be none, keepsize or noblanks}
    
    test parsecommonopts-10.3 {valid value: noblanks} -setup $setup -body {
        ::imgtools::rotate smiley 32 -clipping noblanks destImg
    } -cleanup $cleanup -returnCodes ok -result {destImg}
    
    test parsecommonopts-10.4 {valid value: keepsize} -setup $setup -body {
        ::imgtools::rotate smiley 32 -clipping keepsize destImg
    } -cleanup $cleanup -returnCodes ok -result {destImg}
    
    test parsecommonopts-10.5 {valid value: none} -setup $setup -body {
        ::imgtools::rotate smiley 32 -clipping none destImg
    } -cleanup $cleanup -returnCodes ok -result {destImg}
    
    #
    # ### Imgtools_GetAllowedOptsList ###
    #
    # Tested with scale-1.6, transparency-1.6, rotate-??, etc
    
    #
    # ### Imgtools_FindPhoto ###
    #
    # Tested with other tests as well, but just check once more to be sure
    test findphoto-1.1 {image does not exist} -setup $setup -body {
        ::imgtools::gradient yellow magenta invalid
    } -cleanup $cleanup -returnCodes error -result {image "invalid" not found}
    
    #
    # ### Imgtools_GetSizesFromSpec ###
    #
    
    #
    # Parse string
    #
    test getsizesfromspec-1.0 {separator: lowercase x} -setup $setup -body {
        ::imgtools::scale smiley 10x12 destImg
        list [image width destImg] [image height destImg]
    } -cleanup $cleanup -returnCodes ok -result {10 12}
    
    test getsizesfromspec-1.1 {separator: uppercase X} -setup $setup -body {
        ::imgtools::scale smiley 5X destImg
        list [image width destImg] [image height destImg]
    } -cleanup $cleanup -returnCodes ok -result {5 5}
    
    test getsizesfromspec-1.2 {separator: none} -setup $setup -body {
        ::imgtools::scale smiley 40% destImg
        list [image width destImg] [image height destImg]
    } -cleanup $cleanup -returnCodes ok -result {6 6}
    
    test getsizesfromspec-1.2.1 {separator: more than one} -setup $setup -body {
        ::imgtools::scale smiley 12x13x14 destImg
    } -cleanup $cleanup -returnCodes error -result {expected integer but got "13x14"}
    
    test getsizesfromspec-1.2.2 {separator: more than one, no leading number} -setup $setup -body {
        ::imgtools::scale smiley x15x10 destImg
    } -cleanup $cleanup -returnCodes error -result {expected integer but got "15x10"}
    
    test getsizesfromspec-1.3 {x part given, in percent} -setup $setup -body {
        ::imgtools::scale smiley 60%x100 destImg
        list [image width destImg] [image height destImg]
    } -cleanup $cleanup -returnCodes ok -result {9 15}
    
    test getsizesfromspec-1.4 {no x part, y part in percent} -setup $setup -body {
        ::imgtools::scale smiley x80% destImg
        list [image width destImg] [image height destImg]
    } -cleanup $cleanup -returnCodes ok -result {12 12}
    
    test getsizesfromspec-1.5 {no x part, y part absolute} -setup $setup -body {
        ::imgtools::scale smiley x14 destImg
        list [image width destImg] [image height destImg]
    } -cleanup $cleanup -returnCodes ok -result {14 14}
    
    test getsizesfromspec-1.6 {x part invalid (single % sign)} -setup $setup -body {
        ::imgtools::scale smiley %x50% destImg
    } -cleanup $cleanup -returnCodes error -match glob -result {expected * but got "%"}
    
    test getsizesfromspec-1.7 {y part invalid (single % sign)} -setup $setup -body {
        ::imgtools::scale smiley 50%x% destImg
    } -cleanup $cleanup -returnCodes error -match glob -result {expected * but got "%"}
    
    #
    # calculate new sizes
    #
    if 0 {
        test getsizesfromspec-2.0 {x part given, in percent} -setup $setup -body {
            # already tested with getsizesfromspec-1.3
        } -cleanup $cleanup -returnCodes -result
    }
    
    test getsizesfromspec-2.1 {x part given, absolute} -setup $setup -body {
        ::imgtools::scale smiley 8X7 destImg
        list [image width destImg] [image height destImg]
    } -cleanup $cleanup -returnCodes ok -result {8 7}
    
    test getsizesfromspec-2.2 {x part given, percent, not a proper number} -setup $setup -body {
        ::imgtools::scale smiley 50t%x100 destImg
    } -cleanup $cleanup -returnCodes error -result {expected floating-point number but got "50t"}
    
    test getsizesfromspec-2.3 {x part given, absolute, not a proper number} -setup $setup -body {
        ::imgtools::scale smiley 10.5x10 destImg
    } -cleanup $cleanup -returnCodes error -result {expected integer but got "10.5"}
    
    test getsizesfromspec-2.4 {x part given, negative value} -setup $setup -body {
        ::imgtools::scale smiley -3x13 destImg
    } -cleanup $cleanup -returnCodes error -result {bad width "-3": must be positive}
    
    test getsizesfromspec-2.5 {y part given, in percent} -setup $setup -body {
        ::imgtools::scale smiley 20%x80% destImg
        list [image width destImg] [image height destImg]
    } -cleanup $cleanup -returnCodes ok -result {3 12}
    
    if 0 {
        test getsizesfromspec-2.6 {y part given, absolute} -setup $setup -body {
            #see getsizesfromspec-1.5
        } -cleanup $cleanup -returnCodes -result
    }
    
    test getsizesfromspec-2.7 {y part given, percent, not a proper number} -setup $setup -body {
        ::imgtools::scale smiley 50%x100t destImg
    } -cleanup $cleanup -returnCodes error -result {expected floating-point number but got "100t"}
    
    test getsizesfromspec-2.8 {y part given, absolute, not a proper number} -setup $setup -body {
        ::imgtools::scale smiley 10x10% destImg
    } -cleanup $cleanup -returnCodes error -result {expected integer but got "10%"}
    
    test getsizesfromspec-2.9 {y part given, negative value} -setup $setup -body {
        ::imgtools::scale smiley 3x-13 destImg
    } -cleanup $cleanup -returnCodes error -result {bad height "-13": must be positive}
    
    #
    # calculate sizes
    #
    test getsizesfromspec-3.0 {empty source image} -setup $setup -body {
        ::imgtools::scale emptyImg X20 -shrink destImg
        list [image width destImg] [image height destImg]
    } -cleanup $cleanup -returnCodes ok -result {0 0}
    
    test getsizesfromspec-3.1 {no x spec} -setup $setup -body {
        ::imgtools::scale rotated0 x30 destImg
        list [image width destImg] [image height destImg]
    } -cleanup $cleanup -returnCodes ok -result {53 30}
    
    test getsizesfromspec-3.2 {no y spec} -setup $setup -body {
        ::imgtools::scale rotated0 123% destImg
        list [image width destImg] [image height destImg]
    } -cleanup $cleanup -returnCodes ok -result {48 27}
    
    test getsizesfromspec-3.3 {both x and y} -setup $setup -body {
        ::imgtools::scale rotated0 25x25 destImg
        list [image width destImg] [image height destImg]
    } -cleanup $cleanup -returnCodes ok -result {25 25}
        
    test getsizesfromspec-3.4 {no x, no y spec} -setup $setup -body {
        ::imgtools::scale rotated0 x destImg
    } -cleanup $cleanup -returnCodes error -result {malformed specStr "x": must be widthxheight}
    
    #
    # ### Imgtools_RemovePrercent
    #
    # tested with getsizesfromspec-*.*
    
    #
    # ### Imgtools_GetAlphaVal ###
    #
    test getalphaval-1.0 {Alpha value in percent, rounding up} -setup $setup -body {
        ::imgtools::rotate rotated0 45 -alpha 56.789% destImg
        lindex [getPixel destImg 1 1] 3
    } -cleanup $cleanup -returnCodes ok -result {145}
    
    test getalphaval-1.1 {Alpha value as fraction, rounding down} -setup $setup -body {
        ::imgtools::rotate rotated0 45 -alpha 0.1234 destImg
        expr {[lindex [getPixel destImg 1 1] 3] == 31}
    } -cleanup $cleanup -returnCodes ok -result {1}
    
    test getalphaval-1.2 {Alpha = 0} -setup $setup -body {
        ::imgtools::rotate rotated0 44 -alpha 0 destImg
        expr {[lindex [getPixel destImg 1 1] 3] == 0}
    } -cleanup $cleanup -returnCodes ok -result {1}
    
    test getalphaval-1.3 {Alpha = 1} -setup $setup -body {
        ::imgtools::rotate rotated0 44 -alpha 1 destImg
        expr {[lindex [getPixel destImg 1 1] 3] == 255}
    } -cleanup $cleanup -returnCodes ok -result {1}
    
    test getalphaval-1.4 {Alpha = 0%} -setup $setup -body {
        ::imgtools::rotate rotated0 44 -alpha 0.0% destImg
        expr {[lindex [getPixel destImg 1 1] 3] == 0}
    } -cleanup $cleanup -returnCodes ok -result {1}
    
    test getalphaval-1.5 {Alpha = 100%} -setup $setup -body {
        ::imgtools::rotate rotated0 44 -alpha 100% destImg
        expr {[lindex [getPixel destImg 1 1] 3] == 255}
    } -cleanup $cleanup -returnCodes ok -result {1}
    
    test getalphaval-1.6 {Percent value, number not a double} -setup $setup -body {
        ::imgtools::rotate rotated0 44 -alpha 34.5%% destImg
    } -cleanup $cleanup -returnCodes error -match glob -result {expected floating-point number but got "34.5%"}
    
    test getalphaval-1.7 {Percent value, number smaller than 0} -setup $setup -body {
        ::imgtools::rotate rotated0 44 -alpha -0.00001% destImg
    } -cleanup $cleanup -returnCodes error -match glob -result {* requires a value between 0 and 100%}
    
    test getalphaval-1.8 {Percent value, number larger than 100} -setup $setup -body {
        ::imgtools::rotate rotated0 44 -alpha 100.0001% destImg
    } -cleanup $cleanup -returnCodes error -match glob -result {* requires a value between 0 and 100%}
    
    test getalphaval-1.9 {fraction value, number not a double} -setup $setup -body {
        ::imgtools::rotate rotated0 44 -alpha 3s4.5 destImg
    } -cleanup $cleanup -returnCodes error -result {expected floating-point number but got "3s4.5"}
    
    test getalphaval-1.10 {fraction value, number smaller than 0} -setup $setup -body {
        ::imgtools::rotate rotated0 44 -alpha -1.23e34 destImg
    } -cleanup $cleanup -returnCodes error -match glob -result {* requires a value between 0 and 1}
    
    test getalphaval-1.11 {Percent value, number larger than 1} -setup $setup -body {
        ::imgtools::rotate rotated0 44 -alpha 1.0001 destImg
    } -cleanup $cleanup -returnCodes error -match glob -result {* requires a value between 0 and 1}
    
    #
    # ### Imgtools_ReduceAngle ###
    #
    # tested with rotate* tests.
    
    #
    # ### Imgtools_GetAngle ###
    #
    test getangle-1.1 {trimming with valid value} -setup $setup -body {
        ::imgtools::rotate smiley "4.4 " destImg
    } -cleanup $cleanup -returnCodes ok -result {destImg}
    
    test getangle-1.2 {trimming with "°" char} -setup $setup -body {
        ::imgtools::rotate smiley "-123°\t \n" destImg
    } -cleanup $cleanup -returnCodes ok -result {destImg}
    
    test getangle-1.3 {trimming with invalid value} -setup $setup -body {
        ::imgtools::rotate smiley "invalid \t \n \t" destImg
    } -cleanup $cleanup -returnCodes error -result {expected floating-point number but got "invalid"}
    
    test getangle-1.4 {one "°" sign is ignored} -setup $setup -body {
        ::imgtools::rotate photo 325 destImg
        ::imgtools::rotate photo 325° emptyImg
        compareImages destImg emptyImg
    } -cleanup $cleanup -returnCodes ok -result {1}
    
    test getangle-1.5 {more than one "°" is an error} -setup $setup -body {
        ::imgtools::rotate photo 45°° destImg
    } -cleanup $cleanup -returnCodes error -result {expected floating-point number but got "45°"}
    
    #
    # ### getColor ###
    #
    # tested with parsecommonopts-5.3, gradient-2.4, and others
    
    #
    # ### Imgtools_GetRegion ###
    #
    # also tested with many ohter tests
    test getregion-1.1 {no coords passed - default to image size} -setup $setup -body {
        ::imgtools::gradient yellow magenta rotated0
        list [image width rotated0] [image height rotated0]
    } -cleanup $cleanup -returnCodes ok -result {39 22}
    
    test getregion-1.2 {only x1 passed - y1 must be equal x1, the others image size}  -setup $setup -body {
        ::imgtools::scale smiley 100% -from 2 destImg
        emptyImg copy smiley -from  2 2 15 15
        compareImages destImg emptyImg
    } -cleanup $cleanup -returnCodes ok -result {1}
    
    test getregion-1.3 {x1 and y1 passed. x2/y2: default to image size}  -setup $setup -body {
        ::imgtools::rotate photo 360 -to 3 5 destImg
        emptyImg copy photo -to 3 5 103 80
        compareImages destImg emptyImg
    } -cleanup $cleanup -returnCodes ok -result {1}
    
    test getregion-1.4 {x1,y1,x2 passed. y2: equals x2}  -setup $setup -body {
        ::imgtools::transparency set gradientColor 1 -from 1 2 7 destImg
        emptyImg copy gradientColor -from 1 2 7 7
        compareImages destImg emptyImg
    } -cleanup $cleanup -returnCodes ok -result {1}
    
    test getregion-1.5 {all coords passed}  -setup $setup -body {
        ::imgtools::scale gradientColor 100% -from 14 13 0 1 destImg
        emptyImg copy gradientColor -from 0 1 14 13
        compareImages destImg emptyImg
    } -cleanup $cleanup -returnCodes ok -result {1}
    
    test getregion-2.1 {combinations of corners: nw/se} -setup $setup -body {
        ::imgtools::rotate smiley -360° -from 2 3 10 11 destImg
        emptyImg copy smiley -from 2 3 10 11
        compareImages destImg emptyImg
    } -cleanup $cleanup -returnCodes ok -result {1}
    
    test getregion-2.2 {combinations of corners: se/nw} -setup $setup -body {
        ::imgtools::scale smiley x100% -from 15 15 3 5 destImg
        emptyImg copy smiley -from 15 15 3 5
        compareImages destImg emptyImg
    } -cleanup $cleanup -returnCodes ok -result {1}
    
    test getregion-2.3 {combinations of corners: ne/sw} -setup $setup -body {
        ::imgtools::gradient yellow brown -to 33 5 3 25 destImg
        list  \
            [getPixel destImg 2 10] \
            [getPixel destImg 11 4] \
            [image width destImg] \
            [image height destImg]
    } -cleanup $cleanup -returnCodes ok -result {{0 0 0 0} {0 0 0 0} 33 25}
    
    test getregion-2.4 {combinations of corners: sw/ne} -setup $setup -body {
        ::imgtools::transparency decrease rotated0 0 -from 3 21 33 5 destImg
        emptyImg copy rotated0 -from 3 5 33 21 
        compareImages destImg emptyImg
    } -cleanup $cleanup -returnCodes ok -result {1}
    
    test getregion-3.1 {coords out of bounds (error): start.x} -setup $setup -body {
        ::imgtools::transparency increase smiley .5 -from 200 150 15 14 destImg
    } -cleanup $cleanup -returnCodes error -result {coordinates extend outside image}
    
    test getregion-3.2 {coords out of bounds (error): start.y} -setup $setup -body {
        ::imgtools::transparency increase smiley .5 -from 200 150 14 15 destImg
    } -cleanup $cleanup -returnCodes error -result {coordinates extend outside image}
    
    test getregion-3.3 {coords out of bounds (error): end.x} -setup $setup -body {
        ::imgtools::transparency increase smiley .5 -from 16 3 2 14 destImg
    } -cleanup $cleanup -returnCodes error -result {coordinates extend outside image}
    
    test getregion-3.4 {coords out of bounds (error): end.y} -setup $setup -body {
        ::imgtools::transparency increase smiley .5 -from 2 3 14 16 destImg
    } -cleanup $cleanup -returnCodes error -result {coordinates extend outside image}
    
    test getregion-3.9 {coords out of bounds because of "automatic y" I} -setup $setup -body {
        ::imgtools::scale rotated0 49% -from 25 destImg
    } -cleanup $cleanup -returnCodes error -result {coordinates extend outside image}
    
    test getretion-3.10 {coords out of image because of "automatic y" II} -setup $setup -body {
        ::imgtools::rotate rotated0 2 -from 0 1 38 destImg
    } -cleanup $cleanup -returnCodes error -result {coordinates extend outside image}
    
    test getregion-3.5 {coords out of bounds (accepted): start.x} -setup $setup -body {
        ::imgtools::gradient red blue -to 16 14 20 20 smiley
        list [image width smiley] [image height smiley]
    } -cleanup $cleanup -returnCodes ok -result {20 20}
    
    test getregion-3.6 {coords out of bounds (accepted): start.y} -setup $setup -body {
        ::imgtools::gradient red blue -to 10 16 20 20 smiley
        list [image width smiley] [image height smiley]
    } -cleanup $cleanup -returnCodes ok -result {20 20}
    
    test getregion-3.7 {coords out of bounds (accepted): end.x} -setup $setup -body {
        ::imgtools::gradient red blue -to 2 3 20 14 smiley
        list [image width smiley] [image height smiley]
    } -cleanup $cleanup -returnCodes ok -result {20 15}
    
    test getregion-3.8 {coords out of bounds (accepted): end.y} -setup $setup -body {
        ::imgtools::gradient red blue -to 5 6 10 20 smiley
        list [image width smiley] [image height smiley]
    } -cleanup $cleanup -returnCodes ok -result {15 20}
    
    #
    # ### Imgtools_GetSizeFromCorners
    #
    # function gets called when the -to  or -from options are passed
    test getsizefromcorners-1.1 {test correct size with -to} -setup $setup -body {
        ::imgtools::rotate rotated0 270 -to 90 1 2 88 destImg
        list [image width destImg] [image height destImg]
    } -cleanup $cleanup -returnCodes ok -result {90 88}
    
    test getsizefromcorners-1.2 {correct size with -from} -setup $setup -body {
        ::imgtools::rotate photo -180° -from 2 73 82 3 destImg
        list [image width destImg] [image height destImg]
    } -cleanup $cleanup -returnCodes ok -result {80 70}
    
    #
    # ### Imgtools_Init ###
    # 
    test init-1.0 {Namespace already exists} -setup {} -body {
        # We can't test this as package is already loaded at this point!
        
        #namespace eval ::imgtools {}
        #load [file join [workingDirectory] .. build generic imgtools[info shared]]
    } -cleanup {} -returnCodes ok -result {}
    
    test init-1.1 {scale command gets created} -setup $setup -body {
       info command ::imgtools::scale 
    } -cleanup $cleanup -returnCodes ok -result {::imgtools::scale}
    
    test init-1.2 {rotate command gets created} -setup $setup -body {
       info command ::imgtools::rotate 
    } -cleanup $cleanup -returnCodes ok -result {::imgtools::rotate}
    
    test init-1.3 {transparency command gets created} -setup $setup -body {
       info command ::imgtools::transparency
    } -cleanup $cleanup -returnCodes ok -result {::imgtools::transparency}
    
    test init-1.4 {gradient command gets created} -setup $setup -body {
        info command ::imgtools::gradient
    } -cleanup $cleanup -returnCodes ok -result {::imgtools::gradient}
    
    cleanupTests
}
namespace delete ::imgtools::test::imgtools
