Blame glib/tests/fileutils.c

Packit ae235b
/* Unit tests for gfileutils
Packit ae235b
 * Copyright (C) 1995-1997  Peter Mattis, Spencer Kimball and Josh MacDonald
Packit ae235b
 *
Packit ae235b
 * This work is provided "as is"; redistribution and modification
Packit ae235b
 * in whole or in part, in any medium, physical or electronic is
Packit ae235b
 * permitted without restriction.
Packit ae235b
 *
Packit ae235b
 * This work is distributed in the hope that it will be useful,
Packit ae235b
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit ae235b
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Packit ae235b
 *
Packit ae235b
 * In no event shall the authors or contributors be liable for any
Packit ae235b
 * direct, indirect, incidental, special, exemplary, or consequential
Packit ae235b
 * damages (including, but not limited to, procurement of substitute
Packit ae235b
 * goods or services; loss of use, data, or profits; or business
Packit ae235b
 * interruption) however caused and on any theory of liability, whether
Packit ae235b
 * in contract, strict liability, or tort (including negligence or
Packit ae235b
 * otherwise) arising in any way out of the use of this software, even
Packit ae235b
 * if advised of the possibility of such damage.
Packit ae235b
 */
Packit ae235b
Packit ae235b
#include "config.h"
Packit ae235b
#include <string.h>
Packit ae235b
#include <errno.h>
Packit ae235b
Packit ae235b
/* We are testing some deprecated APIs here */
Packit ae235b
#define GLIB_DISABLE_DEPRECATION_WARNINGS
Packit ae235b
Packit ae235b
#include <glib.h>
Packit ae235b
Packit ae235b
/* Test our stdio wrappers here */
Packit ae235b
#define G_STDIO_NO_WRAP_ON_UNIX
Packit ae235b
#include <glib/gstdio.h>
Packit ae235b
Packit ae235b
#ifdef G_OS_UNIX
Packit ae235b
#include <unistd.h>
Packit ae235b
#include <sys/types.h>
Packit ae235b
#include <sys/stat.h>
Packit ae235b
#endif
Packit ae235b
#include <fcntl.h>
Packit ae235b
#include <utime.h>
Packit ae235b
#ifdef G_OS_WIN32
Packit ae235b
#include <windows.h>
Packit ae235b
#endif
Packit ae235b
Packit ae235b
#define S G_DIR_SEPARATOR_S
Packit ae235b
Packit ae235b
static void
Packit ae235b
check_string (gchar *str, const gchar *expected)
Packit ae235b
{
Packit ae235b
  g_assert_nonnull (str);
Packit ae235b
  g_assert_cmpstr (str, ==, expected);
Packit ae235b
  g_free (str);
Packit ae235b
}
Packit ae235b
Packit ae235b
static void
Packit ae235b
test_build_path (void)
Packit ae235b
{
Packit ae235b
/*  check_string (g_build_path ("", NULL), "");*/
Packit ae235b
  check_string (g_build_path ("", "", NULL), "");
Packit ae235b
  check_string (g_build_path ("", "x", NULL), "x");
Packit ae235b
  check_string (g_build_path ("", "x", "y",  NULL), "xy");
Packit ae235b
  check_string (g_build_path ("", "x", "y", "z", NULL), "xyz");
Packit ae235b
Packit ae235b
/*  check_string (g_build_path (":", NULL), "");*/
Packit ae235b
  check_string (g_build_path (":", ":", NULL), ":");
Packit ae235b
  check_string (g_build_path (":", ":x", NULL), ":x");
Packit ae235b
  check_string (g_build_path (":", "x:", NULL), "x:");
Packit ae235b
  check_string (g_build_path (":", "", "x", NULL), "x");
Packit ae235b
  check_string (g_build_path (":", "", ":x", NULL), ":x");
Packit ae235b
  check_string (g_build_path (":", ":", "x", NULL), ":x");
Packit ae235b
  check_string (g_build_path (":", "::", "x", NULL), "::x");
Packit ae235b
  check_string (g_build_path (":", "x", "", NULL), "x");
Packit ae235b
  check_string (g_build_path (":", "x:", "", NULL), "x:");
Packit ae235b
  check_string (g_build_path (":", "x", ":", NULL), "x:");
Packit ae235b
  check_string (g_build_path (":", "x", "::", NULL), "x::");
Packit ae235b
  check_string (g_build_path (":", "x", "y",  NULL), "x:y");
Packit ae235b
  check_string (g_build_path (":", ":x", "y", NULL), ":x:y");
Packit ae235b
  check_string (g_build_path (":", "x", "y:", NULL), "x:y:");
Packit ae235b
  check_string (g_build_path (":", ":x:", ":y:", NULL), ":x:y:");
Packit ae235b
  check_string (g_build_path (":", ":x::", "::y:", NULL), ":x:y:");
Packit ae235b
  check_string (g_build_path (":", "x", "","y",  NULL), "x:y");
Packit ae235b
  check_string (g_build_path (":", "x", ":", "y",  NULL), "x:y");
Packit ae235b
  check_string (g_build_path (":", "x", "::", "y",  NULL), "x:y");
Packit ae235b
  check_string (g_build_path (":", "x", "y", "z", NULL), "x:y:z");
Packit ae235b
  check_string (g_build_path (":", ":x:", ":y:", ":z:", NULL), ":x:y:z:");
Packit ae235b
  check_string (g_build_path (":", "::x::", "::y::", "::z::", NULL), "::x:y:z::");
Packit ae235b
Packit ae235b
/*  check_string (g_build_path ("::", NULL), "");*/
Packit ae235b
  check_string (g_build_path ("::", "::", NULL), "::");
Packit ae235b
  check_string (g_build_path ("::", ":::", NULL), ":::");
Packit ae235b
  check_string (g_build_path ("::", "::x", NULL), "::x");
Packit ae235b
  check_string (g_build_path ("::", "x::", NULL), "x::");
Packit ae235b
  check_string (g_build_path ("::", "", "x", NULL), "x");
Packit ae235b
  check_string (g_build_path ("::", "", "::x", NULL), "::x");
Packit ae235b
  check_string (g_build_path ("::", "::", "x", NULL), "::x");
Packit ae235b
  check_string (g_build_path ("::", "::::", "x", NULL), "::::x");
Packit ae235b
  check_string (g_build_path ("::", "x", "", NULL), "x");
Packit ae235b
  check_string (g_build_path ("::", "x::", "", NULL), "x::");
Packit ae235b
  check_string (g_build_path ("::", "x", "::", NULL), "x::");
Packit ae235b
Packit ae235b
  /* This following is weird, but keeps the definition simple */
Packit ae235b
  check_string (g_build_path ("::", "x", ":::", NULL), "x:::::");
Packit ae235b
  check_string (g_build_path ("::", "x", "::::", NULL), "x::::");
Packit ae235b
  check_string (g_build_path ("::", "x", "y",  NULL), "x::y");
Packit ae235b
  check_string (g_build_path ("::", "::x", "y", NULL), "::x::y");
Packit ae235b
  check_string (g_build_path ("::", "x", "y::", NULL), "x::y::");
Packit ae235b
  check_string (g_build_path ("::", "::x::", "::y::", NULL), "::x::y::");
Packit ae235b
  check_string (g_build_path ("::", "::x:::", ":::y::", NULL), "::x::::y::");
Packit ae235b
  check_string (g_build_path ("::", "::x::::", "::::y::", NULL), "::x::y::");
Packit ae235b
  check_string (g_build_path ("::", "x", "", "y",  NULL), "x::y");
Packit ae235b
  check_string (g_build_path ("::", "x", "::", "y",  NULL), "x::y");
Packit ae235b
  check_string (g_build_path ("::", "x", "::::", "y",  NULL), "x::y");
Packit ae235b
  check_string (g_build_path ("::", "x", "y", "z", NULL), "x::y::z");
Packit ae235b
  check_string (g_build_path ("::", "::x::", "::y::", "::z::", NULL), "::x::y::z::");
Packit ae235b
  check_string (g_build_path ("::", ":::x:::", ":::y:::", ":::z:::", NULL), ":::x::::y::::z:::");
Packit ae235b
  check_string (g_build_path ("::", "::::x::::", "::::y::::", "::::z::::", NULL), "::::x::y::z::::");
Packit ae235b
}
Packit ae235b
Packit ae235b
static void
Packit ae235b
test_build_pathv (void)
Packit ae235b
{
Packit ae235b
  gchar *args[10];
Packit ae235b
Packit ae235b
  g_assert_null (g_build_pathv ("", NULL));
Packit ae235b
  args[0] = NULL;
Packit ae235b
  check_string (g_build_pathv ("", args), "");
Packit ae235b
  args[0] = ""; args[1] = NULL;
Packit ae235b
  check_string (g_build_pathv ("", args), "");
Packit ae235b
  args[0] = "x"; args[1] = NULL;
Packit ae235b
  check_string (g_build_pathv ("", args), "x");
Packit ae235b
  args[0] = "x"; args[1] = "y"; args[2] = NULL;
Packit ae235b
  check_string (g_build_pathv ("", args), "xy");
Packit ae235b
  args[0] = "x"; args[1] = "y"; args[2] = "z", args[3] = NULL;
Packit ae235b
  check_string (g_build_pathv ("", args), "xyz");
Packit ae235b
Packit ae235b
  args[0] = NULL;
Packit ae235b
  check_string (g_build_pathv (":", args), "");
Packit ae235b
  args[0] = ":"; args[1] = NULL;
Packit ae235b
  check_string (g_build_pathv (":", args), ":");
Packit ae235b
  args[0] = ":x"; args[1] = NULL;
Packit ae235b
  check_string (g_build_pathv (":", args), ":x");
Packit ae235b
  args[0] = "x:"; args[1] = NULL;
Packit ae235b
  check_string (g_build_pathv (":", args), "x:");
Packit ae235b
  args[0] = ""; args[1] = "x"; args[2] = NULL;
Packit ae235b
  check_string (g_build_pathv (":", args), "x");
Packit ae235b
  args[0] = ""; args[1] = ":x"; args[2] = NULL;
Packit ae235b
  check_string (g_build_pathv (":", args), ":x");
Packit ae235b
  args[0] = ":"; args[1] = "x"; args[2] = NULL;
Packit ae235b
  check_string (g_build_pathv (":", args), ":x");
Packit ae235b
  args[0] = "::"; args[1] = "x"; args[2] = NULL;
Packit ae235b
  check_string (g_build_pathv (":", args), "::x");
Packit ae235b
  args[0] = "x"; args[1] = ""; args[2] = NULL;
Packit ae235b
  check_string (g_build_pathv (":", args), "x");
Packit ae235b
  args[0] = "x:"; args[1] = ""; args[2] = NULL;
Packit ae235b
  check_string (g_build_pathv (":", args), "x:");
Packit ae235b
  args[0] = "x"; args[1] = ":"; args[2] = NULL;
Packit ae235b
  check_string (g_build_pathv (":", args), "x:");
Packit ae235b
  args[0] = "x"; args[1] = "::"; args[2] = NULL;
Packit ae235b
  check_string (g_build_pathv (":", args), "x::");
Packit ae235b
  args[0] = "x"; args[1] = "y"; args[2] = NULL;
Packit ae235b
  check_string (g_build_pathv (":", args), "x:y");
Packit ae235b
  args[0] = ":x"; args[1] = "y"; args[2] = NULL;
Packit ae235b
  check_string (g_build_pathv (":", args), ":x:y");
Packit ae235b
  args[0] = "x"; args[1] = "y:"; args[2] = NULL;
Packit ae235b
  check_string (g_build_pathv (":", args), "x:y:");
Packit ae235b
  args[0] = ":x:"; args[1] = ":y:"; args[2] = NULL;
Packit ae235b
  check_string (g_build_pathv (":", args), ":x:y:");
Packit ae235b
  args[0] = ":x::"; args[1] = "::y:"; args[2] = NULL;
Packit ae235b
  check_string (g_build_pathv (":", args), ":x:y:");
Packit ae235b
  args[0] = "x"; args[1] = ""; args[2] = "y"; args[3] = NULL;
Packit ae235b
  check_string (g_build_pathv (":", args), "x:y");
Packit ae235b
  args[0] = "x"; args[1] = ":"; args[2] = "y"; args[3] = NULL;
Packit ae235b
  check_string (g_build_pathv (":", args), "x:y");
Packit ae235b
  args[0] = "x"; args[1] = "::"; args[2] = "y"; args[3] = NULL;
Packit ae235b
  check_string (g_build_pathv (":", args), "x:y");
Packit ae235b
  args[0] = "x"; args[1] = "y"; args[2] = "z"; args[3] = NULL;
Packit ae235b
  check_string (g_build_pathv (":", args), "x:y:z");
Packit ae235b
  args[0] = ":x:"; args[1] = ":y:"; args[2] = ":z:"; args[3] = NULL;
Packit ae235b
  check_string (g_build_pathv (":", args), ":x:y:z:");
Packit ae235b
  args[0] = "::x::"; args[1] = "::y::"; args[2] = "::z::"; args[3] = NULL;
Packit ae235b
  check_string (g_build_pathv (":", args), "::x:y:z::");
Packit ae235b
Packit ae235b
  args[0] = NULL;
Packit ae235b
  check_string (g_build_pathv ("::", args), "");
Packit ae235b
  args[0] = "::"; args[1] = NULL;
Packit ae235b
  check_string (g_build_pathv ("::", args), "::");
Packit ae235b
  args[0] = ":::"; args[1] = NULL;
Packit ae235b
  check_string (g_build_pathv ("::", args), ":::");
Packit ae235b
  args[0] = "::x"; args[1] = NULL;
Packit ae235b
  check_string (g_build_pathv ("::", args), "::x");
Packit ae235b
  args[0] = "x::"; args[1] = NULL;
Packit ae235b
  check_string (g_build_pathv ("::", args), "x::");
Packit ae235b
  args[0] = ""; args[1] = "x"; args[2] = NULL;
Packit ae235b
  check_string (g_build_pathv ("::", args), "x");
Packit ae235b
  args[0] = ""; args[1] = "::x"; args[2] = NULL;
Packit ae235b
  check_string (g_build_pathv ("::", args), "::x");
Packit ae235b
  args[0] = "::"; args[1] = "x"; args[2] = NULL;
Packit ae235b
  check_string (g_build_pathv ("::", args), "::x");
Packit ae235b
  args[0] = "::::"; args[1] = "x"; args[2] = NULL;
Packit ae235b
  check_string (g_build_pathv ("::", args), "::::x");
Packit ae235b
  args[0] = "x"; args[1] = ""; args[2] = NULL;
Packit ae235b
  check_string (g_build_pathv ("::", args), "x");
Packit ae235b
  args[0] = "x::"; args[1] = ""; args[2] = NULL;
Packit ae235b
  check_string (g_build_pathv ("::", args), "x::");
Packit ae235b
  args[0] = "x"; args[1] = "::"; args[2] = NULL;
Packit ae235b
  check_string (g_build_pathv ("::", args), "x::");
Packit ae235b
  /* This following is weird, but keeps the definition simple */
Packit ae235b
  args[0] = "x"; args[1] = ":::"; args[2] = NULL;
Packit ae235b
  check_string (g_build_pathv ("::", args), "x:::::");
Packit ae235b
  args[0] = "x"; args[1] = "::::"; args[2] = NULL;
Packit ae235b
  check_string (g_build_pathv ("::", args), "x::::");
Packit ae235b
  args[0] = "x"; args[1] = "y"; args[2] = NULL;
Packit ae235b
  check_string (g_build_pathv ("::", args), "x::y");
Packit ae235b
  args[0] = "::x"; args[1] = "y"; args[2] = NULL;
Packit ae235b
  check_string (g_build_pathv ("::", args), "::x::y");
Packit ae235b
  args[0] = "x"; args[1] = "y::"; args[2] = NULL;
Packit ae235b
  check_string (g_build_pathv ("::", args), "x::y::");
Packit ae235b
  args[0] = "::x::"; args[1] = "::y::"; args[2] = NULL;
Packit ae235b
  check_string (g_build_pathv ("::", args), "::x::y::");
Packit ae235b
  args[0] = "::x:::"; args[1] = ":::y::"; args[2] = NULL;
Packit ae235b
  check_string (g_build_pathv ("::", args), "::x::::y::");
Packit ae235b
  args[0] = "::x::::"; args[1] = "::::y::"; args[2] = NULL;
Packit ae235b
  check_string (g_build_pathv ("::", args), "::x::y::");
Packit ae235b
  args[0] = "x"; args[1] = ""; args[2] = "y"; args[3] = NULL;
Packit ae235b
  check_string (g_build_pathv ("::", args), "x::y");
Packit ae235b
  args[0] = "x"; args[1] = "::"; args[2] = "y"; args[3] = NULL;
Packit ae235b
  check_string (g_build_pathv ("::", args), "x::y");
Packit ae235b
  args[0] = "x"; args[1] = "::::"; args[2] = "y"; args[3] = NULL;
Packit ae235b
  check_string (g_build_pathv ("::", args), "x::y");
Packit ae235b
  args[0] = "x"; args[1] = "y"; args[2] = "z"; args[3] = NULL;
Packit ae235b
  check_string (g_build_pathv ("::", args), "x::y::z");
Packit ae235b
  args[0] = "::x::"; args[1] = "::y::"; args[2] = "::z::"; args[3] = NULL;
Packit ae235b
  check_string (g_build_pathv ("::", args), "::x::y::z::");
Packit ae235b
  args[0] = ":::x:::"; args[1] = ":::y:::"; args[2] = ":::z:::"; args[3] = NULL;
Packit ae235b
  check_string (g_build_pathv ("::", args), ":::x::::y::::z:::");
Packit ae235b
  args[0] = "::::x::::"; args[1] = "::::y::::"; args[2] = "::::z::::"; args[3] = NULL;
Packit ae235b
  check_string (g_build_pathv ("::", args), "::::x::y::z::::");
Packit ae235b
}
Packit ae235b
Packit ae235b
static void
Packit ae235b
test_build_filename (void)
Packit ae235b
{
Packit ae235b
/*  check_string (g_build_filename (NULL), "");*/
Packit ae235b
  check_string (g_build_filename (S, NULL), S);
Packit ae235b
  check_string (g_build_filename (S"x", NULL), S"x");
Packit ae235b
  check_string (g_build_filename ("x"S, NULL), "x"S);
Packit ae235b
  check_string (g_build_filename ("", "x", NULL), "x");
Packit ae235b
  check_string (g_build_filename ("", S"x", NULL), S"x");
Packit ae235b
  check_string (g_build_filename (S, "x", NULL), S"x");
Packit ae235b
  check_string (g_build_filename (S S, "x", NULL), S S"x");
Packit ae235b
  check_string (g_build_filename ("x", "", NULL), "x");
Packit ae235b
  check_string (g_build_filename ("x"S, "", NULL), "x"S);
Packit ae235b
  check_string (g_build_filename ("x", S, NULL), "x"S);
Packit ae235b
  check_string (g_build_filename ("x", S S, NULL), "x"S S);
Packit ae235b
  check_string (g_build_filename ("x", "y",  NULL), "x"S"y");
Packit ae235b
  check_string (g_build_filename (S"x", "y", NULL), S"x"S"y");
Packit ae235b
  check_string (g_build_filename ("x", "y"S, NULL), "x"S"y"S);
Packit ae235b
  check_string (g_build_filename (S"x"S, S"y"S, NULL), S"x"S"y"S);
Packit ae235b
  check_string (g_build_filename (S"x"S S, S S"y"S, NULL), S"x"S"y"S);
Packit ae235b
  check_string (g_build_filename ("x", "", "y",  NULL), "x"S"y");
Packit ae235b
  check_string (g_build_filename ("x", S, "y",  NULL), "x"S"y");
Packit ae235b
  check_string (g_build_filename ("x", S S, "y",  NULL), "x"S"y");
Packit ae235b
  check_string (g_build_filename ("x", "y", "z", NULL), "x"S"y"S"z");
Packit ae235b
  check_string (g_build_filename (S"x"S, S"y"S, S"z"S, NULL), S"x"S"y"S"z"S);
Packit ae235b
  check_string (g_build_filename (S S"x"S S, S S"y"S S, S S"z"S S, NULL), S S"x"S"y"S"z"S S);
Packit ae235b
Packit ae235b
#ifdef G_OS_WIN32
Packit ae235b
Packit ae235b
  /* Test also using the slash as file name separator */
Packit ae235b
#define U "/"
Packit ae235b
  /* check_string (g_build_filename (NULL), ""); */
Packit ae235b
  check_string (g_build_filename (U, NULL), U);
Packit ae235b
  check_string (g_build_filename (U"x", NULL), U"x");
Packit ae235b
  check_string (g_build_filename ("x"U, NULL), "x"U);
Packit ae235b
  check_string (g_build_filename ("", U"x", NULL), U"x");
Packit ae235b
  check_string (g_build_filename ("", U"x", NULL), U"x");
Packit ae235b
  check_string (g_build_filename (U, "x", NULL), U"x");
Packit ae235b
  check_string (g_build_filename (U U, "x", NULL), U U"x");
Packit ae235b
  check_string (g_build_filename (U S, "x", NULL), U S"x");
Packit ae235b
  check_string (g_build_filename ("x"U, "", NULL), "x"U);
Packit ae235b
  check_string (g_build_filename ("x"S"y", "z"U"a", NULL), "x"S"y"S"z"U"a");
Packit ae235b
  check_string (g_build_filename ("x", U, NULL), "x"U);
Packit ae235b
  check_string (g_build_filename ("x", U U, NULL), "x"U U);
Packit ae235b
  check_string (g_build_filename ("x", S U, NULL), "x"S U);
Packit ae235b
  check_string (g_build_filename (U"x", "y", NULL), U"x"U"y");
Packit ae235b
  check_string (g_build_filename ("x", "y"U, NULL), "x"U"y"U);
Packit ae235b
  check_string (g_build_filename (U"x"U, U"y"U, NULL), U"x"U"y"U);
Packit ae235b
  check_string (g_build_filename (U"x"U U, U U"y"U, NULL), U"x"U"y"U);
Packit ae235b
  check_string (g_build_filename ("x", U, "y",  NULL), "x"U"y");
Packit ae235b
  check_string (g_build_filename ("x", U U, "y",  NULL), "x"U"y");
Packit ae235b
  check_string (g_build_filename ("x", U S, "y",  NULL), "x"S"y");
Packit ae235b
  check_string (g_build_filename ("x", S U, "y",  NULL), "x"U"y");
Packit ae235b
  check_string (g_build_filename ("x", U "y", "z", NULL), "x"U"y"U"z");
Packit ae235b
  check_string (g_build_filename ("x", S "y", "z", NULL), "x"S"y"S"z");
Packit ae235b
  check_string (g_build_filename ("x", S "y", "z", U, "a", "b", NULL), "x"S"y"S"z"U"a"U"b");
Packit ae235b
  check_string (g_build_filename (U"x"U, U"y"U, U"z"U, NULL), U"x"U"y"U"z"U);
Packit ae235b
  check_string (g_build_filename (U U"x"U U, U U"y"U U, U U"z"U U, NULL), U U"x"U"y"U"z"U U);
Packit ae235b
Packit ae235b
#undef U
Packit ae235b
Packit ae235b
#endif /* G_OS_WIN32 */
Packit ae235b
Packit ae235b
}
Packit ae235b
Packit ae235b
static void
Packit ae235b
test_build_filenamev (void)
Packit ae235b
{
Packit ae235b
  gchar *args[10];
Packit ae235b
Packit ae235b
  args[0] = NULL;
Packit ae235b
  check_string (g_build_filenamev (args), "");
Packit ae235b
  args[0] = S; args[1] = NULL;
Packit ae235b
  check_string (g_build_filenamev (args), S);
Packit ae235b
  args[0] = S"x"; args[1] = NULL;
Packit ae235b
  check_string (g_build_filenamev (args), S"x");
Packit ae235b
  args[0] = "x"S; args[1] = NULL;
Packit ae235b
  check_string (g_build_filenamev (args), "x"S);
Packit ae235b
  args[0] = ""; args[1] = "x"; args[2] = NULL;
Packit ae235b
  check_string (g_build_filenamev (args), "x");
Packit ae235b
  args[0] = ""; args[1] = S"x"; args[2] = NULL;
Packit ae235b
  check_string (g_build_filenamev (args), S"x");
Packit ae235b
  args[0] = S; args[1] = "x"; args[2] = NULL;
Packit ae235b
  check_string (g_build_filenamev (args), S"x");
Packit ae235b
  args[0] = S S; args[1] = "x"; args[2] = NULL;
Packit ae235b
  check_string (g_build_filenamev (args), S S"x");
Packit ae235b
  args[0] = "x"; args[1] = ""; args[2] = NULL;
Packit ae235b
  check_string (g_build_filenamev (args), "x");
Packit ae235b
  args[0] = "x"S; args[1] = ""; args[2] = NULL;
Packit ae235b
  check_string (g_build_filenamev (args), "x"S);
Packit ae235b
  args[0] = "x"; args[1] = S; args[2] = NULL;
Packit ae235b
  check_string (g_build_filenamev (args), "x"S);
Packit ae235b
  args[0] = "x"; args[1] = S S; args[2] = NULL;
Packit ae235b
  check_string (g_build_filenamev (args), "x"S S);
Packit ae235b
  args[0] = "x"; args[1] = "y"; args[2] = NULL;
Packit ae235b
  check_string (g_build_filenamev (args), "x"S"y");
Packit ae235b
  args[0] = S"x"; args[1] = "y"; args[2] = NULL;
Packit ae235b
  check_string (g_build_filenamev (args), S"x"S"y");
Packit ae235b
  args[0] = "x"; args[1] = "y"S; args[2] = NULL;
Packit ae235b
  check_string (g_build_filenamev (args), "x"S"y"S);
Packit ae235b
  args[0] = S"x"S; args[1] = S"y"S; args[2] = NULL;
Packit ae235b
  check_string (g_build_filenamev (args), S"x"S"y"S);
Packit ae235b
  args[0] = S"x"S S; args[1] = S S"y"S; args[2] = NULL;
Packit ae235b
  check_string (g_build_filenamev (args), S"x"S"y"S);
Packit ae235b
  args[0] = "x"; args[1] = ""; args[2] = "y"; args[3] = NULL;
Packit ae235b
  check_string (g_build_filenamev (args), "x"S"y");
Packit ae235b
  args[0] = "x"; args[1] = S; args[2] = "y"; args[3] = NULL;
Packit ae235b
  check_string (g_build_filenamev (args), "x"S"y");
Packit ae235b
  args[0] = "x"; args[1] = S S; args[2] = "y"; args[3] = NULL;
Packit ae235b
  check_string (g_build_filenamev (args), "x"S"y");
Packit ae235b
  args[0] = "x"; args[1] = "y"; args[2] = "z"; args[3] = NULL;
Packit ae235b
  check_string (g_build_filenamev (args), "x"S"y"S"z");
Packit ae235b
  args[0] = S"x"S; args[1] = S"y"S; args[2] = S"z"S; args[3] = NULL;
Packit ae235b
  check_string (g_build_filenamev (args), S"x"S"y"S"z"S);
Packit ae235b
  args[0] = S S"x"S S; args[1] = S S"y"S S; args[2] = S S"z"S S; args[3] = NULL;
Packit ae235b
  check_string (g_build_filenamev (args), S S"x"S"y"S"z"S S);
Packit ae235b
Packit ae235b
#ifdef G_OS_WIN32
Packit ae235b
Packit ae235b
  /* Test also using the slash as file name separator */
Packit ae235b
#define U "/"
Packit ae235b
  args[0] = NULL;
Packit ae235b
  check_string (g_build_filenamev (args), "");
Packit ae235b
  args[0] = U; args[1] = NULL;
Packit ae235b
  check_string (g_build_filenamev (args), U);
Packit ae235b
  args[0] = U"x"; args[1] = NULL;
Packit ae235b
  check_string (g_build_filenamev (args), U"x");
Packit ae235b
  args[0] = "x"U; args[1] = NULL;
Packit ae235b
  check_string (g_build_filenamev (args), "x"U);
Packit ae235b
  args[0] = ""; args[1] = U"x"; args[2] = NULL;
Packit ae235b
  check_string (g_build_filenamev (args), U"x");
Packit ae235b
  args[0] = ""; args[1] = U"x"; args[2] = NULL;
Packit ae235b
  check_string (g_build_filenamev (args), U"x");
Packit ae235b
  args[0] = U; args[1] = "x"; args[2] = NULL;
Packit ae235b
  check_string (g_build_filenamev (args), U"x");
Packit ae235b
  args[0] = U U; args[1] = "x"; args[2] = NULL;
Packit ae235b
  check_string (g_build_filenamev (args), U U"x");
Packit ae235b
  args[0] = U S; args[1] = "x"; args[2] = NULL;
Packit ae235b
  check_string (g_build_filenamev (args), U S"x");
Packit ae235b
  args[0] = "x"U; args[1] = ""; args[2] = NULL;
Packit ae235b
  check_string (g_build_filenamev (args), "x"U);
Packit ae235b
  args[0] = "x"S"y"; args[1] = "z"U"a"; args[2] = NULL;
Packit ae235b
  check_string (g_build_filenamev (args), "x"S"y"S"z"U"a");
Packit ae235b
  args[0] = "x"; args[1] = U; args[2] = NULL;
Packit ae235b
  check_string (g_build_filenamev (args), "x"U);
Packit ae235b
  args[0] = "x"; args[1] = U U; args[2] = NULL;
Packit ae235b
  check_string (g_build_filenamev (args), "x"U U);
Packit ae235b
  args[0] = "x"; args[1] = S U; args[2] = NULL;
Packit ae235b
  check_string (g_build_filenamev (args), "x"S U);
Packit ae235b
  args[0] = U"x"; args[1] = "y"; args[2] = NULL;
Packit ae235b
  check_string (g_build_filenamev (args), U"x"U"y");
Packit ae235b
  args[0] = "x"; args[1] = "y"U; args[2] = NULL;
Packit ae235b
  check_string (g_build_filenamev (args), "x"U"y"U);
Packit ae235b
  args[0] = U"x"U; args[1] = U"y"U; args[2] = NULL;
Packit ae235b
  check_string (g_build_filenamev (args), U"x"U"y"U);
Packit ae235b
  args[0] = U"x"U U; args[1] = U U"y"U; args[2] = NULL;
Packit ae235b
  check_string (g_build_filenamev (args), U"x"U"y"U);
Packit ae235b
  args[0] = "x"; args[1] = U; args[2] = "y", args[3] = NULL;
Packit ae235b
  check_string (g_build_filenamev (args), "x"U"y");
Packit ae235b
  args[0] = "x"; args[1] = U U; args[2] = "y", args[3] = NULL;
Packit ae235b
  check_string (g_build_filenamev (args), "x"U"y");
Packit ae235b
  args[0] = "x"; args[1] = U S; args[2] = "y", args[3] = NULL;
Packit ae235b
  check_string (g_build_filenamev (args), "x"S"y");
Packit ae235b
  args[0] = "x"; args[1] = S U; args[2] = "y", args[3] = NULL;
Packit ae235b
  check_string (g_build_filenamev (args), "x"U"y");
Packit ae235b
  args[0] = "x"; args[1] = U "y"; args[2] = "z", args[3] = NULL;
Packit ae235b
  check_string (g_build_filenamev (args), "x"U"y"U"z");
Packit ae235b
  args[0] = "x"; args[1] = S "y"; args[2] = "z", args[3] = NULL;
Packit ae235b
  check_string (g_build_filenamev (args), "x"S"y"S"z");
Packit ae235b
  args[0] = "x"; args[1] = S "y"; args[2] = "z", args[3] = U;
Packit ae235b
  args[4] = "a"; args[5] = "b"; args[6] = NULL;
Packit ae235b
  check_string (g_build_filenamev (args), "x"S"y"S"z"U"a"U"b");
Packit ae235b
  args[0] = U"x"U; args[1] = U"y"U; args[2] = U"z"U, args[3] = NULL;
Packit ae235b
  check_string (g_build_filenamev (args), U"x"U"y"U"z"U);
Packit ae235b
  args[0] = U U"x"U U; args[1] = U U"y"U U; args[2] = U U"z"U U, args[3] = NULL;
Packit ae235b
  check_string (g_build_filenamev (args), U U"x"U"y"U"z"U U);
Packit ae235b
Packit ae235b
#undef U
Packit ae235b
Packit ae235b
#endif /* G_OS_WIN32 */
Packit ae235b
}
Packit ae235b
Packit ae235b
#undef S
Packit ae235b
Packit ae235b
static void
Packit ae235b
test_mkdir_with_parents_1 (const gchar *base)
Packit ae235b
{
Packit ae235b
  char *p0 = g_build_filename (base, "fum", NULL);
Packit ae235b
  char *p1 = g_build_filename (p0, "tem", NULL);
Packit ae235b
  char *p2 = g_build_filename (p1, "zap", NULL);
Packit ae235b
  FILE *f;
Packit ae235b
Packit ae235b
  g_remove (p2);
Packit ae235b
  g_remove (p1);
Packit ae235b
  g_remove (p0);
Packit ae235b
Packit ae235b
  if (g_file_test (p0, G_FILE_TEST_EXISTS))
Packit ae235b
    g_error ("failed, %s exists, cannot test g_mkdir_with_parents\n", p0);
Packit ae235b
Packit ae235b
  if (g_file_test (p1, G_FILE_TEST_EXISTS))
Packit ae235b
    g_error ("failed, %s exists, cannot test g_mkdir_with_parents\n", p1);
Packit ae235b
Packit ae235b
  if (g_file_test (p2, G_FILE_TEST_EXISTS))
Packit ae235b
    g_error ("failed, %s exists, cannot test g_mkdir_with_parents\n", p2);
Packit ae235b
Packit ae235b
  if (g_mkdir_with_parents (p2, 0777) == -1)
Packit ae235b
    {
Packit ae235b
      int errsv = errno;
Packit ae235b
      g_error ("failed, g_mkdir_with_parents(%s) failed: %s\n", p2, g_strerror (errsv));
Packit ae235b
    }
Packit ae235b
Packit ae235b
  if (!g_file_test (p2, G_FILE_TEST_IS_DIR))
Packit ae235b
    g_error ("failed, g_mkdir_with_parents(%s) succeeded, but %s is not a directory\n", p2, p2);
Packit ae235b
Packit ae235b
  if (!g_file_test (p1, G_FILE_TEST_IS_DIR))
Packit ae235b
    g_error ("failed, g_mkdir_with_parents(%s) succeeded, but %s is not a directory\n", p2, p1);
Packit ae235b
Packit ae235b
  if (!g_file_test (p0, G_FILE_TEST_IS_DIR))
Packit ae235b
    g_error ("failed, g_mkdir_with_parents(%s) succeeded, but %s is not a directory\n", p2, p0);
Packit ae235b
Packit ae235b
  g_rmdir (p2);
Packit ae235b
  if (g_file_test (p2, G_FILE_TEST_EXISTS))
Packit ae235b
    g_error ("failed, did g_rmdir(%s), but %s is still there\n", p2, p2);
Packit ae235b
Packit ae235b
  g_rmdir (p1);
Packit ae235b
  if (g_file_test (p1, G_FILE_TEST_EXISTS))
Packit ae235b
    g_error ("failed, did g_rmdir(%s), but %s is still there\n", p1, p1);
Packit ae235b
Packit ae235b
  f = g_fopen (p1, "w");
Packit ae235b
  if (f == NULL)
Packit ae235b
    g_error ("failed, couldn't create file %s\n", p1);
Packit ae235b
  fclose (f);
Packit ae235b
Packit ae235b
  if (g_mkdir_with_parents (p1, 0666) == 0)
Packit ae235b
    g_error ("failed, g_mkdir_with_parents(%s) succeeded, even if %s is a file\n", p1, p1);
Packit ae235b
Packit ae235b
  if (g_mkdir_with_parents (p2, 0666) == 0)
Packit ae235b
    g_error("failed, g_mkdir_with_parents(%s) succeeded, even if %s is a file\n", p2, p1);
Packit ae235b
Packit ae235b
  g_remove (p2);
Packit ae235b
  g_remove (p1);
Packit ae235b
  g_remove (p0);
Packit ae235b
Packit ae235b
  g_free (p2);
Packit ae235b
  g_free (p1);
Packit ae235b
  g_free (p0);
Packit ae235b
}
Packit ae235b
Packit ae235b
static void
Packit ae235b
test_mkdir_with_parents (void)
Packit ae235b
{
Packit ae235b
  gchar *cwd;
Packit ae235b
  if (g_test_verbose())
Packit ae235b
    g_printerr ("checking g_mkdir_with_parents() in subdir ./hum/");
Packit ae235b
  test_mkdir_with_parents_1 ("hum");
Packit ae235b
  g_remove ("hum");
Packit ae235b
  if (g_test_verbose())
Packit ae235b
    g_printerr ("checking g_mkdir_with_parents() in subdir ./hii///haa/hee/");
Packit ae235b
  test_mkdir_with_parents_1 ("hii///haa/hee");
Packit ae235b
  g_remove ("hii/haa/hee");
Packit ae235b
  g_remove ("hii/haa");
Packit ae235b
  g_remove ("hii");
Packit ae235b
  cwd = g_get_current_dir ();
Packit ae235b
  if (g_test_verbose())
Packit ae235b
    g_printerr ("checking g_mkdir_with_parents() in cwd: %s", cwd);
Packit ae235b
  test_mkdir_with_parents_1 (cwd);
Packit ae235b
  g_free (cwd);
Packit ae235b
Packit ae235b
  g_assert_cmpint (g_mkdir_with_parents (NULL, 0), ==, -1);
Packit ae235b
  g_assert_cmpint (errno, ==, EINVAL);
Packit ae235b
}
Packit ae235b
Packit ae235b
static void
Packit ae235b
test_format_size_for_display (void)
Packit ae235b
{
Packit ae235b
#ifdef G_OS_WIN32
Packit ae235b
  SetThreadLocale (MAKELCID (MAKELANGID (LANG_ENGLISH, SUBLANG_ENGLISH_US), SORT_DEFAULT));
Packit ae235b
#endif
Packit ae235b
  /* nobody called setlocale(), so we should get "C" behaviour... */
Packit ae235b
  check_string (g_format_size_for_display (0), "0 bytes");
Packit ae235b
  check_string (g_format_size_for_display (1), "1 byte");
Packit ae235b
  check_string (g_format_size_for_display (2), "2 bytes");
Packit ae235b
  check_string (g_format_size_for_display (1024), "1.0 KB");
Packit ae235b
  check_string (g_format_size_for_display (1024 * 1024), "1.0 MB");
Packit ae235b
  check_string (g_format_size_for_display (1024 * 1024 * 1024), "1.0 GB");
Packit ae235b
  check_string (g_format_size_for_display (1024ULL * 1024 * 1024 * 1024), "1.0 TB");
Packit ae235b
  check_string (g_format_size_for_display (1024ULL * 1024 * 1024 * 1024 * 1024), "1.0 PB");
Packit ae235b
  check_string (g_format_size_for_display (1024ULL * 1024 * 1024 * 1024 * 1024 * 1024), "1.0 EB");
Packit ae235b
Packit ae235b
  check_string (g_format_size (0), "0 bytes");
Packit ae235b
  check_string (g_format_size (1), "1 byte");
Packit ae235b
  check_string (g_format_size (2), "2 bytes");
Packit ae235b
  check_string (g_format_size (1000ULL), "1.0 kB");
Packit ae235b
  check_string (g_format_size (1000ULL * 1000), "1.0 MB");
Packit ae235b
  check_string (g_format_size (1000ULL * 1000 * 1000), "1.0 GB");
Packit ae235b
  check_string (g_format_size (1000ULL * 1000 * 1000 * 1000), "1.0 TB");
Packit ae235b
  check_string (g_format_size (1000ULL * 1000 * 1000 * 1000 * 1000), "1.0 PB");
Packit ae235b
  check_string (g_format_size (1000ULL * 1000 * 1000 * 1000 * 1000 * 1000), "1.0 EB");
Packit ae235b
Packit ae235b
  check_string (g_format_size_full (0, G_FORMAT_SIZE_IEC_UNITS), "0 bytes");
Packit ae235b
  check_string (g_format_size_full (1, G_FORMAT_SIZE_IEC_UNITS), "1 byte");
Packit ae235b
  check_string (g_format_size_full (2, G_FORMAT_SIZE_IEC_UNITS), "2 bytes");
Packit ae235b
Packit ae235b
  check_string (g_format_size_full (2048ULL, G_FORMAT_SIZE_IEC_UNITS), "2.0 KiB");
Packit ae235b
  check_string (g_format_size_full (2048ULL * 1024, G_FORMAT_SIZE_IEC_UNITS), "2.0 MiB");
Packit ae235b
  check_string (g_format_size_full (2048ULL * 1024 * 1024, G_FORMAT_SIZE_IEC_UNITS), "2.0 GiB");
Packit ae235b
  check_string (g_format_size_full (2048ULL * 1024 * 1024 * 1024, G_FORMAT_SIZE_IEC_UNITS), "2.0 TiB");
Packit ae235b
  check_string (g_format_size_full (2048ULL * 1024 * 1024 * 1024 * 1024, G_FORMAT_SIZE_IEC_UNITS), "2.0 PiB");
Packit ae235b
  check_string (g_format_size_full (2048ULL * 1024 * 1024 * 1024 * 1024 * 1024, G_FORMAT_SIZE_IEC_UNITS), "2.0 EiB");
Packit ae235b
Packit ae235b
  check_string (g_format_size_full (238472938, G_FORMAT_SIZE_IEC_UNITS), "227.4 MiB");
Packit ae235b
  check_string (g_format_size_full (238472938, G_FORMAT_SIZE_DEFAULT), "238.5 MB");
Packit ae235b
  check_string (g_format_size_full (238472938, G_FORMAT_SIZE_LONG_FORMAT), "238.5 MB (238472938 bytes)");
Packit ae235b
Packit ae235b
Packit ae235b
  check_string (g_format_size_full (0, G_FORMAT_SIZE_BITS), "0 bits");
Packit ae235b
  check_string (g_format_size_full (1, G_FORMAT_SIZE_BITS), "1 bit");
Packit ae235b
  check_string (g_format_size_full (2, G_FORMAT_SIZE_BITS), "2 bits");
Packit ae235b
Packit ae235b
  check_string (g_format_size_full (2000ULL, G_FORMAT_SIZE_BITS), "2.0 kb");
Packit ae235b
  check_string (g_format_size_full (2000ULL * 1000, G_FORMAT_SIZE_BITS), "2.0 Mb");
Packit ae235b
  check_string (g_format_size_full (2000ULL * 1000 * 1000, G_FORMAT_SIZE_BITS), "2.0 Gb");
Packit ae235b
  check_string (g_format_size_full (2000ULL * 1000 * 1000 * 1000, G_FORMAT_SIZE_BITS), "2.0 Tb");
Packit ae235b
  check_string (g_format_size_full (2000ULL * 1000 * 1000 * 1000 * 1000, G_FORMAT_SIZE_BITS), "2.0 Pb");
Packit ae235b
  check_string (g_format_size_full (2000ULL * 1000 * 1000 * 1000 * 1000 * 1000, G_FORMAT_SIZE_BITS), "2.0 Eb");
Packit ae235b
Packit ae235b
  check_string (g_format_size_full (238472938, G_FORMAT_SIZE_BITS), "238.5 Mb");
Packit ae235b
  check_string (g_format_size_full (238472938, G_FORMAT_SIZE_BITS | G_FORMAT_SIZE_LONG_FORMAT), "238.5 Mb (238472938 bits)");
Packit ae235b
Packit ae235b
Packit ae235b
  check_string (g_format_size_full (0, G_FORMAT_SIZE_BITS | G_FORMAT_SIZE_IEC_UNITS), "0 bits");
Packit ae235b
  check_string (g_format_size_full (1, G_FORMAT_SIZE_BITS | G_FORMAT_SIZE_IEC_UNITS), "1 bit");
Packit ae235b
  check_string (g_format_size_full (2, G_FORMAT_SIZE_BITS | G_FORMAT_SIZE_IEC_UNITS), "2 bits");
Packit ae235b
Packit ae235b
  check_string (g_format_size_full (2048ULL, G_FORMAT_SIZE_BITS | G_FORMAT_SIZE_IEC_UNITS), "2.0 Kib");
Packit ae235b
  check_string (g_format_size_full (2048ULL * 1024, G_FORMAT_SIZE_BITS | G_FORMAT_SIZE_IEC_UNITS), "2.0 Mib");
Packit ae235b
  check_string (g_format_size_full (2048ULL * 1024 * 1024, G_FORMAT_SIZE_BITS | G_FORMAT_SIZE_IEC_UNITS), "2.0 Gib");
Packit ae235b
  check_string (g_format_size_full (2048ULL * 1024 * 1024 * 1024, G_FORMAT_SIZE_BITS | G_FORMAT_SIZE_IEC_UNITS), "2.0 Tib");
Packit ae235b
  check_string (g_format_size_full (2048ULL * 1024 * 1024 * 1024 * 1024, G_FORMAT_SIZE_BITS | G_FORMAT_SIZE_IEC_UNITS), "2.0 Pib");
Packit ae235b
  check_string (g_format_size_full (2048ULL * 1024 * 1024 * 1024 * 1024 * 1024, G_FORMAT_SIZE_BITS | G_FORMAT_SIZE_IEC_UNITS), "2.0 Eib");
Packit ae235b
Packit ae235b
  check_string (g_format_size_full (238472938, G_FORMAT_SIZE_BITS | G_FORMAT_SIZE_IEC_UNITS), "227.4 Mib");
Packit ae235b
  check_string (g_format_size_full (238472938, G_FORMAT_SIZE_BITS | G_FORMAT_SIZE_IEC_UNITS | G_FORMAT_SIZE_LONG_FORMAT), "227.4 Mib (238472938 bits)");
Packit ae235b
}
Packit ae235b
Packit ae235b
static void
Packit ae235b
test_file_errors (void)
Packit ae235b
{
Packit ae235b
#ifdef EEXIST
Packit ae235b
  g_assert_cmpint (g_file_error_from_errno (EEXIST), ==, G_FILE_ERROR_EXIST);
Packit ae235b
#endif
Packit ae235b
#ifdef EISDIR
Packit ae235b
  g_assert_cmpint (g_file_error_from_errno (EISDIR), ==, G_FILE_ERROR_ISDIR);
Packit ae235b
#endif
Packit ae235b
#ifdef EACCES
Packit ae235b
  g_assert_cmpint (g_file_error_from_errno (EACCES), ==, G_FILE_ERROR_ACCES);
Packit ae235b
#endif
Packit ae235b
#ifdef ENAMETOOLONG
Packit ae235b
  g_assert_cmpint (g_file_error_from_errno (ENAMETOOLONG), ==, G_FILE_ERROR_NAMETOOLONG);
Packit ae235b
#endif
Packit ae235b
#ifdef ENOENT
Packit ae235b
  g_assert_cmpint (g_file_error_from_errno (ENOENT), ==, G_FILE_ERROR_NOENT);
Packit ae235b
#endif
Packit ae235b
#ifdef ENOTDIR
Packit ae235b
  g_assert_cmpint (g_file_error_from_errno (ENOTDIR), ==, G_FILE_ERROR_NOTDIR);
Packit ae235b
#endif
Packit ae235b
#ifdef ENXIO
Packit ae235b
  g_assert_cmpint (g_file_error_from_errno (ENXIO), ==, G_FILE_ERROR_NXIO);
Packit ae235b
#endif
Packit ae235b
#ifdef ENODEV
Packit ae235b
  g_assert_cmpint (g_file_error_from_errno (ENODEV), ==, G_FILE_ERROR_NODEV);
Packit ae235b
#endif
Packit ae235b
#ifdef EROFS
Packit ae235b
  g_assert_cmpint (g_file_error_from_errno (EROFS), ==, G_FILE_ERROR_ROFS);
Packit ae235b
#endif
Packit ae235b
#ifdef ETXTBSY
Packit ae235b
  g_assert_cmpint (g_file_error_from_errno (ETXTBSY), ==, G_FILE_ERROR_TXTBSY);
Packit ae235b
#endif
Packit ae235b
#ifdef EFAULT
Packit ae235b
  g_assert_cmpint (g_file_error_from_errno (EFAULT), ==, G_FILE_ERROR_FAULT);
Packit ae235b
#endif
Packit ae235b
#ifdef ELOOP
Packit ae235b
  g_assert_cmpint (g_file_error_from_errno (ELOOP), ==, G_FILE_ERROR_LOOP);
Packit ae235b
#endif
Packit ae235b
#ifdef ENOSPC
Packit ae235b
  g_assert_cmpint (g_file_error_from_errno (ENOSPC), ==, G_FILE_ERROR_NOSPC);
Packit ae235b
#endif
Packit ae235b
#ifdef ENOMEM
Packit ae235b
  g_assert_cmpint (g_file_error_from_errno (ENOMEM), ==, G_FILE_ERROR_NOMEM);
Packit ae235b
#endif
Packit ae235b
#ifdef EMFILE
Packit ae235b
  g_assert_cmpint (g_file_error_from_errno (EMFILE), ==, G_FILE_ERROR_MFILE);
Packit ae235b
#endif
Packit ae235b
#ifdef ENFILE
Packit ae235b
  g_assert_cmpint (g_file_error_from_errno (ENFILE), ==, G_FILE_ERROR_NFILE);
Packit ae235b
#endif
Packit ae235b
#ifdef EBADF
Packit ae235b
  g_assert_cmpint (g_file_error_from_errno (EBADF), ==, G_FILE_ERROR_BADF);
Packit ae235b
#endif
Packit ae235b
#ifdef EINVAL
Packit ae235b
  g_assert_cmpint (g_file_error_from_errno (EINVAL), ==, G_FILE_ERROR_INVAL);
Packit ae235b
#endif
Packit ae235b
#ifdef EPIPE
Packit ae235b
  g_assert_cmpint (g_file_error_from_errno (EPIPE), ==, G_FILE_ERROR_PIPE);
Packit ae235b
#endif
Packit ae235b
#ifdef EAGAIN
Packit ae235b
  g_assert_cmpint (g_file_error_from_errno (EAGAIN), ==, G_FILE_ERROR_AGAIN);
Packit ae235b
#endif
Packit ae235b
#ifdef EINTR
Packit ae235b
  g_assert_cmpint (g_file_error_from_errno (EINTR), ==, G_FILE_ERROR_INTR);
Packit ae235b
#endif
Packit ae235b
#ifdef EIO
Packit ae235b
  g_assert_cmpint (g_file_error_from_errno (EIO), ==, G_FILE_ERROR_IO);
Packit ae235b
#endif
Packit ae235b
#ifdef EPERM
Packit ae235b
  g_assert_cmpint (g_file_error_from_errno (EPERM), ==, G_FILE_ERROR_PERM);
Packit ae235b
#endif
Packit ae235b
#ifdef ENOSYS
Packit ae235b
  g_assert_cmpint (g_file_error_from_errno (ENOSYS), ==, G_FILE_ERROR_NOSYS);
Packit ae235b
#endif
Packit ae235b
}
Packit ae235b
Packit ae235b
static void
Packit ae235b
test_basename (void)
Packit ae235b
{
Packit ae235b
  gchar *b;
Packit ae235b
Packit ae235b
  b = g_path_get_basename ("");
Packit ae235b
  g_assert_cmpstr (b, ==, ".");
Packit ae235b
  g_free (b);
Packit ae235b
Packit ae235b
  b = g_path_get_basename ("///");
Packit ae235b
  g_assert_cmpstr (b, ==, G_DIR_SEPARATOR_S);
Packit ae235b
  g_free (b);
Packit ae235b
Packit ae235b
  b = g_path_get_basename ("/a/b/c/d");
Packit ae235b
  g_assert_cmpstr (b, ==, "d");
Packit ae235b
  g_free (b);
Packit ae235b
}
Packit ae235b
Packit ae235b
static void
Packit ae235b
test_dir_make_tmp (void)
Packit ae235b
{
Packit ae235b
  gchar *name;
Packit ae235b
  GError *error = NULL;
Packit ae235b
  gint ret;
Packit ae235b
Packit ae235b
  name = g_dir_make_tmp ("testXXXXXXtest", &error);
Packit ae235b
  g_assert_no_error (error);
Packit ae235b
  g_assert_true (g_file_test (name, G_FILE_TEST_IS_DIR));
Packit ae235b
  ret = g_rmdir (name);
Packit ae235b
  g_assert_cmpint (ret, ==, 0);
Packit ae235b
  g_free (name);
Packit ae235b
Packit ae235b
  name = g_dir_make_tmp (NULL, &error);
Packit ae235b
  g_assert_no_error (error);
Packit ae235b
  g_assert_true (g_file_test (name, G_FILE_TEST_IS_DIR));
Packit ae235b
  ret = g_rmdir (name);
Packit ae235b
  g_assert_cmpint (ret, ==, 0);
Packit ae235b
  g_free (name);
Packit ae235b
Packit ae235b
  name = g_dir_make_tmp ("test/XXXXXX", &error);
Packit ae235b
  g_assert_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED);
