[gtksourceview] Add unit test for GtkSourceLanguage
- From: Paolo Borelli <pborelli src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtksourceview] Add unit test for GtkSourceLanguage
- Date: Sun, 13 Jan 2013 16:34:20 +0000 (UTC)
commit 052ad01cf710afb48187fabd1c81a7393e2ad89f
Author: Paolo Borelli <pborelli gnome org>
Date: Sun Jan 13 12:20:33 2013 +0100
Add unit test for GtkSourceLanguage
tests/Makefile.am | 10 +++
tests/language-specs/test-empty.lang | 6 ++
tests/language-specs/test-full.lang | 34 +++++++++
tests/test-language.c | 130 ++++++++++++++++++++++++++++++++++
4 files changed, 180 insertions(+), 0 deletions(-)
---
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 0d5f985..cb5f1e8 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -35,6 +35,14 @@ test_languagemanager_LDADD = \
$(DEP_LIBS) \
$(TESTS_LIBS)
+UNIT_TEST_PROGS += test-language
+test_language_SOURCES = \
+ test-language.c
+test_language_LDADD = \
+ $(top_builddir)/gtksourceview/libgtksourceview-3.0.la \
+ $(DEP_LIBS) \
+ $(TESTS_LIBS)
+
UNIT_TEST_PROGS += test-printcompositor
test_printcompositor_SOURCES = \
test-printcompositor.c
@@ -76,6 +84,8 @@ python_tests = \
# $(DEP_LIBS)
EXTRA_DIST = \
+ language-specs/test-empty.lang \
+ language-specs/test-full.lang \
$(python_tests)
# Generated files for the code coverage
diff --git a/tests/language-specs/test-empty.lang b/tests/language-specs/test-empty.lang
new file mode 100644
index 0000000..56771f4
--- /dev/null
+++ b/tests/language-specs/test-empty.lang
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<language id="test-empty" name="Test Empty" version="2.0" hidden="true">
+ <definitions>
+ <context id="test-empty"/>
+ </definitions>
+</language>
diff --git a/tests/language-specs/test-full.lang b/tests/language-specs/test-full.lang
new file mode 100644
index 0000000..4ef9b91
--- /dev/null
+++ b/tests/language-specs/test-full.lang
@@ -0,0 +1,34 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<language id="test-full" name="Test Full" version="2.0" section="Sources">
+ <metadata>
+ <property name="mimetypes">text/x-test;application/x-test</property>
+ <property name="globs">*.test;*.tst</property>
+ <property name="extra-meta">extra</property>
+ </metadata>
+
+ <styles>
+ <style id="string" name="String" map-to="def:string"/>
+ <style id="keyword" name="Keywords" map-to="def:keyword"/>
+ </styles>
+
+ <definitions>
+
+ <context id="string" style-ref="string" end-at-line-end="true" class="string" class-disabled="no-spell-check">
+ <start>"</start>
+ <end>"</end>
+ </context>
+
+ <context id="keywords" style-ref="keyword">
+ <keyword>foo</keyword>
+ <keyword>bar</keyword>
+ </context>
+
+ <context id="test-full" class="no-spell-check">
+ <include>
+ <context ref="string"/>
+ <context ref="keywords"/>
+ </include>
+ </context>
+
+ </definitions>
+</language>
diff --git a/tests/test-language.c b/tests/test-language.c
new file mode 100644
index 0000000..530403d
--- /dev/null
+++ b/tests/test-language.c
@@ -0,0 +1,130 @@
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <stdlib.h>
+#include <gtk/gtk.h>
+#include <gtksourceview/gtksource.h>
+
+typedef struct _TestFixture TestFixture;
+
+struct _TestFixture {
+ GtkSourceLanguageManager *manager;
+};
+
+static void
+test_fixture_setup (TestFixture *fixture,
+ gconstpointer data)
+{
+ const gchar * const *orig_lang_dirs;
+ gchar **lang_dirs;
+ guint n, i;
+
+ fixture->manager = gtk_source_language_manager_get_default ();
+
+ orig_lang_dirs = gtk_source_language_manager_get_search_path (fixture->manager);
+ n = g_strv_length ((gchar **)orig_lang_dirs);
+
+ lang_dirs = g_new0 (gchar *, n + 2);
+ lang_dirs[0] = g_build_filename (TOP_SRCDIR, "tests", "language-specs", NULL);
+ for (i = 0; i < n; i++)
+ {
+ lang_dirs[i + 1] = g_strdup (orig_lang_dirs[i]);
+ }
+
+ gtk_source_language_manager_set_search_path (fixture->manager, lang_dirs);
+ g_strfreev (lang_dirs);
+}
+
+static void
+test_fixture_teardown (TestFixture *fixture,
+ gconstpointer data)
+{
+}
+
+static void
+compare_strv (gchar **strv,
+ gchar **expected_strv)
+{
+ if (expected_strv != NULL)
+ {
+ guint n, i;
+
+ n = g_strv_length (expected_strv);
+ for (i = 0; i < n; i++)
+ {
+ g_assert_cmpstr (strv[i], ==, expected_strv[i]);
+ }
+ }
+ else
+ {
+ g_assert (strv == NULL);
+ }
+}
+
+static void
+check_language (GtkSourceLanguage *language,
+ const char *id,
+ const char *expected_name,
+ const char *expected_section,
+ gboolean expected_hidden,
+ const char *expected_extra_meta,
+ gchar **expected_mime,
+ gchar **expected_glob,
+ gchar **expected_styles,
+ const char *style_id,
+ const char *expected_style_name)
+{
+ gchar **mime;
+ gchar **glob;
+ gchar **styles;
+
+ g_assert_cmpstr (gtk_source_language_get_id (language), ==, id);
+ g_assert_cmpstr (gtk_source_language_get_name (language), ==, expected_name);
+ g_assert_cmpstr (gtk_source_language_get_section (language), ==, expected_section);
+ g_assert (gtk_source_language_get_hidden (language) == expected_hidden);
+ g_assert_cmpstr (gtk_source_language_get_metadata (language, "extra-meta"), ==, expected_extra_meta);
+
+ mime = gtk_source_language_get_mime_types (language);
+ compare_strv (mime, expected_mime);
+ g_strfreev (mime);
+
+ glob = gtk_source_language_get_globs (language);
+ compare_strv (glob, expected_glob);
+ g_strfreev (glob);
+
+ styles = gtk_source_language_get_style_ids (language);
+ compare_strv (styles, expected_styles);
+ g_strfreev (styles);
+
+ if (expected_style_name != NULL)
+ {
+ g_assert_cmpstr (gtk_source_language_get_style_name (language, style_id), ==, expected_style_name);
+ }
+}
+
+static void
+test_language (TestFixture *fixture,
+ gconstpointer data)
+{
+ GtkSourceLanguage *language;
+
+ language = gtk_source_language_manager_get_language (fixture->manager, "test-full");
+ gchar *mime[] = { "text/x-test", "application/x-test", NULL};
+ gchar *glob[] = { "*.test", "*.tst", NULL};
+ gchar *styles[] = { "test-full:keyword", "test-full:string", NULL};
+ check_language (language, "test-full", "Test Full", "Sources", FALSE, "extra", mime, glob, styles, "test-full:string", "String");
+
+ language = gtk_source_language_manager_get_language (fixture->manager, "test-empty");
+ check_language (language, "test-empty", "Test Empty", "Others", TRUE, NULL, NULL, NULL, NULL, NULL, NULL);
+}
+
+int
+main (int argc, char** argv)
+{
+ gtk_test_init (&argc, &argv);
+
+ g_test_add ("/Language/language-properties", TestFixture, NULL, test_fixture_setup, test_language, test_fixture_teardown);
+
+ return g_test_run();
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]