[nautilus-sendto] Add starts of a test case for setting the title



commit 0ca00f4b3d19e6d26070550833d42bae9ec953a3
Author: Bastien Nocera <hadess hadess net>
Date:   Wed Aug 18 14:24:46 2010 +0100

    Add starts of a test case for setting the title

 Makefile.decl                  |   53 ++++++++++++++++++++++++++++++++++++++++
 src/Makefile.am                |   13 +++++++++-
 src/nautilus-sendto-command.c  |   11 +++++++-
 src/nautilus-sendto-mimetype.c |   31 +++++++++++++++++++++++
 src/nautilus-sendto-mimetype.h |   27 ++++++++++++++++++++
 src/test-mimetype.c            |   50 +++++++++++++++++++++++++++++++++++++
 6 files changed, 182 insertions(+), 3 deletions(-)
---
diff --git a/Makefile.decl b/Makefile.decl
new file mode 100644
index 0000000..aab33c3
--- /dev/null
+++ b/Makefile.decl
@@ -0,0 +1,53 @@
+GTESTER        = gtester		# in $PATH for non-GLIB packages
+GTESTER_REPORT = gtester-report		# in $PATH for non-GLIB packages
+
+# initialize variables for unconditional += appending
+TEST_PROGS =
+
+# test: run all tests in cwd and subdirs
+test:	${TEST_PROGS}
+	@test -z "${TEST_PROGS}" || ${GTESTER} --verbose ${TEST_PROGS}
+	@ for subdir in $(SUBDIRS) . ; do \
+	    test "$$subdir" = "." -o "$$subdir" = "po" || \
+	    ( cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) $@ ) || exit $? ; \
+	  done
+
+# test-report: run tests in subdirs and generate report
+# perf-report: run tests in subdirs with -m perf and generate report
+# full-report: like test-report: with -m perf and -m slow
+test-report perf-report full-report:	${TEST_PROGS}
+	@test -z "${TEST_PROGS}" || { \
+	  case $@ in \
+	  test-report) test_options="-k";; \
+	  perf-report) test_options="-k -m=perf";; \
+	  full-report) test_options="-k -m=perf -m=slow";; \
+	  esac ; \
+	  if test -z "$$GTESTER_LOGDIR" ; then	\
+	    ${GTESTER} --verbose $$test_options -o test-report.xml ${TEST_PROGS} ; \
+	  elif test -n "${TEST_PROGS}" ; then \
+	    ${GTESTER} --verbose $$test_options -o `mktemp "$$GTESTER_LOGDIR/log-XXXXXX"` ${TEST_PROGS} ; \
+	  fi ; \
+	}
+	@ ignore_logdir=true ; \
+	  if test -z "$$GTESTER_LOGDIR" ; then \
+	    GTESTER_LOGDIR=`mktemp -d "\`pwd\`/.testlogs-XXXXXX"`; export GTESTER_LOGDIR ; \
+	    ignore_logdir=false ; \
+	  fi ; \
+	  for subdir in $(SUBDIRS) . ; do \
+	    test "$$subdir" = "." -o "$$subdir" = "po" || \
+	    ( cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) $@ ) || exit $? ; \
+	  done ; \
+	  $$ignore_logdir || { \
+	    echo '<?xml version="1.0"?>' > $  xml ; \
+	    echo '<report-collection>'  >> $  xml ; \
+	    for lf in `ls -L "$$GTESTER_LOGDIR"/.` ; do \
+	      sed '1,1s/^<?xml\b[^>?]*?>//' <"$$GTESTER_LOGDIR"/"$$lf" >> $  xml ; \
+	    done ; \
+	    echo >> $  xml ; \
+	    echo '</report-collection>' >> $  xml ; \
+	    rm -rf "$$GTESTER_LOGDIR"/ ; \
+	    ${GTESTER_REPORT} --version 2>/dev/null 1>&2 ; test "$$?" != 0 || ${GTESTER_REPORT} $  xml >$  html ; \
+	  }
+.PHONY: test test-report perf-report full-report
+# run make test as part of make check
+check-local: test
diff --git a/src/Makefile.am b/src/Makefile.am
index 8977b34..8a97328 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -1,3 +1,5 @@
+include $(top_srcdir)/Makefile.decl
+
 SUBDIRS = extension plugins
 INCLUDES =					\
 	-DDATADIR=\"$(datadir)\"		\
@@ -16,7 +18,9 @@ INCLUDES =					\
 noinst_LTLIBRARIES = libnstplugin.la
 libnstplugin_la_SOURCES =			\
 	nst-enum-types.c			\
-	nst-enum-types.h
+	nst-enum-types.h			\
+	nautilus-sendto-mimetype.c		\
+	nautilus-sendto-mimetype.h
 libnstplugin_la_LIBADD = $(NAUTILUS_SENDTO_LIBS)
 
 bin_PROGRAMS = nautilus-sendto
@@ -24,6 +28,13 @@ bin_PROGRAMS = nautilus-sendto
 nautilus_sendto_SOURCES = nautilus-sendto-command.c
 nautilus_sendto_LDADD = $(NAUTILUS_SENDTO_LIBS) libnstplugin.la $(builddir)/plugins/libnautilussendto-1.0.la
 
