Blame libglnx/tests/test-libglnx-shutil.c

rpm-build 0fba15
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*-
rpm-build 0fba15
 *
rpm-build 0fba15
 * Copyright © 2017 Endless Mobile, Inc.
rpm-build 0fba15
 *
rpm-build 0fba15
 * This library is free software; you can redistribute it and/or
rpm-build 0fba15
 * modify it under the terms of the GNU Lesser General Public
rpm-build 0fba15
 * License as published by the Free Software Foundation; either
rpm-build 0fba15
 * version 2 of the License, or (at your option) any later version.
rpm-build 0fba15
 *
rpm-build 0fba15
 * This library is distributed in the hope that it will be useful,
rpm-build 0fba15
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
rpm-build 0fba15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
rpm-build 0fba15
 * Lesser General Public License for more details.
rpm-build 0fba15
 *
rpm-build 0fba15
 * You should have received a copy of the GNU Lesser General Public
rpm-build 0fba15
 * License along with this library; if not, write to the
rpm-build 0fba15
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
rpm-build 0fba15
 * Boston, MA 02111-1307, USA.
rpm-build 0fba15
 */
rpm-build 0fba15
rpm-build 0fba15
#include "config.h"
rpm-build 0fba15
#include "libglnx.h"
rpm-build 0fba15
#include <glib.h>
rpm-build 0fba15
#include <stdlib.h>
rpm-build 0fba15
#include <gio/gio.h>
rpm-build 0fba15
#include <err.h>
rpm-build 0fba15
#include <string.h>
rpm-build 0fba15
rpm-build 0fba15
#include "libglnx-testlib.h"
rpm-build 0fba15
rpm-build 0fba15
static void
rpm-build 0fba15
test_mkdir_p_enoent (void)
rpm-build 0fba15
{
rpm-build 0fba15
  _GLNX_TEST_DECLARE_ERROR(local_error, error);
rpm-build 0fba15
  glnx_autofd int dfd = -1;
rpm-build 0fba15
rpm-build 0fba15
  if (!glnx_ensure_dir (AT_FDCWD, "test", 0755, error))
rpm-build 0fba15
    return;
rpm-build 0fba15
  if (!glnx_opendirat (AT_FDCWD, "test", FALSE, &dfd, error))
rpm-build 0fba15
    return;
rpm-build 0fba15
  if (rmdir ("test") < 0)
rpm-build 0fba15
    return (void) glnx_throw_errno_prefix (error, "rmdir(%s)", "test");
rpm-build 0fba15
rpm-build 0fba15
  /* This should fail with ENOENT. */
rpm-build 0fba15
  glnx_shutil_mkdir_p_at (dfd, "blah/baz", 0755, NULL, error);
rpm-build 0fba15
  g_assert_error (local_error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND);
rpm-build 0fba15
  g_clear_error (&local_error);
rpm-build 0fba15
}
rpm-build 0fba15
rpm-build 0fba15
int
rpm-build 0fba15
main (int    argc,
rpm-build 0fba15
      char **argv)
rpm-build 0fba15
{
rpm-build 0fba15
  int ret;
rpm-build 0fba15
rpm-build 0fba15
  g_test_init (&argc, &argv, NULL);
rpm-build 0fba15
rpm-build 0fba15
  g_test_add_func ("/mkdir-p/enoent", test_mkdir_p_enoent);
rpm-build 0fba15
rpm-build 0fba15
  ret = g_test_run();
rpm-build 0fba15
rpm-build 0fba15
  return ret;
rpm-build 0fba15
}