File: data.test

package info (click to toggle)
snack 2.2.10-dfsg1-12.1
  • links: PTS
  • area: main
  • in suites: wheezy
  • size: 3,024 kB
  • sloc: ansic: 35,473; sh: 8,557; tcl: 1,065; python: 701; makefile: 565
file content (127 lines) | stat: -rw-r--r-- 3,201 bytes parent folder | download | duplicates (9)
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
# Commands covered: sound data/append
#

package require -exact snack 2.2

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

test data-1.1 {data command, read sound from binary variable} {
  if [catch {set fd [open ex1.wav]} res] {
    return $res
  }
  fconfigure $fd -translation binary
  if {$::tcl_version > 8.0} {
    fconfigure $fd -encoding binary
  }
  set data [read $fd]
  
  set s [snack::sound snd]
  $s data $data

  set res [$s info]
  $s destroy
  set res
} {15820 16000 14264 -8288 Lin16 1 WAV 44}

test data-1.2 {data command, read sound from binary string} {
  set s [snack::sound snd]
  $s data "\x00\x00\xFF\x00\x00\x00" -byteorder littleEndian
  set res [$s info]
  $s destroy
  set res
} {3 16000 255 0 Lin16 1 RAW 0}

test data-2.1 {data command, write sound to binary variable} {
  set s [snack::sound snd -load ex1.wav]
  set var [$s data -start 5000 -end 5001 -fileformat raw -byteorder bigEndian]
  binary scan $var S out
  $s destroy
  set out
} 7443

test data-3.1 {data command, append binary variable} {
  if [catch {set fd [open ex1.wav]} res] {
    return $res
  }
  fconfigure $fd -translation binary
  if {$::tcl_version > 8.0} {
    fconfigure $fd -encoding binary
  }
  set data [read $fd]
  set s [snack::sound snd]
  $s length 1000
  $s append $data
  set res [list [$s sample 999] [$s sample 6000] [$s sample 11000]]
  $s destroy
  set res
} {0 7443 779}

test data-4.1 {append command, append binary string} {
  set s [snack::sound snd]
  $s append "\x00\x00\x40\x00\x00\x00" -byteorder littleEndian
  set res [$s info]
  $s destroy
  set res
} {3 16000 64 0 Lin16 1 RAW 0}

test data-4.2 {append command, append binary string} {
  set s [snack::sound snd]
  $s append "\x00\x00\x00\x40\x00\x00" -byteorder littleEndian
  set res [$s info]
  $s destroy
  set res
} {3 16000 16384 0 Lin16 1 RAW 0}

test data-4.3 {append command, append binary string} {
  set s [snack::sound snd]
  $s append "\xff\xc0\x00\x40\x00\x00" -byteorder bigendian
  set res [$s info]
  $s destroy
  set res
} {3 16000 64 -64 Lin16 1 RAW 0}

test data-4.4 {append command, append binary string} {
  set s [snack::sound snd]
  $s append "\xc0\xff\x40\x00\x00\x00" -byteorder littleendian
  set res [$s info]
  $s destroy
  set res
} {3 16000 64 -64 Lin16 1 RAW 0}

test data-4.5 {append command, append binary string} {
  set s [snack::sound snd]
  $s append "\xff\xc0\x00\x40\x00\x00" -guessproperties yes
  set res [$s info]
  $s destroy
  set res
} {3 16000 64 -64 Lin16 1 RAW 0}

test data-4.6 {append command, append binary string} {
  set s [snack::sound snd]
  $s append "\xc0\xff\x40\x00\x00\x00" -guessproperties yes
  set res [$s info]
  $s destroy
  set res
} {3 16000 64 -64 Lin16 1 RAW 0}

test data-4.7 {append command, missing arg} {
  set s [snack::sound snd]
  catch {$s append} res
  $s destroy
  set res
} {wrong # args: should be "snd append variable"}

test data-5.1 {data command, initial data byte is '-'} {
  set s [snack::sound snd]
  $s data "-\x00" -byteorder littleEndian
  set res [$s info]
  $s destroy
  set res
} {1 16000 45 45 Lin16 1 RAW 0}

# cleanup
::tcltest::cleanupTests
return