summaryrefslogtreecommitdiff
path: root/mimeview/tests/testsuite.at
blob: 971b1a211ae4550bbf9acaa65f1ad94ef21deaff (plain)
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
# This file is part of GNU Mailutils. -*- Autotest -*-
# Copyright (C) 2017 Free Software Foundation, Inc.
#
# GNU Mailutils is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 3, or (at
# your option) any later version.
#
# GNU Mailutils is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>.

m4_include([testsuite.inc])

dnl ------------------------------------------------------------
dnl MIMEVIEW_OPTIONS  -- default options for mimeview
m4_pushdef([MIMEVIEW_OPTIONS],[--no-site --no-user])

m4_pushdef([__prepare_input],[
m4_if([$1],[],[],[bf $1 $2
__prepare_input(m4_shift(m4_shift(m4_shift($@))))])])

m4_pushdef([prepare_input],[__prepare_input(m4_shift(m4_shift($@)))])

m4_pushdef([__select_args],[dnl
m4_if([$2],[],[$1],[dnl
__select_args([$1 $2], m4_shift(m4_shift(m4_shift(m4_shift($@)))))])])

m4_pushdef([select_args],[__select_args([],m4_shift(m4_shift($@)))])

m4_pushdef([__build_expect],[dnl
m4_if([$2],[],[$1],[__build_expect([dnl
$1[]dnl
$2: $4
],m4_shift(m4_shift(m4_shift(m4_shift($@)))))])])

m4_pushdef([build_expect],[__build_expect([],m4_shift(m4_shift($@)))])

# MIMETEST(NAME,TYPES,FILE,CONTENT,RES)
m4_pushdef([MIMETEST],[
AT_SETUP([$1])
AT_KEYWORDS([mimeview])
AT_CHECK([
AT_DATA([mime.types],[$2
])
prepare_input($@)
mimeview MIMEVIEW_OPTIONS --identify -f mime.types select_args($@)
],
[0],
[build_expect($@)])
AT_CLEANUP
])

dnl ------------------------------------------------------------

AT_INIT
AT_TESTED([mimeview])
MUT_VERSION([mimeview])

MIMETEST([default],
[application/octet-stream],
[input], [], [application/octet-stream])

MIMETEST([suffixes],
[foo/x-bar bar baz
foo/x-qux qux quux
],
[a.bar], [], [foo/x-bar],
[a.baz], [], [foo/x-bar],
[a.quux], [], [foo/x-qux],
[a.qx], [], [unknown])

MIMETEST([default ordering],
[text/foo bar
text/bar bar
],
[a.bar], [], [text/bar])

MIMETEST([priority],
[text/bar bar
text/foo bar priority(20)
],
[a.bar], [], [text/foo])

AT_BANNER([Functions])

#   match("pattern")                    Pattern match on filename
MIMETEST([match],
[application/x-csource	match(*.c)
],
[a.c],[],[application/x-csource],
[a.c1],[],[unknown])

#   ascii(offset,length)                True if bytes are valid printable ASCII
#                                       (CR, NL, TAB, BS, 32-126)
MIMETEST([ascii],
[application/x-bar	ascii(16,6)
],
[one],[-seek 16 -string foobar -int 100],[application/x-bar],
[two],[-seek 16 -string fooba -byte 129],[unknown])

#   printable(offset,length)            True if bytes are printable 8-bit chars
#                                       (CR, NL, TAB, BS, 32-126, 128-254)
MIMETEST([printable],
[application/x-bar	printable(16,6)
],
[one],[-seek 16 -string foobar -int 100],[application/x-bar],
[two],[-seek 16 -string fooba -byte 129],[application/x-bar],
[three],[-seek 16 -string fooba -byte 127],[unknown])

#   regex(offset,"regex")               True if bytes match regular expression
MIMETEST([regex],
[application/pdf    regex(0,^[[\n\r]]*%PDF)
],
[one],[-byte 10 -byte 10 -byte 13 -byte 10 -string %PDF],[application/pdf],
[two],[-byte 10 -byte 10 -byte 13 -byte 7 -string %PDF],[unknown])

#   string(offset,"string")             True if bytes are identical to string
MIMETEST([string],
[application/x-foo  string(5,FOO)
],
[one],[-seek 5 -string FOO],[application/x-foo],
[two],[-seek 4 -string FOO],[unknown])

#   istring(offset,"string")            True if bytes are identical to
#                                       case-insensitive string
MIMETEST([istring],
[application/x-foo  istring(5,FOO)
],
[one],[-seek 5 -string foO],[application/x-foo],
[two],[-seek 4 -string FOO],[unknown])

#   char(offset,value)                  True if byte is identical
MIMETEST([char],
[application/x-foo  char(5,15)
],
[one],[-seek 5 -byte 15],[application/x-foo],
[two],[-seek 5 -byte 1],[unknown])

#   short(offset,value)                 True if 16-bit integer is identical
MIMETEST([short],
[application/x-foo  short(5,1600)
],
[one],[-seek 5 -short 1600],[application/x-foo],
[two],[-seek 5 -short 1601],[unknown])

#   int(offset,value)                   True if 32-bit integer is identical
MIMETEST([int],
[application/x-foo  int(5,16578)
],
[one],[-seek 5 -int 16578],[application/x-foo],
[two],[-seek 5 -int 16579],[unknown])

#   locale("string")                    True if current locale matches string
# FIXME

#   contains(offset,range,"string")     True if the range contains the string
MIMETEST([contains],
[application/x-foo contains(10,1024,"TESTSTRING")
],
[one],[-seek 512 -string TESTSTRING],[application/x-foo],
[two],[-seek 512 -string TEST],[unknown])

MIMETEST([argument strings],
[application/x-foo string(0,"FOO")
application/x-bar string(0,'B A R')
application/x-baz string(0,"B A"Z<1B0103>BAZ)
application/x-qux string(0,<1B>45" Q "<01>)
],
[one],[-string FOO],[application/x-foo],
[two],[-string 'B A R'],[application/x-bar],
[three],[-string "B AZ" -byte 0x1b -byte 0x01 -byte 0x03 -string BAZ],[application/x-baz],
[four],[-byte 0x1b -string '45 Q ' -byte 0x01],[application/x-qux])

MIMETEST([logical or],
[text/x-bar bar baz string(0,bar) printable(3,10)
],
[one.bar],[],[text/x-bar],
[one.baz],[],[text/x-bar],
[foo],[-string bar],[text/x-bar],
[bar],[-seek 3 -string teststring],[text/x-bar],
[baz],[-seek 3 -string test -byte 0 -string tring],[unknown])

MIMETEST([logical and],
[text/x-foo bar + string(0,bar<10>) + printable(4,10)
],
[one.bar],[-string bar -byte 0x10 -string TESTSTRING],[text/x-foo],
[one],[-string bar -byte 0x10 -string TESTSTRING],[unknown],
[two.bar],[-string bar -byte 0x13 -byte 0x10 -string TEST],[unknown])

MIMETEST([grouping],
[text/x-foo bar (string(0,bar) + printable(4,10))
],
[one.bar],[-string foo],[text/x-foo],
[two.baz],[-string bar -byte 0x10 -string TESTSTRING],[text/x-foo],
[three],[-string bar -byte 0x13 -byte 0x10 -string TESTSTRING],[unknown])

Return to:

Send suggestions and report system problems to the System administrator.