diff options
author | Matthias Clasen <mclasen@redhat.com> | 2021-11-25 15:33:47 +0000 |
---|---|---|
committer | Matthias Clasen <mclasen@redhat.com> | 2021-11-25 15:33:47 +0000 |
commit | f37d293b9cfcc43def6fe4be0483b898774e5a2f (patch) | |
tree | e920196bc79edae865d1365fb89f894385fa86df /tests/test-common.c | |
parent | 55efd092b0319f2a2697c510eafc2b0b23597d26 (diff) | |
parent | 553eac2ba028a87718ca20180cabe78fa3bc0204 (diff) | |
download | pango-f37d293b9cfcc43def6fe4be0483b898774e5a2f.tar.gz |
Merge branch 'serialization-improvements' into 'main'
Rename the serialize errors
See merge request GNOME/pango!520
Diffstat (limited to 'tests/test-common.c')
-rw-r--r-- | tests/test-common.c | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/tests/test-common.c b/tests/test-common.c index 3821a450..12b22cb4 100644 --- a/tests/test-common.c +++ b/tests/test-common.c @@ -82,6 +82,70 @@ done: return diff; } +char * +diff_bytes (GBytes *b1, + GBytes *b2, + GError **error) +{ + const char *command[] = { "diff", "-u", "-i", NULL, NULL, NULL }; + char *diff, *tmpfile, *tmpfile2; + int fd; + const char *text; + gsize len; + + /* write the text buffer to a temporary file */ + fd = g_file_open_tmp (NULL, &tmpfile, error); + if (fd < 0) + return NULL; + + text = (const char *) g_bytes_get_data (b1, &len); + if (write (fd, text, len) != (int) len) + { + close (fd); + g_set_error (error, + G_FILE_ERROR, G_FILE_ERROR_FAILED, + "Could not write data to temporary file '%s'", tmpfile); + goto done; + } + close (fd); + + fd = g_file_open_tmp (NULL, &tmpfile2, error); + if (fd < 0) + return NULL; + + text = (const char *) g_bytes_get_data (b2, &len); + if (write (fd, text, len) != (int) len) + { + close (fd); + g_set_error (error, + G_FILE_ERROR, G_FILE_ERROR_FAILED, + "Could not write data to temporary file '%s'", tmpfile2); + goto done; + } + close (fd); + + command[3] = tmpfile; + command[4] = tmpfile2; + + /* run diff command */ + g_spawn_sync (NULL, + (char **) command, + NULL, + G_SPAWN_SEARCH_PATH, + NULL, NULL, + &diff, + NULL, NULL, + error); + +done: + unlink (tmpfile); + g_free (tmpfile); + unlink (tmpfile2); + g_free (tmpfile2); + + return diff; +} + gboolean file_has_prefix (const char *filename, const char *str, |