diff options
Diffstat (limited to 'mimeview/tests/testsuite.at')
-rw-r--r-- | mimeview/tests/testsuite.at | 200 |
1 files changed, 200 insertions, 0 deletions
diff --git a/mimeview/tests/testsuite.at b/mimeview/tests/testsuite.at new file mode 100644 index 000000000..971b1a211 --- /dev/null +++ b/mimeview/tests/testsuite.at @@ -0,0 +1,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]) |