static void diff_file(const char *file, const char *outfile, const char *msg) { char *diffcmd = malloc(SNPRINTF_SIZE); char *difffname = malloc(SNPRINTF_SIZE); int total_size; assert(file && outfile); assert(diffcmd && difffname); if (total_size = snprintf(difffname, SNPRINTF_SIZE, "%s.diff", outfile) >= SNPRINTF_SIZE) { difffname = malloc(total_size); assert(difffname); snprintf(difffname, total_size, "%s.diff", outfile); } if (total_size = snprintf(diffcmd, SNPRINTF_SIZE, "diff -N \"%s%s\" \"%s\" >> \"%s\"", TEST_RESULT_DIR, file, outfile, difffname) >= SNPRINTF_SIZE) { diffcmd = malloc(total_size); assert(diffcmd); snprintf(diffcmd, total_size, "diff -N \"%s%s\" \"%s\" >> \"%s\"", TEST_RESULT_DIR, file, outfile, difffname); } if (system(diffcmd)) { test_show(msg); show_diff(difffname); free(difffname); free(diffcmd); exit(1); } free(difffname); free(diffcmd); remove(difffname); }
static void show_result(void) { struct merge_list *walk; walk = merge_result; while (walk) { show_result_list(walk); show_diff(walk); walk = walk->next; } }
/* parses @string and check the result against @expected_output */ static gboolean parse_check (const gchar *string, const gchar *env_str, const gchar *expected_output, /* may be NULL */ GError **error) { gchar *output; gboolean success = FALSE; output = ctpltest_parse_string (string, env_str, error); if (output) { if (expected_output && strcmp (output, expected_output) != 0) { g_set_error (error, 0, 0, "Parsing succeeded but output is not the expected one"); show_diff (output, expected_output, stderr); } else { success = TRUE; } g_free (output); } return success; }
static void diff_file() { const char *filename[2] = { "/home/bennylp/Desktop/opt/src/openh264-svn/testbin/test.264", "/home/bennylp/Desktop/opt/src/openh264-svn/testbin/test2.264" }; unsigned size[2]; pj_uint8_t *buf[2], start_nal[3] = {0, 0, 1}; unsigned i, pos[2], frame_cnt, mismatch_cnt=0; for (i=0; i<2; ++i) { FILE *fhnd; const pj_uint8_t start_nal[] = { 0, 0, 1}; fhnd = fopen(filename[i], "rb"); if (!fhnd) { printf("Error opening %s\n", filename[i]); return; } fseek(fhnd, 0, SEEK_END); size[i] = ftell(fhnd); fseek(fhnd, 0, SEEK_SET); buf[i] = (pj_uint8_t*)malloc(size[i] + 4); if (!buf[i]) return; if (fread (buf[i], 1, size[i], fhnd) != (unsigned)size[i]) { fprintf (stderr, "Unable to read whole file\n"); return; } memcpy (buf[i] + size[i], start_nal, sizeof(start_nal)); fclose(fhnd); } if (size[0] != size[1]) { printf("File size mismatch\n"); return; } pos[0] = pos[1] = 0; for ( frame_cnt=0; ; ++frame_cnt) { unsigned nal_len[2]; for (i = 0; i < size[0]; i++) { if (memcmp(buf[0] + pos[0] + i, start_nal, sizeof(start_nal)) == 0 && i > 0) { break; } } nal_len[0] = i; for (i = 0; i < size[1]; i++) { if (memcmp(buf[1] + pos[1] + i, start_nal, sizeof(start_nal)) == 0 && i > 0) { break; } } nal_len[1] = i; if (nal_len[0] != nal_len[1]) { printf("Different size in frame %d (%d vs %d)\n", frame_cnt, nal_len[0], nal_len[1]); } if (memcmp(buf[0]+pos[0], buf[1]+pos[1], nal_len[0]) != 0) { printf("Mismatch in frame %d\n", frame_cnt); show_diff(buf[0]+pos[0], buf[1]+pos[1], nal_len[0]); puts(""); ++mismatch_cnt; } pos[0] += nal_len[0]; pos[1] += nal_len[1]; if (pos[0] >= size[0]) break; } free(buf[0]); free(buf[1]); if (!mismatch_cnt) puts("Files the same!"); else printf("%d mismatches\n", mismatch_cnt); }
void TDB2::revert () { // Extract the details of the last txn, and roll it back. std::vector <std::string> u = undo.get_lines (); std::string uuid; std::string when; std::string current; std::string prior; revert_undo (u, uuid, when, current, prior); // Display diff and confirm. show_diff (current, prior, when); if (! context.config.getBoolean ("confirmation") || confirm (STRING_TDB2_UNDO_CONFIRM)) { // There are six kinds of change possible. Determine which one, and act // accordingly. // // Revert: task add // [1] 0 --> p // - erase from pending // - if in backlog, erase, else cannot undo // // Revert: task modify // [2] p --> p' // - write prior over current in pending // - add prior to backlog // // Revert: task done/delete // [3] p --> c // - add prior to pending // - erase from completed // - add prior to backlog // // Revert: task modify // [4] c --> p // - add prior to completed // - erase from pending // - add prior to backlog // // Revert: task modify // [5] c --> c' // - write prior over current in completed // - add prior to backlog // // Revert: task log // [6] 0 --> c // - erase from completed // - if in backlog, erase, else cannot undo // Modify other data files accordingly. std::vector <std::string> p = pending.get_lines (); revert_pending (p, uuid, prior); std::vector <std::string> c = completed.get_lines (); revert_completed (p, c, uuid, prior); std::vector <std::string> b = backlog.get_lines (); revert_backlog (b, uuid, current, prior); // Commit. If processing makes it this far with no exceptions, then we're // done. File::write (undo._file._data, u); File::write (pending._file._data, p); File::write (completed._file._data, c); File::write (backlog._file._data, b); } else std::cout << STRING_CMD_CONFIG_NO_CHANGE << "\n"; }