[easytag] Add a simple test for et_rename_file()
- From: David King <davidk src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [easytag] Add a simple test for et_rename_file()
- Date: Sun, 19 Apr 2015 08:15:31 +0000 (UTC)
commit c251376180e00a0314981fb567db73610d7686a7
Author: David King <amigadave amigadave com>
Date: Sat Dec 27 18:37:25 2014 +0000
Add a simple test for et_rename_file()
tests/test-misc.c | 80 +++++++++++++++++++++++++++++++++++++++++++++++++++-
1 files changed, 78 insertions(+), 2 deletions(-)
---
diff --git a/tests/test-misc.c b/tests/test-misc.c
index 003b44f..bf13933 100644
--- a/tests/test-misc.c
+++ b/tests/test-misc.c
@@ -1,5 +1,5 @@
/* EasyTAG - tag editor for audio files
- * Copyright (C) 2014 David King <amigadave amigadave com>
+ * Copyright (C) 2014-2015 David King <amigadave amigadave com>
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
@@ -18,6 +18,8 @@
#include "misc.h"
+#include <glib/gstdio.h>
+
GtkWidget *MainWindow;
GSettings *MainSettings;
@@ -110,6 +112,80 @@ misc_normalized_strcmp0 (void)
}
static void
+misc_rename_file (void)
+{
+ gchar *filename1;
+ gchar *filename2;
+ gchar *filename3;
+ gchar *basename;
+ gchar *basename_upper;
+ gchar *dirname;
+ gint fd1;
+ gint fd2;
+ gint fd3;
+ GError *error1 = NULL;
+ GError *error2 = NULL;
+ GError *error3 = NULL;
+
+ fd1 = g_file_open_tmp ("EasyTAG-test1.XXXXXX", &filename1, &error1);
+ fd2 = g_file_open_tmp ("EasyTAG-test2.XXXXXX", &filename2, &error2);
+ g_assert_no_error (error1);
+ g_assert_no_error (error2);
+
+ close (fd1);
+ close (fd2);
+
+ /* Renaming to an existing filename should fail. */
+ et_rename_file (filename1, filename2, &error1);
+ et_rename_file (filename2, filename1, &error2);
+ g_assert_error (error1, G_IO_ERROR, G_IO_ERROR_EXISTS);
+ g_assert_error (error2, G_IO_ERROR, G_IO_ERROR_EXISTS);
+
+ g_clear_error (&error1);
+ g_clear_error (&error2);
+
+ fd3 = g_file_open_tmp ("EasyTAG-test3.XXXXXX", &filename3, &error3);
+ g_assert_no_error (error3);
+
+ close (fd3);
+
+ g_assert_cmpint (g_unlink (filename3), ==, 0);
+
+ g_assert_cmpint (g_rename (filename2, filename3), ==, 0);
+
+ /* Renaming to a new filename should succeed. */
+ et_rename_file (filename1, filename2, &error1);
+ et_rename_file (filename2, filename1, &error2);
+ g_assert_no_error (error1);
+ g_assert_no_error (error2);
+
+ g_assert_cmpint (g_unlink (filename1), ==, 0);
+
+ g_free (filename1);
+ g_free (filename2);
+
+ basename = g_path_get_basename (filename3);
+ dirname = g_path_get_dirname (filename3);
+
+ basename_upper = g_ascii_strup (basename, -1);
+ g_free (basename);
+
+ filename2 = g_build_filename (dirname, basename_upper, NULL);
+ g_free (basename_upper);
+ g_free (dirname);
+
+ /* Renaming to a new filename, differing only by case, should succeed, even
+ * in the case of a case-insensitive filesystem. */
+ et_rename_file (filename3, filename2, &error3);
+ g_assert_no_error (error3);
+
+ g_assert_cmpint (g_unlink (filename2), ==, 0);
+
+ g_free (filename2);
+ g_free (filename3);
+}
+
+static void
misc_str_empty (void)
{
gsize i;
@@ -143,7 +219,6 @@ misc_undo_key (void)
g_assert_cmpint (undo_key, >, 0U);
g_assert_cmpint (undo_key, <, et_undo_key_new ());
}
-
int
main (int argc, char** argv)
{
@@ -152,6 +227,7 @@ main (int argc, char** argv)
g_test_add_func ("/misc/convert-duration", misc_convert_duration);
g_test_add_func ("/misc/filename-prepare", misc_filename_prepare);
g_test_add_func ("/misc/normalized-strcmp0", misc_normalized_strcmp0);
+ g_test_add_func ("/misc/rename-file", misc_rename_file);
g_test_add_func ("/misc/str-empty", misc_str_empty);
g_test_add_func ("/misc/undo-key", misc_undo_key);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]