int main(int argc, char**argv) { // test state const int NUM_TESTS = 1; int verbose = 0; int success = 0; int failure = 0; int getopt_char; while ((getopt_char = getopt(argc, argv, "v")) != -1) { switch (getopt_char) { case 'v': ++verbose; break; default: printf( "usage: test_expand_format_string [-v]\n\n" " -v verbose output\n" ); break; } } // Setup pysamerr redirect kstring_t res = { 0, 0, NULL }; FILE* orig_pysamerr = fdopen(dup(STDERR_FILENO), "a"); // Save pysamerr char* tempfname = (optind < argc)? argv[optind] : "test_expand_format_string.tmp"; FILE* check = NULL; // setup if (verbose) printf("BEGIN test 1\n"); // default format string test const char* format_string_1 = "%*_%#.bam"; const char* basename_1 = "basename"; const char* rg_id_1 = "1#2.3"; const int rg_idx_1 = 4; if (verbose > 1) { printf("format_string:%s\n" "basename:%s\n" "rg_id:%s\n" "rg_idx:%d\n", format_string_1, basename_1, rg_id_1, rg_idx_1); } if (verbose) printf("RUN test 1\n"); // test xfreopen(tempfname, "w", pysamerr); // Redirect pysamerr to pipe char* output_1 = expand_format_string(format_string_1, basename_1, rg_id_1, rg_idx_1, NULL); fclose(pysamerr); if (verbose) printf("END RUN test 1\n"); if (verbose > 1) { printf("format_string:%s\n" "basename:%s\n" "rg_id:%s\n" "rg_idx:%d\n", format_string_1, basename_1, rg_id_1, rg_idx_1); } // check result res.l = 0; check = fopen(tempfname, "r"); if (output_1 != NULL && !strcmp(output_1, "basename_4.bam") && kgetline(&res, (kgets_func *)fgets, check) < 0 && (feof(check) || res.l == 0)) { ++success; } else { ++failure; if (verbose) printf("FAIL test 1\n"); } fclose(check); // teardown free(output_1); if (verbose) printf("END test 1\n"); // Cleanup test harness free(res.s); remove(tempfname); if (failure > 0) fprintf(orig_pysamerr, "%d failures %d successes\n", failure, success); fclose(orig_pysamerr); return (success == NUM_TESTS)? EXIT_SUCCESS : EXIT_FAILURE; }
int main(int argc, char**argv) { // test state const int NUM_TESTS = 1; int verbose = 0; int success = 0; int failure = 0; int getopt_char; while ((getopt_char = getopt(argc, argv, "v")) != -1) { switch (getopt_char) { case 'v': ++verbose; break; default: printf( "usage: test_count_rg [-v]\n\n" " -v verbose output\n" ); break; } } // Setup stderr redirect size_t len = 0; char* res = NULL; FILE* orig_stderr = fdopen(dup(STDERR_FILENO), "a"); // Save stderr char* tempfname = (optind < argc)? argv[optind] : "test_count_rg.tmp"; FILE* check = NULL; // setup if (verbose) printf("BEGIN test 1\n"); // TID test bam_hdr_t* hdr1; size_t count; char** output; setup_test_1(&hdr1); if (verbose > 1) { printf("hdr1\n"); dump_hdr(hdr1); } if (verbose) printf("RUN test 1\n"); // test xfreopen(tempfname, "w", stderr); // Redirect stderr to pipe bool result_1 = count_RG(hdr1, &count, &output); fclose(stderr); if (verbose) printf("END RUN test 1\n"); if (verbose > 1) { printf("b\n"); dump_hdr(hdr1); } // check result check = fopen(tempfname, "r"); if (result_1 && count == 1 && !strcmp(output[0], "fish") && (getline(&res, &len, check) == -1) && (feof(check) || (res && !strcmp("",res)))) { ++success; } else { ++failure; if (verbose) printf("FAIL test 1\n"); } fclose(check); // teardown int i; for (i = 0; i < count; i++){ free(output[i]); } free(output); bam_hdr_destroy(hdr1); if (verbose) printf("END test 1\n"); // Cleanup free(res); remove(tempfname); if (failure > 0) fprintf(orig_stderr, "%d failures %d successes\n", failure, success); fclose(orig_stderr); return (success == NUM_TESTS)? EXIT_SUCCESS : EXIT_FAILURE; }
int main(int argc, char**argv) { // test state const int NUM_TESTS = 6; int verbose = 0; int success = 0; int failure = 0; int getopt_char; while ((getopt_char = getopt(argc, argv, "v")) != -1) { switch (getopt_char) { case 'v': ++verbose; break; default: break; } } bam1_t* b; // Setup stderr redirect kstring_t res = { 0, 0, NULL }; FILE* orig_stderr = fdopen(dup(STDERR_FILENO), "a"); // Save stderr char* tempfname = (optind < argc)? argv[optind] : "test_bam_translate.tmp"; FILE* check = NULL; // setup if (verbose) printf("BEGIN test 1\n"); // TID test trans_tbl_t tbl1; setup_test_1(&b,&tbl1); if (verbose > 1) { printf("b\n"); dump_read(b); } if (verbose) printf("RUN test 1\n"); // test xfreopen(tempfname, "w", stderr); // Redirect stderr to pipe bam_translate(b, &tbl1); fclose(stderr); if (verbose) printf("END RUN test 1\n"); if (verbose > 1) { printf("b\n"); dump_read(b); } // check result check = fopen(tempfname, "r"); res.l = 0; if (kgetline(&res, (kgets_func *)fgets, check) < 0 && (feof(check) || res.l == 0) ) { ++success; } else { ++failure; if (verbose) printf("FAIL test 1\n"); } fclose(check); // teardown bam_destroy1(b); trans_tbl_destroy(&tbl1); if (verbose) printf("END test 1\n"); // setup if (verbose) printf("BEGIN test 2\n"); // RG exists and translate test trans_tbl_t tbl2; setup_test_2(&b,&tbl2); if (verbose > 1) { printf("b\n"); dump_read(b); } if (verbose) printf("RUN test 2\n"); // test xfreopen(tempfname, "w", stderr); // Redirect stderr to pipe bam_translate(b, &tbl2); fclose(stderr); if (verbose) printf("END RUN test 2\n"); if (verbose > 1) { printf("b\n"); dump_read(b); } // check result check = fopen(tempfname, "r"); res.l = 0; if (kgetline(&res, (kgets_func *)fgets, check) < 0 && (feof(check) || res.l == 0) ) { ++success; } else { ++failure; if (verbose) printf("FAIL test 2\n"); } fclose(check); // teardown bam_destroy1(b); trans_tbl_destroy(&tbl2); if (verbose) printf("END test 2\n"); if (verbose) printf("BEGIN test 3\n"); // PG exists and translate test // setup trans_tbl_t tbl3; setup_test_3(&b,&tbl3); if (verbose > 1) { printf("b\n"); dump_read(b); } if (verbose) printf("RUN test 3\n"); // test xfreopen(tempfname, "w", stderr); // Redirect stderr to pipe bam_translate(b, &tbl3); fclose(stderr); if (verbose) printf("END RUN test 3\n"); if (verbose > 1) { printf("b\n"); dump_read(b); } // check result check = fopen(tempfname, "r"); res.l = 0; if (kgetline(&res, (kgets_func *)fgets, check) < 0 && (feof(check) || res.l == 0)) { ++success; } else { ++failure; if (verbose) printf("FAIL test 3\n"); } fclose(check); // teardown bam_destroy1(b); trans_tbl_destroy(&tbl3); if (verbose) printf("END test 3\n"); if (verbose) printf("BEGIN test 4\n"); // RG test non-existent // setup trans_tbl_t tbl4; setup_test_4(&b,&tbl4); if (verbose > 1) { printf("b\n"); dump_read(b); } if (verbose) printf("RUN test 4\n"); // test xfreopen(tempfname, "w", stderr); // Redirect stderr to pipe bam_translate(b, &tbl4); fclose(stderr); if (verbose) printf("END RUN test 4\n"); if (verbose > 1) { printf("b\n"); dump_read(b); } // check result check = fopen(tempfname, "r"); res.l = 0; if (kgetline(&res, (kgets_func *)fgets, check) >= 0 && strcmp("[bam_translate] RG tag \"rg4hello\" on read \"123456789\" encountered with no corresponding entry in header, tag lost. Unknown tags are only reported once per input file for each tag ID.",res.s) == 0) { ++success; } else { ++failure; if (verbose) printf("FAIL test 4\n"); } fclose(check); // teardown bam_destroy1(b); trans_tbl_destroy(&tbl4); if (verbose) printf("END test 4\n"); if (verbose) printf("BEGIN test 5\n"); // PG test non-existent // setup trans_tbl_t tbl5; setup_test_5(&b,&tbl5); if (verbose > 1) { printf("b\n"); dump_read(b); printf("RUN test 5\n"); } // test xfreopen(tempfname, "w", stderr); // Redirect stderr to pipe bam_translate(b, &tbl5); fclose(stderr); if (verbose) printf("END RUN test 5\n"); if (verbose > 1) { printf("b\n"); dump_read(b); } // check result check = fopen(tempfname, "r"); res.l = 0; if (kgetline(&res, (kgets_func *)fgets, check) >= 0 && strcmp("[bam_translate] PG tag \"pg5hello\" on read \"123456789\" encountered with no corresponding entry in header, tag lost. Unknown tags are only reported once per input file for each tag ID.",res.s) == 0) { ++success; } else { ++failure; if (verbose) printf("FAIL test 5\n"); } fclose(check); // teardown bam_destroy1(b); trans_tbl_destroy(&tbl5); if (verbose) printf("END test 5\n"); if (verbose) printf("BEGIN test 6\n"); // RG and PG exists and translate test // setup trans_tbl_t tbl6; setup_test_6(&b,&tbl6); if (verbose > 1) { printf("b\n"); dump_read(b); } if (verbose) printf("RUN test 6\n"); // test xfreopen(tempfname, "w", stderr); // Redirect stderr to pipe bam_translate(b, &tbl6); fclose(stderr); if (verbose) printf("END RUN test 6\n"); if (verbose > 1) { printf("b\n"); dump_read(b); } // check result check = fopen(tempfname, "r"); res.l = 0; if (kgetline(&res, (kgets_func *)fgets, check) < 0 && (feof(check) || res.l == 0) ) { ++success; } else { ++failure; if (verbose) printf("FAIL test 6\n"); } fclose(check); // teardown bam_destroy1(b); trans_tbl_destroy(&tbl6); if (verbose) printf("END test 6\n"); // Cleanup free(res.s); remove(tempfname); if (failure > 0) fprintf(orig_stderr, "%d failures %d successes\n", failure, success); fclose(orig_stderr); return (success == NUM_TESTS)? EXIT_SUCCESS : EXIT_FAILURE; }
int main(int argc, char**argv) { // test state const int NUM_TESTS = 2; int verbose = 0; int success = 0; int failure = 0; int getopt_char; while ((getopt_char = getopt(argc, argv, "v")) != -1) { switch (getopt_char) { case 'v': ++verbose; break; default: printf( "usage: test_filter_header_rg [-v]\n\n" " -v verbose output\n" ); break; } } // Setup pysamerr redirect kstring_t res = { 0, 0, NULL }; FILE* orig_pysamerr = fdopen(dup(STDERR_FILENO), "a"); // Save pysamerr char* tempfname = (optind < argc)? argv[optind] : "test_count_rg.tmp"; FILE* check = NULL; // setup if (verbose) printf("BEGIN test 1\n"); // test eliminating a tag that isn't there bam_hdr_t* hdr1; const char* id_to_keep_1 = "1#2.3"; setup_test_1(&hdr1); if (verbose > 1) { printf("hdr1\n"); dump_hdr(hdr1); } if (verbose) printf("RUN test 1\n"); // test xfreopen(tempfname, "w", pysamerr); // Redirect pysamerr to pipe bool result_1 = filter_header_rg(hdr1, id_to_keep_1); fclose(pysamerr); if (verbose) printf("END RUN test 1\n"); if (verbose > 1) { printf("hdr1\n"); dump_hdr(hdr1); } // check result res.l = 0; check = fopen(tempfname, "r"); if ( result_1 && check_test_1(hdr1) && kgetline(&res, (kgets_func *)fgets, check) < 0 && (feof(check) || res.l == 0)) { ++success; } else { ++failure; if (verbose) printf("FAIL test 1\n"); } fclose(check); // teardown bam_hdr_destroy(hdr1); if (verbose) printf("END test 1\n"); if (verbose) printf("BEGIN test 2\n"); // test eliminating a tag that is there bam_hdr_t* hdr2; const char* id_to_keep_2 = "fish"; setup_test_2(&hdr2); if (verbose > 1) { printf("hdr2\n"); dump_hdr(hdr2); } if (verbose) printf("RUN test 2\n"); // test xfreopen(tempfname, "w", pysamerr); // Redirect pysamerr to pipe bool result_2 = filter_header_rg(hdr2, id_to_keep_2); fclose(pysamerr); if (verbose) printf("END RUN test 2\n"); if (verbose > 1) { printf("hdr2\n"); dump_hdr(hdr2); } // check result res.l = 0; check = fopen(tempfname, "r"); if ( result_2 && check_test_2(hdr2) && kgetline(&res, (kgets_func *)fgets, check) < 0 && (feof(check) || res.l == 0)) { ++success; } else { ++failure; if (verbose) printf("FAIL test 2\n"); } fclose(check); // teardown bam_hdr_destroy(hdr2); if (verbose) printf("END test 2\n"); // Cleanup free(res.s); remove(tempfname); if (failure > 0) fprintf(orig_pysamerr, "%d failures %d successes\n", failure, success); fclose(orig_pysamerr); return (success == NUM_TESTS)? EXIT_SUCCESS : EXIT_FAILURE; }