END_TEST START_TEST (test_selector) { set_fail_freq(1000000); freesasa_parameters p = freesasa_default_parameters; p.shrake_rupley_n_points = 10; FILE *file = fopen(DATADIR "1ubq.pdb", "r"); freesasa_structure *s = freesasa_structure_from_pdb(file, NULL, 0); freesasa_result *result = freesasa_calc_structure(s, NULL); double area; char name[FREESASA_MAX_SELECTION_NAME]; freesasa_set_verbosity(FREESASA_V_SILENT); for (int i = 1; i < 17; ++i) { /* This is a pretty short expression. Have not verified that it's actually exactly 17 memory allocations, but we have success with a frequencey of 18, and 17 seems about right. */ set_fail_freq(i); ck_assert_int_eq(freesasa_select_area("s, resn ALA and not resi 1-20", name, &area, s, result), FREESASA_FAIL); // this expression should come across most allocations } freesasa_set_verbosity(FREESASA_V_NORMAL); fclose(file); freesasa_result_free(result); freesasa_structure_free(s); }
END_TEST START_TEST (test_api) { freesasa_parameters p = freesasa_default_parameters; p.shrake_rupley_n_points = 20; // so the loop below will be fast freesasa_set_verbosity(FREESASA_V_SILENT); for (int i = 1; i < 50; ++i) { p.alg = FREESASA_SHRAKE_RUPLEY; set_fail_freq(i); ck_assert_int_eq(freesasa_calc(&coord, r, &p), NULL); p.alg = FREESASA_LEE_RICHARDS; set_fail_freq(i); ck_assert_int_eq(freesasa_calc(&coord, r, &p), NULL); } FILE *file = fopen(DATADIR "1ubq.pdb","r"); set_fail_freq(10000); freesasa_structure *s=freesasa_structure_from_pdb(file, NULL, 0); ck_assert_ptr_ne(s,NULL); for (int i = 1; i < 256; i *= 2) { //try to spread it out without doing too many calculations set_fail_freq(i); ck_assert_ptr_eq(freesasa_calc_structure(s, NULL), NULL); set_fail_freq(i); ck_assert_ptr_eq(freesasa_structure_get_chains(s, "A"), NULL); } set_fail_freq(1); freesasa_structure_free(s); fclose(file); freesasa_set_verbosity(FREESASA_V_NORMAL); }
END_TEST START_TEST (test_memerr) { FILE *file = fopen(DATADIR "1ubq.pdb","r"); freesasa_structure *structure = freesasa_structure_from_pdb(file, NULL, 0); freesasa_result *result = freesasa_calc_structure(structure, NULL); freesasa_node *rn; freesasa_set_verbosity(FREESASA_V_SILENT); rn = freesasa_tree_new(); for (int i = 1; i < 200; ++i) { int ret; set_fail_after(i); ret = freesasa_tree_add_result(rn, result, structure, "test"); set_fail_after(0); ck_assert_int_eq(ret, FREESASA_FAIL); } freesasa_set_verbosity(FREESASA_V_NORMAL); freesasa_structure_free(structure); freesasa_result_free(result); fclose(file); } END_TEST
static void teardown(void) { freesasa_structure_free(structure); freesasa_result_free(result); freesasa_strvp_free(svp); }