2
Copyright (c) 2010-2011 Giorgio Gonnella <gonnella@zbh.uni-hamburg.de>
3
Copyright (c) 2010-2011 Center for Bioinformatics, University of Hamburg
5
Permission to use, copy, modify, and distribute this software for any
6
purpose with or without fee is hereby granted, provided that the above
7
copyright notice and this permission notice appear in all copies.
9
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18
#ifndef RDJ_ENSURE_OUTPUT_H
19
#define RDJ_ENSURE_OUTPUT_H
22
#include "core/ensure.h"
24
#include "core/xansi_api.h"
26
/* defines macros to make easier to test output to a temporary file */
28
#define GT_ENSURE_OUTPUT_DECLARE(MAXOUTSIZE) \
34
char buffer[MAXOUTSIZE]
36
#define GT_ENSURE_OUTPUT_GETFILE(GTFILE) \
37
fnamestr = gt_str_new(); \
38
handle = gt_xtmpfp(fnamestr); \
39
(GTFILE) = gt_file_new_from_fileptr(handle)
41
#define GT_ENSURE_OUTPUT_TESTFILE(GTFILE, EXPOUT) \
42
(void)fflush(handle); \
43
gt_file_xrewind(GTFILE); \
44
outsize = (size_t)gt_file_xread((GTFILE), buffer, strlen(EXPOUT)); \
45
gt_ensure(had_err, outsize == strlen(EXPOUT)); \
46
gt_ensure(had_err, memcmp((EXPOUT), buffer, outsize) == 0); \
49
fprintf(stderr, "\nExpected file content: \n%s\n", \
51
fprintf(stderr, "\nFile content actually read " \
52
"(up to %lu bytes):\n%s\n", \
53
(unsigned long) strlen(EXPOUT), buffer); \
56
#define GT_ENSURE_OUTPUT_RMFILE(GTFILE) \
57
gt_file_delete(GTFILE); \
58
fname = gt_str_get(fnamestr); \
60
gt_str_delete(fnamestr)
62
#define GT_ENSURE_OUTPUT(FNCALL, EXPOUT) \
63
GT_ENSURE_OUTPUT_GETFILE(outfp); \
65
GT_ENSURE_OUTPUT_TESTFILE(outfp, EXPOUT); \
66
GT_ENSURE_OUTPUT_RMFILE(outfp)
69
Compares the output of the function call FNCALL
70
to the char* EXPOUT (size and content).
72
Usage: GT_ENSURE_OUTPUT_DECLARE in the declarations,
73
then GT_ENSURE_OUTPUT to run the test (also multiple times);
74
FNCALL should print something to the GtFile* outfp
75
or to the FILE* handle
78
- int had_err is the return value variable of the unit test method
79
- GtError *err (required by the gt_ensure macro)
80
- reserved variables: fnamestr, fname, handle, outfp, outsize, buffer