1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148
|
# Commands covered: sound read/write
#
package require -exact snack 2.2
if {[lsearch [namespace children] ::tcltest] == -1} {
package require tcltest
namespace import ::tcltest::*
}
test fileio-1.1 {write/read commands for WAV file format} {
set s [snack::sound snd]
$s length 300
$s write snackTest.wav
set res [$s read snackTest.wav]
$s destroy
set res
} {WAV}
test fileio-1.2 {write/read commands for AU file format} {
set s [snack::sound snd]
$s length 300
$s write snackTest.au
set res [$s read snackTest.au]
$s destroy
set res
} {AU}
test fileio-1.3 {write/read commands for AIFF file format} {
set s [snack::sound snd]
$s length 300
$s write snackTest.aiff
set res [$s read snackTest.aiff]
$s destroy
set res
} {AIFF}
test fileio-1.4 {write/read commands for MP3 file format} {
set s [snack::sound snd]
$s length 300
set res [list [catch {$s write snackTest.mp3} msg] $msg]
$s destroy
set res
} {1 {Unsupported save format}}
test fileio-1.5 {write/read commands for RAW file format} {
set s [snack::sound snd -load ex1.wav]
$s write snackTest.raw -start 5000 -end 10000 -fileformat raw \
-byteorder littleEndian
$s read snackTest.raw -guessproperties 1
set res [$s cget -byteorder]
$s destroy
set res
} {littleEndian}
test fileio-1.6 {write/read commands for RAW file format} {
set s [snack::sound snd -load ex1.wav]
$s write snackTest.raw -start 5000 -end 10000 -fileformat raw \
-byteorder bigEndian
$s read snackTest.raw -guessproperties 1
set res [$s cget -byteorder]
$s destroy
set res
} {bigEndian}
test fileio-1.7 {write/read commands for RAW file format} {
set s [snack::sound snd -load ex1.wav]
$s write snackTest.raw -fileformat raw -byteorder bigEndian
$s read snackTest.raw -rate 16000 -encoding Lin16 -channels 1 \
-byteorder bigEndian -guessproperties 0
set res [$s info]
$s destroy
set res
} {15820 16000 14264 -8288 Lin16 1 RAW 0}
test fileio-2.1 {read command, -start/-end options} {
set s [snack::sound snd]
$s read ex1.wav -start 5000 -end 10000
set res [list [$s sample 0] [$s sample 5000] [$s length]]
$s destroy
set res
} {7443 779 5001}
test fileio-2.2 {read command, missing argument for -end option} {
set s [snack::sound snd]
catch {$s read ex1.wav -start 5000 -end} msg
$s destroy
set msg
} {No argument given for -end option}
test fileio-3.1 {read command, empty -progress option} {
set s [snack::sound snd]
catch {$s read ex1.wav -progress ""} msg
$s destroy
set msg
} WAV
test fileio-3.2 {write command, empty -progress option} {
set s [snack::sound snd]
catch {$s write snackTest.wav -progress ""} msg
$s destroy
set msg
} {}
test fileio-3.3 {read command, -progress option} {
set res ""
proc prog {msg frac} {
lappend ::res $frac
}
set s [snack::sound snd]
$s read ex1.wav -progress prog
$s destroy
set res
} {0.0 1.0}
test fileio-3.4 {write command, -progress option} {
set res ""
proc prog {msg frac} {
lappend ::res $frac
}
set s [snack::sound snd]
$s write snackTest.wav -progress prog
$s destroy
set res
} {0.0 1.0}
test fileio-4.1 {read command, read error should leave current untouched} {
set s [snack::sound snd -load ex1.wav]
catch {$s read nonexisting.wav}
set res [$s info]
$s destroy
set res
} {15820 16000 14264 -8288 Lin16 1 WAV 44}
test fileio-4.2 {read command, No file name given} {
set s [snack::sound snd]
catch {$s read} res
$s destroy
set res
} {No file name given}
# cleanup
catch {::tcltest::removeFile snackTest.wav}
catch {::tcltest::removeFile snackTest.au}
catch {::tcltest::removeFile snackTest.aiff}
catch {::tcltest::removeFile snackTest.raw}
::tcltest::cleanupTests
return
|