[epiphany/overview: 2/30] Add basic tests for EphySnapshotService



commit 5b1dc049c509f98860b510c83a093e958182e3c8
Author: Claudio Saavedra <csaavedra igalia com>
Date:   Tue Jan 24 16:07:39 2012 +0200

    Add basic tests for EphySnapshotService
    
    https://bugzilla.gnome.org/show_bug.cgi?id=668578

 tests/Makefile.am                  |    4 +
 tests/ephy-snapshot-service-test.c |  225 ++++++++++++++++++++++++++++++++++++
 2 files changed, 229 insertions(+), 0 deletions(-)
---
diff --git a/tests/Makefile.am b/tests/Makefile.am
index c44b957..ee8fd8b 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -6,6 +6,7 @@ noinst_PROGRAMS = \
 	test-ephy-location-entry \
 	test-ephy-migration \
 	test-ephy-search-entry \
+	test-ephy-snapshot-service \
 	test-ephy-sqlite \
 	test-ephy-web-view \
 	$(NULL)
@@ -132,6 +133,9 @@ test_ephy_migration_SOURCES = \
 test_ephy_search_entry_SOURCES = \
 	ephy-search-entry-test.c
 
+test_ephy_snapshot_service_SOURCES = \
+	ephy-snapshot-service-test.c
+
 test_ephy_sqlite_SOURCES = \
 	ephy-sqlite-test.c
 
