2007-04-23 Jonathan Chambers <joncham@gmail.com>
[mono.git] / eglib / test / path.c
index 9c9888f4c661b220f8acd7237632fa0fafedf59e..e6731ad0f13dc63ea71ccbb3edcdf3bedd4076e7 100644 (file)
@@ -1,6 +1,8 @@
 #include <glib.h>
 #include <string.h>
 #include <stdio.h>
+#include <unistd.h>
+#include <pthread.h>
 #include "test.h"
 
 /* This test is just to be used with valgrind */
@@ -75,6 +77,12 @@ test_buildpath ()
        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;
        
        return OK;
 }
@@ -106,6 +114,15 @@ test_dirname ()
        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);
        
        return OK;
 }
@@ -134,15 +151,71 @@ test_basename ()
 }
 
 gchar *
-test_ppath (const gchar *program)
+test_ppath ()
 {
        char *s;
        
-       g_return_val_if_fail (program != NULL, NULL);
-
        s = g_find_program_in_path ("ls");
        if (s == NULL)
                return FAILED ("No shell on this system (This assumes Unix)?");
+       g_free (s);
+       return OK;
+}
+
+gchar *
+test_ppath2 ()
+{
+       char *s;
+       const char *path = g_getenv ("PATH");
+       
+       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 ("test-glib");
+       if (s == NULL) {
+               g_setenv ("PATH", path, TRUE);
+               return FAILED ("It should find 'test-glib' in the current directory.");
+       }
+       g_free (s);
+       g_setenv ("PATH", path, TRUE);
+       return OK;
+}
+
+gchar *
+test_cwd ()
+{
+       char *dir = g_get_current_dir ();
+
+       if (dir == NULL)
+               return FAILED ("No current directory?");
+       g_free (dir);
+       
+       if (chdir ("/bin") == -1)
+               return FAILED ("No /bin?");
+       
+       dir = g_get_current_dir ();
+       if (strcmp (dir, "/bin") != 0)
+               return FAILED("Did not go to /bin?");
+       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;
 }
@@ -153,6 +226,9 @@ static Test path_tests [] = {
        {"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}
 };