/* ---------------- pair_set_chimera -------------------------- * Given an alignment, write pairs of atoms to a file in a format * that chimera can read. * We return a char * to space which is allocated by the * scr_printf() routines. */ char * pair_set_chimera (struct pair_set *pair_set, const struct coord *c1, const struct coord *c2) { const char *this_sub = "pair_set_chimera"; int **p; char *s1 = NULL; char *s2 = NULL; char *ret; size_t i; if (pair_set->n == 0) { err_printf (this_sub, "empty pair set\n"); return NULL; } s1 = save_str ("#0"); s2 = save_str ("#1"); p = pair_set->indices; for ( i = 0; i < pair_set->n; i++) { int a = p[i][0], b = p[i][1]; if (( a != GAP_INDEX) && ( b != GAP_INDEX)) { s1 = add_res (s1, a, c1); s2 = add_res (s2, b, c2); } } scr_reset(); ret = scr_printf ("match %s %s", s1, s2); free (s1); free (s2); return (ret); }
static logres_parse_status_t add_res_string(logres_t *r, uint32_t index, const char *ks, const char *ke, const char *vs, const char *ve) { char *k; uint8_t *v; logres_parse_status_t s; k = malloc(ke-ks+1); if(k == NULL) return LOGRES_PARSE_NO_MEM; v = malloc(ve-vs+1); if(v == NULL) { free(k); return LOGRES_PARSE_NO_MEM; } memcpy(k, ks, ke-ks); k[ke-ks] = 0; memcpy(v, vs, ve-vs); v[ve-vs] = 0; s = add_res(r, index, k, v, ve-vs+1); if(s != LOGRES_PARSE_OK) { free(k); free(v); return s; } return LOGRES_PARSE_OK; }
EvalRes expr(const char *s, char **s1, int d) { // printf("Getting expr from `%s`\n", s); EvalRes t = term(s, s1, d); if (t.st != EvalOk) return t; char *s2 = *s1; Token sgn = get_token(*s1, s1); if (sgn.st == InvalidToken) return everr(InvalidToken); if (sgn.t == PLUS) return add_res(t, expr(*s1, s1, d)); else if (sgn.t == MINUS) { *s1 = s2; return add_res(t, expr(*s1, s1, d)); } else if (sgn.t == END || sgn.t == RP) { if (sgn.t == RP && d <= 0) return everr(SyntaxError); *s1 = s2; return t; } else return everr(SyntaxError); }
int run_tests(int argc, char **args) { memset(&test_main, 0, sizeof(test_main)); int arg; int incl_filter = 0; int excl_filter = 0; for (arg = 1; arg < argc; arg++) { if (strlen(args[arg]) == 0) continue; if (0 == strcmp("-f", args[arg])) { incl_filter = 1; continue; } if (0 == strcmp("-e", args[arg])) { excl_filter = 1; continue; } if (incl_filter) { strcpy(test_main.incl_filter, args[arg]); incl_filter = 0; } else if (excl_filter) { strcpy(test_main.excl_filter, args[arg]); excl_filter = 0; } else { printf("running tests from %s\n", args[arg]); FILE *fd = fopen(args[1], "r"); if (fd == NULL) { printf("%s not found\n", args[arg]); return -2; } test_main.spec = fd; } } DBGT("adding suites...\n"); add_suites(); DBGT("%i tests added\n", test_main.test_count); if (test_main.spec) { fclose(test_main.spec); } if (test_main.test_count == 0) { printf("No tests to run\n"); return 0; } int fd_success = open("_tests_ok", O_APPEND | O_TRUNC | O_CREAT | O_RDWR, S_IRUSR | S_IWUSR); int fd_bad = open("_tests_fail", O_APPEND | O_TRUNC | O_CREAT | O_RDWR, S_IRUSR | S_IWUSR); DBGT("running tests...\n"); int ok = 0; int failed = 0; int stopped = 0; test *cur_t = test_main.tests; int i = 1; while (cur_t) { cur_t->setup(cur_t); test *next_test = cur_t->_next; DBGT("TEST %i/%i : running test %s\n", i, test_main.test_count, cur_t->name); i++; int start_error_count = get_error_count(); int res = cur_t->f(cur_t); if (res == TEST_RES_OK && get_error_count() != start_error_count) { res = TEST_RES_FAIL; } cur_t->test_result = res; int fd = res == TEST_RES_OK ? fd_success : fd_bad; write(fd, cur_t->name, strlen(cur_t->name)); write(fd, "\n", 1); switch (res) { case TEST_RES_OK: ok++; printf(" .. ok\n"); break; case TEST_RES_FAIL: failed++; printf(" .. FAILED\n"); if (test_main.on_stop) test_main.on_stop(cur_t); add_res(cur_t, &test_main.failed, &test_main.failed_last); break; case TEST_RES_ASSERT: stopped++; printf(" .. ABORTED\n"); if (test_main.on_stop) test_main.on_stop(cur_t); add_res(cur_t, &test_main.stopped, &test_main.stopped_last); break; } cur_t->teardown(cur_t); free(cur_t); cur_t = next_test; } close(fd_success); close(fd_bad); DBGT("ran %i tests\n", test_main.test_count); printf("Test report, %i tests\n", test_main.test_count); printf("%i succeeded\n", ok); printf("%i failed\n", failed); dump_res(&test_main.failed); printf("%i stopped\n", stopped); dump_res(&test_main.stopped); if (ok < test_main.test_count) { printf("\nFAILED\n"); return -1; } else { printf("\nALL TESTS OK\n"); return 0; } }