Files
mono/eglib/test/path.c
T
Jonathan Chambers 10f6ce36d0 2007-04-27 Jonathan Chambers <[email protected]>
Combined patch from Michael Jerris <[email protected]> and me.
	* winconfig.h: Config file for msvc builds.
	* configure.ac: Add AC_CHECK_HEADERS for getopt.h,  sys/time.h,
	sys/wait.h, and pwd.h.
	
	* src/gspawn.c: Include config.h and use HAVE_* macros.
	* src/eglib-config.h.in: Add inclusion guards.
	* src/ghashtable.c: Fix warnings.
	* src/gmisc.c: Windows implementation of g_getenv, g_setenv,
	and g_unsetenv.
	* src/gpath.c: Include config.h and use HAVE_* macros.
	* src/gmarkup.c: Fix warnings.
	* src/gptrarray.c: Fix warnings.
	* src/gstr.c: Fix warnings and use HAVE_* macros.
	* src/glib.h: Move macros to eglib-config.h and include it.
	* src/gdate.c: Implement g_get_current_time on windows.
	* src/gpattern.c: Fix warnings.
	* src/gdir.c: Implement g_dir on windows.
	* src/gfile.c: Implement mkstemp and g_file_test on windows.
	* src/gtimer.c: Implement g_timer on windows.
	* src/gmodule.c: Fix warnings.
	* src/gunicode.c: Fix warnings.
	* src/gutf8.c: Fix warnings.
	
	* test/ptrarray.c: Fix warnings.
	* test/string.c: Fix warnings.
	* test/list.c: Fix warnings.
	* test/pattern.c: Use HAVE_* macros.
	* test/dir.c: Use HAVE_* macros.
	* test/file.c: Use HAVE_* macros and use system specific files for tests.
	* test/test.c: Fix warnings and use HAVE_* macros.
	* test/timer.c: Use HAVE_* macros.
	* test/string-util.c: Fix warnings.
	* test/test.h: Supress warnings on msvc.
	* test/module.c: Use HAVE_* macros.
	* test/utf8.c: Fix warnings.
	* test/spawn.c: Use HAVE_* macros.
	* test/driver.c: Fix warnings and use HAVE_* macros.
	* test/path.c: Use HAVE_* macros and use system specific files for tests.
	* test/sizes.c: Fix warnings.

2007-04-27  Jonathan Chambers <[email protected]>
	
	Combined patch from Michael Jerris <[email protected]> and me.
	* getopt.c: Added public domain implementation for Windows.
	* getopt.h: Added public domain implementation for Windows.
	* getopt_long.c: Added public domain implementation for Windows.
	* test_eglib.vcproj: Update project.
	* eglib.vcproj: Update project. Add pre-build step to copy
	winconfig.h to config.h for msvc build.


svn path=/trunk/mono/; revision=76406
2007-04-27 20:12:25 +00:00

301 lines
6.8 KiB
C

