18 /* This test is just to be used with valgrind */
23 char *buffer = "var/private";
26 s = g_build_path ("/", "hola///", "//mundo", NULL);
27 if (strcmp (s, "hola/mundo") != 0)
28 return FAILED ("1 Got wrong result, got: %s", s);
31 s = g_build_path ("/", "hola/", "/mundo", NULL);
32 if (strcmp (s, "hola/mundo") != 0)
33 return FAILED ("2 Got wrong result, got: %s", s);
36 s = g_build_path ("/", "hola/", "mundo", NULL);
37 if (strcmp (s, "hola/mundo") != 0)
38 return FAILED ("3 Got wrong result, got: %s", s);
41 s = g_build_path ("/", "hola", "/mundo", NULL);
42 if (strcmp (s, "hola/mundo") != 0)
43 return FAILED ("4 Got wrong result, got: %s", s);
46 s = g_build_path ("/", "/hello", "world/", NULL);
47 if (strcmp (s, "/hello/world/") != 0)
48 return FAILED ("5 Got wrong result, got: %s", s);
51 /* Now test multi-char-separators */
52 s = g_build_path ("**", "hello", "world", NULL);
53 if (strcmp (s, "hello**world") != 0)
54 return FAILED ("6 Got wrong result, got: %s", s);
57 s = g_build_path ("**", "hello**", "world", NULL);
58 if (strcmp (s, "hello**world") != 0)
59 return FAILED ("7 Got wrong result, got: %s", s);
62 s = g_build_path ("**", "hello**", "**world", NULL);
63 if (strcmp (s, "hello**world") != 0)
64 return FAILED ("8 Got wrong result, got: %s", s);
67 s = g_build_path ("**", "hello**", "**world", NULL);
68 if (strcmp (s, "hello**world") != 0)
69 return FAILED ("9 Got wrong result, got: %s", s);
72 s = g_build_path ("1234567890", "hello", "world", NULL);
73 if (strcmp (s, "hello1234567890world") != 0)
74 return FAILED ("10 Got wrong result, got: %s", s);
77 s = g_build_path ("1234567890", "hello1234567890", "1234567890world", NULL);
78 if (strcmp (s, "hello1234567890world") != 0)
79 return FAILED ("11 Got wrong result, got: %s", s);
82 s = g_build_path ("1234567890", "hello12345678901234567890", "1234567890world", NULL);
83 if (strcmp (s, "hello1234567890world") != 0)
84 return FAILED ("12 Got wrong result, got: %s", s);
88 s = g_build_path ("/", "a", "b", "c", "d", NULL);
89 if (strcmp (s, "a/b/c/d") != 0)
90 return FAILED ("13 Got wrong result, got: %s", s);
93 s = g_build_path ("/", "/a", "", "/c/", NULL);
94 if (strcmp (s, "/a/c/") != 0)
95 return FAILED ("14 Got wrong result, got: %s", s);
99 s = g_build_path ("/", NULL, NULL);
101 return FAILED ("must get a non-NULL return");
103 return FAILED ("must get an empty string");
105 // This is to test the regression introduced by Levi for the Windows support
106 // that code errouneously read below the allowed area (in this case dir [-1]).
107 // and caused all kinds of random errors.
110 s = g_build_filename (dir, buffer, NULL);
112 return FAILED ("Must have a '/' at the start");
123 s = g_build_filename ("a", "b", "c", "d", NULL);
125 if (strcmp (s, "a\\b\\c\\d") != 0)
127 if (strcmp (s, "a/b/c/d") != 0)
129 return FAILED ("1 Got wrong result, got: %s", s);
132 s = g_build_filename ("/", "a", NULL);
134 if (strcmp (s, "\\a") != 0)
136 if (strcmp (s, "/a") != 0)
138 return FAILED ("1 Got wrong result, got: %s", s);
141 s = g_build_filename ("/", "foo", "/bar", "tolo/", "/meo/", NULL);
142 if (strcmp (s, "/foo/bar/tolo/meo/") != 0)
143 return FAILED ("1 Got wrong result, got: %s", s);
155 s = g_path_get_dirname ("c:\\home\\miguel");
156 if (strcmp (s, "c:\\home") != 0)
157 return FAILED ("Expected c:\\home, got %s", s);
160 s = g_path_get_dirname ("c:\\home\\dingus\\");
161 if (strcmp (s, "c:\\home\\dingus") != 0)
162 return FAILED ("Expected c:\\home\\dingus, got %s", s);
165 s = g_path_get_dirname ("dir.c");
166 if (strcmp (s, ".") != 0)
167 return FAILED ("Expected `.', got %s", s);
170 s = g_path_get_dirname ("c:\\index.html");
171 if (strcmp (s, "c:") != 0)
172 return FAILED ("Expected [c:], got [%s]", s);
174 s = g_path_get_dirname ("/home/miguel");
175 if (strcmp (s, "/home") != 0)
176 return FAILED ("Expected /home, got %s", s);
179 s = g_path_get_dirname ("/home/dingus/");
180 if (strcmp (s, "/home/dingus") != 0)
181 return FAILED ("Expected /home/dingus, got %s", s);
184 s = g_path_get_dirname ("dir.c");
185 if (strcmp (s, ".") != 0)
186 return FAILED ("Expected `.', got %s", s);
189 s = g_path_get_dirname ("/index.html");
190 if (strcmp (s, "/") != 0)
191 return FAILED ("Expected [/], got [%s]", s);
202 s = g_path_get_basename ("");
203 if (strcmp (s, ".") != 0)
204 return FAILED ("Expected `.', got %s", s);
207 s = g_path_get_basename ("c:\\home\\dingus\\");
208 if (strcmp (s, "dingus") != 0)
209 return FAILED ("1 Expected dingus, got %s", s);
212 s = g_path_get_basename ("c:\\home\\dingus");
213 if (strcmp (s, "dingus") != 0)
214 return FAILED ("2 Expected dingus, got %s", s);
217 s = g_path_get_basename ("");
218 if (strcmp (s, ".") != 0)
219 return FAILED ("Expected `.', got %s", s);
222 s = g_path_get_basename ("/home/dingus/");
223 if (strcmp (s, "dingus") != 0)
224 return FAILED ("1 Expected dingus, got %s", s);
227 s = g_path_get_basename ("/home/dingus");
228 if (strcmp (s, "dingus") != 0)
229 return FAILED ("2 Expected dingus, got %s", s);
240 const gchar *searchfor = "explorer.exe";
242 const gchar *searchfor = "ls";
244 s = g_find_program_in_path (searchfor);
246 return FAILED ("No %s on this system?", searchfor);
255 const char *path = g_getenv ("PATH");
257 const gchar *searchfor = "test_eglib.exe";
259 const gchar *searchfor = "test-glib";
262 g_setenv ("PATH", "", TRUE);
263 s = g_find_program_in_path ("ls");
265 g_setenv ("PATH", path, TRUE);
266 return FAILED ("Found something interesting here: %s", s);
269 s = g_find_program_in_path (searchfor);
271 g_setenv ("PATH", path, TRUE);
272 return FAILED ("It should find '%s' in the current directory.", searchfor);
275 g_setenv ("PATH", path, TRUE);
279 #ifndef DISABLE_FILESYSTEM_TESTS
283 char *dir = g_get_current_dir ();
285 const gchar *newdir = "C:\\Windows";
287 const gchar *newdir = "/bin";
291 return FAILED ("No current directory?");
294 if (chdir (newdir) == -1)
295 return FAILED ("No %s?", newdir);
297 dir = g_get_current_dir ();
298 if (strcmp (dir, newdir) != 0)
299 return FAILED("Did not go to %s?", newdir);
315 const char *home = g_get_home_dir ();
316 const char *tmp = g_get_tmp_dir ();
319 return FAILED ("Where did my home go?");
322 return FAILED ("Where did my /tmp go?");
327 static Test path_tests [] = {
328 {"g_build_filename", test_buildfname},
329 {"g_buildpath", test_buildpath},
330 {"g_path_get_dirname", test_dirname},
331 {"g_path_get_basename", test_basename},
332 {"g_find_program_in_path", test_ppath},
333 {"g_find_program_in_path2", test_ppath2},
334 {"test_cwd", test_cwd },
335 {"test_misc", test_misc },
339 DEFINE_TEST_GROUP_INIT(path_tests_init, path_tests)