2395e623d150a02fdc10624a405810305d8e4396
[platform/upstream/glib.git] / tests / dirname-test.c
1 /* GLIB - Library of useful routines for C programming
2  * Copyright (C) 1995-1997  Peter Mattis, Spencer Kimball and Josh MacDonald
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Library General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Library General Public License for more details.
13  *
14  * You should have received a copy of the GNU Library General Public
15  * License along with this library; if not, write to the
16  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17  * Boston, MA 02111-1307, USA.
18  */
19 #undef G_LOG_DOMAIN
20
21 #include <stdio.h>
22 #include <string.h>
23 #include "glib.h"
24
25 int array[10000];
26 gboolean failed = FALSE;
27
28 #define TEST(m,cond)    G_STMT_START { failed = !(cond); \
29 if (failed) \
30   { if (!m) \
31       g_print ("\n(%s:%d) failed for: %s\n", __FILE__, __LINE__, ( # cond )); \
32     else \
33       g_print ("\n(%s:%d) failed for: %s: (%s)\n", __FILE__, __LINE__, ( # cond ), (gchar*)m); \
34   } \
35 else \
36   g_print ("."); fflush (stdout); \
37 } G_STMT_END
38
39 #define C2P(c)          ((gpointer) ((long) (c)))
40 #define P2C(p)          ((gchar) ((long) (p)))
41
42 #define GLIB_TEST_STRING "el dorado "
43 #define GLIB_TEST_STRING_5 "el do"
44
45 int
46 main (int   argc,
47       char *argv[])
48 {
49   gint i;
50   struct {
51     gchar *filename;
52     gchar *dirname;
53   } dirname_checks[] = {
54 #ifndef NATIVE_WIN32
55     { "/", "/" },
56     { "////", "/" },
57     { ".////", "." },
58     { ".", "." },
59     { "..", "." },
60     { "../", ".." },
61     { "..////", ".." },
62     { "", "." },
63     { "a/b", "a" },
64     { "a/b/", "a/b" },
65     { "c///", "c" },
66 #else
67     { "\\", "\\" },
68     { ".\\\\\\\\", "." },
69     { ".", "." },
70     { "..", "." },
71     { "..\\", ".." },
72     { "..\\\\\\\\", ".." },
73     { "", "." },
74     { "a\\b", "a" },
75     { "a\\b\\", "a\\b" },
76     { "c\\\\\\", "c" },
77 #endif
78   };
79   guint n_dirname_checks = sizeof (dirname_checks) / sizeof (dirname_checks[0]);
80
81   for (i = 0; i < n_dirname_checks; i++)
82     {
83       gchar *dirname;
84
85       dirname = g_dirname (dirname_checks[i].filename);
86       g_assert (strcmp (dirname, dirname_checks[i].dirname) == 0);
87       g_free (dirname);
88     }
89
90   return 0;
91 }
92