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) { |
---|
47 | GBDATA *gb_species_data = GBT_get_species_data(gb_main); |
---|
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"); |
---|
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 |
---|