diff --git a/tests/ephy-snapshot-service-test.c b/tests/ephy-snapshot-service-test.c
new file mode 100644
index 0000000..85151cc
--- /dev/null
+++ b/tests/ephy-snapshot-service-test.c
@@ -0,0 +1,225 @@
+/* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/*
+ *  Copyright  2012 Igalia S.L.
+ *
+ *  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, 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 details.
+ *
+ *  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.
+ *
+ */
+
+#include "config.h"
+#include "ephy-debug.h"
+#include "ephy-snapshot-service.h"
+
+static time_t mtime;
+
+static gboolean
+quit_when_test_done (GtkWidget *w,
+                     GdkEvent *event,
+                     gint *tests)
+{
+  if (--(*tests) == 0)
+    gtk_main_quit ();
+
+  return FALSE;
+}
+
+static void
+on_snapshot_ready (GObject *source,
+                   GAsyncResult *res,
+                   gint *tests)
+{
+  GdkPixbuf *pixbuf;
+  GtkWidget *w,*i;
+  GError *error = NULL;
+
+  pixbuf = ephy_snapshot_service_get_snapshot_finish (EPHY_SNAPSHOT_SERVICE (source),
+                                                      res, &error);
+  g_assert (GDK_IS_PIXBUF (pixbuf) || error != NULL);
+
+  if (error) {
+    g_print ("Error loading pixbuf: %s\n", error->message);
+    g_error_free (error);
+    quit_when_test_done (NULL, NULL, tests);
+    return;
+  }
+
+  w = gtk_window_new (GTK_WINDOW_TOPLEVEL);
+  i = gtk_image_new_from_pixbuf (pixbuf);
+  gtk_container_add (GTK_CONTAINER (w), i);
+  gtk_widget_show_all (w);
+  g_signal_connect (w, "delete-event",
+                    G_CALLBACK (quit_when_test_done), tests);
+}
+
+static void
+test_snapshot (void)
+{
+  EphySnapshotService *service = ephy_snapshot_service_get_default ();
+  gint tests = 1;
+
+  ephy_snapshot_service_get_snapshot_async (service,
+                                            "http://www.gnome.org";,
+                                            mtime,
+                                            NULL,
+                                            (GAsyncReadyCallback)on_snapshot_ready,
+                                            &tests);
+  gtk_main ();
+}
+
+static void
+test_cached_snapshot (void)
+{
+  gint tests = 1;
+  EphySnapshotService *service = ephy_snapshot_service_get_default ();
+
+  ephy_snapshot_service_get_snapshot_async (service,
+                                            "http://www.gnome.org";,
+                                            mtime,
+                                            NULL,
+                                            (GAsyncReadyCallback)on_snapshot_ready,
+                                            &tests);
+  gtk_main ();
+}
+
+static void
+test_many_snapshots (void)
+{
+  gint tests = 3;
+  EphySnapshotService *service = ephy_snapshot_service_get_default ();
+
+  ephy_snapshot_service_get_snapshot_async (service,
+                                            "http://www.igalia.com";,
+                                            mtime,
+                                            NULL,
+                                            (GAsyncReadyCallback)on_snapshot_ready,
+                                            &tests);
+  ephy_snapshot_service_get_snapshot_async (service,
+                                            "http://en.wikipedia.org";,
+                                            mtime,
+                                            NULL,
+                                            (GAsyncReadyCallback)on_snapshot_ready,
+                                            &tests);
+  ephy_snapshot_service_get_snapshot_async (service,
+                                            "http://www.webkitgtk.org";,
+                                            mtime,
+                                            NULL,
+                                            (GAsyncReadyCallback)on_snapshot_ready,
+                                            &tests);
+  gtk_main ();
+}
+
+static void
+test_snapshot_with_cancellable (void)
+{
+  gint tests = 1;
+  EphySnapshotService *service = ephy_snapshot_service_get_default ();
+  GCancellable *cancellable = g_cancellable_new ();
+
+  ephy_snapshot_service_get_snapshot_async (service,
+                                            "http://fi.wikipedia.org";,
+                                            mtime,
+                                            cancellable,
+                                            (GAsyncReadyCallback)on_snapshot_ready,
+                                            &tests);
+  gtk_main ();
+}
+
+static void
+test_already_cancelled_snapshot (void)
+{
+  gint tests = 1;
+  EphySnapshotService *service = ephy_snapshot_service_get_default ();
+  GCancellable *cancellable = g_cancellable_new ();
+
+  g_cancellable_cancel (cancellable);
+  ephy_snapshot_service_get_snapshot_async (service,
+                                            "http://de.wikipedia.org";,
+                                            mtime,
+                                            cancellable,
+                                            (GAsyncReadyCallback)on_snapshot_ready,
+                                            &tests);
+  gtk_main ();
+}
+
+static void
+test_snapshot_and_timed_cancellation (void)
+{
+  gint tests = 1;
+  EphySnapshotService *service = ephy_snapshot_service_get_default ();
+  GCancellable *cancellable = g_cancellable_new ();
+
+  ephy_snapshot_service_get_snapshot_async (service,
+                                            "http://es.wikipedia.org";,
+                                            mtime,
+                                            cancellable,
+                                            (GAsyncReadyCallback)on_snapshot_ready,
+                                            &tests);
+  g_timeout_add_seconds (1, (GSourceFunc)g_cancellable_cancel, cancellable);
+  gtk_main ();
+}
+
+static void
+test_many_snapshots_and_cancel_some (void)
+{
+  gint tests = 3;
+  EphySnapshotService *service = ephy_snapshot_service_get_default ();
+  GCancellable *cancellable = g_cancellable_new ();
+
+  ephy_snapshot_service_get_snapshot_async (service,
+                                            "http://planet.igalia.com";,
+                                            mtime,
+                                            cancellable,
+                                            (GAsyncReadyCallback)on_snapshot_ready,
+                                            &tests);
+  ephy_snapshot_service_get_snapshot_async (service,
+                                            "http://en.wiktionary.org/wiki/blas";,
+                                            mtime,
+                                            NULL,
+                                            (GAsyncReadyCallback)on_snapshot_ready,
+                                            &tests);
+  ephy_snapshot_service_get_snapshot_async (service,
+                                            "http://www.webkit.org";,
+                                            mtime,
+                                            cancellable,
+                                            (GAsyncReadyCallback)on_snapshot_ready,
+                                            &tests);
+  g_timeout_add_seconds (5, (GSourceFunc)g_cancellable_cancel, cancellable);
+  gtk_main ();
+}
+
+int
+main (int argc, char *argv[])
+{
+  gtk_test_init (&argc, &argv);
+  ephy_debug_init ();
+
+  mtime = time(NULL);
+
+  g_test_add_func ("/lib/ephy-snapshot-service/test_snapshot",
+                   test_snapshot);
+  g_test_add_func ("/lib/ephy-snapshot-service/test_cached_snapshot",
+                   test_cached_snapshot);
+  g_test_add_func ("/lib/ephy-snapshot-service/test_many_snapshots",
+                   test_many_snapshots);
+  g_test_add_func ("/lib/ephy-snapshot-service/test_snapshot_with_cancellable",
+                   test_snapshot_with_cancellable);
+  g_test_add_func ("/lib/ephy-snapshot-service/test_already_cancelled_snapshot",
+                   test_already_cancelled_snapshot);
+  g_test_add_func ("/lib/ephy-snapshot-service/test_snapshot_and_timed_cancellation",
+                   test_snapshot_and_timed_cancellation);
+  g_test_add_func ("/lib/ephy-snapshot-service/test_many_snapshots_and_cancel_some",
+                   test_many_snapshots_and_cancel_some);
+  return g_test_run ();
+}



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