#include <config.h>
#include <glib.h>
#include <string.h>
#include <stdio.h>
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#ifdef G_OS_UNIX
#include <pthread.h>
#endif
#include "test.h"
#ifdef G_OS_WIN32
#include <direct.h>
#define chdir _chdir
#endif
/* This test is just to be used with valgrind */
RESULT
test_buildpath ()
{
char *s;
s = g_build_path ("/", "hola///", "//mundo", NULL);
if (strcmp (s, "hola/mundo") != 0)
return FAILED ("1 Got wrong result, got: %s", s);
g_free (s);
s = g_build_path ("/", "hola/", "/mundo", NULL);
if (strcmp (s, "hola/mundo") != 0)
return FAILED ("2 Got wrong result, got: %s", s);
g_free (s);
s = g_build_path ("/", "hola/", "mundo", NULL);
if (strcmp (s, "hola/mundo") != 0)
return FAILED ("3 Got wrong result, got: %s", s);
g_free (s);
s = g_build_path ("/", "hola", "/mundo", NULL);
if (strcmp (s, "hola/mundo") != 0)
return FAILED ("4 Got wrong result, got: %s", s);
g_free (s);
s = g_build_path ("/", "/hello", "world/", NULL);
if (strcmp (s, "/hello/world/") != 0)
return FAILED ("5 Got wrong result, got: %s", s);
g_free (s);
/* Now test multi-char-separators */
s = g_build_path ("**", "hello", "world", NULL);
if (strcmp (s, "hello**world") != 0)
return FAILED ("6 Got wrong result, got: %s", s);
g_free (s);
s = g_build_path ("**", "hello**", "world", NULL);
if (strcmp (s, "hello**world") != 0)
return FAILED ("7 Got wrong result, got: %s", s);
g_free (s);
s = g_build_path ("**", "hello**", "**world", NULL);
if (strcmp (s, "hello**world") != 0)
return FAILED ("8 Got wrong result, got: %s", s);
g_free (s);
s = g_build_path ("**", "hello**", "**world", NULL);
if (strcmp (s, "hello**world") != 0)
return FAILED ("9 Got wrong result, got: %s", s);
g_free (s);
s = g_build_path ("1234567890", "hello", "world", NULL);
if (strcmp (s, "hello1234567890world") != 0)
return FAILED ("10 Got wrong result, got: %s", s);
g_free (s);
s = g_build_path ("1234567890", "hello1234567890", "1234567890world", NULL);
if (strcmp (s, "hello1234567890world") != 0)
return FAILED ("11 Got wrong result, got: %s", s);
g_free (s);
s = g_build_path ("1234567890", "hello12345678901234567890", "1234567890world", NULL);
if (strcmp (s, "hello1234567890world") != 0)
return FAILED ("12 Got wrong result, got: %s", s);
g_free (s);
/* Multiple */
s = g_build_path ("/", "a", "b", "c", "d", NULL);
if (strcmp (s, "a/b/c/d") != 0)
return FAILED ("13 Got wrong result, got: %s", s);
g_free (s);
s = g_build_path ("/", "/a", "", "/c/", NULL);
if (strcmp (s, "/a/c/") != 0)
return FAILED ("14 Got wrong result, got: %s", s);
g_free (s);
return OK;
}
RESULT
test_buildfname ()
{
char *s;
s = g_build_filename ("a", "b", "c", "d", NULL);
#ifdef G_OS_WIN32
if (strcmp (s, "a\\b\\c\\d") != 0)
#else
if (strcmp (s, "a/b/c/d") != 0)
#endif
return FAILED ("1 Got wrong result, got: %s", s);
g_free (s);
return OK;
}
char *
test_dirname ()
{
char *s;
#ifdef G_OS_WIN32
s = g_path_get_dirname ("c:\\home\\miguel");
if (strcmp (s, "c:\\home") != 0)
return FAILED ("Expected c:\\home, got %s", s);
g_free (s);
s = g_path_get_dirname ("c:\\home\\dingus\\");
if (strcmp (s, "c:\\home\\dingus") != 0)
return FAILED ("Expected c:\\home\\dingus, got %s", s);
g_free (s);
s = g_path_get_dirname ("dir.c");
if (strcmp (s, ".") != 0)
return FAILED ("Expected `.', got %s", s);
g_free (s);
s = g_path_get_dirname ("c:\\index.html");
if (strcmp (s, "c:") != 0)
return FAILED ("Expected [c:], got [%s]", s);
#else
s = g_path_get_dirname ("/home/miguel");
if (strcmp (s, "/home") != 0)
return FAILED ("Expected /home, got %s", s);
g_free (s);
s = g_path_get_dirname ("/home/dingus/");
if (strcmp (s, "/home/dingus") != 0)
return FAILED ("Expected /home/dingus, got %s", s);
g_free (s);
s = g_path_get_dirname ("dir.c");
if (strcmp (s, ".") != 0)
return FAILED ("Expected `.', got %s", s);
g_free (s);
s = g_path_get_dirname ("/index.html");
if (strcmp (s, "/") != 0)
return FAILED ("Expected [/], got [%s]", s);
#endif
return OK;
}
char *
test_basename ()
{
char *s;
#ifdef G_OS_WIN32
s = g_path_get_basename ("");
if (strcmp (s, ".") != 0)
return FAILED ("Expected `.', got %s", s);
g_free (s);
s = g_path_get_basename ("c:\\home\\dingus\\");
if (strcmp (s, "dingus") != 0)
return FAILED ("1 Expected dingus, got %s", s);
g_free (s);
s = g_path_get_basename ("c:\\home\\dingus");
if (strcmp (s, "dingus") != 0)
return FAILED ("2 Expected dingus, got %s", s);
g_free (s);
#else
s = g_path_get_basename ("");
if (strcmp (s, ".") != 0)
return FAILED ("Expected `.', got %s", s);
g_free (s);
s = g_path_get_basename ("/home/dingus/");
if (strcmp (s, "dingus") != 0)
return FAILED ("1 Expected dingus, got %s", s);
g_free (s);
s = g_path_get_basename ("/home/dingus");
if (strcmp (s, "dingus") != 0)
return FAILED ("2 Expected dingus, got %s", s);
g_free (s);
#endif
return OK;
}
gchar *
test_ppath ()
{
char *s;
#ifdef G_OS_WIN32
const gchar *searchfor = "explorer.exe";
#else
const gchar *searchfor = "ls";
#endif
s = g_find_program_in_path (searchfor);
if (s == NULL)
return FAILED ("No %s on this system?", searchfor);
g_free (s);
return OK;
}
gchar *
test_ppath2 ()
{
char *s;
const char *path = g_getenv ("PATH");
#ifdef G_OS_WIN32
const gchar *searchfor = "test_eglib.exe";
#else
const gchar *searchfor = "test-glib";
#endif
g_setenv ("PATH", "", TRUE);
s = g_find_program_in_path ("ls");
if (s != NULL) {
g_setenv ("PATH", path, TRUE);
return FAILED ("Found something interesting here: %s", s);
}
g_free (s);
s = g_find_program_in_path (searchfor);
if (s == NULL) {
g_setenv ("PATH", path, TRUE);
return FAILED ("It should find '%s' in the current directory.", searchfor);
}
g_free (s);
g_setenv ("PATH", path, TRUE);
return OK;
}
gchar *
test_cwd ()
{
char *dir = g_get_current_dir ();
#ifdef G_OS_WIN32
const gchar *newdir = "C:\\Windows";
#else
const gchar *newdir = "/bin";
#endif
if (dir == NULL)
return FAILED ("No current directory?");
g_free (dir);
if (chdir (newdir) == -1)
return FAILED ("No %s?", newdir);
dir = g_get_current_dir ();
if (strcmp (dir, newdir) != 0)
return FAILED("Did not go to %s?", newdir);
g_free (dir);
return OK;
}
gchar *
test_misc ()
{
const char *home = g_get_home_dir ();
const char *tmp = g_get_tmp_dir ();
if (home == NULL)
return FAILED ("Where did my home go?");
if (tmp == NULL)
return FAILED ("Where did my /tmp go?");
return OK;
}
static Test path_tests [] = {
{"g_buildpath", test_buildpath},
{"g_build_filename", test_buildfname},
{"g_path_get_dirname", test_dirname},
{"g_path_get_basename", test_basename},
{"g_find_program_in_path", test_ppath},
{"g_find_program_in_path2", test_ppath2},
{"test_cwd", test_cwd },
{"test_misc", test_misc },
{NULL, NULL}
};
DEFINE_TEST_GROUP_INIT(path_tests_init, path_tests)