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);
133 s = g_build_filename ("C:\\", "a", NULL);
134 if (strcmp (s, "C:\\a") != 0)
136 s = g_build_filename ("/", "a", NULL);
137 if (strcmp (s, "/a") != 0)
139 return FAILED ("1 Got wrong result, got: %s", s);
142 s = g_build_filename ("/", "foo", "/bar", "tolo/", "/meo/", NULL);
143 if (strcmp (s, "/foo/bar/tolo/meo/") != 0)
144 return FAILED ("1 Got wrong result, got: %s", s);
156 s = g_path_get_dirname ("c:\\home\\miguel");
157 if (strcmp (s, "c:\\home") != 0)
158 return FAILED ("Expected c:\\home, got %s", s);
161 s = g_path_get_dirname ("c:/home/miguel");
162 if (strcmp (s, "c:/home") != 0)
163 return FAILED ("Expected c:/home, got %s", s);
166 s = g_path_get_dirname ("c:\\home\\dingus\\");
167 if (strcmp (s, "c:\\home\\dingus") != 0)
168 return FAILED ("Expected c:\\home\\dingus, got %s", s);
171 s = g_path_get_dirname ("dir.c");
172 if (strcmp (s, ".") != 0)
173 return FAILED ("Expected `.', got %s", s);
176 s = g_path_get_dirname ("c:\\index.html");
177 if (strcmp (s, "c:") != 0)
178 return FAILED ("Expected [c:], got [%s]", s);
180 s = g_path_get_dirname ("/home/miguel");
181 if (strcmp (s, "/home") != 0)
182 return FAILED ("Expected /home, got %s", s);
185 s = g_path_get_dirname ("/home/dingus/");
186 if (strcmp (s, "/home/dingus") != 0)
187 return FAILED ("Expected /home/dingus, got %s", s);
190 s = g_path_get_dirname ("dir.c");
191 if (strcmp (s, ".") != 0)
192 return FAILED ("Expected `.', got %s", s);
195 s = g_path_get_dirname ("/index.html");
196 if (strcmp (s, "/") != 0)
197 return FAILED ("Expected [/], got [%s]", s);
208 s = g_path_get_basename ("");
209 if (strcmp (s, ".") != 0)
210 return FAILED ("Expected `.', got %s", s);
213 s = g_path_get_basename ("c:\\home\\dingus\\");
214 if (strcmp (s, "dingus") != 0)
215 return FAILED ("1 Expected dingus, got %s", s);
218 s = g_path_get_basename ("c:/home/dingus/");
219 if (strcmp (s, "dingus") != 0)
220 return FAILED ("1 Expected dingus, got %s", s);
223 s = g_path_get_basename ("c:\\home\\dingus");
224 if (strcmp (s, "dingus") != 0)
225 return FAILED ("2 Expected dingus, got %s", s);
228 s = g_path_get_basename ("c:/home/dingus");
229 if (strcmp (s, "dingus") != 0)
230 return FAILED ("2 Expected dingus, got %s", s);
233 s = g_path_get_basename ("");
234 if (strcmp (s, ".") != 0)
235 return FAILED ("Expected `.', got %s", s);
238 s = g_path_get_basename ("/home/dingus/");
239 if (strcmp (s, "dingus") != 0)
240 return FAILED ("1 Expected dingus, got %s", s);
243 s = g_path_get_basename ("/home/dingus");
244 if (strcmp (s, "dingus") != 0)
245 return FAILED ("2 Expected dingus, got %s", s);
256 const gchar *searchfor = "explorer.exe";
258 const gchar *searchfor = "ls";
260 s = g_find_program_in_path (searchfor);
262 return FAILED ("No %s on this system?", searchfor);
271 const char *path = g_getenv ("PATH");
273 const gchar *searchfor = "test_eglib.exe";
275 const gchar *searchfor = "test-glib";
278 g_setenv ("PATH", "", TRUE);
279 s = g_find_program_in_path ("ls");
281 g_setenv ("PATH", path, TRUE);
282 return FAILED ("Found something interesting here: %s", s);
285 s = g_find_program_in_path (searchfor);
287 g_setenv ("PATH", path, TRUE);
288 return FAILED ("It should find '%s' in the current directory.", searchfor);
291 g_setenv ("PATH", path, TRUE);
295 #ifndef DISABLE_FILESYSTEM_TESTS
299 char *dir = g_get_current_dir ();
301 const gchar *newdir = "C:\\Windows";
303 const gchar *newdir = "/bin";
307 return FAILED ("No current directory?");
310 if (chdir (newdir) == -1)
311 return FAILED ("No %s?", newdir);
313 dir = g_get_current_dir ();
314 if (strcmp (dir, newdir) != 0)
315 return FAILED("Did not go to %s?", newdir);
331 const char *home = g_get_home_dir ();
332 const char *tmp = g_get_tmp_dir ();
335 return FAILED ("Where did my home go?");
338 return FAILED ("Where did my /tmp go?");
343 static Test path_tests [] = {
344 {"g_build_filename", test_buildfname},
345 {"g_buildpath", test_buildpath},
346 {"g_path_get_dirname", test_dirname},
347 {"g_path_get_basename", test_basename},
348 {"g_find_program_in_path", test_ppath},
349 {"g_find_program_in_path2", test_ppath2},
350 {"test_cwd", test_cwd },
351 {"test_misc", test_misc },
355 DEFINE_TEST_GROUP_INIT(path_tests_init, path_tests)