[latexila/wip/latexila-next: 18/51] First unit test in latexila, yay! (better late than never)
- From: Sébastien Wilmet <swilmet src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [latexila/wip/latexila-next: 18/51] First unit test in latexila, yay! (better late than never)
- Date: Sat, 20 Sep 2014 17:30:44 +0000 (UTC)
commit 23e2d81120cd17ea158530e5f3f8dec2f42ae5d1
Author: Sébastien Wilmet <swilmet gnome org>
Date: Sun May 4 21:48:53 2014 +0200
First unit test in latexila, yay! (better late than never)
It tests the build tools loading from an XML file.
Makefile.am | 2 +-
configure.ac | 1 +
docs/reference/latexila-sections.txt | 1 +
src/liblatexila/latexila-build-tool.c | 16 +++
src/liblatexila/latexila-build-tool.h | 2 +
src/liblatexila/latexila.h | 2 +
tests/Makefile.am | 18 +++
tests/build_tools_test.xml | 12 ++
tests/test-build-tools.c | 224 +++++++++++++++++++++++++++++++++
9 files changed, 277 insertions(+), 1 deletions(-)
---
diff --git a/Makefile.am b/Makefile.am
index 49b16f8..5125659 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -1,6 +1,6 @@
ACLOCAL_AMFLAGS = -I m4
-SUBDIRS = data man po help src docs
+SUBDIRS = data man po help src tests docs
DISTCHECK_CONFIGURE_FLAGS = --enable-introspection
diff --git a/configure.ac b/configure.ac
index 7d52bf0..cdff66e 100644
--- a/configure.ac
+++ b/configure.ac
@@ -170,6 +170,7 @@ AC_CONFIG_FILES([Makefile
src/gedit/Makefile
src/liblatexila/Makefile
src/ui/Makefile
+ tests/Makefile
README])
AC_OUTPUT
diff --git a/docs/reference/latexila-sections.txt b/docs/reference/latexila-sections.txt
index cd7bf83..7b5ac01 100644
--- a/docs/reference/latexila-sections.txt
+++ b/docs/reference/latexila-sections.txt
@@ -62,6 +62,7 @@ LatexilaBuildToolsPersonalPrivate
LatexilaBuildTool
latexila_build_tool_new
latexila_build_tool_add_job
+latexila_build_tool_get_jobs
latexila_build_tool_get_description
latexila_build_tool_to_xml
<SUBSECTION Standard>
diff --git a/src/liblatexila/latexila-build-tool.c b/src/liblatexila/latexila-build-tool.c
index 2e26860..aa77136 100644
--- a/src/liblatexila/latexila-build-tool.c
+++ b/src/liblatexila/latexila-build-tool.c
@@ -324,6 +324,22 @@ latexila_build_tool_add_job (LatexilaBuildTool *build_tool,
g_return_if_fail (LATEXILA_IS_BUILD_JOB (build_job));
g_queue_push_tail (build_tool->priv->jobs, build_job);
+ g_object_ref (build_job);
+}
+
+/**
+ * latexila_build_tool_get_jobs:
+ * @build_tool: a #LatexilaBuildTool.
+ *
+ * Returns: (element-type LatexilaBuildJob) (transfer none): the list of
+ * #LatexilaBuildJob's.
+ */
+GList *
+latexila_build_tool_get_jobs (LatexilaBuildTool *build_tool)
+{
+ g_return_val_if_fail (LATEXILA_IS_BUILD_TOOL (build_tool), NULL);
+
+ return build_tool->priv->jobs->head;
}
/**
diff --git a/src/liblatexila/latexila-build-tool.h b/src/liblatexila/latexila-build-tool.h
index 8e4b0f5..a9ff897 100644
--- a/src/liblatexila/latexila-build-tool.h
+++ b/src/liblatexila/latexila-build-tool.h
@@ -56,6 +56,8 @@ const gchar * latexila_build_tool_get_description (LatexilaBui
void latexila_build_tool_add_job (LatexilaBuildTool *build_tool,
LatexilaBuildJob *build_job);
+GList * latexila_build_tool_get_jobs (LatexilaBuildTool *build_tool);
+
gchar * latexila_build_tool_to_xml (LatexilaBuildTool *tool);
G_END_DECLS
diff --git a/src/liblatexila/latexila.h b/src/liblatexila/latexila.h
index 3fd9fcf..f284c63 100644
--- a/src/liblatexila/latexila.h
+++ b/src/liblatexila/latexila.h
@@ -20,6 +20,8 @@
#ifndef __LATEXILA_H__
#define __LATEXILA_H__
+#include "latexila-build-job.h"
+#include "latexila-build-tool.h"
#include "latexila-build-tools.h"
#include "latexila-build-tools-default.h"
#include "latexila-build-tools-personal.h"
diff --git a/tests/Makefile.am b/tests/Makefile.am
new file mode 100644
index 0000000..69a7963
--- /dev/null
+++ b/tests/Makefile.am
@@ -0,0 +1,18 @@
+AM_CPPFLAGS = \
+ -I$(top_srcdir) \
+ -I$(top_srcdir)/src/liblatexila \
+ -DSRCDIR=\""$(ABS_SRCDIR)"\" \
+ $(WARN_CFLAGS)
+
+LDADD = $(top_builddir)/src/liblatexila/liblatexila.la
+
+UNIT_TEST_PROGS = test-build-tools
+test_build_tools_SOURCES = test-build-tools.c
+
+noinst_PROGRAMS = $(UNIT_TEST_PROGS)
+TESTS = $(UNIT_TEST_PROGS)
+
+EXTRA_DIST = \
+ build_tools_test.xml
+
+-include $(top_srcdir)/git.mk
diff --git a/tests/build_tools_test.xml b/tests/build_tools_test.xml
new file mode 100644
index 0000000..de2897d
--- /dev/null
+++ b/tests/build_tools_test.xml
@@ -0,0 +1,12 @@
+<tools>
+ <tool id="1" enabled="true" extensions=".tex" icon="compile_pdf">
+ <label>LaTeX → PDF (Latexmk)</label>
+ <job postProcessor="latexmk">latexmk -pdf -synctex=1 $filename</job>
+ <job postProcessor="no-output">build job 2</job>
+ <open>$shortname.pdf</open>
+ </tool>
+
+ <tool enabled="false">
+ <label>build tool 2</label>
+ </tool>
+</tools>
diff --git a/tests/test-build-tools.c b/tests/test-build-tools.c
new file mode 100644
index 0000000..fb3364a
--- /dev/null
+++ b/tests/test-build-tools.c
@@ -0,0 +1,224 @@
+/*
+ * This file is part of LaTeXila.
+ *
+ * Copyright (C) 2014 - Sébastien Wilmet <swilmet gnome org>
+ *
+ * LaTeXila is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * LaTeXila is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with LaTeXila. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "latexila.h"
+#include <gtk/gtk.h>
+
+static void
+check_build_jobs (LatexilaBuildJob *build_job1,
+ LatexilaBuildJob *build_job2)
+{
+ gchar *command1;
+ gchar *command2;
+ LatexilaPostProcessorType pp_type1;
+ LatexilaPostProcessorType pp_type2;
+
+ g_object_get (build_job1,
+ "command", &command1,
+ "post-processor-type", &pp_type1,
+ NULL);
+
+ g_object_get (build_job2,
+ "command", &command2,
+ "post-processor-type", &pp_type2,
+ NULL);
+
+ g_assert_cmpstr (command1, ==, command2);
+ g_assert_cmpint (pp_type1, ==, pp_type2);
+
+ g_free (command1);
+ g_free (command2);
+}
+
+static void
+check_build_tools (LatexilaBuildTool *build_tool1,
+ LatexilaBuildTool *build_tool2)
+{
+ gchar *label1;
+ gchar *label2;
+ gchar *description1;
+ gchar *description2;
+ gchar *extensions1;
+ gchar *extensions2;
+ gchar *icon1;
+ gchar *icon2;
+ gchar *files_to_open1;
+ gchar *files_to_open2;
+ gint id1;
+ gint id2;
+ gboolean enabled1;
+ gboolean enabled2;
+ GList *jobs1;
+ GList *jobs2;
+
+ g_object_get (build_tool1,
+ "label", &label1,
+ "description", &description1,
+ "extensions", &extensions1,
+ "icon", &icon1,
+ "files-to-open", &files_to_open1,
+ "id", &id1,
+ "enabled", &enabled1,
+ NULL);
+
+ g_object_get (build_tool2,
+ "label", &label2,
+ "description", &description2,
+ "extensions", &extensions2,
+ "icon", &icon2,
+ "files-to-open", &files_to_open2,
+ "id", &id2,
+ "enabled", &enabled2,
+ NULL);
+
+ g_assert_cmpstr (label1, ==, label2);
+ g_assert_cmpstr (description1, ==, description2);
+ g_assert_cmpstr (extensions1, ==, extensions2);
+ g_assert_cmpstr (icon1, ==, icon2);
+ g_assert_cmpstr (files_to_open1, ==, files_to_open2);
+ g_assert_cmpint (id1, ==, id2);
+ g_assert_cmpint (enabled1, ==, enabled2);
+
+ jobs1 = latexila_build_tool_get_jobs (build_tool1);
+ jobs2 = latexila_build_tool_get_jobs (build_tool2);
+
+ g_assert_cmpint (g_list_length (jobs1), ==, g_list_length (jobs2));
+
+ for (; jobs1 != NULL; jobs1 = jobs1->next, jobs2 = jobs2->next)
+ {
+ check_build_jobs (jobs1->data, jobs2->data);
+ }
+
+ g_free (label1);
+ g_free (label2);
+ g_free (description1);
+ g_free (description2);
+ g_free (extensions1);
+ g_free (extensions2);
+ g_free (icon1);
+ g_free (icon2);
+ g_free (files_to_open1);
+ g_free (files_to_open2);
+}
+
+static void
+loaded_cb (LatexilaBuildTools *build_tools)
+{
+ GList *list = NULL;
+ LatexilaBuildTool *build_tool;
+ LatexilaBuildJob *build_job;
+ GList *l1;
+ GList *l2;
+
+ /* First build tool */
+
+ build_tool = latexila_build_tool_new ();
+
+ g_object_set (build_tool,
+ "id", 1,
+ "enabled", TRUE,
+ "extensions", ".tex",
+ "icon", "compile_pdf",
+ "label", "LaTeX → PDF (Latexmk)",
+ "files-to-open", "$shortname.pdf",
+ NULL);
+
+ build_job = latexila_build_job_new ();
+
+ g_object_set (build_job,
+ "post-processor-type", LATEXILA_POST_PROCESSOR_TYPE_LATEXMK,
+ "command", "latexmk -pdf -synctex=1 $filename",
+ NULL);
+
+ latexila_build_tool_add_job (build_tool, build_job);
+ g_object_unref (build_job);
+
+ build_job = latexila_build_job_new ();
+
+ g_object_set (build_job,
+ "post-processor-type", LATEXILA_POST_PROCESSOR_TYPE_NO_OUTPUT,
+ "command", "build job 2",
+ NULL);
+
+ latexila_build_tool_add_job (build_tool, build_job);
+ g_object_unref (build_job);
+
+ list = g_list_append (list, build_tool);
+
+ /* Second build tool */
+
+ build_tool = latexila_build_tool_new ();
+
+ g_object_set (build_tool,
+ "enabled", FALSE,
+ "label", "build tool 2",
+ NULL);
+
+ list = g_list_append (list, build_tool);
+
+ /* Compare */
+
+ g_assert_cmpint (g_list_length (list), ==, g_list_length (build_tools->build_tools));
+
+ for (l1 = list, l2 = build_tools->build_tools;
+ l1 != NULL && l2 != NULL;
+ l1 = l1->next, l2 = l2->next)
+ {
+ check_build_tools (l1->data, l2->data);
+ }
+
+ g_list_free_full (list, g_object_unref);
+ gtk_main_quit ();
+}
+
+static void
+test_load (void)
+{
+ LatexilaBuildTools *build_tools;
+ gchar *path;
+ GFile *xml_file;
+
+ path = g_build_filename (SRCDIR, "build_tools_test.xml", NULL);
+ xml_file = g_file_new_for_path (path);
+ g_free (path);
+
+ build_tools = g_object_new (LATEXILA_TYPE_BUILD_TOOLS, NULL);
+
+ g_signal_connect (build_tools,
+ "loaded",
+ G_CALLBACK (loaded_cb),
+ NULL);
+
+ latexila_build_tools_load (build_tools, xml_file);
+ g_object_unref (xml_file);
+
+ gtk_main ();
+ g_object_unref (build_tools);
+}
+
+gint
+main (gint argc,
+ gchar **argv)
+{
+ g_test_init (&argc, &argv, NULL);
+
+ g_test_add_func ("/build-tools/load", test_load);
+
+ return g_test_run ();
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]