# See the file "license.terms" for information on usage and redistribution
# of this file, and for a DISCLAIMER OF ALL WARRANTIES.

if {[lsearch [namespace children] ::tcltest] == -1} {
    package require tcltest
    namespace import ::tcltest::*
}

package require shellicon

source [file join [file dirname [info script]] utilities.tcl]

namespace eval shellicon::test {
    test get-1.1 "get usage message" -body {
        shellicon::get
    } -returnCodes {
        error
    } -result "wrong \# args: should be \"shellicon::get ?options? fileName\""

    test get-1.2 "Using get with invalid file" -body {
        shellicon::get NotExistingFile
    } -returnCodes {
        error
    } -result "failed to load icon:*" -match glob

    test get-1.3 "Using get with invalid option" -body {
        shellicon::get -invalidoption .
    } -returnCodes {
        error
    } -result "bad option \"-invalidoption\": must be -large, -open, or -selected"


    test get-2.1 "get directory icon" -body {
        set img [shellicon::get .]
        isValidPhoto $img
    } -cleanup {
        image delete $img
    } -result true

    test get-2.2 "get directory icon using -large" -body {
        set img [shellicon::get -large .]
        isValidPhoto $img
    } -cleanup {
        image delete $img
    } -result true

    test get-2.3 "get directory icon using -open" -body {
        set img [shellicon::get -open .]
        isValidPhoto $img
    } -cleanup {
        image delete $img
    } -result true

    test get-2.4 "get directory icon using -selected" -body {
        set img [shellicon::get -selected .]
        isValidPhoto $img
    } -cleanup {
        image delete $img
    } -result true

    test get-2.5 "get directory icon using unicode path" -setup {
        set dirName "dir\u266b"
        set dirPath [makeDirectory $dirName]
    } -body {
        set img [shellicon::get $dirPath]
        isValidPhoto $img
    } -cleanup {
        image delete $img
    } -result true

    test get-2.6 "get file icon using unicode path" -setup {
        set fileName "file\u266b"
        set filePath [makeFile "Test file" $fileName]
    } -body {
        set img [shellicon::get $filePath]
        isValidPhoto $img
    } -cleanup {
        image delete $img
    } -result true
}

::tcltest::cleanupTests
namespace delete shellicon::test
return
