[gtksourceview] Fix the order style schemes are loaded.
- From: Paolo Borelli <pborelli src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtksourceview] Fix the order style schemes are loaded.
- Date: Sat, 26 Jan 2013 10:41:59 +0000 (UTC)
commit ccc27f7b689228fad095e3e5b4822c538da35029
Author: Paolo Borelli <pborelli gnome org>
Date: Sat Jan 26 11:33:05 2013 +0100
Fix the order style schemes are loaded.
Since we load in the order of the specified search path, if a scheme is
found twice, the first should win.
Also add a unit test.
gtksourceview/gtksourcestyleschememanager.c | 7 ++--
tests/Makefile.am | 8 +++++
tests/styles/classic.xml | 6 +++
tests/test-styleschememanager.c | 46 +++++++++++++++++++++++++++
4 files changed, 63 insertions(+), 4 deletions(-)
---
diff --git a/gtksourceview/gtksourcestyleschememanager.c b/gtksourceview/gtksourcestyleschememanager.c
index dafbca9..d7c0961 100644
--- a/gtksourceview/gtksourcestyleschememanager.c
+++ b/gtksourceview/gtksourcestyleschememanager.c
@@ -362,12 +362,11 @@ reload_if_needed (GtkSourceStyleSchemeManager *mgr)
if (scheme != NULL)
{
const gchar *id = gtk_source_style_scheme_get_id (scheme);
- GtkSourceStyleScheme *old;
- old = g_hash_table_lookup (schemes_hash, id);
- if (old != NULL)
+ /* scheme with the same id already loaded from a path with higher prio: skip it */
+ if (g_hash_table_contains (schemes_hash, id))
{
- schemes = g_slist_remove (schemes, old);
+ continue;
}
schemes = g_slist_prepend (schemes, scheme);
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 62d904d..663fb16 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -35,6 +35,14 @@ test_languagemanager_LDADD = \
$(DEP_LIBS) \
$(TESTS_LIBS)
+UNIT_TEST_PROGS = test-styleschememanager
+test_styleschememanager_SOURCES = \
+ test-styleschememanager.c
+test_styleschememanager_LDADD = \
+ $(top_builddir)/gtksourceview/libgtksourceview-3.0.la \
+ $(DEP_LIBS) \
+ $(TESTS_LIBS)
+
UNIT_TEST_PROGS += test-language
test_language_SOURCES = \
test-language.c
diff --git a/tests/styles/classic.xml b/tests/styles/classic.xml
new file mode 100644
index 0000000..53ac20f
--- /dev/null
+++ b/tests/styles/classic.xml
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- Just a minimal classic style to check it overrides the real one -->
+<style-scheme id="classic" name="Classic" version="1.0">
+ <author>GtkSourceView team</author>
+ <description>Classic color scheme</description>
+</style-scheme>
diff --git a/tests/test-styleschememanager.c b/tests/test-styleschememanager.c
new file mode 100644
index 0000000..7fdccac
--- /dev/null
+++ b/tests/test-styleschememanager.c
@@ -0,0 +1,46 @@
+#include <gtk/gtk.h>
+#include <gtksourceview/gtksource.h>
+
+static void
+test_get_default (void)
+{
+ GtkSourceStyleSchemeManager *sm1, *sm2;
+
+ sm1 = gtk_source_style_scheme_manager_get_default ();
+ sm2 = gtk_source_style_scheme_manager_get_default ();
+ g_assert (sm1 == sm2);
+}
+
+static void
+test_prepend_search_path (void)
+{
+ GtkSourceStyleSchemeManager *sm;
+ gchar *style_dir;
+ GtkSourceStyleScheme *scheme;
+ const gchar *fname;
+ gchar *expected;
+
+ sm = gtk_source_style_scheme_manager_get_default ();
+
+ style_dir = g_build_filename (TOP_SRCDIR, "tests", "styles", NULL);
+ gtk_source_style_scheme_manager_prepend_search_path (sm, style_dir);
+
+ scheme = gtk_source_style_scheme_manager_get_scheme (sm, "classic");
+ fname = gtk_source_style_scheme_get_filename (scheme);
+ expected = g_build_filename (style_dir, "classic.xml", NULL);
+ g_assert_cmpstr (fname, ==, expected);
+
+ g_free (expected);
+ g_free (style_dir);
+}
+
+int
+main (int argc, char** argv)
+{
+ gtk_test_init (&argc, &argv);
+
+ g_test_add_func ("/StyleSchemeManager/get-default", test_get_default);
+ g_test_add_func ("/StyleSchemeManager/prepend-search-path", test_prepend_search_path);
+
+ return g_test_run();
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]