File: common_seek.test

package info (click to toggle)
tcltrf 2.1.4-dfsg1-1
  • links: PTS
  • area: main
  • in suites: wheezy
  • size: 8,052 kB
  • sloc: ansic: 72,769; tcl: 1,343; makefile: 226; sh: 89; exp: 22
file content (243 lines) | stat: -rw-r--r-- 7,755 bytes parent folder | download | duplicates (6)
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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
# -*- tcl -*-
# Commands covered:  all, common behaviour of seeking
#
# This file contains a collection of tests for one or more of the trf
# commands of the TRF extension. Sourcing this file into Tcl runs the
# tests and generates output for errors.  No output means no errors were
# found.
#
# Copyright (c) 1999 Andreas Kupries (andreas_kupries@users.sourceforge.net)
#
# See the file "license.terms" for information on usage and redistribution
# of this file, and for a DISCLAIMER OF ALL WARRANTIES.
#
# $Id: common_seek.test,v 1.3 1999/10/27 21:18:24 aku Exp $

if {[string compare test [info procs test]] == 1} then {source defs}


#makeFile {hex test data} seektests
exec echo {hex test data} > seektests


# A server socket for the tests, actually doing nothing.

proc null {args} {}
set echo  [socket -server null 0]
set eport [lindex [fconfigure $echo -sockname] 2]

proc 82 {a b} {
    if {[string compare [info tclversion] 8.2] < 0} {
	return $b
    } else {
	return $a
    }
}


# ----------------------------------------------------------------------
# check computation of chosen and used policy, which is based upon
# transforms below it, and of the base channel.

test seek-1.0 {chosen policy, seekable transform, seekable base} {
    set f [open seektests r]
    hex -attach $f -mode encode
    set res [fconfigure $f -seekcfg]
    close $f
    set res
} [82 {ratioNatural {1 2} ratioChosen {1 2} overideAllowed 1 identityForced 0} {ratioNatural {1 2} ratioChosen {0 0} overideAllowed 0 identityForced 0}]

test seek-1.1 {chosen policy, seekable transform, unseekable base} {
    set f [socket localhost $eport]
    hex -attach $f -mode encode
    set res [fconfigure $f -seekcfg]
    close $f
    set res
} {ratioNatural {1 2} ratioChosen {0 0} overideAllowed 0 identityForced 0}

test seek-1.2 {chosen policy, unseekable transform, seekable base} {
    set f [open seektests r]
    ascii85 -attach $f -mode encode
    set res [fconfigure $f -seekcfg]
    close $f
    set res
} [82 {ratioNatural {0 0} ratioChosen {0 0} overideAllowed 1 identityForced 0} {ratioNatural {0 0} ratioChosen {0 0} overideAllowed 0 identityForced 0}]

test seek-1.4 {chosen policy, unseekable transform, unseekable base} {
    set f [socket localhost $eport]
    ascii85 -attach $f -mode encode
    set res [fconfigure $f -seekcfg]
    close $f
    set res
} {ratioNatural {0 0} ratioChosen {0 0} overideAllowed 0 identityForced 0}

test seek-1.5 {chosen policy, seekable transforms, seekable base} {
    set f [open seektests r]
    base64 -attach $f -mode encode
    hex    -attach $f -mode encode
    set res [fconfigure $f -seekcfg]
    close $f
    set res
} [82 {ratioNatural {1 2} ratioChosen {1 2} overideAllowed 1 identityForced 0} {ratioNatural {1 2} ratioChosen {0 0} overideAllowed 0 identityForced 0}]

test seek-1.6 {chosen policy, transform mixture, seekable base} {
    set f [open seektests r]
    ascii85 -attach $f -mode encode
    hex     -attach $f -mode encode
    set res [fconfigure $f -seekcfg]
    close $f
    set res
} {ratioNatural {1 2} ratioChosen {0 0} overideAllowed 0 identityForced 0}

test seek-1.7 {chosen policy, seekable transforms, unseekable base} {
    set f [socket localhost $eport]
    base64 -attach $f -mode encode
    hex    -attach $f -mode encode
    set res [fconfigure $f -seekcfg]
    close $f
    set res
} {ratioNatural {1 2} ratioChosen {0 0} overideAllowed 0 identityForced 0}

test seek-1.8 {chosen policy, transform mixture, unseekable base} {
    set f [socket localhost $eport]
    ascii85 -attach $f -mode encode
    hex     -attach $f -mode encode
    set res [fconfigure $f -seekcfg]
    close $f
    set res
} {ratioNatural {1 2} ratioChosen {0 0} overideAllowed 0 identityForced 0}

