mirror of
https://github.com/rkd77/elinks.git
synced 2024-12-04 14:46:47 -05:00
Add a simple test script of the mailcap cache
It has a few nasty hacks to reduce the dependencies on defined symbols.
This commit is contained in:
parent
754d56b451
commit
1a1bf9960d
@ -6,4 +6,26 @@ OBJS-$(CONFIG_MIMETYPES) += mimetypes.o
|
|||||||
|
|
||||||
OBJS = common.o default.o
|
OBJS = common.o default.o
|
||||||
|
|
||||||
|
TEST_PROGS = \
|
||||||
|
mailcap-cache
|
||||||
|
|
||||||
|
# The dependencies are a bit funny here! I don't know why. Just remember to
|
||||||
|
# make clean before making the test. --jonas
|
||||||
|
mailcap-cache.o: mailcap.c
|
||||||
|
$(call cmd,compile,-DTEST_MAILCAP)
|
||||||
|
|
||||||
|
TESTDEPS = \
|
||||||
|
common.o \
|
||||||
|
$(top_builddir)/src/osdep/osdep.o \
|
||||||
|
$(top_builddir)/src/osdep/stub.o \
|
||||||
|
$(top_builddir)/src/util/conv.o \
|
||||||
|
$(top_builddir)/src/util/error.o \
|
||||||
|
$(top_builddir)/src/util/file.o \
|
||||||
|
$(top_builddir)/src/util/hash.o \
|
||||||
|
$(top_builddir)/src/util/memory.o \
|
||||||
|
$(top_builddir)/src/util/string.o \
|
||||||
|
$(top_builddir)/src/util/time.o
|
||||||
|
|
||||||
|
TESTDEPS-$(CONFIG_DEBUG) += $(top_builddir)/src/util/memdebug.o
|
||||||
|
|
||||||
include $(top_srcdir)/Makefile.lib
|
include $(top_srcdir)/Makefile.lib
|
||||||
|
@ -443,6 +443,8 @@ done_mailcap(struct module *module)
|
|||||||
mailcap_map_size = 0;
|
mailcap_map_size = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifndef TEST_MAILCAP
|
||||||
|
|
||||||
static int
|
static int
|
||||||
change_hook_mailcap(struct session *ses, struct option *current, struct option *changed)
|
change_hook_mailcap(struct session *ses, struct option *current, struct option *changed)
|
||||||
{
|
{
|
||||||
@ -469,6 +471,10 @@ init_mailcap(struct module *module)
|
|||||||
get_mailcap_enable() = 0;
|
get_mailcap_enable() = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#else
|
||||||
|
#define init_mailcap NULL
|
||||||
|
#endif /* TEST_MAILCAP */
|
||||||
|
|
||||||
/* The command semantics include the following:
|
/* The command semantics include the following:
|
||||||
*
|
*
|
||||||
* %s is the filename that contains the mail body data
|
* %s is the filename that contains the mail body data
|
||||||
@ -673,3 +679,108 @@ struct module mailcap_mime_module = struct_module(
|
|||||||
/* init: */ init_mailcap,
|
/* init: */ init_mailcap,
|
||||||
/* done: */ done_mailcap
|
/* done: */ done_mailcap
|
||||||
);
|
);
|
||||||
|
|
||||||
|
#ifdef TEST_MAILCAP
|
||||||
|
/* Some ugly shortcuts for getting defined symbols to work. */
|
||||||
|
int default_mime_backend,
|
||||||
|
install_signal_handler,
|
||||||
|
mimetypes_mime_backend;
|
||||||
|
struct list_head terminals;
|
||||||
|
|
||||||
|
void die(const char *msg, ...)
|
||||||
|
{
|
||||||
|
va_list args;
|
||||||
|
|
||||||
|
if (msg) {
|
||||||
|
va_start(args, msg);
|
||||||
|
vfprintf(stderr, msg, args);
|
||||||
|
fputs("\n", stderr);
|
||||||
|
va_end(args);
|
||||||
|
}
|
||||||
|
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
main(int argc, char *argv[])
|
||||||
|
{
|
||||||
|
unsigned char *format = "description,ask,block,program";
|
||||||
|
int has_gotten = 0;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
for (i = 1; i < argc; i++) {
|
||||||
|
char *arg = argv[i];
|
||||||
|
|
||||||
|
if (strncmp(arg, "--", 2))
|
||||||
|
break;
|
||||||
|
|
||||||
|
arg += 2;
|
||||||
|
|
||||||
|
if (!strncmp(arg, "path", 4)) {
|
||||||
|
arg += 4;
|
||||||
|
if (*arg == '=') {
|
||||||
|
arg++;
|
||||||
|
get_mailcap_path() = arg;
|
||||||
|
} else {
|
||||||
|
i++;
|
||||||
|
if (i >= argc)
|
||||||
|
die("--path expects a parameter");
|
||||||
|
get_mailcap_path() = argv[i];
|
||||||
|
}
|
||||||
|
done_mailcap(NULL);
|
||||||
|
|
||||||
|
} else if (!strncmp(arg, "format", 6)) {
|
||||||
|
arg += 6;
|
||||||
|
if (*arg == '=') {
|
||||||
|
arg++;
|
||||||
|
format = arg;
|
||||||
|
} else {
|
||||||
|
i++;
|
||||||
|
if (i >= argc)
|
||||||
|
die("--format expects a parameter");
|
||||||
|
format = argv[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
} else if (!strncmp(arg, "get", 3)) {
|
||||||
|
struct mime_handler *handler;
|
||||||
|
|
||||||
|
arg += 3;
|
||||||
|
if (*arg == '=') {
|
||||||
|
arg++;
|
||||||
|
} else {
|
||||||
|
i++;
|
||||||
|
if (i >= argc)
|
||||||
|
die("--get expects a parameter");
|
||||||
|
arg = argv[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (has_gotten)
|
||||||
|
printf("\n");
|
||||||
|
has_gotten = 1;
|
||||||
|
printf("type: %s\n", arg);
|
||||||
|
handler = get_mime_handler_mailcap(arg, 0);
|
||||||
|
if (!handler) continue;
|
||||||
|
|
||||||
|
if (strstr(format, "description"))
|
||||||
|
printf("description: %s\n", handler->description);
|
||||||
|
|
||||||
|
if (strstr(format, "ask"))
|
||||||
|
printf("ask: %d\n", handler->ask);
|
||||||
|
|
||||||
|
if (strstr(format, "block"))
|
||||||
|
printf("block: %d\n", handler->block);
|
||||||
|
|
||||||
|
if (strstr(format, "program"))
|
||||||
|
printf("program: %s\n", handler->program);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
die("Unknown argument '%s'", arg - 2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
done_mailcap(NULL);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif /* TEST_MAILCAP */
|
||||||
|
95
src/mime/backend/test-mailcap-cache
Executable file
95
src/mime/backend/test-mailcap-cache
Executable file
@ -0,0 +1,95 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
#
|
||||||
|
# Copyright (c) 2005 Jonas Fonseca
|
||||||
|
#
|
||||||
|
|
||||||
|
test_description='Test mailcap parsing and querying
|
||||||
|
|
||||||
|
This tests the parsing of various mailcap files, if they are
|
||||||
|
"prioritised" correctly, if the test are run correctly and
|
||||||
|
if querying returns the expected mailcap entry.
|
||||||
|
'
|
||||||
|
|
||||||
|
. "$TEST_LIB"
|
||||||
|
|
||||||
|
# Set PAGER to something recognisable since it gets appended as
|
||||||
|
# "|copiousoutput_handler" to entries with copiousoutput.
|
||||||
|
export PAGER=copiousoutput_handler
|
||||||
|
|
||||||
|
################################################################
|
||||||
|
# Parse a simple mailcap file
|
||||||
|
|
||||||
|
cat > mailcap-basic <<EOF
|
||||||
|
# Mimetype Handler
|
||||||
|
text/html; elinks --force-html %s; needsterminal
|
||||||
|
text/enriched; richtext ; copiousoutput
|
||||||
|
text/*; view %s; needsterminal
|
||||||
|
application/postscript; ps2ascii %s ; copiousoutput
|
||||||
|
|
||||||
|
# Convert images to text using the netpbm tools
|
||||||
|
image/*; (anytopnm %s | pnmscale -xysize 200 150 | \
|
||||||
|
pnminvert | ppmtopgm | pgmtopbm | \
|
||||||
|
pbmtoascii -1x2 ) 2>&1 ; copiousoutput
|
||||||
|
EOF
|
||||||
|
|
||||||
|
mailcap-cache \
|
||||||
|
--path "mailcap-basic" \
|
||||||
|
--format "block,program" \
|
||||||
|
--get "text/html" \
|
||||||
|
--get "text/x-csh" \
|
||||||
|
--get "application/postscript" \
|
||||||
|
--get "application/foo" \
|
||||||
|
> output
|
||||||
|
|
||||||
|
cat > expected <<EOF
|
||||||
|
type: text/html
|
||||||
|
block: 1
|
||||||
|
program: elinks --force-html %
|
||||||
|
|
||||||
|
type: text/x-csh
|
||||||
|
block: 1
|
||||||
|
program: view %
|
||||||
|
|
||||||
|
type: application/postscript
|
||||||
|
block: 1
|
||||||
|
program: ps2ascii %|copiousoutput_handler
|
||||||
|
|
||||||
|
type: application/foo
|
||||||
|
EOF
|
||||||
|
|
||||||
|
test_expect_success \
|
||||||
|
'Parse simple mailcap file.' \
|
||||||
|
'cmp output expected' \
|
||||||
|
|
||||||
|
################################################################
|
||||||
|
# Parse a two simple mailcap files; first one with tests
|
||||||
|
|
||||||
|
touch DISPLAY
|
||||||
|
|
||||||
|
cat > mailcap-simple-with-test <<EOF
|
||||||
|
application/postscript; gv %s ; test=test -e "DISPLAY" ;
|
||||||
|
image/*; xzgv %s ; test=test -e "DISPLAY";
|
||||||
|
EOF
|
||||||
|
|
||||||
|
mailcap-cache \
|
||||||
|
--path "mailcap-simple-with-test:mailcap-simple" \
|
||||||
|
--format "block,program" \
|
||||||
|
--get "image/jpeg" \
|
||||||
|
--get "application/postscript" \
|
||||||
|
> output
|
||||||
|
|
||||||
|
cat > expected <<EOF
|
||||||
|
type: image/jpeg
|
||||||
|
block: 0
|
||||||
|
program: xzgv %
|
||||||
|
|
||||||
|
type: application/postscript
|
||||||
|
block: 0
|
||||||
|
program: gv %
|
||||||
|
EOF
|
||||||
|
|
||||||
|
test_expect_success \
|
||||||
|
'Parse two simple mailcap files; first one with tests.' \
|
||||||
|
'cmp output expected' \
|
||||||
|
|
||||||
|
test_done
|
Loading…
Reference in New Issue
Block a user