- # This file is a Tcl script to test out the code in tkImgFmtPPM.c,
- # which reads and write PPM-format image files for photo widgets.
- # The files is organized in the standard fashion for Tcl tests.
- #
- # Copyright (c) 1994-1997 Sun Microsystems, Inc.
- # Copyright (c) 1998-1999 by Scriptics Corporation.
- # All rights reserved.
- #
- # RCS: @(#) $Id: imgPPM.test,v 1.5.2.1 2007/11/26 20:53:57 kennykb Exp $
- package require tcltest 2.1
- namespace import -force tcltest::configure
- namespace import -force tcltest::testsDirectory
- configure -testdir [file join [pwd] [file dirname [info script]]]
- configure -loadfile [file join [testsDirectory] constraints.tcl]
- tcltest::loadTestedCommands
- namespace import -force tcltest::makeFile
- namespace import -force tcltest::removeFile
- eval image delete [image names]
- proc put {file data} {
- set f [open $file w]
- fconfigure $f -translation lf
- puts -nonewline $f $data
- close $f
- }
- test imgPPM-1.1 {FileReadPPM procedure} {
- put test.ppm "P6n0 256n255nabcdef"
- list [catch {image create photo p1 -file test.ppm} msg] $msg
- } {1 {PPM image file "test.ppm" has dimension(s) <= 0}}
- test imgPPM-1.2 {FileReadPPM procedure} {
- put test.ppm "P6n-2 256n255nabcdef"
- list [catch {image create photo p1 -file test.ppm} msg] $msg
- } {1 {PPM image file "test.ppm" has dimension(s) <= 0}}
- test imgPPM-1.3 {FileReadPPM procedure} {
- put test.ppm "P6n10 0n255nabcdef"
- list [catch {image create photo p1 -file test.ppm} msg] $msg
- } {1 {PPM image file "test.ppm" has dimension(s) <= 0}}
- test imgPPM-1.4 {FileReadPPM procedure} {
- put test.ppm "P6n10 -2n255nabcdef"
- list [catch {image create photo p1 -file test.ppm} msg] $msg
- } {1 {PPM image file "test.ppm" has dimension(s) <= 0}}
- test imgPPM-1.5 {FileReadPPM procedure} {
- put test.ppm "P6n10 20n256nabcdef"
- list [catch {image create photo p1 -file test.ppm} msg] $msg
- } {1 {PPM image file "test.ppm" has bad maximum intensity value 256}}
- test imgPPM-1.6 {FileReadPPM procedure} {
- put test.ppm "P6n10 20n0nabcdef"
- list [catch {image create photo p1 -file test.ppm} msg] $msg
- } {1 {PPM image file "test.ppm" has bad maximum intensity value 0}}
- test imgPPM-1.7 {FileReadPPM procedure} {
- put test.ppm "P6n10 10n255nabcdef"
- list [catch {image create photo p1 -file test.ppm} msg] $msg
- } {1 {error reading PPM image file "test.ppm": not enough data}}
- test imgPPM-1.8 {FileReadPPM procedure} {
- put test.ppm "P6n5 4n255n01234567890123456789012345678901234567890123456789012345678"
- list [catch {image create photo p1 -file test.ppm} msg] $msg
- } {1 {error reading PPM image file "test.ppm": not enough data}}
- test imgPPM-1.9 {FileReadPPM procedure} {
- put test.ppm "P6n5 4n150n012345678901234567890123456789012345678901234567890123456789"
- list [catch {image create photo p1 -file test.ppm} msg] $msg
- [image width p1] [image height p1]
- } {0 p1 5 4}
- catch {image delete p1}
- put test.ppm "P6n5 4n255n012345678901234567890123456789012345678901234567890123456789"
- image create photo p1 -file test.ppm
- test imgPPM-2.1 {FileWritePPM procedure} {
- list [catch {p1 write not_a_dir/bar/baz/gorp} msg] [string tolower $msg]
- [string tolower $errorCode]
- } {1 {couldn't open "not_a_dir/bar/baz/gorp": no such file or directory} {posix enoent {no such file or directory}}}
- test imgPPM-2.2 {FileWritePPM procedure} {
- catch {unset data}
- p1 write -format ppm test2.ppm
- set fd [open test2.ppm]
- set data [read $fd]
- close $fd
- set data
- } {P6
- 5 4
- 255
- 012345678901234567890123456789012345678901234567890123456789}
- test imgPPM-3.1 {ReadPPMFileHeader procedure} {
- catch {image delete p1}
- put test.ppm "# n#n#nP6n#n##n5 4n255n012345678901234567890123456789012345678901234567890123456789"
- list [catch {image create photo p1 -file test.ppm} msg] $msg
- } {0 p1}
- test imgPPM-3.2 {ReadPPMFileHeader procedure} {
- catch {image delete p1}
- put test.ppm "P6n5n 4 255n012345678901234567890123456789012345678901234567890123456789"
- list [catch {image create photo p1 -file test.ppm} msg] $msg
- } {0 p1}
- test imgPPM-3.3 {ReadPPMFileHeader procedure} {
- catch {image delete p1}
- put test.ppm "P6n# asdfasdfn5 4n255n012345678901234567890123456789012345678901234567890123456789"
- list [catch {image create photo p1 -file test.ppm} msg] $msg
- } {0 p1}
- test imgPPM-3.4 {ReadPPMFileHeader procedure} {
- catch {image delete p1}
- put test.ppm "P6 n5 4n255n012345678901234567890123456789012345678901234567890123456789"
- list [catch {image create photo p1 -file test.ppm} msg] $msg
- } {0 p1}
- test imgPPM-3.5 {ReadPPMFileHeader procedure} {
- catch {image delete p1}
- put test.ppm "P5n5 4n255n01234567890123456789"
- list [catch {image create photo p1 -file test.ppm} msg] $msg
- } {0 p1}
- test imgPPM-3.6 {ReadPPMFileHeader procedure} {
- catch {image delete p1}
- put test.ppm "P3n5 4n255n012345678901234567890123456789012345678901234567890123456789"
- list [catch {image create photo p1 -file test.ppm} msg] $msg
- } {1 {couldn't recognize data in image file "test.ppm"}}
- test imgPPM-3.7 {ReadPPMFileHeader procedure} {
- catch {image delete p1}
- put test.ppm "P6xn5 4n255n012345678901234567890123456789012345678901234567890123456789"
- list [catch {image create photo p1 -file test.ppm} msg] $msg
- } {1 {couldn't recognize data in image file "test.ppm"}}
- test imgPPM-3.8 {ReadPPMFileHeader procedure} {
- catch {image delete p1}
- put test.ppm "P6nxy5 4n255n012345678901234567890123456789012345678901234567890123456789"
- list [catch {image create photo p1 -file test.ppm} msg] $msg
- } {1 {couldn't recognize data in image file "test.ppm"}}
- test imgPPM-3.9 {ReadPPMFileHeader procedure} {
- catch {image delete p1}
- put test.ppm "P6n5n255n!012345678901234567890123456789012345678901234567890123456789"
- list [catch {image create photo p1 -file test.ppm} msg] $msg
- } {1 {couldn't recognize data in image file "test.ppm"}}
- test imgPPM-3.10 {ReadPPMFileHeader procedure} {
- catch {image delete p1}
- put test.ppm "P6n5 4nzz255n012345678901234567890123456789012345678901234567890123456789"
- list [catch {image create photo p1 -file test.ppm} msg] $msg
- } {1 {couldn't recognize data in image file "test.ppm"}}
- test imgPPM-3.11 {ReadPPMFileHeader procedure, empty file} {
- catch {image delete p1}
- put test.ppm " "
- list [catch {image create photo p1 -file test.ppm} msg] $msg
- } {1 {couldn't recognize data in image file "test.ppm"}}
- test imgPPM-3.12 {ReadPPMFileHeader procedure, file ends too soon} {
- catch {image delete p1}
- put test.ppm "P6n566"
- list [catch {image create photo p1 -file test.ppm} msg] $msg
- } {1 {couldn't recognize data in image file "test.ppm"}}
- test imgPPM-3.13 {ReadPPMFileHeader procedure, file ends too soon} {
- catch {image delete p1}
- put test.ppm "P6n566n#asdf"
- list [catch {image create photo p1 -file test.ppm} msg] $msg
- } {1 {couldn't recognize data in image file "test.ppm"}}
- test imgPPM-4.1 {StringReadPPM procedure, data too short [Bug 1822391]}
- -setup {
- image create photo I -width 1103 -height 997
- }
- -cleanup {
- image delete I
- }
- -body {
- I put "P5n1103 997n255n"
- }
- -returnCodes error
- -result {truncated PPM data}
- removeFile test.ppm
- removeFile test2.ppm
- eval image delete [image names]
- # cleanup
- ::tcltest::cleanupTests
- return