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 244 245 246 247 248 249 250 251 252 253 254 255
|
# -*- tcl -*-
#
# Testing "fumagic" (FileUtil Magic). Filetype recognizer.
#
# Sourcing this file into Tcl runs the tests and generates output for errors.
# No output means no errors were found.
#
# Copyright (c) 2005-2006 by Andreas Kupries <andreas_kupries@users.sourceforge.net>
# All rights reserved.
# -------------------------------------------------------------------------
package require tcltest
source [file join \
[file dirname [file dirname [file join [pwd] [info script]]]] \
devtools testutilities.tcl]
testsNeedTcl 8.6
testsNeedTcltest 1.0
catch {namespace delete ::fileutil::magic}
support {
useLocalFile fumagic.testsupport
useLocal rtcore.tcl fileutil::magic::rt
}
testing {
useLocal filetypes.tcl fileutil::magic::filetype
}
# -------------------------------------------------------------------------
# Now the package specific tests....
set path [makeFile {} bogus]
removeFile bogus
test fumagic.filetype-1.1 {test file non-existance} {
set res [catch {fileutil::magic::filetype $path} msg]
list $res $msg
} [list 1 "file not found: \"$path\""]
test fumagic.filetype-1.2 {test file directory} {
set f [makeDirectory fileTypeTest]
set res [catch {fileutil::magic::filetype $f} msg]
regsub {file[0-9]+} $msg {fileXXX} msg
removeDirectory fileTypeTest
list $res $msg
} {0 {directory application/x-directory {}}}
test fumagic.filetype-1.3 {test file empty} {
set f [makeEmptyFile]
set res [catch {fileutil::magic::filetype $f} msg]
removeEmptyFile
list $res $msg
} {0 {}}
test fumagic.filetype-1.4 {test simple binary} {
set f [makeBinFile]
set res [catch {fileutil::magic::filetype $f} msg]
removeBinFile
list $res $msg
} {0 {}}
test fumagic.filetype-1.5 {test elf executable} {
set f [makeElfFile]
set res [catch {fileutil::magic::filetype $f} msg]
removeElfFile
list $res $msg
} {0 {{ELF 32-bit LSB executable, (SYSV)} {application x-executable} {}}}
test fumagic.filetype-1.6 {test simple text} {
set f [makeTextFile]
set res [catch {fileutil::magic::filetype $f} msg]
removeTextFile
list $res $msg
} {0 {}}
test fumagic.filetype-1.7 {test script file} {
set f [makeScriptFile]
set res [catch {fileutil::magic::filetype $f} msg]
removeScriptFile
list $res $msg
} {0 {{a {/bin/tclsh script text executable}} {} {}}}
test fumagic.filetype-1.8 {test html text} {
set f [makeHtmlFile]
set res [catch {fileutil::magic::filetype $f} msg]
removeHtmlFile
list $res $msg
} {0 {{{HTML document text}} {text html} {}}}
test fumagic.filetype-1.9 {test xml text} {
set f [makeXmlFile]
set res [catch {fileutil::magic::filetype $f} msg]
removeXmlFile
list $res $msg
} {0 {{XML {1.0 document text}} {text xml} {}}}
test fumagic.filetype-1.10 {test xml with dtd text} {
set f [makeXmlDTDFile]
set res [catch {fileutil::magic::filetype $f} msg]
removeXmlDTDFile
list $res $msg
} {0 {{XML {1.0 document text}} {text xml} {}}}
test fumagic.filetype-1.11 {
test PGP message. Their are multiple matches, and the longest match should
carry greater weight, and thus be the one returned. If the match is "PGP
armored data message", this isn't happening.
} {
set f [makePGPFile]
set res [catch {fileutil::magic::filetype $f} msg]
removePGPFile
list $res $msg
} {0 {{{PGP message}} {application pgp} {}}}
test fumagic.filetype-1.12.0 {test binary graphic jpeg} {
set f [makeJpegFile]
set res [catch {fileutil::magic::filetype $f} msg]
removeJpegFile
list $res $msg
} {0 {{{JPEG image data, JFIF standard 1.02, resolution (DPI), density 300x316, segment length 16}} {image jpeg} {jpeg jpg jpe jfif}}}
#the result should actually be 128x112, but current magic files indicate "byte" instead of "ubyte"
test fumagic.filetype-1.12.1 {test binary graphic jpeg} {
set f [makeJpeg2File]
set res [catch {fileutil::magic::filetype $f} msg]
removeJpeg2File
list $res $msg
} {0 {{{JPEG image data, JFIF standard 1.02, resolution (DPI), density 300x316, segment length 16, thumbnail -128x112}} {image jpeg} {jpeg jpg jpe jfif}}}
test fumagic.filetype-1.13 {test binary graphic gif} {
set f [makeGifFile]
set res [catch {fileutil::magic::filetype $f} msg]
removeGifFile
list $res $msg
} {0 {{{GIF image data, version 89a,} {43 x} 64} {image gif} {}}}
test fumagic.filetype-1.14 {test binary graphic png} {
set f [makePngFile]
set res [catch {fileutil::magic::filetype $f} msg]
removePngFile
list $res $msg
} {0 {{{PNG image data, 0 x} 0, 0-bit} {image png} {}}}
#{To do} {implement a "wild guess" mode}
#test fumagic.filetype-1.14.1 {test binary graphic png} {
# set f [makePngFile]
# set res [catch {fileutil::magic::filetype $f} msg]
# removePngFile
# list $res $msg
#} {0 {PNG image data, CORRUPTED, PNG image data, CORRUPTED}}
# The file doesn't really provide a direntries value, so not sure what the
# result means here, but any number is good enough for this test.
test fumagic.filetype-1.15 {test binary graphic tiff} {
set f [makeTiffFile]
set res [catch {fileutil::magic::filetype $f} msg]
removeTiffFile
list $res $msg
} {0 {{{TIFF image data, big-endian, direntries=19789}} {image tiff} {}}}
test fumagic.filetype-1.16 {test binary pdf} {
set f [makePdfFile]
set res [catch {fileutil::magic::filetype $f} msg]
removePdfFile
list $res $msg
} {0 {{{PDF document, version 1.2}} {application pdf} {}}}
test fumagic.filetype-1.17 {test text ps} {
set f [makePSFile]
set res [catch {fileutil::magic::filetype $f} msg]
removePSFile
list $res $msg
} {0 {{{PostScript document text}} {application postscript} {}}}
test fumagic.filetype-1.18 {test text eps} {
set f [makeEPSFile]
set res [catch {fileutil::magic::filetype $f} msg]
removeEPSFile
list $res $msg
} {0 {{{PostScript document text}} {application postscript} {}}}
test fumagic.filetype-1.19 {test binary gravity_wave_data_frame} {
set f [makeIgwdFile]
set res [catch {fileutil::magic::filetype $f} msg]
removeIgwdFile
list $res $msg
} {0 {}}
test fumagic.filetype-1.20 {test binary compressed bzip} {
set f [makeBzipFile]
set res [catch {fileutil::magic::filetype $f} msg]
removeBzipFile
list $res $msg
} {0 {{{bzip2 compressed data, block size = 900k}} {application x-bzip2} {}}}
test fumagic.filetype-1.21 {test binary compressed gzip} {
set f [makeGzipFile]
set res [catch {fileutil::magic::filetype $f} msg]
removeGzipFile
list $res $msg
} {0 {{{gzip compressed data, reserved method, ASCII, last modified: 1}} {application x-gzip} {}}}
test fumagic.filetype-1.22 {test pstring} {
set f [makeWsdlFile]
set res [catch {fileutil::magic::filetype $f} msg]
removeWsdlFile
list $res $msg
} {0 {{{PHP WSDL cache,} {version 0x03, created 7, uri: "hello", source: "some source", target_ns: "and a target"}} {} {}}}
test fumagic.filetype-1.23 {regular expressions} {
set f [makeCSourceFile]
set res [catch {fileutil::magic::filetype $f} msg]
removeCSourceFile
list $res $msg
} {0 {{{C source text}} {text x-c} {}}}
test fumagic.filetype-1.24 {ustring} {
set f [makeXzFile]
set res [catch {fileutil::magic::filetype $f} msg]
removeXzFile
list $res $msg
} {0 {{{XZ compressed data}} {application x-xz} {}}}
test fumagic.filetype-1.25 {
tests negative relative offsets
} {
set f [makePdf2File]
set res [catch {fileutil::magic::filetype $f} msg]
removePdf2File
list $res $msg
} {0 {{{PDF document, version 1.3}} {application pdf} {}}}
test fumagic.filetype-1.26 {
Tests comparisons against the empty string when a file is malformed or
missing data at specified offsets.
} {
set f [makePeFile]
set res [catch {fileutil::magic::filetype $f} msg]
removePeFile
list $res $msg
} {0 {{{MS-DOS executable}} {application x-dosexec} {}}}
test fumagic.filetype-1.27 {
Tests indirect offsets, as well as the "default" test type.
} {
set f [makePe2File]
set res [catch {fileutil::magic::filetype $f} msg]
removePe2File
list $res $msg
} {0 {{{PE32 executable} (GUI) {Intel 80386, for MS Windows}} {application x-dosexec} {}}}
testsuiteCleanup
return
|