[tracker/tracker-0.6] Test tracker-thumbnailer
- From: Ivan Frade <ifrade src gnome org>
- To: svn-commits-list gnome org
- Subject: [tracker/tracker-0.6] Test tracker-thumbnailer
- Date: Wed, 29 Apr 2009 08:38:24 -0400 (EDT)
commit ec89811942101c38c98c0bcbcb9c00a45a191816
Author: Ivan Frade <ivan frade nokia com>
Date: Wed Apr 29 15:36:04 2009 +0300
Test tracker-thumbnailer
Add tests to tracker-thumbnailer. Includes a new gobject (MockDBusGProxy)
to mock the real DBus GProxy object, and some dbus methods are
overloaded to test the object without external dependencies.
---
tests/libtracker-common/Makefile.am | 15 ++-
tests/libtracker-common/mock-dbus-gproxy.c | 56 ++++++
tests/libtracker-common/mock-dbus-gproxy.h | 40 +++++
tests/libtracker-common/mock-thumbnailer-dbus.c | 61 +++++++
tests/libtracker-common/tracker-thumbnailer-test.c | 186 ++++++++++++++++++++
5 files changed, 357 insertions(+), 1 deletions(-)
diff --git a/tests/libtracker-common/Makefile.am b/tests/libtracker-common/Makefile.am
index 4fc2767..2ad9115 100644
--- a/tests/libtracker-common/Makefile.am
+++ b/tests/libtracker-common/Makefile.am
@@ -19,7 +19,8 @@ TEST_PROGS += \
tracker-dbus \
tracker-type-utils \
tracker-file-utils \
- tracker-albumart
+ tracker-albumart \
+ tracker-thumbnailer
INCLUDES = \
-DG_LOG_DOMAIN=\"Tracker\" \
@@ -115,5 +116,17 @@ tracker_albumart_LDADD = \
$(GTHREAD_LIBS) \
$(GLIB2_LIBS)
+tracker_thumbnailer_SOURCES = \
+ tracker-thumbnailer-test.c \
+ mock-dbus-gproxy.c \
+ mock-thumbnailer-dbus.c
+
+tracker_thumbnailer_LDADD = \
+ $(top_builddir)/src/libtracker-common/libtracker-common.la \
+ $(top_builddir)/tests/common/libtracker-testcommon.la \
+ $(GMODULE_LIBS) \
+ $(GCOV_LIBS) \
+ $(GTHREAD_LIBS) \
+ $(GLIB2_LIBS)
EXTRA_DIST = non-utf8.txt
diff --git a/tests/libtracker-common/mock-dbus-gproxy.c b/tests/libtracker-common/mock-dbus-gproxy.c
new file mode 100644
index 0000000..ab814ac
--- /dev/null
+++ b/tests/libtracker-common/mock-dbus-gproxy.c
@@ -0,0 +1,56 @@
+
+#include "mock-dbus-gproxy.h"
+
+
+
+
+enum {
+ MOCK_DBUS_GPROXY_DUMMY_PROPERTY
+};
+static gpointer mock_dbus_gproxy_parent_class = NULL;
+static void mock_dbus_gproxy_finalize (GObject* obj);
+
+
+
+MockDBusGProxy* mock_dbus_gproxy_construct (GType object_type) {
+ MockDBusGProxy * self;
+ self = g_object_newv (object_type, 0, NULL);
+ return self;
+}
+
+
+MockDBusGProxy* mock_dbus_gproxy_new (void) {
+ return mock_dbus_gproxy_construct (TYPE_MOCK_DBUS_GPROXY);
+}
+
+
+static void mock_dbus_gproxy_class_init (MockDBusGProxyClass * klass) {
+ mock_dbus_gproxy_parent_class = g_type_class_peek_parent (klass);
+ G_OBJECT_CLASS (klass)->finalize = mock_dbus_gproxy_finalize;
+}
+
+
+static void mock_dbus_gproxy_instance_init (MockDBusGProxy * self) {
+ self->id = 1;
+}
+
+
+static void mock_dbus_gproxy_finalize (GObject* obj) {
+ MockDBusGProxy * self;
+ self = MOCK_DBUS_GPROXY (obj);
+ G_OBJECT_CLASS (mock_dbus_gproxy_parent_class)->finalize (obj);
+}
+
+
+GType mock_dbus_gproxy_get_type (void) {
+ static GType mock_dbus_gproxy_type_id = 0;
+ if (mock_dbus_gproxy_type_id == 0) {
+ static const GTypeInfo g_define_type_info = { sizeof (MockDBusGProxyClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) mock_dbus_gproxy_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (MockDBusGProxy), 0, (GInstanceInitFunc) mock_dbus_gproxy_instance_init, NULL };
+ mock_dbus_gproxy_type_id = g_type_register_static (G_TYPE_OBJECT, "MockDBusGProxy", &g_define_type_info, 0);
+ }
+ return mock_dbus_gproxy_type_id;
+}
+
+
+
+
diff --git a/tests/libtracker-common/mock-dbus-gproxy.h b/tests/libtracker-common/mock-dbus-gproxy.h
new file mode 100644
index 0000000..687e855
--- /dev/null
+++ b/tests/libtracker-common/mock-dbus-gproxy.h
@@ -0,0 +1,40 @@
+
+#ifndef __MOCK_DBUS_GPROXY_H__
+#define __MOCK_DBUS_GPROXY_H__
+
+#include <glib.h>
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+
+#define TYPE_MOCK_DBUS_GPROXY (mock_dbus_gproxy_get_type ())
+#define MOCK_DBUS_GPROXY(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_MOCK_DBUS_GPROXY, MockDBusGProxy))
+#define MOCK_DBUS_GPROXY_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_MOCK_DBUS_GPROXY, MockDBusGProxyClass))
+#define IS_MOCK_DBUS_GPROXY(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_MOCK_DBUS_GPROXY))
+#define IS_MOCK_DBUS_GPROXY_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_MOCK_DBUS_GPROXY))
+#define MOCK_DBUS_GPROXY_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_MOCK_DBUS_GPROXY, MockDBusGProxyClass))
+
+typedef struct _MockDBusGProxy MockDBusGProxy;
+typedef struct _MockDBusGProxyClass MockDBusGProxyClass;
+typedef struct _MockDBusGProxyPrivate MockDBusGProxyPrivate;
+
+struct _MockDBusGProxy {
+ GObject parent_instance;
+ MockDBusGProxyPrivate * priv;
+ gint id;
+};
+
+struct _MockDBusGProxyClass {
+ GObjectClass parent_class;
+};
+
+
+MockDBusGProxy* mock_dbus_gproxy_construct (GType object_type);
+MockDBusGProxy* mock_dbus_gproxy_new (void);
+GType mock_dbus_gproxy_get_type (void);
+
+
+G_END_DECLS
+
+#endif
diff --git a/tests/libtracker-common/mock-thumbnailer-dbus.c b/tests/libtracker-common/mock-thumbnailer-dbus.c
new file mode 100644
index 0000000..3a66603
--- /dev/null
+++ b/tests/libtracker-common/mock-thumbnailer-dbus.c
@@ -0,0 +1,61 @@
+#include <glib.h>
+#include <dbus/dbus.h>
+#include <dbus/dbus-glib-lowlevel.h>
+#include <dbus/dbus-glib.h>
+#include "mock-dbus-gproxy.h"
+
+DBusGConnection*
+dbus_g_bus_get (DBusBusType type, GError **error)
+{
+ //g_print ("Calling the right function %s\n", __func__);
+ return (DBusGConnection *)g_strdup ("mock connection");
+}
+
+DBusGProxy*
+dbus_g_proxy_new_for_name (DBusGConnection *connection,
+ const char *name,
+ const char *path,
+ const char *interface)
+{
+ //g_print ("Calling the right function %s\n", __func__);
+ return (DBusGProxy *)mock_dbus_gproxy_new ();
+}
+
+gboolean
+dbus_g_proxy_call (DBusGProxy *proxy,
+ const char *method,
+ GError **error,
+ GType first_arg_type,
+ ...)
+{
+ va_list args;
+
+ //g_print ("Calling the right function %s\n", __func__);
+ g_message ("DBUS-CALL: %s", method);
+
+ va_start (args, first_arg_type);
+
+ if (g_strcmp0 (method, "GetSupported") == 0) {
+ GType *t;
+ GStrv *mime_types;
+ gchar *mimetypes[] = {"image/jpeg", "image/png", NULL};
+
+ t = va_arg (args, GType*);
+ mime_types = va_arg (args, GStrv*);
+
+ *mime_types = g_strdupv (mimetypes);
+ }
+
+ va_end (args);
+ return TRUE;
+}
+
+void
+dbus_g_proxy_call_no_reply (DBusGProxy *proxy,
+ const char *method,
+ GType first_arg_type,...)
+{
+
+ g_message ("DBUS-CALL: %s", method);
+}
+
diff --git a/tests/libtracker-common/tracker-thumbnailer-test.c b/tests/libtracker-common/tracker-thumbnailer-test.c
new file mode 100644
index 0000000..af66446
--- /dev/null
+++ b/tests/libtracker-common/tracker-thumbnailer-test.c
@@ -0,0 +1,186 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/*
+ * Copyright (C) 2008, Nokia (urho konttori nokia com)
+ *
+ * This library 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 library 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 this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+#include "config.h"
+#include <glib.h>
+#include <stdlib.h>
+
+#include <libtracker-common/tracker-thumbnailer.h>
+
+static const gchar *old_xdg_config = NULL;
+static TrackerConfig *cosmic_config = NULL;
+
+static void
+set_config_directory ()
+{
+ old_xdg_config = g_getenv ("XDG_CONFIG_HOME");
+ g_setenv ("XDG_CONFIG_HOME", ".", TRUE);
+}
+
+static void
+restore_config_directory ()
+{
+ g_setenv ("XDG_CONFIG_HOME", old_xdg_config, TRUE);
+}
+
+static void
+test_init_shutdown ()
+{
+
+ tracker_thumbnailer_shutdown ();
+
+ tracker_thumbnailer_init (cosmic_config);
+ tracker_thumbnailer_shutdown ();
+
+ tracker_thumbnailer_init (cosmic_config);
+ tracker_thumbnailer_shutdown ();
+
+ tracker_thumbnailer_shutdown ();
+ tracker_thumbnailer_init (cosmic_config);
+ tracker_thumbnailer_init (cosmic_config);
+ tracker_thumbnailer_shutdown ();
+}
+
+static void
+test_queue_file ()
+{
+ tracker_thumbnailer_init (cosmic_config);
+
+ /* URI with supported mimetype */
+ if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR)) {
+ tracker_thumbnailer_queue_file ("file:///a/b/c.jpeg", "image/jpeg");
+ }
+ g_test_trap_assert_stderr ("*Thumbnailer queue appended with uri:'file:///a/b/c.jpeg', mime type:'image/jpeg', request_id:1...*");
+
+
+ /* URI with unsupported mimetype */
+ if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDOUT)) {
+ tracker_thumbnailer_queue_file ("file:///a/b/c.jpeg", "unsupported");
+ exit (0);
+ }
+ g_test_trap_assert_passed ();
+ g_test_trap_assert_stdout ("*Thumbnailer ignoring uri:'file:///a/b/c.jpeg', mime type:'unsupported'*");
+
+
+ /* Path with supported mimetype */
+ if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR)) {
+ tracker_thumbnailer_queue_file ("/a/b/c.jpeg", "image/jpeg");
+ }
+ g_test_trap_assert_stderr ("*Thumbnailer queue appended with uri:'file:///a/b/c.jpeg', mime type:'image/jpeg', request_id:1...*");
+
+
+ tracker_thumbnailer_shutdown ();
+}
+
+static void
+test_queue_send ()
+{
+ gint i;
+
+ tracker_thumbnailer_init (cosmic_config);
+
+ for (i = 0; i < 10; i++) {
+ gchar *filename = g_strdup_printf ("file:///a/b/c%d.jpeg", i);
+ tracker_thumbnailer_queue_file (filename, "image/jpeg");
+ }
+
+ if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR)) {
+ tracker_thumbnailer_queue_send ();
+ }
+ g_test_trap_assert_stderr ("*DBUS-CALL: Queue*");
+ g_test_trap_assert_stderr ("*Thumbnailer queue sent with 10 items to thumbnailer daemon, request ID:10...*");
+
+ tracker_thumbnailer_shutdown ();
+}
+
+static void
+test_move ()
+{
+ tracker_thumbnailer_init (cosmic_config);
+
+ if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR)) {
+ tracker_thumbnailer_move ("file:///a/b/c1.jpeg", "image/jpeg",
+ "file:///a/b/d1.jpeg");
+ }
+ g_test_trap_assert_stderr ("*DBUS-CALL: Move*");
+ g_test_trap_assert_stderr ("*Thumbnailer request to move uri from:'file:///a/b/c1.jpeg' to:'file:///a/b/d1.jpeg', request_id:1...*");
+ tracker_thumbnailer_shutdown ();
+}
+
+static void
+test_remove ()
+{
+ tracker_thumbnailer_init (cosmic_config);
+
+ if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR)) {
+ tracker_thumbnailer_remove ("file:///a/b/c1.jpeg", "image/jpeg");
+ }
+ g_test_trap_assert_stderr ("*DBUS-CALL: Delete*");
+ g_test_trap_assert_stderr ("*Thumbnailer request to remove uri:'file:///a/b/c1.jpeg', request_id:1...*");
+
+ tracker_thumbnailer_shutdown ();
+}
+
+static void
+test_cleanup ()
+{
+ tracker_thumbnailer_init (cosmic_config);
+
+ if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR)) {
+ tracker_thumbnailer_cleanup ("file:///a/b/c1.jpeg");
+ }
+ g_test_trap_assert_stderr ("*DBUS-CALL: Cleanup*");
+ g_test_trap_assert_stderr ("*Thumbnailer cleaning up uri:'file:///a/b/c1.jpeg', request_id:1...*");
+
+ tracker_thumbnailer_shutdown ();
+}
+
+gint
+main (gint argc, gchar **argv)
+{
+ gint result;
+
+ g_type_init ();
+ g_test_init (&argc, &argv, NULL);
+
+ set_config_directory ();
+ cosmic_config = tracker_config_new ();
+ /* True is the default value, but makes sure! */
+ tracker_config_set_enable_thumbnails (cosmic_config, TRUE);
+
+
+ g_test_add_func ("/libtracker-common/tracker-thumbnailer/init_shutdown",
+ test_init_shutdown);
+ g_test_add_func ("/libtracker-common/tracker-thumbnailer/queue_file",
+ test_queue_file);
+ g_test_add_func ("/libtracker-common/tracker-thumbnailer/queue_send",
+ test_queue_send);
+ g_test_add_func ("/libtracker-common/tracker-thumbnailer/move",
+ test_move);
+ g_test_add_func ("/libtracker-common/tracker-thumbnailer/remove",
+ test_remove);
+ g_test_add_func ("/libtracker-common/tracker-thumbnailer/cleanup",
+ test_cleanup);
+
+ result = g_test_run ();
+
+ restore_config_directory ();
+
+ return result;
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]