+pwd=`pwd`
+
+noinst_PROGRAMS = $(TEST_PROGS)
+TEST_PROGS += test-mimetype
+test_mimetype_SOURCES = test-mimetype.c
+test_mimetype_LDADD = $(NAUTILUS_SENDTO_LIBS) libnstplugin.la $(builddir)/plugins/libnautilussendto-1.0.la
+
 nst_headers_to_scan_for_enums = plugins/nautilus-sendto-plugin.h
 # Generate the enums source code, with glib-mkenums:
 # This is based on the same Makefile.am stuff in pango:
diff --git a/src/nautilus-sendto-command.c b/src/nautilus-sendto-command.c
index 671ceb9..a3ac0ee 100644
--- a/src/nautilus-sendto-command.c
+++ b/src/nautilus-sendto-command.c
@@ -28,7 +28,9 @@
 #include <glib/gi18n.h>
 #include <glib/gstdio.h>
 #include <gtk/gtk.h>
+
 #include "nautilus-sendto-plugin.h"
+#include "nautilus-sendto-mimetype.h"
 
 #define NAUTILUS_SENDTO_LAST_MEDIUM	"last-medium"
 #define NAUTILUS_SENDTO_STATUS_LABEL_TIMEOUT_SECONDS 10
@@ -272,6 +274,7 @@ nautilus_sendto_create_ui (void)
 	GtkSettings *gtk_settings;
 	GtkWidget *button_image;
 	const char *ui_file;
+	char *title;
 
 	app = gtk_builder_new ();
 	if (run_from_build_dir) {
@@ -302,8 +305,12 @@ nautilus_sendto_create_ui (void)
 			  G_CALLBACK (update_button_image), button_image);
 	update_button_image (gtk_settings, NULL, button_image);
 
-	/* FIXME:
-	 * Set the title of the window depending on the mime-types in mime_types */
+	/* Set a title depending on the number of files to
+	 * share, and their types */
+	title = nst_title_from_mime_types ((const char **) mime_types, g_list_length (file_list));
+	gtk_window_set_title (GTK_WINDOW (gtk_builder_get_object (app, "nautilus_sendto_dialog")),
+			     title);
+	g_free (title);
 
 	set_model_for_options_treeview (ui);
 	g_signal_connect (G_OBJECT (ui->dialog), "destroy",
diff --git a/src/nautilus-sendto-mimetype.c b/src/nautilus-sendto-mimetype.c
new file mode 100644
index 0000000..ac15b1a
--- /dev/null
+++ b/src/nautilus-sendto-mimetype.c
@@ -0,0 +1,31 @@
+/*
+ * Copyright (C) 2010 Bastien Nocera
+ *
+ * This program 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 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program 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 av.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this program; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301  USA.
+ *
+ * Author:  Roberto Majadas <roberto majadas openshine com>
+ *          Bastien Nocera <hadess hadess net>
+ */
+
+#include "nautilus-sendto-mimetype.h"
+
+char *
+nst_title_from_mime_types (const char **mimetypes,
+			   guint        num_files)
+{
+	return NULL;
+}
+
diff --git a/src/nautilus-sendto-mimetype.h b/src/nautilus-sendto-mimetype.h
new file mode 100644
index 0000000..c23875c
--- /dev/null
+++ b/src/nautilus-sendto-mimetype.h
@@ -0,0 +1,27 @@
+/*
+ * Copyright (C) 2010 Bastien Nocera
+ *
+ * This program 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 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program 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 av.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this program; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301  USA.
+ *
+ * Author:  Roberto Majadas <roberto majadas openshine com>
+ *          Bastien Nocera <hadess hadess net>
+ */
+
+#include <glib.h>
+
+char *nst_title_from_mime_types (const char **mimetypes,
+				 guint        num_files);
+
diff --git a/src/test-mimetype.c b/src/test-mimetype.c
new file mode 100644
index 0000000..ee1d44a
--- /dev/null
+++ b/src/test-mimetype.c
@@ -0,0 +1,50 @@
+
+#include "config.h"
+
+#include <locale.h>
+#include <glib.h>
+#include <glib-object.h>
+#include <glib/gi18n.h>
+
+#include "nautilus-sendto-mimetype.h"
+
+typedef struct {
+	const char **mimetypes;
+	guint num_files;
+	const char *result;
+} TitleTests;
+
+static TitleTests titles[] = {
+	{
+		{ "application/octet-stream", NULL },
+		1,
+		"Sharing one file",
+	},
+};
+
+static void
+test_name (void)
+{
+	guint i;
+
+	for (i = 0; i < G_N_ELEMENTS (titles); i++) {
+		g_assert_cmpstr (nst_title_from_mime_types (titles[i].mimetypes, titles[i].num_files), ==, titles[i].result);
+	}
+}
+
+int main (int argc, char **argv)
+{
+	bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
+	bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
+	textdomain (GETTEXT_PACKAGE);
+
+	setlocale (LC_ALL, "en_US.UTF-8");
+
+	g_type_init ();
+	g_test_init (&argc, &argv, NULL);
+	g_test_bug_base ("http://bugzilla.gnome.org/show_bug.cgi?id=";);
+
+	g_test_add_func ("/mimetype/name", test_name);
+
+	return g_test_run ();
+}



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]