[epiphany/history-rewrite: 20/28] Add tests for EphyHistoryService::get_url()



commit e3c3d3a1c98a383f773bd3d9bf014853a672002d
Author: Claudio Saavedra <csaavedra igalia com>
Date:   Tue Jul 5 13:42:42 2011 +0300

    Add tests for EphyHistoryService::get_url()

 tests/ephy-history.c |   62 ++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 62 insertions(+), 0 deletions(-)
---
diff --git a/tests/ephy-history.c b/tests/ephy-history.c
index 29af83a..f25e41e 100644
--- a/tests/ephy-history.c
+++ b/tests/ephy-history.c
@@ -247,6 +247,66 @@ test_set_url_title_url_not_existent (void)
   gtk_main();
 }
 
+static void
+test_get_url_done (EphyHistoryService *service, gboolean success, gpointer result_data, gpointer user_data)
+{
+  EphyHistoryURL *url;
+  gboolean expected_success = GPOINTER_TO_INT (user_data);
+
+  url = (EphyHistoryURL *)result_data;
+
+  g_assert (success == expected_success);
+
+  if (expected_success == TRUE) {
+    g_assert (url != NULL);
+    g_assert_cmpstr (url->url, ==, "http://www.gnome.org";);
+    g_assert_cmpint (url->id, !=, -1);
+    ephy_history_url_free (url);
+  } else {
+    g_assert (url == NULL);
+  }
+  g_object_unref (service);
+  gtk_main_quit ();
+}
+
+static void
+test_get_url_visit_added (EphyHistoryService *service, gboolean success, gpointer result_data, gpointer user_data)
+{
+  g_assert (success == TRUE);
+
+  ephy_history_service_get_url (service, "http://www.gnome.org";, test_get_url_done, user_data);
+}
+
+static void
+test_get_url_helper (gboolean add_entry)
+{
+  gchar *temporary_file = g_build_filename (g_get_tmp_dir (), "epiphany-history-test.db", NULL);
+  EphyHistoryService *service = ensure_empty_history(temporary_file);
+  g_free (temporary_file);
+
+  if (add_entry == TRUE) {
+    EphyHistoryPageVisit *visit = ephy_history_page_visit_new ("http://www.gnome.org";, 0, EPHY_PAGE_VISIT_TYPED);
+    ephy_history_service_add_visit (service, visit, test_get_url_visit_added, GINT_TO_POINTER (add_entry));
+    ephy_history_page_visit_free (visit);
+  } else {
+    ephy_history_service_get_url (service, "http://www.gnome.org";, test_get_url_done, GINT_TO_POINTER (add_entry));
+  }
+
+  gtk_main();
+}
+
+static void
+test_get_url (void)
+{
+  test_get_url_helper (TRUE);
+}
+
+static void
+test_get_url_not_existent (void)
+{
+  test_get_url_helper (FALSE);
+}
+
 int
 main (int argc, char *argv[])
 {
@@ -260,6 +320,8 @@ main (int argc, char *argv[])
   g_test_add_func ("/embed/history/test_set_url_title", test_set_url_title);
   g_test_add_func ("/embed/history/test_set_url_title_is_correct", test_set_url_title_is_correct);
   g_test_add_func ("/embed/history/test_set_url_title_url_not_existent", test_set_url_title_url_not_existent);
+  g_test_add_func ("/embed/history/test_get_url", test_get_url);
+  g_test_add_func ("/embed/history/test_get_url_not_existent", test_get_url_not_existent);
 
   return g_test_run ();
 }



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