if {[82 1 0]} {
    test seek-1.9 {chosen policy, all seekable, force identity} {
	set f [open seektests r]
	hex -attach $f -mode encode -seekpolicy identity
	set res [fconfigure $f -seekstate]
	close $f
	set res
    } {seekable 1 ratio {1 1} up 0 upBufStart 0 upBufEnd 0 down 0 downBase 0 downAhead 0 changed 0}

    test seek-1.10 {chosen policy, all seekable, force unseekable} {
	set f [open seektests r]
	hex -attach $f -mode encode -seekpolicy unseekable
	set res [fconfigure $f -seekstate]
	close $f
	set res
    } {seekable 0 ratio {0 0} up 0 upBufStart 0 upBufEnd 0 down 0 downBase 0 downAhead 0 changed 0}
}

test seek-1.11 {chosen policy, all seekable, force error} {
    set f [open seektests r]
    catch {hex -attach $f -mode encode -seekpolicy unseek} res
    close $f
    set res
} [82 {Invalid value "unseek", must be one of 'unseekable', 'identity' or ''.} {It is not allowed to overide the seek policy used by this channel.}]

test seek-1.12 {chosen policy, unseekables, force error} {
    set f [open seektests r]
    ascii85 -attach $f -mode encode
    catch {hex -attach $f -mode encode -seekpolicy identity} res
    close $f
    set res
} {It is not allowed to overide the seek policy used by this channel.}



# ----------------------------------------------------------------------
# check seek restrictions set upon transforming and unseekable transforms.

test seek-2.0 {seeking behind start of stream} {

    set f [open seektests r]
    hex -attach $f -mode decode

    catch {seek $f -1} res
    close $f
    regsub $f $res XXXX res
    set res
} {error during seek on "XXXX": invalid argument}

test seek-2.1 {seeking relative to the end} {

    set f [open seektests r]
    hex -attach $f -mode decode

    catch {seek $f 0 end} res
    close $f
    regsub $f $res XXXX res
    set res
} {error during seek on "XXXX": invalid argument}

test seek-2.2 {seeking modulo numBytesTransform} {

    set f [open seektests r]
    hex -attach $f -mode decode

    catch {seek $f 1 cur} res
    close $f
    regsub $f $res XXXX res
    set res
} {error during seek on "XXXX": invalid argument}

test seek-2.3 {seeking modulo numBytesTransform} {

    set f [open seektests r]
    hex -attach $f -mode decode
    read $f 1
    set fail [catch {seek $f 2 cur} res]
    close $f
    regsub $f $res XXXX res
    set res
} {error during seek on "XXXX": invalid argument}

test seek-2.4 {seeking the unseekable} {

    set f [socket localhost $eport]
    hex -attach $f -mode decode

    catch {seek $f 1} res
    close $f
    regsub $f $res XXXX res
    set res
} {error during seek on "XXXX": invalid argument}


# ----------------------------------------------------------------------
# check seek behaviour (discarding buffers, et. al).

test seek-3.0 {picking up the base} {

    set f [open seektests r]
    read $f 3
    hex -attach $f -mode decode
    set res [fconfigure $f -seekstate]
    close $f
    set res
} [82 {seekable 1 ratio {2 1} up 0 upBufStart 0 upBufEnd 0 down 3 downBase 3 downAhead 0 changed 0} {seekable 0 ratio {0 0} up 0 upBufStart 0 upBufEnd 0 down 0 downBase 0 downAhead 0 changed 0}]

test seek-3.1 {picking up the base, read ahead} {

    set f [open seektests r]
    read $f 3
    hex -attach $f -mode decode
    read $f 2
    set res [list [tell $f] [fconfigure $f -seekstate]]
    close $f
    set res
} [82 {2 {seekable 1 ratio {2 1} up 22 upBufStart 22 upBufEnd 22 down 14 downBase 3 downAhead 0 changed 0}} {2 {seekable 0 ratio {0 0} up 22 upBufStart 22 upBufEnd 22 down 11 downBase 0 downAhead 0 changed 0}}]

if {[82 1 0]} {
    test seek-3.2 {resync, discard buffers} {
	set f [open seektests r]
	read $f 3
	hex -attach $f -mode decode
	read $f 2
	seek $f 2 cur
	set res [list [tell $f] [fconfigure $f -seekstate]]
	close $f
	set res
    } {4 {seekable 1 ratio {2 1} up 4 upBufStart 4 upBufEnd 4 down 5 downBase 3 downAhead 0 changed 0}}
}

# ----------------------------------------------------------------------
close $echo
#::tcltest::cleanupTests