12 case EMBL:
return "EMBL";
13 case GCG:
return "GCG";
15 case MACKE:
return "MACKE";
16 case NEXUS:
return "NEXUS";
17 case PHYLIP:
return "PHYLIP";
28 throw_errorf(90,
"Conversion from %s to %s is not supported",
36 throw_errorf(92,
"Conversion from %s to %s is not implemented (but is expected to be here)",
44 throw_error(84,
"Reached EOF before complete entry has been read");
52 fprintf(stderr,
"Total %d sequences have been processed\n", seqCount);
55 log_processed_counter++;
56 log_seq_counter += seqCount;
67 #define TEST_THROW // comment out to temp. disable intentional throws
76 #define FORMATSPEC_OUT_ONLY(tag) { tag, #tag, NULp, 1 }
77 #define FORMATSPEC_GOT______(tag,file) { tag, #tag, "impexp/" file ".eft.exported", 1 }
78 #define FORMATSPEC_GOT_PLAIN(tag,file,seqcount) { tag, #tag, "impexp/" file, seqcount }
80 static FormatSpec format_spec[] = {
83 FORMATSPEC_GOT_PLAIN(
GENBANK,
"genbank.input", 3),
84 FORMATSPEC_GOT_PLAIN(
EMBL,
"embl.input", 5),
85 FORMATSPEC_GOT_PLAIN(
MACKE,
"macke.input", 5),
86 FORMATSPEC_GOT_PLAIN(
SWISSPROT,
"swissprot.input", 1),
89 FORMATSPEC_OUT_ONLY(
GCG),
90 FORMATSPEC_OUT_ONLY(
NEXUS),
91 FORMATSPEC_OUT_ONLY(
PHYLIP),
111 struct Capabilities {
120 bool shall_be_tested() {
121 #if defined(TEST_THROW)
122 return !neverReturns;
123 #else // !defined(TEST_THROW)
124 return supported && !neverReturns;
129 static Capabilities cap[fcount][fcount];
130 #define CAP(from,to) (cap[NUM_##from][NUM_##to])
132 #define TYPE(f) format_spec[f].type
133 #define NAME(f) format_spec[f].name
134 #define INPUT(f) format_spec[f].testfile
135 #define EXSEQ(f) format_spec[f].sequence_count
142 #define UPDATE_ONLY_IF_MORE_THAN_DATE_DIFFERS
144 inline bool more_than_date_differs(
const char *file,
const char *expected) {
148 #if defined(TEST_AUTO_UPDATE)
149 inline bool want_auto_update(
const char *file,
const char *expected) {
150 bool shall_update =
true;
155 #if defined(UPDATE_ONLY_IF_MISSING)
158 #if defined(UPDATE_ONLY_IF_MORE_THAN_DATE_DIFFERS)
159 shall_update = shall_update && more_than_date_differs(file, expected);
163 #else // !TEST_AUTO_UPDATE
164 inline bool want_auto_update(
const char * ,
const char * ) {
169 static void test_expected_conversion(
const char *file,
const char *flavor) {
174 bool shall_update = want_auto_update(file, expected);
180 TEST_REJECT(more_than_date_differs(file, expected));
185 static const char *test_convert(
const char *inf,
const char *outf,
Format inType,
Format ouType) {
195 static void test_convert_by_format_num(
int from,
int to) {
202 const char *error = test_convert(INPUT(from), toFile,
TYPE(from),
TYPE(to));
204 int converted_seqs = log_seq_counter-old_seq_counter;
205 int expected_seqs = EXSEQ(from);
206 if (to == NUM_GCG) expected_seqs = 1;
208 Capabilities& me = cap[from][to];
211 if (error)
TEST_ERROR(
"convert() reports error: '%s' (for supported conversion)", error);
217 test_expected_conversion(toFile,
NULp);
227 #if defined(TEST_THROW)
231 const char *fromFile =
"general/empty.input";
233 error = test_convert(fromFile, toFile,
TYPE(from),
TYPE(to));
236 fromFile =
"general/text.input";
237 error = test_convert(fromFile, toFile,
TYPE(from),
TYPE(to));
247 static void init_cap() {
248 for (
int from = 0; from<fcount; from++) {
249 for (
int to = 0; to<fcount; to++) {
250 Capabilities& me = cap[from][to];
251 if (!isInputFormat(from)) me.supported =
false;
256 #define NOT_SUPPORTED(t1,t2) TEST_EXPECT(isInputFormat(NUM_##t1)); cap[NUM_##t1][NUM_##t2].supported = false
258 static int will_convert(
int from) {
260 for (
int to = 0; to<fcount; to++) {
261 Capabilities& me = cap[from][to];
262 if (me.supported && me.shall_be_tested()) {
269 void TEST_SLOW_converter() {
282 int neverReturns = 0;
284 for (
int from = 0; from<fcount; from++) {
286 if (isInputFormat(from)) {
287 if (will_convert(from)<1) {
288 TEST_ERROR(
"Conversion from %s seems unsupported", NAME(from));
291 for (
int to = 0; to<fcount; to++) {
293 Capabilities& me = cap[from][to];
295 if (me.shall_be_tested()) {
296 TEST_ANNOTATE(
GBS_global_string(
"while converting %s -> %s", NAME(from), NAME(to)));
297 test_convert_by_format_num(from, to);
301 unsupported += !me.supported;
302 neverReturns += me.neverReturns;
308 "Conversion test summary:\n"
310 " - conversions: %3i (possible)\n"
311 " - unsupported: %3i\n"
313 " - neverReturns: %3i (would never return - not checked)\n"
314 " - converted: %3i\n",
322 int untested = possible - tested;
void throw_errorf(int error_num, const char *error_messagef,...) __ATTR__FORMAT(2) __ATTR__NORETURN
const char * GBS_global_string(const char *templat,...)
void convert(const FormattedFile &in, const FormattedFile &out)
#define TEST_EXPECT_LESS_EQUAL(val, ref)
const char * get_msg() const
void throw_conversion_not_implemented(Format inType, Format ouType)
long GB_size_of_file(const char *path)
void throw_incomplete_entry()
#define ARRAY_ELEMS(array)
static int log_seq_counter
static const char * format2name(Format type)
#define TEST_EXPECT(cond)
#define TEST_REJECT(cond)
#define TEST_REJECT_NULL(n)
static void error(const char *msg)
CONSTEXPR_INLINE bool is_input_format(Format inType)
#define TEST_EXPECT_ZERO_OR_SHOW_ERRNO(iocond)
void throw_conversion_failure(Format inType, Format ouType)
static int log_processed_counter
bool ARB_textfiles_have_difflines(const char *file1, const char *file2, int expected_difflines, TextDiffMode tdmode)
void throw_unsupported_input_format(Format inType)
void throw_conversion_not_supported(Format inType, Format ouType)
void throw_error(int error_num, const char *error_message) __ATTR__NORETURN
#define TEST_ERROR(format, strarg)
bool GB_is_regularfile(const char *path)
void log_processed(int seqCount)
#define STATIC_ASSERT(const_expression)
#define TEST_EXPECT_EQUAL(expr, want)
char * GBS_global_string_copy(const char *templat,...)