Packit ae235b
  g_clear_error (&error);
Packit ae235b
  g_assert_null (name);
Packit ae235b
Packit ae235b
  name = g_dir_make_tmp ("XXXXxX", &error);
Packit ae235b
  g_assert_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED);
Packit ae235b
  g_clear_error (&error);
Packit ae235b
  g_assert_null (name);
Packit ae235b
}
Packit ae235b
Packit ae235b
static void
Packit ae235b
test_file_open_tmp (void)
Packit ae235b
{
Packit ae235b
  gchar *name = NULL;
Packit ae235b
  GError *error = NULL;
Packit ae235b
  gint fd;
Packit ae235b
Packit ae235b
  fd = g_file_open_tmp ("testXXXXXXtest", &name, &error);
Packit ae235b
  g_assert_cmpint (fd, !=, -1);
Packit ae235b
  g_assert_no_error (error);
Packit ae235b
  g_assert_nonnull (name);
Packit ae235b
  unlink (name);
Packit ae235b
  g_free (name);
Packit ae235b
  close (fd);
Packit ae235b
Packit ae235b
  fd = g_file_open_tmp (NULL, &name, &error);
Packit ae235b
  g_assert_cmpint (fd, !=, -1);
Packit ae235b
  g_assert_no_error (error);
Packit ae235b
  g_assert_nonnull (name);
Packit ae235b
  g_unlink (name);
Packit ae235b
  g_free (name);
Packit ae235b
  close (fd);
Packit ae235b
Packit ae235b
  name = NULL;
Packit ae235b
  fd = g_file_open_tmp ("test/XXXXXX", &name, &error);
Packit ae235b
  g_assert_cmpint (fd, ==, -1);
Packit ae235b
  g_assert_null (name);
Packit ae235b
  g_assert_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED);
