# This file is a Tcl script to test out SUN reading and writing.
# It is organized in the standard fasion for Tcl tests.

package require Tk

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

package require Img

imageInit

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

    set fmt  "sun"
    set ext  "ras"
    set file "testimgs/img.$ext"

    # Encoded image content in variable imgdata.
    source $file.base64

    test sun-1.1 {} -setup {
        catch {image delete i}
    } -body {
        image create photo i -file $file
        i data -format $fmt
    } -cleanup {
        image delete i
    } -result $imgdata

    test sun-1.2 {} -setup {
        catch {image delete i}
    } -body {
        image create photo i -data $imgdata
        i data -format $fmt
    } -cleanup {
        image delete i
    } -result $imgdata

    test sun-1.3 {} -setup {
        catch {image delete i}
    } -body {
        image create photo i
        i put $imgdata
        i data -format $fmt
    } -cleanup {
        image delete i
    } -result $imgdata

    test sun-1.4 {} -setup {
        catch {image delete i}
    } -body {
        image create photo i
        i put $imgdata -format $fmt
        i data -format $fmt
    } -cleanup {
        image delete i
    } -result $imgdata


    test sun-2.0 {Binary I/O with SUN images} -setup {
        catch {image delete i}
    } -body {
        image create photo i
        set f [open $file r]
        fconfigure $f -translation binary
        set return [catch {i put [read $f]} msg]
        close $f
        lappend return $msg
    } -cleanup {
        image delete i
    } -result {0 {}}
}

imageFinish
namespace delete ::sun::test
