Blame tests/dirname-test.c

Packit ae235b
/* GLIB - Library of useful routines for C programming
Packit ae235b
 * Copyright (C) 1995-1997  Peter Mattis, Spencer Kimball and Josh MacDonald
Packit ae235b
 *
Packit ae235b
 * This library is free software; you can redistribute it and/or
Packit ae235b
 * modify it under the terms of the GNU Lesser General Public
Packit ae235b
 * License as published by the Free Software Foundation; either
Packit ae235b
 * version 2.1 of the License, or (at your option) any later version.
Packit ae235b
 *
Packit ae235b
 * This library 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.  See the GNU
Packit ae235b
 * Lesser General Public License for more details.
Packit ae235b
 *
Packit ae235b
 * You should have received a copy of the GNU Lesser General Public
Packit ae235b
 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
Packit ae235b
 */
Packit ae235b
Packit ae235b
/*
Packit ae235b
 * Modified by the GLib Team and others 1997-2000.  See the AUTHORS
Packit ae235b
 * file for a list of people on the GLib Team.  See the ChangeLog
Packit ae235b
 * files for a list of changes.  These files are distributed with
Packit ae235b
 * GLib at ftp://ftp.gtk.org/pub/gtk/. 
Packit ae235b
 */
Packit ae235b
Packit ae235b
#undef G_DISABLE_ASSERT
Packit ae235b
#undef G_LOG_DOMAIN
Packit ae235b
Packit ae235b
#include <stdio.h>
Packit ae235b
#include <string.h>
Packit ae235b
#include "glib.h"
Packit ae235b
Packit ae235b
int array[10000];
Packit ae235b
gboolean failed = FALSE;
Packit ae235b
Packit ae235b
#define	TEST(m,cond)	G_STMT_START { failed = !(cond); \
Packit ae235b
if (failed) \
Packit ae235b
  { if (!m) \
Packit ae235b
      g_print ("\n(%s:%d) failed for: %s\n", __FILE__, __LINE__, ( # cond )); \
Packit ae235b
    else \
Packit ae235b
      g_print ("\n(%s:%d) failed for: %s: (%s)\n", __FILE__, __LINE__, ( # cond ), (gchar*)m); \
Packit ae235b
  } \
Packit ae235b
else \
Packit ae235b
  g_print ("."); fflush (stdout); \
Packit ae235b
} G_STMT_END
Packit ae235b
Packit ae235b
#define	C2P(c)		((gpointer) ((long) (c)))
Packit ae235b
#define	P2C(p)		((gchar) ((long) (p)))
Packit ae235b
Packit ae235b
#define GLIB_TEST_STRING "el dorado "
Packit ae235b
#define GLIB_TEST_STRING_5 "el do"
Packit ae235b
Packit ae235b
int
Packit ae235b
main (int   argc,
Packit ae235b
      char *argv[])
Packit ae235b
{
Packit ae235b
  gint i;
Packit ae235b
  struct {
Packit ae235b
    gchar *filename;
Packit ae235b
    gchar *dirname;
Packit ae235b
  } dirname_checks[] = {
Packit ae235b
    { "/", "/" },
Packit ae235b
    { "////", "/" },
Packit ae235b
    { ".////", "." },
Packit ae235b
    { ".", "." },
Packit ae235b
    { "..", "." },
Packit ae235b
    { "../", ".." },
Packit ae235b
    { "..////", ".." },
Packit ae235b
    { "", "." },
Packit ae235b
    { "a/b", "a" },
Packit ae235b
    { "a/b/", "a/b" },
Packit ae235b
    { "c///", "c" },
Packit ae235b
    { "/a/b", "/a" },
Packit ae235b
    { "/a/b/", "/a/b" },
Packit ae235b
#ifdef G_OS_WIN32
Packit ae235b
    { "\\", "\\" },
Packit ae235b
    { ".\\\\\\\\", "." },
Packit ae235b
    { ".\\/\\/", "." },
Packit ae235b
    { ".", "." },
Packit ae235b
    { "..", "." },
Packit ae235b
    { "..\\", ".." },
Packit ae235b
    { "..\\\\\\\\", ".." },
Packit ae235b
    { "..\\//\\", ".." },
Packit ae235b
    { "", "." },
Packit ae235b
    { "a\\b", "a" },
Packit ae235b
    { "a\\b\\", "a\\b" },
Packit ae235b
    { "\\a\\b", "\\a" },
Packit ae235b
    { "\\a\\b\\", "\\a\\b" },
Packit ae235b
    { "c\\\\\\", "c" },
Packit ae235b
    { "c/\\\\", "c" },
Packit ae235b
    { "a:", "a:." },
Packit ae235b
    { "a:foo", "a:." },
Packit ae235b
    { "a:foo\\bar", "a:foo" },
Packit ae235b
    { "a:/foo", "a:/" },
Packit ae235b
    { "a:/foo/bar", "a:/foo" },
Packit ae235b
    { "a:/", "a:/" },
Packit ae235b
    { "a://", "a:/" },
Packit ae235b
    { "a:\\foo", "a:\\" },
Packit ae235b
    { "a:\\", "a:\\" },
Packit ae235b
    { "a:\\\\", "a:\\" },
Packit ae235b
    { "a:\\/", "a:\\" },
Packit ae235b
#endif
Packit ae235b
  };
Packit ae235b
  guint n_dirname_checks = sizeof (dirname_checks) / sizeof (dirname_checks[0]);
Packit ae235b
Packit ae235b
  for (i = 0; i < n_dirname_checks; i++)
Packit ae235b
    {
Packit ae235b
      gchar *dirname;
Packit ae235b
Packit ae235b
      dirname = g_path_get_dirname (dirname_checks[i].filename);
Packit ae235b
      if (strcmp (dirname, dirname_checks[i].dirname) != 0)
Packit ae235b
	g_error ("%s returned %s, should return %s",
Packit ae235b
		 dirname_checks[i].filename, dirname,
Packit ae235b
		 dirname_checks[i].dirname);
Packit ae235b
      g_free (dirname);
Packit ae235b
    }
Packit ae235b
Packit ae235b
  return 0;
Packit ae235b
}
Packit ae235b