os/ossrv/glib/tsrc/BC/tests/dirname-test.c
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 /* GLIB - Library of useful routines for C programming
     2  * Copyright (C) 1995-1997  Peter Mattis, Spencer Kimball and Josh MacDonald
     3  * Portion Copyright © 2008-09 Nokia Corporation and/or its subsidiary(-ies). All rights reserved.
     4  * This library is free software; you can redistribute it and/or
     5  * modify it under the terms of the GNU Lesser 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  * Lesser General Public License for more details.
    13  *
    14  * You should have received a copy of the GNU Lesser 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 
    20 /*
    21  * Modified by the GLib Team and others 1997-2000.  See the AUTHORS
    22  * file for a list of people on the GLib Team.  See the ChangeLog
    23  * files for a list of changes.  These files are distributed with
    24  * GLib at ftp://ftp.gtk.org/pub/gtk/. 
    25  */
    26 
    27 #undef G_DISABLE_ASSERT
    28 #undef G_LOG_DOMAIN
    29 
    30 #include <stdio.h>
    31 #include <string.h>
    32 #include "glib.h"
    33 
    34 #ifdef SYMBIAN
    35 #include "mrt2_glib2_test.h"
    36 #endif /*SYMBIAN*/
    37 
    38 int array[10000];
    39 gboolean failed = FALSE;
    40 
    41 #define	TEST(m,cond)	G_STMT_START { failed = !(cond); \
    42 if (failed) \
    43   { assert_failed = TRUE;\
    44   	if (!m) \
    45       g_print ("\n(%s:%d) failed for: %s\n", __FILE__, __LINE__, ( # cond )); \
    46     else \
    47       g_print ("\n(%s:%d) failed for: %s: (%s)\n", __FILE__, __LINE__, ( # cond ), (gchar*)m); \
    48   } \
    49 else \
    50   g_print ("."); fflush (stdout); \
    51 } G_STMT_END
    52 
    53 #define	C2P(c)		((gpointer) ((long) (c)))
    54 #define	P2C(p)		((gchar) ((long) (p)))
    55 
    56 #define GLIB_TEST_STRING "el dorado "
    57 #define GLIB_TEST_STRING_5 "el do"
    58 
    59 
    60 int
    61 main (int   argc,
    62       char *argv[])
    63 {
    64   gint i;
    65   struct {
    66     gchar *filename;
    67     gchar *dirname;
    68   } dirname_checks[] = {
    69     { "/", "/" },
    70     { "////", "/" },
    71     { ".////", "." },
    72     { ".", "." },
    73     { "..", "." },
    74     { "../", ".." },
    75     { "..////", ".." },
    76     { "", "." },
    77     { "a/b", "a" },
    78     { "a/b/", "a/b" },
    79     { "c///", "c" },
    80     { "/a/b", "/a" },
    81     { "/a/b/", "/a/b" },
    82 #ifdef G_OS_WIN32
    83     { "\\", "\\" },
    84     { ".\\\\\\\\", "." },
    85     { ".\\/\\/", "." },
    86     { ".", "." },
    87     { "..", "." },
    88     { "..\\", ".." },
    89     { "..\\\\\\\\", ".." },
    90     { "..\\//\\", ".." },
    91     { "", "." },
    92     { "a\\b", "a" },
    93     { "a\\b\\", "a\\b" },
    94     { "\\a\\b", "\\a" },
    95     { "\\a\\b\\", "\\a\\b" },
    96     { "c\\\\\\", "c" },
    97     { "c/\\\\", "c" },
    98     { "a:", "a:." },
    99     { "a:foo", "a:." },
   100     { "a:foo\\bar", "a:foo" },
   101     { "a:/foo", "a:/" },
   102     { "a:/foo/bar", "a:/foo" },
   103     { "a:/", "a:/" },
   104     { "a://", "a:/" },
   105     { "a:\\foo", "a:\\" },
   106     { "a:\\", "a:\\" },
   107     { "a:\\\\", "a:\\" },
   108     { "a:\\/", "a:\\" },
   109 #endif
   110   };
   111   guint n_dirname_checks = sizeof (dirname_checks) / sizeof (dirname_checks[0]);
   112 
   113   #ifdef SYMBIAN
   114   g_log_set_handler (NULL,  G_LOG_FLAG_FATAL| G_LOG_FLAG_RECURSION | G_LOG_LEVEL_CRITICAL | G_LOG_LEVEL_WARNING | G_LOG_LEVEL_MESSAGE | G_LOG_LEVEL_INFO | G_LOG_LEVEL_DEBUG, &mrtLogHandler, NULL);
   115   g_set_print_handler(mrtPrintHandler);
   116   #endif /*SYMBIAN*/
   117 	  
   118 
   119   for (i = 0; i < n_dirname_checks; i++)
   120     {
   121       gchar *dirname;
   122 
   123       dirname = g_path_get_dirname (dirname_checks[i].filename);
   124       if (strcmp (dirname, dirname_checks[i].dirname) != 0)
   125       {
   126       	g_assert(FALSE && "dirname-test failed");
   127       	g_print ("%s returned %s, should return %s",dirname_checks[i].filename, dirname,dirname_checks[i].dirname);
   128       }
   129       g_free (dirname);
   130     }
   131     
   132     #if SYMBIAN
   133   	testResultXml("dirname-test");
   134   	#endif /* EMULATOR */
   135 
   136   return 0;
   137 }
   138