[gtksourceview] Allow passing empty strings to gtk_source_language_manager_guess_language.
- From: Ignacio Casal Quinteiro <icq src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtksourceview] Allow passing empty strings to gtk_source_language_manager_guess_language.
- Date: Fri, 16 Jul 2010 11:26:24 +0000 (UTC)
commit abff91f277d34c869cfebc2e14562e6ef024dd79
Author: Krzesimir Nowak <qdlacz gmail com>
Date: Thu Jul 15 22:59:32 2010 +0200
Allow passing empty strings to gtk_source_language_manager_guess_language.
Also added tests checking this change.
gtksourceview/gtksourcelanguagemanager.c | 7 +++----
tests/test-languagemanager.c | 30 ++++++++++++++++++++++++++++++
2 files changed, 33 insertions(+), 4 deletions(-)
---
diff --git a/gtksourceview/gtksourcelanguagemanager.c b/gtksourceview/gtksourcelanguagemanager.c
index 4b68c05..1d86bca 100644
--- a/gtksourceview/gtksourcelanguagemanager.c
+++ b/gtksourceview/gtksourcelanguagemanager.c
@@ -625,9 +625,8 @@ gtk_source_language_manager_guess_language (GtkSourceLanguageManager *lm,
GSList *langs = NULL;
g_return_val_if_fail (GTK_IS_SOURCE_LANGUAGE_MANAGER (lm), NULL);
- g_return_val_if_fail (filename != NULL || content_type != NULL, NULL);
- g_return_val_if_fail ((filename == NULL || *filename != 0) &&
- (content_type == NULL || *content_type != 0), NULL);
+ g_return_val_if_fail ((filename != NULL && *filename != '\0') ||
+ (content_type != NULL && *content_type != '\0'), NULL);
ensure_languages (lm);
@@ -638,7 +637,7 @@ gtk_source_language_manager_guess_language (GtkSourceLanguageManager *lm,
- no glob matches
*/
- if (filename != NULL)
+ if (filename != NULL && *filename != '\0')
langs = pick_langs_for_filename (lm, filename);
if (langs != NULL)
diff --git a/tests/test-languagemanager.c b/tests/test-languagemanager.c
index 1d3c04d..3c92a1f 100644
--- a/tests/test-languagemanager.c
+++ b/tests/test-languagemanager.c
@@ -55,18 +55,48 @@ test_guess_language (void)
}
g_test_trap_assert_failed ();
+ if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR))
+ {
+ l = gtk_source_language_manager_guess_language (lm, "", NULL);
+ }
+ g_test_trap_assert_failed ();
+
+ if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR))
+ {
+ l = gtk_source_language_manager_guess_language (lm, NULL, "");
+ }
+ g_test_trap_assert_failed ();
+
+ if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR))
+ {
+ l = gtk_source_language_manager_guess_language (lm, "", "");
+ }
+ g_test_trap_assert_failed ();
+
l = gtk_source_language_manager_guess_language (lm, "foo.abcdef", NULL);
g_assert (l == NULL);
+ l = gtk_source_language_manager_guess_language (lm, "foo.abcdef", "");
+ g_assert (l == NULL);
+
l = gtk_source_language_manager_guess_language (lm, NULL, "image/png");
g_assert (l == NULL);
+ l = gtk_source_language_manager_guess_language (lm, "", "image/png");
+ g_assert (l == NULL);
+
l = gtk_source_language_manager_guess_language (lm, "foo.c", NULL);
g_assert_cmpstr (gtk_source_language_get_id (l), ==, "c");
+ l = gtk_source_language_manager_guess_language (lm, "foo.c", "");
+ g_assert_cmpstr (gtk_source_language_get_id (l), ==, "c");
+
l = gtk_source_language_manager_guess_language (lm, NULL, "text/x-csrc");
g_assert_cmpstr (gtk_source_language_get_id (l), ==, "c");
+ l = gtk_source_language_manager_guess_language (lm, "", "text/x-csrc");
+ g_assert_cmpstr (gtk_source_language_get_id (l), ==, "c");
+
l = gtk_source_language_manager_guess_language (lm, "foo.c", "text/x-csrc");
g_assert_cmpstr (gtk_source_language_get_id (l), ==, "c");
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]