#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 */
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;
}
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;
}
}
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;
}
{"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}
};