File: filetype.test

package info (click to toggle)
tcllib 1.20%2Bdfsg-1
  • links: PTS
  • area: main
  • in suites: bullseye
  • size: 68,064 kB
  • sloc: tcl: 216,842; ansic: 14,250; sh: 2,846; xml: 1,766; yacc: 1,145; pascal: 881; makefile: 107; perl: 84; f90: 84; python: 33; ruby: 13; php: 11
file content (217 lines) | stat: -rw-r--r-- 6,094 bytes parent folder | download | duplicates (4)
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
# -*- tcl -*-
# Tests for the find function.
#
# Sourcing this file into Tcl runs the tests and generates output for errors.
# No output means no errors were found.
#
# Copyright (c) 1998-2000 by Ajuba Solutions.
# Copyright (c) 2001 by ActiveState Tool Corp.
# Copyright (c) 2005-2007,2017 by Andreas Kupries <andreas_kupries@users.sourceforge.net>
# All rights reserved.

# -------------------------------------------------------------------------

source [file join \
	[file dirname [file dirname [file join [pwd] [info script]]]] \
	devtools testutilities.tcl]

testsNeedTcl     8.5 ;# See fumagic.testsupport
testsNeedTcltest 1.0

support {
    useTcllibFile fumagic/fumagic.testsupport ; # Filetype helpers. 8.5+ (dict, apply)
    use           cmdline/cmdline.tcl cmdline
}
testing {
    useLocal fileutil.tcl fileutil
}

# -------------------------------------------------------------------------

set path [makeFile {} bogus]
removeFile bogus

# -------------------------------------------------------------------------

test fileType-1.1 {test file non-existance} {
    set res [catch {fileutil::fileType $path} msg]
    list $res $msg
} [list 1 "file not found: '$path'"]

test fileType-1.2 {test file directory} {
    set f [makeDirectory fileTypeTest]
    set res [catch {fileutil::fileType $f} msg]
    removeDirectory fileTypeTest
    list $res $msg
} [list 0 [list directory]]

test fileType-1.3 {test file empty} {
    set f [makeEmptyFile]
    set res [catch {fileutil::fileType $f} msg]
    removeEmptyFile
    list $res $msg
} [list 0 [list empty]]

test fileType-1.4 {test simple binary} {
    set f [makeBinFile]
    set res [catch {fileutil::fileType $f} msg]
    removeBinFile
    list $res $msg
} [list 0 [list binary]]

test fileType-1.5 {test elf executable} {
    set f [makeElfFile]
    set res [catch {fileutil::fileType $f} msg]
    removeElfFile
    list $res $msg
} [list 0 [list binary executable elf]]

test fileType-1.6 {test simple text} {
    set f [makeTextFile]
    set res [catch {fileutil::fileType $f} msg]
    removeTextFile
    list $res $msg
} [list 0 [list text]]

test fileType-1.7 {test script file} {
    set f [makeScriptFile]
    set res [catch {fileutil::fileType $f} msg]
    removeScriptFile
    list $res $msg
} [list 0 [list text script /bin/tclsh]]

test fileType-1.8 {test html text} {
    set f [makeHtmlFile]
    set res [catch {fileutil::fileType $f} msg]
    removeHtmlFile
    list $res $msg
} [list 0 [list text html]]

test fileType-1.9 {test xml text} {
    set f [makeXmlFile]
    set res [catch {fileutil::fileType $f} msg]
    removeXmlFile
    list $res $msg
} [list 0 [list text xml]]

test fileType-1.10 {test xml with dtd text} {
    set f [makeXmlDTDFile]
    set res [catch {fileutil::fileType $f} msg]
    removeXmlDTDFile
    list $res $msg
} [list 0 [list text xml foobar]]

test fileType-1.11 {test PGP message} {
    set f [makePGPFile]
    set res [catch {fileutil::fileType $f} msg]
    removePGPFile
    list $res $msg
} [list 0 [list text message pgp]]

test fileType-1.12 {test binary graphic jpeg} {
    set f [makeJpegFile]
    set res [catch {fileutil::fileType $f} msg]
    removeJpegFile
    list $res $msg
} [list 0 [list binary graphic jpeg jfif]]

test fileType-1.13 {test binary graphic gif} {
    set f [makeGifFile]
    set res [catch {fileutil::fileType $f} msg]
    removeGifFile
    list $res $msg
} [list 0 [list binary graphic gif]]

test fileType-1.14 {test binary graphic png} {
    set f [makePngFile]
    set res [catch {fileutil::fileType $f} msg]
    removePngFile
    list $res $msg
} [list 0 [list binary graphic png]]

test fileType-1.15 {test binary graphic tiff} {
    set f [makeTiffFile]
    set res [catch {fileutil::fileType $f} msg]
    removeTiffFile
    list $res $msg
} [list 0 [list binary graphic tiff]]

test fileType-1.16 {test binary pdf} {
    set f [makePdfFile]
    set res [catch {fileutil::fileType $f} msg]
    removePdfFile
    list $res $msg
} [list 0 [list binary pdf]]

test fileType-1.17 {test text ps} {
    set f [makePSFile]
    set res [catch {fileutil::fileType $f} msg]
    removePSFile
    list $res $msg
} [list 0 [list text ps eps]]

test fileType-1.18 {test text eps} {
    set f [makeEPSFile]
    set res [catch {fileutil::fileType $f} msg]
    removeEPSFile
    list $res $msg
} [list 0 [list text ps eps]]

test fileType-1.19 {test binary gravity_wave_data_frame} {
    set f [makeIgwdFile]
    set res [catch {fileutil::fileType $f} msg]
    removeIgwdFile
    list $res $msg
} [list 0 [list binary gravity_wave_data_frame]]

test fileType-1.20 {test binary compressed bzip} {
    set f [makeBzipFile]
    set res [catch {fileutil::fileType $f} msg]
    removeBzipFile
    list $res $msg
} [list 0 [list binary compressed bzip]]

test fileType-1.21 {test binary compressed gzip} {
    set f [makeGzipFile]
    set res [catch {fileutil::fileType $f} msg]
    removeGzipFile
    list $res $msg
} [list 0 [list binary compressed gzip]]

test fileType-1.22 {text pdf} {
    set f [asset pdf4tcl_01.pdf]
    set res [catch {fileutil::fileType $f} msg]
    list $res $msg
} [list 0 [list text pdf]]

# -------------------------------------------------------------------------

test fileType-1.23 {sqlite3, fossil repo} {
    set f [asset p.fossil]
    set res [catch {fileutil::fileType $f} msg]
    list $res $msg
} [list 0 [list binary sqlite3 fossil-repository]]

test fileType-1.24 {sqlite3, fossil checkout} {
    set f [asset p.ckout]
    set res [catch {fileutil::fileType $f} msg]
    list $res $msg
} [list 0 [list binary sqlite3 fossil-checkout]]

test fileType-1.25 {sqlite3, fossil global config} {
    set f [asset p.global]
    set res [catch {fileutil::fileType $f} msg]
    list $res $msg
} [list 0 [list binary sqlite3 fossil-global-config]]

test fileType-1.26 {sqlite3, no app} {
    set f [asset p.sqlite]
    set res [catch {fileutil::fileType $f} msg]
    list $res $msg
} [list 0 [list binary sqlite3 A00000000]]

# -------------------------------------------------------------------------

unset path
testsuiteCleanup
return