#include <string.h>
#include <errno.h>
+
+/* We are testing some deprecated APIs here */
+#define GLIB_DISABLE_DEPRECATION_WARNINGS
+
#include <glib.h>
#include <glib/gstdio.h>
{
gchar *args[10];
+ g_assert (g_build_pathv ("", NULL) == NULL);
args[0] = NULL;
check_string (g_build_pathv ("", args), "");
args[0] = ""; args[1] = NULL;
g_remove (p2);
g_remove (p1);
g_remove (p0);
+
+ g_free (p2);
+ g_free (p1);
+ g_free (p0);
}
static void
g_print ("checking g_mkdir_with_parents() in cwd: %s", cwd);
test_mkdir_with_parents_1 (cwd);
g_free (cwd);
+
+ g_assert (g_mkdir_with_parents (NULL, 0) == -1);
+ g_assert (errno == EINVAL);
}
static void
test_format_size_for_display (void)
{
+ /* nobody called setlocale(), so we should get "C" behaviour... */
check_string (g_format_size_for_display (0), "0 bytes");
check_string (g_format_size_for_display (1), "1 byte");
check_string (g_format_size_for_display (2), "2 bytes");
check_string (g_format_size_for_display (1024), "1.0 KB");
check_string (g_format_size_for_display (1024 * 1024), "1.0 MB");
check_string (g_format_size_for_display (1024 * 1024 * 1024), "1.0 GB");
+
+ check_string (g_format_size (0), "0 bytes");
+ check_string (g_format_size (1), "1 byte");
+ check_string (g_format_size (2), "2 bytes");
+ check_string (g_format_size (1000ULL), "1.0 kB");
+ check_string (g_format_size (1000ULL * 1000), "1.0 MB");
+ check_string (g_format_size (1000ULL * 1000 * 1000), "1.0 GB");
+ check_string (g_format_size (1000ULL * 1000 * 1000 * 1000), "1.0 TB");
+ check_string (g_format_size (1000ULL * 1000 * 1000 * 1000 * 1000), "1.0 PB");
+ check_string (g_format_size (1000ULL * 1000 * 1000 * 1000 * 1000 * 1000), "1.0 EB");
+
+ check_string (g_format_size_full (0, G_FORMAT_SIZE_IEC_UNITS), "0 bytes");
+ check_string (g_format_size_full (1, G_FORMAT_SIZE_IEC_UNITS), "1 byte");
+ check_string (g_format_size_full (2, G_FORMAT_SIZE_IEC_UNITS), "2 bytes");
+
+ check_string (g_format_size_full (2048ULL, G_FORMAT_SIZE_IEC_UNITS), "2.0 KiB");
+ check_string (g_format_size_full (2048ULL * 1024, G_FORMAT_SIZE_IEC_UNITS), "2.0 MiB");
+ check_string (g_format_size_full (2048ULL * 1024 * 1024, G_FORMAT_SIZE_IEC_UNITS), "2.0 GiB");
+ check_string (g_format_size_full (2048ULL * 1024 * 1024 * 1024, G_FORMAT_SIZE_IEC_UNITS), "2.0 TiB");
+ check_string (g_format_size_full (2048ULL * 1024 * 1024 * 1024 * 1024, G_FORMAT_SIZE_IEC_UNITS), "2.0 PiB");
+ check_string (g_format_size_full (2048ULL * 1024 * 1024 * 1024 * 1024 * 1024, G_FORMAT_SIZE_IEC_UNITS), "2.0 EiB");
+
+ check_string (g_format_size_full (238472938, G_FORMAT_SIZE_IEC_UNITS), "227.4 MiB");
+ check_string (g_format_size_full (238472938, G_FORMAT_SIZE_DEFAULT), "238.5 MB");
+ check_string (g_format_size_full (238472938, G_FORMAT_SIZE_LONG_FORMAT), "238.5 MB (238472938 bytes)");
+}
+
+static void
+test_file_errors (void)
+{
+ g_assert (g_file_error_from_errno (EEXIST) == G_FILE_ERROR_EXIST);
+ g_assert (g_file_error_from_errno (EISDIR) == G_FILE_ERROR_ISDIR);
+ g_assert (g_file_error_from_errno (EACCES) == G_FILE_ERROR_ACCES);
+ g_assert (g_file_error_from_errno (ENAMETOOLONG) == G_FILE_ERROR_NAMETOOLONG);
+ g_assert (g_file_error_from_errno (ENOENT) == G_FILE_ERROR_NOENT);
+ g_assert (g_file_error_from_errno (ENOTDIR) == G_FILE_ERROR_NOTDIR);
+ g_assert (g_file_error_from_errno (ENXIO) == G_FILE_ERROR_NXIO);
+ g_assert (g_file_error_from_errno (ENODEV) == G_FILE_ERROR_NODEV);
+ g_assert (g_file_error_from_errno (EROFS) == G_FILE_ERROR_ROFS);
+#ifdef ETXTBSY
+ g_assert (g_file_error_from_errno (ETXTBSY) == G_FILE_ERROR_TXTBSY);
+#endif
+ g_assert (g_file_error_from_errno (EFAULT) == G_FILE_ERROR_FAULT);
+#ifdef ELOOP
+ g_assert (g_file_error_from_errno (ELOOP) == G_FILE_ERROR_LOOP);
+#endif
+ g_assert (g_file_error_from_errno (ENOSPC) == G_FILE_ERROR_NOSPC);
+ g_assert (g_file_error_from_errno (ENOMEM) == G_FILE_ERROR_NOMEM);
+ g_assert (g_file_error_from_errno (EMFILE) == G_FILE_ERROR_MFILE);
+ g_assert (g_file_error_from_errno (ENFILE) == G_FILE_ERROR_NFILE);
+ g_assert (g_file_error_from_errno (EBADF) == G_FILE_ERROR_BADF);
+ g_assert (g_file_error_from_errno (EINVAL) == G_FILE_ERROR_INVAL);
+ g_assert (g_file_error_from_errno (EPIPE) == G_FILE_ERROR_PIPE);
+ g_assert (g_file_error_from_errno (EAGAIN) == G_FILE_ERROR_AGAIN);
+ g_assert (g_file_error_from_errno (EINTR) == G_FILE_ERROR_INTR);
+ g_assert (g_file_error_from_errno (EIO) == G_FILE_ERROR_IO);
+ g_assert (g_file_error_from_errno (EPERM) == G_FILE_ERROR_PERM);
+ g_assert (g_file_error_from_errno (ENOSYS) == G_FILE_ERROR_NOSYS);
+}
+
+static void
+test_basename (void)
+{
+ gchar *b;
+
+ b = g_path_get_basename ("");
+ g_assert_cmpstr (b, ==, ".");
+ g_free (b);
+
+ b = g_path_get_basename ("///");
+ g_assert_cmpstr (b, ==, "/");
+ g_free (b);
+
+ b = g_path_get_basename ("/a/b/c/d");
+ g_assert_cmpstr (b, ==, "d");
+ g_free (b);
}
int
g_test_add_func ("/fileutils/build-filenamev", test_build_filenamev);
g_test_add_func ("/fileutils/mkdir-with-parents", test_mkdir_with_parents);
g_test_add_func ("/fileutils/format-size-for-display", test_format_size_for_display);
+ g_test_add_func ("/fileutils/errors", test_file_errors);
+ g_test_add_func ("/fileutils/basename", test_basename);
return g_test_run();
}