Packit ae235b
  g_clear_error (&error);
Packit ae235b
Packit ae235b
  fd = g_file_open_tmp ("XXXXxX", &name, &error);
Packit ae235b
  g_assert_cmpint (fd, ==, -1);
Packit ae235b
  g_assert_null (name);
Packit ae235b
  g_assert_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED);
Packit ae235b
  g_clear_error (&error);
Packit ae235b
}
Packit ae235b
Packit ae235b
static void
Packit ae235b
test_mkstemp (void)
Packit ae235b
{
Packit ae235b
  gchar *name;
Packit ae235b
  gint fd;
Packit ae235b
Packit ae235b
  name = g_strdup ("testXXXXXXtest"),
Packit ae235b
  fd = g_mkstemp (name);
Packit ae235b
  g_assert_cmpint (fd, !=, -1);
Packit ae235b
  g_assert_null (strstr (name, "XXXXXX"));
Packit ae235b
  unlink (name);
Packit ae235b
  close (fd);
Packit ae235b
  g_free (name);
Packit ae235b
Packit ae235b
  name = g_strdup ("testYYYYYYtest"),
Packit ae235b
  fd = g_mkstemp (name);
Packit ae235b
  g_assert_cmpint (fd, ==, -1);
Packit ae235b
  g_free (name);
Packit ae235b
}
Packit ae235b
Packit ae235b
static void
Packit ae235b
test_mkdtemp (void)
Packit ae235b
{
Packit ae235b
  gchar *name;
Packit ae235b
  gchar *ret;
Packit ae235b
Packit ae235b
  name = g_strdup ("testXXXXXXtest"),
Packit ae235b
  ret = g_mkdtemp (name);
Packit ae235b
  g_assert (ret == name);
Packit ae235b
  g_assert_null (strstr (name, "XXXXXX"));
Packit ae235b
  g_rmdir (name);
Packit ae235b
  g_free (name);
Packit ae235b
Packit ae235b
  name = g_strdup ("testYYYYYYtest"),
Packit ae235b
  ret = g_mkdtemp (name);
Packit ae235b
  g_assert_null (ret);
Packit ae235b
  g_free (name);
Packit ae235b
}
Packit ae235b
Packit ae235b
static void
Packit ae235b
test_set_contents (void)
Packit ae235b
{
Packit ae235b
  GError *error = NULL;
Packit ae235b
  gint fd;
Packit ae235b
  gchar *name;
Packit ae235b
  gchar *buf;
Packit ae235b
  gsize len;
Packit ae235b
  gboolean ret;
Packit ae235b
Packit ae235b
  fd = g_file_open_tmp (NULL, &name, &error);
Packit ae235b
  g_assert_no_error (error);
Packit ae235b
  write (fd, "a", 1);
Packit ae235b
  close (fd);
Packit ae235b
Packit ae235b
  ret = g_file_get_contents (name, &buf, &len, &error);
Packit ae235b
  g_assert_true (ret);
Packit ae235b
  g_assert_no_error (error);
Packit ae235b
  g_assert_cmpstr (buf, ==, "a");
Packit ae235b
  g_free (buf);
Packit ae235b
Packit ae235b
  ret = g_file_set_contents (name, "b", 1, &error);
Packit ae235b
  g_assert_true (ret);
Packit ae235b
  g_assert_no_error (error);
Packit ae235b
Packit ae235b
  ret = g_file_get_contents (name, &buf, &len, &error);
Packit ae235b
  g_assert_true (ret);
Packit ae235b
  g_assert_no_error (error);
Packit ae235b
  g_assert_cmpstr (buf, ==, "b");
Packit ae235b
  g_free (buf);
Packit ae235b
Packit ae235b
  g_remove (name);
Packit ae235b
  g_free (name);
Packit ae235b
}
Packit ae235b
Packit ae235b
static void
Packit ae235b
test_read_link (void)
Packit ae235b
{
Packit ae235b
#ifdef HAVE_READLINK
Packit ae235b
#ifdef G_OS_UNIX
Packit ae235b
  int ret;
Packit ae235b
  const gchar *oldpath;
Packit ae235b
  gchar *cwd;
Packit ae235b
  gchar *newpath;
Packit ae235b
  gchar *badpath;
Packit ae235b
  gchar *path;
Packit ae235b
  GError *error = NULL;
Packit ae235b
Packit ae235b
  cwd = g_get_current_dir ();
Packit ae235b
Packit ae235b
  oldpath = g_test_get_filename (G_TEST_DIST, "4096-random-bytes", NULL);
Packit ae235b
  newpath = g_build_filename (cwd, "page-of-junk", NULL);
Packit ae235b
  badpath = g_build_filename (cwd, "4097-random-bytes", NULL);
Packit ae235b
  remove (newpath);
Packit ae235b
  ret = symlink (oldpath, newpath);
Packit ae235b
  g_assert_cmpint (ret, ==, 0);
Packit ae235b
  path = g_file_read_link (newpath, &error);
Packit ae235b
  g_assert_no_error (error);
Packit ae235b
  g_assert_cmpstr (path, ==, oldpath);
Packit ae235b
  g_free (path);
Packit ae235b
Packit ae235b
  remove (newpath);
Packit ae235b
  ret = symlink (badpath, newpath);
Packit ae235b
  g_assert_cmpint (ret, ==, 0);
Packit ae235b
  path = g_file_read_link (newpath, &error);
Packit ae235b
  g_assert_no_error (error);
Packit ae235b
  g_assert_cmpstr (path, ==, badpath);
Packit ae235b
  g_free (path);
Packit ae235b
Packit ae235b
  path = g_file_read_link (oldpath, &error);
Packit ae235b
  g_assert_error (error, G_FILE_ERROR, G_FILE_ERROR_INVAL);
Packit ae235b
  g_assert_null (path);
Packit ae235b
  g_error_free (error);
Packit ae235b
Packit ae235b
  remove (newpath);
Packit ae235b
  g_free (cwd);
Packit ae235b
  g_free (newpath);
Packit ae235b
  g_free (badpath);
Packit ae235b
Packit ae235b
#endif
Packit ae235b
#else
Packit ae235b
  g_test_skip ("Symbolic links not supported");
Packit ae235b
#endif
Packit ae235b
}
Packit ae235b
Packit ae235b
static void
Packit ae235b
test_stdio_wrappers (void)
Packit ae235b
{
Packit ae235b
  GStatBuf buf;
Packit ae235b
  gchar *cwd, *path;
Packit ae235b
  gint ret;
Packit ae235b
  struct utimbuf ut;
Packit ae235b
  GError *error = NULL;
Packit ae235b
Packit ae235b
  g_remove ("mkdir-test/test-create");
Packit ae235b
  ret = g_rmdir ("mkdir-test");
Packit ae235b
  g_assert (ret == 0 || errno == ENOENT);
Packit ae235b
Packit ae235b
  ret = g_stat ("mkdir-test", &buf;;
Packit ae235b
  g_assert_cmpint (ret, ==, -1);
Packit ae235b
  ret = g_mkdir ("mkdir-test", 0666);
Packit ae235b
  g_assert_cmpint (ret, ==, 0);
Packit ae235b
  ret = g_stat ("mkdir-test", &buf;;
Packit ae235b
  g_assert_cmpint (ret, ==, 0);
Packit ae235b
  g_assert_cmpint (S_ISDIR (buf.st_mode), !=, 0);
Packit ae235b
Packit ae235b
  cwd = g_get_current_dir ();
Packit ae235b
  path = g_build_filename (cwd, "mkdir-test", NULL);
Packit ae235b
  g_free (cwd);
Packit ae235b
  ret = g_chdir (path);
Packit ae235b
  g_assert_cmpint (errno, ==, EACCES);
Packit ae235b
  g_assert_cmpint (ret, ==, -1);
Packit ae235b
  ret = g_chmod (path, 0777);
Packit ae235b
  g_assert_cmpint (ret, ==, 0);
Packit ae235b
  ret = g_chdir (path);
Packit ae235b
  g_assert_cmpint (ret, ==, 0);
Packit ae235b
  cwd = g_get_current_dir ();
Packit ae235b
  g_assert_true (g_str_equal (cwd, path));
Packit ae235b
  g_free (cwd);
Packit ae235b
  g_free (path);
Packit ae235b
Packit ae235b
  ret = g_creat ("test-creat", 0555);
Packit ae235b
  g_close (ret, &error);
Packit ae235b
  g_assert_no_error (error);
Packit ae235b
Packit ae235b
  ret = g_access ("test-creat", F_OK);
Packit ae235b
  g_assert_cmpint (ret, ==, 0);
Packit ae235b
Packit ae235b
  ret = g_rename ("test-creat", "test-create");
Packit ae235b
  g_assert_cmpint (ret, ==, 0);
Packit ae235b
Packit ae235b
  ret = g_open ("test-create", O_RDONLY, 0666);
Packit ae235b
  g_close (ret, &error);
Packit ae235b
  g_assert_no_error (error);
Packit ae235b
Packit ae235b
  ut.actime = ut.modtime = (time_t)0;
Packit ae235b
  ret = g_utime ("test-create", &ut);
Packit ae235b
  g_assert_cmpint (ret, ==, 0);
Packit ae235b
Packit ae235b
  ret = g_lstat ("test-create", &buf;;
Packit ae235b
  g_assert_cmpint (ret, ==, 0);
Packit ae235b
  g_assert_cmpint (buf.st_atime, ==, (time_t)0);
Packit ae235b
  g_assert_cmpint (buf.st_mtime, ==, (time_t)0);
Packit ae235b
Packit ae235b
  g_chdir ("..");
Packit ae235b
  g_remove ("mkdir-test/test-create");
Packit ae235b
  g_rmdir ("mkdir-test");
Packit ae235b
}
Packit ae235b
Packit ae235b
int
Packit ae235b
main (int   argc,
Packit ae235b
      char *argv[])
Packit ae235b
{
Packit ae235b
  g_setenv ("LC_ALL", "C", TRUE);
Packit ae235b
  g_test_init (&argc, &argv, NULL);
Packit ae235b
Packit ae235b
  g_test_add_func ("/fileutils/build-path", test_build_path);
Packit ae235b
  g_test_add_func ("/fileutils/build-pathv", test_build_pathv);
Packit ae235b
  g_test_add_func ("/fileutils/build-filename", test_build_filename);
Packit ae235b
  g_test_add_func ("/fileutils/build-filenamev", test_build_filenamev);
Packit ae235b
  g_test_add_func ("/fileutils/mkdir-with-parents", test_mkdir_with_parents);
Packit ae235b
  g_test_add_func ("/fileutils/format-size-for-display", test_format_size_for_display);
Packit ae235b
  g_test_add_func ("/fileutils/errors", test_file_errors);
Packit ae235b
  g_test_add_func ("/fileutils/basename", test_basename);
Packit ae235b
  g_test_add_func ("/fileutils/dir-make-tmp", test_dir_make_tmp);
Packit ae235b
  g_test_add_func ("/fileutils/file-open-tmp", test_file_open_tmp);
Packit ae235b
  g_test_add_func ("/fileutils/mkstemp", test_mkstemp);
Packit ae235b
  g_test_add_func ("/fileutils/mkdtemp", test_mkdtemp);
Packit ae235b
  g_test_add_func ("/fileutils/set-contents", test_set_contents);
Packit ae235b
  g_test_add_func ("/fileutils/read-link", test_read_link);
Packit ae235b
  g_test_add_func ("/fileutils/stdio-wrappers", test_stdio_wrappers);
Packit ae235b
Packit ae235b
  return g_test_run ();
Packit ae235b
}