Commit 4e7f5b5c 4e7f5b5c08095818d7876a86ad6657c57c9a8ad1 by Sergey Poznyakoff

Fix logstream to support mu_locus_range.

* include/mailutils/locus.h (mu_stream_print_locus_range)
(mu_stream_vlprintf, mu_stream_lprintf, mu_lrange_debug): New protos.
* include/mailutils/stream.h (MU_IOCTL_LOGSTREAM_GET_LOCUS_RANGE)
(MU_IOCTL_LOGSTREAM_SET_LOCUS_RANGE): New ioctls.
* include/mailutils/sys/logstream.h (_mu_log_stream): Replace
locus with struct mu_locus_range locrange.
* libmailutils/locus/debug.c: Rewrite.
* libmailutils/locus/ident.c (mu_ident_ref): Accept NULL argument.
Fix initialization.
(mu_ident_deref): Accept NULL argument.
* libmailutils/stream/logstream.c: Rewrite.
* libmailutils/tests/.gitignore: Update.
* libmailutils/tests/Makefile.am: Add new tests.
* libmailutils/tests/testsuite.at: Likewise.
* libmailutils/tests/logstr.at: New testcase.
* libmailutils/tests/logstr.c: New file.
* libmailutils/tests/xscript.at: Minor change.
* sieve/tests/i-numeric.at: Minor change.
1 parent 7bca245a
......@@ -106,7 +106,7 @@ int mu_debug_get_iterator (mu_iterator_t *piterator, int skipunset);
if (mu_debug_line_info) \
{ \
mu_debug_log_begin ("\033X<%d>%s:%d: ", \
MU_LOGMODE_LOCUS, __FILE__, __LINE__); \
MU_LOGMODE_LOCUS, __FILE__, __LINE__); \
mu_debug_log_end s; \
} \
else \
......
......@@ -2,6 +2,7 @@
#define _MAILUTILS_LOCUS_H
#include <string.h>
#include <stdarg.h>
struct mu_locus_point
{
......@@ -49,6 +50,17 @@ void mu_locus_tracker_advance (struct mu_locus_track *trk,
char const *text, size_t leng);
void mu_locus_tracker_retreat (struct mu_locus_track *trk, size_t n);
void mu_stream_print_locus_range (mu_stream_t stream,
struct mu_locus_range const *loc);
void mu_stream_vlprintf (mu_stream_t stream,
struct mu_locus_range const *loc,
char const *fmt, va_list ap);
void mu_stream_lprintf (mu_stream_t stream,
struct mu_locus_range const *loc,
char const *fmt, ...);
void mu_lrange_debug (struct mu_locus_range const *loc,
char const *fmt, ...);
#endif
......
......@@ -32,8 +32,8 @@ extern "C" {
#define MU_LOG_ALERT 6
#define MU_LOG_EMERG 7
#define MU_LOGMODE_SEVERITY 0x0001
#define MU_LOGMODE_LOCUS 0x0002
#define MU_LOGMODE_SEVERITY 0x0001
#define MU_LOGMODE_LOCUS 0x0002
int mu_log_stream_create (mu_stream_t *, mu_stream_t);
int mu_syslog_stream_create (mu_stream_t *, int);
......
......@@ -36,6 +36,7 @@
#include <mailutils/header.h>
#include <mailutils/iterator.h>
#include <mailutils/kwd.h>
/* FIXME #include <mailutils/locus.h> */
#include <mailutils/sieve.h>
#include <mailutils/list.h>
#include <mailutils/locker.h>
......
......@@ -83,7 +83,7 @@ enum mu_buffer_type
/* Opcodes common for various families */
#define MU_IOCTL_OP_GET 0
#define MU_IOCTL_OP_SET 1
/* Opcodes for MU_IOCTL_PROGSTREAM */
#define MU_IOCTL_PROG_STATUS 0
#define MU_IOCTL_PROG_PID 1
......@@ -158,6 +158,15 @@ enum mu_buffer_type
Arg: mu_stream_t*
*/
#define MU_IOCTL_LOGSTREAM_CLONE 14
/* Get locus range.
Arg: struct mu_locus_range *
*/
#define MU_IOCTL_LOGSTREAM_GET_LOCUS_RANGE 15
/* Set locus range.
Arg: struct mu_locus_range *
*/
#define MU_IOCTL_LOGSTREAM_SET_LOCUS_RANGE 16
/* Opcodes for MU_IOCTL_XSCRIPTSTREAM */
/* Swap transcript levels.
......
......@@ -19,6 +19,7 @@
#include <mailutils/types.h>
#include <mailutils/sys/stream.h>
#include <mailutils/locus.h>
struct _mu_log_stream
{
......@@ -30,7 +31,7 @@ struct _mu_log_stream
int logmode; /* Mode flags */
int sevmask; /* Mask out the output of severity level for
these severities. */
struct mu_locus locus; /* Location */
struct mu_locus_range locrange; /* Location in the source file */
};
void _mu_log_stream_setup (struct _mu_log_stream *sp, mu_stream_t transport);
......
......@@ -9,12 +9,78 @@
#include <mailutils/stdstream.h>
void
mu_stream_print_locus_range (mu_stream_t stream,
struct mu_locus_range const *loc)
{
if (loc->beg.mu_col == 0)
{
if (loc->end.mu_file
&& (!mu_locus_point_same_file (&loc->beg, &loc->end)
|| loc->beg.mu_line != loc->end.mu_line))
mu_stream_printf (stream, "%s:%u-%u",
loc->beg.mu_file,
loc->beg.mu_line,
loc->end.mu_line);
else
mu_stream_printf (stream, "%s:%u",
loc->beg.mu_file,
loc->beg.mu_line);
}
else
{
if (loc->end.mu_file
&& !mu_locus_point_same_file (&loc->beg, &loc->end))
mu_stream_printf (stream, "%s:%u.%u-%s:%u.%u",
loc->beg.mu_file,
loc->beg.mu_line, loc->beg.mu_col,
loc->end.mu_file,
loc->end.mu_line, loc->end.mu_col);
else if (loc->end.mu_file && loc->beg.mu_line != loc->end.mu_line)
mu_stream_printf (stream, "%s:%u.%u-%u.%u",
loc->beg.mu_file,
loc->beg.mu_line, loc->beg.mu_col,
loc->end.mu_line, loc->end.mu_col);
else if (loc->end.mu_file && loc->beg.mu_col != loc->end.mu_col)
mu_stream_printf (stream, "%s:%u.%u-%u",
loc->beg.mu_file,
loc->beg.mu_line, loc->beg.mu_col,
loc->end.mu_col);
else
mu_stream_printf (stream, "%s:%u.%u",
loc->beg.mu_file,
loc->beg.mu_line, loc->beg.mu_col);
}
}
void
mu_stream_vlprintf (mu_stream_t stream,
struct mu_locus_range const *loc,
char const *fmt, va_list ap)
{
mu_stream_print_locus_range (stream, loc);
mu_stream_write (stream, ": ", 2, NULL);
mu_stream_vprintf (mu_strerr, fmt, ap);
mu_stream_write (stream, "\n", 1, NULL);
}
void
mu_stream_lprintf (mu_stream_t stream,
struct mu_locus_range const *loc,
char const *fmt, ...)
{
va_list ap;
va_start (ap, fmt);
mu_stream_vlprintf (stream, loc, fmt, ap);
va_end (ap);
}
void
mu_lrange_debug (struct mu_locus_range const *loc,
char const *fmt, ...)
{
va_list ap;
int rc, mode;
rc = mu_stream_ioctl (mu_strerr, MU_IOCTL_LOGSTREAM,
MU_IOCTL_LOGSTREAM_GET_MODE, &mode);
if (rc == 0)
......@@ -23,37 +89,13 @@ mu_lrange_debug (struct mu_locus_range const *loc,
rc = mu_stream_ioctl (mu_strerr, MU_IOCTL_LOGSTREAM,
MU_IOCTL_LOGSTREAM_SET_MODE, &new_mode);
}
if (loc->beg.mu_col == 0)
mu_debug_log_begin ("%s:%u", loc->beg.mu_file, loc->beg.mu_line);
else if (!mu_locus_point_same_file (&loc->beg, &loc->end))
mu_debug_log_begin ("%s:%u.%u-%s:%u.%u",
loc->beg.mu_file,
loc->beg.mu_line, loc->beg.mu_col,
loc->end.mu_file,
loc->end.mu_line, loc->end.mu_col);
else if (loc->beg.mu_line != loc->end.mu_line)
mu_debug_log_begin ("%s:%u.%u-%u.%u",
loc->beg.mu_file,
loc->beg.mu_line, loc->beg.mu_col,
loc->end.mu_line, loc->end.mu_col);
else if (loc->beg.mu_col != loc->end.mu_col)
mu_debug_log_begin ("%s:%u.%u-%u",
loc->beg.mu_file,
loc->beg.mu_line, loc->beg.mu_col,
loc->end.mu_col);
else
mu_debug_log_begin ("%s:%u.%u",
loc->beg.mu_file,
loc->beg.mu_line, loc->beg.mu_col);
mu_stream_write (mu_strerr, ": ", 2, NULL);
va_start (ap, fmt);
mu_stream_vprintf (mu_strerr, fmt, ap);
mu_stream_lprintf (mu_strerr, loc, fmt, ap);
va_end (ap);
mu_debug_log_nl ();
if (rc == 0)
mu_stream_ioctl (mu_strerr, MU_IOCTL_LOGSTREAM,
MU_IOCTL_LOGSTREAM_SET_MODE, &mode);
}
......
......@@ -20,10 +20,13 @@ mu_ident_ref (char const *name, char const **refname)
int rc;
struct mu_ident_ref *ref, **refptr;
if (!name)
return EINVAL;
if (!refname)
return MU_ERR_OUT_PTR_NULL;
if (!name)
{
*refname = NULL;
return 0;
}
if (!nametab)
{
......@@ -46,6 +49,7 @@ mu_ident_ref (char const *name, char const **refname)
mu_assoc_remove (nametab, name);
return rc;
}
*refptr = ref;
ref->count = 0;
break;
......@@ -68,9 +72,7 @@ mu_ident_deref (char const *name)
struct mu_ident_ref *ref;
int rc;
if (!name)
return EINVAL;
if (!nametab)
if (!name || !nametab)
return 0;
rc = mu_assoc_lookup (nametab, name, &ref);
......
......@@ -30,6 +30,7 @@
#include <mailutils/nls.h>
#include <mailutils/stream.h>
#include <mailutils/debug.h>
#include <mailutils/locus.h>
#include <mailutils/sys/logstream.h>
char *_mu_severity_str[] = {
......@@ -69,25 +70,77 @@ mu_severity_to_string (unsigned n, const char **pstr)
return 0;
}
static void
lr_set_line (struct mu_locus_range *loc, unsigned val, int end)
{
if (end)
loc->end.mu_line = val;
else
loc->beg.mu_line = val;
}
static void
lr_set_col (struct mu_locus_range *loc, unsigned val, int end)
{
if (end)
loc->end.mu_col = val;
else
loc->beg.mu_col = val;
}
static int
_locus_set_file (struct mu_locus *loc, const char *file, size_t len)
lr_set_file (struct mu_locus_range *loc, char const *fname, unsigned len,
int end)
{
free (loc->mu_file);
if (file)
char const *refname;
struct mu_locus_point *pt = end ? &loc->end : &loc->beg;
int rc;
if (fname == NULL)
{
loc->mu_file = malloc (len + 1);
if (!loc->mu_file)
return ENOMEM;
memcpy (loc->mu_file, file, len);
loc->mu_file[len] = 0;
refname = NULL;
rc = 0;
}
else if (len == 0)
rc = mu_ident_ref (fname, &refname);
else
loc->mu_file = NULL;
{
char *name;
name = malloc (len + 1);
if (!name)
return errno;
memcpy (name, fname, len);
name[len] = 0;
rc = mu_ident_ref (name, &refname);
free (name);
}
if (rc)
return rc;
mu_ident_deref (pt->mu_file);
pt->mu_file = refname;
return 0;
}
#define _locus_set_line(loc, line) ((loc)->mu_line = line)
#define _locus_set_col(loc, col) ((loc)->mu_col = col)
/* Field modification map (binary):
FfLlCc
The bits f, l, and c (file, line, and column) are toggled cyclically.
The value 0 means locus beg, 1 meand locus end.
The bits F, L, and C are set once and indicate that the corresponding
bit was toggled at least once.
*/
#define FMM_COL 0
#define FMM_LINE 1
#define FMM_FILE 2
#define FMM_SHIFT(n) ((n)<<1)
#define FMM_MASK(n) (0x3 << FMM_SHIFT (n))
#define FMM_VAL(m,n) (((m) >> FMM_SHIFT (n)) & 0x1)
#define FMM_SET(m,n,v) ((m) = ((m) & ~FMM_MASK (n)) | (((v) << FMM_SHIFT (n))|0x2))
#define FMM_CYCLE(m, n) \
FMM_SET ((m), (n), ((FMM_VAL ((m), (n)) + 1) % 2))
static int
_log_write (struct _mu_stream *str, const char *buf, size_t size,
......@@ -96,8 +149,8 @@ _log_write (struct _mu_stream *str, const char *buf, size_t size,
struct _mu_log_stream *sp = (struct _mu_log_stream *)str;
unsigned severity = sp->severity;
int logmode = sp->logmode;
struct mu_locus loc = sp->locus;
const char *fname = NULL;
struct mu_locus_range loc;
int fmm = 0;
unsigned flen = 0;
int save_locus = 0;
int rc;
......@@ -120,6 +173,10 @@ _log_write (struct _mu_stream *str, const char *buf, size_t size,
n = __x; \
} while (0)
loc = sp->locrange;
mu_ident_ref (loc.beg.mu_file, &loc.beg.mu_file);
mu_ident_ref (loc.end.mu_file, &loc.end.mu_file);
/* Tell them we've consumed everything */
*pnwrite = size;
......@@ -167,21 +224,24 @@ _log_write (struct _mu_stream *str, const char *buf, size_t size,
case 'l':
/* Input line (decimal) */
READNUM (n);
_locus_set_line (&loc, n);
lr_set_line (&loc, n, FMM_VAL (fmm, FMM_LINE));
FMM_CYCLE (fmm, FMM_LINE);
logmode |= MU_LOGMODE_LOCUS;
break;
case 'c':
/* Column in input line (decimal) */
READNUM (n);
_locus_set_col (&loc, n);
lr_set_col (&loc, n, FMM_VAL (fmm, FMM_COL));
FMM_CYCLE (fmm, FMM_COL);
logmode |= MU_LOGMODE_LOCUS;
break;
case 'f':
/* File name. Format: <N>S */
READNUM (flen);
fname = buf;
lr_set_file (&loc, buf, flen, FMM_VAL (fmm, FMM_FILE));
FMM_CYCLE (fmm, FMM_FILE);
buf += flen;
size -= flen;
logmode |= MU_LOGMODE_LOCUS;
......@@ -197,58 +257,41 @@ _log_write (struct _mu_stream *str, const char *buf, size_t size,
if (severity >= _mu_severity_num)
severity = MU_LOG_EMERG;
if (fname)
{
loc.mu_file = NULL;
_locus_set_file (&loc, fname, flen);
}
if (save_locus)
{
_locus_set_file (&sp->locus, loc.mu_file, strlen (loc.mu_file));
_locus_set_line (&sp->locus, loc.mu_line);
_locus_set_col (&sp->locus, loc.mu_col);
sp->locrange = loc;
mu_ident_ref (sp->locrange.beg.mu_file, &sp->locrange.beg.mu_file);
mu_ident_ref (sp->locrange.end.mu_file, &sp->locrange.end.mu_file);
}
if (severity < sp->threshold)
rc = 0;
else
{
if (fname)
free (loc.mu_file);
return 0;
}
mu_stream_ioctl (sp->transport, MU_IOCTL_LOGSTREAM,
MU_IOCTL_LOGSTREAM_SET_SEVERITY, &severity);
mu_stream_ioctl (sp->transport, MU_IOCTL_LOGSTREAM,
MU_IOCTL_LOGSTREAM_SET_SEVERITY, &severity);
if (logmode & MU_LOGMODE_LOCUS)
{
if (loc.mu_file)
if ((logmode & MU_LOGMODE_LOCUS) && loc.beg.mu_file)
{
mu_stream_print_locus_range (sp->transport, &loc);
mu_stream_write (sp->transport, ": ", 2, NULL);
}
if ((logmode & MU_LOGMODE_SEVERITY) &&
!(sp->sevmask & MU_DEBUG_LEVEL_MASK (severity)))
{
mu_stream_write (sp->transport, loc.mu_file,
strlen (loc.mu_file), NULL);
mu_stream_write (sp->transport, ":", 1, NULL);
if (loc.mu_line)
mu_stream_printf (sp->transport, "%u", loc.mu_line);
mu_stream_write (sp->transport, ":", 1, NULL);
if (loc.mu_col)
mu_stream_printf (sp->transport, "%u:", loc.mu_col);
mu_stream_write (sp->transport, " ", 1, NULL);
char *s = gettext (_mu_severity_str[severity]);
rc = mu_stream_write (sp->transport, s, strlen (s), NULL);
if (rc)
return rc;
mu_stream_write (sp->transport, ": ", 2, NULL);
}
rc = mu_stream_write (sp->transport, buf, size, NULL);
}
if (fname)
free (loc.mu_file);
if ((logmode & MU_LOGMODE_SEVERITY) &&
!(sp->sevmask & MU_DEBUG_LEVEL_MASK(severity)))
{
char *s = gettext (_mu_severity_str[severity]);
rc = mu_stream_write (sp->transport, s, strlen (s), NULL);
if (rc)
return rc;
mu_stream_write (sp->transport, ": ", 2, NULL);
}
return mu_stream_write (sp->transport, buf, size, NULL);
mu_ident_deref (loc.beg.mu_file);
mu_ident_deref (loc.end.mu_file);
return rc;
}
static int
......@@ -375,72 +418,133 @@ _log_ctl (struct _mu_stream *str, int code, int opcode, void *arg)
sp->logmode = *(int*)arg;
break;
case MU_IOCTL_LOGSTREAM_SET_LOCUS_RANGE:
{
struct mu_locus_range *lr = arg;
if (!arg)
{
mu_ident_deref (sp->locrange.beg.mu_file);
mu_ident_deref (sp->locrange.end.mu_file);
memset (&sp->locrange, 0, sizeof sp->locrange);
}
else
{
char const *begname, *endname;
status = mu_ident_ref (lr->beg.mu_file, &begname);
if (status)
return status;
status = mu_ident_ref (lr->end.mu_file, &endname);
if (status)
{
mu_ident_deref (begname);
return status;
}
mu_ident_deref (sp->locrange.beg.mu_file);
sp->locrange.beg.mu_file = begname;
sp->locrange.beg.mu_line = lr->beg.mu_line;
sp->locrange.beg.mu_col = lr->beg.mu_col;
mu_ident_deref (sp->locrange.end.mu_file);
sp->locrange.end.mu_file = endname;
sp->locrange.end.mu_line = lr->end.mu_line;
sp->locrange.end.mu_col = lr->end.mu_col;
}
}
break;
case MU_IOCTL_LOGSTREAM_GET_LOCUS_RANGE:
if (!arg)
return EINVAL;
else
{
struct mu_locus_range *lr = arg;
char const *begname, *endname;
status = mu_ident_ref (sp->locrange.beg.mu_file, &begname);
if (status)
return status;
status = mu_ident_ref (sp->locrange.end.mu_file, &endname);
if (status)
{
mu_ident_deref (begname);
return status;
}
lr->beg.mu_file = begname;
lr->beg.mu_line = sp->locrange.beg.mu_line;
lr->beg.mu_col = sp->locrange.beg.mu_col;
lr->end.mu_file = endname;
lr->end.mu_line = sp->locrange.end.mu_line;
lr->end.mu_col = sp->locrange.end.mu_col;
}
break;
case MU_IOCTL_LOGSTREAM_GET_LOCUS:
if (!arg)
return EINVAL;
else
{
struct mu_locus *ploc = arg;
if (sp->locus.mu_file)
if (sp->locrange.beg.mu_file)
{
ploc->mu_file = strdup (sp->locus.mu_file);
ploc->mu_file = strdup (sp->locrange.beg.mu_file);
if (!ploc->mu_file)
return ENOMEM;
}
else
ploc->mu_file = NULL;
ploc->mu_line = sp->locus.mu_line;
ploc->mu_col = sp->locus.mu_col;
ploc->mu_line = sp->locrange.beg.mu_line;
ploc->mu_col = sp->locrange.beg.mu_col;
}
break;
case MU_IOCTL_LOGSTREAM_SET_LOCUS:
{
struct mu_locus *ploc = arg;
if (!arg)
mu_ident_deref (sp->locrange.end.mu_file);
sp->locrange.end.mu_file = NULL;
if (arg)
{
free (sp->locus.mu_file);
sp->locus.mu_file = NULL;
sp->locus.mu_line = 0;
sp->locus.mu_col = 0;
status = lr_set_file (&sp->locrange, ploc->mu_file, 0, 0);
if (status)
return status;
lr_set_line (&sp->locrange, ploc->mu_line, 0);
lr_set_col (&sp->locrange, ploc->mu_col, 0);
}
else
{
if (ploc->mu_file)
_locus_set_file (&sp->locus, ploc->mu_file,
strlen (ploc->mu_file));
if (ploc->mu_line)
_locus_set_line (&sp->locus, ploc->mu_line);
if (ploc->mu_col)
_locus_set_col (&sp->locus, ploc->mu_col);
mu_ident_deref (sp->locrange.beg.mu_file);
sp->locrange.beg.mu_file = NULL;
}
break;
}
case MU_IOCTL_LOGSTREAM_SET_LOCUS_LINE:
if (!arg)
return EINVAL;
sp->locus.mu_line = *(unsigned*)arg;
sp->locrange.beg.mu_line = *(unsigned*)arg;
break;
case MU_IOCTL_LOGSTREAM_SET_LOCUS_COL:
if (!arg)
return EINVAL;
sp->locus.mu_col = *(unsigned*)arg;
sp->locrange.beg.mu_col = *(unsigned*)arg;
break;
case MU_IOCTL_LOGSTREAM_ADVANCE_LOCUS_LINE:
if (!arg)
sp->locus.mu_line++;
sp->locrange.beg.mu_line++;
else
sp->locus.mu_line += *(int*)arg;
sp->locrange.beg.mu_line += *(int*)arg;
break;
case MU_IOCTL_LOGSTREAM_ADVANCE_LOCUS_COL:
if (!arg)
sp->locus.mu_col++;
sp->locrange.beg.mu_col++;
else
sp->locus.mu_col += *(int*)arg;
sp->locrange.beg.mu_col += *(int*)arg;
break;
case MU_IOCTL_LOGSTREAM_SUPPRESS_SEVERITY:
......@@ -484,14 +588,12 @@ _log_ctl (struct _mu_stream *str, int code, int opcode, void *arg)
newp->threshold = sp->threshold;
newp->logmode = sp->logmode;
newp->sevmask = sp->sevmask;
if (sp->locus.mu_file)
{
newp->locus.mu_file = strdup (sp->locus.mu_file);
if (!newp->locus.mu_file)
return ENOMEM;
}
newp->locus.mu_line = sp->locus.mu_line;
newp->locus.mu_col = sp->locus.mu_col;
newp->locrange = sp->locrange;
mu_ident_ref (sp->locrange.beg.mu_file,
&sp->locrange.beg.mu_file);
mu_ident_ref (sp->locrange.end.mu_file,
&sp->locrange.end.mu_file);
*(mu_stream_t*) arg = str;
}
break;
......
......@@ -19,6 +19,7 @@ fsfolder
globtest
imapio
listop
logstr
mailcap
mimehdr
modmesg
......
......@@ -54,6 +54,7 @@ noinst_PROGRAMS = \
globtest\
imapio\
listop\
logstr\
mailcap\
mimehdr\
modtofsaf\
......@@ -106,6 +107,7 @@ TESTSUITE_AT = \
inline-comment.at\
linecon.at\
list.at\
logstr.at\
mailcap.at\
mimehdr.at\
modmesg00.at\
......
# 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/>.
AT_SETUP(Logger stream)
AT_KEYWORDS([logstream])
AT_CHECK([logstr],
[0],
[00. simple print
hello world
01. severity
info: one
emerg: two
mode was: 0x0001
02. suppress severity
info: this message is seen
emerg: and this one as well
03. suppress severity name
info: this message is seen
emerg: and this one as well
04. severity mask
one
two
emerg: three
05. set/get locus point
input:1: filename and line number
input:1.3: filename, line and column numbers
06. locus: file, line
input:1: file, line
07. locus: file, line, col
input:1.1-10: file, line, col
08. locus: file, line-range
input:1-2: file, line-range
09. locus: file, line-range, col
input:1.1-2.10: file, line-range, col
10. locus: file-range, line-range, col-range
input:1.1-next:2.10: file-range, line-range, col-range
11. set locus line
input:1.1-next:2.10: initial
input:8.1-next:2.10: locus line changed
12. advance locus line
input:1.1-next:5.10: initial
input:3.1-next:5.10: locus line advanced
13. set locus column
input:1.1-next:2.10: initial
input:1.8-next:2.10: locus column changed
14. advance locus column
input:1.1-next:5.10: initial
input:1.5-next:5.10: locus line advanced
15. fmt: severity
info: severity
16. fmt: locus (file, line)
a:10: one
17. fmt: locus (file, line, column)
a:10.5: one
18. fmt: locus (range)
a:10.5-b:14.8: one
19. fmt: locus; restore defaults
a:10.5-b:14.8: one
default
20. fmt: locus; restore defaults, display locus
a:10.5-b:14.8: one
input:1.1-next:5.10: default
21. fmt: set locus
a:10.5-b:14.8: one
a:10.5-b:14.8: default
])
AT_CLEANUP
\ No newline at end of file
/* This file is part of GNU Mailutils test suite
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/>. */
#include <mailutils/mailutils.h>
#include <mailutils/locus.h>
/* Check normal operation.
Expected output: hello world
*/
static void
simple_print (mu_stream_t str)
{
mu_stream_printf (str, "hello world\n");
}
/* Check severity control.
Expected output:
info: one
emerg: two
mode was: 0x0001
*/
static void
check_severity (mu_stream_t str)
{
unsigned severity = MU_DIAG_INFO;
int mode = MU_LOGMODE_SEVERITY, old_mode;
mu_stream_ioctl (str, MU_IOCTL_LOGSTREAM,
MU_IOCTL_LOGSTREAM_SET_MODE, &mode);
mu_stream_ioctl (str, MU_IOCTL_LOGSTREAM,
MU_IOCTL_LOGSTREAM_SET_SEVERITY, &severity);
mu_stream_printf (str, "one\n");
severity = MU_DIAG_EMERG;
mu_stream_ioctl (str, MU_IOCTL_LOGSTREAM,
MU_IOCTL_LOGSTREAM_SET_SEVERITY, &severity);
mu_stream_printf (str, "two\n");
mu_stream_ioctl (str, MU_IOCTL_LOGSTREAM,
MU_IOCTL_LOGSTREAM_GET_MODE, &old_mode);
mode = 0;
mu_stream_ioctl (str, MU_IOCTL_LOGSTREAM,
MU_IOCTL_LOGSTREAM_SET_MODE, &mode);
mu_stream_printf (str, "mode was: 0x%04X\n", old_mode);
}
/* Check severity suppression mechanism.
Expected output:
info: this message is seen
emerg: and this one as well
*/
static void
check_suppress (mu_stream_t str)
{
unsigned severity;
int mode = MU_LOGMODE_SEVERITY;
mu_stream_ioctl (str, MU_IOCTL_LOGSTREAM,
MU_IOCTL_LOGSTREAM_SET_MODE, &mode);
severity = MU_DIAG_INFO;
mu_stream_ioctl (str, MU_IOCTL_LOGSTREAM,
MU_IOCTL_LOGSTREAM_SUPPRESS_SEVERITY,
&severity);
severity = MU_DIAG_DEBUG;
mu_stream_ioctl (str, MU_IOCTL_LOGSTREAM,
MU_IOCTL_LOGSTREAM_SET_SEVERITY, &severity);
mu_stream_printf (str, "this message is not seen\n");
severity = MU_DIAG_INFO;
mu_stream_ioctl (str, MU_IOCTL_LOGSTREAM,
MU_IOCTL_LOGSTREAM_SET_SEVERITY, &severity);
mu_stream_printf (str, "this message is seen\n");
severity = MU_DIAG_EMERG;
mu_stream_ioctl (str, MU_IOCTL_LOGSTREAM,
MU_IOCTL_LOGSTREAM_SET_SEVERITY, &severity);
mu_stream_printf (str, "and this one as well\n");
}
/* Check suppression by severity name.
Expected output:
info: this message is seen
emerg: and this one as well
*/
static void
check_suppress_name (mu_stream_t str)
{
int mode = MU_LOGMODE_SEVERITY, severity;
mu_stream_ioctl (str, MU_IOCTL_LOGSTREAM,
MU_IOCTL_LOGSTREAM_SET_MODE, &mode);
mu_stream_ioctl (str, MU_IOCTL_LOGSTREAM,
MU_IOCTL_LOGSTREAM_SUPPRESS_SEVERITY_NAME,
"info");
severity = MU_DIAG_DEBUG;
mu_stream_ioctl (str, MU_IOCTL_LOGSTREAM,
MU_IOCTL_LOGSTREAM_SET_SEVERITY, &severity);
mu_stream_printf (str, "this message is not seen\n");
severity = MU_DIAG_INFO;
mu_stream_ioctl (str, MU_IOCTL_LOGSTREAM,
MU_IOCTL_LOGSTREAM_SET_SEVERITY, &severity);
mu_stream_printf (str, "this message is seen\n");
severity = MU_DIAG_EMERG;
mu_stream_ioctl (str, MU_IOCTL_LOGSTREAM,
MU_IOCTL_LOGSTREAM_SET_SEVERITY, &severity);
mu_stream_printf (str, "and this one as well\n");
}
/* Check setting locus point
Expected output:
input:1: filename and line number
input:1.3: filename, line and column numbers
*/
static void
set_locus_point (mu_stream_t str)
{
int mode = MU_LOGMODE_LOCUS;
struct mu_locus pt, pt2;
mu_stream_ioctl (str, MU_IOCTL_LOGSTREAM,
MU_IOCTL_LOGSTREAM_SET_MODE, &mode);
pt.mu_file = "input";
pt.mu_line = 1;
pt.mu_col = 0;
mu_stream_ioctl (str, MU_IOCTL_LOGSTREAM,
MU_IOCTL_LOGSTREAM_SET_LOCUS, &pt);
mu_stream_printf (str, "filename and line number\n");
pt.mu_file = "input";
pt.mu_line = 1;
pt.mu_col = 3;
mu_stream_ioctl (str, MU_IOCTL_LOGSTREAM,
MU_IOCTL_LOGSTREAM_SET_LOCUS, &pt);
mu_stream_printf (str, "filename, line and column numbers\n");
MU_ASSERT (mu_stream_ioctl (str, MU_IOCTL_LOGSTREAM,
MU_IOCTL_LOGSTREAM_GET_LOCUS, &pt2));
if (strcmp (pt.mu_file, pt2.mu_file))
mu_error ("%s:%d: mu_file differs\n", __FILE__, __LINE__);
if (pt.mu_line != pt2.mu_line)
mu_error ("%s:%d: mu_line differs\n", __FILE__, __LINE__);
if (pt.mu_col != pt2.mu_col)
mu_error ("%s:%d: mu_col differs\n", __FILE__, __LINE__);
/* FIXME: remove this after switching to mu_locus_point */
free (pt2.mu_file);
}
static void
comp_range (mu_stream_t str, struct mu_locus_range *lr1,
char const *file, int line)
{
struct mu_locus_range lr2;
MU_ASSERT (mu_stream_ioctl (str, MU_IOCTL_LOGSTREAM,
MU_IOCTL_LOGSTREAM_GET_LOCUS_RANGE, &lr2));
if (strcmp (lr1->beg.mu_file, lr2.beg.mu_file))
mu_error ("%s:%d: beg.mu_file differs", file, line);
if (lr1->beg.mu_line != lr2.beg.mu_line)
mu_error ("%s:%d: beg.mu_line differs", file, line);
if (lr1->beg.mu_col != lr2.beg.mu_col)
mu_error ("%s:%d: beg.mu_col differs", file, line);
mu_ident_deref (lr2.beg.mu_file);
if (strcmp (lr1->end.mu_file, lr2.end.mu_file))
mu_error ("%s:%d: end.mu_file differs", __FILE__, __LINE__);
if (lr1->end.mu_line != lr2.end.mu_line)
mu_error ("%s:%d: end.mu_line differs", __FILE__, __LINE__);
if (lr1->end.mu_col != lr2.end.mu_col)
mu_error ("%s:%d: end.mu_col differs", __FILE__, __LINE__);
mu_ident_deref (lr2.end.mu_file);
}
/* Check MU_IOCTL_LOGSTREAM_SET_LOCUS_RANGE.
Passed: file, line.
Expected output:
input:1: file, line
*/
static void
lr_file_line (mu_stream_t str)
{
int mode = MU_LOGMODE_LOCUS;
struct mu_locus_range lr;
mu_stream_ioctl (str, MU_IOCTL_LOGSTREAM,
MU_IOCTL_LOGSTREAM_SET_MODE, &mode);
lr.beg.mu_file = "input";
lr.beg.mu_line = 1;
lr.beg.mu_col = 0;
lr.end.mu_file = "input";
lr.end.mu_line = 1;
lr.end.mu_col = 0;
mu_stream_ioctl (str, MU_IOCTL_LOGSTREAM,
MU_IOCTL_LOGSTREAM_SET_LOCUS_RANGE, &lr);
mu_stream_printf (str, "file, line\n");
comp_range (str, &lr, __FILE__, __LINE__);
}
/* Check MU_IOCTL_LOGSTREAM_SET_LOCUS_RANGE.
Passed: file, line, col.
Expected output:
input:1.1-10: file, line, col
*/
static void
lr_file_line_col (mu_stream_t str)
{
int mode = MU_LOGMODE_LOCUS;
struct mu_locus_range lr;
mu_stream_ioctl (str, MU_IOCTL_LOGSTREAM,
MU_IOCTL_LOGSTREAM_SET_MODE, &mode);
lr.beg.mu_file = "input";
lr.beg.mu_line = 1;
lr.beg.mu_col = 1;
lr.end.mu_file = "input";
lr.end.mu_line = 1;
lr.end.mu_col = 10;
mu_stream_ioctl (str, MU_IOCTL_LOGSTREAM,
MU_IOCTL_LOGSTREAM_SET_LOCUS_RANGE, &lr);
mu_stream_printf (str, "file, line, col\n");
comp_range (str, &lr, __FILE__, __LINE__);
}
/* Check MU_IOCTL_LOGSTREAM_SET_LOCUS_RANGE.
Passed: file, line-range
Expected output:
input:1-2: file, line-range
*/
static void
lr_file_line2 (mu_stream_t str)
{
int mode = MU_LOGMODE_LOCUS;
struct mu_locus_range lr;
mu_stream_ioctl (str, MU_IOCTL_LOGSTREAM,
MU_IOCTL_LOGSTREAM_SET_MODE, &mode);
lr.beg.mu_file = "input";
lr.beg.mu_line = 1;
lr.beg.mu_col = 0;
lr.end.mu_file = "input";
lr.end.mu_line = 2;
lr.end.mu_col = 0;
mu_stream_ioctl (str, MU_IOCTL_LOGSTREAM,
MU_IOCTL_LOGSTREAM_SET_LOCUS_RANGE, &lr);
mu_stream_printf (str, "file, line-range\n");
comp_range (str, &lr, __FILE__, __LINE__);
}
/* Check MU_IOCTL_LOGSTREAM_SET_LOCUS_RANGE.
Passed: file, line-range, column
Expected output:
input:1.1-2.10: file, line-range, col
*/
static void
lr_file_line2_col (mu_stream_t str)
{
int mode = MU_LOGMODE_LOCUS;
struct mu_locus_range lr;
mu_stream_ioctl (str, MU_IOCTL_LOGSTREAM,
MU_IOCTL_LOGSTREAM_SET_MODE, &mode);
lr.beg.mu_file = "input";
lr.beg.mu_line = 1;
lr.beg.mu_col = 1;
lr.end.mu_file = "input";
lr.end.mu_line = 2;
lr.end.mu_col = 10;
mu_stream_ioctl (str, MU_IOCTL_LOGSTREAM,
MU_IOCTL_LOGSTREAM_SET_LOCUS_RANGE, &lr);
mu_stream_printf (str, "file, line-range, col\n");
comp_range (str, &lr, __FILE__, __LINE__);
}
/* Check MU_IOCTL_LOGSTREAM_SET_LOCUS_RANGE.
Passed: file-range, line-range, column-range
Expected output:
input:1.1-next:2.10: file-range, line-range, col-range
*/
static void
lr_file2_line_col (mu_stream_t str)
{
int mode = MU_LOGMODE_LOCUS;
struct mu_locus_range lr;
mu_stream_ioctl (str, MU_IOCTL_LOGSTREAM,
MU_IOCTL_LOGSTREAM_SET_MODE, &mode);
lr.beg.mu_file = "input";
lr.beg.mu_line = 1;
lr.beg.mu_col = 1;
lr.end.mu_file = "next";
lr.end.mu_line = 2;
lr.end.mu_col = 10;
mu_stream_ioctl (str, MU_IOCTL_LOGSTREAM,
MU_IOCTL_LOGSTREAM_SET_LOCUS_RANGE, &lr);
mu_stream_printf (str, "file-range, line-range, col-range\n");
comp_range (str, &lr, __FILE__, __LINE__);
}
/* Check MU_IOCTL_LOGSTREAM_SET_LOCUS_LINE.
Expected output:
input:1.1-next:2.10: initial
input:8.1-next:2.10: locus line changed
*/
static void
set_locus_line (mu_stream_t str)
{
int mode = MU_LOGMODE_LOCUS;
struct mu_locus_range lr;
unsigned line;
mu_stream_ioctl (str, MU_IOCTL_LOGSTREAM,
MU_IOCTL_LOGSTREAM_SET_MODE, &mode);
lr.beg.mu_file = "input";
lr.beg.mu_line = 1;
lr.beg.mu_col = 1;
lr.end.mu_file = "next";
lr.end.mu_line = 2;
lr.end.mu_col = 10;
mu_stream_ioctl (str, MU_IOCTL_LOGSTREAM,
MU_IOCTL_LOGSTREAM_SET_LOCUS_RANGE, &lr);
mu_stream_printf (str, "initial\n");
line = 8;
mu_stream_ioctl (str, MU_IOCTL_LOGSTREAM,
MU_IOCTL_LOGSTREAM_SET_LOCUS_LINE, &line);
mu_stream_printf (str, "locus line changed\n");
lr.beg.mu_line = line;
comp_range (str, &lr, __FILE__, __LINE__);
}
/* Check MU_IOCTL_LOGSTREAM_ADVANCE_LOCUS_LINE.
Expected output:
input:1.1-next:5.10: initial
input:3.1-next:5.10: locus line advanced
*/
static void
advance_locus_line (mu_stream_t str)
{
int mode = MU_LOGMODE_LOCUS;
struct mu_locus_range lr;
unsigned line;
mu_stream_ioctl (str, MU_IOCTL_LOGSTREAM,
MU_IOCTL_LOGSTREAM_SET_MODE, &mode);
lr.beg.mu_file = "input";
lr.beg.mu_line = 1;
lr.beg.mu_col = 1;
lr.end.mu_file = "next";
lr.end.mu_line = 5;
lr.end.mu_col = 10;
mu_stream_ioctl (str, MU_IOCTL_LOGSTREAM,
MU_IOCTL_LOGSTREAM_SET_LOCUS_RANGE, &lr);
mu_stream_printf (str, "initial\n");
line = 2;
mu_stream_ioctl (str, MU_IOCTL_LOGSTREAM,
MU_IOCTL_LOGSTREAM_ADVANCE_LOCUS_LINE, &line);
mu_stream_printf (str, "locus line advanced\n");
lr.beg.mu_line += line;
comp_range (str, &lr, __FILE__, __LINE__);
}
/* Check MU_IOCTL_LOGSTREAM_SET_LOCUS_COL.
Expected output:
input:1.1-next:2.10: initial
input:1.8-next:2.10: locus column changed
*/
static void
set_locus_col (mu_stream_t str)
{
int mode = MU_LOGMODE_LOCUS;
struct mu_locus_range lr;
unsigned col;
mu_stream_ioctl (str, MU_IOCTL_LOGSTREAM,
MU_IOCTL_LOGSTREAM_SET_MODE, &mode);
lr.beg.mu_file = "input";
lr.beg.mu_line = 1;
lr.beg.mu_col = 1;
lr.end.mu_file = "next";
lr.end.mu_line = 2;
lr.end.mu_col = 10;
mu_stream_ioctl (str, MU_IOCTL_LOGSTREAM,
MU_IOCTL_LOGSTREAM_SET_LOCUS_RANGE, &lr);
mu_stream_printf (str, "initial\n");
col = 8;
mu_stream_ioctl (str, MU_IOCTL_LOGSTREAM,
MU_IOCTL_LOGSTREAM_SET_LOCUS_COL, &col);
mu_stream_printf (str, "locus column changed\n");
lr.beg.mu_col = col;
comp_range (str, &lr, __FILE__, __LINE__);
}
/* Check MU_IOCTL_LOGSTREAM_ADVANCE_LOCUS_COL.
Expected output:
input:1.1-next:5.10: initial
input:1.5-next:5.10: locus line advanced
*/
static void
advance_locus_col (mu_stream_t str)
{
int mode = MU_LOGMODE_LOCUS;
struct mu_locus_range lr;
unsigned col;
mu_stream_ioctl (str, MU_IOCTL_LOGSTREAM,
MU_IOCTL_LOGSTREAM_SET_MODE, &mode);
lr.beg.mu_file = "input";
lr.beg.mu_line = 1;
lr.beg.mu_col = 1;
lr.end.mu_file = "next";
lr.end.mu_line = 5;
lr.end.mu_col = 10;
mu_stream_ioctl (str, MU_IOCTL_LOGSTREAM,
MU_IOCTL_LOGSTREAM_SET_LOCUS_RANGE, &lr);
mu_stream_printf (str, "initial\n");
col = 4;
mu_stream_ioctl (str, MU_IOCTL_LOGSTREAM,
MU_IOCTL_LOGSTREAM_ADVANCE_LOCUS_COL, &col);
mu_stream_printf (str, "locus line advanced\n");
lr.beg.mu_col += col;
comp_range (str, &lr, __FILE__, __LINE__);
}
/* Check severity mask.
Expected output:
one
two
emerg: two
*/
static void
check_severity_mask (mu_stream_t str)
{
unsigned severity;
int mode = MU_LOGMODE_SEVERITY, mask;
mu_stream_ioctl (str, MU_IOCTL_LOGSTREAM,
MU_IOCTL_LOGSTREAM_SET_MODE, &mode);
mask = MU_DEBUG_LEVEL_UPTO (MU_DIAG_NOTICE);
mu_stream_ioctl (str, MU_IOCTL_LOGSTREAM,
MU_IOCTL_LOGSTREAM_SET_SEVERITY_MASK, &mask);
severity = MU_DIAG_INFO;
mu_stream_ioctl (str, MU_IOCTL_LOGSTREAM,
MU_IOCTL_LOGSTREAM_SET_SEVERITY, &severity);
mu_stream_printf (str, "one\n");
severity = MU_DIAG_NOTICE;
mu_stream_ioctl (str, MU_IOCTL_LOGSTREAM,
MU_IOCTL_LOGSTREAM_SET_SEVERITY, &severity);
mu_stream_printf (str, "two\n");
severity = MU_DIAG_EMERG;
mu_stream_ioctl (str, MU_IOCTL_LOGSTREAM,
MU_IOCTL_LOGSTREAM_SET_SEVERITY, &severity);
mu_stream_printf (str, "three\n");
}
/* Check ESC-s & ESC-O format specifiers.
Expected output:
info: severity
*/
static void
fmt_severity (mu_stream_t str)
{
mu_stream_printf (str, "\033s<%d>\033O<%d>severity\n",
MU_DIAG_INFO, MU_LOGMODE_SEVERITY);
}
/* Check ESC-f and ESC-l format specifiers.
Expected output:
a:10: one
*/
static void
fmt_locus1 (mu_stream_t str)
{
char *file = "a";
mu_stream_printf (str, "\033f<%d>%s\033l<%d>one\n",
strlen (file), file, 10);
}
/* Check ESC-f, ESC-l, and ESC-c format specifiers.
Expected output:
a:10.5: one
*/
static void
fmt_locus2 (mu_stream_t str)
{
char *file = "a";
mu_stream_printf (str, "\033f<%d>%s\033l<%d>\033c<%d>one\n",
strlen (file), file, 10, 5);
}
/* Check setting range with ESC-f, ESC-l, and ESC-c format specifiers.
Expected output:
a:10.5-b:14.8: one
*/
static void
fmt_locus3 (mu_stream_t str)
{
char *file[] = { "a", "b" };
mu_stream_printf (str, "\033f<%d>%s\033l<%d>\033c<%d>"
"\033f<%d>%s\033l<%d>\033c<%d>one\n",
strlen (file[0]), file[0], 10, 5,
strlen (file[1]), file[1], 14, 8);
}
/* Check that ESC-f, ESC-l, and ESC-c format specifiers don't clobber
default stream settings.
Expected output:
a:10.5-b:14.8: one
default
*/
static void
fmt_locus4 (mu_stream_t str)
{
char *file[] = { "a", "b" };
struct mu_locus_range lr;
lr.beg.mu_file = "input";
lr.beg.mu_line = 1;
lr.beg.mu_col = 1;
lr.end.mu_file = "next";
lr.end.mu_line = 5;
lr.end.mu_col = 10;
mu_stream_ioctl (str, MU_IOCTL_LOGSTREAM,
MU_IOCTL_LOGSTREAM_SET_LOCUS_RANGE, &lr);
mu_stream_printf (str, "\033f<%d>%s\033l<%d>\033c<%d>"
"\033f<%d>%s\033l<%d>\033c<%d>one\n",
strlen (file[0]), file[0], 10, 5,
strlen (file[1]), file[1], 14, 8);
mu_stream_printf (str, "default\n");
}
/* Check that ESC-f, ESC-l, and ESC-c format specifiers don't clobber
default stream settings and locus.
Expected output:
a:10.5-b:14.8: one
input:1.1-next:5.10: default
*/
static void
fmt_locus5 (mu_stream_t str)
{
char *file[] = { "a", "b" };
struct mu_locus_range lr;
int mode;
lr.beg.mu_file = "input";
lr.beg.mu_line = 1;
lr.beg.mu_col = 1;
lr.end.mu_file = "next";
lr.end.mu_line = 5;
lr.end.mu_col = 10;
mu_stream_ioctl (str, MU_IOCTL_LOGSTREAM,
MU_IOCTL_LOGSTREAM_SET_LOCUS_RANGE, &lr);
mode = MU_LOGMODE_LOCUS;
mu_stream_ioctl (str, MU_IOCTL_LOGSTREAM,
MU_IOCTL_LOGSTREAM_SET_MODE, &mode);
mu_stream_printf (str, "\033f<%d>%s\033l<%d>\033c<%d>"
"\033f<%d>%s\033l<%d>\033c<%d>one\n",
strlen (file[0]), file[0], 10, 5,
strlen (file[1]), file[1], 14, 8);
mu_stream_printf (str, "default\n");
}
/* Check the ESC-S specifier (store locus).
Expected output:
a:10.5-b:14.8: one
a:10.5-b:14.8: default
*/
static void
fmt_locus6 (mu_stream_t str)
{
char *file[] = { "a", "b" };
struct mu_locus_range lr;
int mode;
lr.beg.mu_file = "input";
lr.beg.mu_line = 1;
lr.beg.mu_col = 1;
lr.end.mu_file = "next";
lr.end.mu_line = 5;
lr.end.mu_col = 10;
mu_stream_ioctl (str, MU_IOCTL_LOGSTREAM,
MU_IOCTL_LOGSTREAM_SET_LOCUS_RANGE, &lr);
mode = MU_LOGMODE_LOCUS;
mu_stream_ioctl (str, MU_IOCTL_LOGSTREAM,
MU_IOCTL_LOGSTREAM_SET_MODE, &mode);
mu_stream_printf (str, "\033S\033f<%d>%s\033l<%d>\033c<%d>"
"\033f<%d>%s\033l<%d>\033c<%d>one\n",
strlen (file[0]), file[0], 10, 5,
strlen (file[1]), file[1], 14, 8);
mu_stream_printf (str, "default\n");
}
struct testcase
{
char const *id;
void (*handler) (mu_stream_t);
};
struct testcase testcases[] = {
{ "simple print", simple_print },
{ "severity", check_severity },
{ "suppress severity", check_suppress },
{ "suppress severity name", check_suppress_name },
{ "severity mask", check_severity_mask },
{ "set/get locus point", set_locus_point },
{ "locus: file, line", lr_file_line },
{ "locus: file, line, col", lr_file_line_col },
{ "locus: file, line-range", lr_file_line2 },
{ "locus: file, line-range, col", lr_file_line2_col },
{ "locus: file-range, line-range, col-range", lr_file2_line_col },
{ "set locus line", set_locus_line },
{ "advance locus line", advance_locus_line },
{ "set locus column", set_locus_col },
{ "advance locus column", advance_locus_col },
{ "fmt: severity", fmt_severity },
{ "fmt: locus (file, line)", fmt_locus1 },
{ "fmt: locus (file, line, column)", fmt_locus2 },
{ "fmt: locus (range)", fmt_locus3 },
{ "fmt: locus; restore defaults", fmt_locus4 },
{ "fmt: locus; restore defaults, display locus", fmt_locus5 },
{ "fmt: set locus", fmt_locus6 },
{ NULL }
};
static mu_stream_t
create_log (void)
{
mu_stream_t str, transport;
int yes = 1;
MU_ASSERT (mu_stdio_stream_create (&transport, MU_STDOUT_FD, 0));
mu_stream_ioctl (transport, MU_IOCTL_FD, MU_IOCTL_FD_SET_BORROW, &yes);
MU_ASSERT (mu_log_stream_create (&str, transport));
mu_stream_unref (transport);
return str;
}
static void
log_reset (mu_stream_t str)
{
int mode = 0;
MU_ASSERT (mu_stream_ioctl (str, MU_IOCTL_LOGSTREAM,
MU_IOCTL_LOGSTREAM_SET_MODE, &mode));
MU_ASSERT (mu_stream_ioctl (str, MU_IOCTL_LOGSTREAM,
MU_IOCTL_LOGSTREAM_SET_LOCUS_RANGE, NULL));
mode = 0;
MU_ASSERT (mu_stream_ioctl (str, MU_IOCTL_LOGSTREAM,
MU_IOCTL_LOGSTREAM_SET_SEVERITY_MASK,
&mode));
}
int
main (int argc, char **argv)
{
mu_stream_t log;
struct testcase *tp;
int i;
mu_set_program_name (argv[0]);
mu_stdstream_setup (MU_STDSTREAM_RESET_NONE);
log = create_log ();
for (i = 0, tp = testcases; tp->id; tp++, i++)
{
mu_stream_printf (log, "%02d. %s\n", i, tp->id);
tp->handler (log);
log_reset (log);
}
return 0;
}
......@@ -152,6 +152,10 @@ m4_include([strin.at])
m4_include([strout.at])
m4_include([strerr.at])
AT_BANNER([Streams])
m4_include([logstr.at])
m4_include([xscript.at])
m4_include([list.at])
m4_include([address.at])
m4_include([wordsplit.at])
......@@ -208,4 +212,3 @@ m4_include([msgset.at])
m4_include([globtest.at])
m4_include([xscript.at])
......
......@@ -14,7 +14,6 @@
# You should have received a copy of the GNU General Public License
# along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>.
AT_BANNER([Transcript stream])
AT_SETUP([Transcript stream])
AT_KEYWORDS([stream xscript])
AT_DATA([input],[first line
......
......@@ -38,7 +38,7 @@ if header :comparator "i;ascii-numeric" :contains "X-Number" "15"
discard;
}
],[78],[],
[sieve: prog:4:1: comparator `i;ascii-numeric' is incompatible with match type `contains' in call to `header'
[sieve: prog:4.1: comparator `i;ascii-numeric' is incompatible with match type `contains' in call to `header'
])
AT_CLEANUP
......
atconfig
atlocal
bs
cwdrepl
fldel
lstuid
package.m4
......