ARB
arb_unit_test.h
Go to the documentation of this file.
1 // =============================================================== //
2 // //
3 // File : arb_unit_test.h //
4 // Purpose : useful high level code used in multiple units //
5 // //
6 // Coded by Ralf Westram (coder@reallysoft.de) in October 2010 //
7 // Institute of Microbiology (Technical University Munich) //
8 // http://www.arb-home.de/ //
9 // //
10 // =============================================================== //
11 
12 #ifndef ARB_UNIT_TEST_H
13 #define ARB_UNIT_TEST_H
14 
15 #ifdef UNIT_TESTS
16 
17 namespace arb_unit_test {
18 
19  struct test_alignment_data {
20  int mark;
21  const char *name;
22  const char *data;
23  };
24 
25  inline void test_insert_SAI_data(GBDATA *gb_main, ARB_ERROR& error, const char *test_aliname, test_alignment_data *ali_data, int sai_count) {
26  for (int sp = 0; sp<sai_count && !error; ++sp) {
27  test_alignment_data& sai = ali_data[sp];
28  GBDATA *gb_species = GBT_find_or_create_SAI(gb_main, sai.name);
29  if (!gb_species) error = GB_await_error();
30  else {
31  GB_write_flag(gb_species, sai.mark);
32 
33  GBDATA *gb_data = GBT_add_data(gb_species, test_aliname, "data", GB_STRING);
34  if (!gb_data) error = GB_await_error();
35  else error = GB_write_string(gb_data, sai.data);
36  }
37  }
38  }
39 
40  inline GBDATA *test_create_DB(ARB_ERROR& error, const char *test_aliname, test_alignment_data *ali_data, int species_count, bool use_compression) {
41  GBDATA *gb_main = GB_open("nodb.arb", "crw");
42  error = GB_push_transaction(gb_main);
43 
44  GB_allow_compression(gb_main, use_compression);
45 
46  if (!error) {
48  if (!gb_species_data) error = GB_await_error();
49  else {
50  long ali_len = strlen(ali_data[0].data);
51  GBDATA *gb_alignment = GBT_create_alignment(gb_main, test_aliname, ali_len, 1, 0, "rna", "by test_create_DB");
52  if (!gb_alignment) error = GB_await_error();
53  else {
54  for (int sp = 0; sp<species_count && !error; ++sp) {
55  test_alignment_data& species = ali_data[sp];
56  GBDATA *gb_species = GBT_find_or_create_species(gb_main, species.name, true);
57  if (!gb_species) error = GB_await_error();
58  else {
59  GB_write_flag(gb_species, species.mark);
60 
61  GBDATA *gb_data = GBT_add_data(gb_species, test_aliname, "data", GB_STRING);
62  if (!gb_data) error = GB_await_error();
63  else error = GB_write_string(gb_data, species.data);
64  }
65  }
66  }
67  if (!error) error = GBT_set_default_alignment(gb_main, test_aliname);
68  }
69  }
70 
71  error = GB_pop_transaction(gb_main);
72 
73  return gb_main;
74  }
75 
76 #define TEST_SPECIES_COUNT(test_ali_data) ARRAY_ELEMS(test_ali_data)
77 
78 #define TEST_CREATE_DB(error,test_aliname,test_ali_data,compress) \
79  arb_unit_test::test_create_DB(error, test_aliname, test_ali_data, \
80  TEST_SPECIES_COUNT(test_ali_data), compress)
81 
82 #define TEST_DB_INSERT_SAI(gb_main, error,test_aliname,test_ali_data) \
83  arb_unit_test::test_insert_SAI_data(gb_main, error, test_aliname, test_ali_data, \
84  TEST_SPECIES_COUNT(test_ali_data))
85 
86 };
87 
88 #endif // UNIT_TESTS
89 
90 #else
91 #error arb_unit_test.h included twice
92 #endif // ARB_UNIT_TEST_H
GBDATA * GB_open(const char *path, const char *opent)
Definition: ad_load.cxx:1363
GB_ERROR GB_write_string(GBDATA *gbd, const char *s)
Definition: arbdb.cxx:1387
bool GB_allow_compression(GBDATA *gb_main, bool allow_compression)
Definition: arbdb.cxx:1896
GB_ERROR GB_push_transaction(GBDATA *gbd)
Definition: arbdb.cxx:2494
NOT4PERL GBDATA * GBT_add_data(GBDATA *species, const char *ali_name, const char *key, GB_TYPES type) __ATTR__DEPRECATED_TODO("better use GBT_create_sequence_data()")
Definition: adali.cxx:597
GB_ERROR GB_await_error()
Definition: arb_msg.cxx:342
GBDATA * gb_species_data
Definition: adname.cxx:33
GB_ERROR GBT_set_default_alignment(GBDATA *gb_main, const char *alignment_name)
Definition: adali.cxx:765
static void error(const char *msg)
Definition: mkptypes.cxx:96
GB_ERROR GB_pop_transaction(GBDATA *gbd)
Definition: arbdb.cxx:2524
void GB_write_flag(GBDATA *gbd, long flag)
Definition: arbdb.cxx:2773
GBDATA * GBT_create_alignment(GBDATA *gb_main, const char *name, long len, long aligned, long security, const char *type, const char *why_created)
Definition: adali.cxx:388
GBDATA * GBT_find_or_create_species(GBDATA *gb_main, const char *name, bool markCreated)
Definition: aditem.cxx:61
GBDATA * GBT_find_or_create_SAI(GBDATA *gb_main, const char *name)
Definition: aditem.cxx:65
GBDATA * gb_main
Definition: adname.cxx:32
GBDATA * GBT_get_species_data(GBDATA *gb_main)
Definition: aditem.cxx:105