DatabaseConnectionFixture::DatabaseConnectionFixture(): db_filepath("Testfile_01"), pdbc(0) { pdbc = new DatabaseConnection; abort_if_exists(db_filepath); pdbc->open(db_filepath); JEWEL_ASSERT (pdbc->is_valid()); }
void move_to_final(char *tmp, char *dst) { abort_if_exists(dst); if (rename(tmp, dst) < 0) { fprintf(stderr, "%s:Unable to rename output file '%s'", progname, dst); perror(progname); exit(2); } }
ExampleFixture::ExampleFixture(): db_filepath("Testfile_dpof"), pdbc(0) { pdbc = new DerivedDatabaseConnection; abort_if_exists(db_filepath); pdbc->open(db_filepath); JEWEL_ASSERT (pdbc->is_valid()); ExampleA::setup_tables(*pdbc); ExampleB::setup_tables(*pdbc); ExampleC::setup_tables(*pdbc); }
int main(int argc, char* argv[]) { bool do_compress = false; bool to_stdout = false; bool use_literal = false; char fn_buffer[1024] = {'\0'}; char tmp_fn_buffer[1024] = {'\0'}; FILE* ifile; FILE* ofile; char *progname_iter; int file_index; int c; char *cvalue = NULL; progname = strtok(argv[0], "/"); while ((progname_iter = strtok(NULL, "/")) != NULL) { progname = progname_iter; } if (strcmp(progname, "qzip") == 0) { do_compress = true; } else if (strcmp(progname, "qunzip") == 0) { do_compress = false; } else if (strcmp(progname, "qcat") == 0) { do_compress = false; to_stdout = true; } else { fprintf(stderr, "Unknown executable invocation: '%s'\n", progname); usage(1); } while ((c = getopt (argc, argv, "dh?")) != -1) { switch (c) { case 'd': do_compress = false; break; case '-': use_literal = true; case 'h': case 'v': usage(0); break; case '?': default: usage(1); } } if (optind > 0 && strcmp(argv[optind-1], "--") == 0) { use_literal = true; } if (optind < argc && strcmp(argv[optind], "-") == 0 && !use_literal) { to_stdout = true; } for (file_index = optind; file_index <= argc; file_index++) { if (argc > optind && file_index == argc) { // We ensure that we go through the loop at least once. // If there are files listed as argv, then ignore the // last iteration. break; } if (do_compress) { // Compress if (argc > 1 && !to_stdout) { sprintf(fn_buffer, "%s.qz", argv[file_index]); sprintf(tmp_fn_buffer, "%s.qz.%d", argv[file_index], getpid()); abort_if_exists(fn_buffer); abort_if_exists(tmp_fn_buffer); ifile = fopen(argv[file_index], "rb"); if (!ifile) { fprintf(stderr, "Unable to open input file '%s':", argv[file_index]); perror(NULL); exit(2); } ofile = fopen(tmp_fn_buffer, "wb"); } else { strcpy(fn_buffer, "stdout"); ifile = stdin; ofile = stdout; } } else { // Decompress if (argc > 1 && !to_stdout) { bool err = false; if (strlen(argv[file_index]) < 4) err = true; if (!err) { strcpy(tmp_fn_buffer, argv[file_index] + strlen(argv[file_index]) - 3); if (strcmp(tmp_fn_buffer, ".qz") != 0) { err = true; } } if (err) { fprintf(stderr, "%s: File does not end in '.qz': '%s'\n", progname, argv[file_index]); exit(1); } if (! to_stdout) { strncpy(fn_buffer, argv[file_index], strlen(argv[file_index]) - 3); sprintf(tmp_fn_buffer, "%s.%d", fn_buffer, getpid()); abort_if_exists(fn_buffer); } ifile = fopen(argv[file_index], "rb"); if (!ifile) { fprintf(stderr, "Unable to open compressed file '%s':", argv[file_index]); perror(NULL); exit(2); } if (to_stdout) { strcpy(fn_buffer, "stdin"); ofile = stdout; } else { ofile = fopen(tmp_fn_buffer, "wb"); } } else { strcpy(fn_buffer, "stdin"); ifile = stdin; ofile = stdout; } } if (!ofile) { perror("Unable to open output file"); exit(2); } if (do_compress) { stream_compress(ifile, ofile); } else { stream_decompress(ifile, ofile); } fclose(ifile); if (argc > 1 && !to_stdout) { fclose(ofile); move_to_final(tmp_fn_buffer, fn_buffer); if (unlink(argv[file_index]) < 0) { fprintf(stderr, "%s: Unable to unlink original file '%s'\n", progname, argv[1]); perror(progname); exit(3); } } } exit(0); }