[glib: 1/2] tests: Check that cancelling g_file_replace don't overwrite existing file



commit 2f290b3a5fa9e97124a3302e0232e11c863f5e7e
Author: Tomasz Miąsko <tomasz miasko gmail com>
Date:   Sun Nov 25 00:00:00 2018 +0000

    tests: Check that cancelling g_file_replace don't overwrite existing file

 gio/tests/file.c | 23 ++++++++++++++++++++---
 1 file changed, 20 insertions(+), 3 deletions(-)
---
diff --git a/gio/tests/file.c b/gio/tests/file.c
index 658d17549..efb2eaadd 100644
--- a/gio/tests/file.c
+++ b/gio/tests/file.c
@@ -523,6 +523,11 @@ test_create_delete (gconstpointer d)
   g_free (data);
 }
 
+static const gchar *original_data =
+    "/**\n"
+    " * g_file_replace_contents_async:\n"
+    "**/\n";
+
 static const gchar *replace_data =
     "/**\n"
     " * g_file_replace_contents_async:\n"
@@ -675,7 +680,8 @@ test_replace_cancel (void)
   GFileInfo *info;
   GCancellable *cancellable;
   gchar *path;
-  gsize nwrote;
+  gchar *contents;
+  gsize nwrote, length;
   guint count;
   GError *error = NULL;
 
@@ -688,8 +694,8 @@ test_replace_cancel (void)
 
   file = g_file_get_child (tmpdir, "file");
   g_file_replace_contents (file,
-                           replace_data,
-                           strlen (replace_data),
+                           original_data,
+                           strlen (original_data),
                            NULL, FALSE, 0, NULL,
                            NULL, &error);
   g_assert_no_error (error);
@@ -777,6 +783,17 @@ test_replace_cancel (void)
   g_object_unref (cancellable);
   g_object_unref (ostream);
 
+  /* Make sure that file contents wasn't actually replaced. */
+  g_file_load_contents (file,
+                        NULL,
+                        &contents,
+                        &length,
+                        NULL,
+                        &error);
+  g_assert_no_error (error);
+  g_assert_cmpstr (contents, ==, original_data);
+  g_free (contents);
+
   g_file_delete (file, NULL, &error);
   g_assert_no_error (error);
   g_object_unref (file);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]