udapted vi.po
[rhythmbox.git] / tests / test-file-helpers.c
blob5efd8470caff1583c5a1b829da82c11779ddd77f
1 #include <string.h>
3 #include <check.h>
4 #include <gtk/gtk.h>
5 #include "test-utils.h"
6 #include "rb-file-helpers.h"
7 #include "rb-util.h"
8 #include "rb-debug.h"
10 static void
11 test_get_short_path_name (const char *in, const char *expected)
13 char *out;
15 out = rb_uri_get_short_path_name (in);
16 rb_debug ("extracting short path from \"%s\", expecting \"%s\", got \"%s\"", in, expected, out);
17 fail_unless (strcmp (out, expected) == 0);
18 g_free (out);
21 START_TEST (test_rb_uri_get_short_path_name)
23 char *in;
24 char *out;
26 /* nothing */
27 in = NULL;
28 out = rb_uri_get_short_path_name (in);
29 fail_unless (out == NULL);
30 g_free (out);
32 /* just a file name */
33 test_get_short_path_name ("something.ogg", "something.ogg");
35 /* relative file name */
36 test_get_short_path_name ("x/something.ogg", "something.ogg");
38 /* full path name */
39 test_get_short_path_name ("/var/lib/something.ogg", "something.ogg");
41 /* URI with a single path component */
42 test_get_short_path_name ("file://something.ogg", "something.ogg");
44 /* URI with multiple path components */
45 test_get_short_path_name ("file:///home/nobody/something.ogg", "something.ogg");
47 /* URI with query string */
48 test_get_short_path_name ("http://example.com/something.ogg?q=z&h=w", "something.ogg");
50 /* non-standard URI protocol */
51 test_get_short_path_name ("daap://10.0.0.1:3523/databases/1/items/46343.ogg", "46343.ogg");
53 /* non-standard URI protocol with query string */
54 test_get_short_path_name ("daap://10.0.0.1:3523/databases/1/items/46383.ogg?session=2463435", "46383.ogg");
56 /* trailing slash */
57 test_get_short_path_name ("/usr/share/nothing/", "nothing");
59 END_TEST
61 static Suite *
62 rb_file_helpers_suite ()
64 Suite *s = suite_create ("rb-file-helpers");
65 TCase *tc_chain = tcase_create ("rb-file-helpers-core");
67 suite_add_tcase (s, tc_chain);
69 tcase_add_test (tc_chain, test_rb_uri_get_short_path_name);
71 return s;
74 int
75 main (int argc, char **argv)
77 int ret;
78 SRunner *sr;
79 Suite *s;
81 rb_profile_start ("rb-file-helpers test suite");
82 g_thread_init (NULL);
83 rb_threads_init ();
84 gtk_set_locale ();
85 gtk_init (&argc, &argv);
86 gnome_vfs_init ();
87 rb_debug_init (TRUE);
88 rb_file_helpers_init ();
90 GDK_THREADS_ENTER ();
92 /* setup tests */
93 s = rb_file_helpers_suite ();
94 sr = srunner_create (s);
95 srunner_run_all (sr, CK_NORMAL);
96 ret = srunner_ntests_failed (sr);
97 srunner_free (sr);
99 rb_file_helpers_shutdown ();
100 gnome_vfs_shutdown ();
102 rb_profile_end ("rb-file-helpers test suite");
103 return ret;