hythmbox-2.98/tests/test-file-helpers.c

No issues found

  1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
  2  *
  3  *  This program is free software; you can redistribute it and/or modify
  4  *  it under the terms of the GNU General Public License as published by
  5  *  the Free Software Foundation; either version 2 of the License, or
  6  *  (at your option) any later version.
  7  *
  8  *  The Rhythmbox authors hereby grant permission for non-GPL compatible
  9  *  GStreamer plugins to be used and distributed together with GStreamer
 10  *  and Rhythmbox. This permission is above and beyond the permissions granted
 11  *  by the GPL license by which Rhythmbox is covered. If you modify this code
 12  *  you may extend this exception to your version of the code, but you are not
 13  *  obligated to do so. If you do not wish to do so, delete this exception
 14  *  statement from your version.
 15  *
 16  *  This program is distributed in the hope that it will be useful,
 17  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 18  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 19  *  GNU General Public License for more details.
 20  *
 21  *  You should have received a copy of the GNU General Public License
 22  *  along with this program; if not, write to the Free Software
 23  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA.
 24  *
 25  */
 26 
 27 
 28 #include "config.h"
 29 
 30 #include <string.h>
 31 
 32 #include <check.h>
 33 #include <gtk/gtk.h>
 34 #include <locale.h>
 35 #include "test-utils.h"
 36 #include "rb-file-helpers.h"
 37 #include "rb-util.h"
 38 #include "rb-debug.h"
 39 
 40 static void
 41 test_get_short_path_name (const char *in, const char *expected)
 42 {
 43 	char *out;
 44 
 45 	out = rb_uri_get_short_path_name (in);
 46 	rb_debug ("extracting short path from \"%s\", expecting \"%s\", got \"%s\"", in, expected, out);
 47 	fail_unless (strcmp (out, expected) == 0);
 48 	g_free (out);
 49 }
 50 
 51 START_TEST (test_rb_uri_get_short_path_name)
 52 {
 53 	char *in;
 54 	char *out;
 55 
 56 	init_once (TRUE);
 57 
 58 	/* nothing */
 59 	in = NULL;
 60 	out = rb_uri_get_short_path_name (in);
 61 	fail_unless (out == NULL);
 62 	g_free (out);
 63 
 64 	/* just a file name */
 65 	test_get_short_path_name ("something.ogg", "something.ogg");
 66 
 67 	/* relative file name */
 68 	test_get_short_path_name ("x/something.ogg", "something.ogg");
 69 
 70 	/* full path name */
 71 	test_get_short_path_name ("/var/lib/something.ogg", "something.ogg");
 72 
 73 	/* URI with a single path component */
 74 	test_get_short_path_name ("file://something.ogg", "something.ogg");
 75 
 76 	/* URI with multiple path components */
 77 	test_get_short_path_name ("file:///home/nobody/something.ogg", "something.ogg");
 78 
 79 	/* URI with query string */
 80 	test_get_short_path_name ("http://example.com/something.ogg?q=z&h=w", "something.ogg");
 81 
 82 	/* non-standard URI protocol */
 83 	test_get_short_path_name ("daap://10.0.0.1:3523/databases/1/items/46343.ogg", "46343.ogg");
 84 
 85 	/* non-standard URI protocol with query string */
 86 	test_get_short_path_name ("daap://10.0.0.1:3523/databases/1/items/46383.ogg?session=2463435", "46383.ogg");
 87 
 88 	/* trailing slash */
 89 	test_get_short_path_name ("/usr/share/nothing/", "nothing");
 90 }
 91 END_TEST
 92 
 93 START_TEST (test_rb_check_dir_has_space)
 94 {
 95 	init_once (TRUE);
 96 	fail_unless (rb_check_dir_has_space_uri ("file:///tmp", 1));
 97 	fail_unless (rb_check_dir_has_space_uri ("file:///etc/passwd", 1));
 98 	fail_unless (rb_check_dir_has_space_uri ("file:///tmp/NONEXISTANT_FILE", 1));
 99 	fail_unless (rb_check_dir_has_space_uri ("file:///tmp/NONEXISTANT/THISDOESNTEXISTEITHER/NORDOESTHIS", G_MAXUINT64) == FALSE);
100 }
101 END_TEST
102 
103 static Suite *
104 rb_file_helpers_suite ()
105 {
106 	Suite *s = suite_create ("rb-file-helpers");
107 	TCase *tc_chain = tcase_create ("rb-file-helpers-core");
108 
109 	suite_add_tcase (s, tc_chain);
110 
111 	tcase_add_test (tc_chain, test_rb_uri_get_short_path_name);
112 	tcase_add_test (tc_chain, test_rb_check_dir_has_space);
113 
114 	return s;
115 }
116 
117 int
118 main (int argc, char **argv)
119 {
120 	int ret;
121 	SRunner *sr;
122 	Suite *s;
123 
124 	rb_profile_start ("rb-file-helpers test suite");
125 	rb_threads_init ();
126 	setlocale (LC_ALL, NULL);
127 	rb_debug_init (TRUE);
128 	rb_file_helpers_init (TRUE);
129 
130 	/* setup tests */
131 	s = rb_file_helpers_suite ();
132 	sr = srunner_create (s);
133 
134 	init_setup (sr, argc, argv);
135 	init_once (FALSE);
136 
137 	srunner_run_all (sr, CK_NORMAL);
138 	ret = srunner_ntests_failed (sr);
139 	srunner_free (sr);
140 
141 	rb_file_helpers_shutdown ();
142 
143 	rb_profile_end ("rb-file-helpers test suite");
144 	return ret;
145 }